PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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 1.1.2 All 80 releases
ablocks / includes / blocks / coupon / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.0, at includes/blocks/coupon/block.php

209 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Coupon;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Range;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\Icon;
13 use ABlocks\Controls\Alignment;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\Border;
16 use ABlocks\Controls\TextShadow;
17 use ABlocks\Classes\CssGeneratorV2;
18 use ABlocks\Controls\Color;
19
20
21
22 class Block extends BlockBaseAbstract {
23 protected $block_name = 'coupon';
24
25 public function build_css_v1( $attributes ) {
26 $css_generator = new CssGenerator( $attributes, $this->block_name );
27 $css_generator->add_class_styles(
28 '{{WRAPPER}}',
29 $this->get_wrapper_css( $attributes ),
30 $this->get_wrapper_css( $attributes, 'Tablet' ),
31 $this->get_wrapper_css( $attributes, 'Mobile' )
32 );
33
34 $css_generator->add_class_styles(
35 '{{WRAPPER}} .ablocks-icon-wrap',
36 Icon::get_wrapper_css( $attributes ),
37 Icon::get_wrapper_css( $attributes, 'Tablet' ),
38 Icon::get_wrapper_css( $attributes, 'Mobile' )
39 );
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ablocks-icon-wrap:hover',
42 Icon::get_wrapper_hover_css( $attributes ),
43 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
44 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
45 );
46
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
49 Icon::get_element_image_css( $attributes ),
50 Icon::get_element_image_css( $attributes, 'Tablet' ),
51 Icon::get_element_image_css( $attributes, 'Mobile' )
52 );
53 $css_generator->add_class_styles(
54 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
55 Icon::get_element_image_hover_css( $attributes ),
56 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
57 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
58 );
59 $css_generator->add_class_styles(
60 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
61 Icon::get_element_css( $attributes ),
62 Icon::get_element_css( $attributes, 'Tablet' ),
63 Icon::get_element_css( $attributes, 'Mobile' ),
64 );
65 $css_generator->add_class_styles(
66 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
67 Icon::get_element_image_hover_css( $attributes ),
68 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
69 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
70 );
71
72 $css_generator->add_class_styles(
73 '{{WRAPPER}} .ablocks-coupon-code',
74 $this->get_coupon_text_css( $attributes ),
75 $this->get_coupon_text_css( $attributes, 'Tablet' ),
76 $this->get_coupon_text_css( $attributes, 'Mobile' )
77 );
78
79 $css_generator->add_class_styles(
80 '{{WRAPPER}} .ablocks-coupon-clipboard',
81 $this->get_btn_text_css( $attributes ),
82 $this->get_btn_text_css( $attributes, 'Tablet' ),
83 $this->get_btn_text_css( $attributes, 'Mobile' )
84 );
85
86 return $css_generator->generate_css();
87 }
88 public function build_css_v2( $attributes ) {
89 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
90 $css_generator->add_class_styles(
91 '{{WRAPPER}}',
92 $this->get_wrapper_css( $attributes ),
93 $this->get_wrapper_css( $attributes, 'Tablet' ),
94 $this->get_wrapper_css( $attributes, 'Mobile' )
95 );
96
97 $css_generator->add_class_styles(
98 '{{WRAPPER}} .ablocks-icon-wrap',
99 Icon::get_wrapper_css( $attributes ),
100 Icon::get_wrapper_css( $attributes, 'Tablet' ),
101 Icon::get_wrapper_css( $attributes, 'Mobile' )
102 );
103 $css_generator->add_class_styles(
104 '{{WRAPPER}} .ablocks-icon-wrap:hover',
105 Icon::get_wrapper_hover_css( $attributes ),
106 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
107 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
108 );
109
110 $css_generator->add_class_styles(
111 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
112 Icon::get_element_image_css( $attributes ),
113 Icon::get_element_image_css( $attributes, 'Tablet' ),
114 Icon::get_element_image_css( $attributes, 'Mobile' )
115 );
116 $css_generator->add_class_styles(
117 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
118 Icon::get_element_image_hover_css( $attributes ),
119 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
120 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
121 );
122 $css_generator->add_class_styles(
123 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
124 Icon::get_element_css( $attributes ),
125 Icon::get_element_css( $attributes, 'Tablet' ),
126 Icon::get_element_css( $attributes, 'Mobile' ),
127 );
128 $css_generator->add_class_styles(
129 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
130 Icon::get_element_image_hover_css( $attributes ),
131 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
132 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
133 );
134
135 $css_generator->add_class_styles(
136 '{{WRAPPER}} .ablocks-coupon-code',
137 $this->get_coupon_text_css( $attributes ),
138 $this->get_coupon_text_css( $attributes, 'Tablet' ),
139 $this->get_coupon_text_css( $attributes, 'Mobile' )
140 );
141
142 $css_generator->add_class_styles(
143 '{{WRAPPER}} .ablocks-coupon-clipboard',
144 $this->get_btn_text_css( $attributes ),
145 $this->get_btn_text_css( $attributes, 'Tablet' ),
146 $this->get_btn_text_css( $attributes, 'Mobile' )
147 );
148
149 return $css_generator->generate_css();
150 }
151 public function build_css( $attributes ) {
152 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
153 return $this->build_css_v2( $attributes );
154 }
155 return $this->build_css_v1( $attributes );
156 }
157
158
159 public function get_wrapper_css( $attributes, $device = '' ) {
160 $css = [];
161
162 if ( isset( $attributes['position'][ 'value' . $device ] ) ) {
163 $css['justify-content'] = $attributes['position'][ 'value' . $device ];
164 }
165
166 return $css;
167 }
168
169 public function get_button_hover_css( $attributes, $device = '' ) {
170 return array_merge(
171 [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
172 [ 'background' => Color::get_css( isset( $attributes['backgroundH'] ) ? $attributes['backgroundH'] : '' ) ],
173 isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
174 );
175 }
176
177
178 public function get_coupon_text_css( $attributes, $device = '' ) {
179 $typographyGlobal = ( isset( $attributes['couponTypographyGlobal'] ) ? $attributes['couponTypographyGlobal'] : '' );
180 return array_merge(
181 [ 'color' => Color::get_css( isset( $attributes['couponCodeColor'] ) ? $attributes['couponCodeColor'] : '' ) ],
182 [ 'background' => Color::get_css( isset( $attributes['couponCodeBgColor'] ) ? $attributes['couponCodeBgColor'] : '' ) ],
183 isset( $attributes['couponBorder'] ) ? Border::get_css( $attributes['couponBorder'], '', $device ) : [],
184 isset( $attributes['couponPadding'] ) ? Dimensions::get_css( $attributes['couponPadding'], 'padding', $device ) : [],
185 Typography::get_css( $attributes['couponTypography'], '', $device, $typographyGlobal ),
186 TextShadow::get_css( $attributes['couponTextShadow'], '', $device )
187 );
188 }
189
190 public function get_btn_text_css( $attributes, $device = '' ) {
191 $typographyGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
192 return array_merge(
193 [ 'color' => Color::get_css( isset( $attributes['couponBtnTextColor'] ) ? $attributes['couponBtnTextColor'] : '' ) ],
194 [ 'background' => Color::get_css( isset( $attributes['couponBtnBgColor'] ) ? $attributes['couponBtnBgColor'] : '' ) ],
195 Border::get_css( $attributes['buttonBorder'], '', $device ),
196 Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device ),
197 Typography::get_css( $attributes['buttonTypography'], '', $device, $typographyGlobal ),
198 TextShadow::get_css( $attributes['buttonTextShadow'], '', $device )
199 );
200 }
201
202 public function get_icon_css( $attributes, $device = '' ) {
203
204 return ! empty( $attributes['iconRotate'] ) ? [ 'transform' => 'rotate(' . $attributes['iconRotate'] . 'deg)' ] : [];
205
206 }
207
208 }
209