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
← All changes | includes/blocks/price-menu/block.php +372 -0 1.0.2 → 2.14.0 View file →
@@ -1,0 +1,372 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_all_menu_css( $attributes, $device ); } )
105 + );
106 + $css_generator->add_class_styles(
107 + '{{WRAPPER}} .ablocks-price-menu-item, {{WRAPPER}} .ablocks-price-menu-item-details',
108 + $this->get_gap_around_css( $attributes, '' ),
109 + $this->get_gap_around_css( $attributes, 'Tablet' ),
110 + $this->get_gap_around_css( $attributes, 'Mobile' ),
111 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_gap_around_css( $attributes, $device ); } )
112 + );
113 + $css_generator->add_class_styles(
114 + '{{WRAPPER}} .ablocks-price-menu-item-details-brief',
115 + $this->get_details_brief_css( $attributes, '' ),
116 + $this->get_details_brief_css( $attributes, 'Tablet' ),
117 + $this->get_details_brief_css( $attributes, 'Mobile' ),
118 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_details_brief_css( $attributes, $device ); } )
119 + );
120 + $css_generator->add_class_styles(
121 + '{{WRAPPER}} .ablocks-block--price-menu-item',
122 + $this->get_item_css( $attributes, '' ),
123 + $this->get_item_css( $attributes, 'Tablet' ),
124 + $this->get_item_css( $attributes, 'Mobile' ),
125 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_item_css( $attributes, $device ); } )
126 + );
127 + $css_generator->add_class_styles(
128 + '{{WRAPPER}} .ablocks-block--price-menu-item:hover',
129 + $this->get_item_hover_css( $attributes, '' ),
130 + $this->get_item_hover_css( $attributes, 'Tablet' ),
131 + $this->get_item_hover_css( $attributes, 'Mobile' ),
132 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_item_hover_css( $attributes, $device ); } )
133 + );
134 +
135 + $css_generator->add_class_styles(
136 + '{{WRAPPER}} .ablocks-price-menu-item',
137 + $this->get_inner_item_css( $attributes, '' ),
138 + $this->get_inner_item_css( $attributes, 'Tablet' ),
139 + $this->get_inner_item_css( $attributes, 'Mobile' ),
140 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_inner_item_css( $attributes, $device ); } )
141 + );
142 +
143 + // TitleText CSS
144 + $css_generator->add_class_styles(
145 + '{{WRAPPER}} .ablocks-price-menu-item-details-title',
146 + $this->get_title_text_css( $attributes, '' ),
147 + $this->get_title_text_css( $attributes, 'Tablet' ),
148 + $this->get_title_text_css( $attributes, 'Mobile' ),
149 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_text_css( $attributes, $device ); } )
150 + );
151 + // DescriptionText CSS
152 + $css_generator->add_class_styles(
153 + '{{WRAPPER}} .ablocks-price-menu-item-details-des',
154 + $this->get_description_text_css( $attributes, '' ),
155 + $this->get_description_text_css( $attributes, 'Tablet' ),
156 + $this->get_description_text_css( $attributes, 'Mobile' ),
157 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_description_text_css( $attributes, $device ); } )
158 + );
159 + // SeparatorText CSS
160 + $css_generator->add_class_styles(
161 + '{{WRAPPER}} .ablocks-price-menu-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ),
162 + $this->get_divider_css( $attributes, '' ),
163 + $this->get_divider_css( $attributes, 'Tablet' ),
164 + $this->get_divider_css( $attributes, 'Mobile' ),
165 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_divider_css( $attributes, $device ); } )
166 + );
167 + // PriceText CSS
168 + $css_generator->add_class_styles(
169 + '{{WRAPPER}} .ablocks-price-menu-item-price',
170 + $this->get_price_text_css( $attributes, '' ),
171 + $this->get_price_text_css( $attributes, 'Tablet' ),
172 + $this->get_price_text_css( $attributes, 'Mobile' ),
173 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_price_text_css( $attributes, $device ); } )
174 + );
175 +
176 + return $css_generator->generate_css();
177 + }
178 + public function build_css( $attributes ) {
179 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
180 + return $this->build_css_v2( $attributes );
181 + }
182 + return $this->build_css_v1( $attributes );
183 + }
184 +
185 + public function get_item_css( $attributes, $device = '' ) {
186 + $css = [];
187 +
188 + if ( ! empty( $attributes['transition'] ) ) {
189 + $css['transition-duration'] = $attributes['transition'] . 's';
190 + }
191 + return array_merge(
192 + [ 'background' => Color::get_css( isset( $attributes['itemBackground'] ) ? $attributes['itemBackground'] : '' ) ],
193 + $css,
194 + isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) : [],
195 + isset( $attributes['itemBorder'] ) ? Border::get_css( $attributes['itemBorder'], '', $device ) : [],
196 + isset( $attributes['itemPadding'] ) ? Dimensions::get_css( $attributes['itemPadding'], 'padding', $device ) : [],
197 + );
198 + }
199 +
200 + public function get_item_hover_css( $attributes, $device = '' ) {
201 + return array_merge(
202 + [ 'background' => Color::get_css( isset( $attributes['itemBackgroundH'] ) ? $attributes['itemBackgroundH'] : '' ) ],
203 + isset( $attributes['itemBorder'] ) ? Border::get_hover_css( $attributes['itemBorder'], '', $device ) : [],
204 + );
205 + }
206 +
207 + public function get_inner_item_css( $attributes, $device = '' ) {
208 + $css = [];
209 +
210 + if ( isset( $attributes['itemsDirection'][ 'value' . $device ] ) ) {
211 + $css['flex-direction'] = $attributes['itemsDirection'][ 'value' . $device ];
212 + }
213 +
214 + if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
215 + $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
216 + }
217 +
218 + return $css;
219 + }
220 +
221 + public function get_gap_around_css( $attributes, $device = '' ) {
222 + $css = [];
223 + if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
224 + $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
225 + }
226 +
227 + return array_merge(
228 + $css,
229 + Range::get_css([
230 + 'attributeValue' => $attributes['gap'],
231 + 'attribute_object_key' => 'value',
232 + 'isResponsive' => true,
233 + 'hasUnit' => true,
234 + 'defaultValue' => 10,
235 + 'unitDefaultValue' => 'px',
236 + 'property' => 'gap',
237 + 'device' => $device,
238 + ]),
239 + );
240 + }
241 +
242 + public function get_details_brief_css( $attributes, $device = '' ) {
243 + $css = [];
244 + if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
245 + if ( $attributes['itemsDirection'][ 'value' . $device ] === 'row' ) {
246 + $css['justify-content'] = 'space-between';
247 + } else {
248 + $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
249 + }
250 + }
251 +
252 + return array_merge(
253 + Range::get_css([
254 + 'attributeValue' => $attributes['gap'],
255 + 'attribute_object_key' => 'value',
256 + 'isResponsive' => true,
257 + 'hasUnit' => true,
258 + 'defaultValue' => 10,
259 + 'unitDefaultValue' => 'px',
260 + 'property' => 'gap',
261 + 'device' => $device,
262 + ]),
263 + $css
264 + );
265 + }
266 +
267 + public function get_all_menu_css( $attributes, $device = '' ) {
268 + $css = [];
269 + $css['display'] = 'flex';
270 + $css['flex-wrap'] = 'wrap';
271 + $css['flex-direction'] = 'column';
272 +
273 + return array_merge(
274 + $css,
275 + Range::get_css([
276 + 'attributeValue' => $attributes['columnGap'],
277 + 'attribute_object_key' => 'value',
278 + 'isResponsive' => true,
279 + 'isResponsive' => true,
280 + 'defaultValue' => 20,
281 + 'unitDefaultValue' => 'px',
282 + 'property' => 'gap',
283 + 'device' => $device,
284 + ]),
285 + );
286 + }
287 +
288 + public function get_title_text_css( $attributes, $device = '' ) {
289 + $typographyValueGlobal = ! empty( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : array();
290 + return array_merge(
291 + [ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' ) ],
292 + isset( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) : [],
293 + isset( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : [],
294 + isset( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : [],
295 + isset( $attributes['titleAlignment'] ) ? Alignment::get_css( $attributes['titleAlignment'], 'text-align', $device ) : [],
296 + );
297 + }
298 + public function get_description_text_css( $attributes, $device = '' ) {
299 + $typographyValueGlobal = ! empty( $attributes['descriptionTypographyGlobal'] ) ? $attributes['descriptionTypographyGlobal'] : array();
300 + return array_merge(
301 + [ 'color' => Color::get_css( isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : '' ) ],
302 + isset( $attributes['descriptionTypography'] ) ? Typography::get_css( $attributes['descriptionTypography'], '', $device, $typographyValueGlobal ) : [],
303 + isset( $attributes['descriptionTextStroke'] ) ? TextStroke::get_css( $attributes['descriptionTextStroke'], '', $device ) : [],
304 + isset( $attributes['descriptionTextShadow'] ) ? TextShadow::get_css( $attributes['descriptionTextShadow'], '', $device ) : [],
305 + isset( $attributes['descriptionAlignment'] ) ? Alignment::get_css( $attributes['descriptionAlignment'], 'text-align', $device ) : [],
306 + );
307 + }
308 + public function get_divider_css( $attributes, $device = '' ) {
309 + $css = [];
310 + $divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60;
311 + $default_Unit = $attributes['allowDescription'] === true ? '%' : 'px';
312 + $css['--ablocks-divider-pattern-color'] = Color::get_css(
313 + isset( $attributes['color'] ) ? $attributes['color'] : '#000000');
314 +
315 + $moreRangeCSS = [];
316 + if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) {
317 + $moreRangeCSS = Range::get_css([
318 + 'attributeValue' => $attributes['size'],
319 + 'attribute_object_key' => 'value',
320 + 'isResponsive' => false,
321 + 'defaultValue' => 20,
322 + 'hasUnit' => false,
323 + 'unitDefaultValue' => 'px',
324 + 'property' => '--ablocks-divider-pattern-height',
325 + ]);
326 + } elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) {
327 + $moreRangeCSS = Range::get_css([
328 + 'attributeValue' => $attributes['weight'],
329 + 'attribute_object_key' => 'value',
330 + 'isResponsive' => false,
331 + 'defaultValue' => 2,
332 + 'hasUnit' => false,
333 + 'unitDefaultValue' => 'px',
334 + 'property' => '--ablocks-divider-pattern-weight',
335 + ]);
336 + }//end if
337 +
338 + if ( ! empty( $attributes['dividerPatternUrl'] ) ) {
339 + if ( $attributes['dividerType'] === 'mask-style' ) {
340 + $css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')';
341 + } else {
342 + $css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl'];
343 + }
344 + }
345 +
346 + return array_merge(
347 + $css,
348 + Range::get_css([
349 + 'attributeValue' => $attributes['width'],
350 + 'attribute_object_key' => 'value',
351 + 'isResponsive' => true,
352 + 'defaultValue' => 100,
353 + 'hasUnit' => false,
354 + 'unitDefaultValue' => $attributes['allowDescription'] === true ? '%' : 'px',
355 + 'property' => 'width',
356 + 'device' => $device,
357 + ]),
358 + $moreRangeCSS,
359 + );
360 + }
361 + public function get_price_text_css( $attributes, $device = '' ) {
362 + $typographyValueGlobal = ! empty( $attributes['priceTypographyGlobal'] ) ? $attributes['priceTypographyGlobal'] : array();
363 + return array_merge(
364 + [ 'color' => Color::get_css( isset( $attributes['priceColor'] ) ? $attributes['priceColor'] : '' ) ],
365 + isset( $attributes['priceTypography'] ) ? Typography::get_css( $attributes['priceTypography'], '', $device, $typographyValueGlobal ) : [],
366 + isset( $attributes['priceTextStroke'] ) ? TextStroke::get_css( $attributes['priceTextStroke'], '', $device ) : [],
367 + isset( $attributes['priceTextShadow'] ) ? TextShadow::get_css( $attributes['priceTextShadow'], '', $device ) : [],
368 + isset( $attributes['priceAlignment'] ) ? Alignment::get_css( $attributes['priceAlignment'], 'text-align', $device ) : [],
369 + );
370 + }
371 +
372 +}