BBoss_Global_Search_Activity_Comment

BuddyPress Global Search - search activity comment **************************************.

Defined (1)

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

/includes/search-types/class.BBoss_Global_Search_Activity_Comments.php  
  1. class BBoss_Global_Search_Activity_Comment extends BBoss_Global_Search_Type { 
  2. private $type = 'activity_comment'; 
  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. * @return object BBoss_Global_Search_Activities 
  9. */ 
  10. public static function instance() { 
  11. // Store the instance locally to avoid private static replication 
  12. static $instance = null; 
  13.  
  14. // Only run these methods if they haven't been run previously 
  15. if (null === $instance) { 
  16. $instance = new BBoss_Global_Search_Activity_Comment(); 
  17.  
  18. // Always return the instance 
  19. return $instance; 
  20.  
  21. /** 
  22. * A dummy constructor to prevent this class from being loaded more than once. 
  23. * @since 1.0.0 
  24. */ 
  25. private function __construct() { /** Do nothing here */ 
  26.  
  27. function sql( $search_term, $only_totalrow_count=false ) { 
  28.  
  29. /** 
  30. * SELECT DISTINCT a.id  
  31. * FROM wp_bp_activity a  
  32. * WHERE  
  33. * a.is_spam = 0  
  34. * AND a.content LIKE '%nothing%'  
  35. * AND a.hide_sitewide = 0  
  36. * AND a.type NOT IN ('activity_comment', 'last_activity')  
  37. *  
  38. * ORDER BY a.date_recorded DESC LIMIT 0, 21 
  39. */ 
  40. global $wpdb, $bp; 
  41.  
  42. $query_placeholder = array(); 
  43.  
  44. $sql = " SELECT "; 
  45.  
  46. if( $only_totalrow_count ) { 
  47. $sql .= " COUNT( DISTINCT id ) "; 
  48. } else { 
  49. $sql .= " DISTINCT a.id , 'activity_comment' as type, a.content LIKE '%%%s%%' AS relevance, a.date_recorded as entry_date "; 
  50. $query_placeholder[] = $search_term; 
  51.  
  52. //searching only activity updates, others don't make sense 
  53. $sql .= " FROM  
  54. {$bp->activity->table_name} a  
  55. WHERE  
  56. 1=1  
  57. AND is_spam = 0  
  58. AND a.content LIKE '%%%s%%'  
  59. AND a.hide_sitewide = 0  
  60. AND a.type = 'activity_comment' 
  61. "; 
  62. $query_placeholder[] = $search_term; 
  63. $sql = $wpdb->prepare( $sql, $query_placeholder ); 
  64.  
  65. return apply_filters(  
  66. 'BBoss_Global_Search_Activity_Comment_sql',  
  67. $sql,  
  68. array(  
  69. 'search_term' => $search_term,  
  70. 'only_totalrow_count' => $only_totalrow_count,  
  71. )  
  72. ); 
  73.  
  74. protected function generate_html( $template_type='' ) { 
  75. $post_ids_arr = array(); 
  76. foreach( $this->search_results['items'] as $item_id=>$item_html ) { 
  77. $post_ids_arr[] = $item_id; 
  78.  
  79. $post_ids = implode( ', ', $post_ids_arr ); 
  80.  
  81. if( bp_has_activities( array( 'display_comments' => 'stream', 'include'=>$post_ids, 'per_page'=>count($post_ids_arr) ) ) ) { 
  82.  
  83. while ( bp_activities() ) { 
  84. bp_the_activity(); 
  85.  
  86. $result = array( 
  87. 'id' => bp_get_activity_id(),  
  88. 'type' => $this->type,  
  89. 'title' => $this->search_term,  
  90. 'html' => buddyboss_global_search_buffer_template_part( 'loop/activity-comment', $template_type, false ),  
  91. ); 
  92.  
  93. $this->search_results['items'][bp_get_activity_id()] = $result; 
  94.