PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.10.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.10.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.10.0, at includes/blocks/storeengine-product-review/block.php

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