NGG_Search_Manager

Class NGG_Search_Manager.

Defined (1)

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

/admin/manage/class-ngg-search-manager.php  
  1. class NGG_Search_Manager extends NGG_Abstract_Image_Manager { 
  2.  
  3. private $search; 
  4.  
  5. /** 
  6. * Select the search parameter and add the gallery ID column. 
  7. */ 
  8. public function __construct() { 
  9. $this->search = $_GET['s']; 
  10.  
  11. add_filter( 'ngg_manage_images_columns', array( $this, 'add_column' ) ); 
  12. add_action( 'ncg_manage_image_custom_column', array( $this, 'add_column_content' ), 10, 2 ); 
  13.  
  14. public function display() { 
  15.  
  16. parent::display(); 
  17.  
  18. set_query_var( 's', $this->search ); 
  19. $request = get_search_query(); 
  20.  
  21. /** 
  22. * Display the actual table. 
  23. */ 
  24. $table = new NGG_Image_List_Table( self::BASE ); 
  25. $table->prepare_items( $request ); 
  26. ?> 
  27. <div class="wrap"> 
  28. <h2><?php printf( __( 'Image results for %s', 'nggallery' ), $this->search ) ?></h2> 
  29. <form id="update_images" class="nggform" method="POST" action="<?php echo self::BASE . '&mode=search&s=' . $this->search; ?>" accept-charset="utf-8"> 
  30. <?php wp_nonce_field( 'ngg-update-images', '_ngg_nonce_images' ); ?> 
  31. <input type="hidden" id="page_type" name="page_type" value="image"/> 
  32. <?php $table->display(); ?> 
  33. </form> 
  34. </div> 
  35. <?php 
  36. $this->print_dialogs(); 
  37. $this->print_scripts(); 
  38.  
  39.  
  40. /** 
  41. * Add the gallery ID column. 
  42. * @access private 
  43. * @param $columns 
  44. * @return array|bool 
  45. */ 
  46. public function add_column( $columns ) { 
  47.  
  48. $key = 'gid'; 
  49. $value = '<span class="dashicons dashicons-format-gallery" title="' . __( 'Gallery ID', 'nggallery' ) . '"></span>'; 
  50.  
  51. return $this->array_insert_after( 'id', $columns, $key, $value ); 
  52.  
  53. /** 
  54. * Add the gallery id. 
  55. * @access private 
  56. * @param string $name 
  57. * @param nggImage $item 
  58. */ 
  59. public function add_column_content( $name, $item ) { 
  60. if ( $name === "gid" ) { 
  61. echo $item->galleryid; 
  62.  
  63. /** 
  64. * Inserts a new key/value after the key in the array. 
  65. * @param $key The key to insert after. 
  66. * @param $array array An array to insert in to. 
  67. * @param $new_key The key to insert. 
  68. * @param $new_value An value to insert. 
  69. * @return array|bool The new array if the key exists, FALSE otherwise. 
  70. * @see http://eosrei.net/articles/2011/11/php-arrayinsertafter-arrayinsertbefore 
  71. */ 
  72. private function array_insert_after( $key, array $array, $new_key, $new_value ) { 
  73. if ( array_key_exists( $key, $array ) ) { 
  74. $new = array(); 
  75. foreach ( $array as $k => $value ) { 
  76. $new[ $k ] = $value; 
  77. if ( $k === $key ) { 
  78. $new[ $new_key ] = $new_value; 
  79.  
  80. return $new; 
  81.  
  82. return false;