Ticket #7329: 7329.03.patch
File 7329.03.patch, 8.3 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-template.php
2227 2227 * Output the depth of the current activity comment. 2228 2228 * 2229 2229 * @since 2.0.0 2230 * @since 2.8.0 Added $comment as a parameter. 2231 * 2232 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 2233 * when used in activity comment loop. 2230 2234 */ 2231 function bp_activity_comment_depth( ) {2232 echo bp_activity_get_comment_depth( );2235 function bp_activity_comment_depth( $comment = 0 ) { 2236 echo bp_activity_get_comment_depth( $comment ); 2233 2237 } 2238 2234 2239 /** 2235 2240 * Return the current activity comment depth. 2236 2241 * 2237 2242 * @since 2.0.0 2243 * @since 2.8.0 Added $comment as a parameter. 2238 2244 * 2239 * @return int $depth Depth for the current activity comment. 2245 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 2246 * when used in activity comment loop. 2247 * @return int 2240 2248 */ 2241 function bp_activity_get_comment_depth() { 2242 global $activities_template; 2249 function bp_activity_get_comment_depth( $comment = 0 ) { 2250 $depth = 0; 2251 2252 // Activity comment loop takes precedence. 2253 if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) { 2254 $depth = $GLOBALS['activities_template']->activity->current_comment->depth; 2255 2256 // Get depth for activity comment manually. 2257 } elseif ( ! empty( $comment ) ) { 2258 // We passed an activity ID, so fetch the activity object. 2259 if ( is_int( $comment ) ) { 2260 $comment = new BP_Activity_Activity( $comment ); 2261 } 2262 2263 // Recurse through activity tree to find the depth. 2264 if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) { 2265 // Fetch the entire root comment tree... ugh. 2266 $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) ); 2267 2268 // Recursively find our comment object from the comment tree. 2269 $iterator = new RecursiveArrayIterator( $comments ); 2270 $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST ); 2271 foreach ( $recursive as $cid => $cobj ) { 2272 // Skip items that are not a comment object. 2273 if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) { 2274 continue; 2275 } 2276 2277 // We found the activity comment! Set the depth. 2278 if ( $cid === $comment->id && isset( $cobj->depth ) ) { 2279 $depth = $cobj->depth; 2280 break; 2281 } 2282 } 2283 } 2284 } 2243 2285 2244 2286 /** 2245 2287 * Filters the comment depth of the current activity comment. … … 2248 2290 * 2249 2291 * @param int $depth Depth for the current activity comment. 2250 2292 */ 2251 return apply_filters( 'bp_activity_get_comment_depth', $ activities_template->activity->current_comment->depth );2293 return apply_filters( 'bp_activity_get_comment_depth', $depth ); 2252 2294 } 2253 2295 2254 2296 /** … … 2884 2926 // Fall back on current comment in activity loop. 2885 2927 $comment_depth = isset( $comment->depth ) 2886 2928 ? intval( $comment->depth ) 2887 : bp_activity_get_comment_depth( );2929 : bp_activity_get_comment_depth( $comment ); 2888 2930 2889 2931 // Threading is turned on, so check the depth. 2890 2932 if ( get_option( 'thread_comments' ) ) { -
src/bp-activity/classes/class-bp-activity-list-table.php
807 807 $parent_activity = (object) $item; 808 808 } elseif ( 'activity_comment' === $item['type'] ) { 809 809 $parent_activity = new BP_Activity_Activity( $item['item_id'] ); 810 $can_comment = bp_activity_can_comment_reply( (object) $item ); 810 811 } 811 812 812 813 if ( isset( $parent_activity->type ) && bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' ) ) { -
src/bp-blogs/bp-blogs-activity.php
1147 1147 } 1148 1148 1149 1149 $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' ); 1151 1151 1152 1152 // Initialize a local object so we won't have to query this again in the 1153 1153 // comment loop. … … 1300 1300 1301 1301 // Check comment depth and disable if depth is too large. 1302 1302 if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){ 1303 if ( bp_activity_get_comment_depth( ) > buddypress()->blogs->thread_depth[$comment->item_id] ) {1303 if ( bp_activity_get_comment_depth( $comment ) >= buddypress()->blogs->thread_depth[ $comment->item_id ] ) { 1304 1304 $retval = false; 1305 1305 } 1306 1306 } -
new file tests/phpunit/testcases/activity/functions/bpActivityGetCommentDepth.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * @group activity 5 * @group bp_activity_get_comment_depth 6 */ 7 class BP_Tests_Activity_Functions_BpActivityGetCommentDepth extends BP_UnitTestCase { 8 /** 9 * @ticket BP7329 10 */ 11 public function test_depth_inside_activity_comment_loop() { 12 $u = $this->factory->user->create(); 13 14 // create an activity update 15 $parent_activity = $this->factory->activity->create( array( 16 'type' => 'activity_update', 17 'user_id' => $u 18 ) ); 19 20 // create some activity comments 21 $comment_one = bp_activity_new_comment( array( 22 'user_id' => $u, 23 'activity_id' => $parent_activity, 24 'content' => 'depth 1' 25 ) ); 26 27 $comment_one_one = bp_activity_new_comment( array( 28 'user_id' => $u, 29 'activity_id' => $parent_activity, 30 'parent_id' => $comment_one, 31 'content' => 'depth 2' 32 ) ); 33 34 $comment_two = bp_activity_new_comment( array( 35 'user_id' => $u, 36 'activity_id' => $parent_activity, 37 'content' => 'depth 1' 38 ) ); 39 40 // Instantiate activity loop, which also includes activity comments. 41 bp_has_activities( 'display_comments=threaded' ); 42 43 // Loop through activity comments generated in activity loop. 44 $recursive = new RecursiveIteratorIterator( new RecursiveArrayIterator( $GLOBALS['activities_template']->activities[0]->children ), RecursiveIteratorIterator::SELF_FIRST ); 45 foreach ( $recursive as $aid => $a ) { 46 if ( ! is_numeric( $aid ) || ! is_object( $a ) ) { 47 continue; 48 } 49 50 /* 51 * Emulate activity comment loop global, which bp_activity_get_comment_depth() 52 * relies on by default. 53 */ 54 $GLOBALS['activities_template']->activity = new stdClass; 55 $GLOBALS['activities_template']->activity->current_comment = $a; 56 57 // $aid is the activity ID for the current activity comment. 58 switch ( $aid ) { 59 case $comment_one : 60 case $comment_two : 61 $this->assertSame( bp_activity_get_comment_depth(), 1 ); 62 break; 63 64 case $comment_one_one : 65 $this->assertSame( bp_activity_get_comment_depth(), 2 ); 66 break; 67 } 68 69 } 70 71 // Clean up after ourselves! 72 $GLOBALS['activities_template'] = null; 73 } 74 75 /** 76 * @ticket BP7329 77 */ 78 public function test_depth_outside_of_activity_comment_loop() { 79 $u = $this->factory->user->create(); 80 81 // create an activity update 82 $parent_activity = $this->factory->activity->create( array( 83 'type' => 'activity_update', 84 'user_id' => $u 85 ) ); 86 87 // create some activity comments 88 $comment_one = bp_activity_new_comment( array( 89 'user_id' => $u, 90 'activity_id' => $parent_activity, 91 'content' => 'depth 1' 92 ) ); 93 94 $comment_one_one = bp_activity_new_comment( array( 95 'user_id' => $u, 96 'activity_id' => $parent_activity, 97 'parent_id' => $comment_one, 98 'content' => 'depth 2' 99 ) ); 100 101 $comment_two = bp_activity_new_comment( array( 102 'user_id' => $u, 103 'activity_id' => $parent_activity, 104 'content' => 'depth 1' 105 ) ); 106 107 $this->assertSame( bp_activity_get_comment_depth( $comment_one ), 1 ); 108 $this->assertSame( bp_activity_get_comment_depth( $comment_one_one ), 2 ); 109 $this->assertSame( bp_activity_get_comment_depth( $comment_two ), 1 ); 110 } 111 }