Skip to:
Content

BuddyPress.org

Changeset 2842 for trunk/bp-blogs.php


Ignore:
Timestamp:
03/12/2010 01:03:42 PM (15 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r2770 r2842  
    2626                KEY user_id (user_id),
    2727                KEY blog_id (blog_id)
    28              ) {$charset_collate};";
    29 
    30     $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_posts} (
    31                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    32                 user_id bigint(20) NOT NULL,
    33                 blog_id bigint(20) NOT NULL,
    34                 post_id bigint(20) NOT NULL,
    35                 date_created datetime NOT NULL,
    36                 KEY user_id (user_id),
    37                 KEY blog_id (blog_id),
    38                 KEY post_id (post_id)
    39              ) {$charset_collate};";
    40 
    41     $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_comments} (
    42                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    43                 user_id bigint(20) NOT NULL,
    44                 blog_id bigint(20) NOT NULL,
    45                 comment_id bigint(20) NOT NULL,
    46                 comment_post_id bigint(20) NOT NULL,
    47                 date_created datetime NOT NULL,
    48                 KEY user_id (user_id),
    49                 KEY blog_id (blog_id),
    50                 KEY comment_id (comment_id),
    51                 KEY comment_post_id (comment_post_id)
    5228             ) {$charset_collate};";
    5329
     
    9470
    9571    $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
    96     $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts';
    97     $bp->blogs->table_name_blog_comments = $wpdb->base_prefix . 'bp_user_blogs_comments';
    9872    $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
    9973    $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
     
    181155    do_action( 'bp_blogs_screen_my_blogs' );
    182156    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
    183 }
    184 
    185 function bp_blogs_screen_recent_posts() {
    186     do_action( 'bp_blogs_screen_recent_posts' );
    187     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
    188 }
    189 
    190 function bp_blogs_screen_recent_comments() {
    191     do_action( 'bp_blogs_screen_recent_comments' );
    192     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
    193157}
    194158
     
    331295}
    332296
    333 
    334297function bp_blogs_record_existing_blogs() {
    335298    global $bp, $wpdb;
     
    403366        $user_id = (int)$post->post_author;
    404367
    405     /* This is to stop infinate loops with Donncha's sitewide tags plugin */
     368    /* This is to stop infinite loops with Donncha's sitewide tags plugin */
    406369    if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    407370        return false;
     
    411374        return false;
    412375
    413     if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
    414         if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    415 
    416             /* If we're on a multiblog install, record this post */
    417             if ( bp_core_is_multisite() ) {
    418                 $recorded_post = new BP_Blogs_Post;
    419                 $recorded_post->user_id = $user_id;
    420                 $recorded_post->blog_id = $blog_id;
    421                 $recorded_post->post_id = $post_id;
    422                 $recorded_post->date_created = strtotime( $post->post_date );
    423 
    424                 $recorded_post_id = $recorded_post->save();
    425 
    426                 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    427             }
    428 
    429             if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    430                 /* Record this in activity streams */
    431                 $post_permalink = get_permalink( $post_id );
    432 
    433                 $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>' );
    434                 $activity_content = $post->post_content;
    435 
    436                 bp_blogs_record_activity( array(
    437                     'user_id' => (int)$post->post_author,
    438                     'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
    439                     'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
    440                     'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    441                     'type' => 'new_blog_post',
    442                     'item_id' => $blog_id,
    443                     'secondary_item_id' => $post_id,
    444                     'recorded_time' => $post->post_date_gmt
    445                 ));
    446             }
    447         }
    448     } else {
    449         $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    450 
    451         /* Delete the recorded post if the status is not published or it is password protected */
    452         if ( 'publish' != $post->post_status || '' != $post->post_password ) {
    453             return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
    454 
    455         /* If the post author has changed, delete the post and re-add it. */
    456         } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
    457             // Delete the existing recorded post
    458             bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
    459 
    460             // Re-record the post with the new author.
    461             bp_blogs_record_post( $post_id );
    462         }
     376    if ( 'publish' == $post->post_status && '' == $post->post_password ) {
     377        bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    463378
    464379        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    465             /* Now re-record the post in the activity streams */
     380            /* Record this in activity streams */
    466381            $post_permalink = get_permalink( $post_id );
    467382
     
    478393                'secondary_item_id' => $post_id,
    479394                'recorded_time' => $post->post_date_gmt
    480             ) );
     395            ));
    481396        }
    482     }
    483 
    484     do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
     397    } else
     398        bp_blogs_remove_post( $post_id, $blog_id );
     399
     400    do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
    485401}
    486402add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    487403
    488 function bp_blogs_record_comment( $comment_id, $is_approved ) {
     404function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    489405    global $wpdb, $bp;
    490 
    491     if ( !$is_approved )
    492         return false;
    493406
    494407    $comment = get_comment($comment_id);
     
    505418    if ( !empty( $post->post_password ) )
    506419        return false;
    507 
    508     /* If we're on a multiblog install, record this post */
    509     if ( bp_core_is_multisite() ) {
    510         $recorded_comment = new BP_Blogs_Comment;
    511         $recorded_comment->user_id = $user_id;
    512         $recorded_comment->blog_id = $wpdb->blogid;
    513         $recorded_comment->comment_id = $comment_id;
    514         $recorded_comment->comment_post_id = $comment->comment_post_ID;
    515         $recorded_comment->date_created = strtotime( $comment->comment_date_gmt );
    516 
    517         $recorded_commment_id = $recorded_comment->save();
    518 
    519         bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    520     }
    521420
    522421    if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
     
    542441}
    543442add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     443add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
    544444
    545445function bp_blogs_manage_comment( $comment_id, $comment_status ) {
     
    601501add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    602502
    603 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
     503function bp_blogs_remove_post( $post_id, $blog_id = false ) {
    604504    global $current_blog, $bp;
    605505
     
    609509        $blog_id = (int)$current_blog->blog_id;
    610510
    611     if ( !$existing_post )
    612         $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    613 
    614     // Delete post from the bp_blogs table
    615     BP_Blogs_Post::delete( $post_id, $blog_id );
    616 
    617511    // Delete activity stream item
    618512    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    624518function bp_blogs_remove_comment( $comment_id ) {
    625519    global $wpdb, $bp;
    626 
    627     $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
    628     BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
    629520
    630521    // Delete activity stream item
     
    663554    /* If this is regular blog, delete all data for that blog. */
    664555    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    665     BP_Blogs_Post::delete_posts_for_blog( $blog_id );
    666     BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
    667556
    668557    // Delete activity stream item
     
    677566}
    678567
    679 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
    680 function bp_blogs_get_posts_for_user( $user_id ) {
    681     return BP_Blogs_Post::get_posts_for_user( $user_id );
    682 }
    683 
    684 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
    685 function bp_blogs_get_comments_for_user( $user_id ) {
    686     return BP_Blogs_Comment::get_comments_for_user( $user_id );
    687 }
    688 
    689 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
    690     global $bp;
    691 
    692     if ( !is_numeric( $limit ) )
    693         $limit = 5;
    694 
    695     return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
    696 }
    697 
    698568function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    699569    return BP_Blogs_Blog::get_all( $limit, $page );
     
    702572function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
    703573    return BP_Blogs_Blog::get( 'random', $limit, $page );
    704 }
    705 
    706 function bp_blogs_get_all_posts( $limit = null, $page = null ) {
    707     return BP_Blogs_Post::get_all( $limit, $page );
    708 }
    709 
    710 function bp_blogs_total_post_count( $blog_id ) {
    711     return BP_Blogs_Post::total_post_count( $blog_id );
    712 }
    713 
    714 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
    715     return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    716574}
    717575
     
    832690
    833691function bp_blogs_remove_data( $user_id ) {
     692    if ( !bp_core_is_multisite() )
     693        return false;
     694
    834695    /* If this is regular blog, delete all data for that blog. */
    835696    BP_Blogs_Blog::delete_blogs_for_user( $user_id );
    836     BP_Blogs_Post::delete_posts_for_user( $user_id );
    837     BP_Blogs_Comment::delete_comments_for_user( $user_id );
    838697
    839698    do_action( 'bp_blogs_remove_data', $user_id );
     
    867726}
    868727
    869 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
    870     wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
    871 }
    872 
    873 function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
    874     bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
    875 
    876     /* Clear the sitewide activity cache */
    877     wp_cache_delete( 'sitewide_activity', 'bp' );
    878 }
    879 
    880 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
    881     wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
    882 }
    883 
    884 function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
    885     bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
    886 
    887     /* Clear the sitewide activity cache */
    888     wp_cache_delete( 'sitewide_activity', 'bp' );
    889 }
    890 
    891728// List actions to clear object caches on
    892729add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
    893 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
    894 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
    895 
    896730add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
    897 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
    898 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    899731
    900732// List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset for help on using the changeset viewer.