Skip to:
Content

BuddyPress.org

Ticket #4600: bp-activity-classes.php.patch

File bp-activity-classes.php.patch, 2.9 KB (added by sboisvert, 13 years ago)
  • bp-activity/bp-activity-classes.php

     
    452452
    453453                $activity_comments = array();
    454454
    455                 /* Now fetch the activity comments and parse them into the correct position in the activities array. */
     455                // Now fetch the activity comments and parse them into the correct position in the activities array.
    456456                foreach( (array) $activities as $activity ) {
    457                         if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
    458                                 $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam );
     457                         $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;
     458                         $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id );
    459459                }
    460460
    461461                /* Merge the comments with the activity items */
     
    478478         * @return array The updated activities with nested comments
    479479         * @since 1.2
    480480         */
    481         function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only' ) {
     481        function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only',$top_level_parent_id = 0 ) {
    482482                global $wpdb, $bp;
    483483
     484                if ( empty( $top_level_parent_id ) ) {
     485                        $top_level_parent_id = $activity_id;
     486                }
     487               
    484488                if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
    485489                        // Select the user's fullname with the query
    486490                        if ( bp_is_active( 'xprofile' ) ) {
     
    501505                        else
    502506                                $spam_sql = '';
    503507
    504                         $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' ${spam_sql} AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
     508                        // The mptt BETWEEN clause allows us to limit returned descendants to the right part of the tree
     509                        $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' ${spam_sql} AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
    505510
    506511                        // Retrieve all descendants of the $root node
    507512                        $descendants = $wpdb->get_results( $sql );