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 / controls / background.php

background.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/controls/background.php

323 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Controls;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\ControlBaseAbstract;
9
10 class Background extends ControlBaseAbstract {
11 public static function get_attribute_default_value( $is_responsive = false ) {
12 if ( $is_responsive ) {
13 return [
14 'backgroundType' => 'none',
15 'backgroundTypeH' => 'none',
16 'backgroundColor' => '',
17 'backgroundColorH' => '',
18 'imgId' => '',
19 'imgIdTablet' => '',
20 'imgIdMobile' => '',
21 'imgUrl' => '',
22 'imgUrlTablet' => '',
23 'imgUrlMobile' => '',
24 'imgSize' => '',
25 'imgSizeTablet' => '',
26 'imgSizeMobile' => '',
27 'imgPosition' => '',
28 'imgPositionTablet' => '',
29 'imgPositionMobile' => '',
30 'imgXPositionUnit' => 'px',
31 'imgXPositionUnitTablet' => '',
32 'imgXPositionUnitMobile' => '',
33 'imgXPosition' => '',
34 'imgXPositionTablet' => '',
35 'imgXPositionMobile' => '',
36 'imgYPositionUnit' => 'px',
37 'imgYPositionUnitTablet' => '',
38 'imgYPositionUnitMobile' => '',
39 'imgYPosition' => '',
40 'imgYPositionTablet' => '',
41 'imgYPositionMobile' => '',
42 'imgAttachment' => '',
43 'imgRepeat' => '',
44 'imgRepeatTablet' => '',
45 'imgRepeatMobile' => '',
46 'imgDisplaySize' => '',
47 'imgDisplaySizeTablet' => '',
48 'imgDisplaySizeMobile' => '',
49 'imgDisplaySizeWidth' => '',
50 'imgDisplaySizeWidthTablet' => '',
51 'imgDisplaySizeWidthMobile' => '',
52 'imgDisplaySizeWidthUnit' => 'px',
53 'imgDisplaySizeWidthUnitTablet' => '',
54 'imgDisplaySizeWidthUnitMobile' => '',
55 // Background image - Hover
56 'imgIdH' => '',
57 'imgIdTabletH' => '',
58 'imgIdMobileH' => '',
59 'imgUrlH' => '',
60 'imgUrlHTablet' => '',
61 'imgUrlHMobile' => '',
62 'imgSizeH' => '',
63 'imgSizeHTablet' => '',
64 'imgSizeHMobile' => '',
65 'imgPositionH' => '',
66 'imgPositionHTablet' => '',
67 'imgPositionHMobile' => '',
68 'imgXPositionUnitH' => 'px',
69 'imgXPositionUnitHTablet' => '',
70 'imgXPositionUnitHMobile' => '',
71 'imgXPositionH' => '',
72 'imgXPositionHTablet' => '',
73 'imgXPositionHMobile' => '',
74 'imgYPositionUnitH' => 'px',
75 'imgYPositionUnitHTablet' => '',
76 'imgYPositionUnitHMobile' => '',
77 'imgYPositionH' => '',
78 'imgYPositionHTablet' => '',
79 'imgYPositionHMobile' => '',
80 'imgAttachmentH' => '',
81 'imgRepeatH' => '',
82 'imgRepeatHTablet' => '',
83 'imgRepeatHMobile' => '',
84 'imgDisplaySizeH' => '',
85 'imgDisplaySizeHTablet' => '',
86 'imgDisplaySizeHMobile' => '',
87 'imgDisplaySizeWidthH' => '',
88 'imgDisplaySizeWidthHTablet' => '',
89 'imgDisplaySizeWidthHMobile' => '',
90 'imgDisplaySizeWidthHUnit' => 'px',
91 'imgDisplaySizeWidthHUnitTablet' => '',
92 'imgDisplaySizeWidthHUnitMobile' => '',
93 // Background image transition
94 'transitionDuration' => '',
95 // Background video
96 'videoUrl' => '',
97 'youtubeURL' => '',
98 'vimeoURL' => '',
99 'selfHostedURL' => '',
100 'externalLink' => false,
101 'videoSource' => 'none',
102 'videoPlayOnce' => '',
103 'videoStartTime' => '',
104 'videoEndTime' => '',
105 'playOnMobile' => '',
106 'videoPrivacyMode' => '',
107 'fallbackImageUrl' => '',
108 ];
109 }//end if
110 return [
111 'backgroundType' => 'none',
112 'backgroundTypeH' => 'none',
113 'backgroundColor' => '',
114 'backgroundColorH' => '',
115 // Background image - Normal
116 'imgId' => '',
117 'imgUrl' => '',
118 'imgSize' => '',
119 'imgPosition' => '',
120 'imgAttachment' => '',
121 'imgRepeat' => '',
122 'imgDisplaySize' => '',
123 'imgdisplaySizeWidth' => '',
124 'imgDisplaySizeWidthUnit' => 'px',
125 'imgXPositionUnit' => 'px',
126 'imgXPosition' => '',
127 'imgYPositionUnit' => 'px',
128 'imgYPosition' => '',
129 // Background image - Hover
130 'imgIdH' => '',
131 'imgUrlH' => '',
132 'imgSizeH' => '',
133 'imgPositionH' => '',
134 'imgXPositionUnitH' => 'px',
135 'imgXPositionH' => '',
136 'imgYPositionUnitH' => 'px',
137 'imgYPositionH' => '',
138 'imgAttachmentH' => '',
139 'imgRepeatH' => '',
140 'imgDisplaySizeH' => '',
141 'imgDisplaySizeWidthH' => '',
142 'imgDisplaySizeWidthHUnit' => 'px',
143 // Background image transition
144 'transitionDuration' => '',
145 // Background video
146 'videoUrl' => '',
147 'youtubeURL' => '',
148 'vimeoURL' => '',
149 'selfHostedURL' => '',
150 'externalLink' => false,
151 'videoSource' => 'none',
152 'videoPlayOnce' => '',
153 'videoStartTime' => '',
154 'videoEndTime' => '',
155 'playOnMobile' => '',
156 'videoPrivacyMode' => '',
157 'fallbackImageUrl' => '',
158 ];
159 }
160
161 public static function get_attribute( $attribute_name, $is_responsive = false ) {
162 return [
163 $attribute_name => [
164 'type' => 'object',
165 'default' => self::get_attribute_default_value( $is_responsive ),
166 ]
167 ];
168 }
169
170 public static function get_css( $attribute_value, $property = '', $device = '' ) {
171 $value = wp_parse_args( $attribute_value, self::get_attribute_default_value( (bool) $device ) );
172 $css = [];
173
174 if ( $device ) {
175 $unitXPositionUnit = self::get_unit(
176 [
177 'unit' => isset( $value['imgXPositionUnit'] ) ? $value['imgXPositionUnit'] : '',
178 'unitTablet' => isset( $value['imgXPositionUnitTablet'] ) ? $value['imgXPositionUnitTablet'] : '',
179 'unitMobile' => isset( $value['imgXPositionUnitMobile'] ) ? $value['imgXPositionUnitMobile'] : '',
180 ],
181 $device
182 );
183 $unitYPositionUnit = self::get_unit(
184 [
185 'unit' => isset( $value['imgYPositionUnit'] ) ? $value['imgYPositionUnit'] : '',
186 'unitTablet' => isset( $value['imgYPositionUnitTablet'] ) ? $value['imgYPositionUnitTablet'] : '',
187 'unitMobile' => isset( $value['imgYPositionUnitMobile'] ) ? $value['imgYPositionUnitMobile'] : '',
188 ],
189 $device
190 );
191 $imgDisplaySizeWidthUnit = self::get_unit(
192 [
193 'unit' => isset( $value['imgDisplaySizeWidthUnit'] ) ? $value['imgDisplaySizeWidthUnit'] : '',
194 'unitTablet' => isset( $value['imgDisplaySizeWidthUnitTablet'] ) ? $value['imgDisplaySizeWidthUnitTablet'] : '',
195 'unitMobile' => isset( $value['imgDisplaySizeWidthUnitMobile'] ) ? $value['imgDisplaySizeWidthUnitMobile'] : '',
196 ],
197 $device
198 );
199 } else {
200 $unitXPositionUnit = isset( $value['imgXPositionUnit'] ) ? $value['imgXPositionUnit'] : '';
201 $unitYPositionUnit = isset( $value['imgYPositionUnit'] ) ? $value['imgYPositionUnit'] : '';
202 $imgDisplaySizeWidthUnit = isset( $value['imgDisplaySizeWidthUnit'] ) ? $value['imgDisplaySizeWidthUnit'] : '';
203 }//end if
204
205 if ( 'image' === $value['backgroundType'] && '' !== $value[ 'imgUrl' . $device ] ) {
206 // background image
207 $css[ $property . '-image' ] = 'url("' . $value[ 'imgUrl' . $device ] . '")';
208 // background-position css
209 if ( '' !== $value[ 'imgPosition' . $device ] ) {
210 if ( 'custom' === $value[ 'imgPosition' . $device ] ) {
211 $imgXPosition = isset( $value[ 'imgXPosition' . $device ] ) ? $value[ 'imgXPosition' . $device ] : '0';
212 $imgYPosition = isset( $value[ 'imgYPosition' . $device ] ) ? $value[ 'imgYPosition' . $device ] : '0';
213 $css[ $property . '-position' ] = $imgXPosition . $unitXPositionUnit . $imgYPosition . $unitYPositionUnit;
214 } else {
215 $css[ $property . '-position' ] = $value[ 'imgPosition' . $device ];
216 }
217 }
218 // background-attachments css
219 if ( isset( $value[ 'imgAttachment' . $device ] ) && '' !== $value[ 'imgAttachment' . $device ] ) {
220 $css[ $property . '-attachment' ] = $value[ 'imgAttachment' . $device ];
221 }
222 // background-repeat css
223 if ( '' !== $value[ 'imgRepeat' . $device ] ) {
224 $css[ $property . '-repeat' ] = $value[ 'imgRepeat' . $device ];
225 }
226 // background-size css
227 if ( '' !== $value[ 'imgDisplaySize' . $device ] ) {
228 if ( 'custom' === $value[ 'imgDisplaySize' . $device ] ) {
229 $css[ $property . '-size' ] = isset( $value[ 'imgDisplaySizeWidth' . $device ] ) ? $value[ 'imgDisplaySizeWidth' . $device ] . $imgDisplaySizeWidthUnit . ' auto' : '';
230 } else {
231 $css[ $property . '-size' ] = $value[ 'imgDisplaySize' . $device ];
232 }
233 }
234 } elseif ( 'video' === $value['backgroundType'] && '' !== $value['fallbackImageUrl'] ) {
235 $css[ $property . '-image' ] = 'url("' . $value['fallbackImageUrl'] . '")';
236 $css[ $property . '-size' ] = 'cover';
237 } elseif ( 'color' === $value['backgroundType'] && $value['backgroundColor'] ) {
238 $css[ $property ] = $value['backgroundColor'];
239 }//end if
240
241 if ( '' !== $value['transitionDuration'] ) {
242 $css['transition'] = $property . ' ' . $value['transitionDuration'] . 's ease';
243 }
244
245 return $css;
246 }
247
248 public static function get_hover_css( $attribute_value, $property = '', $device = '' ) {
249 $value = wp_parse_args( $attribute_value, self::get_attribute_default_value( (bool) $device ) );
250 $css = [];
251
252 if ( $device ) {
253 $unitXPositionUnitH = self::get_unit(
254 [
255 'unit' => isset( $value['imgXPositionUnitH'] ) ? $value['imgXPositionUnitH'] : '',
256 'unitTablet' => isset( $value['imgXPositionUnitHTablet'] ) ? $value['imgXPositionUnitHTablet'] : '',
257 'unitMobile' => isset( $value['imgXPositionUnitHMobile'] ) ? $value['imgXPositionUnitHMobile'] : '',
258 ],
259 $device
260 );
261 $unitYPositionUnitH = self::get_unit(
262 [
263 'unit' => isset( $value['imgYPositionUnitH'] ) ? $value['imgYPositionUnitH'] : '',
264 'unitTablet' => isset( $value['imgYPositionUnitHTablet'] ) ? $value['imgYPositionUnitHTablet'] : '',
265 'unitMobile' => isset( $value['imgYPositionUnitHMobile'] ) ? $value['imgYPositionUnitHMobile'] : '',
266 ],
267 $device
268 );
269 $imgDisplaySizeWidthUnitH = self::get_unit(
270 [
271 'unit' => isset( $value['imgDisplaySizeWidthHUnit'] ) ? $value['imgDisplaySizeWidthHUnit'] : '',
272 'unitTablet' => isset( $value['imgDisplaySizeWidthHUnitTablet'] ) ? $value['imgDisplaySizeWidthHUnitTablet'] : '',
273 'unitMobile' => isset( $value['imgDisplaySizeWidthHUnitMobile'] ) ? $value['imgDisplaySizeWidthHUnitMobile'] : '',
274 ],
275 $device
276 );
277 } else {
278 $unitXPositionUnitH = isset( $value['imgXPositionUnitH'] ) ? $value['imgXPositionUnitH'] : '';
279 $unitYPositionUnitH = isset( $value['imgYPositionUnitH'] ) ? $value['imgYPositionUnitH'] : '';
280 $imgDisplaySizeWidthUnitH = isset( $value['imgDisplaySizeWidthHUnit'] ) ? $value['imgDisplaySizeWidthHUnit'] : '';
281 }//end if
282
283 if ( 'image' === $value['backgroundTypeH'] && '' !== $value[ 'imgUrlH' . $device ] ) {
284 // background image
285 $css[ $property . '-image' ] = 'url("' . $value[ 'imgUrlH' . $device ] . '")';
286 // background-position css
287 if ( '' !== $value[ 'imgPositionH' . $device ] ) {
288 if ( 'custom' === $value[ 'imgPositionH' . $device ] ) {
289 $imgXPosition = isset( $value[ 'imgXPositionH' . $device ] ) ? $value[ 'imgXPositionH' . $device ] : '0';
290 $imgYPosition = isset( $value[ 'imgYPositionH' . $device ] ) ? $value[ 'imgYPositionH' . $device ] : '0';
291 $css[ $property . '-position' ] = $imgXPosition . $unitXPositionUnitH . $imgYPosition . $unitYPositionUnitH;
292 } else {
293 $css[ $property . '-position' ] = $value[ 'imgPositionH' . $device ];
294 }
295 }
296 // background-attachments css
297 if ( '' !== isset( $value[ 'imgAttachmentH' . $device ] ) ) {
298 $css[ $property . '-attachment' ] = isset( $value[ 'imgAttachmentH' . $device ] );
299 }
300 // background-repeat css
301 if ( '' !== $value[ 'imgRepeatH' . $device ] ) {
302 $css[ $property . '-repeat' ] = $value[ 'imgRepeatH' . $device ];
303 }
304 // background-size css
305 if ( '' !== $value[ 'imgDisplaySizeH' . $device ] ) {
306 if ( 'custom' === $value[ 'imgDisplaySizeH' . $device ] ) {
307 $css[ $property . '-size' ] = isset( $value[ 'imgDisplaySizeWidthH' . $device ] ) ? $value[ 'imgDisplaySizeWidthH' . $device ] . $imgDisplaySizeWidthUnitH . ' auto' : '';
308 } else {
309 $css[ $property . '-size' ] = $value[ 'imgDisplaySizeH' . $device ];
310 }
311 }
312 } elseif ( 'video' === $value['backgroundTypeH'] && '' !== $value['fallbackImageUrlH'] ) {
313 $css[ $property . '-image' ] = 'url("' . $value['fallbackImageUrlH'] . '")';
314 $css[ $property . '-size' ] = 'cover';
315 } elseif ( 'color' === $value['backgroundTypeH'] && $value['backgroundColorH'] ) {
316 $css[ $property ] = $value['backgroundColorH'];
317 }//end if
318
319 return $css;
320 }
321
322 }
323