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
← All changes | includes/blocks/coupon/block.php +223 -0 2.7.5 → 2.14.0 View file →
@@ -1,0 +1,223 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
33 + );
34 +
35 + $css_generator->add_class_styles(
36 + '{{WRAPPER}} .ablocks-icon-wrap',
37 + Icon::get_wrapper_css( $attributes ),
38 + Icon::get_wrapper_css( $attributes, 'Tablet' ),
39 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
40 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
41 + );
42 + $css_generator->add_class_styles(
43 + '{{WRAPPER}} .ablocks-icon-wrap:hover',
44 + Icon::get_wrapper_hover_css( $attributes ),
45 + Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
46 + Icon::get_wrapper_hover_css( $attributes, 'Mobile' ),
47 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } )
48 + );
49 +
50 + $css_generator->add_class_styles(
51 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
52 + Icon::get_element_image_css( $attributes ),
53 + Icon::get_element_image_css( $attributes, 'Tablet' ),
54 + Icon::get_element_image_css( $attributes, 'Mobile' ),
55 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
56 + );
57 + $css_generator->add_class_styles(
58 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
59 + Icon::get_element_image_hover_css( $attributes ),
60 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
61 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
62 + );
63 + $css_generator->add_class_styles(
64 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
65 + Icon::get_element_css( $attributes ),
66 + Icon::get_element_css( $attributes, 'Tablet' ),
67 + Icon::get_element_css( $attributes, 'Mobile' ),
68 + );
69 + $css_generator->add_class_styles(
70 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
71 + Icon::get_element_image_hover_css( $attributes ),
72 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
73 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
74 + );
75 +
76 + $css_generator->add_class_styles(
77 + '{{WRAPPER}} .ablocks-coupon-code',
78 + $this->get_coupon_text_css( $attributes ),
79 + $this->get_coupon_text_css( $attributes, 'Tablet' ),
80 + $this->get_coupon_text_css( $attributes, 'Mobile' ),
81 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_text_css( $attributes, $device ); } )
82 + );
83 +
84 + $css_generator->add_class_styles(
85 + '{{WRAPPER}} .ablocks-coupon-clipboard',
86 + $this->get_btn_text_css( $attributes ),
87 + $this->get_btn_text_css( $attributes, 'Tablet' ),
88 + $this->get_btn_text_css( $attributes, 'Mobile' ),
89 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_btn_text_css( $attributes, $device ); } )
90 + );
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}}',
98 + $this->get_wrapper_css( $attributes ),
99 + $this->get_wrapper_css( $attributes, 'Tablet' ),
100 + $this->get_wrapper_css( $attributes, 'Mobile' ),
101 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
102 + );
103 +
104 + $css_generator->add_class_styles(
105 + '{{WRAPPER}} .ablocks-icon-wrap',
106 + Icon::get_wrapper_css( $attributes ),
107 + Icon::get_wrapper_css( $attributes, 'Tablet' ),
108 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
109 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
110 + );
111 + $css_generator->add_class_styles(
112 + '{{WRAPPER}} .ablocks-icon-wrap:hover',
113 + Icon::get_wrapper_hover_css( $attributes ),
114 + Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
115 + Icon::get_wrapper_hover_css( $attributes, 'Mobile' ),
116 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } )
117 + );
118 +
119 + $css_generator->add_class_styles(
120 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
121 + Icon::get_element_image_css( $attributes ),
122 + Icon::get_element_image_css( $attributes, 'Tablet' ),
123 + Icon::get_element_image_css( $attributes, 'Mobile' ),
124 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
125 + );
126 + $css_generator->add_class_styles(
127 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
128 + Icon::get_element_image_hover_css( $attributes ),
129 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
130 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
131 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
132 + );
133 + $css_generator->add_class_styles(
134 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
135 + Icon::get_element_css( $attributes ),
136 + Icon::get_element_css( $attributes, 'Tablet' ),
137 + Icon::get_element_css( $attributes, 'Mobile' ),
138 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } )
139 + );
140 + $css_generator->add_class_styles(
141 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
142 + Icon::get_element_image_hover_css( $attributes ),
143 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
144 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
145 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
146 + );
147 +
148 + $css_generator->add_class_styles(
149 + '{{WRAPPER}} .ablocks-coupon-code',
150 + $this->get_coupon_text_css( $attributes ),
151 + $this->get_coupon_text_css( $attributes, 'Tablet' ),
152 + $this->get_coupon_text_css( $attributes, 'Mobile' ),
153 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_text_css( $attributes, $device ); } )
154 + );
155 +
156 + $css_generator->add_class_styles(
157 + '{{WRAPPER}} .ablocks-coupon-clipboard',
158 + $this->get_btn_text_css( $attributes ),
159 + $this->get_btn_text_css( $attributes, 'Tablet' ),
160 + $this->get_btn_text_css( $attributes, 'Mobile' ),
161 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_btn_text_css( $attributes, $device ); } )
162 + );
163 +
164 + return $css_generator->generate_css();
165 + }
166 + public function build_css( $attributes ) {
167 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
168 + return $this->build_css_v2( $attributes );
169 + }
170 + return $this->build_css_v1( $attributes );
171 + }
172 +
173 +
174 + public function get_wrapper_css( $attributes, $device = '' ) {
175 + $css = [];
176 +
177 + if ( isset( $attributes['position'][ 'value' . $device ] ) ) {
178 + $css['justify-content'] = $attributes['position'][ 'value' . $device ];
179 + }
180 +
181 + return $css;
182 + }
183 +
184 + public function get_button_hover_css( $attributes, $device = '' ) {
185 + return array_merge(
186 + [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
187 + [ 'background' => Color::get_css( isset( $attributes['backgroundH'] ) ? $attributes['backgroundH'] : '' ) ],
188 + isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
189 + );
190 + }
191 +
192 +
193 + public function get_coupon_text_css( $attributes, $device = '' ) {
194 + $typographyGlobal = ( isset( $attributes['couponTypographyGlobal'] ) ? $attributes['couponTypographyGlobal'] : '' );
195 + return array_merge(
196 + [ 'color' => Color::get_css( isset( $attributes['couponCodeColor'] ) ? $attributes['couponCodeColor'] : '' ) ],
197 + [ 'background' => Color::get_css( isset( $attributes['couponCodeBgColor'] ) ? $attributes['couponCodeBgColor'] : '' ) ],
198 + isset( $attributes['couponBorder'] ) ? Border::get_css( $attributes['couponBorder'], '', $device ) : [],
199 + isset( $attributes['couponPadding'] ) ? Dimensions::get_css( $attributes['couponPadding'], 'padding', $device ) : [],
200 + Typography::get_css( $attributes['couponTypography'], '', $device, $typographyGlobal ),
201 + TextShadow::get_css( $attributes['couponTextShadow'], '', $device )
202 + );
203 + }
204 +
205 + public function get_btn_text_css( $attributes, $device = '' ) {
206 + $typographyGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
207 + return array_merge(
208 + [ 'color' => Color::get_css( isset( $attributes['couponBtnTextColor'] ) ? $attributes['couponBtnTextColor'] : '' ) ],
209 + [ 'background' => Color::get_css( isset( $attributes['couponBtnBgColor'] ) ? $attributes['couponBtnBgColor'] : '' ) ],
210 + Border::get_css( $attributes['buttonBorder'], '', $device ),
211 + Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device ),
212 + Typography::get_css( $attributes['buttonTypography'], '', $device, $typographyGlobal ),
213 + TextShadow::get_css( $attributes['buttonTextShadow'], '', $device )
214 + );
215 + }
216 +
217 + public function get_icon_css( $attributes, $device = '' ) {
218 +
219 + return ! empty( $attributes['iconRotate'] ) ? [ 'transform' => 'rotate(' . $attributes['iconRotate'] . 'deg)' ] : [];
220 +
221 + }
222 +
223 +}