Changeset 2842 for trunk/bp-blogs.php
- Timestamp:
- 03/12/2010 01:03:42 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r2770 r2842 26 26 KEY user_id (user_id), 27 27 KEY blog_id (blog_id) 28 ) {$charset_collate};";29 30 $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_posts} (31 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,32 user_id bigint(20) NOT NULL,33 blog_id bigint(20) NOT NULL,34 post_id bigint(20) NOT NULL,35 date_created datetime NOT NULL,36 KEY user_id (user_id),37 KEY blog_id (blog_id),38 KEY post_id (post_id)39 ) {$charset_collate};";40 41 $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_comments} (42 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,43 user_id bigint(20) NOT NULL,44 blog_id bigint(20) NOT NULL,45 comment_id bigint(20) NOT NULL,46 comment_post_id bigint(20) NOT NULL,47 date_created datetime NOT NULL,48 KEY user_id (user_id),49 KEY blog_id (blog_id),50 KEY comment_id (comment_id),51 KEY comment_post_id (comment_post_id)52 28 ) {$charset_collate};"; 53 29 … … 94 70 95 71 $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs'; 96 $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts';97 $bp->blogs->table_name_blog_comments = $wpdb->base_prefix . 'bp_user_blogs_comments';98 72 $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta'; 99 73 $bp->blogs->format_notification_function = 'bp_blogs_format_notifications'; … … 181 155 do_action( 'bp_blogs_screen_my_blogs' ); 182 156 bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) ); 183 }184 185 function bp_blogs_screen_recent_posts() {186 do_action( 'bp_blogs_screen_recent_posts' );187 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );188 }189 190 function bp_blogs_screen_recent_comments() {191 do_action( 'bp_blogs_screen_recent_comments' );192 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );193 157 } 194 158 … … 331 295 } 332 296 333 334 297 function bp_blogs_record_existing_blogs() { 335 298 global $bp, $wpdb; … … 403 366 $user_id = (int)$post->post_author; 404 367 405 /* This is to stop infin ate loops with Donncha's sitewide tags plugin */368 /* This is to stop infinite loops with Donncha's sitewide tags plugin */ 406 369 if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) 407 370 return false; … … 411 374 return false; 412 375 413 if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) { 414 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 415 416 /* If we're on a multiblog install, record this post */ 417 if ( bp_core_is_multisite() ) { 418 $recorded_post = new BP_Blogs_Post; 419 $recorded_post->user_id = $user_id; 420 $recorded_post->blog_id = $blog_id; 421 $recorded_post->post_id = $post_id; 422 $recorded_post->date_created = strtotime( $post->post_date ); 423 424 $recorded_post_id = $recorded_post->save(); 425 426 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 427 } 428 429 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 430 /* Record this in activity streams */ 431 $post_permalink = get_permalink( $post_id ); 432 433 $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>' ); 434 $activity_content = $post->post_content; 435 436 bp_blogs_record_activity( array( 437 'user_id' => (int)$post->post_author, 438 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ), 439 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ), 440 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 441 'type' => 'new_blog_post', 442 'item_id' => $blog_id, 443 'secondary_item_id' => $post_id, 444 'recorded_time' => $post->post_date_gmt 445 )); 446 } 447 } 448 } else { 449 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 450 451 /* Delete the recorded post if the status is not published or it is password protected */ 452 if ( 'publish' != $post->post_status || '' != $post->post_password ) { 453 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 454 455 /* If the post author has changed, delete the post and re-add it. */ 456 } else if ( (int)$existing_post->user_id != (int)$post->post_author ) { 457 // Delete the existing recorded post 458 bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 459 460 // Re-record the post with the new author. 461 bp_blogs_record_post( $post_id ); 462 } 376 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 377 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 463 378 464 379 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 465 /* Now re-record the post in theactivity streams */380 /* Record this in activity streams */ 466 381 $post_permalink = get_permalink( $post_id ); 467 382 … … 478 393 'secondary_item_id' => $post_id, 479 394 'recorded_time' => $post->post_date_gmt 480 ) 395 )); 481 396 } 482 } 483 484 do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded ); 397 } else 398 bp_blogs_remove_post( $post_id, $blog_id ); 399 400 do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id ); 485 401 } 486 402 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); 487 403 488 function bp_blogs_record_comment( $comment_id, $is_approved ) {404 function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 489 405 global $wpdb, $bp; 490 491 if ( !$is_approved )492 return false;493 406 494 407 $comment = get_comment($comment_id); … … 505 418 if ( !empty( $post->post_password ) ) 506 419 return false; 507 508 /* If we're on a multiblog install, record this post */509 if ( bp_core_is_multisite() ) {510 $recorded_comment = new BP_Blogs_Comment;511 $recorded_comment->user_id = $user_id;512 $recorded_comment->blog_id = $wpdb->blogid;513 $recorded_comment->comment_id = $comment_id;514 $recorded_comment->comment_post_id = $comment->comment_post_ID;515 $recorded_comment->date_created = strtotime( $comment->comment_date_gmt );516 517 $recorded_commment_id = $recorded_comment->save();518 519 bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );520 }521 420 522 421 if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { … … 542 441 } 543 442 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 443 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 ); 544 444 545 445 function bp_blogs_manage_comment( $comment_id, $comment_status ) { … … 601 501 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 602 502 603 function bp_blogs_remove_post( $post_id, $blog_id = false , $existing_post = false) {503 function bp_blogs_remove_post( $post_id, $blog_id = false ) { 604 504 global $current_blog, $bp; 605 505 … … 609 509 $blog_id = (int)$current_blog->blog_id; 610 510 611 if ( !$existing_post )612 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );613 614 // Delete post from the bp_blogs table615 BP_Blogs_Post::delete( $post_id, $blog_id );616 617 511 // Delete activity stream item 618 512 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) ); … … 624 518 function bp_blogs_remove_comment( $comment_id ) { 625 519 global $wpdb, $bp; 626 627 $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );628 BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );629 520 630 521 // Delete activity stream item … … 663 554 /* If this is regular blog, delete all data for that blog. */ 664 555 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 665 BP_Blogs_Post::delete_posts_for_blog( $blog_id );666 BP_Blogs_Comment::delete_comments_for_blog( $blog_id );667 556 668 557 // Delete activity stream item … … 677 566 } 678 567 679 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */680 function bp_blogs_get_posts_for_user( $user_id ) {681 return BP_Blogs_Post::get_posts_for_user( $user_id );682 }683 684 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */685 function bp_blogs_get_comments_for_user( $user_id ) {686 return BP_Blogs_Comment::get_comments_for_user( $user_id );687 }688 689 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {690 global $bp;691 692 if ( !is_numeric( $limit ) )693 $limit = 5;694 695 return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );696 }697 698 568 function bp_blogs_get_all_blogs( $limit = null, $page = null ) { 699 569 return BP_Blogs_Blog::get_all( $limit, $page ); … … 702 572 function bp_blogs_get_random_blogs( $limit = null, $page = null ) { 703 573 return BP_Blogs_Blog::get( 'random', $limit, $page ); 704 }705 706 function bp_blogs_get_all_posts( $limit = null, $page = null ) {707 return BP_Blogs_Post::get_all( $limit, $page );708 }709 710 function bp_blogs_total_post_count( $blog_id ) {711 return BP_Blogs_Post::total_post_count( $blog_id );712 }713 714 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {715 return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );716 574 } 717 575 … … 832 690 833 691 function bp_blogs_remove_data( $user_id ) { 692 if ( !bp_core_is_multisite() ) 693 return false; 694 834 695 /* If this is regular blog, delete all data for that blog. */ 835 696 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 836 BP_Blogs_Post::delete_posts_for_user( $user_id );837 BP_Blogs_Comment::delete_comments_for_user( $user_id );838 697 839 698 do_action( 'bp_blogs_remove_data', $user_id ); … … 867 726 } 868 727 869 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {870 wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );871 }872 873 function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {874 bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );875 876 /* Clear the sitewide activity cache */877 wp_cache_delete( 'sitewide_activity', 'bp' );878 }879 880 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {881 wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );882 }883 884 function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {885 bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );886 887 /* Clear the sitewide activity cache */888 wp_cache_delete( 'sitewide_activity', 'bp' );889 }890 891 728 // List actions to clear object caches on 892 729 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 893 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );894 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );895 896 730 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 ); 897 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );898 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );899 731 900 732 // List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset
for help on using the changeset viewer.