PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.0
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 1.2.0 1.2.1 All 78 releases
ablocks / includes / controls / background-overlay.php

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

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