NGG_Image_List_Table

Class NGG_List_Table.

Defined (1)

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

/admin/manage/class-ngg-image-list-table.php  
  1. class NGG_Image_List_Table extends WP_List_Table { 
  2.  
  3. private $base; 
  4.  
  5. public function __construct( $base, $screen = null ) { 
  6.  
  7. parent::__construct( array( 'screen' => $screen, 'plural' => 'ngg-manager' ) ); 
  8.  
  9. $this->base = $base; 
  10.  
  11. add_filter( 'manage_' . $this->screen->id . '_columns', array( $this, 'get_columns' ), 0 ); 
  12.  
  13. /** 
  14. * Prepare the items for the table to process 
  15. * @param bool|string $search The search string, or false if we don't search. 
  16. */ 
  17. public function prepare_items($search = false) { 
  18.  
  19. /** 
  20. * @global $nggdb nggdb 
  21. */ 
  22. global $nggdb; 
  23.  
  24. $columns = $this->get_columns(); 
  25. $hidden = $this->get_hidden_columns(); 
  26. $sortable = $this->get_sortable_columns(); 
  27.  
  28. $this->_column_headers = array( $columns, $hidden, $sortable ); 
  29.  
  30. if( $search ) { 
  31. // look now for the images 
  32. $search_for_images = (array) $nggdb->search_for_images( $search ); 
  33. $search_for_tags = (array) nggTags::find_images_for_tags( $search , 'ASC' ); 
  34.  
  35. // finally merge the two results together 
  36. $this->items = array_merge( $search_for_images , $search_for_tags ); 
  37.  
  38. $this->set_pagination_args( array( 
  39. 'total_items' => count( $this->items ) 
  40. ) ); 
  41.  
  42. } else { 
  43.  
  44. /** 
  45. * Do the pagination. 
  46. */ 
  47. $currentPage = $this->get_pagenum(); 
  48. $perPage = $this->get_items_per_page('ngg_images_per_page', 50); 
  49.  
  50. $options = get_option( 'ngg_options' ); 
  51. $gallery_id = (int) $_GET['gid']; 
  52.  
  53. $start = ( $currentPage - 1 ) * $perPage; 
  54.  
  55. $this->items = $nggdb->get_gallery( $gallery_id, $options['galSort'], $options['galSortDir'], false,  
  56. $perPage,  
  57. $start ); 
  58.  
  59. $totalItems = (int) nggdb::count_images_in_gallery( $gallery_id ); 
  60.  
  61. $this->set_pagination_args( array( 
  62. 'total_items' => $totalItems,  
  63. 'per_page' => $perPage 
  64. ) ); 
  65.  
  66. /** 
  67. * Override to add a button if on top. 
  68. * @param string $which 
  69. */ 
  70. protected function bulk_actions($which = '') { 
  71. parent::bulk_actions($which); 
  72.  
  73. if($which === 'top') { 
  74. ?> 
  75. <button type="submit" class="button-primary action manager-save" name="update_images"> 
  76. <?php _e( "Save Changes", 'nggallery' ); ?> 
  77. </button> 
  78. <?php 
  79.  
  80. /** 
  81. * Get the hidden columns from the screen options. 
  82. */ 
  83. public function get_hidden_columns() { 
  84. return (array) get_user_option( 'manage' . $this->screen->id . 'columnshidden' );; 
  85.  
  86. /** 
  87. * The checkbox column. 
  88. * @param nggImage $item 
  89. * @return string 
  90. */ 
  91. protected function column_cb( $item ) { 
  92. return '<input name="doaction[]" type="checkbox" value="' . $item->pid . '" />'; 
  93.  
  94. /** 
  95. * @param nggImage $item 
  96. * @return string 
  97. */ 
  98. protected function column_thumbnail( $item ) { 
  99. $out = '<a href="' . esc_url( add_query_arg( 'i', mt_rand(),  
  100. $item->imageURL ) ) . '" class="shutter" title="' . esc_attr( $item->filename ) . '">'; 
  101. $out .= '<img class="thumb" src="' . esc_url( add_query_arg( 'i', mt_rand(),  
  102. $item->thumbURL ) ) . '" id="thumb' . $item->pid . '" /></a>'; 
  103.  
  104. return $out; 
  105.  
  106. /** 
  107. * @param nggImage $item 
  108. * @return string 
  109. */ 
  110. protected function column_filename( $item ) { 
  111. $date = mysql2date( get_option( 'date_format' ), $item->imagedate ); 
  112. ob_start(); 
  113. ?> 
  114. <a href="<?php echo esc_url( $item->imageURL ) ?>" class="thickbox" title="<?php esc_attr_e( $item->filename ) ?>"> 
  115. <strong> 
  116. <?php esc_html_e( $item->filename ) ?> 
  117. </strong> 
  118. </a> 
  119. <br> 
  120. <span class="date"><?php echo $date ?></span> 
  121. <input type="text" class="datepicker" value="<?php echo $date ?>"/> 
  122. <span class="change"> <?php _e( 'Change Date', 'nggallery' ); ?></span> 
  123. <input type="hidden" class="rawdate" name="date[<?php echo $item->pid ?>]" value="<?php echo $item->imagedate ?>"/> 
  124. <?php if ( ! empty( $item->meta_data ) ) { ?> 
  125. <br><?php echo $item->meta_data['width'] ?> x <?php echo $item->meta_data['height'] ?><?php _e( 'pixel',  
  126. 'nggallery' ) ?> 
  127. <?php } ?> 
  128. <p> 
  129. <?php 
  130. $actions = $this->get_row_actions( $item ); 
  131. $action_count = count( $actions ); 
  132. $i = 0; 
  133. echo '<div class="row-actions">'; 
  134. foreach ( $actions as $action => $link ) { 
  135. ++ $i; 
  136. ( $i == $action_count ) ? $sep = '' : $sep = ' | '; 
  137. echo "<span class='$action'>$link$sep</span>"; 
  138. echo '</div>'; 
  139. ?> 
  140. </p> 
  141. <?php 
  142.  
  143. return ob_get_clean(); 
  144.  
  145. /** 
  146. * @param $item nggImage 
  147. * @return string 
  148. */ 
  149. protected function column_alt_title_desc( $item ) { 
  150. $img_alt_text = nggGallery::suppress_injection( $item->alttext ); 
  151. $img_description = nggGallery::suppress_injection( $item->description ); 
  152.  
  153. $out = '<input placeholder="' . __( "Alt & title text",  
  154. 'nggallery' ) . '" name="alttext[' . $item->pid . ']" type="text" style="width:95%; margin-bottom: 2px;" value="' . $img_alt_text . '"/>'; 
  155. $out .= '<br>'; 
  156. $out .= '<textarea placeholder="' . __( "Description",  
  157. 'nggallery' ) . '" name="description[' . $item->pid . ']" style="width:95%; margin: 1px;" rows="2">' . $img_description . '</textarea>'; 
  158.  
  159. return $out; 
  160.  
  161. /** 
  162. * Define what data to show on each column of the table 
  163. * @param nggImage $item Data 
  164. * @param String $column_name - Current column name 
  165. * @return Mixed 
  166. */ 
  167. protected function column_default( $item, $column_name ) { 
  168. switch ( $column_name ) { 
  169. case 'id': 
  170. return '<input type="hidden" name="pid[]" value="' . $item->pid . '">' . $item->pid; 
  171. case 'tags': 
  172. $item->tags = wp_get_object_terms( $item->pid, 'ngg_tag', 'fields=names' ); 
  173. if ( is_array( $item->tags ) ) { 
  174. $item->tags = implode( ', ', $item->tags ); 
  175.  
  176. return '<textarea placeholder="' . __( "Separated by commas",  
  177. 'nggallery' ) . '" name="tags[' . $item->pid . ']" style="width:95%;" rows="2">' . $item->tags . '</textarea>'; 
  178. case 'exclude': 
  179. return '<input name="exclude[' . $item->pid . ']" type="checkbox" value="1" ' . checked( $item->exclude, true, false ) . '/>'; 
  180. default: 
  181. ob_start(); 
  182. //The old action needs a pid. 
  183. do_action( 'ngg_manage_image_custom_column', $column_name, $item->pid ); 
  184.  
  185. //We pass the whole object to new action. 
  186. do_action( 'ncg_manage_image_custom_column', $column_name, $item ); 
  187.  
  188. return ob_get_clean(); 
  189.  
  190. /** 
  191. * With this we can register the columns in the screen options API. 
  192. */ 
  193. public static function get_columns_static() { 
  194. $columns = array( 
  195. 'cb' => '<input type="checkbox" />',  
  196. 'id' => __( 'ID', 'nggallery' ),  
  197. 'thumbnail' => __( 'Thumbnail', 'nggallery' ),  
  198. 'filename' => __( 'Filename', 'nggallery' ),  
  199. 'alt_title_desc' => __( 'Alt & Title Text', 'nggallery' ) . '/' . __( 'Description', 'nggallery' ),  
  200. 'tags' => __( 'Tags', 'nggallery' ),  
  201. 'exclude' => __( 'Exclude', 'nggallery' ) 
  202. ); 
  203.  
  204. /** 
  205. * Apply a filter to the columns. 
  206. */ 
  207. $columns = apply_filters( 'ngg_manage_images_columns', $columns ); 
  208.  
  209. return $columns; 
  210.  
  211. /** 
  212. * Get the columns. 
  213. */ 
  214. public function get_columns() { 
  215.  
  216. return self::get_columns_static(); 
  217.  
  218. /** 
  219. * @param $item nggImage 
  220. * @return array|mixed|void 
  221. */ 
  222. private function get_row_actions( $item ) { 
  223.  
  224. if(isset($_GET['paged'])) { 
  225. $paged = '&paged=' . $_GET['paged']; 
  226. } else { 
  227. $paged = ''; 
  228.  
  229. $url = $this->base . '&mode=image&gid=' . $_GET['gid'] . $paged; 
  230.  
  231. $actions = array( 
  232. 'view' => '<a class="shutter" href="' . esc_url( $item->imageURL ) . '" title="' . esc_attr( sprintf( __( 'View "%s"' ),  
  233. sanitize_title( $item->filename ) ) ) . '">' . __( 'View', 'nggallery' ) . '</a>',  
  234. 'meta' => '<a class="ngg-dialog" data-action="show_meta" data-id="' . $item->pid . '" href="#" title="' . __( 'Show Meta data',  
  235. 'nggallery' ) . '">' . __( 'Meta', 'nggallery' ) . '</a>',  
  236. 'custom_thumb' => '<a class="ngg-dialog" data-action="edit_thumb" data-id="' . $item->pid . '" href="#" title="' . __( 'Customize thumbnail',  
  237. 'nggallery' ) . '">' . __( 'Edit thumb', 'nggallery' ) . '</a>',  
  238. 'rotate' => '<a class="ngg-dialog" data-action="rotate" data-id="' . $item->pid . '" href="#" title="' . __( 'Rotate',  
  239. 'nggallery' ) . '">' . __( 'Rotate', 'nggallery' ) . '</a>',  
  240. ); 
  241. if ( file_exists( $item->imagePath . '_backup' ) ) { 
  242. $actions['recover'] = '<a class="confirm_recover" href="' . wp_nonce_url( $url . "&action=recover&pid=" . $item->pid, 'ngg_row_action' ) . 
  243. '" data-file="' . esc_attr($item->filename) . '">' . 
  244. __( 'Recover', 'nggallery' ) . '</a>'; 
  245. $actions['delete'] = '<a class="confirm_delete" href="' . wp_nonce_url( $url . "&action=delete&pid=" . $item->pid, 'ngg_row_action' ) . 
  246. '" class="delete column-delete" data-file="' . esc_attr($item->filename) . '">' . 
  247. __( 'Delete' ) . '</a>'; 
  248.  
  249. $actions = apply_filters( 'ngg_manage_images_actions', $actions ); 
  250.  
  251. return $actions; 
  252.  
  253. /** 
  254. * Get the sortable columns. 
  255. */ 
  256. protected function get_sortable_columns() { 
  257. return array(); 
  258.  
  259. protected function get_bulk_actions() { 
  260. return array( 
  261. 'set_watermark' => __( 'Set watermark', 'nggallery' ),  
  262. 'new_thumbnail' => __( 'Create new thumbnails', 'nggallery' ),  
  263. 'resize_images' => __( 'Resize images', 'nggallery' ),  
  264. 'import_meta' => __( 'Import metadata', 'nggallery' ),  
  265. 'recover_images' => __( 'Recover from backup', 'nggallery' ),  
  266. 'delete_images' => __( 'Delete images', 'nggallery' ),  
  267. 'rotate_cw' => __( 'Rotate images clockwise', 'nggallery' ),  
  268. 'rotate_ccw' => __( 'Rotate images counter-clockwise', 'nggallery' ),  
  269. 'copy_to' => __( 'Copy to...', 'nggallery' ),  
  270. 'move_to' => __( 'Move to...', 'nggallery' ),  
  271. 'add_tags' => __( 'Add tags', 'nggallery' ),  
  272. 'delete_tags' => __( 'Delete tags', 'nggallery' ),  
  273. 'overwrite_tags' => __( 'Overwrite tags', 'nggallery' ),  
  274. );