Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 15th, 2011  |  syntax: None  |  size: 5.17 KB  |  views: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. function bp_activity_hashtags_filter( $content ) {
  3.         global $bp;
  4.        
  5.         //what are we doing here? - same at atme mentions
  6.         //$pattern = '/[#]([_0-9a-zA-Z-]+)/';
  7.         $pattern = '/(?(?<!color: )(?<!color: )[#]([_0-9a-zA-Z-]+)|(^|\s|\b)[#]([_0-9a-zA-Z-]+))/';
  8.  
  9.         //unicode support???
  10.         //$pattern = '/(#|\\uFF03)([a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]+)/i';
  11.         //$pattern = '/(^|[^0-9A-Z&/]+)(#|\uFF03)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]*)/i';
  12.         //the twitter pattern
  13.         //"(^|[^0-9A-Z&/]+)(#|\uFF03)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]*)"
  14.        
  15.         preg_match_all( $pattern, $content, $hashtags );
  16.         if ( $hashtags ) {
  17.                 /* Make sure there's only one instance of each tag */
  18.                 if ( !$hashtags = array_unique( $hashtags[1] ) )
  19.                         return $content;
  20.  
  21.                 //but we need to watch for edits and if something was already wrapped in html link - thus check for space or word boundary prior
  22.                 foreach( (array)$hashtags as $hashtag ) {
  23.                         $pattern = "/(^|\s|\b)#". $hashtag ."($|\b)/";
  24.                         $content = preg_replace( $pattern, ' <a href="' . $bp->root_domain . "/" . bp_get_activity_root_slug() . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . htmlspecialchars( $hashtag ) . '" rel="nofollow" class="hashtag">#'. htmlspecialchars( $hashtag ) .'</a>', $content );
  25.                 }
  26.         }
  27.        
  28.         return $content;
  29. }
  30.  
  31. function bp_activity_hashtags_querystring( $query_string, $object ) {
  32.         global $bp;
  33.  
  34.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  35.                 return $query_string;
  36.  
  37.         if ( empty( $bp->action_variables[0] ) )
  38.                 return $query_string;
  39.  
  40.         if ( 'feed' == $bp->action_variables[1] )
  41.                 return $query_string;
  42.  
  43.         if ( strlen( $query_string ) < 1 )
  44.                 return 'display_comments=true&search_terms=#'. $bp->action_variables[0] . '<';
  45.  
  46.         /* Now pass the querystring to override default values. */
  47.         $query_string .= '&display_comments=true&search_terms=#'. $bp->action_variables[0] . '<';
  48.  
  49.         return $query_string;
  50. }
  51. add_filter( 'bp_ajax_querystring', 'bp_activity_hashtags_querystring', 11, 2 );
  52.  
  53. //thanks r-a-y for the snippet
  54. function bp_activity_hashtags_header() {
  55.         global $bp, $bp_unfiltered_uri;
  56.        
  57.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  58.                 return;
  59.        
  60.         printf( __( '<h3>Activity results for #%s</h3>', 'bp-activity-hashtags' ), $bp->action_variables[0] );
  61.        
  62. }
  63. add_action( 'bp_before_activity_loop', 'bp_activity_hashtags_header' );
  64.  
  65. function bp_activity_hashtags_page_title( $title, $rawtitle ) {
  66.         global $bp;
  67.  
  68.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  69.                 return $title;
  70.  
  71.         if ( empty( $bp->action_variables[0] ) )
  72.                 return $title;
  73.  
  74.         if ( !empty( $rawtitle ) )
  75.                 return $title;
  76.  
  77.         return apply_filters( 'bp_activity_page_title', $title . esc_attr( $bp->action_variables[0] ), esc_attr( $bp->action_variables[0] ) );
  78.  
  79. }
  80. add_filter( 'bp_page_title', 'bp_activity_hashtags_page_title', 1, 2 );
  81.  
  82. function bp_activity_hashtags_insert_rel_head() {
  83.         global $bp;
  84.  
  85.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  86.                 return false;
  87.  
  88.         if ( empty( $bp->action_variables[0] ) )
  89.                 return false;
  90.                
  91.         $link = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
  92.  
  93.         echo '<link rel="alternate" type="application/rss+xml" title="'. get_blog_option( BP_ROOT_BLOG, 'blogname' ) .' | '. esc_attr( $bp->action_variables[0] ) .' | Hashtag" href="'. $link .'" />';
  94. }
  95. add_action('bp_head','bp_activity_hashtags_insert_rel_head');
  96.  
  97.  
  98. function bp_activity_hashtags_activity_feed_link( $feedurl ) {
  99.         global $bp;
  100.  
  101.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  102.                 return $feedurl;
  103.  
  104.         if ( empty( $bp->action_variables[0] ) )
  105.                 return $feedurl;
  106.  
  107.         return $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
  108.  
  109. }
  110. add_filter( 'bp_get_sitewide_activity_feed_link', 'bp_activity_hashtags_activity_feed_link', 1, 1 );
  111.  
  112. function bp_activity_hashtags_action_router() {
  113.         global $bp, $wp_query;
  114.  
  115.         if ( $bp->current_component != $bp->activity->slug || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
  116.                 return false;
  117.  
  118.         if ( empty( $bp->action_variables[0] ) )
  119.                 return false;
  120.                
  121.         if ( 'feed' == $bp->action_variables[1] ) {
  122.        
  123.                 $link = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] );
  124.                 $link_self = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
  125.  
  126.                 $wp_query->is_404 = false;
  127.                 status_header( 200 );
  128.  
  129.                 include_once( dirname( __FILE__ ) . '/feeds/bp-activity-hashtags-feed.php' );
  130.                 die;
  131.        
  132.         } else {
  133.        
  134.                 bp_core_load_template( 'activity/index' );
  135.        
  136.         }
  137.        
  138. }
  139. add_action( 'wp', 'bp_activity_hashtags_action_router', 3 );
  140.  
  141.  
  142. function bp_activity_hashtags_current_activity() {
  143.         global $activities_template;
  144.         return $activities_template->current_activity;
  145. }
  146. ?>
  147.  
clone this paste RAW Paste Data