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 / paypal-button / block.php

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

305 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\PaypalButton;
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\Border;
13 use ABlocks\Controls\BoxShadow;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\TextShadow;
17 use ABlocks\Controls\Icon;
18 use ABlocks\Controls\Range;
19 use ABlocks\Controls\Color;
20
21
22 class Block extends BlockBaseAbstract {
23 protected $block_name = 'paypal-button';
24
25 public function build_css_v1( $attributes ) {
26
27 // Generate CSS start
28 $css_generator = new CssGenerator( $attributes, $this->block_name );
29
30 // Generate wrapper CSS start
31 $css_generator->add_class_styles(
32 '{{WRAPPER}}',
33 $this->get_wrapper_css( $attributes ),
34 $this->get_wrapper_css( $attributes, 'Tablet' ),
35 $this->get_wrapper_css( $attributes, 'Mobile' ),
36 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
37 );
38 // Generate wrapper CSS end
39
40 // Generate button CSS start
41 $css_generator->add_class_styles(
42 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button',
43 $this->get_button_css( $attributes ),
44 $this->get_button_css( $attributes, 'Tablet' ),
45 $this->get_button_css( $attributes, 'Mobile' ),
46 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } )
47 );
48 // Generate button CSS end
49
50 // Generate button hover CSS start
51 $css_generator->add_class_styles(
52 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button:hover',
53 $this->get_button_hover_css( $attributes ),
54 $this->get_button_hover_css( $attributes, 'Tablet' ),
55 $this->get_button_hover_css( $attributes, 'Mobile' ),
56 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_hover_css( $attributes, $device ); } )
57 );
58
59 // Generate button icon hover CSS
60 $css_generator->add_class_styles(
61 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
62 $this->get_icon_hover_css( $attributes ),
63 $this->get_icon_hover_css( $attributes, 'Tablet' ),
64 $this->get_icon_hover_css( $attributes, 'Mobile' ),
65 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_hover_css( $attributes, $device ); } )
66 );
67
68 // Generate button text CSS start
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button .ablocks-paypal-button__text',
71 $this->get_button_text_css( $attributes )
72 );
73
74 // Generate button icon CSS start
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .ablocks-icon-wrap',
77 Icon::get_wrapper_css( $attributes ),
78 Icon::get_wrapper_css( $attributes, 'Tablet' ),
79 Icon::get_wrapper_css( $attributes, 'Mobile' ),
80 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
81 );
82 $css_generator->add_class_styles(
83 '{{WRAPPER}} .ablocks-icon-wrap:hover',
84 Icon::get_wrapper_hover_css( $attributes ),
85 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
86 Icon::get_wrapper_hover_css( $attributes, 'Mobile' ),
87 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } )
88 );
89
90 $css_generator->add_class_styles(
91 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
92 Icon::get_element_image_css( $attributes ),
93 Icon::get_element_image_css( $attributes, 'Tablet' ),
94 Icon::get_element_image_css( $attributes, 'Tablet' ),
95 );
96 $css_generator->add_class_styles(
97 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
98 Icon::get_element_image_hover_css( $attributes ),
99 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
100 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
101 );
102 $css_generator->add_class_styles(
103 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
104 Icon::get_element_css( $attributes ),
105 Icon::get_element_css( $attributes, 'Tablet' ),
106 Icon::get_element_css( $attributes, 'Mobile' ),
107 );
108 $css_generator->add_class_styles(
109 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
110 Icon::get_element_image_hover_css( $attributes ),
111 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
112 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
113 );
114
115 return $css_generator->generate_css();
116 }
117
118 public function build_css_v2( $attributes ) {
119
120 // Generate CSS start
121 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
122
123 // Generate wrapper CSS start
124 $css_generator->add_class_styles(
125 '{{WRAPPER}}',
126 $this->get_wrapper_css( $attributes ),
127 $this->get_wrapper_css( $attributes, 'Tablet' ),
128 $this->get_wrapper_css( $attributes, 'Mobile' ),
129 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
130 );
131 // Generate wrapper CSS end
132
133 // Generate button CSS start
134 $css_generator->add_class_styles(
135 '{{WRAPPER}} .ablocks-paypal-button',
136 $this->get_button_css( $attributes ),
137 $this->get_button_css( $attributes, 'Tablet' ),
138 $this->get_button_css( $attributes, 'Mobile' ),
139 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } )
140 );
141 // Generate button CSS end
142
143 // Generate button hover CSS start
144 $css_generator->add_class_styles(
145 '{{WRAPPER}} .ablocks-paypal-button:hover',
146 $this->get_button_hover_css( $attributes ),
147 $this->get_button_hover_css( $attributes, 'Tablet' ),
148 $this->get_button_hover_css( $attributes, 'Mobile' ),
149 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_hover_css( $attributes, $device ); } )
150 );
151
152 // Generate button icon hover CSS
153 $css_generator->add_class_styles(
154 '{{WRAPPER}} .ablocks-paypal-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
155 $this->get_icon_hover_css( $attributes ),
156 $this->get_icon_hover_css( $attributes, 'Tablet' ),
157 $this->get_icon_hover_css( $attributes, 'Mobile' ),
158 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_hover_css( $attributes, $device ); } )
159 );
160
161 // Generate button text CSS start
162 $css_generator->add_class_styles(
163 '{{WRAPPER}} .ablocks-paypal-button .ablocks-paypal-button__text',
164 $this->get_button_text_css( $attributes )
165 );
166
167 // Generate button icon CSS start
168 $css_generator->add_class_styles(
169 '{{WRAPPER}} .ablocks-icon-wrap',
170 Icon::get_wrapper_css( $attributes ),
171 Icon::get_wrapper_css( $attributes, 'Tablet' ),
172 Icon::get_wrapper_css( $attributes, 'Mobile' ),
173 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
174 );
175 $css_generator->add_class_styles(
176 '{{WRAPPER}} .ablocks-icon-wrap:hover',
177 Icon::get_wrapper_hover_css( $attributes ),
178 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
179 Icon::get_wrapper_hover_css( $attributes, 'Mobile' ),
180 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } )
181 );
182
183 $css_generator->add_class_styles(
184 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
185 Icon::get_element_image_css( $attributes ),
186 Icon::get_element_image_css( $attributes, 'Tablet' ),
187 Icon::get_element_image_css( $attributes, 'Tablet' ),
188 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
189 );
190 $css_generator->add_class_styles(
191 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
192 Icon::get_element_image_hover_css( $attributes ),
193 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
194 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
195 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
196 );
197 $css_generator->add_class_styles(
198 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
199 Icon::get_element_css( $attributes ),
200 Icon::get_element_css( $attributes, 'Tablet' ),
201 Icon::get_element_css( $attributes, 'Mobile' ),
202 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } )
203 );
204 $css_generator->add_class_styles(
205 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
206 Icon::get_element_image_hover_css( $attributes ),
207 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
208 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
209 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
210 );
211
212 return $css_generator->generate_css();
213 }
214
215 public function build_css( $attributes ) {
216 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
217 return $this->build_css_v2( $attributes );
218 }
219 return $this->build_css_v1( $attributes );
220 }
221
222 public function get_wrapper_css( $attributes, $device = '' ) {
223 $css = [];
224 $position = isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] !== 'stretch';
225
226 if ( $position ) {
227 $css['text-align'] = $attributes['position'][ 'value' . $device ];
228 }
229
230 return $css;
231 }
232
233 public function get_button_css( $attributes, $device = '' ) {
234 $css = [];
235
236 if ( ! empty( $attributes['background'] ) ) {
237 $css['background'] = Color::get_css( isset( $attributes['background'] ) ? $attributes['background'] : '' );
238 } else {
239 $css['background'] = $attributes['buttonType'];
240 }
241
242 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
243 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
244 }
245
246 if ( isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] === 'stretch' ) {
247 $css['width'] = '100%';
248 }
249 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
250 return array_merge(
251 Range::get_css([
252 'attributeValue' => $attributes['iconSpace'],
253 'attribute_object_key' => 'value',
254 'isResponsive' => true,
255 'defaultValue' => 10,
256 'hasUnit' => true,
257 'unitDefaultValue' => 'px',
258 'property' => 'column-gap',
259 'device' => $device,
260 ]),
261 $css,
262 [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ],
263 Border::get_css( $attributes['border'], '', $device ),
264 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
265 Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ),
266 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
267 );
268 }
269
270 public function get_button_hover_css( $attributes, $device = '' ) {
271 $css = [];
272 return array_merge(
273 [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
274 [ 'background' => Color::get_css( isset( $attributes['backgroundH'] ) ? $attributes['backgroundH'] : '' ) ],
275 Range::get_css([
276 'attributeValue' => $attributes['transition'],
277 'attribute_object_key' => 'value',
278 'defaultValue' => 10,
279 'unitDefaultValue' => 's',
280 'property' => 'transition-duration',
281 'device' => $device,
282 ]),
283 $css,
284 Border::get_hover_css( $attributes['border'], '', $device ),
285 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device )
286 );
287 }
288
289 public function get_button_text_css( $attributes, $device = '' ) {
290 return TextShadow::get_css( $attributes['textShadow'] );
291 }
292
293 public function get_icon_hover_css( $attributes, $device = '' ) {
294 $css = [];
295
296 if ( ! empty( $attributes['textColorH'] ) ) {
297 $css['fill'] = $attributes['textColorH'];
298 }
299
300 return $css;
301 }
302
303
304 }
305