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/star-ratings/block.php +90 -3 2.9.1 → 2.14.0 View file →
@@ -1,9 +1,14 @@
1 1 <?php
2 2 namespace ABlocks\Blocks\StarRatings;
3 3
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
4 8 use ABlocks\Classes\BlockBaseAbstract;
5 9 use ABlocks\Classes\CssGenerator;
10 +use ABlocks\Classes\CssGeneratorV2;
6 11 use ABlocks\Controls\Alignment;
7 12 use ABlocks\Controls\TextShadow;
8 13 use ABlocks\Controls\TextStroke;
9 14 use ABlocks\Controls\Typography;
@@ -8,13 +13,14 @@
8 13 use ABlocks\Controls\TextStroke;
9 14 use ABlocks\Controls\Typography;
10 15 use ABlocks\Controls\Icon;
11 16 use ABlocks\Controls\Range;
17 +use ABlocks\Controls\Color;
12 18
13 19 class Block extends BlockBaseAbstract {
14 20 protected $block_name = 'star-ratings';
15 21
16 - public function build_css( $attributes ) {
22 + public function build_css_v1( $attributes ) {
17 23
18 24 $css_generator = new CssGenerator( $attributes, $this->block_name );
19 25
20 26 $css_generator->add_class_styles(
@@ -34,9 +40,10 @@
34 40 $css_generator->add_class_styles(
35 41 '{{WRAPPER}} .ablocks-icon-wrap',
36 42 Icon::get_wrapper_css( $attributes ),
37 43 Icon::get_wrapper_css( $attributes, 'Tablet' ),
38 - Icon::get_wrapper_css( $attributes, 'Mobile' )
44 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
45 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
39 46 );
40 47
41 48 $css_generator->add_class_styles(
42 49 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
@@ -73,12 +80,78 @@
73 80 );
74 81
75 82 return $css_generator->generate_css();
76 83 }
84 + public function build_css_v2( $attributes ) {
77 85
86 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
78 87
88 + $css_generator->add_class_styles(
89 + '{{WRAPPER}}:not(.ablocks-has-block-container), {{WRAPPER}}.ablocks-block--star-ratings > .ablocks-block-container',
90 + $this->get_container_css( $attributes ),
91 + $this->get_container_css( $attributes, 'Tablet' ),
92 + $this->get_container_css( $attributes, 'Mobile' ),
93 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_container_css( $attributes, $device ); } )
94 + );
95 + // rating icon css
96 + $css_generator->add_class_styles(
97 + '{{WRAPPER}} .ablocks-rating',
98 + $this->get_rating_css( $attributes ),
99 + $this->get_rating_css( $attributes, 'Tablet' ),
100 + $this->get_rating_css( $attributes, 'Mobile' ),
101 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_css( $attributes, $device ); } )
102 + );
103 +
104 + $css_generator->add_class_styles(
105 + '{{WRAPPER}} .ablocks-icon-wrap',
106 + Icon::get_wrapper_css( $attributes ),
107 + Icon::get_wrapper_css( $attributes, 'Tablet' ),
108 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
109 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
110 + );
111 +
112 + $css_generator->add_class_styles(
113 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
114 + Icon::get_element_image_css( $attributes ),
115 + Icon::get_element_image_css( $attributes, 'Tablet' ),
116 + Icon::get_element_image_css( $attributes, 'Mobile' ),
117 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
118 + );
119 +
120 + // rating icon spacing css
121 + $css_generator->add_class_styles(
122 + '{{WRAPPER}} .ablocks-star-ratings-icons',
123 + $this->get_rating_icon_spacing_css( $attributes ),
124 + $this->get_rating_icon_spacing_css( $attributes, 'Tablet' ),
125 + $this->get_rating_icon_spacing_css( $attributes, 'Mobile' ),
126 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_icon_spacing_css( $attributes, $device ); } )
127 + );
128 + // rating number css
129 + $css_generator->add_class_styles(
130 + '{{WRAPPER}} .ablocks-star-rating-number',
131 + $this->get_rating_number_css( $attributes ),
132 + $this->get_rating_number_css( $attributes, 'Tablet' ),
133 + $this->get_rating_number_css( $attributes, 'Mobile' ),
134 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_rating_number_css( $attributes, $device ); } )
135 + );
136 +
137 + return $css_generator->generate_css();
138 + }
139 + public function build_css( $attributes ) {
140 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
141 + return $this->build_css_v2( $attributes );
142 + }
143 + return $this->build_css_v1( $attributes );
144 + }
145 +
146 +
79 147 public function get_container_css( $attributes, $device = '' ) {
148 + $css = [];
149 + $css['display'] = 'flex';
150 + $css['align-items'] = 'center';
151 + $css['flex-wrap'] = 'wrap';
80 152 return array_merge(
153 + $css,
81 154 Range::get_css([
82 155 'attributeValue' => $attributes['ratingNumberGap'],
83 156 'attribute_object_key' => 'value',
84 157 'isResponsive' => true,
@@ -92,9 +165,23 @@
92 165 );
93 166 }
94 167
95 168 public function get_rating_number_css( $attributes, $device = '' ) {
96 - return Typography::get_css( $attributes['ratingNumberTypography'], '', $device );
169 + $css = [];
170 + if ( ! empty( $attributes['ratingNumberPosition'] ) ) {
171 + if ( 'left' === $attributes['ratingNumberPosition'] ) {
172 + $css['order'] = '-5';
173 + } else {
174 + $css['order'] = '10';
175 + }
176 + }
177 + $typographyValueGlobal = ! empty( $attributes['ratingNumberTypographyGlobal'] ) ? $attributes['ratingNumberTypographyGlobal'] : array();
178 + // rating number css
179 + return array_merge(
180 + [ 'color' => Color::get_css( isset( $attributes['ratingNumberColor'] ) ? $attributes['ratingNumberColor'] : '' ) ],
181 + Typography::get_css( $attributes['ratingNumberTypography'], '', $device, $typographyValueGlobal )
182 + );
183 +
97 184 }
98 185
99 186 public function get_rating_css( $attributes, $device = '' ) {
100 187 $rating_css = [];