PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 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 All 81 releases
ablocks / includes / blocks / lists / block.php

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

384 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\lists;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Alignment;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Width;
14 use ABlocks\Controls\Border;
15 use ABlocks\Classes\CssGeneratorV2;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\Color;
18
19 class Block extends BlockBaseAbstract {
20
21 protected $block_name = 'lists';
22
23 public function build_css_v1( $attributes ) {
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25 // Wrapper CSS
26 $css_generator->add_class_styles(
27 '{{WRAPPER}}',
28 $this->get_wrapper_css( $attributes, '' ),
29 $this->get_wrapper_css( $attributes, 'Tablet' ),
30 $this->get_wrapper_css( $attributes, 'Mobile' ),
31 );
32 // List CSS
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ablocks-list',
35 $this->get_list_css( $attributes, '' ),
36 $this->get_list_css( $attributes, 'Tablet' ),
37 $this->get_list_css( $attributes, 'Mobile' ),
38 );
39 // List Wrapper CSS
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ablocks-list__item-content',
42 $this->get_list_wrapper_css( $attributes, '' ),
43 $this->get_list_wrapper_css( $attributes, 'Tablet' ),
44 $this->get_list_wrapper_css( $attributes, 'Mobile' ),
45 );
46
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-list_item-content-divider',
49 $this->get_Divider_Wrapper_css( $attributes, '' ),
50 $this->get_Divider_Wrapper_css( $attributes, 'Tablet' ),
51 $this->get_Divider_Wrapper_css( $attributes, 'Mobile' ),
52 );
53 // Marker CSS
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-marker',
56 $this->get_marker_css( $attributes, '' ),
57 $this->get_marker_css( $attributes, 'Tablet' ),
58 $this->get_marker_css( $attributes, 'Mobile' ),
59 );
60 // Icon CSS
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon',
63 $this->get_icon_css( $attributes, '' ),
64 $this->get_icon_css( $attributes, 'Tablet' ),
65 $this->get_icon_css( $attributes, 'Mobile' ),
66 );
67 // Icon hover css
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon:hover',
70 $this->get_icon_hover_css( $attributes, '' ),
71 $this->get_icon_hover_css( $attributes, 'Tablet' ),
72 $this->get_icon_hover_css( $attributes, 'Mobile' ),
73 );
74
75 // List text CSS
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-text',
78 $this->get_list_text_css( $attributes ),
79 $this->get_list_text_css( $attributes, 'Tablet' ),
80 $this->get_list_text_css( $attributes, 'Mobile' ),
81 );
82
83 return $css_generator->generate_css();
84 }
85 public function build_css_v2( $attributes ) {
86 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
87 // Wrapper CSS
88 $css_generator->add_class_styles(
89 '{{WRAPPER}}',
90 $this->get_wrapper_css( $attributes, '' ),
91 $this->get_wrapper_css( $attributes, 'Tablet' ),
92 $this->get_wrapper_css( $attributes, 'Mobile' ),
93 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
94 );
95 // List CSS
96 $css_generator->add_class_styles(
97 '{{WRAPPER}} .ablocks-list',
98 $this->get_list_css( $attributes, '' ),
99 $this->get_list_css( $attributes, 'Tablet' ),
100 $this->get_list_css( $attributes, 'Mobile' ),
101 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_css( $attributes, $device ); } )
102 );
103 // List Wrapper CSS
104 $css_generator->add_class_styles(
105 '{{WRAPPER}} .ablocks-list__item-content',
106 $this->get_list_wrapper_css( $attributes, '' ),
107 $this->get_list_wrapper_css( $attributes, 'Tablet' ),
108 $this->get_list_wrapper_css( $attributes, 'Mobile' ),
109 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_wrapper_css( $attributes, $device ); } )
110 );
111
112 $css_generator->add_class_styles(
113 '{{WRAPPER}} .ablocks-list_item-content-divider',
114 $this->get_Divider_Wrapper_css( $attributes, '' ),
115 $this->get_Divider_Wrapper_css( $attributes, 'Tablet' ),
116 $this->get_Divider_Wrapper_css( $attributes, 'Mobile' ),
117 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_Divider_Wrapper_css( $attributes, $device ); } )
118 );
119 // Marker CSS
120 $css_generator->add_class_styles(
121 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-marker',
122 $this->get_marker_css( $attributes, '' ),
123 $this->get_marker_css( $attributes, 'Tablet' ),
124 $this->get_marker_css( $attributes, 'Mobile' ),
125 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_marker_css( $attributes, $device ); } )
126 );
127 // Icon CSS
128 $css_generator->add_class_styles(
129 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon',
130 $this->get_icon_css( $attributes, '' ),
131 $this->get_icon_css( $attributes, 'Tablet' ),
132 $this->get_icon_css( $attributes, 'Mobile' ),
133 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_css( $attributes, $device ); } )
134 );
135 // Icon hover css
136 $css_generator->add_class_styles(
137 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon:hover',
138 $this->get_icon_hover_css( $attributes, '' ),
139 $this->get_icon_hover_css( $attributes, 'Tablet' ),
140 $this->get_icon_hover_css( $attributes, 'Mobile' ),
141 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_hover_css( $attributes, $device ); } )
142 );
143
144 // List text CSS
145 $css_generator->add_class_styles(
146 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-text',
147 $this->get_list_text_css( $attributes ),
148 $this->get_list_text_css( $attributes, 'Tablet' ),
149 $this->get_list_text_css( $attributes, 'Mobile' ),
150 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_text_css( $attributes, $device ); } )
151 );
152
153 return $css_generator->generate_css();
154 }
155 public function build_css( $attributes ) {
156 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
157 return $this->build_css_v2( $attributes );
158 }
159 return $this->build_css_v1( $attributes );
160 }
161 public function get_wrapper_css( $attributes, $device = '' ) {
162 $typography = isset( $attributes['typography'] ) ? $attributes['typography'] : '';
163 $alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : '';
164 $typographyglobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
165 return array_merge(
166 Alignment::get_css( $alignment, 'text-align', $device ),
167 Typography::get_css( $typography, '', $device, $typographyglobal ),
168 );
169 }
170
171 public function get_list_css( $attributes, $device = '' ) {
172 $css = [];
173
174 if ( isset( $attributes['spaceBetween'][ 'value' . $device ] ) && ! empty( $attributes['spaceBetween'][ 'value' . $device ] ) ) {
175 $css['gap'] = $attributes['spaceBetween'][ 'value' . $device ] . 'px';
176 }
177
178 $stack = $attributes[ 'stack' . $device ] ?? $attributes['stack'] ?? '';
179 if ( $stack === 'vertical' ) {
180 $css['flex-direction'] = 'column';
181 $vertical_alignment = $attributes[ 'verticalAlignment' . $device ] ?? $attributes['verticalAlignment'] ?? '';
182 if ( ! empty( $vertical_alignment ) ) {
183 $css['align-items'] = $vertical_alignment;
184 }
185 } elseif ( $stack === 'horizontal' ) {
186 $css['flex-direction'] = 'row';
187 $horizontal_alignment = $attributes[ 'horizontalAlignment' . $device ] ?? $attributes['horizontalAlignment'] ?? '';
188 if ( ! empty( $horizontal_alignment ) ) {
189 $css['justify-content'] = $horizontal_alignment;
190 }
191 }
192
193 $width_css = isset( $attributes[ 'width' . $device ] )
194 ? Width::get_css( $attributes[ 'width' . $device ], 'width', $device )
195 : [];
196
197 $css = array_merge(
198 $css,
199 $width_css,
200 isset( $attributes['horizontalAlignment'] )
201 ? Alignment::get_css( $attributes['horizontalAlignment'], 'justify-content', $device )
202 : []
203 );
204 foreach ( $css as $property => $value ) {
205 if ( is_array( $value ) ) {
206 unset( $css[ $property ] );
207 }
208 }
209 return $css;
210 }
211
212 public function get_list_wrapper_css( $attributes, $device = '' ) {
213 $css = [];
214 $marker_type = $attributes['markerType'] ?? '';
215 $text_indent = $attributes['textIndent'][ 'value' . $device ] ?? '';
216 if ( $marker_type && 'icon' === $marker_type ) {
217 if ( ! empty( $attributes['position'][ 'value' . $device ] ) ) {
218 $css['align-items'] = $attributes['position'][ 'value' . $device ];
219 }
220 }
221 if ( $text_indent && ! empty( $text_indent ) ) {
222 $css['gap'] = $text_indent . 'px';
223 }
224
225 return $css;
226 }
227
228 public function get_divider_wrapper_css( $attributes, $device = '' ) {
229 $css = [];
230 $width_css = [];
231 $weight_css = [];
232
233 if ( isset( $attributes['divider'] ) && ! empty( $attributes['divider'] ) ) {
234 $border_color = Color::get_css(
235 isset( $attributes['borderColor'] ) ? $attributes['borderColor'] : 'black');
236 $divider_pattern_url = isset( $attributes['dividerPatternUrl'] ) ? $attributes['dividerPatternUrl'] : '';
237 $stack = isset( $attributes['stack'] ) ? $attributes['stack'] : '';
238
239 if ( ! empty( $divider_pattern_url ) ) {
240 if ( $stack === 'vertical' ) {
241 $css['border-bottom-color'] = $border_color;
242 $css['border-bottom-style'] = $divider_pattern_url;
243 $weight_css = Range::get_css([
244 'attributeValue' => $attributes['weight'],
245 'attribute_object_key' => 'value',
246 'isResponsive' => true,
247 'defaultValue' => 5,
248 'hasUnit' => true,
249 'unitDefaultValue' => 'px',
250 'property' => 'border-bottom-width',
251 'device' => $device,
252 ]);
253 } elseif ( $stack === 'horizontal' ) {
254 $css['border-right-color'] = $border_color;
255 $css['border-right-style'] = $divider_pattern_url;
256 $weight_css = Range::get_css([
257 'attributeValue' => $attributes['weight'],
258 'attribute_object_key' => 'value',
259 'isResponsive' => true,
260 'defaultValue' => 5,
261 'hasUnit' => true,
262 'unitDefaultValue' => 'px',
263 'property' => 'border-right-width',
264 'device' => $device,
265 ]);
266 }//end if
267 }//end if
268
269 if ( $stack === 'vertical' && ! empty( $attributes['width'][ 'value' . $device ] ) ) {
270 $width_css = Range::get_css([
271 'attributeValue' => $attributes['width'],
272 'attribute_object_key' => 'value',
273 'isResponsive' => true,
274 'defaultValue' => 100,
275 'hasUnit' => true,
276 'unitDefaultValue' => 'px',
277 'property' => 'width',
278 'device' => $device,
279 ]);
280 }
281 }//end if
282
283 return array_merge(
284 $css,
285 $weight_css,
286 $width_css
287 );
288 }
289
290
291
292 public function get_marker_css( $attributes, $device = '' ) {
293 $css = [];
294 $marker_size = isset( $attributes['markerSize'][ 'value' . $device ] ) ? $attributes['markerSize'][ 'value' . $device ] : '';
295 if ( isset( $attributes['markerColor'] ) && ! empty( $attributes['markerColor'] ) ) {
296 $css['background'] = Color::get_css(
297 isset( $attributes['markerColor'] ) ? $attributes['markerColor'] : '');
298 }
299
300 if ( $marker_size && ! empty( $marker_size ) ) {
301 $css['max-width'] = $marker_size . 'px';
302 $css['max-height'] = $marker_size . 'px';
303 $css['min-width'] = $marker_size . 'px';
304 $css['min-height'] = $marker_size . 'px';
305 $css['margin-top'] = 'calc((1lh - ' . $marker_size . 'px) / 2)';
306 }
307
308 return $css;
309 }
310
311 public function get_icon_css( $attributes, $device = '' ) {
312 $css = [];
313 $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
314 $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : '';
315 $css['box-sizing'] = 'content-box';
316
317 if ( isset( $attributes['markerType'] ) && $attributes['markerType'] === 'icon' ) {
318 if ( $attributes['iconType'] === 'stacked' ) {
319 $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '#ddd';
320 $css['padding'] = '.2em';
321 $css['color'] = Color::get_css(
322 isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#000000');
323
324 if ( $attributes['iconShape'] === 'circle' ) {
325 $css['border-radius'] = '50px';
326 }
327 } elseif ( $attributes['iconType'] === 'framed' ) {
328 $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : 'transparent';
329 $css['padding'] = '.2em';
330 $css['color'] = Color::get_css(
331 isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d');
332 $css['border'] = '2px solid ' . ( ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d' );
333
334 if ( $attributes['iconShape'] === 'circle' ) {
335 $css['border-radius'] = '50px';
336 }
337 }
338
339 if ( ! empty( $attributes[ 'iconColor' . $device ] ) && isset( $attributes[ 'iconColor' . $device ] ) ) {
340 $css['color'] = Color::get_css(
341 isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '');
342 $css['fill'] = Color::get_css(
343 isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '');
344
345 }
346
347 if ( ! empty( $attributes['iconBackgroundColor'] ) ) {
348 $css['background'] = Color::get_css(
349 isset( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '');
350
351 }
352 }//end if
353
354 return array_merge(
355 $css,
356 Range::get_css([
357 'attributeValue' => $attributes['iconSize'],
358 'attribute_object_key' => 'value',
359 'isResponsive' => true,
360 'defaultValue' => 20,
361 'hasUnit' => true,
362 'unitDefaultValue' => 'px',
363 'property' => 'font-size',
364 'device' => $device,
365 ]),
366 isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
367 Dimensions::get_css( $padding, 'padding', $device )
368 );
369 }
370
371
372 public function get_icon_hover_css( $attributes, $device = '' ) {
373 $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
374 return array_merge(
375 isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : []
376 );
377 }
378
379 public function get_list_text_css( $attributes, $device = '' ) {
380 $css = [];
381 return [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ];
382 }
383 }
384