NGG_Slideshow_Widget

The NextCellent Slideshow widget.

Defined (1)

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

/widgets/class-ngg-slideshow-widget.php  
  1. class NGG_Slideshow_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Register the widget. 
  5. */ 
  6. public function __construct() { 
  7. parent::__construct( 'slideshow', __( 'NextCellent Slideshow', 'nggallery' ), array( 
  8. 'classname' => 'widget_slideshow',  
  9. 'description' => __( 'Show a NextCellent Gallery Slideshow', 'nggallery' ) 
  10. ) ); 
  11.  
  12. /** 
  13. * Front-end display of widget. 
  14. * @see WP_Widget::widget() 
  15. * @param array $args Widget arguments. 
  16. * @param array $instance Saved values from the database. 
  17. */ 
  18. public function widget( $args, $instance ) { 
  19.  
  20. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Slideshow', 'nggallery' ) : $instance['title'], $instance, $this->id_base ); 
  21.  
  22. try { 
  23. $out = nggShowSlideshow( $instance['galleryid'], $instance ); 
  24. } catch ( NGG_Not_Found $e ) { 
  25. $out = $e->getMessage(); 
  26.  
  27. if ( ! empty( $out ) ) { 
  28. echo $args['before_widget']; 
  29. if ( $title ) { 
  30. echo $args['before_title'] . $title . $args['after_title']; 
  31. echo '<div class="ngg_slideshow widget">' . $out . '</div>'; 
  32. echo $args['after_widget']; 
  33.  
  34.  
  35. /** 
  36. * Sanitize widget form values as they are saved. 
  37. * @see WP_Widget::update() 
  38. * @param array $new_instance Values just sent to be saved. 
  39. * @param array $old_instance Previously saved values from database. 
  40. * @return array Updated safe values to be saved. 
  41. */ 
  42. function update( $new_instance, $old_instance ) { 
  43. $instance = $old_instance; 
  44.  
  45. $instance['title'] = sanitize_text_field( $new_instance['title'] ); 
  46.  
  47. if ( is_numeric( $new_instance['galleryid'] ) ) { 
  48. $instance['galleryid'] = (int) $new_instance['galleryid']; 
  49. } elseif ( $new_instance['galleryid'] == 'recent' ) { 
  50. $instance['galleryid'] = 'recent'; 
  51. } else { 
  52. $instance['galleryid'] = 'random'; 
  53.  
  54. $instance['height'] = (int) $new_instance['height']; 
  55. $instance['width'] = (int) $new_instance['width']; 
  56. $instance['autodim'] = (bool) $new_instance['autodim']; 
  57.  
  58. return $instance; 
  59.  
  60. /** 
  61. * Back-end widget form. 
  62. * @see WP_Widget::form() 
  63. * @param array $instance Previously saved values from database. 
  64. * @return string Default return is 'noform'. 
  65. */ 
  66. function form( $instance ) { 
  67.  
  68. global $ngg; 
  69. $ngg_options = $ngg->options; 
  70.  
  71. //Defaults 
  72. $instance = wp_parse_args( (array) $instance, array( 
  73. 'title' => __( 'Slideshow', 'nggallery' ),  
  74. 'galleryid' => 'random',  
  75. 'width' => $ngg_options['irWidth'],  
  76. 'height' => $ngg_options['irHeight'],  
  77. 'class' => 'ngg-widget-slideshow',  
  78. 'nav' => false,  
  79. 'autoplay' => true,  
  80. 'autodim' => $ngg_options['irAutoDim'],  
  81. ) ); 
  82. $height = esc_attr( $instance['height'] ); 
  83. $width = esc_attr( $instance['width'] ); 
  84. ?> 
  85. <p> 
  86. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
  87. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" 
  88. name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" 
  89. value="<?php esc_attr_e( $instance['title'] ); ?>"/> 
  90. </p> 
  91. <p> 
  92. <label 
  93. for="<?php echo $this->get_field_id( 'galleryid' ); ?>"><?php _e( 'Select a gallery:', 'nggallery' ); ?></label> 
  94. <select name="<?php echo $this->get_field_name( 'galleryid' ); ?>" 
  95. id="<?php echo $this->get_field_id( 'galleryid' ); ?>" class="widefat"> 
  96. <option 
  97. value="random" <?php selected( $instance['galleryid'], 'random' ); ?> ><?php _e( 'Random images', 'nggallery' ); ?></option> 
  98. <option 
  99. value="recent" <?php selected( $instance['galleryid'], 'recent' ); ?> ><?php _e( 'Recent images', 'nggallery' ); ?></option> 
  100. <?php $this->print_gallery_select( $instance['galleryid'] ); ?> 
  101. </select> 
  102. </p> 
  103. <p> 
  104. <input id="<?php echo $this->get_field_id( 'autodim' ); ?>" 
  105. name="<?php echo $this->get_field_name( 'autodim' ); ?>" type="checkbox" 
  106. value="true" <?php checked( true, $instance['autodim'] ); ?>> 
  107. <label for="<?php echo $this->get_field_id( 'autodim' ); ?>"> 
  108. <?php _e( "Let the slideshow fit in the available space.", 'nggallery' ); ?> 
  109. </label> 
  110. <br><span class="description"><?php _e( "The given width and height are ignored when this is selected.", 'nggallery' ); ?></span> 
  111. </p> 
  112. <table> 
  113. <tr> 
  114. <td> 
  115. <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width:', 'nggallery' ); ?></label> 
  116. </td> 
  117. <td> 
  118. <input id="<?php echo $this->get_field_id( 'width' ); ?>" 
  119. name="<?php echo $this->get_field_name( 'width' ); ?>" type="number" min="0" 
  120. style="padding: 3px; width: 60px;" value="<?php echo $width; ?>"/> px 
  121. </td> 
  122. </tr> 
  123. <tr> 
  124. <td> 
  125. <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Height:', 'nggallery' ); ?></label> 
  126. </td> 
  127. <td> 
  128. <input id="<?php echo $this->get_field_id( 'height' ); ?>" 
  129. name="<?php echo $this->get_field_name( 'height' ); ?>" type="number" min="0" 
  130. style="padding: 3px; width: 60px;" value="<?php echo $height; ?>"/> px 
  131. </td> 
  132. </tr> 
  133. </table> 
  134. <?php 
  135.  
  136. private function print_gallery_select( $gallery_id ) { 
  137. global $nggdb; 
  138.  
  139. $galleries = $nggdb->find_all_galleries(); 
  140.  
  141. if ( $galleries ) { 
  142. foreach ( $galleries as $gallery ) { 
  143. $out = '<option value="' . $gallery->gid . '" '; 
  144. $out .= selected( $gallery_id, $gallery->gid, false ); 
  145. $out .= '>' . esc_attr( $gallery->name ) . '</option>'; 
  146. echo $out; 
  147.