PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.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 1.1.2 All 80 releases
← All changes | includes/blocks/lists/block.php +375 -0 2.7.62.13.0 View file →
@@ -1,0 +1,375 @@
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 + );
94 + // List CSS
95 + $css_generator->add_class_styles(
96 + '{{WRAPPER}} .ablocks-list',
97 + $this->get_list_css( $attributes, '' ),
98 + $this->get_list_css( $attributes, 'Tablet' ),
99 + $this->get_list_css( $attributes, 'Mobile' ),
100 + );
101 + // List Wrapper CSS
102 + $css_generator->add_class_styles(
103 + '{{WRAPPER}} .ablocks-list__item-content',
104 + $this->get_list_wrapper_css( $attributes, '' ),
105 + $this->get_list_wrapper_css( $attributes, 'Tablet' ),
106 + $this->get_list_wrapper_css( $attributes, 'Mobile' ),
107 + );
108 +
109 + $css_generator->add_class_styles(
110 + '{{WRAPPER}} .ablocks-list_item-content-divider',
111 + $this->get_Divider_Wrapper_css( $attributes, '' ),
112 + $this->get_Divider_Wrapper_css( $attributes, 'Tablet' ),
113 + $this->get_Divider_Wrapper_css( $attributes, 'Mobile' ),
114 + );
115 + // Marker CSS
116 + $css_generator->add_class_styles(
117 + '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-marker',
118 + $this->get_marker_css( $attributes, '' ),
119 + $this->get_marker_css( $attributes, 'Tablet' ),
120 + $this->get_marker_css( $attributes, 'Mobile' ),
121 + );
122 + // Icon CSS
123 + $css_generator->add_class_styles(
124 + '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon',
125 + $this->get_icon_css( $attributes, '' ),
126 + $this->get_icon_css( $attributes, 'Tablet' ),
127 + $this->get_icon_css( $attributes, 'Mobile' ),
128 + );
129 + // Icon hover css
130 + $css_generator->add_class_styles(
131 + '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon:hover',
132 + $this->get_icon_hover_css( $attributes, '' ),
133 + $this->get_icon_hover_css( $attributes, 'Tablet' ),
134 + $this->get_icon_hover_css( $attributes, 'Mobile' ),
135 + );
136 +
137 + // List text CSS
138 + $css_generator->add_class_styles(
139 + '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-text',
140 + $this->get_list_text_css( $attributes ),
141 + $this->get_list_text_css( $attributes, 'Tablet' ),
142 + $this->get_list_text_css( $attributes, 'Mobile' ),
143 + );
144 +
145 + return $css_generator->generate_css();
146 + }
147 + public function build_css( $attributes ) {
148 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
149 + return $this->build_css_v2( $attributes );
150 + }
151 + return $this->build_css_v1( $attributes );
152 + }
153 + public function get_wrapper_css( $attributes, $device = '' ) {
154 + $typography = isset( $attributes['typography'] ) ? $attributes['typography'] : '';
155 + $alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : '';
156 + $typographyglobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
157 + return array_merge(
158 + Alignment::get_css( $alignment, 'text-align', $device ),
159 + Typography::get_css( $typography, '', $device, $typographyglobal ),
160 + );
161 + }
162 +
163 + public function get_list_css( $attributes, $device = '' ) {
164 + $css = [];
165 +
166 + if ( isset( $attributes['spaceBetween'][ 'value' . $device ] ) && ! empty( $attributes['spaceBetween'][ 'value' . $device ] ) ) {
167 + $css['gap'] = $attributes['spaceBetween'][ 'value' . $device ] . 'px';
168 + }
169 +
170 + $stack = $attributes[ 'stack' . $device ] ?? $attributes['stack'] ?? '';
171 + if ( $stack === 'vertical' ) {
172 + $css['flex-direction'] = 'column';
173 + $vertical_alignment = $attributes[ 'verticalAlignment' . $device ] ?? $attributes['verticalAlignment'] ?? '';
174 + if ( ! empty( $vertical_alignment ) ) {
175 + $css['align-items'] = $vertical_alignment;
176 + }
177 + } elseif ( $stack === 'horizontal' ) {
178 + $css['flex-direction'] = 'row';
179 + $horizontal_alignment = $attributes[ 'horizontalAlignment' . $device ] ?? $attributes['horizontalAlignment'] ?? '';
180 + if ( ! empty( $horizontal_alignment ) ) {
181 + $css['justify-content'] = $horizontal_alignment;
182 + }
183 + }
184 +
185 + $width_css = isset( $attributes[ 'width' . $device ] )
186 + ? Width::get_css( $attributes[ 'width' . $device ], 'width', $device )
187 + : [];
188 +
189 + $css = array_merge(
190 + $css,
191 + $width_css,
192 + isset( $attributes['horizontalAlignment'] )
193 + ? Alignment::get_css( $attributes['horizontalAlignment'], 'justify-content', $device )
194 + : []
195 + );
196 + foreach ( $css as $property => $value ) {
197 + if ( is_array( $value ) ) {
198 + unset( $css[ $property ] );
199 + }
200 + }
201 + return $css;
202 + }
203 +
204 + public function get_list_wrapper_css( $attributes, $device = '' ) {
205 + $css = [];
206 + $marker_type = $attributes['markerType'] ?? '';
207 + $text_indent = $attributes['textIndent'][ 'value' . $device ] ?? '';
208 + if ( $marker_type && 'icon' === $marker_type ) {
209 + if ( ! empty( $attributes['position'][ 'value' . $device ] ) ) {
210 + $css['align-items'] = $attributes['position'][ 'value' . $device ];
211 + }
212 + }
213 + if ( $text_indent && ! empty( $text_indent ) ) {
214 + $css['gap'] = $text_indent . 'px';
215 + }
216 +
217 + return $css;
218 + }
219 +
220 + public function get_divider_wrapper_css( $attributes, $device = '' ) {
221 + $css = [];
222 + $width_css = [];
223 + $weight_css = [];
224 +
225 + if ( isset( $attributes['divider'] ) && ! empty( $attributes['divider'] ) ) {
226 + $border_color = Color::get_css(
227 + isset( $attributes['borderColor'] ) ? $attributes['borderColor'] : 'black');
228 + $divider_pattern_url = isset( $attributes['dividerPatternUrl'] ) ? $attributes['dividerPatternUrl'] : '';
229 + $stack = isset( $attributes['stack'] ) ? $attributes['stack'] : '';
230 +
231 + if ( ! empty( $divider_pattern_url ) ) {
232 + if ( $stack === 'vertical' ) {
233 + $css['border-bottom-color'] = $border_color;
234 + $css['border-bottom-style'] = $divider_pattern_url;
235 + $weight_css = Range::get_css([
236 + 'attributeValue' => $attributes['weight'],
237 + 'attribute_object_key' => 'value',
238 + 'isResponsive' => true,
239 + 'defaultValue' => 5,
240 + 'hasUnit' => true,
241 + 'unitDefaultValue' => 'px',
242 + 'property' => 'border-bottom-width',
243 + 'device' => $device,
244 + ]);
245 + } elseif ( $stack === 'horizontal' ) {
246 + $css['border-right-color'] = $border_color;
247 + $css['border-right-style'] = $divider_pattern_url;
248 + $weight_css = Range::get_css([
249 + 'attributeValue' => $attributes['weight'],
250 + 'attribute_object_key' => 'value',
251 + 'isResponsive' => true,
252 + 'defaultValue' => 5,
253 + 'hasUnit' => true,
254 + 'unitDefaultValue' => 'px',
255 + 'property' => 'border-right-width',
256 + 'device' => $device,
257 + ]);
258 + }//end if
259 + }//end if
260 +
261 + if ( $stack === 'vertical' && ! empty( $attributes['width'][ 'value' . $device ] ) ) {
262 + $width_css = Range::get_css([
263 + 'attributeValue' => $attributes['width'],
264 + 'attribute_object_key' => 'value',
265 + 'isResponsive' => true,
266 + 'defaultValue' => 100,
267 + 'hasUnit' => true,
268 + 'unitDefaultValue' => 'px',
269 + 'property' => 'width',
270 + 'device' => $device,
271 + ]);
272 + }
273 + }//end if
274 +
275 + return array_merge(
276 + $css,
277 + $weight_css,
278 + $width_css
279 + );
280 + }
281 +
282 +
283 +
284 + public function get_marker_css( $attributes, $device = '' ) {
285 + $css = [];
286 + $marker_size = isset( $attributes['markerSize'][ 'value' . $device ] ) ? $attributes['markerSize'][ 'value' . $device ] : '';
287 + if ( isset( $attributes['markerColor'] ) && ! empty( $attributes['markerColor'] ) ) {
288 + $css['background'] = Color::get_css(
289 + isset( $attributes['markerColor'] ) ? $attributes['markerColor'] : '');
290 + }
291 +
292 + if ( $marker_size && ! empty( $marker_size ) ) {
293 + $css['max-width'] = $marker_size . 'px';
294 + $css['max-height'] = $marker_size . 'px';
295 + $css['min-width'] = $marker_size . 'px';
296 + $css['min-height'] = $marker_size . 'px';
297 + $css['margin-top'] = 'calc((1lh - ' . $marker_size . 'px) / 2)';
298 + }
299 +
300 + return $css;
301 + }
302 +
303 + public function get_icon_css( $attributes, $device = '' ) {
304 + $css = [];
305 + $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
306 + $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : '';
307 + $css['box-sizing'] = 'content-box';
308 +
309 + if ( isset( $attributes['markerType'] ) && $attributes['markerType'] === 'icon' ) {
310 + if ( $attributes['iconType'] === 'stacked' ) {
311 + $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '#ddd';
312 + $css['padding'] = '.2em';
313 + $css['color'] = Color::get_css(
314 + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#000000');
315 +
316 + if ( $attributes['iconShape'] === 'circle' ) {
317 + $css['border-radius'] = '50px';
318 + }
319 + } elseif ( $attributes['iconType'] === 'framed' ) {
320 + $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : 'transparent';
321 + $css['padding'] = '.2em';
322 + $css['color'] = Color::get_css(
323 + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d');
324 + $css['border'] = '2px solid ' . ( ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d' );
325 +
326 + if ( $attributes['iconShape'] === 'circle' ) {
327 + $css['border-radius'] = '50px';
328 + }
329 + }
330 +
331 + if ( ! empty( $attributes[ 'iconColor' . $device ] ) && isset( $attributes[ 'iconColor' . $device ] ) ) {
332 + $css['color'] = Color::get_css(
333 + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '');
334 + $css['fill'] = Color::get_css(
335 + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '');
336 +
337 + }
338 +
339 + if ( ! empty( $attributes['iconBackgroundColor'] ) ) {
340 + $css['background'] = Color::get_css(
341 + isset( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '');
342 +
343 + }
344 + }//end if
345 +
346 + return array_merge(
347 + $css,
348 + Range::get_css([
349 + 'attributeValue' => $attributes['iconSize'],
350 + 'attribute_object_key' => 'value',
351 + 'isResponsive' => true,
352 + 'defaultValue' => 20,
353 + 'hasUnit' => true,
354 + 'unitDefaultValue' => 'px',
355 + 'property' => 'font-size',
356 + 'device' => $device,
357 + ]),
358 + isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
359 + Dimensions::get_css( $padding, 'padding', $device )
360 + );
361 + }
362 +
363 +
364 + public function get_icon_hover_css( $attributes, $device = '' ) {
365 + $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
366 + return array_merge(
367 + isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : []
368 + );
369 + }
370 +
371 + public function get_list_text_css( $attributes, $device = '' ) {
372 + $css = [];
373 + return [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ];
374 + }
375 +}