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 / storeengine-product-review / block.php

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

353 lines 16.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\StoreengineProductReview;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Background;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\Color;
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'storeengine-product-review';
22
23 public function build_css( $attributes ) {
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings',
28 $this->get_feedback_section_css( $attributes ),
29 $this->get_feedback_section_css( $attributes, 'Tablet' ),
30 $this->get_feedback_section_css( $attributes, 'Mobile' ),
31 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_feedback_section_css( $attributes, $device ); } )
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings:hover',
35 $this->get_feedback_section_hover_css( $attributes ),
36 $this->get_feedback_section_hover_css( $attributes, 'Tablet' ),
37 $this->get_feedback_section_hover_css( $attributes, 'Mobile' ),
38 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_feedback_section_hover_css( $attributes, $device ); } )
39 );
40
41 $css_generator->add_class_styles(
42 '{{WRAPPER}} .storeengine-single-product__content-item h2',
43 $this->get_heading_css( $attributes ),
44 $this->get_heading_css( $attributes, 'Tablet' ),
45 $this->get_heading_css( $attributes, 'Mobile' ),
46 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_css( $attributes, $device ); } )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .storeengine-single-product__content-item h2:hover',
50 $this->get_heading_hover_css( $attributes ),
51 $this->get_heading_hover_css( $attributes, 'Tablet' ),
52 $this->get_heading_hover_css( $attributes, 'Mobile' ),
53 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_hover_css( $attributes, $device ); } )
54 );
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating',
57 $this->get_avarage_css( $attributes, '' ),
58 $this->get_avarage_css( $attributes, 'Tablet' ),
59 $this->get_avarage_css( $attributes, 'Mobile' ),
60 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_avarage_css( $attributes, $device ); } )
61 );
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating:hover',
64 $this->get_avarage_hover_css( $attributes, '' ),
65 $this->get_avarage_hover_css( $attributes, 'Tablet' ),
66 $this->get_avarage_hover_css( $attributes, 'Mobile' ),
67 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_avarage_hover_css( $attributes, $device ); } )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating-html .storeengine-icon,
71 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating-html .storeengine-icon:before',
72 $this->get_rating_css( $attributes, '' ),
73 $this->get_rating_css( $attributes, 'Tablet' ),
74 $this->get_rating_css( $attributes, 'Mobile' ),
75 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_css( $attributes, $device ); } )
76 );
77 $css_generator->add_class_styles(
78 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating-html .storeengine-icon:hover,
79 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-rating-html .storeengine-icon:hover::before',
80 $this->get_rating_hover_css( $attributes, '' ),
81 $this->get_rating_hover_css( $attributes, 'Tablet' ),
82 $this->get_rating_hover_css( $attributes, 'Mobile' ),
83 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_hover_css( $attributes, $device ); } )
84 );
85 $css_generator->add_class_styles(
86 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-review',
87 $this->get_review_text_css( $attributes, '' ),
88 $this->get_review_text_css( $attributes, 'Tablet' ),
89 $this->get_review_text_css( $attributes, 'Mobile' ),
90 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_text_css( $attributes, $device ); } )
91 );
92 $css_generator->add_class_styles(
93 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-avg-review:hover',
94 $this->get_review_text_hover_css( $attributes, '' ),
95 $this->get_review_text_hover_css( $attributes, 'Tablet' ),
96 $this->get_review_text_hover_css( $attributes, 'Mobile' ),
97 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_text_hover_css( $attributes, $device ); } )
98 );
99 $css_generator->add_class_styles(
100 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-fill',
101 $this->get_rating_fill_css( $attributes, '' ),
102 $this->get_rating_fill_css( $attributes, 'Tablet' ),
103 $this->get_rating_fill_css( $attributes, 'Mobile' ),
104 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_fill_css( $attributes, $device ); } )
105 );
106 $css_generator->add_class_styles(
107 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-fill:hover',
108 $this->get_rating_fill_hover_css( $attributes, '' ),
109 $this->get_rating_fill_hover_css( $attributes, 'Tablet' ),
110 $this->get_rating_fill_hover_css( $attributes, 'Mobile' ),
111 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_fill_hover_css( $attributes, $device ); } )
112 );
113 $css_generator->add_class_styles(
114 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-fill,
115 {{WEAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-label span,
116 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-label,
117 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-col',
118 $this->get_rating_text_css( $attributes, '' ),
119 $this->get_rating_text_css( $attributes, 'Tablet' ),
120 $this->get_rating_text_css( $attributes, 'Mobile' ),
121 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_text_css( $attributes, $device ); } )
122 );
123 $css_generator->add_class_styles(
124 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-fill:hover,
125 {{WEAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-label span:hover,
126 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-label:hover,
127 {{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-ratings-list-item-col:hover',
128 $this->get_rating_text_hover_css( $attributes, '' ),
129 $this->get_rating_text_hover_css( $attributes, 'Tablet' ),
130 $this->get_rating_text_hover_css( $attributes, 'Mobile' ),
131 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_text_hover_css( $attributes, $device ); } )
132 );
133 $css_generator->add_class_styles(
134 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-icon',
135 $this->get_feedback_star_css( $attributes, '' ),
136 $this->get_feedback_star_css( $attributes, 'Tablet' ),
137 $this->get_feedback_star_css( $attributes, 'Mobile' ),
138 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_feedback_star_css( $attributes, $device ); } )
139 );
140 $css_generator->add_class_styles(
141 '{{WRAPPER}} .storeengine-single-product__content-item--feedback .storeengine-product-feedback-ratings .storeengine-ratings-list-item .storeengine-icon:hover',
142 $this->get_feedback_star_hover_css( $attributes, '' ),
143 $this->get_feedback_star_hover_css( $attributes, 'Tablet' ),
144 $this->get_feedback_star_hover_css( $attributes, 'Mobile' ),
145 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_feedback_star_hover_css( $attributes, $device ); } )
146 );
147
148 return $css_generator->generate_css();
149 }
150
151 public function get_feedback_section_css( $attributes, $device = '' ) {
152 return array_merge(
153 [ 'background' => Color::get_css( isset( $attributes['section_bg'] ) ? $attributes['section_bg'] : '#FFF' ) ],
154 Border::get_css( $attributes['border'], '', $device ),
155 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
156 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
157 Range::get_css([
158 'attributeValue' => $attributes['section_height'],
159 'attribute_object_key' => 'value',
160 'isResponsive' => true,
161 'defaultValue' => 100,
162 'hasUnit' => true,
163 'unitDefaultValue' => '%',
164 'property' => 'height',
165 'device' => $device,
166 ]),
167 Range::get_css([
168 'attributeValue' => $attributes['section_width'],
169 'attribute_object_key' => 'value',
170 'isResponsive' => true,
171 'defaultValue' => 100,
172 'hasUnit' => true,
173 'unitDefaultValue' => '%',
174 'property' => 'width',
175 'device' => $device,
176 ]),
177 );
178
179 }
180
181 public function get_feedback_section_hover_css( $attributes, $device = '' ) {
182 return array_merge(
183 [ 'background' => Color::get_css( isset( $attributes['section_bg_hover'] ) ? $attributes['section_bg_hover'] : '#FFF' ) ],
184 Border::get_hover_css( $attributes['border'], '', $device ),
185 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
186 );
187 }
188
189 public function get_heading_css( $attributes, $device = '' ) {
190 $typography_global = isset( $attributes['heading_typographyGlobal'] ) ? $attributes['heading_typographyGlobal'] : '';
191
192 $typography_value = ! empty( $attributes['heading_typography'] ) ?
193 Typography::get_css( $attributes['heading_typography'], '', $device, $typography_global )
194 : array();
195
196 return array_merge(
197 [ 'color' => Color::get_css( isset( $attributes['heading_color'] ) ? $attributes['heading_color'] : '' ) ],
198 $typography_value
199 );
200 }
201
202 public function get_heading_hover_css( $attributes, $device = '' ) {
203 return [ 'color' => Color::get_css( isset( $attributes['heading_hover_color'] ) ? $attributes['heading_hover_color'] : '' ) ];
204 }
205
206 public function get_avarage_css( $attributes, $device = '' ) {
207 $typography_global = isset( $attributes['avg_typographyGlobal'] ) ? $attributes['avg_typographyGlobal'] : '';
208
209 $typography_value = ! empty( $attributes['avg_typography'] ) ?
210 Typography::get_css( $attributes['avg_typography'], '', $device, $typography_global )
211 : array();
212
213 return array_merge(
214 [ 'color' => Color::get_css( isset( $attributes['avg_color'] ) ? $attributes['avg_color'] : '#111' ) ],
215 $typography_value
216 );
217 }
218
219 public function get_avarage_hover_css( $attributes, $device = '' ) {
220 return [
221 'color' => Color::get_css( isset( $attributes['avg_color_hover'] ) ? $attributes['avg_color_hover'] : '#111' )
222 ];
223 }
224
225 public function get_rating_css( $attributes, $device = '' ) {
226 return array_merge(
227 [ 'color' => Color::get_css( isset( $attributes['rating_color'] ) ? $attributes['rating_color'] : '#111' ) ],
228 Range::get_css([
229 'attributeValue' => $attributes['rating_size'],
230 'attribute_object_key' => 'value',
231 'isResponsive' => true,
232 'defaultValue' => 16,
233 'hasUnit' => true,
234 'unitDefaultValue' => 'px',
235 'property' => 'font-size',
236 'device' => $device,
237 ]),
238 );
239 }
240
241 public function get_rating_hover_css( $attributes, $device = '' ) {
242 return [ 'color' => Color::get_css( isset( $attributes['rating_color_hover'] ) ? $attributes['rating_color_hover'] : '#111' ) ];
243 }
244
245 public function get_review_text_css( $attributes, $device = '' ) {
246 $typography_global = isset( $attributes['total_typographyGlobal'] )
247 ? $attributes['total_typographyGlobal'] : '';
248
249 $typography_value = ! empty( $attributes['total_typography'] ) ?
250 Typography::get_css( $attributes['total_typography'], '', $device )
251 : array();
252
253 return array_merge(
254 [ 'color' => Color::get_css( isset( $attributes['total_rating_color'] ) ? $attributes['total_rating_color'] : '#999' ) ],
255 $typography_value
256 );
257 }
258
259 public function get_review_text_hover_css( $attributes, $device = '' ) {
260 return [
261 'color' => Color::get_css( isset( $attributes['total_rating_hover'] ) ? $attributes['total_rating_hover'] : '#999' )
262 ];
263 }
264
265 public function get_rating_fill_css( $attributes, $device = '' ) {
266 return [
267 'background' => Color::get_css( isset( $attributes['fillBg'] ) ? $attributes['fillBg'] : '#e7e7e7' )
268 ];
269 }
270
271 public function get_rating_fill_hover_css( $attributes, $device = '' ) {
272 return [
273 'background' => Color::get_css( isset( $attributes['fillBgH'] ) ? $attributes['fillBgH'] : '#e7e7e7' )
274 ];
275 }
276
277 public function get_rating_text_css( $attributes, $device = '' ) {
278 $typography_global = isset( $attributes['listTypographyGlobal'] )
279 ? $attributes['listTypographyGlobal'] : '';
280
281 $typography_value = ! empty( $attributes['listTypography'] ) ?
282 Typography::get_css( $attributes['listTypography'], '', $device, $typography_global )
283 : array();
284
285 return array_merge(
286 [ 'color' => Color::get_css( isset( $attributes['listColor'] ) ? $attributes['listColor'] : '#999' ) ],
287 $typography_value
288 );
289 }
290
291 public function get_rating_text_hover_css( $attributes, $device = '' ) {
292 return [
293 'color' => Color::get_css( isset( $attributes['listColorH'] ) ? $attributes['listColorH'] : '#999' )
294 ];
295 }
296
297 public function get_feedback_star_css( $attributes, $device = '' ) {
298 return array_merge(
299 [ 'color' => Color::get_css( isset( $attributes['starColor'] ) ? $attributes['starColor'] : '#f4c150' ) ],
300 Range::get_css([
301 'attributeValue' => $attributes['startSize'],
302 'attribute_object_key' => 'value',
303 'isResponsive' => true,
304 'defaultValue' => 16,
305 'hasUnit' => true,
306 'unitDefaultValue' => 'px',
307 'property' => 'font-size',
308 'device' => $device,
309 ]),
310 );
311 }
312
313 public function get_feedback_star_hover_css( $attributes, $device = '' ) {
314 return [
315 'color' => Color::get_css( isset( $attributes['starColorH'] ) ? $attributes['starColorH'] : '#999' )
316 ];
317 }
318
319
320 public function render_block_content( $attributes, $content, $block_instance ) {
321 $attr_array = [
322 'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ),
323 ];
324
325 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
326 $is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) );
327
328 $is_custom = $attributes['isCustom'];
329
330 if ( $is_custom ) {
331 if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
332 $attr_array['product_id'] = $block_instance->context['postId'];
333 }
334 } else {
335 if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
336 $attr_array['product_id'] = $block_instance->context['postId'];
337 }
338 }
339
340 if ( $is_editor && empty( $attr_array['product_id'] ) ) {
341 return '<p>Only in editor preview. Please Select a Product</p>';
342 }
343
344 if ( $is_editor ) {
345 $attr_array['dummy'] = true;
346 }
347
348 $shortcode = '[storeengine_single_product_reviews ' . Helper::attr_shortcode( $attr_array ) . ']';
349 echo do_shortcode( $shortcode );
350
351 }
352 }
353