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 / social-shares / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.10.0, at includes/blocks/social-shares/block.php

354 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\SocialShares;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 use ABlocks\Classes\BlockBaseAbstract;
8 use ABlocks\Classes\CssGenerator;
9 use ABlocks\Controls\Alignment;
10 use ABlocks\Controls\Border;
11 use ABlocks\Controls\BoxShadow;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\TextShadow;
14 use ABlocks\Controls\TextStroke;
15 use ABlocks\Controls\Range;
16 use ABlocks\Classes\CssGeneratorV2;
17 use ABlocks\Controls\Color;
18 class Block extends BlockBaseAbstract {
19 protected $block_name = 'social-shares';
20
21 public function build_css_v1( $attributes ) {
22 $css_generator = new CssGenerator( $attributes, $this->block_name );
23 $css_generator->add_class_styles(
24 '{{WRAPPER}}.ablocks-block--social-shares .ablocks-block-container',
25 $this->get_share_css( $attributes, '' ),
26 $this->get_share_css( $attributes, 'Tablet' ),
27 $this->get_share_css( $attributes, 'Mobile' )
28 );
29 // Social Button Styles
30 $css_generator->add_class_styles(
31 '{{WRAPPER}} .ablocks-block-container .ablocks-social-share',
32 $this->get_social_share_bar_css( $attributes ),
33 $this->get_social_share_bar_css( $attributes, 'Table' ),
34 $this->get_social_share_bar_css( $attributes, 'Mobile' )
35 );
36 // share Hover Styles
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .ablocks-block-container .ablocks-social-share:hover',
39 $this->get_share_border_hover_css( $attributes, '' ),
40 $this->get_share_border_hover_css( $attributes, 'Tablet' ),
41 $this->get_share_border_hover_css( $attributes, 'Mobile' )
42 );
43 // share Icon Size
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon',
46 $this->get_share_icon_css( $attributes ),
47 $this->get_share_icon_css( $attributes, 'Table' ),
48 $this->get_share_icon_css( $attributes, 'Mobile' ),
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon:hover',
52 $this->get_share_icon_hover_css(
53 $attributes
54 ),
55 );
56 // item style
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} .ablocks-social-share-item',
59 $this->get_item_border_css( $attributes ),
60 $this->get_item_border_css( $attributes, 'Tablet' ),
61 $this->get_item_border_css( $attributes, 'Mobile' )
62 );
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .ablocks-block-container .ablocks-social-share-item:hover',
65 $this->get_Item_border_hover_css( $attributes ),
66 $this->get_Item_border_hover_css( $attributes, 'Tablet' ),
67 $this->get_Item_border_hover_css( $attributes, 'Mobile' )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-social-share-item--icon',
71 $this->get_share_item_css( $attributes ),
72 $this->get_share_item_css( $attributes, 'Tablet' ),
73 $this->get_share_item_css( $attributes, 'Mobile' ),
74 );
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .ablocks-social-share-item--icon>.ablocks-svg-icon',
77 $this->shareItemIconSVG( $attributes ),
78 $this->shareItemIconSVG( $attributes, 'Tablet' ),
79 $this->shareItemIconSVG( $attributes, 'Mobile' ),
80 );
81 $css_generator->add_class_styles(
82 '{{WRAPPER}} .ablocks-social-share-item--text',
83 $this->get_share_item_text_css( $attributes, '' ),
84 $this->get_share_item_text_css( $attributes, 'Tablet' ),
85 $this->get_share_item_text_css( $attributes, 'Mobile' )
86 );
87 return $css_generator->generate_css();
88 }
89 public function build_css_v2( $attributes ) {
90 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
91 $css_generator->add_class_styles(
92 '{{WRAPPER}}.ablocks-block--social-shares:not(.ablocks-has-container),
93 {{WRAPPER}}.ablocks-block--social-shares .ablocks-block-container',
94 $this->get_share_css( $attributes, '' ),
95 $this->get_share_css( $attributes, 'Tablet' ),
96 $this->get_share_css( $attributes, 'Mobile' )
97 );
98 // Social Button Styles
99 $css_generator->add_class_styles(
100 '{{WRAPPER}} .ablocks-social-share',
101 $this->get_social_share_bar_css( $attributes ),
102 $this->get_social_share_bar_css( $attributes, 'Table' ),
103 $this->get_social_share_bar_css( $attributes, 'Mobile' )
104 );
105 // share Hover Styles
106 $css_generator->add_class_styles(
107 '{{WRAPPER}} .ablocks-social-share:hover',
108 $this->get_share_border_hover_css( $attributes, '' ),
109 $this->get_share_border_hover_css( $attributes, 'Tablet' ),
110 $this->get_share_border_hover_css( $attributes, 'Mobile' )
111 );
112
113 // share Icon Size
114 $css_generator->add_class_styles(
115 '{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon',
116 $this->get_share_icon_css( $attributes ),
117 $this->get_share_icon_css( $attributes, 'Table' ),
118 $this->get_share_icon_css( $attributes, 'Mobile' ),
119 );
120 $css_generator->add_class_styles(
121 '{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon:hover',
122 $this->get_share_icon_hover_css(
123 $attributes
124 ),
125 );
126 // item style
127 $css_generator->add_class_styles(
128 '{{WRAPPER}} .ablocks-social-share-item',
129 $this->get_item_border_css( $attributes ),
130 $this->get_item_border_css( $attributes, 'Tablet' ),
131 $this->get_item_border_css( $attributes, 'Mobile' )
132 );
133 $css_generator->add_class_styles(
134 '{{WRAPPER}} .ablocks-social-share-item:hover',
135 $this->get_Item_border_hover_css( $attributes ),
136 $this->get_Item_border_hover_css( $attributes, 'Tablet' ),
137 $this->get_Item_border_hover_css( $attributes, 'Mobile' )
138 );
139 $css_generator->add_class_styles(
140 '{{WRAPPER}} .ablocks-social-share-item--icon',
141 $this->get_share_item_css( $attributes ),
142 $this->get_share_item_css( $attributes, 'Tablet' ),
143 $this->get_share_item_css( $attributes, 'Mobile' ),
144 );
145 $css_generator->add_class_styles(
146 '{{WRAPPER}} .ablocks-social-share-item--icon>.ablocks-svg-icon',
147 $this->shareItemIconSVG( $attributes ),
148 $this->shareItemIconSVG( $attributes, 'Tablet' ),
149 $this->shareItemIconSVG( $attributes, 'Mobile' ),
150 );
151 $css_generator->add_class_styles(
152 '{{WRAPPER}} .ablocks-social-share-item--text',
153 $this->get_share_item_text_css( $attributes, '' ),
154 $this->get_share_item_text_css( $attributes, 'Tablet' ),
155 $this->get_share_item_text_css( $attributes, 'Mobile' )
156 );
157 return $css_generator->generate_css();
158 }
159 public function build_css( $attributes ) {
160 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
161 return $this->build_css_v2( $attributes );
162 }
163 return $this->build_css_v1( $attributes );
164 }
165 public function get_share_css( $attributes, $device = '' ) {
166 $css = [];
167 $stack = $attributes[ 'stack' . $device ] ?? $attributes['stack'] ?? '';
168 if ( $stack === 'vertical' ) {
169 $css['flex-direction'] = 'column';
170 if ( ! empty( $attributes[ 'verticalAlignment' . $device ] ) ) {
171 $css['align-items'] = $attributes[ 'verticalAlignment' . $device ];
172 }
173 } elseif ( $stack === 'horizontal' ) {
174 $css['flex-direction'] = 'row';
175 $horizontal_alignment = $attributes[ 'horizontalAlignment' . $device ] ?? $attributes['horizontalAlignment'] ?? '';
176 if ( ! empty( $horizontal_alignment ) ) {
177 $css['justify-content'] = $horizontal_alignment;
178 }
179 }
180 $alignment_css = isset( $attributes['horizontalAlignment'] )
181 ? Alignment::get_css( $attributes['horizontalAlignment'], 'justify-content', $device )
182 : [];
183 $css = array_merge( $css, $alignment_css );
184
185 foreach ( $css as $property => $value ) {
186 if ( ! is_string( $value ) || empty( $value ) ) {
187 unset( $css[ $property ] );
188 }
189 }
190 return array_merge(
191 $css,
192 Range::get_css([
193 'attributeValue' => $attributes['spaceBetween'],
194 'attribute_object_key' => 'value',
195 'isResponsive' => true,
196 'defaultValue' => 20,
197 'hasUnit' => true,
198 'unitDefaultValue' => 'px',
199 'property' => 'gap',
200 'device' => $device,
201 ])
202 );
203 }
204
205
206 public function get_social_share_bar_css( $attributes, $device = '' ) {
207 return array_merge(
208 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
209 Border::get_css( $attributes['border'], $device ),
210 Range::get_css([
211 'attributeValue' => $attributes['shareSize'],
212 'attribute_object_key' => 'value',
213 'isResponsive' => false,
214 'defaultValue' => 48,
215 'hasUnit' => true,
216 'unitDefaultValue' => 'px',
217 'property' => 'height',
218 'device' => $device,
219 ]),
220 Range::get_css([
221 'attributeValue' => $attributes['shareSize'],
222 'attribute_object_key' => 'value',
223 'isResponsive' => false,
224 'defaultValue' => 48,
225 'hasUnit' => true,
226 'unitDefaultValue' => 'px',
227 'property' => 'width',
228 'device' => $device,
229 ]),
230 );
231 }
232
233 public function get_share_border_hover_css( $attributes, $device = '' ) {
234 return array_merge(
235 [ 'background' => Color::get_css( isset( $attributes['buttonHover'] ) ? $attributes['buttonHover'] : '' ) ],
236 ( isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : [] )
237 );
238 }
239 public function get_share_icon_css( $attributes, $device = '' ) {
240 return array_merge(
241 [ 'fill' => Color::get_css( isset( $attributes['shareButtonIconColor'] ) ? $attributes['shareButtonIconColor'] : '' ) . '!important' ],
242 Range::get_css( [
243 'attributeValue' => $attributes['shareIconSize'],
244 'attribute_object_key' => 'value',
245 'isResponsive' => false,
246 'defaultValue' => 16,
247 'hasUnit' => true,
248 'unitDefaultValue' => 'px',
249 'property' => 'width',
250 'device' => $device,
251 ] ),
252 Range::get_css( [
253 'attributeValue' => $attributes['shareIconSize'],
254 'attribute_object_key' => 'value',
255 'isResponsive' => false,
256 'defaultValue' => 16,
257 'hasUnit' => true,
258 'unitDefaultValue' => 'px',
259 'property' => 'height',
260 'device' => $device,
261 ] )
262 );
263 }
264 public function get_share_icon_hover_css( $attributes, $device = '' ) {
265 return [ 'fill' => Color::get_css( isset( $attributes['shareButtonIconColorH'] ) ? $attributes['shareButtonIconColorH'] : '' ) . '!important' ];
266 }
267 public function shareItemIconSVG( $attributes, $device = '' ) {
268 return Range::get_css( [
269 'attributeValue' => $attributes['shareItemIconSize'],
270 'attribute_object_key' => 'value',
271 'isResponsive' => false,
272 'defaultValue' => 42,
273 'hasUnit' => true,
274 'unitDefaultValue' => 'px',
275 'property' => 'height',
276 'device' => $device,
277 ] );
278 }
279
280 public function get_share_item_css( $attributes, $device = '' ) {
281 $css = [];
282 $range_width = Range::get_css([
283 'attributeValue' => $attributes['itemIconWidth'],
284 'attribute_object_key' => 'value',
285 'isResponsive' => false,
286 'defaultValue' => 43,
287 'hasUnit' => true,
288 'unitDefaultValue' => 'px',
289 'property' => 'width',
290 'device' => $device,
291 ]);
292 $range_height = Range::get_css([
293 'attributeValue' => $attributes['itemIconHeight'],
294 'attribute_object_key' => 'value',
295 'isResponsive' => false,
296 'defaultValue' => 42,
297 'hasUnit' => true,
298 'unitDefaultValue' => 'px',
299 'property' => 'height',
300 'device' => $device,
301 ] );
302 return array_merge( $css, $range_width, $range_height );
303 }
304 public function get_item_border_css( $attributes, $device = '' ) {
305 $css = ( isset( $attributes['itemBorder'] )
306 ? Border::get_css( $attributes['itemBorder'], '', $device )
307 : [] );
308 return array_merge(
309 $css,
310 BoxShadow::get_css( $attributes['shareItemShadow'], '', $device ),
311 );
312 }
313 public function get_Item_border_hover_css( $attributes, $device = '' ) {
314 return array_merge(
315 ( isset( $attributes['itemBorder'] ) ? Border::get_hover_css( $attributes['itemBorder'], '', $device ) : [] ),
316 BoxShadow::get_hover_css( $attributes['shareItemShadow'], '', $device )
317 );
318 }
319 public function get_share_item_text_css( $attributes, $device = '' ) {
320 $css = [];
321 $range_width = Range::get_css([
322 'attributeValue' => $attributes['itemTextWidth'],
323 'attribute_object_key' => 'value',
324 'isResponsive' => false,
325 'defaultValue' => 80,
326 'hasUnit' => true,
327 'unitDefaultValue' => 'px',
328 'property' => 'width',
329 'device' => $device,
330 ]);
331 $range_height = Range::get_css( [
332 'attributeValue' => $attributes['itemTextHeight'],
333 'attribute_object_key' => 'value',
334 'isResponsive' => false,
335 'defaultValue' => 42,
336 'hasUnit' => true,
337 'unitDefaultValue' => 'px',
338 'property' => 'height',
339 'device' => $device,
340 ] );
341 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
342 return array_merge(
343 $css,
344 $range_width,
345 $range_height,
346 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : [],
347 isset( $attributes['typography'] ) ? Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ) : [],
348 isset( $attributes['textShadow'] ) ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : [],
349 isset( $attributes['textStroke'] ) ? TextStroke::get_css( $attributes['textStroke'], '', $device ) : []
350 );
351 }
352
353 }
354