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 +108 -31 2.9.1 → 2.14.0 View file →
@@ -13,8 +13,10 @@
13 13 use ABlocks\Controls\Alignment;
14 14 use ABlocks\Controls\Typography;
15 15 use ABlocks\Controls\Border;
16 16 use ABlocks\Controls\TextShadow;
17 +use ABlocks\Classes\CssGeneratorV2;
18 +use ABlocks\Controls\Color;
17 19
18 20
19 21
20 22 class Block extends BlockBaseAbstract {
@@ -19,16 +21,85 @@
19 21
20 22 class Block extends BlockBaseAbstract {
21 23 protected $block_name = 'coupon';
22 24
23 - public function build_css( $attributes ) {
24 - $css_generator = new CssGenerator( $attributes );
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 + );
25 34
26 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(
27 97 '{{WRAPPER}}',
28 98 $this->get_wrapper_css( $attributes ),
29 99 $this->get_wrapper_css( $attributes, 'Tablet' ),
30 - $this->get_wrapper_css( $attributes, 'Mobile' )
100 + $this->get_wrapper_css( $attributes, 'Mobile' ),
101 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
31 102 );
32 103
33 104 $css_generator->add_class_styles(
34 105 '{{WRAPPER}} .ablocks-icon-wrap',
@@ -33,16 +104,25 @@
33 104 $css_generator->add_class_styles(
34 105 '{{WRAPPER}} .ablocks-icon-wrap',
35 106 Icon::get_wrapper_css( $attributes ),
36 107 Icon::get_wrapper_css( $attributes, 'Tablet' ),
37 - Icon::get_wrapper_css( $attributes, 'Mobile' )
108 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
109 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
38 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 + );
39 118
40 119 $css_generator->add_class_styles(
41 120 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
42 121 Icon::get_element_image_css( $attributes ),
43 122 Icon::get_element_image_css( $attributes, 'Tablet' ),
44 - Icon::get_element_image_css( $attributes, 'Mobile' )
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 ); } )
45 125 );
46 126 $css_generator->add_class_styles(
47 127 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
48 128 Icon::get_element_image_hover_css( $attributes ),
@@ -47,8 +127,9 @@
47 127 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
48 128 Icon::get_element_image_hover_css( $attributes ),
49 129 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
50 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 ); } )
51 132 );
52 133 $css_generator->add_class_styles(
53 134 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
54 135 Icon::get_element_css( $attributes ),
@@ -53,8 +134,9 @@
53 134 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
54 135 Icon::get_element_css( $attributes ),
55 136 Icon::get_element_css( $attributes, 'Tablet' ),
56 137 Icon::get_element_css( $attributes, 'Mobile' ),
138 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } )
57 139 );
58 140 $css_generator->add_class_styles(
59 141 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
60 142 Icon::get_element_image_hover_css( $attributes ),
@@ -59,8 +141,9 @@
59 141 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
60 142 Icon::get_element_image_hover_css( $attributes ),
61 143 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
62 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 ); } )
63 146 );
64 147
65 148 $css_generator->add_class_styles(
66 149 '{{WRAPPER}} .ablocks-coupon-code',
@@ -65,9 +148,10 @@
65 148 $css_generator->add_class_styles(
66 149 '{{WRAPPER}} .ablocks-coupon-code',
67 150 $this->get_coupon_text_css( $attributes ),
68 151 $this->get_coupon_text_css( $attributes, 'Tablet' ),
69 - $this->get_coupon_text_css( $attributes, 'Mobile' )
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 ); } )
70 154 );
71 155
72 156 $css_generator->add_class_styles(
73 157 '{{WRAPPER}} .ablocks-coupon-clipboard',
@@ -72,13 +156,20 @@
72 156 $css_generator->add_class_styles(
73 157 '{{WRAPPER}} .ablocks-coupon-clipboard',
74 158 $this->get_btn_text_css( $attributes ),
75 159 $this->get_btn_text_css( $attributes, 'Tablet' ),
76 - $this->get_btn_text_css( $attributes, 'Mobile' )
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 ); } )
77 162 );
78 163
79 164 return $css_generator->generate_css();
80 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 + }
81 172
82 173
83 174 public function get_wrapper_css( $attributes, $device = '' ) {
84 175 $css = [];
@@ -90,50 +181,36 @@
90 181 return $css;
91 182 }
92 183
93 184 public function get_button_hover_css( $attributes, $device = '' ) {
94 - $css = [];
95 -
96 - if ( isset( $attributes['textColorH'] ) ) {
97 - $css['color'] = $attributes['textColorH'];
98 - }
99 - if ( isset( $attributes['backgroundH'] ) ) {
100 - $css['background'] = $attributes['backgroundH'];
101 - }
102 -
103 185 return array_merge(
186 + [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
187 + [ 'background' => Color::get_css( isset( $attributes['backgroundH'] ) ? $attributes['backgroundH'] : '' ) ],
104 188 isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
105 - $css
106 189 );
107 190 }
108 191
109 192
110 193 public function get_coupon_text_css( $attributes, $device = '' ) {
111 - $css = [
112 - 'color' => $attributes['couponCodeColor'],
113 - 'background' => $attributes['couponCodeBgColor'],
114 - ];
115 -
194 + $typographyGlobal = ( isset( $attributes['couponTypographyGlobal'] ) ? $attributes['couponTypographyGlobal'] : '' );
116 195 return array_merge(
117 - $css,
196 + [ 'color' => Color::get_css( isset( $attributes['couponCodeColor'] ) ? $attributes['couponCodeColor'] : '' ) ],
197 + [ 'background' => Color::get_css( isset( $attributes['couponCodeBgColor'] ) ? $attributes['couponCodeBgColor'] : '' ) ],
118 198 isset( $attributes['couponBorder'] ) ? Border::get_css( $attributes['couponBorder'], '', $device ) : [],
119 199 isset( $attributes['couponPadding'] ) ? Dimensions::get_css( $attributes['couponPadding'], 'padding', $device ) : [],
120 - Typography::get_css( $attributes['couponTypography'], '', $device ),
200 + Typography::get_css( $attributes['couponTypography'], '', $device, $typographyGlobal ),
121 201 TextShadow::get_css( $attributes['couponTextShadow'], '', $device )
122 202 );
123 203 }
124 204
125 205 public function get_btn_text_css( $attributes, $device = '' ) {
126 - $css = [
127 - 'color' => $attributes['couponBtnTextColor'],
128 - 'background' => $attributes['couponBtnBgColor'],
129 - ];
130 -
206 + $typographyGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
131 207 return array_merge(
132 - $css,
208 + [ 'color' => Color::get_css( isset( $attributes['couponBtnTextColor'] ) ? $attributes['couponBtnTextColor'] : '' ) ],
209 + [ 'background' => Color::get_css( isset( $attributes['couponBtnBgColor'] ) ? $attributes['couponBtnBgColor'] : '' ) ],
133 210 Border::get_css( $attributes['buttonBorder'], '', $device ),
134 211 Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device ),
135 - Typography::get_css( $attributes['buttonTypography'], '', $device ),
212 + Typography::get_css( $attributes['buttonTypography'], '', $device, $typographyGlobal ),
136 213 TextShadow::get_css( $attributes['buttonTextShadow'], '', $device )
137 214 );
138 215 }
139 216