Guest User

Untitled

a guest
Jan 11th, 2011
3,251
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if ( !class_exists( 'E2E_News_Feed' ) ) :
  4.    
  5. class E2E_News_Feed {
  6.     function __construct() {
  7.         add_action( 'init', array( $this, 'register_post_types' ) );
  8.         add_action( 'save_post', array( $this, 'record_activity' ), 10, 2 );
  9.     }
  10.    
  11.     // Be sure to set up FeedWordPress so that it imports to E2E Feed Items
  12.     function register_post_types() {
  13.          $feed_labels = array(
  14.             'name' => _x('E2E Feed Item', 'post type general name'),
  15.             'singular_name' => _x('E2E Feed Item', 'post type singular name'),
  16.             'add_new' => _x('Add New', 'book'),
  17.             'add_new_item' => __('Add New E2E Feed Item'),
  18.             'edit_item' => __('Edit E2E Feed Item'),
  19.             'new_item' => __('New E2E Feed Item'),
  20.             'view_item' => __('View E2E Feed Item'),
  21.             'search_items' => __('Search E2E Feed Items'),
  22.             'not_found' =>  __('No E2E Feed Items found'),
  23.             'not_found_in_trash' => __('No E2E Feed Items found in Trash'),
  24.             'parent_item_colon' => ''
  25.           );
  26.    
  27.         register_post_type( 'e2e_feed_item', array(
  28.             'label' => 'E2E Feed Item',
  29.             'labels' => $feed_labels,
  30.             'public' => true,
  31.             '_builtin' => false,
  32.             'show_ui' => true,
  33.             'hierarchical' => false,
  34.             'taxonomies' => array( 'post_tag', 'category' ),
  35.             'supports' => array('title', 'editor', 'revisions', 'excerpt'),
  36.             'query_var' => true,
  37.             //'rewrite' => false
  38.             'rewrite' => array( "slug" => "feed-item", 'with_front' => false ), // Permalinks format
  39.         ));
  40.     }
  41.    
  42.     function record_activity( $post_id, $post, $user_id = false ) {
  43.         global $bp, $wpdb;
  44.    
  45.         $post_id = (int)$post_id;
  46.         $blog_id = (int)$wpdb->blogid;
  47.    
  48.         if ( !$user_id )
  49.             $user_id = (int)$post->post_author;
  50.    
  51.         /* This is to stop infinite loops with Donncha's sitewide tags plugin */
  52.         if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
  53.             return false;
  54.    
  55.         /* Don't record this if it's not a post */
  56.         if ( $post->post_type != 'e2e_feed_item' )
  57.             return false;
  58.    
  59.         if ( 'publish' == $post->post_status && '' == $post->post_password ) {
  60.             if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
  61.                 /* Record this in activity streams */
  62.                 $post_permalink = get_permalink( $post_id );
  63.    
  64.                 $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  65.                 $activity_content = $post->post_content;
  66.    
  67.                 bp_blogs_record_activity( array(
  68.                     'user_id' => (int)$post->post_author,
  69.                     'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
  70.                     'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
  71.                     'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
  72.                     'type' => 'new_blog_post',
  73.                     'item_id' => $blog_id,
  74.                     'secondary_item_id' => $post_id,
  75.                     'recorded_time' => $post->post_date_gmt
  76.                 ));
  77.             }
  78.         } else
  79.             bp_blogs_remove_post( $post_id, $blog_id );
  80.    
  81.         bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
  82.    
  83.         do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  84.     }
  85.  
  86. }
  87.  
  88. endif;
  89.  
  90.  
  91.  
  92. ?>
RAW Paste Data