Skip to:
Content

BuddyPress.org

Changeset 5328


Ignore:
Timestamp:
11/13/2011 09:06:39 PM (15 years ago)
Author:
djpaul
Message:

When a blog comment status transition occurs, update the relevant activity's status. See #3660

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-functions.php

    r5302 r5328  
    289289add_action( 'edit_comment', 'bp_blogs_record_comment', 10    );
    290290
    291 function bp_blogs_manage_comment( $comment_id, $comment_status ) {
    292         if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
    293                 return bp_blogs_remove_comment( $comment_id );
    294 
    295         return bp_blogs_record_comment( $comment_id, true );
    296 }
    297 add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
    298 
    299291function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
    300292        global $wpdb;
    … …  
    397389}
    398390add_action( 'delete_comment', 'bp_blogs_remove_comment' );
     391
     392
     393/**
     394 * When a blog comment status transition occurs, update the relevant activity's status.
     395 *
     396 * @global object $bp BuddyPress global settings
     397 * @param string $new_status New comment status.
     398 * @param string $old_status Previous comment status.
     399 * @param object $comment Comment data.
     400 * @since 1.6
     401 */
     402function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
     403        global $bp;
     404
     405        // Check the Activity component is active
     406        if ( ! bp_is_active( 'activity' ) )
     407                return;
     408
     409        /**
     410         * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     411         *
     412         * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     413         * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     414         * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     415         * Otherwise, record the comment into the activity stream.
     416         */
     417
     418        // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
     419        if ( in_array( $new_status, array( 'delete', 'hold' ) ) )
     420                return bp_blogs_remove_comment( $comment->comment_ID );
     421
     422        // These clauses handle trash, spam, and un-spams.
     423        elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) )
     424                $action = 'spam_activity';
     425        elseif ( 'approved' == $new_status )
     426                $action = 'ham_activity';
     427
     428        // Get the activity
     429        $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
     430
     431        // Check activity item exists
     432        if ( ! $activity_id ) {
     433
     434                // If no activity exists, but the comment has been approved, record it into the activity table.
     435                if ( 'approved' == $new_status )
     436                        return bp_blogs_record_comment( $comment->comment_ID, true );
     437
     438                return;
     439        }
     440
     441        // Create an activity object
     442        $activity = new BP_Activity_Activity( $activity_id );
     443        if ( empty( $activity->component ) )
     444                return;
     445
     446        // Spam/ham the activity if it's not already in that state
     447        if ( 'spam_activity' == $action && ! $activity->is_spam ) {
     448                bp_activity_mark_as_spam( $activity );
     449        } elseif ( 'ham_activity' == $action) {
     450                bp_activity_mark_as_ham( $activity );
     451        }
     452
     453        // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
     454        $comment_akismet_history = create_function( '$t', '$t[] = "new_blog_comment"; return $t;' );
     455        add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
     456
     457        // Save the updated activity
     458        $activity->save();
     459
     460        // Remove the "new_blog_comment" activity type whitelist so we don't break anything
     461        remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
     462}
     463add_action( 'transition_comment_status', 'bp_blogs_transition_activity_status', 10, 3 );
    399464
    400465function bp_blogs_total_blogs() {
  • trunk/bp-core/deprecated/1.6.php

    r5305 r5328  
    4848        bp_is_user_spammer( $user_id );
    4949}
     50
     51
     52/**
     53 * Blogs functions
     54 */
     55
     56/*
     57 * @deprecated 1.6
     58 * @deprecated No longer used; see bp_blogs_transition_activity_status()
     59 */
     60function bp_blogs_manage_comment( $comment_id, $comment_status ) {
     61        _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
     62}
    5063?>
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r5302 r5328  
    345345        // Load up the activity item
    346346        $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    347         if ( empty( $activity->id ) ) {
     347        if ( empty( $activity->component ) ) {
    348348                echo '-1';
    349349                return false;
Note: See TracChangeset for help on using the changeset viewer.