ReduxFramework_sortable

The Gravity Forms Advanced File Uploader ReduxFramework sortable class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/sortable/field_sortable.php  
  1. class ReduxFramework_sortable { 
  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 2.0.1 
  7. */ 
  8. function __construct( $field = array(), $value = '', $parent ) { 
  9. $this->parent = $parent; 
  10. $this->field = $field; 
  11. $this->value = $value; 
  12.  
  13. /** 
  14. * Field Render Function. 
  15. * Takes the vars and outputs the HTML for the field in the settings 
  16. * @since Redux_Options 2.0.1 
  17. */ 
  18. function render() { 
  19.  
  20. if ( empty( $this->field['mode'] ) ) { 
  21. $this->field['mode'] = "text"; 
  22.  
  23. if ( $this->field['mode'] != "checkbox" && $this->field['mode'] != "text" ) { 
  24. $this->field['mode'] = "text"; 
  25.  
  26. $class = ( isset( $this->field['class'] ) ) ? $this->field['class'] : ''; 
  27. $options = $this->field['options']; 
  28.  
  29. // This is to weed out missing options that might be in the default 
  30. // Why? Who knows. Call it a dummy check. 
  31. if ( ! empty( $this->value ) ) { 
  32. foreach ( $this->value as $k => $v ) { 
  33. if ( ! isset( $options[ $k ] ) ) { 
  34. unset( $this->value[ $k ] ); 
  35.  
  36. $noSort = false; 
  37. foreach ( $options as $k => $v ) { 
  38. if ( ! isset( $this->value[ $k ] ) ) { 
  39.  
  40. // A save has previously been done. 
  41. if ( is_array( $this->value ) && array_key_exists( $k, $this->value ) ) { 
  42. $this->value[ $k ] = $v; 
  43.  
  44. // Missing database entry, meaning no save has yet been done. 
  45. } else { 
  46. $noSort = true; 
  47. $this->value[ $k ] = ''; 
  48.  
  49. // If missing database entries are found, it means no save has been done 
  50. // and therefore no sort should be done. Set the default array in the same 
  51. // order as the options array. Why? The sort order is based on the 
  52. // saved default array. If entries are missing, the sort is messed up. 
  53. // - kp 
  54. if ( true == $noSort ) { 
  55. $dummyArr = array(); 
  56.  
  57. foreach ( $options as $k => $v ) { 
  58. $dummyArr[ $k ] = $this->value[ $k ]; 
  59. unset( $this->value ); 
  60. $this->value = $dummyArr; 
  61. unset( $dummytArr ); 
  62.  
  63. echo '<ul id="' . $this->field['id'] . '-list" class="redux-sortable ' . $class . '">'; 
  64.  
  65.  
  66. foreach ( $this->value as $k => $nicename ) { 
  67.  
  68. echo '<li>'; 
  69.  
  70. $checked = ""; 
  71. $name = 'name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' . '" '; 
  72. if ( $this->field['mode'] == "checkbox" ) { 
  73. $value_display = $this->value[ $k ]; 
  74.  
  75. if ( ! empty( $this->value[ $k ] ) ) { 
  76. $checked = 'checked="checked" '; 
  77. $class .= " checkbox_sortable"; 
  78. $name = ""; 
  79. echo '<input type="hidden" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' . '" id="' . $this->field['id'] . '-' . $k . '-hidden" value="' . $value_display . '" />'; 
  80.  
  81. echo '<div class="checkbox-container">'; 
  82. } else { 
  83. $value_display = isset( $this->value[ $k ] ) ? $this->value[ $k ] : ''; 
  84.  
  85.  
  86. if ($this->field['mode'] != "checkbox") { 
  87. echo '<label class="bugger" for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $k . '</strong></label>'; 
  88. echo "<br />";  
  89.  
  90. echo '<input rel="' . $this->field['id'] . '-' . $k . '-hidden" class="' . $class . '" ' . $checked . 'type="' . $this->field['mode'] . '" ' . $name . 'id="' . $this->field['id'] . '[' . $k . ']" value="' . esc_attr( $value_display ) . '" placeholder="' . $nicename . '" />'; 
  91.  
  92. echo '<span class="compact drag"><i class="el-icon-move icon-large"></i></span>'; 
  93. if ( $this->field['mode'] == "checkbox" || ( isset( $this->field['label'] ) && $this->field['label'] == true ) ) { 
  94. if ( $this->field['mode'] != "checkbox" ) { 
  95. //echo "<br />"; 
  96. //echo '<label for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $k . '</strong></label>'; 
  97. } else { 
  98. echo '<label for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $options[ $k ] . '</strong></label>'; 
  99. if ( $this->field['mode'] == "checkbox" ) { 
  100. echo '</div>'; 
  101. echo '</li>'; 
  102. echo '</ul>'; 
  103.  
  104. function enqueue() { 
  105. redux_enqueue_style( 
  106. $this->parent,  
  107. 'redux-field-sortable-css',  
  108. ReduxFramework::$_url . 'inc/fields/sortable/field_sortable.css',  
  109. ReduxFramework::$_dir . 'inc/fields/sortable',  
  110. array(),  
  111. time(),  
  112. false 
  113. );  
  114.  
  115. // wp_enqueue_style( 
  116. // 'redux-field-sortable-css',  
  117. // ReduxFramework::$_url . 'inc/fields/sortable/field_sortable.css',  
  118. // time(),  
  119. // true 
  120. // ); 
  121.  
  122. wp_enqueue_script( 
  123. 'redux-field-sortable-js',  
  124. ReduxFramework::$_url . 'inc/fields/sortable/field_sortable' . Redux_Functions::isMin() . '.js',  
  125. array( 'jquery', 'redux-js' ),  
  126. time(),  
  127. true 
  128. );