PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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.9.1, at includes/controls/border.php

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