PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / controls / border.php

border.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/controls/border.php

332 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Controls;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\ControlBaseAbstract;
9 use ABlocks\Controls\Color;
10
11 class Border extends ControlBaseAbstract {
12 public static function get_attribute_default_value( $is_responsive = false ) {
13
14 if ( $is_responsive ) {
15 return array(
16 'borderStyle' => 'default',
17 'borderStyleH' => 'default',
18 // border color
19 'borderColor' => '',
20 // border color - Hover
21 'borderColorH' => '',
22 // width
23 'isLinkedWidth' => true,
24 'isLinkedWidthTablet' => true,
25 'isLinkedWidthMobile' => true,
26 'commonWidth' => '',
27 'commonWidthTablet' => '',
28 'commonWidthMobile' => '',
29 'topWidth' => '',
30 'rightWidth' => '',
31 'bottomWidth' => '',
32 'leftWidth' => '',
33 'topWidthTablet' => '',
34 'rightWidthTablet' => '',
35 'bottomWidthTablet' => '',
36 'leftWidthTablet' => '',
37 'topWidthMobile' => '',
38 'rightWidthMobile' => '',
39 'bottomWidthMobile' => '',
40 'leftWidthMobile' => '',
41 'unitWidth' => 'px',
42 'unitWidthTablet' => '',
43 'unitWidthMobile' => '',
44 'isLinkedWidthH' => true,
45 'isLinkedWidthHTablet' => true,
46 'isLinkedWidthHMobile' => true,
47 // Width Hover
48 'commonWidthH' => '',
49 'commonWidthHTablet' => '',
50 'commonWidthHMobile' => '',
51 'topWidthH' => '',
52 'rightWidthH' => '',
53 'bottomWidthH' => '',
54 'leftWidthH' => '',
55 'topWidthHTablet' => '',
56 'rightWidthHTablet' => '',
57 'bottomWidthHTablet' => '',
58 'leftWidthHTablet' => '',
59 'topWidthHMobile' => '',
60 'rightWidthHMobile' => '',
61 'bottomWidthHMobile' => '',
62 'leftWidthHMobile' => '',
63 'unitWidthH' => 'px',
64 'unitWidthHTablet' => '',
65 'unitWidthHMobile' => '',
66 // Radius
67 'isLinkedRadius' => true,
68 'isLinkedRadiusTablet' => true,
69 'isLinkedRadiusMobile' => true,
70 'commonRadius' => '',
71 'commonRadiusTablet' => '',
72 'commonRadiusMobile' => '',
73 'topRadius' => '',
74 'rightRadius' => '',
75 'bottomRadius' => '',
76 'leftRadius' => '',
77 'topRadiusTablet' => '',
78 'rightRadiusTablet' => '',
79 'bottomRadiusTablet' => '',
80 'leftRadiusTablet' => '',
81 'topRadiusMobile' => '',
82 'rightRadiusMobile' => '',
83 'bottomRadiusMobile' => '',
84 'leftRadiusMobile' => '',
85 'unitRadius' => 'px',
86 'unitRadiusTablet' => '',
87 'unitRadiusMobile' => '',
88 // Radius Hover
89 'isLinkedRadiusH' => true,
90 'isLinkedRadiusHTablet' => true,
91 'isLinkedRadiusHMobile' => true,
92 'commonRadiusH' => '',
93 'commonRadiusHTablet' => '',
94 'commonRadiusHMobile' => '',
95 'topRadiusH' => '',
96 'rightRadiusH' => '',
97 'bottomRadiusH' => '',
98 'leftRadiusH' => '',
99 'topRadiusHTablet' => '',
100 'rightRadiusHTablet' => '',
101 'bottomRadiusHTablet' => '',
102 'leftRadiusHTablet' => '',
103 'topRadiusHMobile' => '',
104 'rightRadiusHMobile' => '',
105 'bottomRadiusHMobile' => '',
106 'leftRadiusHMobile' => '',
107 'unitRadiusH' => 'px',
108 'unitRadiusHTablet' => '',
109 'unitRadiusHMobile' => '',
110 'transitionDuration' => ''
111 );
112 }//end if
113 return [
114 'borderStyle' => 'default',
115 'borderStyleH' => 'default',
116 // border color
117 'borderColor' => '',
118 // border color - Hover
119 'borderColorH' => '',
120 // border width - Normal
121 'isLinkedWidth' => true,
122 'isLinkedWidthTablet' => true,
123 'isLinkedWidthMobile' => true,
124 'commonWidth' => '',
125 'topWidth' => '',
126 'rightWidth' => '',
127 'bottomWidth' => '',
128 'leftWidth' => '',
129 'unitWidth' => 'px',
130
131 // border width - Hover
132 'isLinkedWidthH' => true,
133 'isLinkedWidthHTablet' => true,
134 'isLinkedWidthHMobile' => true,
135 'commonWidthH' => '',
136 'topWidthH' => '',
137 'rightWidthH' => '',
138 'bottomWidthH' => '',
139 'leftWidthH' => '',
140 'unitWidthH' => 'px',
141
142 // border Radius
143 'isLinkedRadius' => true,
144 'commonRadius' => '',
145 'topRadius' => '',
146 'rightRadius' => '',
147 'bottomRadius' => '',
148 'leftRadius' => '',
149 'unitRadius' => 'px',
150
151 // border RadiusH - Hover
152 'isLinkedRadiusH' => true,
153 'isLinkedRadiusHTablet' => true,
154 'isLinkedRadiusHMobile' => true,
155 'commonRadiusH' => '',
156 'topRadiusH' => '',
157 'leftRadiusH' => '',
158 'unitRadiusH' => 'px',
159 'transitionDuration' => '',
160 ];
161 }
162
163 public static function get_attribute( $attributeName, $isResponsive = false ) {
164 $attribute_value = self::get_attribute_default_value( $isResponsive );
165 if ( $isResponsive ) {
166 return [
167 $attributeName => [
168 'type' => 'object',
169 'default' => $attribute_value
170 ]
171 ];
172 }
173 return [
174 $attributeName => [
175 'type' => 'object',
176 'default' => $attribute_value
177 ]
178 ];
179 }
180 public static function get_css( $attribute_value, $property = '', $device = '' ) {
181 $value = wp_parse_args( $attribute_value, self::get_attribute_default_value( true ) );
182 $css = [];
183
184 // Separate handling of width units
185 if ( $device ) {
186 $widthUnit = self::get_unit([
187 'unit' => $value['unitWidth'],
188 'unitTablet' => $value['unitWidthTablet'],
189 'unitMobile' => $value['unitWidthMobile'],
190 ], $device);
191 } else {
192 $widthUnit = $value['unitWidth'];
193 }
194
195 // Handle width
196 if ( $value[ 'isLinkedWidth' . $device ] ) {
197 if ( '' !== $value[ 'commonWidth' . $device ] ) {
198 $css['border-width'] = $value[ 'commonWidth' . $device ] . $widthUnit;
199 }
200 } else {
201 // Only emit border-width when at least one side was actually set —
202 // otherwise every unlinked border produced "border-width:0px 0px 0px 0px".
203 $has_width = '' !== $value[ 'topWidth' . $device ] || '' !== $value[ 'rightWidth' . $device ]
204 || '' !== $value[ 'bottomWidth' . $device ] || '' !== $value[ 'leftWidth' . $device ];
205 if ( $has_width ) {
206 $topWidth = ! empty( $value[ 'topWidth' . $device ] ) ? $value[ 'topWidth' . $device ] : 0;
207 $rightWidth = ! empty( $value[ 'rightWidth' . $device ] ) ? $value[ 'rightWidth' . $device ] : 0;
208 $bottomWidth = ! empty( $value[ 'bottomWidth' . $device ] ) ? $value[ 'bottomWidth' . $device ] : 0;
209 $leftWidth = ! empty( $value[ 'leftWidth' . $device ] ) ? $value[ 'leftWidth' . $device ] : 0;
210
211 $borderWidth = $topWidth . $widthUnit . ' ' . $rightWidth . $widthUnit . ' ' . $bottomWidth . $widthUnit . ' ' . $leftWidth . $widthUnit;
212
213 $css['border-width'] = $borderWidth;
214 }
215 }
216
217 // Handle border style and color
218 if ( '' !== $value['borderStyle'] && 'default' !== $value['borderStyle'] ) {
219 $css['border-style'] = $value['borderStyle'];
220 }
221 if ( '' !== $value['borderColor'] ) {
222 $css['border-color'] = Color::get_css( $value['borderColor'] );
223 }
224
225 // Separate handling of radius units
226 if ( $device ) {
227 $radiusUnit = self::get_unit([
228 'unit' => $value['unitRadius'],
229 'unitTablet' => $value['unitRadiusTablet'],
230 'unitMobile' => $value['unitRadiusMobile'],
231 ], $device);
232 } else {
233 $radiusUnit = $value['unitRadius'];
234 }
235
236 // Handle radius
237 if ( $value[ 'isLinkedRadius' . $device ] ) {
238 if ( '' !== $value[ 'commonRadius' . $device ] ) {
239 $css['border-radius'] = $value[ 'commonRadius' . $device ] . $radiusUnit;
240 }
241 } else {
242 if ( '' !== $value[ 'topRadius' . $device ] ) {
243 $css['border-top-left-radius'] = $value[ 'topRadius' . $device ] . $radiusUnit;
244 }
245 if ( '' !== $value[ 'rightRadius' . $device ] ) {
246 $css['border-top-right-radius'] = $value[ 'rightRadius' . $device ] . $radiusUnit;
247 }
248 if ( '' !== $value[ 'bottomRadius' . $device ] ) {
249 $css['border-bottom-right-radius'] = $value[ 'bottomRadius' . $device ] . $radiusUnit;
250 }
251 if ( '' !== $value[ 'leftRadius' . $device ] ) {
252 $css['border-bottom-left-radius'] = $value[ 'leftRadius' . $device ] . $radiusUnit;
253 }
254 }
255
256 // Handle transition duration
257 if ( self::has_value( $value['transitionDuration'] ) ) {
258 $css['transition'] = "border {$value['transitionDuration']}s, border-radius {$value['transitionDuration']}s";
259 }
260
261 return $css;
262 }
263
264 public static function get_hover_css( $attribute_value, $property = '', $device = '' ) {
265 $value = wp_parse_args( $attribute_value, self::get_attribute_default_value( true ) ); // avoid Undefined error
266 $css = [];
267
268 // Handle width units based on device
269 $widthUnit = self::get_unit( [
270 'unit' => $value['unitWidthH'],
271 'unitTablet' => $value['unitWidthHTablet'],
272 'unitMobile' => $value['unitWidthHMobile'],
273 ], $device );
274
275 if ( ! empty( $value['borderStyleH'] ) && 'default' !== $value['borderStyleH'] ) {
276 // Handle hover width
277 if ( ! empty( $value[ 'isLinkedWidthH' . $device ] ) ) {
278 if ( '' !== $value[ 'commonWidthH' . $device ] ) {
279 $css['border-width'] = $value[ 'commonWidthH' . $device ] . $widthUnit;
280 }
281 } else {
282 $topWidth = ! empty( $value[ 'topWidthH' . $device ] ) ? $value[ 'topWidthH' . $device ] : 0;
283 $rightWidth = ! empty( $value[ 'rightWidthH' . $device ] ) ? $value[ 'rightWidthH' . $device ] : 0;
284 $bottomWidth = ! empty( $value[ 'bottomWidthH' . $device ] ) ? $value[ 'bottomWidthH' . $device ] : 0;
285 $leftWidth = ! empty( $value[ 'leftWidthH' . $device ] ) ? $value[ 'leftWidthH' . $device ] : 0;
286
287 $css['border-width'] = $topWidth . $widthUnit . ' ' . $rightWidth . $widthUnit . ' ' . $bottomWidth . $widthUnit . ' ' . $leftWidth . $widthUnit;
288 }
289
290 // Handle hover border color
291 if ( ! empty( $value['borderColorH'] ) ) {
292 $css['border-color'] = Color::get_css( $value['borderColorH'] );
293 }
294 }
295
296 // Handle hover border style
297 if ( ! empty( $value['borderStyleH'] ) && 'default' !== $value['borderStyleH'] ) {
298 $css['border-style'] = $value['borderStyleH'];
299 }
300
301 // Handle radius units based on device
302 $radiusUnit = self::get_unit( [
303 'unit' => $value['unitRadiusH'],
304 'unitTablet' => $value['unitRadiusHTablet'],
305 'unitMobile' => $value['unitRadiusHMobile'],
306 ], $device );
307
308 // Handle hover border radius
309 if ( ! empty( $value[ 'isLinkedRadiusH' . $device ] ) ) {
310 if ( '' !== ( $value[ 'commonRadiusH' . $device ] ?? '' ) ) {
311 $css['border-radius'] = $value[ 'commonRadiusH' . $device ] . $radiusUnit;
312 }
313 } else {
314 if ( isset( $value[ 'topRadiusH' . $device ] ) && '' !== $value[ 'topRadiusH' . $device ] ) {
315 $css['border-top-left-radius'] = $value[ 'topRadiusH' . $device ] . $radiusUnit;
316 }
317 if ( isset( $value[ 'rightRadiusH' . $device ] ) && '' !== $value[ 'rightRadiusH' . $device ] ) {
318 $css['border-top-right-radius'] = $value[ 'rightRadiusH' . $device ] . $radiusUnit;
319 }
320 if ( isset( $value[ 'bottomRadiusH' . $device ] ) && '' !== $value[ 'bottomRadiusH' . $device ] ) {
321 $css['border-bottom-right-radius'] = $value[ 'bottomRadiusH' . $device ] . $radiusUnit;
322 }
323 if ( isset( $value[ 'leftRadiusH' . $device ] ) && '' !== $value[ 'leftRadiusH' . $device ] ) {
324 $css['border-bottom-left-radius'] = $value[ 'leftRadiusH' . $device ] . $radiusUnit;
325 }
326 }
327
328 return $css;
329
330 }
331 }
332