Changeset 3728 for trunk/bp-blogs.php
- Timestamp:
- 01/18/2011 12:53:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r3708 r3728 1 1 <?php 2 3 // Required Files 2 4 require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' ); 3 5 require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' ); 4 6 5 / * Include the sitewide blog posts widget if this is a multisite installation */7 // Include the sitewide blog posts widget if this is a multisite installation 6 8 if ( is_multisite() ) 7 9 require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' ); … … 11 13 12 14 if ( !defined( 'BP_BLOGS_SLUG' ) && isset( $bp->pages->blogs->slug ) ) 13 define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug);14 else if( !defined( 'BP_BLOGS_SLUG' ) )15 define ( 'BP_BLOGS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->blogs->slug ) ); 16 else if( !defined( 'BP_BLOGS_SLUG' ) ) 15 17 define ( 'BP_BLOGS_SLUG', 'blogs' ); 16 18 17 19 // For internal identification 18 $bp->blogs->id = 'blogs'; 19 20 $bp->blogs->slug = BP_BLOGS_SLUG; 21 20 $bp->blogs->id = 'blogs'; 21 $bp->blogs->name = $bp->pages->blogs->name; 22 23 // Slugs 24 $bp->blogs->slug = BP_BLOGS_SLUG; 25 $bp->blogs->root_slug = $bp->pages->blogs->slug; 26 27 // Tables 22 28 $bp->blogs->table_name = $bp->table_prefix . 'bp_user_blogs'; 23 29 $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta'; 24 30 25 $bp->blogs->format_notification_function = 'bp_blogs_format_notifications'; 31 // Notifications 32 $bp->blogs->format_notification_function = 'bp_blogs_format_notifications'; 26 33 27 34 // Register this in the active components array 28 $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;35 $bp->active_components[$bp->blogs->slug] = $bp->blogs->id; 29 36 30 37 // The default text for the blogs directory search box … … 36 43 37 44 /** 38 * bp_blogs_setup_nav()39 *40 45 * Adds "Blog" to the navigation arrays for the current and logged in user. 41 46 * … … 47 52 global $bp; 48 53 49 /* Blog/post/comment menus should not appear on single WordPress setups. Although comments 50 and posts made by users will still show on their activity stream .*/ 54 /** 55 * Blog/post/comment menus should not appear on single WordPress setups. 56 * Although comments and posts made by users will still show on their 57 * activity stream. 58 */ 51 59 if ( !is_multisite() ) 52 60 return false; 53 61 54 / * Add 'Blogs' to the main navigation */62 // Add 'Blogs' to the main navigation 55 63 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 ) ); 56 64 57 65 $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/'; 58 66 59 / * Set up the component options navigation for Blog */67 // Set up the component options navigation for Blog 60 68 if ( $bp->blogs->slug == $bp->current_component ) { 61 69 if ( bp_is_my_profile() ) { … … 64 72 } 65 73 } else { 66 /* If we are not viewing the logged in user, set up the current users avatar and name */ 74 // If we are not viewing the logged in user, set up the current 75 // users avatar and name 67 76 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 68 77 $bp->bp_options_title = $bp->displayed_user->fullname; … … 87 96 88 97 89 /******************************************************************************* *98 /******************************************************************************* 90 99 * Screen Functions 91 100 * … … 117 126 bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) ); 118 127 } 119 /* The create screen is not attached to a nav item, so we need to attach it to an action */120 128 add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 ); 121 129 122 130 123 /******************************************************************************* *131 /******************************************************************************* 124 132 * Activity & Notification Functions 125 133 * … … 148 156 return false; 149 157 150 /* Because blog, comment, and blog post code execution happens before anything else 151 we may need to manually instantiate the activity component globals */ 158 /** 159 * Because blog, comment, and blog post code execution happens before 160 * anything else we may need to manually instantiate the activity 161 * component globals. 162 */ 152 163 if ( !$bp->activity && function_exists('bp_activity_setup_globals') ) 153 164 bp_activity_setup_globals(); 154 165 155 166 $defaults = array( 156 'user_id' => $bp->loggedin_user->id,157 'action' => '',158 'content' => '',159 'primary_link' => '',160 'component' => $bp->blogs->id,161 'type' => false,162 'item_id' => false,167 'user_id' => $bp->loggedin_user->id, 168 'action' => '', 169 'content' => '', 170 'primary_link' => '', 171 'component' => $bp->blogs->id, 172 'type' => false, 173 'item_id' => false, 163 174 'secondary_item_id' => false, 164 'recorded_time' => bp_core_current_time(),165 'hide_sitewide' => false175 'recorded_time' => bp_core_current_time(), 176 'hide_sitewide' => false 166 177 ); 167 178 … … 169 180 extract( $r, EXTR_SKIP ); 170 181 171 / * Remove large images and replace them with just one image thumbnail */182 // Remove large images and replace them with just one image thumbnail 172 183 if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) ) 173 184 $content = bp_activity_thumbnail_content_images( $content, $primary_link ); … … 179 190 $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content ); 180 191 181 / * Check for an existing entry and update if one exists. */192 // Check for an existing entry and update if one exists. 182 193 $id = bp_activity_get_activity_id( array( 183 194 'user_id' => $user_id, … … 194 205 global $bp; 195 206 196 if ( function_exists( 'bp_activity_delete_by_item_id') ) {207 if ( function_exists( 'bp_activity_delete_by_item_id' ) ) { 197 208 $defaults = array( 198 'item_id' => false,199 'component' => $bp->blogs->id,200 'type' => false,201 'user_id' => false,209 'item_id' => false, 210 'component' => $bp->blogs->id, 211 'type' => false, 212 'user_id' => false, 202 213 'secondary_item_id' => false 203 214 ); … … 229 240 230 241 $defaults = array( 231 'type' => 'active', // active, alphabetical, newest, or random. 232 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on. 233 'search_terms' => false, // Limit to blogs that match these search terms 234 235 'per_page' => 20, // The number of results to return per page 236 'page' => 1, // The page to return if limiting per page 242 'type' => 'active', // active, alphabetical, newest, or random 243 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on 244 'search_terms' => false, // Limit to blogs that match these search terms 245 'per_page' => 20, // The number of results to return per page 246 'page' => 1, // The page to return if limiting per page 237 247 ); 238 248 … … 246 256 global $bp, $wpdb; 247 257 248 / * Truncate user blogs table and re-record. */258 // Truncate user blogs table and re-record. 249 259 $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" ); 250 260 … … 320 330 321 331 /** 322 * bp_blogs_update_option_blogname()323 *324 332 * Updates blogname in BuddyPress blogmeta table 325 333 * … … 330 338 function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) { 331 339 global $wpdb; 340 332 341 bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue ); 333 342 } … … 335 344 336 345 /** 337 * bp_blogs_update_option_blogdescription()338 *339 346 * Updates blogdescription in BuddyPress blogmeta table 340 347 * … … 345 352 function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) { 346 353 global $wpdb; 354 347 355 bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue ); 348 356 } … … 380 388 381 389 bp_blogs_record_activity( array( 382 'user_id' 390 'user_id' => (int)$post->post_author, 383 391 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ), 384 392 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ), … … 402 410 403 411 /** 404 * bp_blogs_record_comment()405 *406 412 * Record blog comment activity. Checks if blog is public and post is not 407 413 * password protected. … … 428 434 429 435 // Get the user_id from the comment author email. 430 $user = get_user_by_email( $recorded_comment->comment_author_email );436 $user = get_user_by_email( $recorded_comment->comment_author_email ); 431 437 $user_id = (int)$user->ID; 432 438 … … 436 442 437 443 // Get blog and post data 438 $blog_id = (int)$wpdb->blogid;444 $blog_id = (int)$wpdb->blogid; 439 445 $recorded_comment->post = get_post( $recorded_comment->comment_post_ID ); 440 446 … … 451 457 452 458 // Prepare to record in activity streams 453 if ( is_multisite() ) { 454 $activity_action = sprintf( __( '%1$s commented on the blog post %2$s on the blog %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 455 } else { 456 $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 457 } 459 if ( is_multisite() ) 460 $activity_action = sprintf( __( '%1$s commented on the blog post %2$s on the blog %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 461 else 462 $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 458 463 459 464 $activity_content = $recorded_comment->comment_content; … … 478 483 } 479 484 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 480 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );485 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 ); 481 486 482 487 function bp_blogs_manage_comment( $comment_id, $comment_status ) { … … 509 514 } 510 515 add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 ); 511 add_action( 'profile_update', 'bp_blogs_add_user_to_blog');512 add_action( 'user_register', 'bp_blogs_add_user_to_blog');516 add_action( 'profile_update', 'bp_blogs_add_user_to_blog' ); 517 add_action( 'user_register', 'bp_blogs_add_user_to_blog' ); 513 518 514 519 function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) { … … 605 610 global $bp; 606 611 607 / * If this is regular blog, delete all data for that blog. */612 // If this is regular blog, delete all data for that blog. 608 613 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 609 614 … … 643 648 644 649 645 // 646 // Blog meta functions 647 // These functions are used to store specific blogmeta in one global table, rather than in each 648 // blog's options table. Significantly speeds up global blog queries. 649 // By default each blog's name, description and last updated time are stored and synced here. 650 // 650 /******************************************************************************* 651 * Blog meta functions 652 * 653 * These functions are used to store specific blogmeta in one global table, 654 * rather than in each blog's options table. Significantly speeds up global blog 655 * queries. By default each blog's name, description and last updated time are 656 * stored and synced here. 657 */ 651 658 652 659 function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) { … … 663 670 $meta_value = trim( $meta_value ); 664 671 665 if ( !$meta_key ) {672 if ( !$meta_key ) 666 673 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) ); 667 } else if ( $meta_value ) {674 else if ( $meta_value ) 668 675 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) ); 669 } else {676 else 670 677 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) ); 671 }672 678 673 679 wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ); … … 723 729 $meta_value = maybe_serialize($meta_value); 724 730 725 if (empty( $meta_value)) {731 if (empty( $meta_value ) ) 726 732 return bp_blogs_delete_blogmeta( $blog_id, $meta_key ); 727 }728 733 729 734 $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) ); 730 735 731 if ( !$cur ) {736 if ( !$cur ) 732 737 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) ); 733 } else if ( $cur->meta_value != $meta_value ) {738 else if ( $cur->meta_value != $meta_value ) 734 739 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key ) ); 735 } else { 736 return false; 737 } 740 else 741 return false; 738 742 739 743 wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $meta_value, 'bp' ); … … 746 750 return false; 747 751 748 / * If this is regular blog, delete all data for that blog. */752 // If this is regular blog, delete all data for that blog. 749 753 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 750 754 751 755 do_action( 'bp_blogs_remove_data', $user_id ); 752 756 } 753 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );754 add_action( 'delete_user', 'bp_blogs_remove_data' );757 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 758 add_action( 'delete_user', 'bp_blogs_remove_data' ); 755 759 add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' ); 756 760 757 761 758 /******************************************************************************* *762 /******************************************************************************* 759 763 * Caching 760 764 * … … 775 779 // List actions to clear object caches on 776 780 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 777 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );781 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 ); 778 782 779 783 // List actions to clear super cached pages on, if super cache is installed 780 784 add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' ); 781 add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );782 add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );785 add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' ); 786 add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' ); 783 787 add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' ); 784 add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );785 add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );786 add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );787 add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );788 add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );788 add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' ); 789 add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' ); 790 add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' ); 791 add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' ); 792 add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' ); 789 793 790 794 ?>
Note: See TracChangeset
for help on using the changeset viewer.