PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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.9.1, at includes/blocks/paypal-button/block.php

193 lines 5.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\Controls\Alignment;
11 use ABlocks\Controls\Border;
12 use ABlocks\Controls\BoxShadow;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\TextShadow;
16 use ABlocks\Controls\Icon;
17 use ABlocks\Controls\Range;
18
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'paypal-button';
22
23 public function build_css( $attributes ) {
24
25 // Generate CSS start
26 $css_generator = new CssGenerator( $attributes, $this->block_name );
27
28 // Generate wrapper CSS start
29 $css_generator->add_class_styles(
30 '{{WRAPPER}}',
31 $this->get_wrapper_css( $attributes ),
32 $this->get_wrapper_css( $attributes, 'Tablet' ),
33 $this->get_wrapper_css( $attributes, 'Mobile' )
34 );
35 // Generate wrapper CSS end
36
37 // Generate button CSS start
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button',
40 $this->get_button_css( $attributes ),
41 $this->get_button_css( $attributes, 'Tablet' ),
42 $this->get_button_css( $attributes, 'Mobile' )
43 );
44 // Generate button CSS end
45
46 // Generate button hover CSS start
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button:hover',
49 $this->get_button_hover_css( $attributes ),
50 $this->get_button_hover_css( $attributes, 'Tablet' ),
51 $this->get_button_hover_css( $attributes, 'Mobile' )
52 );
53
54 // Generate button icon hover CSS
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
57 $this->get_icon_hover_css( $attributes ),
58 $this->get_icon_hover_css( $attributes, 'Tablet' ),
59 $this->get_icon_hover_css( $attributes, 'Mobile' )
60 );
61
62 // Generate button text CSS start
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .ablocks-block-container .ablocks-paypal-button .ablocks-paypal-button__text',
65 $this->get_button_text_css( $attributes )
66 );
67
68 // Generate button icon CSS start
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-icon-wrap',
71 Icon::get_wrapper_css( $attributes ),
72 Icon::get_wrapper_css( $attributes, 'Tablet' ),
73 Icon::get_wrapper_css( $attributes, 'Mobile' )
74 );
75
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
78 Icon::get_element_image_css( $attributes ),
79 Icon::get_element_image_css( $attributes, 'Tablet' ),
80 Icon::get_element_image_css( $attributes, 'Tablet' ),
81 );
82 $css_generator->add_class_styles(
83 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
84 Icon::get_element_image_hover_css( $attributes ),
85 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
86 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
87 );
88 $css_generator->add_class_styles(
89 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
90 Icon::get_element_css( $attributes ),
91 Icon::get_element_css( $attributes, 'Tablet' ),
92 Icon::get_element_css( $attributes, 'Mobile' ),
93 );
94 $css_generator->add_class_styles(
95 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
96 Icon::get_element_image_hover_css( $attributes ),
97 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
98 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
99 );
100
101 return $css_generator->generate_css();
102 }
103
104 public function get_wrapper_css( $attributes, $device = '' ) {
105 $css = [];
106 $position = isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] !== 'stretch';
107
108 if ( $position ) {
109 $css['text-align'] = $attributes['position'][ 'value' . $device ];
110 }
111
112 return $css;
113 }
114
115 public function get_button_css( $attributes, $device = '' ) {
116 $css = [];
117
118 if ( ! empty( $attributes['background'] ) ) {
119 $css['background'] = $attributes['background'];
120 } else {
121 $css['background'] = $attributes['buttonType'];
122 }
123
124 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
125 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
126 }
127
128 if ( isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] === 'stretch' ) {
129 $css['width'] = '100%';
130 }
131
132 return array_merge(
133 Range::get_css([
134 'attributeValue' => $attributes['iconSpace'],
135 'attribute_object_key' => 'value',
136 'isResponsive' => true,
137 'defaultValue' => 10,
138 'hasUnit' => true,
139 'unitDefaultValue' => 'px',
140 'property' => 'column-gap',
141 'device' => $device,
142 ]),
143 $css,
144 [ 'color' => $attributes['textColor'] ?? '#000000' ],
145 Border::get_css( $attributes['border'], '', $device ),
146 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
147 Typography::get_css( $attributes['typography'], '', $device ),
148 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
149 );
150 }
151
152 public function get_button_hover_css( $attributes, $device = '' ) {
153 $css = [];
154 if ( ! empty( $attributes['textColorH'] ) ) {
155 $css['color'] = $attributes['textColorH'];
156 }
157
158 if ( ! empty( $attributes['backgroundH'] ) ) {
159 $css['background'] = $attributes['backgroundH'];
160 }
161
162 return array_merge(
163 Range::get_css([
164 'attributeValue' => $attributes['transition'],
165 'attribute_object_key' => 'value',
166 'defaultValue' => 10,
167 'unitDefaultValue' => 's',
168 'property' => 'transition-duration',
169 'device' => $device,
170 ]),
171 $css,
172 Border::get_hover_css( $attributes['border'], '', $device ),
173 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device )
174 );
175 }
176
177 public function get_button_text_css( $attributes, $device = '' ) {
178 return TextShadow::get_css( $attributes['textShadow'] );
179 }
180
181 public function get_icon_hover_css( $attributes, $device = '' ) {
182 $css = [];
183
184 if ( ! empty( $attributes['textColorH'] ) ) {
185 $css['fill'] = $attributes['textColorH'];
186 }
187
188 return $css;
189 }
190
191
192 }
193