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

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

266 lines 9.5 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 use ABlocks\Classes\BlockBaseAbstract;
5 use ABlocks\Classes\CssGenerator;
6 use ABlocks\Controls\Alignment;
7 use ABlocks\Controls\Dimensions;
8 use ABlocks\Controls\Typography;
9 use ABlocks\Controls\Width;
10 use ABlocks\Controls\Border;
11
12 class Block extends BlockBaseAbstract {
13
14 protected $block_name = 'lists';
15
16 public function build_css( $attributes ) {
17 // Generate CSS
18 $css_generator = new CssGenerator( $attributes );
19 // Wrapper CSS
20 $css_generator->add_class_styles(
21 '{{WRAPPER}}',
22 $this->get_wrapper_css( $attributes, '' ),
23 $this->get_wrapper_css( $attributes, 'Tablet' ),
24 $this->get_wrapper_css( $attributes, 'Mobile' ),
25 );
26 // List CSS
27 $css_generator->add_class_styles(
28 '{{WRAPPER}} .ablocks-list',
29 $this->get_list_css( $attributes, '' ),
30 $this->get_list_css( $attributes, 'Tablet' ),
31 $this->get_list_css( $attributes, 'Mobile' ),
32 );
33 // List Wrapper CSS
34 $css_generator->add_class_styles(
35 '{{WRAPPER}} .ablocks-list__item-content',
36 $this->get_list_wrapper_css( $attributes, '' ),
37 $this->get_list_wrapper_css( $attributes, 'Tablet' ),
38 $this->get_list_wrapper_css( $attributes, 'Mobile' ),
39 );
40
41 $css_generator->add_class_styles(
42 '{{WRAPPER}} .ablocks-list_item-content-divider',
43 $this->get_Divider_Wrapper_css( $attributes, '' ),
44 $this->get_Divider_Wrapper_css( $attributes, 'Tablet' ),
45 $this->get_Divider_Wrapper_css( $attributes, 'Mobile' ),
46 );
47 // Marker CSS
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-marker',
50 $this->get_marker_css( $attributes, '' ),
51 $this->get_marker_css( $attributes, 'Tablet' ),
52 $this->get_marker_css( $attributes, 'Mobile' ),
53 );
54 // Icon CSS
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon',
57 $this->get_icon_css( $attributes, '' ),
58 $this->get_icon_css( $attributes, 'Tablet' ),
59 $this->get_icon_css( $attributes, 'Mobile' ),
60 );
61 // Icon hover css
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon:hover',
64 $this->get_icon_hover_css( $attributes, '' ),
65 $this->get_icon_hover_css( $attributes, 'Tablet' ),
66 $this->get_icon_hover_css( $attributes, 'Mobile' ),
67 );
68
69 // List text CSS
70 $css_generator->add_class_styles(
71 '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-text',
72 $this->get_list_text_css( $attributes ),
73 $this->get_list_text_css( $attributes, 'Tablet' ),
74 $this->get_list_text_css( $attributes, 'Mobile' ),
75 );
76
77 return $css_generator->generate_css();
78 }
79
80 public function get_wrapper_css( $attributes, $device = '' ) {
81 $typography = isset( $attributes['typography'] ) ? $attributes['typography'] : '';
82 $alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : '';
83 return array_merge(
84 Alignment::get_css( $alignment, 'text-align', $device ),
85 Typography::get_css( $typography, '', $device ),
86 );
87 }
88
89 public function get_list_css( $attributes, $device = '' ) {
90 $css = [];
91
92 if ( isset( $attributes['spaceBetween'][ 'value' . $device ] ) && ! empty( $attributes['spaceBetween'][ 'value' . $device ] ) ) {
93 $css['gap'] = $attributes['spaceBetween'][ 'value' . $device ] . 'px';
94 }
95
96 $stack = $attributes[ 'stack' . $device ] ?? $attributes['stack'] ?? '';
97 if ( $stack === 'vertical' ) {
98 $css['flex-direction'] = 'column';
99 $vertical_alignment = $attributes[ 'verticalAlignment' . $device ] ?? $attributes['verticalAlignment'] ?? '';
100 if ( ! empty( $vertical_alignment ) ) {
101 $css['align-items'] = $vertical_alignment;
102 }
103 } elseif ( $stack === 'horizontal' ) {
104 $css['flex-direction'] = 'row';
105 $horizontal_alignment = $attributes[ 'horizontalAlignment' . $device ] ?? $attributes['horizontalAlignment'] ?? '';
106 if ( ! empty( $horizontal_alignment ) ) {
107 $css['justify-content'] = $horizontal_alignment;
108 }
109 }
110
111 $width_css = isset( $attributes[ 'width' . $device ] )
112 ? Width::get_css( $attributes[ 'width' . $device ], 'width', $device )
113 : [];
114
115 $css = array_merge(
116 $css,
117 $width_css,
118 isset( $attributes['horizontalAlignment'] )
119 ? Alignment::get_css( $attributes['horizontalAlignment'], 'justify-content', $device )
120 : []
121 );
122 foreach ( $css as $property => $value ) {
123 if ( is_array( $value ) ) {
124 unset( $css[ $property ] );
125 }
126 }
127 return $css;
128 }
129
130 public function get_list_wrapper_css( $attributes, $device = '' ) {
131 $css = [];
132 $marker_type = $attributes['markerType'] ?? '';
133 $text_indent = $attributes['textIndent'][ 'value' . $device ] ?? '';
134 if ( $marker_type && 'icon' === $marker_type ) {
135 if ( ! empty( $attributes['position'][ 'value' . $device ] ) ) {
136 $css['align-items'] = $attributes['position'][ 'value' . $device ];
137 }
138 }
139 if ( $text_indent && ! empty( $text_indent ) ) {
140 $css['gap'] = $text_indent . 'px';
141 }
142
143 return $css;
144 }
145
146 public function get_divider_wrapper_css( $attributes, $device = '' ) {
147 $css = [];
148
149 if ( isset( $attributes['divider'] ) && ! empty( $attributes['divider'] ) ) {
150 $weight_value = isset( $attributes['weight'][ 'value' . $device ] ) ? $attributes['weight'][ 'value' . $device ] : 1;
151 $weight_unit = isset( $attributes['weight'][ 'valueUnit' . $device ] ) ? $attributes['weight'][ 'valueUnit' . $device ] : 'px';
152
153 $border_color = isset( $attributes['borderColor'] ) ? $attributes['borderColor'] : 'black';
154 $divider_pattern_url = isset( $attributes['dividerPatternUrl'] ) ? $attributes['dividerPatternUrl'] : '';
155 $stack = isset( $attributes['stack'] ) ? $attributes['stack'] : '';
156
157 if ( ! empty( $divider_pattern_url ) ) {
158 if ( $stack === 'vertical' ) {
159 $css['border-bottom'] = "{$weight_value}{$weight_unit} {$divider_pattern_url} {$border_color}";
160 } elseif ( $stack === 'horizontal' ) {
161 $css['border-right'] = "{$weight_value}{$weight_unit} {$divider_pattern_url} {$border_color}";
162 }
163 }
164
165 if ( $stack === 'horizontal' ) {
166 $width_value = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : '0';
167 } else {
168 $width_value = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : '100';
169 $width_unit = isset( $attributes['width'][ 'valueUnit' . $device ] ) ? $attributes['width'][ 'valueUnit' . $device ] : '%';
170 $css['width'] = "{$width_value}{$width_unit}";
171 }
172 }//end if
173
174 return $css;
175 }
176
177
178
179 public function get_marker_css( $attributes, $device = '' ) {
180 $css = [];
181 $marker_size = isset( $attributes['markerSize'][ 'value' . $device ] ) ? $attributes['markerSize'][ 'value' . $device ] : '';
182 if ( isset( $attributes['markerColor'] ) && ! empty( $attributes['markerColor'] ) ) {
183 $css['background'] = $attributes['markerColor'];
184 }
185
186 if ( $marker_size && ! empty( $marker_size ) ) {
187 $css['max-width'] = $marker_size . 'px';
188 $css['max-height'] = $marker_size . 'px';
189 $css['min-width'] = $marker_size . 'px';
190 $css['min-height'] = $marker_size . 'px';
191 }
192
193 return $css;
194 }
195
196 public function get_icon_css( $attributes, $device = '' ) {
197 $css = [];
198 $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
199 $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : '';
200 $css['box-sizing'] = 'content-box';
201
202 if ( isset( $attributes['markerType'] ) && $attributes['markerType'] === 'icon' ) {
203 if ( $attributes['iconType'] === 'stacked' ) {
204 $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '#ddd';
205 $css['padding'] = '.2em';
206 $css['color'] = ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#000000';
207
208 if ( $attributes['iconShape'] === 'circle' ) {
209 $css['border-radius'] = '50px';
210 }
211 } elseif ( $attributes['iconType'] === 'framed' ) {
212 $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : 'transparent';
213 $css['padding'] = '.2em';
214 $css['color'] = ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d';
215 $css['border'] = '2px solid ' . ( ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d' );
216
217 if ( $attributes['iconShape'] === 'circle' ) {
218 $css['border-radius'] = '50px';
219 }
220 }
221
222 $defaultUnit = 'px';
223
224 $unit = ! empty( $attributes['iconSize'][ 'valueUnit' . $device ] ) ? $attributes['iconSize'][ 'valueUnit' . $device ] : $defaultUnit;
225
226 if ( ! empty( $attributes['iconSize'][ 'value' . $device ] ) ) {
227 $css['font-size'] = $attributes['iconSize'][ 'value' . $device ] . $unit;
228 }
229
230 if ( ! empty( $attributes[ 'iconColor' . $device ] ) && isset( $attributes[ 'iconColor' . $device ] ) ) {
231 $css['color'] = $attributes['iconColor'];
232 $css['fill'] = $attributes['iconColor'];
233 }
234
235 if ( isset( $attributes['iconBackground'] ) && $attributes['iconBackground'] ) {
236 if ( ! empty( $attributes['iconBackgroundColor'] ) ) {
237 $css['background'] = $attributes['iconBackgroundColor'];
238 }
239 }
240 }//end if
241
242 return array_merge(
243 $css,
244 isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
245 Dimensions::get_css( $padding, 'padding', $device )
246 );
247 }
248
249
250 public function get_icon_hover_css( $attributes, $device = '' ) {
251 $border = isset( $attributes['border'] ) ? $attributes['border'] : '';
252 return array_merge(
253 isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : []
254 );
255 }
256
257 public function get_list_text_css( $attributes, $device = '' ) {
258 $css = [];
259 if ( isset( $attributes['textColor'] ) ) {
260 $css['color'] = $attributes['textColor'];
261 }
262
263 return $css;
264 }
265 }
266