Changeset 8189
- Timestamp:
- 03/28/2014 10:33:16 PM (11 years ago)
- Location:
- trunk/bp-blogs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs/bp-blogs-activity.php
r8126 r8189 346 346 ) ); 347 347 } 348 349 /** 350 * Check if a blog post's activity item should be closed from commenting. 351 * 352 * This mirrors the {@link comments_open()} and {@link _close_comments_for_old_post()} 353 * functions, but for use with the BuddyPress activity stream to be as 354 * lightweight as possible. 355 * 356 * By lightweight, we actually mirror a few of the blog's commenting settings 357 * to blogmeta and checks the values in blogmeta instead. This is to prevent 358 * multiple {@link switch_to_blog()} calls in the activity stream. 359 * 360 * @since BuddyPress (2.0.0) 361 * 362 * @param object $activity The BP_Activity_Activity object 363 * @return bool 364 */ 365 function bp_blogs_comments_open( $activity ) { 366 $open = true; 367 368 $blog_id = $activity->item_id; 369 370 // see if we've mirrored the close comments option before 371 $days_old = bp_blogs_get_blogmeta( $blog_id, 'close_comments_days_old' ); 372 373 // we've never cached these items before, so do it now 374 if ( '' === $days_old ) { 375 switch_to_blog( $blog_id ); 376 377 // use comments_open() 378 remove_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 379 $open = comments_open( $activity->secondary_item_id ); 380 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 381 382 // might as well mirror values to blogmeta since we're here! 383 $thread_depth = get_option( 'thread_comments' ); 384 if ( ! empty( $thread_depth ) ) { 385 $thread_depth = get_option( 'thread_comments_depth' ); 386 } else { 387 // perhaps filter this? 388 $thread_depth = 1; 389 } 390 391 bp_blogs_update_blogmeta( $blog_id, 'close_comments_for_old_posts', get_option( 'close_comments_for_old_posts' ) ); 392 bp_blogs_update_blogmeta( $blog_id, 'close_comments_days_old', get_option( 'close_comments_days_old' ) ); 393 bp_blogs_update_blogmeta( $blog_id, 'thread_comments_depth', $thread_depth ); 394 395 restore_current_blog(); 396 397 // check blogmeta and manually check activity item 398 // basically a copy of _close_comments_for_old_post() 399 } else { 400 401 // comments are closed 402 if ( 'closed' == bp_activity_get_meta( $activity->id, 'post_comment_status' ) ) { 403 return false; 404 } 405 406 if ( ! bp_blogs_get_blogmeta( $blog_id, 'close_comments_for_old_posts' ) ) { 407 return $open; 408 } 409 410 $days_old = (int) $days_old; 411 if ( ! $days_old ) { 412 return $open; 413 } 414 415 /* commenting out for now - needs some more thought... 416 should we add the post type to activity meta? 417 418 $post = get_post($post_id); 419 420 // This filter is documented in wp-includes/comment.php 421 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 422 if ( ! in_array( $post->post_type, $post_types ) ) 423 return $open; 424 */ 425 426 if ( time() - strtotime( $activity->date_recorded ) > ( $days_old * DAY_IN_SECONDS ) ) { 427 return false; 428 } 429 430 return $open; 431 } 432 433 return $open; 434 } -
trunk/bp-blogs/bp-blogs-functions.php
r8135 r8189 183 183 return false; 184 184 185 $url = get_home_url( $blog_id ); 186 $name = get_blog_option( $blog_id, 'blogname' ); 187 $description = get_blog_option( $blog_id, 'blogdescription' ); 188 189 if ( empty( $name ) ) 190 return false; 185 $name = get_blog_option( $blog_id, 'blogname' ); 186 187 if ( empty( $name ) ) { 188 return false; 189 } 190 191 $url = get_home_url( $blog_id ); 192 $description = get_blog_option( $blog_id, 'blogdescription' ); 193 $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' ); 194 $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' ); 195 196 $thread_depth = get_blog_option( $blog_id, 'thread_comments' ); 197 if ( ! empty( $thread_depth ) ) { 198 $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' ); 199 } else { 200 // perhaps filter this? 201 $thread_depth = 1; 202 } 191 203 192 204 $recorded_blog = new BP_Blogs_Blog; … … 200 212 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 201 213 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); 214 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts ); 215 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old ); 216 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth ); 202 217 203 218 $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true; … … 251 266 } 252 267 add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 ); 268 269 /** 270 * Update "Close comments for old posts" option in BuddyPress blogmeta table. 271 * 272 * @since BuddyPress (2.0.0) 273 * 274 * @global object $wpdb DB Layer. 275 * 276 * @param string $oldvalue Value before save. Passed by do_action() but 277 * unused here. 278 * @param string $newvalue Value to change meta to. 279 */ 280 function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) { 281 global $wpdb; 282 283 bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_for_old_posts', $newvalue ); 284 } 285 add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_update_option_close_comments_for_old_posts', 10, 2 ); 286 287 /** 288 * Update "Close comments after days old" option in BuddyPress blogmeta table. 289 * 290 * @since BuddyPress (2.0.0) 291 * 292 * @global object $wpdb DB Layer. 293 * 294 * @param string $oldvalue Value before save. Passed by do_action() but 295 * unused here. 296 * @param string $newvalue Value to change meta to. 297 */ 298 function bp_blogs_update_option_close_close_comments_days_old( $oldvalue, $newvalue ) { 299 global $wpdb; 300 301 bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue ); 302 } 303 add_action( 'update_option_close_comments_days_old', 'bp_blogs_update_option_close_comments_days_old', 10, 2 ); 304 305 /** 306 * When toggling threaded comments, update thread depth in blogmeta table. 307 * 308 * @since BuddyPress (2.0.0) 309 * 310 * @global object $wpdb DB Layer. 311 * 312 * @param string $oldvalue Value before save. Passed by do_action() but 313 * unused here. 314 * @param string $newvalue Value to change meta to. 315 */ 316 function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) { 317 global $wpdb; 318 319 if ( empty( $newvalue ) ) { 320 $thread_depth = 1; 321 } else { 322 $thread_depth = get_option( 'thread_comments_depth' ); 323 } 324 325 bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $thread_depth ); 326 } 327 add_action( 'update_option_thread_comments', 'bp_blogs_update_option_thread_comments', 10, 2 ); 328 329 /** 330 * When updating comment depth, update thread depth in blogmeta table. 331 * 332 * @since BuddyPress (2.0.0) 333 * 334 * @global object $wpdb DB Layer. 335 * 336 * @param string $oldvalue Value before save. Passed by do_action() but 337 * unused here. 338 * @param string $newvalue Value to change meta to. 339 */ 340 function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) { 341 global $wpdb; 342 343 $comments_enabled = get_option( 'thread_comments' ); 344 345 if ( $comments_enabled ) { 346 bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $newvalue ); 347 } 348 } 349 add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 ); 253 350 254 351 /**
Note: See TracChangeset
for help on using the changeset viewer.