PluginProbe
QuadMenu – Mega Menu / 1.8.9
QuadMenu – Mega Menu v1.8.9
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 / lib / ReduxCore / inc / fields / spacing / field_spacing.php

field_spacing.php in QuadMenu – Mega Menu 1.8.9, at lib/ReduxCore/inc/fields/spacing/field_spacing.php

385 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 if ( ! class_exists( 'ReduxFramework_spacing' ) ) {
9 class ReduxFramework_spacing {
10
11 /**
12 * Field Constructor.
13 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
14 *
15 * @since ReduxFramework 1.0.0
16 */
17 function __construct( $field = array(), $value = '', $parent ) {
18 $this->parent = $parent;
19 $this->field = $field;
20 $this->value = $value;
21 }
22
23 /**
24 * Field Render Function.
25 * Takes the vars and outputs the HTML for the field in the settings
26 *
27 * @since ReduxFramework 1.0.0
28 */
29 function render() {
30 /*
31 * So, in_array() wasn't doing it's job for checking a passed array for a proper value.
32 * It's wonky. It only wants to check the keys against our array of acceptable values, and not the key's
33 * value. So we'll use this instead. Fortunately, a single no array value can be passed and it won't
34 * take a dump.
35 */
36
37 // No errors please
38 // Set field values
39 $defaults = array(
40 'units' => '',
41 'mode' => 'padding',
42 'top' => true,
43 'bottom' => true,
44 'all' => false,
45 'left' => true,
46 'right' => true,
47 'units_extended' => false,
48 'display_units' => true
49 );
50
51 $this->field = wp_parse_args( $this->field, $defaults );
52
53 // Set default values
54 $defaults = array(
55 'top' => '',
56 'right' => '',
57 'bottom' => '',
58 'left' => '',
59 'units' => 'px'
60 );
61
62 $this->value = wp_parse_args( $this->value, $defaults );
63
64 /*
65 * Acceptable values checks. If the passed variable doesn't pass muster, we unset them
66 * and reset them with default values to avoid errors.
67 */
68
69 // If units field has a value but is not an acceptable value, unset the variable
70 if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], array(
71 '',
72 false,
73 '%',
74 'in',
75 'cm',
76 'mm',
77 'em',
78 'rem',
79 'ex',
80 'pt',
81 'pc',
82 'px'
83 ) )
84 ) {
85 unset( $this->field['units'] );
86 }
87
88 //if there is a default unit value but is not an accepted value, unset the variable
89 if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], array(
90 '',
91 '%',
92 'in',
93 'cm',
94 'mm',
95 'em',
96 'rem',
97 'ex',
98 'pt',
99 'pc',
100 'px'
101 ) )
102 ) {
103 unset( $this->value['units'] );
104 }
105
106 // if ($this->field['mode'] == "absolute") {
107 // $this->field['units'] = "";
108 // $this->value['units'] = "";
109 // }
110
111 if ( $this->field['units'] == false ) {
112 $this->value == "";
113 }
114
115 if ( isset( $this->field['mode'] ) && ! in_array( $this->field['mode'], array(
116 'margin',
117 'padding'
118 ) )
119 ) {
120 if ( $this->field['mode'] == "absolute" ) {
121 $absolute = true;
122 }
123 $this->field['mode'] = "";
124 }
125
126 $value = array(
127 'top' => isset( $this->value[ $this->field['mode'] . '-top' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-top' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),
128 'right' => isset( $this->value[ $this->field['mode'] . '-right' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-right' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),
129 'bottom' => isset( $this->value[ $this->field['mode'] . '-bottom' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-bottom' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),
130 'left' => isset( $this->value[ $this->field['mode'] . '-left' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-left' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION )
131 );
132
133 // if field units has a value and is NOT an array, then evaluate as needed.
134 if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) {
135
136 //if units fields has a value and is not empty but units value does not then make units value the field value
137 if ( isset( $this->field['units'] ) && $this->field['units'] != "" && ! isset( $this->value['units'] ) || $this->field['units'] == false ) {
138 $this->value['units'] = $this->field['units'];
139
140 // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?)
141 } else if ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) {
142 $this->field['units'] = 'px';
143 $this->value['units'] = 'px';
144
145 // If units field has NO value but units value does, then set unit field to value field
146 } else if ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { // If Value is defined
147 $this->field['units'] = $this->value['units'];
148
149 // if unit value is set and unit value doesn't equal unit field (coz who knows why)
150 // then set unit value to unit field
151 } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) {
152 $this->value['units'] = $this->field['units'];
153 }
154
155 // do stuff based on unit field NOT set as an array
156 } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) {
157 // nothing to do here, but I'm leaving the construct just in case I have to debug this again.
158 }
159
160 if ( isset( $this->field['units'] ) ) {
161 $value['units'] = $this->value['units'];
162 }
163
164 $this->value = $value;
165
166 if ( ! empty( $this->field['mode'] ) ) {
167 $this->field['mode'] = $this->field['mode'] . "-";
168 }
169
170
171 $defaults = array(
172 'top' => '',
173 'right' => '',
174 'bottom' => '',
175 'left' => '',
176 'units' => ''
177 );
178
179 $this->value = wp_parse_args( $this->value, $defaults );
180
181 if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js
182 $select2_params = json_encode( $this->field['select2'] );
183 $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES );
184
185 echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">';
186 }
187
188 echo '<input type="hidden" class="field-units" value="' . $this->value['units'] . '">';
189
190 if ( isset( $this->field['all'] ) && $this->field['all'] == true ) {
191 echo '<div class="field-spacing-input input-prepend"><span class="add-on"><i class="el el-fullscreen icon-large"></i></span><input type="text" class="redux-spacing-all redux-spacing-input mini ' . $this->field['class'] . '" placeholder="' . __( 'All', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-all" value="' . $this->value['top'] . '"></div>';
192 }
193
194 if ( $this->field['top'] === true ) {
195 echo '<input type="hidden" class="redux-spacing-value" id="' . $this->field['id'] . '-top" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] . 'top]' . '" value="' . $this->value['top'] . ( ! empty( $this->value['top'] ) ? $this->value['units'] : '' ) . '">';
196 }
197
198 if ( $this->field['right'] === true ) {
199 echo '<input type="hidden" class="redux-spacing-value" id="' . $this->field['id'] . '-right" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] . 'right]' . '" value="' . $this->value['right'] . ( ! empty( $this->value['right'] ) ? $this->value['units'] : '' ) . '">';
200 }
201
202 if ( $this->field['bottom'] === true ) {
203 echo '<input type="hidden" class="redux-spacing-value" id="' . $this->field['id'] . '-bottom" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] . 'bottom]' . '" value="' . $this->value['bottom'] . ( ! empty( $this->value['bottom'] ) ? $this->value['units'] : '' ) . '">';
204 }
205
206 if ( $this->field['left'] === true ) {
207 echo '<input type="hidden" class="redux-spacing-value" id="' . $this->field['id'] . '-left" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] . 'left]' . '" value="' . $this->value['left'] . ( ! empty( $this->value['left'] ) ? $this->value['units'] : '' ) . '">';
208 }
209
210 if ( ! isset( $this->field['all'] ) || $this->field['all'] !== true ) {
211 /**
212 * Top
213 * */
214 if ( $this->field['top'] === true ) {
215 echo '<div class="field-spacing-input input-prepend"><span class="add-on"><i class="el el-arrow-up icon-large"></i></span><input type="text" class="redux-spacing-top redux-spacing-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Top', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-top" value="' . $this->value['top'] . '"></div>';
216 }
217
218 /**
219 * Right
220 * */
221 if ( $this->field['right'] === true ) {
222 echo '<div class="field-spacing-input input-prepend"><span class="add-on"><i class="el el-arrow-right icon-large"></i></span><input type="text" class="redux-spacing-right redux-spacing-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Right', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-right" value="' . $this->value['right'] . '"></div>';
223 }
224
225 /**
226 * Bottom
227 * */
228 if ( $this->field['bottom'] === true ) {
229 echo '<div class="field-spacing-input input-prepend"><span class="add-on"><i class="el el-arrow-down icon-large"></i></span><input type="text" class="redux-spacing-bottom redux-spacing-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Bottom', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-bottom" value="' . $this->value['bottom'] . '"></div>';
230 }
231
232 /**
233 * Left
234 * */
235 if ( $this->field['left'] === true ) {
236 echo '<div class="field-spacing-input input-prepend"><span class="add-on"><i class="el el-arrow-left icon-large"></i></span><input type="text" class="redux-spacing-left redux-spacing-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Left', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-left" value="' . $this->value['left'] . '"></div>';
237 }
238 }
239
240 /**
241 * Units
242 * */
243 if ( $this->field['units'] !== false && is_array( $this->field['units'] ) /* && !isset($absolute) */ && $this->field['display_units'] == true ) {
244
245 echo '<div class="select_wrapper spacing-units" original-title="' . __( 'Units', 'redux-framework' ) . '">';
246 echo '<select data-placeholder="' . __( 'Units', 'redux-framework' ) . '" class="redux-spacing redux-spacing-units select ' . $this->field['class'] . '" original-title="' . __( 'Units', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[units]' . '" id="' . $this->field['id'] . '_units">';
247
248 if ( $this->field['units_extended'] ) {
249 $testUnits = array( 'px', 'em', 'rem', '%', 'in', 'cm', 'mm', 'ex', 'pt', 'pc' );
250 } else {
251 $testUnits = array( 'px', 'em', 'pt', 'rem', '%' );
252 }
253
254 if ( $this->field['units'] != "" || is_array( $this->field['units'] ) ) {
255 $testUnits = $this->field['units'];
256 }
257
258 echo '<option></option>';
259
260 if ( in_array( $this->field['units'], $testUnits ) ) {
261 echo '<option value="' . $this->field['units'] . '" selected="selected">' . $this->field['units'] . '</option>';
262 } else {
263 foreach ( $testUnits as $aUnit ) {
264 echo '<option value="' . $aUnit . '" ' . selected( $this->value['units'], $aUnit, false ) . '>' . $aUnit . '</option>';
265 }
266 }
267 echo '</select></div>';
268
269 }
270 }
271
272 /**
273 * Enqueue Function.
274 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
275 *
276 * @since ReduxFramework 1.0.0
277 */
278 function enqueue() {
279 wp_enqueue_style( 'select2-css' );
280
281 wp_enqueue_script(
282 'redux-field-spacing-js',
283 ReduxFramework::$_url . 'inc/fields/spacing/field_spacing' . Redux_Functions::isMin() . '.js',
284 array( 'jquery', 'select2-js', 'redux-js' ),
285 time(),
286 true
287 );
288
289 if ($this->parent->args['dev_mode']) {
290 wp_enqueue_style(
291 'redux-field-spacing-css',
292 ReduxFramework::$_url . 'inc/fields/spacing/field_spacing.css',
293 array(),
294 time(),
295 'all'
296 );
297 }
298 } //function
299
300 public function output() {
301
302 if ( ! isset( $this->field['mode'] ) ) {
303 $this->field['mode'] = "padding";
304 }
305
306 if ( isset( $this->field['mode'] ) && ! in_array( $this->field['mode'], array(
307 'padding',
308 'absolute',
309 'margin'
310 ) )
311 ) {
312 $this->field['mode'] = "";
313 }
314
315 $mode = ( $this->field['mode'] != "absolute" ) ? $this->field['mode'] : "";
316 $units = isset( $this->value['units'] ) ? $this->value['units'] : "";
317 $style = '';
318
319 if ( ! empty( $mode ) ) {
320 foreach ( $this->value as $key => $value ) {
321 if ( $key == "units" ) {
322 continue;
323 }
324
325 // Strip off any alpha for is_numeric test - kp
326 $num_no_alpha = preg_replace('/[^\d.-]/', '', $value);
327
328 // Output if it's a numeric entry
329 if ( isset( $value ) && is_numeric( $num_no_alpha ) ) {
330 $style .= $key . ':' . $value . ';';
331 }
332
333 }
334 } else {
335 $this->value['top'] = isset( $this->value['top'] ) ? $this->value['top'] : 0;
336 $this->value['bottom'] = isset( $this->value['bottom'] ) ? $this->value['bottom'] : 0;
337 $this->value['left'] = isset( $this->value['left'] ) ? $this->value['left'] : 0;
338 $this->value['right'] = isset( $this->value['right'] ) ? $this->value['right'] : 0;
339
340 $cleanValue = array(
341 'top' => isset( $this->value[ $mode . '-top' ] ) ? filter_var( $this->value[ $mode . '-top' ], FILTER_SANITIZE_NUMBER_INT ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_INT ),
342 'right' => isset( $this->value[ $mode . '-right' ] ) ? filter_var( $this->value[ $mode . '-right' ], FILTER_SANITIZE_NUMBER_INT ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_INT ),
343 'bottom' => isset( $this->value[ $mode . '-bottom' ] ) ? filter_var( $this->value[ $mode . '-bottom' ], FILTER_SANITIZE_NUMBER_INT ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_INT ),
344 'left' => isset( $this->value[ $mode . '-left' ] ) ? filter_var( $this->value[ $mode . '-left' ], FILTER_SANITIZE_NUMBER_INT ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_INT )
345 );
346
347 if ( isset( $this->field['all'] ) && true == $this->field['all'] ) {
348 $style .= $mode . 'top:' . $cleanValue['top'] . $units . ';';
349 $style .= $mode . 'bottom:' . $cleanValue['top'] . $units . ';';
350 $style .= $mode . 'right:' . $cleanValue['top'] . $units . ';';
351 $style .= $mode . 'left:' . $cleanValue['top'] . $units . ';';
352 } else {
353 if ( true == $this->field['top'] ) {
354 $style .= $mode . 'top:' . $cleanValue['top'] . $units . ';';
355 }
356
357 if ( true == $this->field['bottom'] ) {
358 $style .= $mode . 'bottom:' . $cleanValue['bottom'] . $units . ';';
359 }
360
361 if ( true == $this->field['left'] ) {
362 $style .= $mode . 'left:' . $cleanValue['left'] . $units . ';';
363 }
364
365 if ( true == $this->field['right'] ) {
366 $style .= $mode . 'right:' . $cleanValue['right'] . $units . ';';
367 }
368 }
369 }
370
371 if ( ! empty( $style ) ) {
372
373 if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) {
374 $keys = implode( ",", $this->field['output'] );
375 $this->parent->outputCSS .= $keys . "{" . $style . '}';
376 }
377
378 if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) {
379 $keys = implode( ",", $this->field['compiler'] );
380 $this->parent->compilerCSS .= $keys . "{" . $style . '}';
381 }
382 }
383 }
384 }
385 }