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 / background-overlay.php

background-overlay.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/controls/background-overlay.php

530 lines 17.9 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 BackgroundOverlay extends ControlBaseAbstract {
11
12 public static function get_attribute_default_value( $is_responsive = false ) {
13 return [
14 'backgroundOverlayType' => 'none',
15 'backgroundOverlayTypeH' => 'none',
16 // Normal background image attribute
17 'imgId' => '',
18 'imgIdTablet' => '',
19 'imgIdMobile' => '',
20 'imgUrl' => '',
21 'imgUrlTablet' => '',
22 'imgUrlMobile' => '',
23 'imgSize' => '',
24 'imgSizeTablet' => '',
25 'imgSizeMobile' => '',
26 'imgPosition' => '',
27 'imgPositionTablet' => '',
28 'imgPositionMobile' => '',
29 'imgXPositionUnit' => 'px',
30 'imgXPositionUnitTablet' => 'px',
31 'imgXPositionUnitMobile' => 'px',
32 'imgXPositionTabletUnit' => '',
33 'imgXPositionMobileUnit' => '',
34 'imgXPosition' => '',
35 'imgXPositionTablet' => '',
36 'imgXPositionMobile' => '',
37 'imgYPositionUnit' => 'px',
38 'imgYPositionUnitTablet' => '',
39 'imgYPositionUnitMobile' => '',
40 'imgYPosition' => '',
41 'imgYPositionTablet' => '',
42 'imgYPositionMobile' => '',
43 'imgAttachment' => '',
44 'imgRepeat' => '',
45 'imgRepeatTablet' => '',
46 'imgRepeatMobile' => '',
47 'imgDisplaySize' => '',
48 'imgDisplaySizeTablet' => '',
49 'imgDisplaySizeMobile' => '',
50 'imgDisplaySizeWidth' => '',
51 'imgDisplaySizeWidthTablet' => '',
52 'imgDisplaySizeWidthMobile' => '',
53 'imgDisplaySizeWidthUnit' => 'px',
54 'imgDisplaySizeWidthUnitTablet' => '',
55 'imgDisplaySizeWidthUnitMobile' => '',
56 // Hover background image attribute
57 'imgIdH' => '',
58 'imgIdTabletH' => '',
59 'imgIdMobileH' => '',
60 'imgUrlH' => '',
61 'imgUrlHTablet' => '',
62 'imgUrlHMobile' => '',
63 'imgSizeH' => '',
64 'imgSizeHTablet' => '',
65 'imgSizeHMobile' => '',
66 'imgPositionH' => '',
67 'imgPositionHTablet' => '',
68 'imgPositionHMobile' => '',
69 'imgXPositionUnitH' => 'px',
70 'imgXPositionUnitHTablet' => '',
71 'imgXPositionUnitHMobile' => '',
72 'imgXPositionH' => '',
73 'imgXPositionHTablet' => '',
74 'imgXPositionHMobile' => '',
75 'imgYPositionUnitH' => 'px',
76 'imgYPositionUnitHTablet' => '',
77 'imgYPositionUnitHMobile' => '',
78 'imgYPositionH' => '',
79 'imgYPositionHTablet' => '',
80 'imgYPositionHMobile' => '',
81 'imgAttachmentH' => '',
82 'imgRepeatH' => '',
83 'imgRepeatHTablet' => '',
84 'imgRepeatHMobile' => '',
85 'imgDisplaySizeH' => '',
86 'imgDisplaySizeHTablet' => '',
87 'imgDisplaySizeHMobile' => '',
88 'imgDisplaySizeWidthH' => '',
89 'imgDisplaySizeWidthHTablet' => '',
90 'imgDisplaySizeWidthHMobile' => '',
91 'imgDisplaySizeWidthHUnit' => 'px',
92 'imgDisplaySizeWidthHUnitTablet' => '',
93 'imgDisplaySizeWidthHUnitMobile' => '',
94
95 'blendMode' => '',
96 'blur' => '',
97 'brightness' => '',
98 'contrast' => '',
99 'saturate' => '',
100 'hue' => '',
101 'opacity' => '',
102 'opacityTablet' => '',
103 'opacityMobile' => '',
104 // HOVER
105 'blendModeH' => '',
106 'blurH' => '',
107 'brightnessH' => '',
108 'contrastH' => '',
109 'saturateH' => '',
110 'hueH' => '',
111 'opacityH' => '',
112 'opacityHTablet' => '',
113 'opacityHMobile' => '',
114
115 'transitionDuration' => '',
116 ];
117 }
118
119 public static function get_attribute(
120 $attribute_name,
121 $is_responsive = false
122 ) {
123 $default_value = self::get_attribute_default_value( $is_responsive );
124
125 return [
126 $attribute_name => [
127 'type' => 'object',
128 'default' => $default_value,
129 ],
130 ];
131 }
132
133 public static function get_css(
134 $attribute_value,
135 $property = '',
136 $device = ''
137 ) {
138 }
139
140 public static function get_before_css(
141 $attribute_value,
142 $extra_border_value,
143 $property = '',
144 $device = ''
145 ) {
146 // Merge default values with the provided attribute values
147 $value = array_merge(
148 self::get_attribute_default_value( $device ? true : false ),
149 $attribute_value
150 );
151
152 // Get the units for X and Y position, and display size width
153 $unitX_position_unit = self::get_unit(
154 [
155 'unit' => $value['imgXPositionUnit'],
156 'unitTablet' => $value['imgXPositionUnitTablet'],
157 'unitMobile' => $value['imgXPositionUnitMobile'],
158 ],
159 $device
160 );
161
162 $unitY_position_unit = self::get_unit(
163 [
164 'unit' => $value['imgYPositionUnit'],
165 'unitTablet' => $value['imgYPositionUnitTablet'],
166 'unitMobile' => $value['imgYPositionUnitMobile'],
167 ],
168 $device
169 );
170
171 $display_size_width_unit = self::get_unit(
172 [
173 'unit' => $value['imgDisplaySizeWidthUnit'],
174 'unitTablet' => $value['imgDisplaySizeWidthUnitTablet'],
175 'unitMobile' => $value['imgDisplaySizeWidthUnitMobile'],
176 ],
177 $device
178 );
179
180 $css = [];
181
182 $topDiff = ! empty( $extra_border_value['commonWidth'] ) ? intval( $extra_border_value['commonWidth'] ) : intval( $extra_border_value['topWidth'] ?? 0 );
183 $bottomDiff = ! empty( $extra_border_value['commonWidth'] ) ? intval( $extra_border_value['commonWidth'] ) : intval( $extra_border_value['bottomWidth'] ?? 0 );
184 $leftDiff = ! empty( $extra_border_value['commonWidth'] ) ? intval( $extra_border_value['commonWidth'] ) : intval( $extra_border_value['leftWidth'] ?? 0 );
185 $rightDiff = ! empty( $extra_border_value['commonWidth'] ) ? intval( $extra_border_value['commonWidth'] ) : intval( $extra_border_value['rightWidth'] ?? 0 );
186
187 // Radius calculations
188 $topRadiusValue = ! empty( $extra_border_value['commonRadius'] ) ? intval( $extra_border_value['commonRadius'] ) : intval( $extra_border_value['topRadius'] ?? 0 );
189 $leftRadiusValue = ! empty( $extra_border_value['commonRadius'] ) ? intval( $extra_border_value['commonRadius'] ) : intval( $extra_border_value['leftRadius'] ?? 0 );
190 $rightRadiusValue = ! empty( $extra_border_value['commonRadius'] ) ? intval( $extra_border_value['commonRadius'] ) : intval( $extra_border_value['rightRadius'] ?? 0 );
191 $bottomRadiusValue = ! empty( $extra_border_value['commonRadius'] ) ? intval( $extra_border_value['commonRadius'] ) : intval( $extra_border_value['bottomRadius'] ?? 0 );
192
193 // Ensure no negative values
194 $css['border-top-left-radius'] = max( $topRadiusValue - $topDiff, 0 ) . 'px';
195 $css['border-top-right-radius'] = max( $rightRadiusValue - $rightDiff, 0 ) . 'px';
196 $css['border-bottom-left-radius'] = max( $bottomRadiusValue - $bottomDiff, 0 ) . 'px';
197 $css['border-bottom-right-radius'] = max( $leftRadiusValue - $leftDiff, 0 ) . 'px';
198
199 // Handle transition duration
200 if ( self::has_value( $value['transitionDuration'] ) ) {
201 $css['transition'] = "border {$value['transitionDuration']}s, border-radius {$value['transitionDuration']}s";
202 }
203
204 // If background is set to image
205 if ( $value['backgroundOverlayType'] === 'image' ) {
206 $img_url_key = 'imgUrl' . $device;
207 if ( ! empty( $value[ $img_url_key ] ) ) {
208 $filter_values = [
209 'brightness' =>
210 'brightness(' . ( $value['brightness'] ?? 100 ) . '%)',
211 'contrast' =>
212 'contrast(' . ( $value['contrast'] ?? 100 ) . '%)',
213 'saturate' =>
214 'saturate(' . ( $value['saturate'] ?? 100 ) . '%)',
215 'blur' => 'blur(' . ( $value['blur'] ?? 0 ) . 'px)',
216 'hue' => 'hue-rotate(' . ( $value['hue'] ?? 0 ) . 'deg)',
217 ];
218
219 // CSS for background image and ::before pseudo element
220 $css[ "{$property}-image" ] =
221 'url("' . $value[ $img_url_key ] . '")';
222 $css['position'] = 'absolute';
223 $css['content'] = "''";
224 $css['top'] = '0';
225 $css['left'] = '0';
226 $css['width'] = '100%';
227 $css['height'] = '100%';
228
229 // Handle background-position
230 $img_position_key = 'imgPosition' . $device;
231 if ( ! empty( $value[ $img_position_key ] ) ) {
232 if ( $value[ $img_position_key ] === 'custom' ) {
233 $css[ "{$property}-position" ] =
234 ( $value[ 'imgXPosition' . $device ] ?? '0' ) .
235 $unitX_position_unit .
236 ' ' .
237 ( $value[ 'imgYPosition' . $device ] ?? '0' ) .
238 $unitY_position_unit;
239 } else {
240 $css[ "{$property}-position" ] =
241 $value[ $img_position_key ];
242 }
243 }
244
245 // Handle background attachment
246 $img_attachment_key = 'imgAttachment' . $device;
247 if ( ! empty( $value[ $img_attachment_key ] ) ) {
248 $css[ "{$property}-attachment" ] =
249 $value[ $img_attachment_key ];
250 }
251
252 // Handle background repeat
253 $img_repeat_key = 'imgRepeat' . $device;
254 if ( ! empty( $value[ $img_repeat_key ] ) ) {
255 $css[ "{$property}-repeat" ] = $value[ $img_repeat_key ];
256 }
257
258 // Handle background size
259 $img_display_size_key = 'imgDisplaySize' . $device;
260 if ( ! empty( $value[ $img_display_size_key ] ) ) {
261 if ( $value[ $img_display_size_key ] === 'custom' ) {
262 $css[ "{$property}-size" ] =
263 $value[ 'imgDisplaySizeWidth' . $device ] .
264 $display_size_width_unit;
265 } else {
266 $css[ "{$property}-size" ] =
267 $value[ $img_display_size_key ];
268 }
269 }
270
271 // Handle opacity
272 if ( $device === 'Tablet' && isset( $value['opacityTablet'] ) ) {
273 $css['opacity'] = $value['opacityTablet'];
274 } elseif ( $device === 'Mobile' && isset( $value['opacityMobile'] ) ) {
275 $css['opacity'] = $value['opacityMobile'];
276 } elseif ( isset( $value['opacity'] ) ) {
277 $css['opacity'] = $value['opacity'];
278 }
279
280 // Handle blend mode
281 if ( ! empty( $value['blendMode'] ) ) {
282 $css['mix-blend-mode'] = $value['blendMode'];
283 }
284
285 // Add filter CSS
286 $css['filter'] = implode( ' ', $filter_values );
287
288 // Handle transition duration
289 if ( ! empty( $value['transitionDuration'] ) ) {
290 $css['transition'] =
291 'all ' . $value['transitionDuration'] . 's';
292 }
293 }//end if
294 } elseif ( $value['backgroundOverlayType'] === 'color' ) {
295 $background_color_key = 'backgroundColor' . $device;
296 if ( ! empty( $value[ $background_color_key ] ) ) {
297 $css['position'] = 'absolute';
298 $css['content'] = "''";
299 $css['top'] = '0';
300 $css['left'] = '0';
301 $css['width'] = '100%';
302 $css['height'] = '100%';
303 $css[ $property ] = $value[ $background_color_key ];
304
305 // Handle opacity
306
307 if ( $device === 'Tablet' && isset( $value['opacityTablet'] ) ) {
308 $css['opacity'] = $value['opacityTablet'];
309 } elseif ( $device === 'Mobile' && isset( $value['opacityMobile'] ) ) {
310 $css['opacity'] = $value['opacityMobile'];
311 } elseif ( isset( $value['opacity'] ) ) {
312 $css['opacity'] = $value['opacity'];
313 }
314
315 // Handle blend mode
316 if ( ! empty( $value['blendMode'] ) ) {
317 $css['mix-blend-mode'] = $value['blendMode'];
318 }
319
320 // Add filter CSS
321 $filter_values = [
322 'brightness' =>
323 'brightness(' . ( $value['brightness'] ?? 100 ) . '%)',
324 'contrast' =>
325 'contrast(' . ( $value['contrast'] ?? 100 ) . '%)',
326 'saturate' =>
327 'saturate(' . ( $value['saturate'] ?? 100 ) . '%)',
328 'blur' => 'blur(' . ( $value['blur'] ?? 0 ) . 'px)',
329 'hue' => 'hue-rotate(' . ( $value['hue'] ?? 0 ) . 'deg)',
330 ];
331 $css['filter'] = implode( ' ', $filter_values );
332
333 // Handle transition duration
334 if ( ! empty( $value['transitionDuration'] ) ) {
335 $css['transition'] =
336 'all ' . $value['transitionDuration'] . 's';
337 }
338 }//end if
339 }//end if
340
341 return $css;
342 }
343
344 public static function get_before_hover_css(
345 $attribute_value,
346 $extra_border_value,
347 $property = '',
348 $device = ''
349 ) {
350 // Merge default values with the provided attribute values
351 $value = array_merge(
352 self::get_attribute_default_value( $device ? true : false ),
353 $attribute_value
354 );
355 // Get the units for X and Y position hover states and display size hover width
356 $unit_x_position_unit_h = self::get_unit(
357 [
358 'unit' => $value['imgXPositionUnitH'],
359 'unitTablet' => $value['imgXPositionUnitHTablet'],
360 'unitMobile' => $value['imgXPositionUnitHMobile'],
361 ],
362 $device
363 );
364
365 $unit_y_position_unit_h = self::get_unit(
366 [
367 'unit' => $value['imgYPositionUnitH'],
368 'unitTablet' => $value['imgYPositionUnitHTablet'],
369 'unitMobile' => $value['imgYPositionUnitHMobile'],
370 ],
371 $device
372 );
373
374 $img_display_size_width_h_unit = self::get_unit(
375 [
376 'unit' => $value['imgDisplaySizeWidthHUnit'],
377 'unitTablet' => $value['imgDisplaySizeWidthHUnitTablet'],
378 'unitMobile' => $value['imgDisplaySizeWidthHMobile'],
379 ],
380 $device
381 );
382
383 $css = [];
384 $topDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['topWidth'] ?? 0 );
385 $bottomDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['bottomWidth'] ?? 0 );
386 $leftDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['leftWidth'] ?? 0 );
387 $rightDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['rightWidth'] ?? 0 );
388
389 // Radius calculations
390 $topRadiusValueH = ! empty( $extra_border_value['commonRadiusH'] ) ? intval( $extra_border_value['commonRadiusH'] ) : intval( $extra_border_value['topRadius'] ?? 0 );
391 $leftRadiusValueH = ! empty( $extra_border_value['commonRadiusH'] ) ? intval( $extra_border_value['commonRadiusH'] ) : intval( $extra_border_value['leftRadius'] ?? 0 );
392 $rightRadiusValueH = ! empty( $extra_border_value['commonRadiusH'] ) ? intval( $extra_border_value['commonRadiusH'] ) : intval( $extra_border_value['rightRadius'] ?? 0 );
393 $bottomRadiusValueH = ! empty( $extra_border_value['commonRadiusH'] ) ? intval( $extra_border_value['commonRadiusH'] ) : intval( $extra_border_value['bottomRadius'] ?? 0 );
394
395 // Ensure no negative values
396 $css['border-top-left-radius'] = max( $topRadiusValueH - $topDiffH, 0 ) . 'px';
397 $css['border-top-right-radius'] = max( $rightRadiusValueH - $rightDiffH, 0 ) . 'px';
398 $css['border-bottom-left-radius'] = max( $bottomRadiusValueH - $bottomDiffH, 0 ) . 'px';
399 $css['border-bottom-right-radius'] = max( $leftRadiusValueH - $leftDiffH, 0 ) . 'px';
400
401 // If hover background is set to image
402 if ( $value['backgroundOverlayTypeH'] === 'image' ) {
403 $img_url_h_key = 'imgUrlH' . $device;
404
405 if ( ! empty( $value[ $img_url_h_key ] ) ) {
406 $filter_values_h = [
407 'brightness' =>
408 'brightness(' . ( $value['brightnessH'] ?? 100 ) . '%)',
409 'contrast' =>
410 'contrast(' . ( $value['contrastH'] ?? 100 ) . '%)',
411 'saturate' =>
412 'saturate(' . ( $value['saturateH'] ?? 100 ) . '%)',
413 'blur' => 'blur(' . ( $value['blurH'] ?? 0 ) . 'px)',
414 'hue' => 'hue-rotate(' . ( $value['hueH'] ?? 0 ) . 'deg)',
415 ];
416
417 // CSS for background image and ::before pseudo element on hover
418 $css[ "{$property}-image" ] =
419 'url("' . esc_url( $value[ $img_url_h_key ] ) . '")';
420 $css['position'] = 'absolute';
421 $css['content'] = "''";
422 $css['top'] = '0';
423 $css['left'] = '0';
424 $css['width'] = '100%';
425 $css['height'] = '100%';
426
427 // Handle background-position on hover
428 $img_position_h_key = 'imgPositionH' . $device;
429 if ( ! empty( $value[ $img_position_h_key ] ) ) {
430 if ( $value[ $img_position_h_key ] === 'custom' ) {
431 $css[ "{$property}-position" ] =
432 ( $value[ 'imgXPositionH' . $device ] ?? '0' ) .
433 $unit_x_position_unit_h .
434 ' ' .
435 ( $value[ 'imgYPositionH' . $device ] ?? '0' ) .
436 $unit_y_position_unit_h;
437 } else {
438 $css[ "{$property}-position" ] = esc_attr(
439 $value[ $img_position_h_key ]
440 );
441 }
442 }
443
444 // Handle background attachment on hover
445 if ( ! empty( $value['imgAttachmentH'] ) ) {
446 $css[ "{$property}-attachment" ] = esc_attr(
447 $value['imgAttachmentH']
448 );
449 }
450
451 // Handle background repeat on hover
452 if ( ! empty( $value[ 'imgRepeatH' . $device ] ) ) {
453 $css[ "{$property}-repeat" ] = esc_attr(
454 $value[ 'imgRepeatH' . $device ]
455 );
456 }
457
458 // Handle background size on hover
459 $img_display_size_h_key = 'imgDisplaySizeH' . $device;
460 if ( ! empty( $value[ $img_display_size_h_key ] ) ) {
461 if ( $value[ $img_display_size_h_key ] === 'custom' ) {
462 $css[ "{$property}-size" ] =
463 esc_attr( $value[ 'imgDisplaySizeWidthH' . $device ] ) .
464 esc_attr( $img_display_size_width_h_unit );
465 } else {
466 $css[ "{$property}-size" ] = esc_attr(
467 $value[ $img_display_size_h_key ]
468 );
469 }
470 }
471 // Handle opacity on hover
472 if ( $device === 'Tablet' && isset( $value['opacityHTablet'] ) ) {
473 $css['opacity'] = $value['opacityHTablet'];
474 } elseif ( $device === 'Mobile' && isset( $value['opacityHMobile'] ) ) {
475 $css['opacity'] = $value['opacityHMobile'];
476 } elseif ( isset( $value['opacityH'] ) ) {
477 $css['opacity'] = $value['opacityH'];
478 }
479 // Handle blend mode on hover
480 if ( ! empty( $value['blendModeH'] ) ) {
481 $css['mix-blend-mode'] = esc_attr( $value['blendModeH'] );
482 }
483
484 // Add filter CSS on hover
485 $css['filter'] = implode( ' ', $filter_values_h );
486 }//end if
487 } elseif ( $value['backgroundOverlayTypeH'] === 'color' ) {
488 // If hover background is set to color
489 $background_color_h_key = 'backgroundColorH' . $device;
490 if ( ! empty( $value[ $background_color_h_key ] ) ) {
491 $css['position'] = 'absolute';
492 $css['content'] = "''";
493 $css['top'] = '0';
494 $css['left'] = '0';
495 $css['width'] = '100%';
496 $css['height'] = '100%';
497 $css[ $property ] = esc_attr( $value[ $background_color_h_key ] );
498
499 if ( $device === 'Tablet' && isset( $value['opacityHTablet'] ) ) {
500 $css['opacity'] = $value['opacityHTablet'];
501 } elseif ( $device === 'Mobile' && isset( $value['opacityHMobile'] ) ) {
502 $css['opacity'] = $value['opacityHMobile'];
503 } elseif ( isset( $value['opacityH'] ) ) {
504 $css['opacity'] = $value['opacityH'];
505 }
506
507 // Handle blend mode on hover
508 if ( ! empty( $value['blendModeH'] ) ) {
509 $css['mix-blend-mode'] = esc_attr( $value['blendModeH'] );
510 }
511
512 // Add filter CSS on hover
513 $filter_values_h = [
514 'brightness' =>
515 'brightness(' . ( $value['brightnessH'] ?? 100 ) . '%)',
516 'contrast' =>
517 'contrast(' . ( $value['contrastH'] ?? 100 ) . '%)',
518 'saturate' =>
519 'saturate(' . ( $value['saturateH'] ?? 100 ) . '%)',
520 'blur' => 'blur(' . ( $value['blurH'] ?? 0 ) . 'px)',
521 'hue' => 'hue-rotate(' . ( $value['hueH'] ?? 0 ) . 'deg)',
522 ];
523 $css['filter'] = implode( ' ', $filter_values_h );
524 }//end if
525 }//end if
526
527 return $css;
528 }
529 }
530