Changeset 11413
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-template.php
r11360 r11413 2228 2228 * 2229 2229 * @since 2.0.0 2230 */ 2231 function bp_activity_comment_depth() { 2232 echo bp_activity_get_comment_depth(); 2233 } 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. 2234 */ 2235 function bp_activity_comment_depth( $comment = 0 ) { 2236 echo bp_activity_get_comment_depth( $comment ); 2237 } 2238 2234 2239 /** 2235 2240 * Return the current activity comment depth. 2236 2241 * 2237 2242 * @since 2.0.0 2238 * 2239 * @return int $depth Depth for the current activity comment. 2240 */ 2241 function bp_activity_get_comment_depth() { 2242 global $activities_template; 2243 * @since 2.8.0 Added $comment as a parameter. 2244 * 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 2248 */ 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 /** … … 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 … … 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.
Note: See TracChangeset
for help on using the changeset viewer.