PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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
ablocks / includes / blocks / price-menu / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.0, at includes/blocks/price-menu/block.php

363 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\PriceMenu;
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\Alignment;
12 use ABlocks\Controls\Border;
13 use ABlocks\Controls\Dimensions;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\TextShadow;
16 use ABlocks\Controls\TextStroke;
17 use ABlocks\Controls\Range;
18 use ABlocks\Controls\Color;
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'price-menu';
21
22 public function build_css_v1( $attributes ) {
23
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .ablocks-block-container',
28 $this->get_all_menu_css( $attributes, '' ),
29 $this->get_all_menu_css( $attributes, 'Tablet' ),
30 $this->get_all_menu_css( $attributes, 'Mobile' ),
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .ablocks-price-menu-item, {{WRAPPER}} .ablocks-price-menu-item-details',
34 $this->get_gap_around_css( $attributes, '' ),
35 $this->get_gap_around_css( $attributes, 'Tablet' ),
36 $this->get_gap_around_css( $attributes, 'Mobile' ),
37 );
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .ablocks-price-menu-item-details-brief',
40 $this->get_details_brief_css( $attributes, '' ),
41 $this->get_details_brief_css( $attributes, 'Tablet' ),
42 $this->get_details_brief_css( $attributes, 'Mobile' ),
43 );
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ablocks-block--price-menu-item',
46 $this->get_item_css( $attributes, '' ),
47 $this->get_item_css( $attributes, 'Tablet' ),
48 $this->get_item_css( $attributes, 'Mobile' ),
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .ablocks-block--price-menu-item:hover',
52 $this->get_item_hover_css( $attributes, '' ),
53 $this->get_item_hover_css( $attributes, 'Tablet' ),
54 $this->get_item_hover_css( $attributes, 'Mobile' ),
55 );
56
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} .ablocks-price-menu-item',
59 $this->get_inner_item_css( $attributes, '' ),
60 $this->get_inner_item_css( $attributes, 'Tablet' ),
61 $this->get_inner_item_css( $attributes, 'Mobile' ),
62 );
63
64 // TitleText CSS
65 $css_generator->add_class_styles(
66 '{{WRAPPER}} .ablocks-price-menu-item-details-title',
67 $this->get_title_text_css( $attributes, '' ),
68 $this->get_title_text_css( $attributes, 'Tablet' ),
69 $this->get_title_text_css( $attributes, 'Mobile' ),
70 );
71 // DescriptionText CSS
72 $css_generator->add_class_styles(
73 '{{WRAPPER}} .ablocks-price-menu-item-details-des',
74 $this->get_description_text_css( $attributes, '' ),
75 $this->get_description_text_css( $attributes, 'Tablet' ),
76 $this->get_description_text_css( $attributes, 'Mobile' ),
77 );
78 // SeparatorText CSS
79 $css_generator->add_class_styles(
80 '{{WRAPPER}} .ablocks-price-menu-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ),
81 $this->get_divider_css( $attributes, '' ),
82 $this->get_divider_css( $attributes, 'Tablet' ),
83 $this->get_divider_css( $attributes, 'Mobile' ),
84 );
85 // PriceText CSS
86 $css_generator->add_class_styles(
87 '{{WRAPPER}} .ablocks-price-menu-item-price',
88 $this->get_price_text_css( $attributes, '' ),
89 $this->get_price_text_css( $attributes, 'Tablet' ),
90 $this->get_price_text_css( $attributes, 'Mobile' ),
91 );
92
93 return $css_generator->generate_css();
94 }
95 public function build_css_v2( $attributes ) {
96
97 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
98
99 $css_generator->add_class_styles(
100 '{{WRAPPER}}:not(.ablocks-has-block-container), {{WRAPPER}}.ablocks-block--price-menu > .ablocks-block-container',
101 $this->get_all_menu_css( $attributes, '' ),
102 $this->get_all_menu_css( $attributes, 'Tablet' ),
103 $this->get_all_menu_css( $attributes, 'Mobile' ),
104 );
105 $css_generator->add_class_styles(
106 '{{WRAPPER}} .ablocks-price-menu-item, {{WRAPPER}} .ablocks-price-menu-item-details',
107 $this->get_gap_around_css( $attributes, '' ),
108 $this->get_gap_around_css( $attributes, 'Tablet' ),
109 $this->get_gap_around_css( $attributes, 'Mobile' ),
110 );
111 $css_generator->add_class_styles(
112 '{{WRAPPER}} .ablocks-price-menu-item-details-brief',
113 $this->get_details_brief_css( $attributes, '' ),
114 $this->get_details_brief_css( $attributes, 'Tablet' ),
115 $this->get_details_brief_css( $attributes, 'Mobile' ),
116 );
117 $css_generator->add_class_styles(
118 '{{WRAPPER}} .ablocks-block--price-menu-item',
119 $this->get_item_css( $attributes, '' ),
120 $this->get_item_css( $attributes, 'Tablet' ),
121 $this->get_item_css( $attributes, 'Mobile' ),
122 );
123 $css_generator->add_class_styles(
124 '{{WRAPPER}} .ablocks-block--price-menu-item:hover',
125 $this->get_item_hover_css( $attributes, '' ),
126 $this->get_item_hover_css( $attributes, 'Tablet' ),
127 $this->get_item_hover_css( $attributes, 'Mobile' ),
128 );
129
130 $css_generator->add_class_styles(
131 '{{WRAPPER}} .ablocks-price-menu-item',
132 $this->get_inner_item_css( $attributes, '' ),
133 $this->get_inner_item_css( $attributes, 'Tablet' ),
134 $this->get_inner_item_css( $attributes, 'Mobile' ),
135 );
136
137 // TitleText CSS
138 $css_generator->add_class_styles(
139 '{{WRAPPER}} .ablocks-price-menu-item-details-title',
140 $this->get_title_text_css( $attributes, '' ),
141 $this->get_title_text_css( $attributes, 'Tablet' ),
142 $this->get_title_text_css( $attributes, 'Mobile' ),
143 );
144 // DescriptionText CSS
145 $css_generator->add_class_styles(
146 '{{WRAPPER}} .ablocks-price-menu-item-details-des',
147 $this->get_description_text_css( $attributes, '' ),
148 $this->get_description_text_css( $attributes, 'Tablet' ),
149 $this->get_description_text_css( $attributes, 'Mobile' ),
150 );
151 // SeparatorText CSS
152 $css_generator->add_class_styles(
153 '{{WRAPPER}} .ablocks-price-menu-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ),
154 $this->get_divider_css( $attributes, '' ),
155 $this->get_divider_css( $attributes, 'Tablet' ),
156 $this->get_divider_css( $attributes, 'Mobile' ),
157 );
158 // PriceText CSS
159 $css_generator->add_class_styles(
160 '{{WRAPPER}} .ablocks-price-menu-item-price',
161 $this->get_price_text_css( $attributes, '' ),
162 $this->get_price_text_css( $attributes, 'Tablet' ),
163 $this->get_price_text_css( $attributes, 'Mobile' ),
164 );
165
166 return $css_generator->generate_css();
167 }
168 public function build_css( $attributes ) {
169 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
170 return $this->build_css_v2( $attributes );
171 }
172 return $this->build_css_v1( $attributes );
173 }
174
175 public function get_item_css( $attributes, $device = '' ) {
176 $css = [];
177
178 if ( isset( $attributes['transition'] ) ) {
179 $css['transition-duration'] = $attributes['transition'] . 's';
180 }
181 return array_merge(
182 [ 'background' => Color::get_css( isset( $attributes['itemBackground'] ) ? $attributes['itemBackground'] : '' ) ],
183 $css,
184 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) : [],
185 isset( $attributes['itemBorder'] ) ? Border::get_css( $attributes['itemBorder'], '', $device ) : [],
186 isset( $attributes['itemPadding'] ) ? Dimensions::get_css( $attributes['itemPadding'], 'padding', $device ) : [],
187 );
188 }
189
190 public function get_item_hover_css( $attributes, $device = '' ) {
191 return array_merge(
192 [ 'background' => Color::get_css( isset( $attributes['itemBackgroundH'] ) ? $attributes['itemBackgroundH'] : '' ) ],
193 isset( $attributes['itemBorder'] ) ? Border::get_hover_css( $attributes['itemBorder'], '', $device ) : [],
194 );
195 }
196
197 public function get_inner_item_css( $attributes, $device = '' ) {
198 $css = [];
199
200 if ( isset( $attributes['itemsDirection'][ 'value' . $device ] ) ) {
201 $css['flex-direction'] = $attributes['itemsDirection'][ 'value' . $device ];
202 }
203
204 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
205 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
206 }
207
208 return $css;
209 }
210
211 public function get_gap_around_css( $attributes, $device = '' ) {
212 $css = [];
213 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
214 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
215 }
216
217 return array_merge(
218 $css,
219 Range::get_css([
220 'attributeValue' => $attributes['gap'],
221 'attribute_object_key' => 'value',
222 'isResponsive' => true,
223 'hasUnit' => true,
224 'defaultValue' => 10,
225 'unitDefaultValue' => 'px',
226 'property' => 'gap',
227 'device' => $device,
228 ]),
229 );
230 }
231
232 public function get_details_brief_css( $attributes, $device = '' ) {
233 $css = [];
234 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
235 if ( $attributes['itemsDirection'][ 'value' . $device ] === 'row' ) {
236 $css['justify-content'] = 'space-between';
237 } else {
238 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
239 }
240 }
241
242 return array_merge(
243 Range::get_css([
244 'attributeValue' => $attributes['gap'],
245 'attribute_object_key' => 'value',
246 'isResponsive' => true,
247 'hasUnit' => true,
248 'defaultValue' => 10,
249 'unitDefaultValue' => 'px',
250 'property' => 'gap',
251 'device' => $device,
252 ]),
253 $css
254 );
255 }
256
257 public function get_all_menu_css( $attributes, $device = '' ) {
258 $css = [];
259 $css['display'] = 'flex';
260 $css['flex-wrap'] = 'wrap';
261 $css['flex-direction'] = 'column';
262
263 return array_merge(
264 $css,
265 Range::get_css([
266 'attributeValue' => $attributes['columnGap'],
267 'attribute_object_key' => 'value',
268 'isResponsive' => true,
269 'isResponsive' => true,
270 'defaultValue' => 20,
271 'unitDefaultValue' => 'px',
272 'property' => 'gap',
273 'device' => $device,
274 ]),
275 );
276 }
277
278 public function get_title_text_css( $attributes, $device = '' ) {
279 $typographyValueGlobal = ! empty( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : array();
280 return array_merge(
281 [ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' ) ],
282 isset( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) : [],
283 isset( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : [],
284 isset( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : [],
285 isset( $attributes['titleAlignment'] ) ? Alignment::get_css( $attributes['titleAlignment'], 'text-align', $device ) : [],
286 );
287 }
288 public function get_description_text_css( $attributes, $device = '' ) {
289 $typographyValueGlobal = ! empty( $attributes['descriptionTypographyGlobal'] ) ? $attributes['descriptionTypographyGlobal'] : array();
290 return array_merge(
291 [ 'color' => Color::get_css( isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : '' ) ],
292 isset( $attributes['descriptionTypography'] ) ? Typography::get_css( $attributes['descriptionTypography'], '', $device, $typographyValueGlobal ) : [],
293 isset( $attributes['descriptionTextStroke'] ) ? TextStroke::get_css( $attributes['descriptionTextStroke'], '', $device ) : [],
294 isset( $attributes['descriptionTextShadow'] ) ? TextShadow::get_css( $attributes['descriptionTextShadow'], '', $device ) : [],
295 isset( $attributes['descriptionAlignment'] ) ? Alignment::get_css( $attributes['descriptionAlignment'], 'text-align', $device ) : [],
296 );
297 }
298 public function get_divider_css( $attributes, $device = '' ) {
299 $css = [];
300 $divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60;
301 $default_Unit = $attributes['allowDescription'] === true ? '%' : 'px';
302 $css['--ablocks-divider-pattern-color'] = Color::get_css(
303 isset( $attributes['color'] ) ? $attributes['color'] : '#000000');
304
305 $moreRangeCSS = [];
306 if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) {
307 $moreRangeCSS = Range::get_css([
308 'attributeValue' => $attributes['size'],
309 'attribute_object_key' => 'value',
310 'isResponsive' => false,
311 'defaultValue' => 20,
312 'hasUnit' => false,
313 'unitDefaultValue' => 'px',
314 'property' => '--ablocks-divider-pattern-height',
315 ]);
316 } elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) {
317 $moreRangeCSS = Range::get_css([
318 'attributeValue' => $attributes['weight'],
319 'attribute_object_key' => 'value',
320 'isResponsive' => false,
321 'defaultValue' => 2,
322 'hasUnit' => false,
323 'unitDefaultValue' => 'px',
324 'property' => '--ablocks-divider-pattern-weight',
325 ]);
326 }//end if
327
328 if ( ! empty( $attributes['dividerPatternUrl'] ) ) {
329 if ( $attributes['dividerType'] === 'mask-style' ) {
330 $css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')';
331 } else {
332 $css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl'];
333 }
334 }
335
336 return array_merge(
337 $css,
338 Range::get_css([
339 'attributeValue' => $attributes['width'],
340 'attribute_object_key' => 'value',
341 'isResponsive' => true,
342 'defaultValue' => 100,
343 'hasUnit' => false,
344 'unitDefaultValue' => $attributes['allowDescription'] === true ? '%' : 'px',
345 'property' => 'width',
346 'device' => $device,
347 ]),
348 $moreRangeCSS,
349 );
350 }
351 public function get_price_text_css( $attributes, $device = '' ) {
352 $typographyValueGlobal = ! empty( $attributes['priceTypographyGlobal'] ) ? $attributes['priceTypographyGlobal'] : array();
353 return array_merge(
354 [ 'color' => Color::get_css( isset( $attributes['priceColor'] ) ? $attributes['priceColor'] : '' ) ],
355 isset( $attributes['priceTypography'] ) ? Typography::get_css( $attributes['priceTypography'], '', $device, $typographyValueGlobal ) : [],
356 isset( $attributes['priceTextStroke'] ) ? TextStroke::get_css( $attributes['priceTextStroke'], '', $device ) : [],
357 isset( $attributes['priceTextShadow'] ) ? TextShadow::get_css( $attributes['priceTextShadow'], '', $device ) : [],
358 isset( $attributes['priceAlignment'] ) ? Alignment::get_css( $attributes['priceAlignment'], 'text-align', $device ) : [],
359 );
360 }
361
362 }
363