Changeset 3300 for trunk/bp-blogs.php
- Timestamp:
- 10/24/2010 09:22:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r3232 r3300 10 10 global $bp, $wpdb; 11 11 12 if ( !defined( 'BP_BLOGS_SLUG' ) ) 13 define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug ); 14 12 15 /* For internal identification */ 13 16 $bp->blogs->id = 'blogs'; … … 45 48 46 49 /* Add 'Blogs' to the main navigation */ 47 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs-> name, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );48 49 $blogs_link = $bp->loggedin_user->domain . $bp->blogs-> name. '/';50 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) ); 51 52 $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/'; 50 53 51 54 /* Set up the component options navigation for Blog */ … … 97 100 } 98 101 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' ) );107 }108 109 102 function bp_blogs_screen_create_a_blog() { 110 103 global $bp; … … 164 157 'item_id' => false, 165 158 'secondary_item_id' => false, 166 'recorded_time' => gmdate( "Y-m-d H:i:s"),159 'recorded_time' => bp_core_current_time(), 167 160 'hide_sitewide' => false 168 161 ); … … 179 172 180 173 if ( !empty( $content ) ) 181 $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );174 $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content ); 182 175 183 176 /* Check for an existing entry and update if one exists. */ … … 245 238 } 246 239 247 248 240 function bp_blogs_record_existing_blogs() { 249 241 global $bp, $wpdb; … … 270 262 } 271 263 264 /** 265 * Makes BuddyPress aware of a new site so that it can track its activity. 266 * 267 * @global object $bp BuddyPress global settings 268 * @param int $blog_id 269 * @param int $user_id 270 * @param $bool $no_activity ; optional. 271 * @since 1.0 272 * @uses BP_Blogs_Blog 273 */ 272 274 function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 273 275 global $bp; … … 290 292 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 291 293 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 292 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s") );293 294 / * Only record this activity if the blog is public */294 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); 295 296 // Only record this activity if the blog is public 295 297 if ( (int)$_POST['blog_public'] && !$no_activity ) { 296 / * Record this in activity streams */298 // Record this in activity streams 297 299 bp_blogs_record_activity( array( 298 'user_id' => $recorded_blog->user_id,299 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%1$s created the blog %2$s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),300 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_ blog_option( $recorded_blog->blog_id, 'siteurl'), $recorded_blog->blog_id ),301 'type' => 'new_blog',302 'item_id' => $recorded_blog->blog_id300 'user_id' => $recorded_blog->user_id, 301 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ), 302 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ), 303 'type' => 'new_blog', 304 'item_id' => $recorded_blog->blog_id 303 305 ) ); 304 306 } … … 307 309 } 308 310 add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 ); 311 312 /** 313 * bp_blogs_update_option_blogname() 314 * 315 * Updates blogname in BuddyPress blogmeta table 316 * 317 * @global object $wpdb DB Layer 318 * @param string $oldvalue Value before save (not used) 319 * @param string $newvalue Value to change meta to 320 */ 321 function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) { 322 global $wpdb; 323 bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue ); 324 } 325 add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 ); 326 327 /** 328 * bp_blogs_update_option_blogdescription() 329 * 330 * Updates blogdescription in BuddyPress blogmeta table 331 * 332 * @global object $wpdb DB Layer 333 * @param string $oldvalue Value before save (not used) 334 * @param string $newvalue Value to change meta to 335 */ 336 function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) { 337 global $wpdb; 338 bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue ); 339 } 340 add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 ); 309 341 310 342 function bp_blogs_record_post( $post_id, $post, $user_id = false ) { … … 317 349 $user_id = (int)$post->post_author; 318 350 319 /* This is to stop infin ate loops with Donncha's sitewide tags plugin */351 /* This is to stop infinite loops with Donncha's sitewide tags plugin */ 320 352 if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) 321 353 return false; … … 325 357 return false; 326 358 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 378 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 379 359 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 380 360 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 381 /* Now re-record the post in theactivity streams */361 /* Record this in activity streams */ 382 362 $post_permalink = get_permalink( $post_id ); 383 363 384 $activity_action = sprintf( __( '% 1$s wrote a new blog post: %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );364 $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>' ); 385 365 $activity_content = $post->post_content; 386 366 … … 394 374 'secondary_item_id' => $post_id, 395 375 'recorded_time' => $post->post_date_gmt 396 ) 376 )); 397 377 } 398 } 399 400 bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 401 402 do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded ); 378 } else 379 bp_blogs_remove_post( $post_id, $blog_id ); 380 381 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 382 383 do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id ); 403 384 } 404 385 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); 405 386 387 /** 388 * bp_blogs_record_comment() 389 * 390 * Record blog comment activity. Checks if blog is public and post is not 391 * password protected. 392 * 393 * @global object $wpdb 394 * @global $bp $bp 395 * @param int $comment_id 396 * @param bool $is_approved 397 * @return mixed 398 */ 406 399 function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 407 400 global $wpdb, $bp; … … 436 429 // If blog is public allow activity to be posted 437 430 if ( get_blog_option( $blog_id, 'blog_public' ) ) { 431 438 432 // Get activity related links 439 433 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); … … 441 435 442 436 // Prepare to record in activity streams 443 $activity_action 444 $activity_content 437 $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>' ); 438 $activity_content = $recorded_comment->comment_content; 445 439 446 440 // Record in activity streams … … 523 517 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 524 518 525 function bp_blogs_remove_post( $post_id, $blog_id = false , $existing_post = false) {519 function bp_blogs_remove_post( $post_id, $blog_id = false ) { 526 520 global $current_blog, $bp; 527 521 … … 531 525 $blog_id = (int)$current_blog->blog_id; 532 526 533 if ( !$existing_post )534 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );535 536 // Delete post from the bp_blogs table537 BP_Blogs_Post::delete( $post_id, $blog_id );538 539 527 // Delete activity stream item 540 528 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) ); … … 546 534 function bp_blogs_remove_comment( $comment_id ) { 547 535 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 );551 536 552 537 // Delete activity stream item … … 585 570 /* If this is regular blog, delete all data for that blog. */ 586 571 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 );589 572 590 573 // Delete activity stream item … … 599 582 } 600 583 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 620 584 function bp_blogs_get_all_blogs( $limit = null, $page = null ) { 621 585 return BP_Blogs_Blog::get_all( $limit, $page ); … … 626 590 } 627 591 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 );638 }639 640 592 function bp_blogs_is_blog_hidden( $blog_id ) { 641 593 return BP_Blogs_Blog::is_hidden( $blog_id ); … … 648 600 $blog = bp_blogs_get_random_blogs( 1, 1 ); 649 601 650 bp_core_redirect( get_ blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );602 bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) ); 651 603 } 652 604 } … … 664 616 global $wpdb, $bp; 665 617 666 if ( !is_numeric( $blog_id ) )618 if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() ) 667 619 return false; 668 620 … … 692 644 $blog_id = (int) $blog_id; 693 645 694 if ( !$blog_id )646 if ( !$blog_id || !bp_core_is_multisite() ) 695 647 return false; 696 648 … … 724 676 global $wpdb, $bp; 725 677 726 if ( !is_numeric( $blog_id ) )678 if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() ) 727 679 return false; 728 680 … … 754 706 755 707 function bp_blogs_remove_data( $user_id ) { 708 if ( !bp_core_is_multisite() ) 709 return false; 710 756 711 /* If this is regular blog, delete all data for that blog. */ 757 712 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 );760 713 761 714 do_action( 'bp_blogs_remove_data', $user_id ); 762 715 } 763 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 ); 764 add_action( 'delete_user', 'bp_blogs_remove_data', 1 ); 716 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 717 add_action( 'delete_user', 'bp_blogs_remove_data' ); 718 add_action( 'make_spam_user', 'bp_blogs_remove_data' ); 765 719 766 720 … … 789 743 } 790 744 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 813 745 // List actions to clear object caches on 814 746 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 818 747 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 );821 748 822 749 // List actions to clear super cached pages on, if super cache is installed
Note: See TracChangeset
for help on using the changeset viewer.