ReduxFramework_sorter

The Gravity Forms Advanced File Uploader ReduxFramework sorter class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/sorter/field_sorter.php  
  1. class ReduxFramework_sorter { 
  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 Redux_Options 1.0.0 
  7. */ 
  8. function __construct( $field = array(), $value = '', $parent ) { 
  9. $this->parent = $parent; 
  10. $this->field = $field; 
  11. $this->value = $value; 
  12.  
  13. private function replace_id_with_slug($arr) { 
  14. $new_arr = array(); 
  15.  
  16. foreach($arr as $id => $name) { 
  17.  
  18. if ( is_numeric ( $id ) ) { 
  19. $slug = strtolower($name); 
  20. $slug = str_replace(' ', '-', $slug); 
  21.  
  22. $new_arr[$slug] = $name; 
  23. } else { 
  24. $new_arr[$id] = $name; 
  25.  
  26. return $new_arr; 
  27.  
  28. private function is_value_empty($val) { 
  29. foreach($val as $section => $arr) { 
  30. if (!empty($arr)) { 
  31. return false; 
  32.  
  33. return true; 
  34.  
  35. /** 
  36. * Field Render Function. 
  37. * Takes the vars and outputs the HTML for the field in the settings 
  38. * @since 1.0.0 
  39. */ 
  40. function render() { 
  41.  
  42. if ( ! is_array( $this->value ) && isset( $this->field['options'] ) ) { 
  43. $this->value = $this->field['options']; 
  44.  
  45. if ( ! isset( $this->field['args'] ) ) { 
  46. $this->field['args'] = array(); 
  47.  
  48. if ( isset( $this->field['data'] ) && ! empty( $this->field['data'] ) && is_array( $this->field['data'] ) ) { 
  49. foreach ( $this->field['data'] as $key => $data ) { 
  50. if ( ! isset( $this->field['args'][ $key ] ) ) { 
  51. $this->field['args'][ $key ] = array(); 
  52.  
  53. $this->field['options'][ $key ] = $this->parent->get_wordpress_data( $data, $this->field['args'][ $key ] ); 
  54.  
  55. // id numbers as array keys won't work in the checks below 
  56. // so, replace them with slugs of the value. 
  57. $this->field['options'][ $key ] = $this->replace_id_with_slug($this->field['options'][ $key ]); 
  58.  
  59. // Make sure to get list of all the default blocks first 
  60. $all_blocks = ! empty( $this->field['options'] ) ? $this->field['options'] : array(); 
  61. $temp = array(); // holds default blocks 
  62. $temp2 = array(); // holds saved blocks 
  63.  
  64. foreach ( $all_blocks as $blocks ) { 
  65. $temp = array_merge( $temp, $blocks ); 
  66.  
  67. if ($this->is_value_empty ( $this->value)) { 
  68. $this->value = $this->field['options']; 
  69.  
  70. $sortlists = $this->value; 
  71.  
  72. foreach($sortlists as $section => $arr) { 
  73. $sortlists[$section] = $this->replace_id_with_slug($arr); 
  74.  
  75. if ( is_array( $sortlists ) ) { 
  76. foreach ( $sortlists as $sortlist ) { 
  77. $temp2 = array_merge( $temp2, $sortlist ); 
  78.  
  79. // now let's compare if we have anything missing 
  80. foreach ( $temp as $k => $v ) { 
  81. // k = id/slug 
  82. // v = name 
  83.  
  84. if (!empty($temp2)) { 
  85. if ( ! array_key_exists( $k, $temp2 ) ) { 
  86. $sortlists['disabled'][ $k ] = $v; 
  87.  
  88. // now check if saved blocks has blocks not registered under default blocks 
  89. foreach ( $sortlists as $key => $sortlist ) { 
  90. // key = enabled, disabled, backup 
  91. // sortlist = id => name 
  92.  
  93. foreach ( $sortlist as $k => $v ) { 
  94. // k = id 
  95. // v = name 
  96. if ( ! array_key_exists( $k, $temp ) ) { 
  97. unset( $sortlist[ $k ] ); 
  98. $sortlists[ $key ] = $sortlist; 
  99.  
  100. // assuming all sync'ed, now get the correct naming for each block 
  101. foreach ( $sortlists as $key => $sortlist ) { 
  102. foreach ( $sortlist as $k => $v ) { 
  103. $sortlist[ $k ] = $temp[ $k ]; 
  104. $sortlists[ $key ] = $sortlist; 
  105.  
  106. if ( $sortlists ) { 
  107. echo '<fieldset id="' . $this->field['id'] . '" class="redux-sorter-container redux-sorter">'; 
  108.  
  109. foreach ( $sortlists as $group => $sortlist ) { 
  110. $filled = ""; 
  111.  
  112. if ( isset( $this->field['limits'][ $group ] ) && count( $sortlist ) >= $this->field['limits'][ $group ] ) { 
  113. $filled = " filled"; 
  114.  
  115. echo '<ul id="' . $this->field['id'] . '_' . $group . '" class="sortlist_' . $this->field['id'] . $filled . '" data-id="' . $this->field['id'] . '" data-group-id="' . $group . '">'; 
  116. echo '<h3>' . $group . '</h3>'; 
  117.  
  118. if ( ! isset( $sortlist['placebo'] ) ) { 
  119. array_unshift( $sortlist, array( "placebo" => "placebo" ) ); 
  120.  
  121. foreach ( $sortlist as $key => $list ) { 
  122.  
  123. echo '<input class="sorter-placebo" type="hidden" name="' . $this->field['name'] . '[' . $group . '][placebo]' . $this->field['name_suffix'] . '" value="placebo">'; 
  124.  
  125. if ( $key != "placebo" ) { 
  126.  
  127. //echo '<li id="' . $key . '" class="sortee">'; 
  128. echo '<li id="sortee-' . $key . '" class="sortee" data-id="'. $key .'">'; 
  129. echo '<input class="position ' . $this->field['class'] . '" type="hidden" name="' . $this->field['name'] . '[' . $group . '][' . $key . ']' . $this->field['name_suffix'] . '" value="' . $list . '">'; 
  130. echo $list; 
  131. echo '</li>'; 
  132.  
  133. echo '</ul>'; 
  134. echo '</fieldset>'; 
  135.  
  136. function enqueue() { 
  137. redux_enqueue_style( 
  138. $this->parent,  
  139. 'redux-field-sorder-css',  
  140. ReduxFramework::$_url . 'inc/fields/sorter/field_sorter.css',  
  141. ReduxFramework::$_dir . 'inc/fields/sorter',  
  142. array(),  
  143. time(),  
  144. false 
  145. );  
  146.  
  147. // wp_enqueue_style( 
  148. // 'redux-field-sorder-css',  
  149. // ReduxFramework::$_url . 'inc/fields/sorter/field_sorter.css',  
  150. // time(),  
  151. // true 
  152. // ); 
  153.  
  154. wp_enqueue_script( 
  155. 'redux-field-sorter-js',  
  156. ReduxFramework::$_url . 'inc/fields/sorter/field_sorter' . Redux_Functions::isMin() . '.js',  
  157. array( 'jquery', 'redux-js' ),  
  158. time(),  
  159. true 
  160. ); 
  161.  
  162. /** 
  163. * Functions to pass data from the PHP to the JS at render time. 
  164. * @return array Params to be saved as a javascript object accessable to the UI. 
  165. * @since Redux_Framework 3.1.5 
  166. */ 
  167. function localize( $field, $value = "" ) { 
  168.  
  169. $params = array(); 
  170.  
  171. if ( isset( $field['limits'] ) && ! empty( $field['limits'] ) ) { 
  172. $params['limits'] = $field['limits']; 
  173.  
  174. if ( empty( $value ) ) { 
  175. $value = $this->value; 
  176. $params['val'] = $value; 
  177.  
  178. return $params;