BBoss_Global_Search_Posts_Comments

BuddyPress Global Search - search posts **************************************.

Defined (1)

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

/includes/search-types/class.BBoss_Global_Search_Posts_Comments.php  
  1. class BBoss_Global_Search_Posts_Comments extends BBoss_Global_Search_Type { 
  2. private $type = 'posts_comments'; 
  3.  
  4. /** 
  5. * Insures that only one instance of Class exists in memory at any 
  6. * one time. Also prevents needing to define globals all over the place. 
  7. * @since 1.0.0 
  8. * @see buddyboss_global_search() 
  9. * @return object BBoss_Global_Search_Posts 
  10. */ 
  11. public static function instance() { 
  12. // Store the instance locally to avoid private static replication 
  13. static $instance = null; 
  14.  
  15. // Only run these methods if they haven't been run previously 
  16. if (null === $instance) { 
  17. $instance = new BBoss_Global_Search_Posts_Comments(); 
  18.  
  19. //add_action( 'bboss_global_search_settings_item_posts', array( $instance, 'print_search_options' ) ); 
  20.  
  21. // Always return the instance 
  22. return $instance; 
  23.  
  24. /** 
  25. * A dummy constructor to prevent this class from being loaded more than once. 
  26. * @since 1.0.0 
  27. */ 
  28. private function __construct() { /** Do nothing here */ 
  29.  
  30. public function sql( $search_term, $only_totalrow_count=false ) { 
  31.  
  32. global $wpdb; 
  33. $query_placeholder = array();  
  34.  
  35. $sql = " SELECT "; 
  36.  
  37. if( $only_totalrow_count ) { 
  38. $sql .= " COUNT( DISTINCT comment_ID ) "; 
  39. } else { 
  40. $sql .= " DISTINCT comment_ID AS id, 'posts_comments' as type, comment_content LIKE '%%%s%%' AS relevance, comment_date as entry_date "; 
  41. $query_placeholder[] = $search_term; 
  42.  
  43.  
  44. $sql .= " FROM {$wpdb->comments} WHERE 1=1 AND comment_content LIKE '%%%s%%' AND comment_approved = 1 "; 
  45.  
  46. $query_placeholder[] = $search_term; 
  47.  
  48. $sql = $wpdb->prepare( $sql, $query_placeholder ); 
  49.  
  50. return apply_filters(  
  51. 'BBoss_Global_Search_Posts_Comments_sql',  
  52. $sql,  
  53. array(  
  54. 'search_term' => $search_term,  
  55. 'only_totalrow_count' => $only_totalrow_count,  
  56. )  
  57. ); 
  58.  
  59. protected function generate_html( $template_type='' ) { 
  60. $comment_ids = array(); 
  61. foreach( $this->search_results['items'] as $item_id=>$item_html ) { 
  62. $comment_ids[] = $item_id; 
  63.  
  64. //now we have all the posts 
  65. //lets do a wp_query and generate html for all posts 
  66. $comment_query = new WP_Comment_Query( array( 'comment__in'=> $comment_ids ) ); 
  67. $_comments = $comment_query->comments; 
  68.  
  69. foreach ( $_comments as $_comment ) { 
  70. global $current_comment; 
  71. $current_comment = $_comment; 
  72.  
  73. $result = array( 
  74. 'id' => $_comment->comment_ID,  
  75. 'type' => $this->type,  
  76. 'title' => $this->search_term,  
  77. 'html' => buddyboss_global_search_buffer_template_part( 'loop/comment', $template_type, false ),  
  78. ); 
  79.  
  80. $this->search_results['items'][$_comment->comment_ID] = $result;