PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.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 / paypal-button / block.php

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

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