Skip to:
Content

BuddyPress.org

Changeset 2644


Ignore:
Timestamp:
02/10/2010 03:15:48 PM (15 years ago)
Author:
apeatling
Message:

Fixes #1862 - remove all child comments when deleting a comment.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2636 r2644  
    687687 * The action passes one parameter that is a single activity ID or an
    688688 * array of activity IDs depending on the number deleted.
     689 *
     690 * If you are deleting an activity comment please use bp_activity_delete_comment();
    689691*/
    690692
     
    755757    /* End deprecation */
    756758
     759function bp_activity_delete_comment( $activity_id, $comment_id ) {
     760    /* Recursively delete all children of this comment. */
     761    if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
     762        foreach( (array)$children as $child )
     763            bp_activity_delete_comment( $activity_id, $child->id );
     764    }
     765    bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
     766
     767    /* Delete the actual comment */
     768    if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
     769        return false;
     770
     771    /* Recalculate the comment tree */
     772    BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
     773
     774    return true;
     775}
     776
    757777function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
    758778    global $bp;
  • trunk/bp-activity/bp-activity-classes.php

    r2619 r2644  
    3939            $this->date_recorded = $row->date_recorded;
    4040            $this->hide_sitewide = $row->hide_sitewide;
     41            $this->mptt_left = $row->mptt_left;
     42            $this->mptt_right = $row->mptt_right;
    4143        }
    4244    }
     
    374376
    375377        /* Get all descendants of this node */
    376         $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
     378        $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
    377379
    378380        /* Loop the descendants and recalculate the left and right values */
     
    390392    }
    391393
     394    function get_child_comments( $parent_id ) {
     395        global $bp, $wpdb;
     396
     397        return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
     398    }
     399
    392400    function get_recorded_components() {
    393401        global $wpdb, $bp;
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r2606 r2644  
    226226    return true;
    227227}
    228 add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity' );
    229228add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' );
     229
     230function bp_dtheme_delete_activity_comment() {
     231    global $bp;
     232
     233    /* Check the nonce */
     234    check_admin_referer( 'bp_activity_delete_link' );
     235
     236    if ( !is_user_logged_in() ) {
     237        echo '-1';
     238        return false;
     239    }
     240
     241    $comment = new BP_Activity_Activity( $_POST['id'] );
     242
     243    /* Check access */
     244    if ( !is_site_admin() && $comment->user_id != $bp->loggedin_user->id )
     245        return false;
     246
     247    if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) || !bp_activity_delete_comment( $comment->item_id, $comment->id ) ) {
     248        echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
     249        return false;
     250    }
     251
     252    return true;
     253}
     254add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
    230255
    231256function bp_dtheme_mark_activity_favorite() {
  • trunk/bp-themes/bp-default/_inc/global.js

    r2641 r2644  
    373373            var link_href = target.attr('href');
    374374            var comment_li = target.parent().parent();
     375            var form = comment_li.parents('div.activity-comments').children('form');
    375376
    376377            var nonce = link_href.split('_wpnonce=');
     
    386387            j('div.activity-comments ul div.error').remove();
    387388
     389            /* Reset the form position */
     390            comment_li.parents('div.activity-comments').append(form);
     391
    388392            j.post( ajaxurl, {
    389                 action: 'delete_activity',
     393                action: 'delete_activity_comment',
    390394                'cookie': encodeURIComponent(document.cookie),
    391395                '_wpnonce': nonce,
     
    398402                    comment_li.prepend( response.substr( 2, response.length ) ).hide().fadeIn( 200 );
    399403                } else {
    400                     comment_li.fadeOut( 200, function() {
    401                         var children = j( 'li#' + comment_li.attr('id') + ' ul:first' );
    402 
    403                         /* Fade in sub comments if any were found. */
    404                         if ( children.length )
    405                             comment_li.parent().append( children.html() ).hide().fadeIn( 200 );
    406                     });
     404                    var children = j( 'li#' + comment_li.attr('id') + ' ul' ).children('li');
     405                    comment_li.fadeOut(200);
    407406
    408407                    /* Decrease the "Reply (X)" button count */
    409408                    var parent_li = comment_li.parents('ul#activity-stream > li');
    410                     j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html( j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html() - 1 );
     409                    j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html( j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html() - ( 1 + children.length ) );
    411410                }
    412411            });
Note: See TracChangeset for help on using the changeset viewer.