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

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

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