Advertisement
Guest User

r-a-y

a guest
Jun 12th, 2010
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. class BP_Blog_Post_Fav {
  2.  
  3.     var $activity_id;
  4.  
  5.     function init() {
  6.         add_action( 'the_post', array( &$this, 'get_blog_post_activity_id' ) );
  7.     }
  8.  
  9.     function get_blog_post_activity_id() {
  10.         global $current_blog, $post;
  11.        
  12.         if( isset($post->ID) ) :
  13.             $activity_id = bp_activity_get_activity_id( array(
  14.             'user_id' => $post->post_author,
  15.             'type' => 'new_blog_post',
  16.             'component' => 'blogs',
  17.             'item_id' => $current_blog->blog_id,
  18.             'secondary_item_id' => $post->ID) );
  19.  
  20.             $this->activity_id = $activity_id;
  21.  
  22.             if( !empty($this->activity_id) ) {
  23.                 add_filter( 'bp_get_activity_favorite_link', array( &$this, 'bp_get_activity_favorite_link' ) );
  24.                 add_filter( 'bp_get_activity_unfavorite_link', array( &$this, 'bp_get_activity_unfavorite_link' ) );   
  25.                 add_filter( 'bp_get_activity_is_favorite', array( &$this, 'bp_get_activity_is_favorite' ) );
  26.             }      
  27.  
  28.         endif;
  29.  
  30.     }
  31.  
  32.     function bp_get_activity_favorite_link() {
  33.         global $current_blog;
  34.  
  35.         if( $current_blog->blog_id != BP_ROOT_BLOG )
  36.             switch_to_blog( BP_ROOT_BLOG );
  37.  
  38.         $nonce = wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $this->activity_id . '/' ), 'mark_favorite' );
  39.  
  40.         if( $current_blog->blog_id != BP_ROOT_BLOG )
  41.             restore_current_blog();
  42.  
  43.         return $nonce;
  44.     }
  45.  
  46.     function bp_get_activity_unfavorite_link() {
  47.         global $current_blog;
  48.  
  49.         if( $current_blog->blog_id != BP_ROOT_BLOG )
  50.             switch_to_blog( BP_ROOT_BLOG );
  51.  
  52.         $nonce = wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $this->activity_id . '/' ), 'unmark_favorite' );
  53.  
  54.         if( $current_blog->blog_id != BP_ROOT_BLOG )
  55.             restore_current_blog();
  56.  
  57.         return $nonce;
  58.     }
  59.  
  60.     function bp_get_activity_is_favorite() {
  61.         global $bp;
  62.  
  63.         return in_array( $this->activity_id, (array)bp_activity_get_user_favorites($bp->loggedin_user->id) );
  64.     }      
  65. }
  66. $my_bp_favorite = new BP_Blog_Post_Fav();
  67. $my_bp_favorite->init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement