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 / blocks / container / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.0, at includes/blocks/container/block.php

524 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Container;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Classes\CssGeneratorV2;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\BackgroundOverlay;
13 use ABlocks\Controls\Range;
14 use ABlocks\Helper;
15
16 class Block extends BlockBaseAbstract {
17 protected $block_name = 'container';
18
19 public function build_css_v1( $attributes ) {
20 $css_generator = new CssGenerator( $attributes, $this->block_name );
21 $css_generator->add_class_styles(
22 '.ablocks-is-fse-theme {{WRAPPER}}:not(.block-editor-block-list__block).ablocks-block--container--is-root, body:not(.ablocks-is-fse-theme) {{WRAPPER}}:not(.block-editor-block-list__block).ablocks-block--container--is-root',
23 $this->reset_static_css( $attributes ),
24 $this->reset_static_css( $attributes, 'Tablet' ),
25 $this->reset_static_css( $attributes, 'Mobile' ),
26 );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}}.ablocks-block--container',
30 $this->get_main_wrapper_css( $attributes ),
31 $this->get_main_wrapper_css( $attributes, 'Tablet' ),
32 $this->get_main_wrapper_css( $attributes, 'Mobile' )
33 );
34
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} > .ablocks-block-container',
37 $this->get_block_container_css( $attributes ),
38 $this->get_block_container_css( $attributes, 'Tablet' ),
39 $this->get_block_container_css( $attributes, 'Mobile' )
40 );
41
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} > .ablocks-block-container',
44 $this->get_inner_blocks_closest_parent_css( $attributes ),
45 $this->get_inner_blocks_closest_parent_css( $attributes, 'Tablet' ),
46 $this->get_inner_blocks_closest_parent_css( $attributes, 'Mobile' )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} > .ablocks-block-container > *:not(style,.ablocks-block--container)',
50 $this->get_container_inner_blocks_row_column_display_css( $attributes ),
51 $this->get_container_inner_blocks_row_column_display_css( $attributes, 'Tablet' ),
52 $this->get_container_inner_blocks_row_column_display_css( $attributes, 'Mobile' )
53 );
54
55 $css_generator->add_class_styles(
56 '{{WRAPPER}}::before',
57 $this->get_container_before_css( $attributes ),
58 $this->get_container_before_css( $attributes, 'Tablet' ),
59 $this->get_container_before_css( $attributes, 'Mobile' ),
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}}:hover::before',
63 $this->get_container_before_hover_css( $attributes ),
64 $this->get_container_before_hover_css( $attributes, 'Tablet' ),
65 $this->get_container_before_hover_css( $attributes, 'Mobile' ),
66 );
67 $css_generator->add_class_styles(
68 '{{WRAPPER}} .ablocks-block-container >.ablocks-container-shape-bring-to-front',
69 $this->getContainerShapeTopCSS( $attributes ),
70 $this->getContainerShapeTopCSS( $attributes, 'Tablet' ),
71 $this->getContainerShapeTopCSS( $attributes, 'Mobile' ),
72 );
73 $css_generator->add_class_styles(
74 '{{WRAPPER}} .ablocks-block-container >.ablocks-container-shape-bring-to-front',
75 $this->getContainerShapeBottomCSS( $attributes ),
76 $this->getContainerShapeBottomCSS( $attributes, 'Tablet' ),
77 $this->getContainerShapeBottomCSS( $attributes, 'Mobile' ),
78 );
79 $css_generator->add_class_styles(
80 '{{WRAPPER}} .ablocks-shape-top > svg',
81 $this->getContainerShapeTopSvgCSS( $attributes ),
82 $this->getContainerShapeTopSvgCSS( $attributes, 'Tablet' ),
83 $this->getContainerShapeTopSvgCSS( $attributes, 'Mobile' ),
84 );
85 $css_generator->add_class_styles(
86 '{{WRAPPER}} .ablocks-shape-bottom > svg',
87 $this->getContainerShapeBottomSvgCSS( $attributes ),
88 $this->getContainerShapeBottomSvgCSS( $attributes, 'Tablet' ),
89 $this->getContainerShapeBottomSvgCSS( $attributes, 'Mobile' ),
90 );
91
92 return $css_generator->generate_css();
93 }
94
95 public function build_css_v2( $attributes ) {
96 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
97 if ( isset( $attributes['isRootContainer'] ) && (bool) $attributes['isRootContainer'] ) {
98 $css_generator->add_class_styles(
99 '.ablocks-is-fse-theme {{WRAPPER}}.ablocks-block--container--is-root,
100 body:not(.ablocks-is-fse-theme) {{WRAPPER}}.ablocks-block--container--is-root',
101 $this->reset_static_css( $attributes ),
102 $this->reset_static_css( $attributes, 'Tablet' ),
103 $this->reset_static_css( $attributes, 'Mobile' ),
104 );
105 }
106 $css_generator->add_class_styles(
107 '{{WRAPPER}}.ablocks-block--container',
108 $this->get_main_wrapper_css( $attributes ),
109 $this->get_main_wrapper_css( $attributes, 'Tablet' ),
110 $this->get_main_wrapper_css( $attributes, 'Mobile' )
111 );
112
113 // Block Container only available root block
114 $css_generator->add_class_styles(
115 $attributes['isRootContainer'] ? '{{WRAPPER}} > .ablocks-block-container' : '{{WRAPPER}}',
116 $this->get_block_container_css( $attributes ),
117 $this->get_block_container_css( $attributes, 'Tablet' ),
118 $this->get_block_container_css( $attributes, 'Mobile' )
119 );
120
121 $css_generator->add_class_styles(
122 $attributes['isRootContainer'] ? '{{WRAPPER}} > .ablocks-block-container' : '{{WRAPPER}}',
123 $this->get_inner_blocks_closest_parent_css( $attributes ),
124 $this->get_inner_blocks_closest_parent_css( $attributes, 'Tablet' ),
125 $this->get_inner_blocks_closest_parent_css( $attributes, 'Mobile' )
126 );
127 $css_generator->add_class_styles(
128 '{{WRAPPER}}.ablocks-has-block-container > .ablocks-block-container',
129 $this->get_inner_blocks_closest_parent_css( $attributes ),
130 $this->get_inner_blocks_closest_parent_css( $attributes, 'Tablet' ),
131 $this->get_inner_blocks_closest_parent_css( $attributes, 'Mobile' )
132 );
133
134 $css_generator->add_class_styles(
135 $attributes['isRootContainer'] ? '{{WRAPPER}} > .ablocks-block-container > *:not(style,.ablocks-block--container)' : '{{WRAPPER}}',
136 $this->get_container_inner_blocks_row_column_display_css_2( $attributes ),
137 $this->get_container_inner_blocks_row_column_display_css_2( $attributes, 'Tablet' ),
138 $this->get_container_inner_blocks_row_column_display_css_2( $attributes, 'Mobile' )
139 );
140
141 $css_generator->add_class_styles(
142 '{{WRAPPER}}::before',
143 $this->get_container_before_css( $attributes ),
144 $this->get_container_before_css( $attributes, 'Tablet' ),
145 $this->get_container_before_css( $attributes, 'Mobile' ),
146 );
147 $css_generator->add_class_styles(
148 '{{WRAPPER}}:hover::before',
149 $this->get_container_before_hover_css( $attributes ),
150 $this->get_container_before_hover_css( $attributes, 'Tablet' ),
151 $this->get_container_before_hover_css( $attributes, 'Mobile' ),
152 );
153 $css_generator->add_class_styles(
154 '{{WRAPPER}} .ablocks-container-shape-top > svg',
155 $this->getContainerShapeTopSvgCSS( $attributes ),
156 $this->getContainerShapeTopSvgCSS( $attributes, 'Tablet' ),
157 $this->getContainerShapeTopSvgCSS( $attributes, 'Mobile' ),
158 );
159 $css_generator->add_class_styles(
160 '{{WRAPPER}} .ablocks-container-shape-bottom > svg',
161 $this->getContainerShapeBottomSvgCSS( $attributes ),
162 $this->getContainerShapeBottomSvgCSS( $attributes, 'Tablet' ),
163 $this->getContainerShapeBottomSvgCSS( $attributes, 'Mobile' ),
164 );
165
166 $css_generator->add_class_styles(
167 '{{WRAPPER}} .ablocks-container-shape-top',
168 $this->getContainerShapeTopCSS( $attributes ),
169 $this->getContainerShapeTopCSS( $attributes, 'Tablet' ),
170 $this->getContainerShapeTopCSS( $attributes, 'Mobile' ),
171 );
172 $css_generator->add_class_styles(
173 '{{WRAPPER}} .ablocks-container-shape-bottom',
174 $this->getContainerShapeBottomCSS( $attributes ),
175 $this->getContainerShapeBottomCSS( $attributes, 'Tablet' ),
176 $this->getContainerShapeBottomCSS( $attributes, 'Mobile' ),
177 );
178
179 return $css_generator->generate_css();
180 }
181
182 public function build_css( $attributes ) {
183 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
184 return $this->build_css_v2( $attributes );
185 }
186 return $this->build_css_v1( $attributes );
187 }
188
189 public function get_inner_blocks_closest_parent_css( $attributes, $device = '' ) {
190 $css = [
191 'display' => 'flex',
192 ];
193
194 $gridColumn = Range::get_css([
195 'attributeValue' => $attributes['gridColumn'],
196 'attributeObjectKey' => 'value',
197 'isResponsive' => true,
198 'hasUnit' => true,
199 'defaultValue' => 0,
200 'defaultValueTablet' => 2,
201 'defaultValueMobile' => 1,
202 'property' => 'value',
203 'unitDefaultValue' => '',
204 'device' => $device,
205 ]);
206
207 $gridRow = Range::get_css([
208 'attributeValue' => $attributes['gridRow'],
209 'attributeObjectKey' => 'value',
210 'isResponsive' => true,
211 'hasUnit' => true,
212 'defaultValue' => 0,
213 'property' => 'value',
214 'unitDefaultValue' => '',
215 'device' => $device,
216 ]);
217 if ( ( $attributes['layout'] ?? '' ) !== 'grid' ) {
218 $css['display'] = 'flex';
219 if ( ! empty( $attributes[ 'direction' . $device ] ) ) {
220 $css['flex-direction'] = $attributes[ 'direction' . $device ];
221 }
222 if ( ! empty( $attributes[ 'wrap' . $device ] ) ) {
223 $css['flex-wrap'] = $attributes[ 'wrap' . $device ];
224 }
225 } else {
226 $css['display'] = 'grid';
227 if ( ! empty( $gridColumn['value'] ) ) {
228 $css['grid-template-columns'] = 'repeat(' . $gridColumn['value'] . ', 1fr)';
229 }
230 if ( ! empty( $gridRow['value'] ) ) {
231 $css['grid-template-rows'] = 'repeat(' . $gridRow['value'] . ', auto)';
232 }
233 }
234
235 // Set alignment properties
236 if ( ! empty( $attributes[ 'justify' . $device ] ) ) {
237 $css['justify-content'] = $attributes[ 'justify' . $device ];
238 }
239 if ( ! empty( $attributes[ 'align' . $device ] ) ) {
240 $css['align-items'] = $attributes[ 'align' . $device ];
241 }
242
243 // Need to add below code support
244 if ( ! empty( $attributes['dir'][ 'value' . $device ] ) ) {
245 $css['flex-direction'] = $attributes['dir'][ 'value' . $device ];
246 }
247 if ( ! empty( $attributes['justification'][ 'value' . $device ] ) ) {
248 $css['justify-content'] = $attributes['justification'][ 'value' . $device ];
249 }
250 if ( ! empty( $attributes['justification'][ 'value' . $device ] ) ) {
251 $css['justify-items'] = $attributes['justification'][ 'value' . $device ];
252 }
253 if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) {
254 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
255 }
256 if ( ! empty( $attributes['wrapping'][ 'value' . $device ] ) ) {
257 $css['flex-wrap'] = $attributes['wrapping'][ 'value' . $device ];}
258
259 // Merge additional CSS properties safely
260 return array_merge(
261 $css,
262 Range::get_css([
263 'attributeValue' => $attributes['minimumHeight'],
264 'attributeObjectKey' => 'value',
265 'isResponsive' => true,
266 'hasUnit' => true,
267 'defaultValue' => 0,
268 'property' => 'min-height',
269 'unitDefaultValue' => 'px',
270 'device' => $device,
271 ]),
272 Range::get_css([
273 'attributeValue' => $attributes['gap'],
274 'attributeObjectKey' => 'rowGap',
275 'isResponsive' => true,
276 'hasUnit' => true,
277 'defaultValue' => 0,
278 'property' => 'row-gap',
279 'unitDefaultValue' => 'px',
280 'device' => $device,
281 ]),
282 Range::get_css([
283 'attributeValue' => $attributes['gap'],
284 'attributeObjectKey' => 'columnGap',
285 'isResponsive' => true,
286 'hasUnit' => true,
287 'defaultValue' => 0,
288 'property' => 'column-gap',
289 'unitDefaultValue' => 'px',
290 'device' => $device,
291 ])
292 );
293 }
294
295
296
297 public function get_container_inner_blocks_row_column_display_css( $attributes, $device = '' ) {
298 $css = [];
299 if ( ! empty( $attributes['dir'][ 'value' . $device ] ) && ( 'row' === $attributes['dir'][ 'value' . $device ] || 'row-reverse' === $attributes['dir'][ 'value' . $device ] ) ) {
300 $css['display'] = 'inline-block';
301 $css['width'] = 'auto';
302 }
303 return $css;
304 }
305
306 public function get_container_inner_blocks_row_column_display_css_2( $attributes, $device = '' ) {
307 $css = [];
308 if ( ! empty( $attributes['dir'][ 'value' . $device ] ) && ( 'row' === $attributes['dir'][ 'value' . $device ] || 'row-reverse' === $attributes['dir'][ 'value' . $device ] ) ) {
309 $css['display'] = 'inline-flex';
310 // $css['width'] = 'auto';
311 }
312 return $css;
313 }
314
315 public function get_block_container_css( $attributes, $device = '' ) {
316 $css = [];
317 $preparedContentWidth = Range::get_css([
318 'attributeValue' => $attributes['containerContentWidth'],
319 'attributeObjectKey' => 'value',
320 'isResponsive' => true,
321 'hasUnit' => true,
322 'defaultValue' => 1140,
323 'property' => 'value',
324 'unitDefaultValue' => 'px',
325 'device' => $device,
326 ]);
327 $content_box_width_value = $preparedContentWidth['value'] ?? '';
328 if ( empty( $content_box_width_value ) && $device === '' ) {
329 $content_box_width_value = Helper::get_settings( 'default_container_width' ) ?? 1140;
330 }
331 $content_box_width_unit = $preparedContentWidth['valueUnit'] ?? 'px';
332 $is_root_container = isset( $attributes['isRootContainer'] ) ? $attributes['isRootContainer'] : false;
333
334 if ( $is_root_container && $attributes['containerWidthType'] === 'boxed' && ! empty( $content_box_width_value ) ) {
335 $css['max-width'] = "min(100%, {$content_box_width_value}{$content_box_width_unit})";
336 $css['margin-right'] = 'auto !important';
337 $css['margin-left'] = 'auto !important';
338 }
339
340 return $css;
341 }
342
343 public function reset_static_css( $attributes, $device = '' ) {
344 $preparedContainer = Range::get_css([
345 'attributeValue' => $attributes['containerWidth'],
346 'attributeObjectKey' => 'value',
347 'isResponsive' => true,
348 'hasUnit' => true,
349 'defaultValue' => 100,
350 'property' => 'value',
351 'unitDefaultValue' => '%',
352 'device' => '',
353 ]);
354 $css = [];
355 if ( 'custom' === $attributes['containerWidthType'] && ! empty( $preparedContainer['value'] ) ) {
356 $css['margin-left'] = 'auto !important';
357 $css['margin-right'] = 'auto !important';
358 }
359 return $css;
360 }
361 public function get_main_wrapper_css( $attributes, $device = '' ) {
362 $css = [];
363 $prepared_container = Range::get_css([
364 'attributeValue' => $attributes['containerWidth'],
365 'attributeObjectKey' => 'value',
366 'isResponsive' => true,
367 'hasUnit' => true,
368 'defaultValue' => 100,
369 'property' => 'value',
370 'unitDefaultValue' => '%',
371 'device' => $device,
372 ]);
373
374 $is_root_container = isset( $attributes['isRootContainer'] ) ? $attributes['isRootContainer'] : false;
375 if ( ( ! $is_root_container || 'custom' === $attributes['containerWidthType'] ) && ! empty( $prepared_container['value'] ) ) {
376 $css['max-width'] = "min(100%, {$prepared_container['value']}{$prepared_container['valueUnit']}) !important";
377 }
378
379 if ( 'custom' === $attributes['containerWidthType'] && ! empty( $prepared_container['value'] ) && $is_root_container ) {
380 $css['margin-left'] = 'auto !important';
381 $css['margin-right'] = 'auto !important';
382 }
383
384 if ( $is_root_container && 'custom' !== $attributes['containerWidthType'] ) {
385 unset( $css['max-width'] );
386 unset( $css['margin-left'] );
387 unset( $css['margin-right'] );
388 }
389
390 $css['overflow'] = ! empty( $attributes['overflow'] ) ? $attributes['overflow'] : 'visible';
391
392 return array_merge(
393 Dimensions::get_css( $attributes['_padding'], 'padding', $device ),
394 $css
395 );
396 }
397 public static function get_container_before_css( $attributes, $device = '' ) {
398 if ( ! isset( $attributes['_backgroundOverlay']['backgroundOverlayType'] ) || $attributes['_backgroundOverlay']['backgroundOverlayType'] === 'none' ) {
399 return [];
400 }
401 return array_merge(
402 BackgroundOverlay::get_before_css( $attributes['_backgroundOverlay'], $attributes['_border'], 'background', $device ),
403 );
404 }
405 public static function get_container_before_hover_css( $attributes, $device = '' ) {
406 if ( ! isset( $attributes['_backgroundOverlay']['backgroundOverlayTypeH'] ) || $attributes['_backgroundOverlay']['backgroundOverlayTypeH'] === 'none' ) {
407 return [];
408 }
409 return array_merge(
410 BackgroundOverlay::get_before_hover_css( $attributes['_backgroundOverlay'], $attributes['_border'], 'background', $device ),
411 );
412 }
413
414 public function getContainerShapeTopCSS( $attributes, $device = '' ) {
415 $css = [];
416
417 if ( ! empty( $attributes['topShapeBringToFront'] ) &&
418 $attributes['shapeTop'] !== '' ) {
419 $css['z-index'] = 1;
420 $css['position'] = 'absolute';
421 }
422 return $css;
423 }
424
425 public function getContainerShapeBottomCSS( $attributes, $device = '' ) {
426 $css = [];
427
428 if ( ! empty( $attributes['bottomShapeBringToFront'] ) &&
429 $attributes['shapeBottom'] !== '' ) {
430 $css['z-index'] = 1;
431 $css['position'] = 'absolute';
432 }
433 return $css;
434 }
435
436 public function getContainerShapeTopSvgCSS( $attributes, $device = '' ) {
437 $css = [];
438
439 if ( empty( $attributes['shapeTop'] ) ) {
440 return [];
441 }
442
443 if ( ! empty( $attributes['shapeTopColor'] ) ) {
444 $css['fill'] = $attributes['shapeTopColor'];
445 }
446 $topShapeFlip = isset( $attributes['topShapeFlip'] ) ? $attributes['topShapeFlip'] : false;
447 $shapeTop = isset( $attributes['shapeTop'] ) ? $attributes['shapeTop'] : '';
448
449 if ( $topShapeFlip && $shapeTop !== '' ) {
450 $css['transform'] = 'translateX(0%) rotateY(180deg)';
451 } else {
452 $css['transform'] = 'translateX(0%)';
453 }
454
455 return array_merge(
456 Range::get_css([
457 'attributeValue' => $attributes['shapeTopHeight'],
458 'attribute_object_key' => 'value',
459 'isResponsive' => true,
460 'defaultValue' => 100,
461 'hasUnit' => true,
462 'unitDefaultValue' => 'px',
463 'property' => 'height',
464 'device' => $device,
465 ]),
466 Range::get_css([
467 'attributeValue' => $attributes['shapeTopWidth'],
468 'attribute_object_key' => 'value',
469 'isResponsive' => true,
470 'defaultValue' => 100,
471 'hasUnit' => true,
472 'unitDefaultValue' => '%',
473 'property' => 'width',
474 'device' => $device,
475 ]),
476 $css,
477 );
478 }
479
480 public function getContainerShapeBottomSvgCSS( $attributes, $device = '' ) {
481 $css = [];
482
483 if ( empty( $attributes['shapeBottom'] ) ) {
484 return [];
485 }
486
487 if ( ! empty( $attributes['shapeBottomColor'] ) ) {
488 $css['fill'] = $attributes['shapeBottomColor'];
489 }
490
491 $bottomShapeFlip = isset( $attributes['bottomShapeFlip'] ) ? $attributes['bottomShapeFlip'] : false;
492 $shapeBottom = isset( $attributes['shapeBottom'] ) ? $attributes['shapeBottom'] : '';
493
494 if ( $bottomShapeFlip && $shapeBottom !== '' ) {
495 $css['transform'] = 'translateX(0%) rotateY(180deg)';
496 } else {
497 $css['transform'] = 'translateX(0%)';
498 }
499 return array_merge(
500 Range::get_css([
501 'attributeValue' => $attributes['shapeBottomHeight'],
502 'attribute_object_key' => 'value',
503 'isResponsive' => true,
504 'defaultValue' => 100,
505 'hasUnit' => true,
506 'unitDefaultValue' => 'px',
507 'property' => 'height',
508 'device' => $device,
509 ]),
510 Range::get_css([
511 'attributeValue' => $attributes['shapeBottomWidth'],
512 'attribute_object_key' => 'value',
513 'isResponsive' => true,
514 'defaultValue' => 100,
515 'hasUnit' => true,
516 'unitDefaultValue' => '%',
517 'property' => 'width',
518 'device' => $device,
519 ]),
520 $css,
521 );
522 }
523 }
524