PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / redux / ReduxCore / inc / fields / dimensions / field_dimensions.php

field_dimensions.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/fields/dimensions/field_dimensions.php

308 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( ! class_exists( 'ReduxFrameworkLegacy_dimensions' ) ) {
8 class ReduxFrameworkLegacy_dimensions {
9
10 /**
11 * Field Constructor.
12 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
13 *
14 * @since ReduxFrameworkLegacy 1.0.0
15 */
16 function __construct( $field = array(), $value = '', $parent = null ) {
17 $this->parent = $parent;
18 $this->field = $field;
19 $this->value = $value;
20
21 // No errors please
22 $defaults = array(
23 'width' => true,
24 'height' => true,
25 'units_extended' => false,
26 'units' => 'px',
27 'mode' => array(
28 'width' => false,
29 'height' => false,
30 ),
31 );
32
33 $this->field = wp_parse_args( $this->field, $defaults );
34
35 $defaults = array(
36 'width' => '',
37 'height' => '',
38 'units' => 'px',
39 );
40
41 $this->value = wp_parse_args( $this->value, $defaults );
42
43 if ( isset( $this->value['unit'] ) ) {
44 $this->value['units'] = $this->value['unit'];
45 }
46 } //function
47
48 /**
49 * Field Render Function.
50 * Takes the vars and outputs the HTML for the field in the settings
51 *
52 * @since ReduxFrameworkLegacy 1.0.0
53 */
54 function render() {
55
56 /*
57 * Acceptable values checks. If the passed variable doesn't pass muster, we unset them
58 * and reset them with default values to avoid errors.
59 */
60
61 // If units field has a value but is not an acceptable value, unset the variable
62 if ( isset( $this->field['units'] ) && ! ReduxLegacy_Helpers::array_in_array(
63 $this->field['units'],
64 array(
65 '',
66 false,
67 '%',
68 'in',
69 'cm',
70 'mm',
71 'em',
72 'ex',
73 'pt',
74 'pc',
75 'px',
76 'rem',
77 )
78 )
79 ) {
80 unset( $this->field['units'] );
81 }
82
83 // if there is a default unit value but is not an accepted value, unset the variable
84 if ( isset( $this->value['units'] ) && ! ReduxLegacy_Helpers::array_in_array(
85 $this->value['units'],
86 array(
87 '',
88 '%',
89 'in',
90 'cm',
91 'mm',
92 'em',
93 'ex',
94 'pt',
95 'pc',
96 'px',
97 )
98 )
99 ) {
100 unset( $this->value['units'] );
101 }
102
103 /*
104 * Since units field could be an array, string value or bool (to hide the unit field)
105 * we need to separate our functions to avoid those nasty PHP index notices!
106 */
107
108 // if field units has a value and IS an array, then evaluate as needed.
109 if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) {
110
111 // if units fields has a value but units value does not then make units value the field value
112 if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || $this->field['units'] == false ) {
113 $this->value['units'] = $this->field['units'];
114
115 // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?)
116 } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) {
117 $this->field['units'] = 'px';
118 $this->value['units'] = 'px';
119
120 // If units field has NO value but units value does, then set unit field to value field
121 } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) {
122 $this->field['units'] = $this->value['units'];
123
124 // if unit value is set and unit value doesn't equal unit field (coz who knows why)
125 // then set unit value to unit field
126 } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) {
127 $this->value['units'] = $this->field['units'];
128 }
129
130 // do stuff based on unit field NOT set as an array
131 } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) {
132 // nothing to do here, but I'm leaving the construct just in case I have to debug this again.
133 }
134
135 echo '<fieldset id="' . $this->field['id'] . '-fieldset" class="redux-dimensions-container" data-id="' . $this->field['id'] . '">';
136
137 if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js
138 $select2_params = json_encode( $this->field['select2'] );
139 $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES );
140
141 echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">';
142 }
143
144 // This used to be unit field, but was giving the PHP index error when it was an array,
145 // so I changed it.
146 echo '<input type="hidden" class="field-units" value="' . $this->value['units'] . '">';
147
148 /**
149 * Width
150 * */
151 if ( $this->field['width'] === true ) {
152 if ( ! empty( $this->value['width'] ) && strpos( $this->value['width'], $this->value['units'] ) === false ) {
153 $this->value['width'] = filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
154 if ( $this->field['units'] !== false ) {
155 $this->value['width'] .= $this->value['units'];
156 }
157 }
158 echo '<div class="field-dimensions-input input-prepend">';
159 echo '<span class="add-on"><i class="el el-resize-horizontal icon-large"></i></span>';
160 echo '<input type="text" class="redux-dimensions-input redux-dimensions-width mini ' . $this->field['class'] . '" placeholder="' . __( 'Width', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-width" value="' . filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) . '">';
161 echo '<input data-id="' . $this->field['id'] . '" type="hidden" id="' . $this->field['id'] . '-width" name="' . $this->field['name'] . $this->field['name_suffix'] . '[width]' . '" value="' . $this->value['width'] . '"></div>';
162 }
163
164 /**
165 * Height
166 * */
167 if ( $this->field['height'] === true ) {
168 if ( ! empty( $this->value['height'] ) && strpos( $this->value['height'], $this->value['units'] ) === false ) {
169 $this->value['height'] = filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
170 if ( $this->field['units'] !== false ) {
171 $this->value['height'] .= $this->value['units'];
172 }
173 }
174 echo '<div class="field-dimensions-input input-prepend">';
175 echo '<span class="add-on"><i class="el el-resize-vertical icon-large"></i></span>';
176 echo '<input type="text" class="redux-dimensions-input redux-dimensions-height mini ' . $this->field['class'] . '" placeholder="' . __( 'Height', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-height" value="' . filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) . '">';
177 echo '<input data-id="' . $this->field['id'] . '" type="hidden" id="' . $this->field['id'] . '-height" name="' . $this->field['name'] . $this->field['name_suffix'] . '[height]' . '" value="' . $this->value['height'] . '"></div>';
178 }
179
180 /**
181 * Units
182 * */
183 // If units field is set and units field NOT false then
184 // fill out the options object and show it, otherwise it's hidden
185 // and the default units value will apply.
186 if ( isset( $this->field['units'] ) && $this->field['units'] !== false ) {
187 echo '<div class="select_wrapper dimensions-units" original-title="' . __( 'Units', 'redux-framework' ) . '">';
188 echo '<select data-id="' . $this->field['id'] . '" data-placeholder="' . __( 'Units', 'redux-framework' ) . '" class="redux-dimensions redux-dimensions-units select ' . $this->field['class'] . '" original-title="' . __( 'Units', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[units]' . '">';
189
190 // Extended units, show 'em all
191 if ( $this->field['units_extended'] ) {
192 $testUnits = array( 'px', 'em', 'rem', '%', 'in', 'cm', 'mm', 'ex', 'pt', 'pc' );
193 } else {
194 $testUnits = array( 'px', 'em', 'rem', '%' );
195 }
196
197 if ( $this->field['units'] != '' && is_array( $this->field['units'] ) ) {
198 $testUnits = $this->field['units'];
199 }
200
201 if ( in_array( $this->field['units'], $testUnits ) ) {
202 echo '<option value="' . $this->field['units'] . '" selected="selected">' . $this->field['units'] . '</option>';
203 } else {
204 foreach ( $testUnits as $aUnit ) {
205 echo '<option value="' . $aUnit . '" ' . selected( $this->value['units'], $aUnit, false ) . '>' . $aUnit . '</option>';
206 }
207 }
208 echo '</select></div>';
209 }
210 echo '</fieldset>';
211 } //function
212
213 /**
214 * Enqueue Function.
215 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
216 *
217 * @since ReduxFrameworkLegacy 1.0.0
218 */
219 function enqueue() {
220 wp_enqueue_style( 'select2-css' );
221
222 wp_enqueue_script(
223 'redux-field-dimensions-js',
224 ReduxFrameworkLegacy::$_url . 'inc/fields/dimensions/field_dimensions' . ReduxLegacy_Functions::isMin() . '.js',
225 array( 'jquery', 'select2-js', 'redux-js' ),
226 time(),
227 true
228 );
229
230 if ( $this->parent->args['dev_mode'] ) {
231 wp_enqueue_style(
232 'redux-field-dimensions-css',
233 ReduxFrameworkLegacy::$_url . 'inc/fields/dimensions/field_dimensions.css',
234 array(),
235 time(),
236 'all'
237 );
238 }
239 }
240
241 public function output() {
242
243 // if field units has a value and IS an array, then evaluate as needed.
244 if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) {
245
246 // if units fields has a value but units value does not then make units value the field value
247 if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || $this->field['units'] == false ) {
248 $this->value['units'] = $this->field['units'];
249
250 // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?)
251 } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) {
252 $this->field['units'] = 'px';
253 $this->value['units'] = 'px';
254
255 // If units field has NO value but units value does, then set unit field to value field
256 } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) {
257 $this->field['units'] = $this->value['units'];
258
259 // if unit value is set and unit value doesn't equal unit field (coz who knows why)
260 // then set unit value to unit field
261 } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) {
262 $this->value['units'] = $this->field['units'];
263 }
264
265 // do stuff based on unit field NOT set as an array
266 } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) {
267 // nothing to do here, but I'm leaving the construct just in case I have to debug this again.
268 }
269
270 $units = isset( $this->value['units'] ) ? $this->value['units'] : '';
271
272 if ( ! is_array( $this->field['mode'] ) ) {
273 $height = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'height';
274 $width = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'width';
275 } else {
276 $height = $this->field['mode']['height'] != false ? $this->field['mode']['height'] : 'height';
277 $width = $this->field['mode']['width'] != false ? $this->field['mode']['width'] : 'width';
278 }
279
280 $cleanValue = array(
281 $height => isset( $this->value['height'] ) ? filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '',
282 $width => isset( $this->value['width'] ) ? filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '',
283 );
284
285 $style = '';
286
287 foreach ( $cleanValue as $key => $value ) {
288 // Output if it's a numeric entry
289 if ( isset( $value ) && is_numeric( $value ) ) {
290 $style .= $key . ':' . $value . $units . ';';
291 }
292 }
293
294 if ( ! empty( $style ) ) {
295 if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) {
296 $keys = implode( ',', $this->field['output'] );
297 $this->parent->outputCSS .= $keys . '{' . $style . '}';
298 }
299
300 if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) {
301 $keys = implode( ',', $this->field['compiler'] );
302 $this->parent->compilerCSS .= $keys . '{' . $style . '}';
303 }
304 }
305 } //function
306 } //class
307 }
308