Skip to:
Content

BuddyPress.org

Ticket #7329: 7329.02.patch

File 7329.02.patch, 4.2 KB (added by r-a-y, 8 years ago)
  • src/bp-activity/bp-activity-template.php

     
    22302230 * Output the depth of the current activity comment.
    22312231 *
    22322232 * @since 2.0.0
     2233 *
     2234 * @param object|null $comment Object of the activity comment. Usually unnecessary when used in activity
     2235 *                             comment loop.
    22332236 */
    2234 function bp_activity_comment_depth() {
    2235         echo bp_activity_get_comment_depth();
     2237function bp_activity_comment_depth( $comment = null ) {
     2238        echo bp_activity_get_comment_depth( $comment );
    22362239}
     2240
    22372241        /**
    22382242         * Return the current activity comment depth.
    22392243         *
    22402244         * @since 2.0.0
    22412245         *
    2242          * @return int $depth Depth for the current activity comment.
     2246         * @param  object|null $comment Object of the activity comment. Usually unnecessary when used in
     2247         *                              activity comment loop.
     2248         * @return int         $depth   Depth for the current activity comment.
    22432249         */
    2244         function bp_activity_get_comment_depth() {
     2250        function bp_activity_get_comment_depth( $comment = null ) {
    22452251                global $activities_template;
    22462252
     2253                $depth = 1;
     2254                if ( isset( $activities_template->activity->current_comment->depth ) ) {
     2255                        $depth = $activities_template->activity->current_comment->depth;
     2256                } elseif ( ! empty( $comment->id ) ) {
     2257                        // Fetch the entire root comment tree... ugh.
     2258                        $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) );
     2259
     2260                        // Recursively find our comment object from the comment tree.
     2261                        $iterator  = new RecursiveArrayIterator( $comments );
     2262                        $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST );
     2263                        foreach ( $recursive as $cid => $cobj ) {
     2264                                // We found the activity comment! Set the depth.
     2265                                if ( $cid === $comment->id && isset( $cobj->depth ) ) {
     2266                                        $depth = $cobj->depth;
     2267
     2268                                        /*
     2269                                         * Here, we're iterating the depth to anticipate the next comment.
     2270                                         *
     2271                                         * We're doing this because:
     2272                                         * - We're (probably) displaying activity comments in stream mode.
     2273                                         * - We need to iterate so bp_blogs_can_comment_reply() knows how to
     2274                                         *   disable replies for activity comments.
     2275                                         */
     2276                                        ++$depth;
     2277
     2278                                        break;
     2279                                }
     2280                        }
     2281                }
     2282
    22472283                /**
    22482284                 * Filters the comment depth of the current activity comment.
    22492285                 *
     
    22512287                 *
    22522288                 * @param int $depth Depth for the current activity comment.
    22532289                 */
    2254                 return apply_filters( 'bp_activity_get_comment_depth', $activities_template->activity->current_comment->depth );
     2290                return apply_filters( 'bp_activity_get_comment_depth', $depth );
    22552291        }
    22562292
    22572293/**
  • src/bp-blogs/bp-blogs-activity.php

     
    11471147        }
    11481148
    11491149        $allow_comments = bp_blogs_comments_open( $activity );
    1150         $thread_depth   = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
     1150        $thread_depth   = (int) bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
    11511151
    11521152        // Initialize a local object so we won't have to query this again in the
    11531153        // comment loop.
     
    12991299        }
    13001300
    13011301        // Check comment depth and disable if depth is too large.
    1302         if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){
    1303                 if ( bp_activity_get_comment_depth() > buddypress()->blogs->thread_depth[$comment->item_id] ) {
     1302        if ( isset( buddypress()->blogs->thread_depth[ $comment->item_id ] ) ) {
     1303                if ( bp_activity_get_comment_depth( $comment ) > buddypress()->blogs->thread_depth[ $comment->item_id ] ) {
    13041304                        $retval = false;
    13051305                }
    13061306        }
    13071307
    13081308        // Check if we should disable activity replies based on the parent activity.
    1309         if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){
     1309        if ( isset( buddypress()->blogs->allow_comments[ $comment->item_id ] ) ) {
    13101310                // The blog post has closed off commenting, so we should disable all activity
    13111311                // comments under the parent 'new_blog_post' activity entry.
    1312                 if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) {
     1312                if ( empty( buddypress()->blogs->allow_comments[ $comment->item_id ] ) ) {
    13131313                        $retval = false;
    13141314                }
    13151315        }