Skip to:
Content

BuddyPress.org

Changeset 3232 for trunk/bp-blogs.php


Ignore:
Timestamp:
09/06/2010 04:24:57 PM (14 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r2946 r3232  
    1010    global $bp, $wpdb;
    1111
    12     if ( !defined( 'BP_BLOGS_SLUG' ) )
    13         define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );
    14 
    1512    /* For internal identification */
    1613    $bp->blogs->id = 'blogs';
    17     $bp->blogs->name = $bp->pages->blogs->name;
     14
    1815    $bp->blogs->slug = BP_BLOGS_SLUG;
    1916
    20     $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
    21     $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
     17    $bp->blogs->table_name          = $bp->table_prefix . 'bp_user_blogs';
     18    $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta';
     19
    2220    $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
    2321
     
    9795    do_action( 'bp_blogs_screen_my_blogs' );
    9896    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
     97}
     98
     99function bp_blogs_screen_recent_posts() {
     100    do_action( 'bp_blogs_screen_recent_posts' );
     101    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
     102}
     103
     104function bp_blogs_screen_recent_comments() {
     105    do_action( 'bp_blogs_screen_recent_comments' );
     106    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
    99107}
    100108
     
    237245}
    238246
     247
    239248function bp_blogs_record_existing_blogs() {
    240249    global $bp, $wpdb;
     
    308317        $user_id = (int)$post->post_author;
    309318
    310     /* This is to stop infinite loops with Donncha's sitewide tags plugin */
     319    /* This is to stop infinate loops with Donncha's sitewide tags plugin */
    311320    if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    312321        return false;
     
    316325        return false;
    317326
    318     if ( 'publish' == $post->post_status && '' == $post->post_password ) {
     327    if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
     328        if ( 'publish' == $post->post_status && '' == $post->post_password ) {
     329
     330            /* If we're on a multiblog install, record this post */
     331            if ( bp_core_is_multisite() ) {
     332                $recorded_post = new BP_Blogs_Post;
     333                $recorded_post->user_id = $user_id;
     334                $recorded_post->blog_id = $blog_id;
     335                $recorded_post->post_id = $post_id;
     336                $recorded_post->date_created = strtotime( $post->post_date );
     337
     338                $recorded_post_id = $recorded_post->save();
     339
     340                bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     341            }
     342
     343            if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
     344                /* Record this in activity streams */
     345                $post_permalink = get_permalink( $post_id );
     346
     347                $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>' );
     348                $activity_content = $post->post_content;
     349
     350                bp_blogs_record_activity( array(
     351                    'user_id' => (int)$post->post_author,
     352                    'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
     353                    'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
     354                    'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
     355                    'type' => 'new_blog_post',
     356                    'item_id' => $blog_id,
     357                    'secondary_item_id' => $post_id,
     358                    'recorded_time' => $post->post_date_gmt
     359                ));
     360            }
     361        }
     362    } else {
     363        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
     364
     365        /* Delete the recorded post if the status is not published or it is password protected */
     366        if ( 'publish' != $post->post_status || '' != $post->post_password ) {
     367            return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
     368
     369        /* If the post author has changed, delete the post and re-add it. */
     370        } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
     371            // Delete the existing recorded post
     372            bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
     373
     374            // Re-record the post with the new author.
     375            bp_blogs_record_post( $post_id );
     376        }
     377
    319378        bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    320379
    321380        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    322             /* Record this in activity streams */
     381            /* Now re-record the post in the activity streams */
    323382            $post_permalink = get_permalink( $post_id );
    324383
     
    335394                'secondary_item_id' => $post_id,
    336395                'recorded_time' => $post->post_date_gmt
    337             ));
     396            ) );
    338397        }
    339     } else
    340         bp_blogs_remove_post( $post_id, $blog_id );
     398    }
    341399
    342400    bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    343401
    344     do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
     402    do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
    345403}
    346404add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
     
    349407    global $wpdb, $bp;
    350408
    351     $comment = get_comment($comment_id);
    352 
    353     if ( !$is_approved )
    354         return false;
    355 
    356     $comment->post = get_post( $comment->comment_post_ID );
    357 
    358     /* Get the user_id from the author email. */
    359     $user = get_user_by_email( $comment->comment_author_email );
     409    // Get the users comment
     410    $recorded_comment = get_comment( $comment_id );
     411
     412    // Don't record activity if the comment hasn't been approved
     413    if ( !$is_approved || !$recorded_comment->comment_approved )
     414        return false;
     415
     416    // Don't record activity if no email address has been included
     417    if ( empty( $recorded_comment->comment_author_email ) )
     418        return false;
     419
     420    // Get the user_id from the comment author email.
     421    $user = get_user_by_email( $recorded_comment->comment_author_email );
    360422    $user_id = (int)$user->ID;
    361423
    362     if ( !$user_id )
    363         return false;
    364 
    365     /* If this is a password protected post, don't record the comment */
    366     if ( !empty( $post->post_password ) )
    367         return false;
    368 
    369     if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    370         /* Record in activity streams */
    371         $comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
    372         $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    373         $activity_content = $comment->comment_content;
    374 
    375         /* Record this in activity streams */
     424    // If there's no registered user id, don't record activity
     425    if ( empty( $user_id ) )
     426        return false;
     427
     428    // Get blog and post data
     429    $blog_id = (int)$wpdb->blogid;
     430    $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
     431
     432    // If this is a password protected post, don't record the comment
     433    if ( !empty( $recorded_comment->post->post_password ) )
     434        return false;
     435
     436    // If blog is public allow activity to be posted
     437    if ( get_blog_option( $blog_id, 'blog_public' ) ) {
     438        // Get activity related links
     439        $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
     440        $comment_link   = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
     441
     442        // Prepare to record in activity streams
     443        $activity_action        = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     444        $activity_content       = $recorded_comment->comment_content;
     445
     446        // Record in activity streams
    376447        bp_blogs_record_activity( array(
    377             'user_id' => $user_id,
    378             'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),
    379             'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    380             'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    381             'type' => 'new_blog_comment',
    382             'item_id' => $wpdb->blogid,
     448            'user_id'           => $user_id,
     449            'action'            => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
     450            'content'           => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
     451            'primary_link'      => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
     452            'type'              => 'new_blog_comment',
     453            'item_id'           => $blog_id,
    383454            'secondary_item_id' => $comment_id,
    384             'recorded_time' => $comment->comment_date_gmt
     455            'recorded_time'     => $recorded_comment->comment_date_gmt
    385456        ) );
    386     }
    387 
    388     bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     457
     458        // Update the blogs last active date
     459        bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     460    }
    389461
    390462    return $recorded_comment;
     
    451523add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    452524
    453 function bp_blogs_remove_post( $post_id, $blog_id = false ) {
     525function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
    454526    global $current_blog, $bp;
    455527
     
    459531        $blog_id = (int)$current_blog->blog_id;
    460532
     533    if ( !$existing_post )
     534        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
     535
     536    // Delete post from the bp_blogs table
     537    BP_Blogs_Post::delete( $post_id, $blog_id );
     538
    461539    // Delete activity stream item
    462540    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    468546function bp_blogs_remove_comment( $comment_id ) {
    469547    global $wpdb, $bp;
     548
     549    $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
     550    BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
    470551
    471552    // Delete activity stream item
     
    504585    /* If this is regular blog, delete all data for that blog. */
    505586    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
     587    BP_Blogs_Post::delete_posts_for_blog( $blog_id );
     588    BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
    506589
    507590    // Delete activity stream item
     
    516599}
    517600
     601/* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
     602function bp_blogs_get_posts_for_user( $user_id ) {
     603    return BP_Blogs_Post::get_posts_for_user( $user_id );
     604}
     605
     606/* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
     607function bp_blogs_get_comments_for_user( $user_id ) {
     608    return BP_Blogs_Comment::get_comments_for_user( $user_id );
     609}
     610
     611function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
     612    global $bp;
     613
     614    if ( !is_numeric( $limit ) )
     615        $limit = 5;
     616
     617    return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
     618}
     619
    518620function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    519621    return BP_Blogs_Blog::get_all( $limit, $page );
     
    522624function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
    523625    return BP_Blogs_Blog::get( 'random', $limit, $page );
     626}
     627
     628function bp_blogs_get_all_posts( $limit = null, $page = null ) {
     629    return BP_Blogs_Post::get_all( $limit, $page );
     630}
     631
     632function bp_blogs_total_post_count( $blog_id ) {
     633    return BP_Blogs_Post::total_post_count( $blog_id );
     634}
     635
     636function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
     637    return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    524638}
    525639
     
    640754
    641755function bp_blogs_remove_data( $user_id ) {
    642     if ( !bp_core_is_multisite() )
    643         return false;
    644 
    645756    /* If this is regular blog, delete all data for that blog. */
    646757    BP_Blogs_Blog::delete_blogs_for_user( $user_id );
     758    BP_Blogs_Post::delete_posts_for_user( $user_id );
     759    BP_Blogs_Comment::delete_comments_for_user( $user_id );
    647760
    648761    do_action( 'bp_blogs_remove_data', $user_id );
    649762}
    650 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
    651 add_action( 'delete_user', 'bp_blogs_remove_data' );
    652 add_action( 'make_spam_user', 'bp_blogs_remove_data' );
     763add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 );
     764add_action( 'delete_user', 'bp_blogs_remove_data', 1 );
    653765
    654766
     
    677789}
    678790
     791function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
     792    wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
     793}
     794
     795function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
     796    bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
     797
     798    /* Clear the sitewide activity cache */
     799    wp_cache_delete( 'sitewide_activity', 'bp' );
     800}
     801
     802function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
     803    wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
     804}
     805
     806function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
     807    bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
     808
     809    /* Clear the sitewide activity cache */
     810    wp_cache_delete( 'sitewide_activity', 'bp' );
     811}
     812
    679813// List actions to clear object caches on
    680814add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
     815add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
     816add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
     817
    681818add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
     819add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
     820add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    682821
    683822// List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset for help on using the changeset viewer.