ReduxFramework_slider

The Gravity Forms Advanced File Uploader ReduxFramework slider class.

Defined (1)

The class is defined in the following location(s).

/inc/ReduxFramework/ReduxCore/inc/fields/slider/field_slider.php  
  1. class ReduxFramework_slider { 
  2.  
  3. /** 
  4. * Field Constructor. 
  5. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function 
  6. * @since ReduxFramework 3.1.8 
  7. */ 
  8. private $display_none = 0; 
  9. private $display_label = 1; 
  10. private $display_text = 2; 
  11. private $display_select = 3; 
  12.  
  13. function __construct( $field = array(), $value = '', $parent ) { 
  14.  
  15. //parent::__construct( $parent->sections, $parent->args ); 
  16. $this->parent = $parent; 
  17. $this->field = $field; 
  18. $this->value = $value; 
  19.  
  20. // Set defaults 
  21. $defaults = array( 
  22. 'handles' => 1,  
  23. 'resolution' => 1,  
  24. 'display_value' => 'text',  
  25. 'float_mark' => '.',  
  26. ); 
  27.  
  28. $this->field = wp_parse_args( $this->field, $defaults ); 
  29.  
  30. // Sanitize float mark 
  31. switch ( $this->field['float_mark'] ) { 
  32. case ', ': 
  33. case '.': 
  34. break; 
  35. default: 
  36. $this->field['float_mark'] = '.'; 
  37. break; 
  38.  
  39. // Sanitize resolution value 
  40. $this->field['resolution'] = $this->cleanVal( $this->field['resolution'] ); 
  41.  
  42. // Sanitize handle value 
  43. switch ( $this->field['handles'] ) { 
  44. case 0: 
  45. case 1: 
  46. $this->field['handles'] = 1; 
  47. break; 
  48. default: 
  49. $this->field['handles'] = 2; 
  50. break; 
  51.  
  52. // Sanitize display value 
  53. switch ( $this->field['display_value'] ) { 
  54. case 'label': 
  55. $this->field['display_value'] = $this->display_label; 
  56. break; 
  57. case 'text': 
  58. default: 
  59. $this->field['display_value'] = $this->display_text; 
  60. break; 
  61. case 'select': 
  62. $this->field['display_value'] = $this->display_select; 
  63. break; 
  64. case 'none': 
  65. $this->field['display_value'] = $this->display_none; 
  66. break; 
  67.  
  68. private function cleanVal( $var ) { 
  69. if ( is_float( $var ) ) { 
  70. $cleanVar = floatval( $var ); 
  71. } else { 
  72. $cleanVar = intval( $var ); 
  73.  
  74. return $cleanVar; 
  75.  
  76. private function cleanDefault( $val ) { 
  77. if ( empty( $val ) && ! empty( $this->field['default'] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  78. $val = $this->cleanVal( $this->field['default'] ); 
  79.  
  80. if ( empty( $val ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  81. $val = $this->cleanVal( $this->field['min'] ); 
  82.  
  83. if ( empty( $val ) ) { 
  84. $val = 0; 
  85.  
  86. // Extra Validation 
  87. if ( $val < $this->field['min'] ) { 
  88. $val = $this->cleanVal( $this->field['min'] ); 
  89. } else if ( $val > $this->field['max'] ) { 
  90. $val = $this->cleanVal( $this->field['max'] ); 
  91.  
  92. return $val; 
  93.  
  94. private function cleanDefaultArray( $val ) { 
  95. $one = $this->value[1]; 
  96. $two = $this->value[2]; 
  97.  
  98. if ( empty( $one ) && ! empty( $this->field['default'][1] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  99. $one = $this->cleanVal( $this->field['default'][1] ); 
  100.  
  101. if ( empty( $one ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  102. $one = $this->cleanVal( $this->field['min'] ); 
  103.  
  104. if ( empty( $one ) ) { 
  105. $one = 0; 
  106.  
  107. if ( empty( $two ) && ! empty( $this->field['default'][2] ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  108. $two = $this->cleanVal( $this->field['default'][1] + 1 ); 
  109.  
  110. if ( empty( $two ) && $this->cleanVal( $this->field['min'] ) >= 1 ) { 
  111. $two = $this->cleanVal( $this->field['default'][1] + 1 ); 
  112.  
  113. if ( empty( $two ) ) { 
  114. $two = $this->field['default'][1] + 1; 
  115.  
  116. $val[0] = $one; 
  117. $val[1] = $two; 
  118.  
  119. return $val; 
  120.  
  121.  
  122. /** 
  123. * Clean the field data to the fields defaults given the parameters. 
  124. * @since Redux_Framework 3.1.8 
  125. */ 
  126. function clean() { 
  127.  
  128. // Set min to 0 if no value is set. 
  129. $this->field['min'] = empty( $this->field['min'] ) ? 0 : $this->cleanVal( $this->field['min'] ); 
  130.  
  131. // Set max to min + 1 if empty. 
  132. $this->field['max'] = empty( $this->field['max'] ) ? $this->field['min'] + 1 : $this->cleanVal( $this->field['max'] ); 
  133.  
  134. // Set step to 1 if step is empty ot step > max. 
  135. $this->field['step'] = empty( $this->field['step'] ) || $this->field['step'] > $this->field['max'] ? 1 : $this->cleanVal( $this->field['step'] ); 
  136.  
  137. if ( 2 == $this->field['handles'] ) { 
  138. if ( ! is_array( $this->value ) ) { 
  139. $this->value[1] = 0; 
  140. $this->value[2] = 1; 
  141. $this->value = $this->cleanDefaultArray( $this->value ); 
  142. } else { 
  143. if ( is_array( $this->value ) ) { 
  144. $this->value = 0; 
  145. $this->value = $this->cleanDefault( $this->value ); 
  146.  
  147. // More dummy checks 
  148. //if ( ! is_array( $this->field['default'] ) && 2 == $this->field['handles'] ) { 
  149. if ( ! is_array( $this->value ) && 2 == $this->field['handles'] ) { 
  150. $this->value[0] = $this->field['min']; 
  151. $this->value[1] = $this->field['min'] + 1; 
  152.  
  153. //if ( is_array( $this->field['default'] ) && 1 == $this->field['handles'] ) { 
  154. if ( is_array( $this->value ) && 1 == $this->field['handles'] ) { 
  155. $this->value = $this->field['min']; 
  156.  
  157.  
  158. /** 
  159. * Enqueue Function. 
  160. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  161. * @since ReduxFramework 3.1.8 
  162. */ 
  163. function enqueue() { 
  164.  
  165. $min = Redux_Functions::isMin(); 
  166.  
  167. wp_enqueue_style( 
  168. 'redux-nouislider-css',  
  169. ReduxFramework::$_url . 'inc/fields/slider/vendor/nouislider/redux.jquery.nouislider.css',  
  170. array(),  
  171. filemtime( ReduxFramework::$_dir . 'inc/fields/slider/vendor/nouislider/redux.jquery.nouislider.css' ),  
  172. 'all' 
  173. ); 
  174.  
  175. wp_register_script( 
  176. 'redux-nouislider-js',  
  177. ReduxFramework::$_url . 'inc/fields/slider/vendor/nouislider/redux.jquery.nouislider' . $min . '.js',  
  178. array( 'jquery' ),  
  179. '5.0.0',  
  180. true 
  181. ); 
  182.  
  183. wp_enqueue_script( 
  184. 'redux-field-slider-js',  
  185. ReduxFramework::$_url . 'inc/fields/slider/field_slider' . $min . '.js',  
  186. array( 'jquery', 'redux-nouislider-js', 'redux-js', 'select2-js' ),  
  187. time(),  
  188. true 
  189. ); 
  190.  
  191. redux_enqueue_style( 
  192. $this->parent,  
  193. 'redux-field-slider-css',  
  194. ReduxFramework::$_url . 'inc/fields/slider/field_slider.css',  
  195. ReduxFramework::$_dir . 'inc/fields/slider',  
  196. array(),  
  197. time(),  
  198. false 
  199. );  
  200.  
  201. // wp_enqueue_style( 
  202. // 'redux-field-slider-css',  
  203. // ReduxFramework::$_url . 'inc/fields/slider/field_slider.css',  
  204. // time(),  
  205. // true 
  206. // ); 
  207.  
  208. //function 
  209.  
  210. /** 
  211. * Field Render Function. 
  212. * Takes the vars and outputs the HTML for the field in the settings 
  213. * @since ReduxFramework 0.0.4 
  214. */ 
  215. function render() { 
  216.  
  217. $this->clean(); 
  218.  
  219. $fieldID = $this->field['id']; 
  220. $fieldName = $this->field['name'] . $this->field['name_suffix']; 
  221. //$fieldName = $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']'; 
  222.  
  223. // Set handle number variable. 
  224. $twoHandles = false; 
  225. if ( 2 == $this->field['handles'] ) { 
  226. $twoHandles = true; 
  227.  
  228. // Set default values(s) 
  229. if ( true == $twoHandles ) { 
  230. $valOne = $this->value[0]; 
  231. $valTwo = $this->value[1]; 
  232.  
  233. $html = 'data-default-one="' . $valOne . '" '; 
  234. $html .= 'data-default-two="' . $valTwo . '" '; 
  235.  
  236. $nameOne = $fieldName . '[1]'; 
  237. $nameTwo = $fieldName . '[2]'; 
  238.  
  239. $idOne = $fieldID . '[1]'; 
  240. $idTwo = $fieldID . '[2]'; 
  241. } else { 
  242. $valOne = $this->value; 
  243. $valTwo = ''; 
  244.  
  245. $html = 'data-default-one="' . $valOne . '"'; 
  246.  
  247. $nameOne = $fieldName; 
  248. $nameTwo = ''; 
  249.  
  250. $idOne = $fieldID; 
  251. $idTwo = ''; 
  252.  
  253. $showInput = false; 
  254. $showLabel = false; 
  255. $showSelect = false; 
  256.  
  257. // TEXT output 
  258. if ( $this->display_text == $this->field['display_value'] ) { 
  259. $showInput = true; 
  260. echo '<input type="text" 
  261. name="' . $nameOne . '" 
  262. id="' . $idOne . '" 
  263. value="' . $valOne . '" 
  264. class="redux-slider-input redux-slider-input-one-' . $fieldID . ' ' . $this->field['class'] . '"/>'; 
  265.  
  266. // LABEL output 
  267. } elseif ( $this->display_label == $this->field['display_value'] ) { 
  268. $showLabel = true; 
  269.  
  270. $labelNum = $twoHandles ? '-one' : ''; 
  271.  
  272. echo '<div class="redux-slider-label' . $labelNum . '" 
  273. id="redux-slider-label-one-' . $fieldID . '" 
  274. name="' . $nameOne . '"> 
  275. </div>'; 
  276.  
  277. // SELECT output 
  278. } elseif ( $this->display_select == $this->field['display_value'] ) { 
  279. $showSelect = true; 
  280.  
  281. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  282. $select2_params = json_encode( $this->field['select2'] ); 
  283. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  284.  
  285. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  286.  
  287.  
  288. echo '<select class="redux-slider-select-one redux-slider-select-one-' . $fieldID . ' ' . $this->field['class'] . '" 
  289. name="' . $nameOne . '" 
  290. id="' . $idOne . '"> 
  291. </select>'; 
  292.  
  293. // DIV output 
  294. echo  
  295. '<div 
  296. class="redux-slider-container ' . $this->field['class'] . '" 
  297. id="' . $fieldID . '" 
  298. data-id="' . $fieldID . '" 
  299. data-min="' . $this->field['min'] . '" 
  300. data-max="' . $this->field['max'] . '" 
  301. data-step="' . $this->field['step'] . '" 
  302. data-handles="' . $this->field['handles'] . '" 
  303. data-display="' . $this->field['display_value'] . '" 
  304. data-rtl="' . is_rtl() . '" 
  305. data-float-mark="' . $this->field['float_mark'] . '" 
  306. data-resolution="' . $this->field['resolution'] . '" ' . $html . '> 
  307. </div>'; 
  308.  
  309. // Double slider output 
  310. if ( true == $twoHandles ) { 
  311.  
  312. // TEXT 
  313. if ( true == $showInput ) { 
  314. echo '<input type="text" 
  315. name="' . $nameTwo . '" 
  316. id="' . $idTwo . '" 
  317. value="' . $valTwo . '" 
  318. class="redux-slider-input redux-slider-input-two-' . $fieldID . ' ' . $this->field['class'] . '"/>'; 
  319.  
  320. // LABEL 
  321. if ( true == $showLabel ) { 
  322. echo '<div class="redux-slider-label-two" 
  323. id="redux-slider-label-two-' . $fieldID . '" 
  324. name="' . $nameTwo . '"> 
  325. </div>'; 
  326.  
  327. // SELECT 
  328. if ( true == $showSelect ) { 
  329. echo '<select class="redux-slider-select-two redux-slider-select-two-' . $fieldID . ' ' . $this->field['class'] . '" 
  330. name="' . $nameTwo . '" 
  331. id="' . $idTwo . '"> 
  332. </select>'; 
  333.  
  334.  
  335. // NO output (input hidden) 
  336. if ( $this->display_none == $this->field['display_value'] || $this->display_label == $this->field['display_value'] ) { 
  337. echo '<input type="hidden" 
  338. class="redux-slider-value-one-' . $fieldID . ' ' . $this->field['class'] . '" 
  339. name="' . $nameOne . '" 
  340. id="' . $idOne . '" 
  341. value="' . $valOne . '"/>'; 
  342.  
  343. // double slider hidden output 
  344. if ( true == $twoHandles ) { 
  345. echo '<input type="hidden" 
  346. class="redux-slider-value-two-' . $fieldID . ' ' . $this->field['class'] . '" 
  347. name="' . $nameTwo . '" 
  348. id="' . $idTwo . '" 
  349. value="' . $valTwo . '"/>';