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 / spacing / spacing.php

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

175 lines 6.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: spacing
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_spacing' ) ) {
12 class CSF_Field_spacing 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 'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
22 'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
23 'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
24 'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
25 'all_icon' => '<i class="fas fa-arrows-alt"></i>',
26 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
27 'top_placeholder' => esc_html__( 'top', 'csf' ),
28 'right_placeholder' => esc_html__( 'right', 'csf' ),
29 'bottom_placeholder' => esc_html__( 'bottom', 'csf' ),
30 'left_placeholder' => esc_html__( 'left', 'csf' ),
31 'all_placeholder' => esc_html__( 'all', 'csf' ),
32 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
33 'top' => true,
34 'left' => true,
35 'bottom' => true,
36 'right' => true,
37 'unit' => true,
38 'show_units' => true,
39 'all' => false,
40 'units' => array( 'px', '%', 'em' )
41 ) );
42
43 $default_values = array(
44 'top' => '',
45 'right' => '',
46 'bottom' => '',
47 'left' => '',
48 'all' => '',
49 'unit' => 'px',
50 );
51
52 $value = wp_parse_args( $this->value, $default_values );
53 $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
54 $is_unit = ( ! empty( $unit ) ) ? ' csf--is-unit' : '';
55
56 echo $this->field_before();
57
58 echo '<div class="csf--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
59
60 if ( ! empty( $args['all'] ) ) {
61
62 $placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
63
64 echo '<div class="csf--input">';
65 echo ( ! empty( $args['all_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['all_icon'] .'</span>' : '';
66 echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
67 echo ( $unit ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
68 echo '</div>';
69
70 } else {
71
72 $properties = array();
73
74 foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
75 if ( ! empty( $args[$prop] ) ) {
76 $properties[] = $prop;
77 }
78 }
79
80 $properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
81
82 foreach ( $properties as $property ) {
83
84 $placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
85
86 echo '<div class="csf--input">';
87 echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args[$property.'_icon'] .'</span>' : '';
88 echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
89 echo ( $unit ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
90 echo '</div>';
91
92 }
93
94 }
95
96 if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
97 echo '<div class="csf--input">';
98 echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
99 foreach ( $args['units'] as $unit ) {
100 $selected = ( $value['unit'] === $unit ) ? ' selected' : '';
101 echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
102 }
103 echo '</select>';
104 echo '</div>';
105 }
106
107 echo '</div>';
108
109 echo $this->field_after();
110
111 }
112
113 public function output() {
114
115 $output = '';
116 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
117 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
118 $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
119
120 $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding';
121
122 if ( $mode === 'border-radius' || $mode === 'radius' ) {
123
124 $top = 'border-top-left-radius';
125 $right = 'border-top-right-radius';
126 $bottom = 'border-bottom-right-radius';
127 $left = 'border-bottom-left-radius';
128
129 } else if ( $mode === 'relative' || $mode === 'absolute' || $mode === 'none' ) {
130
131 $top = 'top';
132 $right = 'right';
133 $bottom = 'bottom';
134 $left = 'left';
135
136 } else {
137
138 $top = $mode .'-top';
139 $right = $mode .'-right';
140 $bottom = $mode .'-bottom';
141 $left = $mode .'-left';
142
143 }
144
145 if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && $this->value['all'] !== '' ) {
146
147 $output = $element .'{';
148 $output .= $top .':'. $this->value['all'] . $unit . $important .';';
149 $output .= $right .':'. $this->value['all'] . $unit . $important .';';
150 $output .= $bottom .':'. $this->value['all'] . $unit . $important .';';
151 $output .= $left .':'. $this->value['all'] . $unit . $important .';';
152 $output .= '}';
153
154 } else {
155
156 $top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $top .':'. $this->value['top'] . $unit . $important .';' : '';
157 $right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $right .':'. $this->value['right'] . $unit . $important .';' : '';
158 $bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $bottom .':'. $this->value['bottom'] . $unit . $important .';' : '';
159 $left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $left .':'. $this->value['left'] . $unit . $important .';' : '';
160
161 if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' ) {
162 $output = $element .'{'. $top . $right . $bottom . $left .'}';
163 }
164
165 }
166
167 $this->parent->output_css .= $output;
168
169 return $output;
170
171 }
172
173 }
174 }
175