PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.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 / star-ratings / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/star-ratings/block.php

206 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\StarRatings;
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\TextShadow;
13 use ABlocks\Controls\TextStroke;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\Icon;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\Color;
18
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'star-ratings';
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_container_css( $attributes ),
29 $this->get_container_css( $attributes, 'Tablet' ),
30 $this->get_container_css( $attributes, 'Mobile' ),
31 );
32 // rating icon css
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ablocks-rating',
35 $this->get_rating_css( $attributes ),
36 $this->get_rating_css( $attributes, 'Tablet' ),
37 $this->get_rating_css( $attributes, 'Mobile' ),
38 );
39
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ablocks-icon-wrap',
42 Icon::get_wrapper_css( $attributes ),
43 Icon::get_wrapper_css( $attributes, 'Tablet' ),
44 Icon::get_wrapper_css( $attributes, 'Mobile' )
45 );
46
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
49 Icon::get_element_image_css( $attributes ),
50 Icon::get_element_image_css( $attributes, 'Tablet' ),
51 Icon::get_element_image_css( $attributes, 'Mobile' ),
52 );
53
54 // rating icon spacing css
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-star-ratings-icons',
57 $this->get_rating_icon_spacing_css( $attributes ),
58 $this->get_rating_icon_spacing_css( $attributes, 'Tablet' ),
59 $this->get_rating_icon_spacing_css( $attributes, 'Mobile' ),
60 );
61
62 $get_desktop_rating_number_css = $this->get_rating_number_css( $attributes );
63 if ( ! empty( $attributes['ratingNumberColor'] ) ) {
64 $get_desktop_rating_number_css['color'] = $attributes['ratingNumberColor'];
65 }
66 if ( ! empty( $attributes['ratingNumberPosition'] ) ) {
67 if ( 'left' === $attributes['ratingNumberPosition'] ) {
68 $get_desktop_rating_number_css['order'] = '-5';
69 } else {
70 $get_desktop_rating_number_css['order'] = '10';
71 }
72 }
73 // rating number css
74 $css_generator->add_class_styles(
75 '{{WRAPPER}} .ablocks-star-rating-number',
76 $get_desktop_rating_number_css,
77 $this->get_rating_number_css( $attributes, 'Tablet' ),
78 $this->get_rating_number_css( $attributes, 'Mobile' ),
79 );
80
81 return $css_generator->generate_css();
82 }
83 public function build_css_v2( $attributes ) {
84
85 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
86
87 $css_generator->add_class_styles(
88 '{{WRAPPER}}:not(.ablocks-has-block-container), {{WRAPPER}}.ablocks-block--star-ratings > .ablocks-block-container',
89 $this->get_container_css( $attributes ),
90 $this->get_container_css( $attributes, 'Tablet' ),
91 $this->get_container_css( $attributes, 'Mobile' ),
92 );
93 // rating icon css
94 $css_generator->add_class_styles(
95 '{{WRAPPER}} .ablocks-rating',
96 $this->get_rating_css( $attributes ),
97 $this->get_rating_css( $attributes, 'Tablet' ),
98 $this->get_rating_css( $attributes, 'Mobile' ),
99 );
100
101 $css_generator->add_class_styles(
102 '{{WRAPPER}} .ablocks-icon-wrap',
103 Icon::get_wrapper_css( $attributes ),
104 Icon::get_wrapper_css( $attributes, 'Tablet' ),
105 Icon::get_wrapper_css( $attributes, 'Mobile' )
106 );
107
108 $css_generator->add_class_styles(
109 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
110 Icon::get_element_image_css( $attributes ),
111 Icon::get_element_image_css( $attributes, 'Tablet' ),
112 Icon::get_element_image_css( $attributes, 'Mobile' ),
113 );
114
115 // rating icon spacing css
116 $css_generator->add_class_styles(
117 '{{WRAPPER}} .ablocks-star-ratings-icons',
118 $this->get_rating_icon_spacing_css( $attributes ),
119 $this->get_rating_icon_spacing_css( $attributes, 'Tablet' ),
120 $this->get_rating_icon_spacing_css( $attributes, 'Mobile' ),
121 );
122 // rating number css
123 $css_generator->add_class_styles(
124 '{{WRAPPER}} .ablocks-star-rating-number',
125 $this->get_rating_number_css( $attributes ),
126 $this->get_rating_number_css( $attributes, 'Tablet' ),
127 $this->get_rating_number_css( $attributes, 'Mobile' ),
128 );
129
130 return $css_generator->generate_css();
131 }
132 public function build_css( $attributes ) {
133 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
134 return $this->build_css_v2( $attributes );
135 }
136 return $this->build_css_v1( $attributes );
137 }
138
139
140 public function get_container_css( $attributes, $device = '' ) {
141 $css = [];
142 $css['display'] = 'flex';
143 $css['align-items'] = 'center';
144 $css['flex-wrap'] = 'wrap';
145 return array_merge(
146 $css,
147 Range::get_css([
148 'attributeValue' => $attributes['ratingNumberGap'],
149 'attribute_object_key' => 'value',
150 'isResponsive' => true,
151 'defaultValue' => 0,
152 'hasUnit' => true,
153 'unitDefaultValue' => 'px',
154 'property' => 'gap',
155 'device' => $device,
156 ]),
157 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) : [],
158 );
159 }
160
161 public function get_rating_number_css( $attributes, $device = '' ) {
162 $css = [];
163 if ( ! empty( $attributes['ratingNumberPosition'] ) ) {
164 if ( 'left' === $attributes['ratingNumberPosition'] ) {
165 $css['order'] = '-5';
166 } else {
167 $css['order'] = '10';
168 }
169 }
170 $typographyValueGlobal = ! empty( $attributes['ratingNumberTypographyGlobal'] ) ? $attributes['ratingNumberTypographyGlobal'] : array();
171 // rating number css
172 return array_merge(
173 [ 'color' => Color::get_css( isset( $attributes['ratingNumberColor'] ) ? $attributes['ratingNumberColor'] : '' ) ],
174 Typography::get_css( $attributes['ratingNumberTypography'], '', $device, $typographyValueGlobal )
175 );
176
177 }
178
179 public function get_rating_css( $attributes, $device = '' ) {
180 $rating_css = [];
181 $size_value = $attributes['size'][ 'value' . $device ] ?? '';
182 $size_unit = $attributes['size'][ 'valueUnit' . $device ] ?? 'px';
183 $unit = ! empty( $attributes['gap'][ 'valueUnit' . $device ] ) ? $attributes['gap'][ 'valueUnit' . $device ] : 'px';
184
185 if ( ! empty( $size_value ) ) {
186 $rating_css['font-size'] = $size_value . $size_unit;
187 }
188 return $rating_css;
189 }
190
191
192 public function get_rating_icon_spacing_css( $attributes, $device = '' ) {
193 $spacing_value = Range::get_css([
194 'attributeValue' => $attributes['spacing'],
195 'attribute_object_key' => 'value',
196 'isResponsive' => true,
197 'defaultValue' => 0,
198 'hasUnit' => true,
199 'unitDefaultValue' => 'px',
200 'property' => 'gap',
201 'device' => $device,
202 ]);
203 return $spacing_value;
204 }
205 }
206