Changeset 3232 for trunk/bp-blogs.php
- Timestamp:
- 09/06/2010 04:24:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r2946 r3232 10 10 global $bp, $wpdb; 11 11 12 if ( !defined( 'BP_BLOGS_SLUG' ) )13 define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );14 15 12 /* For internal identification */ 16 13 $bp->blogs->id = 'blogs'; 17 $bp->blogs->name = $bp->pages->blogs->name; 14 18 15 $bp->blogs->slug = BP_BLOGS_SLUG; 19 16 20 $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs'; 21 $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta'; 17 $bp->blogs->table_name = $bp->table_prefix . 'bp_user_blogs'; 18 $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta'; 19 22 20 $bp->blogs->format_notification_function = 'bp_blogs_format_notifications'; 23 21 … … 97 95 do_action( 'bp_blogs_screen_my_blogs' ); 98 96 bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) ); 97 } 98 99 function bp_blogs_screen_recent_posts() { 100 do_action( 'bp_blogs_screen_recent_posts' ); 101 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) ); 102 } 103 104 function bp_blogs_screen_recent_comments() { 105 do_action( 'bp_blogs_screen_recent_comments' ); 106 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) ); 99 107 } 100 108 … … 237 245 } 238 246 247 239 248 function bp_blogs_record_existing_blogs() { 240 249 global $bp, $wpdb; … … 308 317 $user_id = (int)$post->post_author; 309 318 310 /* This is to stop infin ite loops with Donncha's sitewide tags plugin */319 /* This is to stop infinate loops with Donncha's sitewide tags plugin */ 311 320 if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) 312 321 return false; … … 316 325 return false; 317 326 318 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 327 if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) { 328 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 329 330 /* If we're on a multiblog install, record this post */ 331 if ( bp_core_is_multisite() ) { 332 $recorded_post = new BP_Blogs_Post; 333 $recorded_post->user_id = $user_id; 334 $recorded_post->blog_id = $blog_id; 335 $recorded_post->post_id = $post_id; 336 $recorded_post->date_created = strtotime( $post->post_date ); 337 338 $recorded_post_id = $recorded_post->save(); 339 340 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 341 } 342 343 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 344 /* Record this in activity streams */ 345 $post_permalink = get_permalink( $post_id ); 346 347 $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 348 $activity_content = $post->post_content; 349 350 bp_blogs_record_activity( array( 351 'user_id' => (int)$post->post_author, 352 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ), 353 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ), 354 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 355 'type' => 'new_blog_post', 356 'item_id' => $blog_id, 357 'secondary_item_id' => $post_id, 358 'recorded_time' => $post->post_date_gmt 359 )); 360 } 361 } 362 } else { 363 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 364 365 /* Delete the recorded post if the status is not published or it is password protected */ 366 if ( 'publish' != $post->post_status || '' != $post->post_password ) { 367 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 368 369 /* If the post author has changed, delete the post and re-add it. */ 370 } else if ( (int)$existing_post->user_id != (int)$post->post_author ) { 371 // Delete the existing recorded post 372 bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 373 374 // Re-record the post with the new author. 375 bp_blogs_record_post( $post_id ); 376 } 377 319 378 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 320 379 321 380 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 322 /* Record this inactivity streams */381 /* Now re-record the post in the activity streams */ 323 382 $post_permalink = get_permalink( $post_id ); 324 383 … … 335 394 'secondary_item_id' => $post_id, 336 395 'recorded_time' => $post->post_date_gmt 337 ) );396 ) ); 338 397 } 339 } else 340 bp_blogs_remove_post( $post_id, $blog_id ); 398 } 341 399 342 400 bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 343 401 344 do_action( 'bp_blogs_new_blog_post', $ post_id, $post, $user_id );402 do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded ); 345 403 } 346 404 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); … … 349 407 global $wpdb, $bp; 350 408 351 $comment = get_comment($comment_id); 352 353 if ( !$is_approved ) 354 return false; 355 356 $comment->post = get_post( $comment->comment_post_ID ); 357 358 /* Get the user_id from the author email. */ 359 $user = get_user_by_email( $comment->comment_author_email ); 409 // Get the users comment 410 $recorded_comment = get_comment( $comment_id ); 411 412 // Don't record activity if the comment hasn't been approved 413 if ( !$is_approved || !$recorded_comment->comment_approved ) 414 return false; 415 416 // Don't record activity if no email address has been included 417 if ( empty( $recorded_comment->comment_author_email ) ) 418 return false; 419 420 // Get the user_id from the comment author email. 421 $user = get_user_by_email( $recorded_comment->comment_author_email ); 360 422 $user_id = (int)$user->ID; 361 423 362 if ( !$user_id ) 363 return false; 364 365 /* If this is a password protected post, don't record the comment */ 366 if ( !empty( $post->post_password ) ) 367 return false; 368 369 if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 370 /* Record in activity streams */ 371 $comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id; 372 $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 373 $activity_content = $comment->comment_content; 374 375 /* Record this in activity streams */ 424 // If there's no registered user id, don't record activity 425 if ( empty( $user_id ) ) 426 return false; 427 428 // Get blog and post data 429 $blog_id = (int)$wpdb->blogid; 430 $recorded_comment->post = get_post( $recorded_comment->comment_post_ID ); 431 432 // If this is a password protected post, don't record the comment 433 if ( !empty( $recorded_comment->post->post_password ) ) 434 return false; 435 436 // If blog is public allow activity to be posted 437 if ( get_blog_option( $blog_id, 'blog_public' ) ) { 438 // Get activity related links 439 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 440 $comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) ); 441 442 // Prepare to record in activity streams 443 $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 444 $activity_content = $recorded_comment->comment_content; 445 446 // Record in activity streams 376 447 bp_blogs_record_activity( array( 377 'user_id' => $user_id,378 'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),379 'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),380 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),381 'type' => 'new_blog_comment',382 'item_id' => $wpdb->blogid,448 'user_id' => $user_id, 449 'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ), 450 'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ), 451 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ), 452 'type' => 'new_blog_comment', 453 'item_id' => $blog_id, 383 454 'secondary_item_id' => $comment_id, 384 'recorded_time' => $comment->comment_date_gmt455 'recorded_time' => $recorded_comment->comment_date_gmt 385 456 ) ); 386 } 387 388 bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 457 458 // Update the blogs last active date 459 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 460 } 389 461 390 462 return $recorded_comment; … … 451 523 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 452 524 453 function bp_blogs_remove_post( $post_id, $blog_id = false ) {525 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) { 454 526 global $current_blog, $bp; 455 527 … … 459 531 $blog_id = (int)$current_blog->blog_id; 460 532 533 if ( !$existing_post ) 534 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 535 536 // Delete post from the bp_blogs table 537 BP_Blogs_Post::delete( $post_id, $blog_id ); 538 461 539 // Delete activity stream item 462 540 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) ); … … 468 546 function bp_blogs_remove_comment( $comment_id ) { 469 547 global $wpdb, $bp; 548 549 $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id ); 550 BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid ); 470 551 471 552 // Delete activity stream item … … 504 585 /* If this is regular blog, delete all data for that blog. */ 505 586 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 587 BP_Blogs_Post::delete_posts_for_blog( $blog_id ); 588 BP_Blogs_Comment::delete_comments_for_blog( $blog_id ); 506 589 507 590 // Delete activity stream item … … 516 599 } 517 600 601 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */ 602 function bp_blogs_get_posts_for_user( $user_id ) { 603 return BP_Blogs_Post::get_posts_for_user( $user_id ); 604 } 605 606 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */ 607 function bp_blogs_get_comments_for_user( $user_id ) { 608 return BP_Blogs_Comment::get_comments_for_user( $user_id ); 609 } 610 611 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) { 612 global $bp; 613 614 if ( !is_numeric( $limit ) ) 615 $limit = 5; 616 617 return BP_Blogs_Post::get_latest_posts( $blog_id, $limit ); 618 } 619 518 620 function bp_blogs_get_all_blogs( $limit = null, $page = null ) { 519 621 return BP_Blogs_Blog::get_all( $limit, $page ); … … 522 624 function bp_blogs_get_random_blogs( $limit = null, $page = null ) { 523 625 return BP_Blogs_Blog::get( 'random', $limit, $page ); 626 } 627 628 function bp_blogs_get_all_posts( $limit = null, $page = null ) { 629 return BP_Blogs_Post::get_all( $limit, $page ); 630 } 631 632 function bp_blogs_total_post_count( $blog_id ) { 633 return BP_Blogs_Post::total_post_count( $blog_id ); 634 } 635 636 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) { 637 return BP_Blogs_Post::total_comment_count( $blog_id, $post_id ); 524 638 } 525 639 … … 640 754 641 755 function bp_blogs_remove_data( $user_id ) { 642 if ( !bp_core_is_multisite() )643 return false;644 645 756 /* If this is regular blog, delete all data for that blog. */ 646 757 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 758 BP_Blogs_Post::delete_posts_for_user( $user_id ); 759 BP_Blogs_Comment::delete_comments_for_user( $user_id ); 647 760 648 761 do_action( 'bp_blogs_remove_data', $user_id ); 649 762 } 650 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 651 add_action( 'delete_user', 'bp_blogs_remove_data' ); 652 add_action( 'make_spam_user', 'bp_blogs_remove_data' ); 763 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 ); 764 add_action( 'delete_user', 'bp_blogs_remove_data', 1 ); 653 765 654 766 … … 677 789 } 678 790 791 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) { 792 wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' ); 793 } 794 795 function bp_blogs_format_clear_post_cache( $recorded_post_obj ) { 796 bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id ); 797 798 /* Clear the sitewide activity cache */ 799 wp_cache_delete( 'sitewide_activity', 'bp' ); 800 } 801 802 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) { 803 wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' ); 804 } 805 806 function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) { 807 bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id ); 808 809 /* Clear the sitewide activity cache */ 810 wp_cache_delete( 'sitewide_activity', 'bp' ); 811 } 812 679 813 // List actions to clear object caches on 680 814 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 815 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 ); 816 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 ); 817 681 818 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 ); 819 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 ); 820 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 ); 682 821 683 822 // List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset
for help on using the changeset viewer.