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 / slider / field_slider.php

field_slider.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/fields/slider/field_slider.php

416 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Redux Framework is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * any later version.
8 * Redux Framework is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
14 *
15 * @package ReduxFrameworkLegacy
16 * @subpackage Field_Slider
17 * @author Kevin Provance (kprovance)
18 * @version 2.0.0
19 */
20
21 // Exit if accessed directly
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 if ( ! class_exists( 'ReduxFrameworkLegacy_slider' ) ) {
27 class ReduxFrameworkLegacy_slider {
28
29 public $parent;
30 public $field;
31 public $value;
32
33 /**
34 * Field Constructor.
35 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
36 *
37 * @since ReduxFrameworkLegacy 3.1.8
38 */
39 private $display_none = 0;
40 private $display_label = 1;
41 private $display_text = 2;
42 private $display_select = 3;
43
44 function __construct( $field = array(), $value = '', $parent = null ) {
45
46 // parent::__construct( $parent->sections, $parent->args );
47 $this->parent = $parent;
48 $this->field = $field;
49 $this->value = $value;
50
51 // Set defaults
52 $defaults = array(
53 'handles' => 1,
54 'resolution' => 1,
55 'display_value' => 'text',
56 'float_mark' => '.',
57 'forced' => true,
58 );
59
60 $this->field = wp_parse_args( $this->field, $defaults );
61
62 // Sanitize float mark
63 switch ( $this->field['float_mark'] ) {
64 case ',':
65 case '.':
66 break;
67 default:
68 $this->field['float_mark'] = '.';
69 break;
70 }
71
72 // Sanitize resolution value
73 $this->field['resolution'] = $this->cleanVal( $this->field['resolution'] );
74
75 // Sanitize handle value
76 switch ( $this->field['handles'] ) {
77 case 0:
78 case 1:
79 $this->field['handles'] = 1;
80 break;
81 default:
82 $this->field['handles'] = 2;
83 break;
84 }
85
86 // Sanitize display value
87 switch ( $this->field['display_value'] ) {
88 case 'label':
89 $this->field['display_value'] = $this->display_label;
90 break;
91 case 'text':
92 default:
93 $this->field['display_value'] = $this->display_text;
94 break;
95 case 'select':
96 $this->field['display_value'] = $this->display_select;
97 break;
98 case 'none':
99 $this->field['display_value'] = $this->display_none;
100 break;
101 }
102 }
103
104 private function cleanVal( $var ) {
105 if ( is_float( $var ) ) {
106 $cleanVar = floatval( $var );
107 } else {
108 $cleanVar = intval( $var );
109 }
110
111 return $cleanVar;
112 }
113
114 private function cleanDefault( $val ) {
115 if ( empty( $val ) && ! empty( $this->field['default'] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
116 $val = $this->cleanVal( $this->field['default'] );
117 }
118
119 if ( empty( $val ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
120 $val = $this->cleanVal( $this->field['min'] );
121 }
122
123 if ( empty( $val ) ) {
124 $val = 0;
125 }
126
127 // Extra Validation
128 if ( $val < $this->field['min'] ) {
129 $val = $this->cleanVal( $this->field['min'] );
130 } elseif ( $val > $this->field['max'] ) {
131 $val = $this->cleanVal( $this->field['max'] );
132 }
133
134 return $val;
135 }
136
137 private function cleanDefaultArray( $val ) {
138 $one = $this->value[1];
139 $two = $this->value[2];
140
141 if ( empty( $one ) && ! empty( $this->field['default'][1] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
142 $one = $this->cleanVal( $this->field['default'][1] );
143 }
144
145 if ( empty( $one ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
146 $one = $this->cleanVal( $this->field['min'] );
147 }
148
149 if ( empty( $one ) ) {
150 $one = 0;
151 }
152
153 if ( empty( $two ) && ! empty( $this->field['default'][2] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
154 $two = $this->cleanVal( $this->field['default'][1] + 1 );
155 }
156
157 if ( empty( $two ) && $this->cleanVal( $this->field['min'] ) >= 1 ) {
158 $two = $this->cleanVal( $this->field['default'][1] + 1 );
159 }
160
161 if ( empty( $two ) ) {
162 $two = $this->field['default'][1] + 1;
163 }
164
165 $val[0] = $one;
166 $val[1] = $two;
167
168 return $val;
169 }
170
171
172 /**
173 * Clean the field data to the fields defaults given the parameters.
174 *
175 * @since Redux_Framework 3.1.8
176 */
177 function clean() {
178
179 // Set min to 0 if no value is set.
180 $this->field['min'] = empty( $this->field['min'] ) ? 0 : $this->cleanVal( $this->field['min'] );
181
182 // Set max to min + 1 if empty.
183 $this->field['max'] = empty( $this->field['max'] ) ? $this->field['min'] + 1 : $this->cleanVal( $this->field['max'] );
184
185 // Set step to 1 if step is empty ot step > max.
186 $this->field['step'] = empty( $this->field['step'] ) || $this->field['step'] > $this->field['max'] ? 1 : $this->cleanVal( $this->field['step'] );
187
188 if ( 2 == $this->field['handles'] ) {
189 if ( ! is_array( $this->value ) ) {
190 $this->value[1] = 0;
191 $this->value[2] = 1;
192 }
193 $this->value = $this->cleanDefaultArray( $this->value );
194 } else {
195 if ( is_array( $this->value ) ) {
196 $this->value = 0;
197 }
198 $this->value = $this->cleanDefault( $this->value );
199 }
200
201 // More dummy checks
202 // if ( ! is_array( $this->field['default'] ) && 2 == $this->field['handles'] ) {
203 if ( ! is_array( $this->value ) && 2 == $this->field['handles'] ) {
204 $this->value[0] = $this->field['min'];
205 $this->value[1] = $this->field['min'] + 1;
206 }
207
208 // if ( is_array( $this->field['default'] ) && 1 == $this->field['handles'] ) {
209 if ( is_array( $this->value ) && 1 == $this->field['handles'] ) {
210 $this->value = $this->field['min'];
211 }
212 }
213
214 /**
215 * Enqueue Function.
216 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
217 *
218 * @since ReduxFrameworkLegacy 3.1.8
219 */
220 function enqueue() {
221
222 $min = ReduxLegacy_Functions::isMin();
223
224 wp_enqueue_style( 'select2-css' );
225
226 wp_enqueue_style(
227 'redux-nouislider-css',
228 ReduxFrameworkLegacy::$_url . 'inc/fields/slider/vendor/nouislider/redux.jquery.nouislider.css',
229 array(),
230 '5.0.0',
231 'all'
232 );
233
234 wp_register_script(
235 'redux-nouislider-js',
236 ReduxFrameworkLegacy::$_url . 'inc/fields/slider/vendor/nouislider/redux.jquery.nouislider' . $min . '.js',
237 array( 'jquery' ),
238 '5.0.0',
239 true
240 );
241
242 wp_enqueue_script(
243 'redux-field-slider-js',
244 ReduxFrameworkLegacy::$_url . 'inc/fields/slider/field_slider' . $min . '.js',
245 array( 'jquery', 'redux-nouislider-js', 'redux-js', 'select2-js' ),
246 time(),
247 true
248 );
249
250 if ( $this->parent->args['dev_mode'] ) {
251 wp_enqueue_style(
252 'redux-field-slider-css',
253 ReduxFrameworkLegacy::$_url . 'inc/fields/slider/field_slider.css',
254 array(),
255 time(),
256 'all'
257 );
258 }
259 }
260
261 // function
262
263 /**
264 * Field Render Function.
265 * Takes the vars and outputs the HTML for the field in the settings
266 *
267 * @since ReduxFrameworkLegacy 0.0.4
268 */
269 function render() {
270
271 $this->clean();
272
273 $fieldID = $this->field['id'];
274 $fieldName = $this->field['name'] . $this->field['name_suffix'];
275 // $fieldName = $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']';
276
277 // Set handle number variable.
278 $twoHandles = false;
279 if ( 2 == $this->field['handles'] ) {
280 $twoHandles = true;
281 }
282
283 // Set default values(s)
284 if ( true == $twoHandles ) {
285 $valOne = $this->value[0];
286 $valTwo = $this->value[1];
287
288 $html = 'data-default-one="' . $valOne . '" ';
289 $html .= 'data-default-two="' . $valTwo . '" ';
290
291 $nameOne = $fieldName . '[1]';
292 $nameTwo = $fieldName . '[2]';
293
294 $idOne = $fieldID . '[1]';
295 $idTwo = $fieldID . '[2]';
296 } else {
297 $valOne = $this->value;
298 $valTwo = '';
299
300 $html = 'data-default-one="' . $valOne . '"';
301
302 $nameOne = $fieldName;
303 $nameTwo = '';
304
305 $idOne = $fieldID;
306 $idTwo = '';
307 }
308
309 $showInput = false;
310 $showLabel = false;
311 $showSelect = false;
312
313 // TEXT output
314 if ( $this->display_text == $this->field['display_value'] ) {
315 $showInput = true;
316 echo '<input type="text"
317 name="' . $nameOne . '"
318 id="' . $idOne . '"
319 value="' . $valOne . '"
320 class="redux-slider-input redux-slider-input-one-' . $fieldID . ' ' . $this->field['class'] . '"/>';
321
322 // LABEL output
323 } elseif ( $this->display_label == $this->field['display_value'] ) {
324 $showLabel = true;
325
326 $labelNum = $twoHandles ? '-one' : '';
327
328 echo '<div class="redux-slider-label' . $labelNum . '"
329 id="redux-slider-label-one-' . $fieldID . '"
330 name="' . $nameOne . '">
331 </div>';
332
333 // SELECT output
334 } elseif ( $this->display_select == $this->field['display_value'] ) {
335 $showSelect = true;
336
337 if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js
338 $select2_params = json_encode( $this->field['select2'] );
339 $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES );
340
341 echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">';
342 }
343
344 echo '<select class="redux-slider-select-one redux-slider-select-one-' . $fieldID . ' ' . $this->field['class'] . '"
345 name="' . $nameOne . '"
346 id="' . $idOne . '">
347 </select>';
348 }
349
350 // DIV output
351 echo '<div
352 class="redux-slider-container ' . $this->field['class'] . '"
353 id="' . $fieldID . '"
354 data-id="' . $fieldID . '"
355 data-min="' . $this->field['min'] . '"
356 data-max="' . $this->field['max'] . '"
357 data-step="' . $this->field['step'] . '"
358 data-handles="' . $this->field['handles'] . '"
359 data-display="' . $this->field['display_value'] . '"
360 data-rtl="' . is_rtl() . '"
361 data-forced="' . $this->field['forced'] . '"
362 data-float-mark="' . $this->field['float_mark'] . '"
363 data-resolution="' . $this->field['resolution'] . '" ' . $html . '>
364 </div>';
365
366 // Double slider output
367 if ( true == $twoHandles ) {
368
369 // TEXT
370 if ( true == $showInput ) {
371 echo '<input type="text"
372 name="' . $nameTwo . '"
373 id="' . $idTwo . '"
374 value="' . $valTwo . '"
375 class="redux-slider-input redux-slider-input-two-' . $fieldID . ' ' . $this->field['class'] . '"/>';
376 }
377
378 // LABEL
379 if ( true == $showLabel ) {
380 echo '<div class="redux-slider-label-two"
381 id="redux-slider-label-two-' . $fieldID . '"
382 name="' . $nameTwo . '">
383 </div>';
384 }
385
386 // SELECT
387 if ( true == $showSelect ) {
388 echo '<select class="redux-slider-select-two redux-slider-select-two-' . $fieldID . ' ' . $this->field['class'] . '"
389 name="' . $nameTwo . '"
390 id="' . $idTwo . '">
391 </select>';
392
393 }
394 }
395
396 // NO output (input hidden)
397 if ( $this->display_none == $this->field['display_value'] || $this->display_label == $this->field['display_value'] ) {
398 echo '<input type="hidden"
399 class="redux-slider-value-one-' . $fieldID . ' ' . $this->field['class'] . '"
400 name="' . $nameOne . '"
401 id="' . $idOne . '"
402 value="' . $valOne . '"/>';
403
404 // double slider hidden output
405 if ( true == $twoHandles ) {
406 echo '<input type="hidden"
407 class="redux-slider-value-two-' . $fieldID . ' ' . $this->field['class'] . '"
408 name="' . $nameTwo . '"
409 id="' . $idTwo . '"
410 value="' . $valTwo . '"/>';
411 }
412 }
413 }
414 }
415 }
416