/bp-forums/bbpress/search.php

  1. <?php 
  2. require_once( './bb-load.php' ); 
  3.  
  4. if ( !$q = trim( @$_GET['search'] ) ) 
  5. $q = trim( @$_GET['q'] ); 
  6.  
  7. $bb_query_form = new BB_Query_Form; 
  8.  
  9. if ( $q = stripslashes( $q ) ) { 
  10. $per_page = ceil( (int) bb_get_option( 'page_topics' ) / 2 ); 
  11.  
  12. /** Recent */ 
  13. add_filter( 'bb_recent_search_fields', create_function( '$f', 'return $f . ", MAX(post_time) AS post_time";' ) ); 
  14. add_filter( 'bb_recent_search_group_by', create_function( '', 'return "t.topic_id";' ) ); 
  15. $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'count' => true, 'per_page' => $per_page, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' ); 
  16. $recent = $bb_query_form->results; 
  17. $recent_count = $recent ? $bb_query_form->found_rows : 0; 
  18.  
  19. /** Relevant */ 
  20. $bb_query_form->BB_Query_Form( 'topic', array( 'search' => $q ), array( 'per_page' => $per_page, 'count' => true, 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' ); 
  21. $relevant = $bb_query_form->results; 
  22. $relevant_count = $relevant ? $bb_query_form->found_rows : 0; 
  23.  
  24. $search_count = max( $recent_count, $relevant_count ); 
  25.  
  26. $q = $bb_query_form->get( 'search' ); 
  27.  
  28. do_action( 'do_search', $q ); 
  29.  
  30. // Cache topics 
  31. // NOT bbdb::prepared 
  32. if ( $recent ) : 
  33. $topic_ids = array(); 
  34. foreach ($recent as $bb_post) { 
  35. $topic_ids[] = (int) $bb_post->topic_id; 
  36. $topic_ids = join($topic_ids); 
  37. if ( $topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE topic_id IN ($topic_ids)") ) 
  38. $topics = bb_append_meta( $topics, 'topic' ); 
  39. endif; 
  40.  
  41. bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'per_page', 'search_count' ), $q ); 
.