PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / background / background.php

background.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/background/background.php

362 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
3 /**
4 *
5 * Field: background
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_background' ) ) {
12 class CSF_Field_background extends CSF_Fields {
13
14 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
15 parent::__construct( $field, $value, $unique, $where, $parent );
16 }
17
18 public function render() {
19
20 $args = wp_parse_args( $this->field, array(
21 'background_color' => true,
22 'background_image' => true,
23 'background_position' => true,
24 'background_repeat' => true,
25 'background_attachment' => true,
26 'background_size' => true,
27 'background_origin' => false,
28 'background_clip' => false,
29 'background_blend_mode' => false,
30 'background_gradient' => false,
31 'background_gradient_color' => true,
32 'background_gradient_direction' => true,
33 'background_image_preview' => true,
34 'background_auto_attributes' => false,
35 'compact' => false,
36 'background_image_library' => 'image',
37 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
38 'background_image_placeholder' => esc_html__( 'Not selected', 'csf' ),
39 ) );
40
41 if ( $args['compact'] ) {
42 $args['background_color'] = false;
43 $args['background_auto_attributes'] = true;
44 }
45
46 $default_value = array(
47 'background-color' => '',
48 'background-image' => '',
49 'background-position' => '',
50 'background-repeat' => '',
51 'background-attachment' => '',
52 'background-size' => '',
53 'background-origin' => '',
54 'background-clip' => '',
55 'background-blend-mode' => '',
56 'background-gradient-color' => '',
57 'background-gradient-direction' => '',
58 );
59
60 $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
61
62 $this->value = wp_parse_args( $this->value, $default_value );
63
64 echo $this->field_before();
65
66 echo '<div class="csf--background-colors">';
67
68 //
69 // Background Color
70 if ( ! empty( $args['background_color'] ) ) {
71
72 echo '<div class="csf--color">';
73
74 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
75 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'From', 'csf' ) .'</div>' : '';
76
77 CSF::field( array(
78 'id' => 'background-color',
79 'type' => 'color',
80 'default' => $default_value['background-color'],
81 ), $this->value['background-color'], $this->field_name(), 'field/background' );
82
83 echo '</div>';
84
85 }
86
87 //
88 // Background Gradient Color
89 if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) {
90
91 echo '<div class="csf--color">';
92
93 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
94 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'To', 'csf' ) .'</div>' : '';
95
96 CSF::field( array(
97 'id' => 'background-gradient-color',
98 'type' => 'color',
99 'default' => $default_value['background-gradient-color'],
100 ), $this->value['background-gradient-color'], $this->field_name(), 'field/background' );
101
102 echo '</div>';
103
104 }
105
106 //
107 // Background Gradient Direction
108 if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) {
109
110 echo '<div class="csf--color">';
111
112 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
113 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf---title">'. esc_html__( 'Direction', 'csf' ) .'</div>' : '';
114
115 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
116 CSF::field( array(
117 'id' => 'background-gradient-direction',
118 'type' => 'select',
119 'options' => array(
120 '' => esc_html__( 'Gradient Direction', 'csf' ),
121 'to bottom' => esc_html__( '&#8659; top to bottom', 'csf' ),
122 'to right' => esc_html__( '&#8658; left to right', 'csf' ),
123 '135deg' => esc_html__( '&#8664; corner top to right', 'csf' ),
124 '-135deg' => esc_html__( '&#8665; corner top to left', 'csf' ),
125 ),
126 ), $this->value['background-gradient-direction'], $this->field_name(), 'field/background' );
127 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
128
129 echo '</div>';
130
131 }
132
133 echo '</div>';
134
135 //
136 // Background Image
137 if ( ! empty( $args['background_image'] ) ) {
138
139 echo '<div class="csf--background-image">';
140
141 CSF::field( array(
142 'id' => 'background-image',
143 'type' => 'media',
144 'class' => 'csf-assign-field-background',
145 'library' => $args['background_image_library'],
146 'preview' => $args['background_image_preview'],
147 'placeholder' => $args['background_image_placeholder'],
148 'attributes' => array( 'data-depend-id' => $this->field['id'] ),
149 ), $this->value['background-image'], $this->field_name(), 'field/background' );
150
151 echo '</div>';
152
153 }
154
155 $auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' csf--auto-attributes' : '';
156 $hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' csf--attributes-hidden' : '';
157
158 echo '<div class="csf--background-attributes'. esc_attr( $auto_class . $hidden_class ) .'">';
159
160 //
161 // Background Position
162 if ( ! empty( $args['background_position'] ) ) {
163
164 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
165 CSF::field( array(
166 'id' => 'background-position',
167 'type' => 'select',
168 'options' => array(
169 '' => esc_html__( 'Background Position', 'csf' ),
170 'left top' => esc_html__( 'Left Top', 'csf' ),
171 'left center' => esc_html__( 'Left Center', 'csf' ),
172 'left bottom' => esc_html__( 'Left Bottom', 'csf' ),
173 'center top' => esc_html__( 'Center Top', 'csf' ),
174 'center center' => esc_html__( 'Center Center', 'csf' ),
175 'center bottom' => esc_html__( 'Center Bottom', 'csf' ),
176 'right top' => esc_html__( 'Right Top', 'csf' ),
177 'right center' => esc_html__( 'Right Center', 'csf' ),
178 'right bottom' => esc_html__( 'Right Bottom', 'csf' ),
179 ),
180 ), $this->value['background-position'], $this->field_name(), 'field/background' );
181 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
182
183 }
184
185 //
186 // Background Repeat
187 if ( ! empty( $args['background_repeat'] ) ) {
188
189 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
190 CSF::field( array(
191 'id' => 'background-repeat',
192 'type' => 'select',
193 'options' => array(
194 '' => esc_html__( 'Background Repeat', 'csf' ),
195 'repeat' => esc_html__( 'Repeat', 'csf' ),
196 'no-repeat' => esc_html__( 'No Repeat', 'csf' ),
197 'repeat-x' => esc_html__( 'Repeat Horizontally', 'csf' ),
198 'repeat-y' => esc_html__( 'Repeat Vertically', 'csf' ),
199 ),
200 ), $this->value['background-repeat'], $this->field_name(), 'field/background' );
201 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
202
203 }
204
205 //
206 // Background Attachment
207 if ( ! empty( $args['background_attachment'] ) ) {
208
209 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
210 CSF::field( array(
211 'id' => 'background-attachment',
212 'type' => 'select',
213 'options' => array(
214 '' => esc_html__( 'Background Attachment', 'csf' ),
215 'scroll' => esc_html__( 'Scroll', 'csf' ),
216 'fixed' => esc_html__( 'Fixed', 'csf' ),
217 ),
218 ), $this->value['background-attachment'], $this->field_name(), 'field/background' );
219 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
220
221 }
222
223 //
224 // Background Size
225 if ( ! empty( $args['background_size'] ) ) {
226
227 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
228 CSF::field( array(
229 'id' => 'background-size',
230 'type' => 'select',
231 'options' => array(
232 '' => esc_html__( 'Background Size', 'csf' ),
233 'cover' => esc_html__( 'Cover', 'csf' ),
234 'contain' => esc_html__( 'Contain', 'csf' ),
235 'auto' => esc_html__( 'Auto', 'csf' ),
236 ),
237 ), $this->value['background-size'], $this->field_name(), 'field/background' );
238 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
239
240 }
241
242 //
243 // Background Origin
244 if ( ! empty( $args['background_origin'] ) ) {
245
246 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
247 CSF::field( array(
248 'id' => 'background-origin',
249 'type' => 'select',
250 'options' => array(
251 '' => esc_html__( 'Background Origin', 'csf' ),
252 'padding-box' => esc_html__( 'Padding Box', 'csf' ),
253 'border-box' => esc_html__( 'Border Box', 'csf' ),
254 'content-box' => esc_html__( 'Content Box', 'csf' ),
255 ),
256 ), $this->value['background-origin'], $this->field_name(), 'field/background' );
257 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
258
259 }
260
261 //
262 // Background Clip
263 if ( ! empty( $args['background_clip'] ) ) {
264
265 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
266 CSF::field( array(
267 'id' => 'background-clip',
268 'type' => 'select',
269 'options' => array(
270 '' => esc_html__( 'Background Clip', 'csf' ),
271 'border-box' => esc_html__( 'Border Box', 'csf' ),
272 'padding-box' => esc_html__( 'Padding Box', 'csf' ),
273 'content-box' => esc_html__( 'Content Box', 'csf' ),
274 ),
275 ), $this->value['background-clip'], $this->field_name(), 'field/background' );
276 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
277
278 }
279
280 //
281 // Background Blend Mode
282 if ( ! empty( $args['background_blend_mode'] ) ) {
283
284 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
285 CSF::field( array(
286 'id' => 'background-blend-mode',
287 'type' => 'select',
288 'options' => array(
289 '' => esc_html__( 'Background Blend Mode', 'csf' ),
290 'normal' => esc_html__( 'Normal', 'csf' ),
291 'multiply' => esc_html__( 'Multiply', 'csf' ),
292 'screen' => esc_html__( 'Screen', 'csf' ),
293 'overlay' => esc_html__( 'Overlay', 'csf' ),
294 'darken' => esc_html__( 'Darken', 'csf' ),
295 'lighten' => esc_html__( 'Lighten', 'csf' ),
296 'color-dodge' => esc_html__( 'Color Dodge', 'csf' ),
297 'saturation' => esc_html__( 'Saturation', 'csf' ),
298 'color' => esc_html__( 'Color', 'csf' ),
299 'luminosity' => esc_html__( 'Luminosity', 'csf' ),
300 ),
301 ), $this->value['background-blend-mode'], $this->field_name(), 'field/background' );
302 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
303
304 }
305
306 echo '</div>';
307
308 echo $this->field_after();
309
310 }
311
312 public function output() {
313
314 $output = '';
315 $bg_image = array();
316 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
317 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
318
319 // Background image and gradient
320 $background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : '';
321 $background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : '';
322 $background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : '';
323 $background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : '';
324
325
326 if ( $background_color && $background_gd_color ) {
327 $gd_direction = ( $background_gd_direction ) ? $background_gd_direction .',' : '';
328 $bg_image[] = 'linear-gradient('. $gd_direction . $background_color .','. $background_gd_color .')';
329 unset( $this->value['background-color'] );
330 }
331
332 if ( $background_image ) {
333 $bg_image[] = 'url('. $background_image .')';
334 }
335
336 if ( ! empty( $bg_image ) ) {
337 $output .= 'background-image:'. implode( ',', $bg_image ) . $important .';';
338 }
339
340 // Common background properties
341 $properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' );
342
343 foreach ( $properties as $property ) {
344 $property = 'background-'. $property;
345 if ( ! empty( $this->value[$property] ) ) {
346 $output .= $property .':'. $this->value[$property] . $important .';';
347 }
348 }
349
350 if ( $output ) {
351 $output = $element .'{'. $output .'}';
352 }
353
354 $this->parent->output_css .= $output;
355
356 return $output;
357
358 }
359
360 }
361 }
362