ReduxFramework_select_image

The Gravity Forms Advanced File Uploader ReduxFramework select image class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/select_image/field_select_image.php  
  1. class ReduxFramework_select_image { 
  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 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. /** 
  14. * Field Render Function. 
  15. * Takes the vars and outputs the HTML for the field in the settings 
  16. * @since ReduxFramework 1.0.0 
  17. */ 
  18. function render() { 
  19.  
  20. // If options is NOT empty, the process 
  21. if ( ! empty( $this->field['options'] ) ) { 
  22.  
  23. // Strip off the file ext 
  24. if ( isset( $this->value ) ) { 
  25. $name = explode( ".", $this->value ); 
  26. $name = str_replace( '.' . end( $name ), '', $this->value ); 
  27. $name = basename( $name ); 
  28. //$this->value = trim( $name ); 
  29. $filename = trim($name); 
  30.  
  31. // beancounter 
  32. $x = 1; 
  33.  
  34. // Process width 
  35. if ( ! empty( $this->field['width'] ) ) { 
  36. $width = ' style="width:' . $this->field['width'] . ';"'; 
  37. } else { 
  38. $width = ' style="width: 40%;"'; 
  39.  
  40. // Process placeholder 
  41. $placeholder = ( isset( $this->field['placeholder'] ) ) ? esc_attr( $this->field['placeholder'] ) : __( 'Select an item', 'redux-framework' ); 
  42.  
  43. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  44. $select2_params = json_encode( $this->field['select2'] ); 
  45. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  46.  
  47. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  48. }  
  49.  
  50. // Begin the <select> tag 
  51. echo '<select data-id="' . $this->field['id'] . '" data-placeholder="' . $placeholder . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '" class="redux-select-item redux-select-images ' . $this->field['class'] . '"' . $width . ' rows="6">'; 
  52. echo '<option></option>'; 
  53.  
  54.  
  55. // Enum through the options array 
  56. foreach ( $this->field['options'] as $k => $v ) { 
  57.  
  58. // No array? No problem! 
  59. if ( ! is_array( $v ) ) { 
  60. $v = array( 'img' => $v ); 
  61.  
  62. // No title set? Make it blank. 
  63. if ( ! isset( $v['title'] ) ) { 
  64. $v['title'] = ''; 
  65.  
  66. // No alt? Set it to title. We do this so the alt tag shows 
  67. // something. It also makes HTML/SEO purists happy. 
  68. if ( ! isset( $v['alt'] ) ) { 
  69. $v['alt'] = $v['title']; 
  70.  
  71. // Set the selected entry 
  72. $selected = selected( $this->value, $v['img'], false ); 
  73.  
  74. // If selected returns something other than a blank space, we 
  75. // found our default/saved name. Save the array number in a 
  76. // variable to use later on when we want to extract its associted 
  77. // url. 
  78. if ( '' != $selected ) { 
  79. $arrNum = $x; 
  80.  
  81. // Add the option tag, with values. 
  82. echo '<option value="' . $v['img'] . '" ' . $selected . '>' . $v['alt'] . '</option>'; 
  83.  
  84. // Add a bean 
  85. $x ++; 
  86.  
  87. // Close the <select> tag 
  88. echo '</select>'; 
  89.  
  90. // Some space 
  91. echo '<br /><br />'; 
  92.  
  93. // Show the preview image. 
  94. echo '<div>'; 
  95.  
  96. // just in case. You never know. 
  97. if ( ! isset( $arrNum ) ) { 
  98. $this->value = ''; 
  99.  
  100. // Set the default image. To get the url from the default name,  
  101. // we save the array count from the for/each loop, when the default image 
  102. // is mark as selected. Since the for/each loop starts at one, we must 
  103. // substract one from the saved array number. We then pull the url 
  104. // out of the options array, and there we go. 
  105. if ( '' == $this->value ) { 
  106. echo '<img src="#" class="redux-preview-image" style="visibility:hidden;" id="image_' . $this->field['id'] . '">'; 
  107. } else { 
  108. echo '<img src=' . $this->field['options'][ $arrNum - 1 ]['img'] . ' class="redux-preview-image" id="image_' . $this->field['id'] . '">'; 
  109.  
  110. // Close the <div> tag. 
  111. echo '</div>'; 
  112. } else { 
  113.  
  114. // No options specified. Really? 
  115. echo '<strong>' . __( 'No items of this type were found.', 'redux-framework' ) . '</strong>'; 
  116. } //function 
  117.  
  118. /** 
  119. * Enqueue Function. 
  120. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  121. * @since ReduxFramework 1.0.0 
  122. */ 
  123. function enqueue() { 
  124. wp_enqueue_script( 
  125. 'field-select-image-js',  
  126. ReduxFramework::$_url . 'inc/fields/select_image/field_select_image' . Redux_Functions::isMin() . '.js',  
  127. array('jquery', 'select2-js', 'redux-js'),  
  128. time(),  
  129. true 
  130. ); 
  131.  
  132. redux_enqueue_style( 
  133. $this->parent,  
  134. 'redux-field-select-image-css',  
  135. ReduxFramework::$_url . 'inc/fields/select_image/field_select_image.css',  
  136. ReduxFramework::$_dir . 'inc/fields/select_image',  
  137. array(),  
  138. time(),  
  139. false 
  140. );  
  141.  
  142. // wp_enqueue_style( 
  143. // 'redux-field-select-image-css',  
  144. // ReduxFramework::$_url . 'inc/fields/select_image/field_select_image.css',  
  145. // time(),  
  146. // true 
  147. // ); 
  148. } //function 
  149. } //class