Skip to:
Content

BuddyPress.org

Changeset 3053


Ignore:
Timestamp:
06/14/2010 11:10:18 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Fix issue where comments would appear in activity even if blog was private. Also clean up bp_blogs_record_comment function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-blogs.php

    r3033 r3053  
    432432add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    433433
     434/**
     435 * bp_blogs_record_comment()
     436 *
     437 * Record blog comment activity. Checks if blog is public and post is not
     438 * password protected.
     439 *
     440 * @global object $wpdb
     441 * @global $bp $bp
     442 * @param <type> $comment_id
     443 * @param <type> $is_approved
     444 * @return <type>
     445 */
    434446function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    435447    global $wpdb, $bp;
    436448
    437     $comment = get_comment($comment_id);
    438 
    439     if ( !$is_approved )
    440         return false;
    441 
    442     $comment->post = get_post( $comment->comment_post_ID );
    443 
    444     /* Get the user_id from the author email. */
    445     $user = get_user_by_email( $comment->comment_author_email );
     449    // Get the users comment
     450    $recorded_comment = get_comment( $comment_id );
     451
     452    // Don't record activity if the comment hasn't been approved
     453    if ( !$is_approved || true != $recorded_comment->comment_approved )
     454        return false;
     455
     456    // Get blog and post data
     457    $blog_id = (int)$wpdb->blogid;
     458    $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
     459
     460    // Get the user_id from the comment author email.
     461    $user = get_user_by_email( $recorded_comment->comment_author_email );
    446462    $user_id = (int)$user->ID;
    447463
     464    // If there's no registered user id, don't record activity
    448465    if ( !$user_id )
    449466        return false;
    450467
    451     /* If this is a password protected post, don't record the comment */
    452     if ( !empty( $post->post_password ) )
    453         return false;
    454 
    455     if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    456         /* Record in activity streams */
    457         $comment_link = htmlspecialchars( get_comment_link( $comment->comment_ID ) );
    458         $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '">' . $comment->post->post_title . '</a>' );
    459         $activity_content = $comment->comment_content;
    460 
    461         /* Record this in activity streams */
     468    // If this is a password protected post, don't record the comment
     469    if ( !empty( $recorded_comment->post->post_password ) )
     470        return false;
     471
     472    // If blog is public allow activity to be posted
     473    if ( get_blog_option( $blog_id, 'blog_public' ) ) {
     474
     475        // Prepare to record in activity streams
     476        $comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
     477        $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '">' . $recorded_comment->post->post_title . '</a>' );
     478        $activity_content = $recorded_comment->comment_content;
     479
     480        // Record in activity streams
    462481        bp_blogs_record_activity( array(
    463482            'user_id' => $user_id,
    464             'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),
    465             'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    466             'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
     483            'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
     484            'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
     485            'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
    467486            'type' => 'new_blog_comment',
    468             'item_id' => $wpdb->blogid,
     487            'item_id' => $blog_id,
    469488            'secondary_item_id' => $comment_id,
    470             'recorded_time' => $comment->comment_date_gmt
     489            'recorded_time' => $recorded_comment->comment_date_gmt
    471490        ) );
    472491
     492        // Update the blogs last active date
    473493        bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    474494    }
Note: See TracChangeset for help on using the changeset viewer.