ReduxFramework_slides

Main ReduxFramework_slides class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/slides/field_slides.php  
  1. class ReduxFramework_slides { 
  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 1.0.0 
  7. * @access public 
  8. * @return void 
  9. */ 
  10. function __construct ( $field = array(), $value = '', $parent ) { 
  11. $this->parent = $parent; 
  12. $this->field = $field; 
  13. $this->value = $value; 
  14.  
  15. /** 
  16. * Field Render Function. 
  17. * Takes the vars and outputs the HTML for the field in the settings 
  18. * @since 1.0.0 
  19. * @access public 
  20. * @return void 
  21. */ 
  22. public function render () { 
  23.  
  24. $defaults = array( 
  25. 'show' => array( 
  26. 'title' => true,  
  27. 'description' => true,  
  28. 'url' => true,  
  29. ),  
  30. 'content_title' => __ ( 'Slide', 'redux-framework' ) 
  31. ); 
  32.  
  33. $this->field = wp_parse_args ( $this->field, $defaults ); 
  34.  
  35. echo '<div class="redux-slides-accordion" data-new-content-title="' . esc_attr ( sprintf ( __ ( 'New %s', 'redux-framework' ), $this->field[ 'content_title' ] ) ) . '">'; 
  36.  
  37. $x = 0; 
  38.  
  39. $multi = ( isset ( $this->field[ 'multi' ] ) && $this->field[ 'multi' ] ) ? ' multiple="multiple"' : ""; 
  40.  
  41. if ( isset ( $this->value ) && is_array ( $this->value ) && !empty ( $this->value ) ) { 
  42.  
  43. $slides = $this->value; 
  44.  
  45. foreach ( $slides as $slide ) { 
  46.  
  47. if ( empty ( $slide ) ) { 
  48. continue; 
  49.  
  50. $defaults = array( 
  51. 'title' => '',  
  52. 'description' => '',  
  53. 'sort' => '',  
  54. 'url' => '',  
  55. 'image' => '',  
  56. 'thumb' => '',  
  57. 'attachment_id' => '',  
  58. 'height' => '',  
  59. 'width' => '',  
  60. 'select' => array(),  
  61. ); 
  62. $slide = wp_parse_args ( $slide, $defaults ); 
  63.  
  64. if ( empty ( $slide[ 'thumb' ] ) && !empty ( $slide[ 'attachment_id' ] ) ) { 
  65. $img = wp_get_attachment_image_src ( $slide[ 'attachment_id' ], 'full' ); 
  66. $slide[ 'image' ] = $img[ 0 ]; 
  67. $slide[ 'width' ] = $img[ 1 ]; 
  68. $slide[ 'height' ] = $img[ 2 ]; 
  69.  
  70. echo '<div class="redux-slides-accordion-group"><fieldset class="redux-field" data-id="' . $this->field[ 'id' ] . '"><h3><span class="redux-slides-header">' . $slide[ 'title' ] . '</span></h3><div>'; 
  71.  
  72. $hide = ''; 
  73. if ( empty ( $slide[ 'image' ] ) ) { 
  74. $hide = ' hide'; 
  75.  
  76.  
  77. echo '<div class="screenshot' . $hide . '">'; 
  78. echo '<a class="of-uploaded-image" href="' . $slide[ 'image' ] . '">'; 
  79. echo '<img class="redux-slides-image" id="image_image_id_' . $x . '" src="' . $slide[ 'thumb' ] . '" alt="" target="_blank" rel="external" />'; 
  80. echo '</a>'; 
  81. echo '</div>'; 
  82.  
  83. echo '<div class="redux_slides_add_remove">'; 
  84.  
  85. echo '<span class="button media_upload_button" id="add_' . $x . '">' . __ ( 'Upload', 'redux-framework' ) . '</span>'; 
  86.  
  87. $hide = ''; 
  88. if ( empty ( $slide[ 'image' ] ) || $slide[ 'image' ] == '' ) { 
  89. $hide = ' hide'; 
  90.  
  91. echo '<span class="button remove-image' . $hide . '" id="reset_' . $x . '" rel="' . $slide[ 'attachment_id' ] . '">' . __ ( 'Remove', 'redux-framework' ) . '</span>'; 
  92.  
  93. echo '</div>' . "\n"; 
  94.  
  95. echo '<ul id="' . $this->field[ 'id' ] . '-ul" class="redux-slides-list">'; 
  96.  
  97. if ( $this->field[ 'show' ][ 'title' ] ) { 
  98. $title_type = "text"; 
  99. } else { 
  100. $title_type = "hidden"; 
  101.  
  102. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'title' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'title' ] ) : __ ( 'Title', 'redux-framework' ); 
  103. echo '<li><input type="' . $title_type . '" id="' . $this->field[ 'id' ] . '-title_' . $x . '" name="' . $this->field[ 'name' ] . '[' . $x . '][title]' . $this->field['name_suffix'] . '" value="' . esc_attr ( $slide[ 'title' ] ) . '" placeholder="' . $placeholder . '" class="full-text slide-title" /></li>'; 
  104.  
  105. if ( $this->field[ 'show' ][ 'description' ] ) { 
  106. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'description' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'description' ] ) : __ ( 'Description', 'redux-framework' ); 
  107. echo '<li><textarea name="' . $this->field[ 'name' ] . '[' . $x . '][description]' . $this->field['name_suffix'] . '" id="' . $this->field[ 'id' ] . '-description_' . $x . '" placeholder="' . $placeholder . '" class="large-text" rows="6">' . esc_attr ( $slide[ 'description' ] ) . '</textarea></li>'; 
  108.  
  109. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'url' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'url' ] ) : __ ( 'URL', 'redux-framework' ); 
  110. if ( $this->field[ 'show' ][ 'url' ] ) { 
  111. $url_type = "text"; 
  112. } else { 
  113. $url_type = "hidden"; 
  114.  
  115. echo '<li><input type="' . $url_type . '" id="' . $this->field[ 'id' ] . '-url_' . $x . '" name="' . $this->field[ 'name' ] . '[' . $x . '][url]' . $this->field['name_suffix'] .'" value="' . esc_attr ( $slide[ 'url' ] ) . '" class="full-text" placeholder="' . $placeholder . '" /></li>'; 
  116. echo '<li><input type="hidden" class="slide-sort" name="' . $this->field[ 'name' ] . '[' . $x . '][sort]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-sort_' . $x . '" value="' . $slide[ 'sort' ] . '" />'; 
  117. echo '<li><input type="hidden" class="upload-id" name="' . $this->field[ 'name' ] . '[' . $x . '][attachment_id]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_id_' . $x . '" value="' . $slide[ 'attachment_id' ] . '" />'; 
  118. echo '<input type="hidden" class="upload-thumbnail" name="' . $this->field[ 'name' ] . '[' . $x . '][thumb]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-thumb_url_' . $x . '" value="' . $slide[ 'thumb' ] . '" readonly="readonly" />'; 
  119. echo '<input type="hidden" class="upload" name="' . $this->field[ 'name' ] . '[' . $x . '][image]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_url_' . $x . '" value="' . $slide[ 'image' ] . '" readonly="readonly" />'; 
  120. echo '<input type="hidden" class="upload-height" name="' . $this->field[ 'name' ] . '[' . $x . '][height]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_height_' . $x . '" value="' . $slide[ 'height' ] . '" />'; 
  121. echo '<input type="hidden" class="upload-width" name="' . $this->field[ 'name' ] . '[' . $x . '][width]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_width_' . $x . '" value="' . $slide[ 'width' ] . '" /></li>'; 
  122. echo '<li><a href="javascript:void(0);" class="button deletion redux-slides-remove">' . __ ( 'Delete', 'redux-framework' ) . '</a></li>'; 
  123. echo '</ul></div></fieldset></div>'; 
  124. $x ++; 
  125.  
  126. if ( $x == 0 ) { 
  127. echo '<div class="redux-slides-accordion-group"><fieldset class="redux-field" data-id="' . $this->field[ 'id' ] . '"><h3><span class="redux-slides-header">New ' . $this->field[ 'content_title' ] . '</span></h3><div>'; 
  128.  
  129. $hide = ' hide'; 
  130.  
  131. echo '<div class="screenshot' . $hide . '">'; 
  132. echo '<a class="of-uploaded-image" href="">'; 
  133. echo '<img class="redux-slides-image" id="image_image_id_' . $x . '" src="" alt="" target="_blank" rel="external" />'; 
  134. echo '</a>'; 
  135. echo '</div>'; 
  136.  
  137. //Upload controls DIV 
  138. echo '<div class="upload_button_div">'; 
  139.  
  140. //If the user has WP3.5+ show upload/remove button 
  141. echo '<span class="button media_upload_button" id="add_' . $x . '">' . __ ( 'Upload', 'redux-framework' ) . '</span>'; 
  142.  
  143. echo '<span class="button remove-image' . $hide . '" id="reset_' . $x . '" rel="' . $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . '][attachment_id]">' . __ ( 'Remove', 'redux-framework' ) . '</span>'; 
  144.  
  145. echo '</div>' . "\n"; 
  146.  
  147. echo '<ul id="' . $this->field[ 'id' ] . '-ul" class="redux-slides-list">'; 
  148. if ( $this->field[ 'show' ][ 'title' ] ) { 
  149. $title_type = "text"; 
  150. } else { 
  151. $title_type = "hidden"; 
  152. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'title' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'title' ] ) : __ ( 'Title', 'redux-framework' ); 
  153. echo '<li><input type="' . $title_type . '" id="' . $this->field[ 'id' ] . '-title_' . $x . '" name="' . $this->field[ 'name' ] . '[' . $x . '][title]' . $this->field['name_suffix'] .'" value="" placeholder="' . $placeholder . '" class="full-text slide-title" /></li>'; 
  154.  
  155. if ( $this->field[ 'show' ][ 'description' ] ) { 
  156. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'description' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'description' ] ) : __ ( 'Description', 'redux-framework' ); 
  157. echo '<li><textarea name="' . $this->field[ 'name' ] . '[' . $x . '][description]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-description_' . $x . '" placeholder="' . $placeholder . '" class="large-text" rows="6"></textarea></li>'; 
  158. $placeholder = ( isset ( $this->field[ 'placeholder' ][ 'url' ] ) ) ? esc_attr ( $this->field[ 'placeholder' ][ 'url' ] ) : __ ( 'URL', 'redux-framework' ); 
  159. if ( $this->field[ 'show' ][ 'url' ] ) { 
  160. $url_type = "text"; 
  161. } else { 
  162. $url_type = "hidden"; 
  163. echo '<li><input type="' . $url_type . '" id="' . $this->field[ 'id' ] . '-url_' . $x . '" name="' . $this->field[ 'name' ] . '[' . $x . '][url]' . $this->field['name_suffix'] .'" value="" class="full-text" placeholder="' . $placeholder . '" /></li>'; 
  164. echo '<li><input type="hidden" class="slide-sort" name="' . $this->field[ 'name' ] . '[' . $x . '][sort]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-sort_' . $x . '" value="' . $x . '" />'; 
  165. echo '<li><input type="hidden" class="upload-id" name="' . $this->field[ 'name' ] . '[' . $x . '][attachment_id]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_id_' . $x . '" value="" />'; 
  166. echo '<input type="hidden" class="upload" name="' . $this->field[ 'name' ] . '[' . $x . '][image]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_url_' . $x . '" value="" readonly="readonly" />'; 
  167. echo '<input type="hidden" class="upload-height" name="' . $this->field[ 'name' ] . '[' . $x . '][height]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_height_' . $x . '" value="" />'; 
  168. echo '<input type="hidden" class="upload-width" name="' . $this->field[ 'name' ] . '[' . $x . '][width]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-image_width_' . $x . '" value="" /></li>'; 
  169. echo '<input type="hidden" class="upload-thumbnail" name="' . $this->field[ 'name' ] . '[' . $x . '][thumb]' . $this->field['name_suffix'] .'" id="' . $this->field[ 'id' ] . '-thumb_url_' . $x . '" value="" /></li>'; 
  170. echo '<li><a href="javascript:void(0);" class="button deletion redux-slides-remove">' . __ ( 'Delete', 'redux-framework' ) . '</a></li>'; 
  171. echo '</ul></div></fieldset></div>'; 
  172. echo '</div><a href="javascript:void(0);" class="button redux-slides-add button-primary" rel-id="' . $this->field[ 'id' ] . '-ul" rel-name="' . $this->field[ 'name' ] . '[title][]' . $this->field['name_suffix'] .'">' . sprintf ( __ ( 'Add %s', 'redux-framework' ), $this->field[ 'content_title' ] ) . '</a><br/>'; 
  173.  
  174. /** 
  175. * Enqueue Function. 
  176. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  177. * @since 1.0.0 
  178. * @access public 
  179. * @return void 
  180. */ 
  181. public function enqueue () { 
  182.  
  183.  
  184. wp_enqueue_script( 
  185. 'redux-field-media-js',  
  186. ReduxFramework::$_url . 'assets/js/media/media' . Redux_Functions::isMin() . '.js',  
  187. array( 'jquery', 'redux-js' ),  
  188. time(),  
  189. true 
  190. ); 
  191.  
  192. redux_enqueue_style( 
  193. $this->parent,  
  194. 'redux-field-media-css',  
  195. ReduxFramework::$_url . 'inc/fields/media/field_media.css',  
  196. ReduxFramework::$_dir . 'inc/fields/media',  
  197. array(),  
  198. time(),  
  199. false 
  200. );  
  201.  
  202. // wp_enqueue_style ( 
  203. // 'redux-field-media-css',  
  204. // ReduxFramework::$_url . 'inc/fields/media/field_media.css',  
  205. // time (),  
  206. // true 
  207. // ); 
  208.  
  209. wp_enqueue_script ( 
  210. 'redux-field-slides-js',  
  211. ReduxFramework::$_url . 'inc/fields/slides/field_slides' . Redux_Functions::isMin () . '.js',  
  212. array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'wp-color-picker', 'redux-field-media-js' ),  
  213. time (),  
  214. true 
  215. ); 
  216.  
  217. redux_enqueue_style( 
  218. $this->parent,  
  219. 'redux-field-slides-css',  
  220. ReduxFramework::$_url . 'inc/fields/slides/field_slides.css',  
  221. ReduxFramework::$_dir . 'inc/fields/slides',  
  222. array(),  
  223. time(),  
  224. false 
  225. );  
  226.  
  227. // wp_enqueue_style ( 
  228. // 'redux-field-slides-css',  
  229. // ReduxFramework::$_url . 'inc/fields/slides/field_slides.css',  
  230. // time (),  
  231. // true 
  232. // );