sbrajesh

Brajesh Singh

Apr 30th, 2010
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.55 KB | None | 0 0
  1. <?php
  2.  
  3. /* Add these code to your cunctions.php to allow Single Search page for all buddypress components*/
  4. //  Remove Buddypress search drowpdown for selecting members etc
  5. add_filter("bp_search_form_type_select", "bpmag_remove_search_dropdown"  );
  6. function bpmag_remove_search_dropdown($select_html){
  7.     return '';
  8. }
  9.  
  10. remove_action( 'init', 'bp_core_action_search_site', 5 );//force buddypress to not process the search/redirect
  11. add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search
  12.  
  13. function bp_buddydev_search(){
  14. global $bp;
  15.     if ( $bp->current_component == BP_SEARCH_SLUG )//if thids is search page
  16.         bp_core_load_template( apply_filters( 'bp_core_template_search_template', 'search-single' ) );//load the single searh template
  17. }
  18. add_action("advance-search","bpmag_show_search_results",1);//highest priority
  19.  
  20. /* we just need to filter the query and change search_term=The search text*/
  21. function bpmag_show_search_results(){
  22.     //filter the ajaxquerystring
  23.      add_filter("bp_ajax_querystring","bpmag_global_search_qs",100,2);
  24. }
  25.  
  26. //show the search results for member*/
  27. function bpmag_show_member_search(){
  28.     ?>
  29.    <div class="memberss-search-result search-result">
  30.    <h2 class="content-title"><?php _e("Members Results","bpmag");?></h2>
  31.   <?php locate_template( array( 'members/members-loop.php' ), true ) ;  ?>
  32.   <?php global $members_template;
  33.     if($members_template->total_member_count>1):?>
  34.         <a href="<?php echo bp_get_root_domain().'/'.BP_MEMBERS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e(sprintf("View all %d matched Members",$members_template->total_member_count),"bpmag");?></a>
  35.     <?php   endif; ?>
  36. </div>
  37. <?php  
  38.  }
  39.  
  40. //Hook Member results to search page
  41. add_action("advance-search","bpmag_show_member_search",10); //the priority defines where in page this result will show up(the order of member search in other searchs)
  42. function bpmag_show_groups_search(){
  43.     ?>
  44. <div class="groups-search-result search-result">
  45.     <h2 class="content-title"><?php _e("Group Search","bpmag");?></h2>
  46.     <?php locate_template( array('groups/groups-loop.php' ), true ) ;  ?>
  47.    
  48.     <a href="<?php echo bp_get_root_domain().'/'.BP_GROUPS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Groups","bpmag");?></a>
  49. </div>
  50.     <?php
  51.  //endif;
  52.   }
  53.  
  54. //Hook Groups results to search page
  55.  if(bp_is_active( 'groups' ))
  56.     add_action("advance-search","bpmag_show_groups_search",10);
  57.  
  58. /**
  59.  *
  60.  * Show blog posts in search
  61.  */
  62. function bpmag_show_site_blog_search(){
  63.     ?>
  64.  <div class="blog-search-result search-result">
  65.  
  66.   <h2 class="content-title"><?php _e("Blog Search","bpmag");?></h2>
  67.    
  68.    <?php locate_template( array( 'search-loop.php' ), true ) ;  ?>
  69.    <a href="<?php echo bp_get_root_domain().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Posts","bpmag");?></a>
  70. </div>
  71.    <?php
  72.   }
  73.  
  74. //Hook Blog Post results to search page
  75.  add_action("advance-search","bpmag_show_site_blog_search",10);
  76.  
  77. //show forums search
  78. function bpmag_show_forums_search(){
  79.     ?>
  80.  <div class="forums-search-result search-result">
  81.    <h2 class="content-title"><?php _e("Forums Search","bpmag");?></h2>
  82.   <?php locate_template( array( 'forums/forums-loop.php' ), true ) ;  ?>
  83.   <a href="<?php echo bp_get_root_domain().'/'.BP_FORUMS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched forum posts","bpmag");?></a>
  84. </div>
  85.   <?php
  86.   }
  87.  
  88. //Hook Forums results to search page
  89. if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' ) && !(int) bp_get_option( 'bp-disable-forum-directory' ) ) && bp_forums_is_installed_correctly() )
  90.  add_action("advance-search","bpmag_show_forums_search",20);
  91.  
  92.  
  93. //show blogs search result
  94.  
  95. function bpmag_show_blogs_search(){
  96.  
  97.     ?>
  98.   <div class="blogs-search-result search-result">
  99.   <h2 class="content-title"><?php _e("Blogs Search","bpmag");?></h2>
  100.   <?php locate_template( array( 'blogs/blogs-loop.php' ), true ) ;  ?>
  101.   <a href="<?php echo bp_get_root_domain().'/'.BP_BLOGS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Blogs","bpmag");?></a>
  102.  </div>
  103.   <?php
  104. }
  105. //Hook Blogs results to search page if blogs comonent is active
  106.  if(bp_is_active( 'blogs' ))
  107.     add_action("advance-search","bpmag_show_blogs_search",10);
  108.  
  109.  
  110.  //modify the query string with the search term
  111. function bpmag_global_search_qs(){
  112.     return "search_terms=".$_REQUEST['search-terms'];
  113. }
  114. function bpmag_is_advance_search(){
  115. global $bp;
  116. if($bp->current_component == BP_SEARCH_SLUG)
  117.     return true;
  118. return false;
  119. }
  120. ?>
Add Comment
Please, Sign In to add comment