Skip to:
Content

BuddyPress.org

Changeset 3300 for trunk/bp-blogs.php


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (15 years ago)
Author:
djpaul
Message:

Fixed #2676

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r3232 r3300  
    1010    global $bp, $wpdb;
    1111
     12    if ( !defined( 'BP_BLOGS_SLUG' ) )
     13        define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );
     14
    1215    /* For internal identification */
    1316    $bp->blogs->id = 'blogs';
     
    4548
    4649    /* Add 'Blogs' to the main navigation */
    47     bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->name, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    48 
    49     $blogs_link = $bp->loggedin_user->domain . $bp->blogs->name . '/';
     50    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
     51
     52    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
    5053
    5154    /* Set up the component options navigation for Blog */
     
    97100}
    98101
    99 function 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 
    104 function 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' ) );
    107 }
    108 
    109102function bp_blogs_screen_create_a_blog() {
    110103    global $bp;
     
    164157        'item_id' => false,
    165158        'secondary_item_id' => false,
    166         'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     159        'recorded_time' => bp_core_current_time(),
    167160        'hide_sitewide' => false
    168161    );
     
    179172
    180173    if ( !empty( $content ) )
    181         $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );
     174        $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
    182175
    183176    /* Check for an existing entry and update if one exists. */
     
    245238}
    246239
    247 
    248240function bp_blogs_record_existing_blogs() {
    249241    global $bp, $wpdb;
     
    270262}
    271263
     264/**
     265 * Makes BuddyPress aware of a new site so that it can track its activity.
     266 *
     267 * @global object $bp BuddyPress global settings
     268 * @param int $blog_id
     269 * @param int $user_id
     270 * @param $bool $no_activity ; optional.
     271 * @since 1.0
     272 * @uses BP_Blogs_Blog
     273 */
    272274function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
    273275    global $bp;
     
    290292    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    291293    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    292     bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    293 
    294     /* Only record this activity if the blog is public */
     294    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
     295
     296    // Only record this activity if the blog is public
    295297    if ( (int)$_POST['blog_public'] && !$no_activity ) {
    296         /* Record this in activity streams */
     298        // Record this in activity streams
    297299        bp_blogs_record_activity( array(
    298             'user_id' => $recorded_blog->user_id,
    299             'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%1$s created the blog %2$s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
    300             'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
    301             'type' => 'new_blog',
    302             'item_id' => $recorded_blog->blog_id
     300            'user_id'      => $recorded_blog->user_id,
     301            'action'       => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
     302            'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
     303            'type'         => 'new_blog',
     304            'item_id'      => $recorded_blog->blog_id
    303305        ) );
    304306    }
     
    307309}
    308310add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
     311
     312/**
     313 * bp_blogs_update_option_blogname()
     314 *
     315 * Updates blogname in BuddyPress blogmeta table
     316 *
     317 * @global object $wpdb DB Layer
     318 * @param string $oldvalue Value before save (not used)
     319 * @param string $newvalue Value to change meta to
     320 */
     321function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
     322    global $wpdb;
     323    bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
     324}
     325add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
     326
     327/**
     328 * bp_blogs_update_option_blogdescription()
     329 *
     330 * Updates blogdescription in BuddyPress blogmeta table
     331 *
     332 * @global object $wpdb DB Layer
     333 * @param string $oldvalue Value before save (not used)
     334 * @param string $newvalue Value to change meta to
     335 */
     336function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
     337    global $wpdb;
     338    bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
     339}
     340add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
    309341
    310342function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
     
    317349        $user_id = (int)$post->post_author;
    318350
    319     /* This is to stop infinate loops with Donncha's sitewide tags plugin */
     351    /* This is to stop infinite loops with Donncha's sitewide tags plugin */
    320352    if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    321353        return false;
     
    325357        return false;
    326358
    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 
    378         bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    379 
     359    if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    380360        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    381             /* Now re-record the post in the activity streams */
     361            /* Record this in activity streams */
    382362            $post_permalink = get_permalink( $post_id );
    383363
    384             $activity_action = sprintf( __( '%1$s wrote a new blog post: %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     364            $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>' );
    385365            $activity_content = $post->post_content;
    386366
     
    394374                'secondary_item_id' => $post_id,
    395375                'recorded_time' => $post->post_date_gmt
    396             ) );
     376            ));
    397377        }
    398     }
    399 
    400     bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    401 
    402     do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
     378    } else
     379        bp_blogs_remove_post( $post_id, $blog_id );
     380
     381    bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     382
     383    do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
    403384}
    404385add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    405386
     387/**
     388 * bp_blogs_record_comment()
     389 *
     390 * Record blog comment activity. Checks if blog is public and post is not
     391 * password protected.
     392 *
     393 * @global object $wpdb
     394 * @global $bp $bp
     395 * @param int $comment_id
     396 * @param bool $is_approved
     397 * @return mixed
     398 */
    406399function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    407400    global $wpdb, $bp;
     
    436429    // If blog is public allow activity to be posted
    437430    if ( get_blog_option( $blog_id, 'blog_public' ) ) {
     431
    438432        // Get activity related links
    439433        $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
     
    441435
    442436        // 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;
     437        $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>' );
     438        $activity_content   = $recorded_comment->comment_content;
    445439
    446440        // Record in activity streams
     
    523517add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    524518
    525 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
     519function bp_blogs_remove_post( $post_id, $blog_id = false ) {
    526520    global $current_blog, $bp;
    527521
     
    531525        $blog_id = (int)$current_blog->blog_id;
    532526
    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 
    539527    // Delete activity stream item
    540528    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    546534function bp_blogs_remove_comment( $comment_id ) {
    547535    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 );
    551536
    552537    // Delete activity stream item
     
    585570    /* If this is regular blog, delete all data for that blog. */
    586571    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 );
    589572
    590573    // Delete activity stream item
     
    599582}
    600583
    601 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
    602 function 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. */
    607 function bp_blogs_get_comments_for_user( $user_id ) {
    608     return BP_Blogs_Comment::get_comments_for_user( $user_id );
    609 }
    610 
    611 function 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 
    620584function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    621585    return BP_Blogs_Blog::get_all( $limit, $page );
     
    626590}
    627591
    628 function bp_blogs_get_all_posts( $limit = null, $page = null ) {
    629     return BP_Blogs_Post::get_all( $limit, $page );
    630 }
    631 
    632 function bp_blogs_total_post_count( $blog_id ) {
    633     return BP_Blogs_Post::total_post_count( $blog_id );
    634 }
    635 
    636 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
    637     return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    638 }
    639 
    640592function bp_blogs_is_blog_hidden( $blog_id ) {
    641593    return BP_Blogs_Blog::is_hidden( $blog_id );
     
    648600        $blog = bp_blogs_get_random_blogs( 1, 1 );
    649601
    650         bp_core_redirect( get_blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );
     602        bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
    651603    }
    652604}
     
    664616    global $wpdb, $bp;
    665617
    666     if ( !is_numeric( $blog_id ) )
     618    if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
    667619        return false;
    668620
     
    692644    $blog_id = (int) $blog_id;
    693645
    694     if ( !$blog_id )
     646    if ( !$blog_id || !bp_core_is_multisite() )
    695647        return false;
    696648
     
    724676    global $wpdb, $bp;
    725677
    726     if ( !is_numeric( $blog_id ) )
     678    if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
    727679        return false;
    728680
     
    754706
    755707function bp_blogs_remove_data( $user_id ) {
     708    if ( !bp_core_is_multisite() )
     709        return false;
     710
    756711    /* If this is regular blog, delete all data for that blog. */
    757712    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 );
    760713
    761714    do_action( 'bp_blogs_remove_data', $user_id );
    762715}
    763 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 );
    764 add_action( 'delete_user', 'bp_blogs_remove_data', 1 );
     716add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
     717add_action( 'delete_user', 'bp_blogs_remove_data' );
     718add_action( 'make_spam_user', 'bp_blogs_remove_data' );
    765719
    766720
     
    789743}
    790744
    791 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
    792     wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
    793 }
    794 
    795 function 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 
    802 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
    803     wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
    804 }
    805 
    806 function 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 
    813745// List actions to clear object caches on
    814746add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
    815 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
    816 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
    817 
    818747add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
    819 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
    820 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    821748
    822749// List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset for help on using the changeset viewer.