Skip to:
Content

BuddyPress.org

Changeset 2842


Ignore:
Timestamp:
03/12/2010 01:03:42 PM (16 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

Location:
trunk
Files:
1 deleted
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2822 r2842  
    11<?php
    22
    3 define ( 'BP_ACTIVITY_DB_VERSION', '2060' );
     3define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
    44
    55/* Define the slug for the component */
     
    4545                                date_recorded datetime NOT NULL,
    4646                                hide_sitewide bool DEFAULT 0,
    47                                 mptt_left int(11) NOT NULL,
    48                                 mptt_right int(11) NOT NULL,
     47                                mptt_left int(11) NOT NULL DEFAULT 0,
     48                                mptt_right int(11) NOT NULL DEFAULT 0,
    4949                                KEY date_recorded (date_recorded),
    5050                                KEY user_id (user_id),
  • trunk/bp-blogs.php

    r2770 r2842  
    2626                                KEY user_id (user_id),
    2727                                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)
    5228                         ) {$charset_collate};";
    5329
     
    9470
    9571        $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';
    9872        $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
    9973        $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
     
    181155        do_action( 'bp_blogs_screen_my_blogs' );
    182156        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' ) );
    193157}
    194158
     
    331295}
    332296
    333 
    334297function bp_blogs_record_existing_blogs() {
    335298        global $bp, $wpdb;
     
    403366                $user_id = (int)$post->post_author;
    404367
    405         /* This is to stop infinate loops with Donncha's sitewide tags plugin */
     368        /* This is to stop infinite loops with Donncha's sitewide tags plugin */
    406369        if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    407370                return false;
     
    411374                return false;
    412375
    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" ) );
    463378
    464379                if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    465                         /* Now re-record the post in the activity streams */
     380                        /* Record this in activity streams */
    466381                        $post_permalink = get_permalink( $post_id );
    467382
     
    478393                                'secondary_item_id' => $post_id,
    479394                                'recorded_time' => $post->post_date_gmt
    480                         ) );
     395                        ));
    481396                }
    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 );
    485401}
    486402add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    487403
    488 function bp_blogs_record_comment( $comment_id, $is_approved ) {
     404function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    489405        global $wpdb, $bp;
    490 
    491         if ( !$is_approved )
    492                 return false;
    493406
    494407        $comment = get_comment($comment_id);
     
    505418        if ( !empty( $post->post_password ) )
    506419                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         }
    521420
    522421        if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
     
    542441}
    543442add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     443add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
    544444
    545445function bp_blogs_manage_comment( $comment_id, $comment_status ) {
     
    601501add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    602502
    603 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
     503function bp_blogs_remove_post( $post_id, $blog_id = false ) {
    604504        global $current_blog, $bp;
    605505
     
    609509                $blog_id = (int)$current_blog->blog_id;
    610510
    611         if ( !$existing_post )
    612                 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    613 
    614         // Delete post from the bp_blogs table
    615         BP_Blogs_Post::delete( $post_id, $blog_id );
    616 
    617511        // Delete activity stream item
    618512        bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    624518function bp_blogs_remove_comment( $comment_id ) {
    625519        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 );
    629520
    630521        // Delete activity stream item
     
    663554        /* If this is regular blog, delete all data for that blog. */
    664555        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 );
    667556
    668557        // Delete activity stream item
     
    677566}
    678567
    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 
    698568function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    699569        return BP_Blogs_Blog::get_all( $limit, $page );
     
    702572function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
    703573        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 );
    716574}
    717575
     
    832690
    833691function bp_blogs_remove_data( $user_id ) {
     692        if ( !bp_core_is_multisite() )
     693                return false;
     694
    834695        /* If this is regular blog, delete all data for that blog. */
    835696        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 );
    838697
    839698        do_action( 'bp_blogs_remove_data', $user_id );
     
    867726}
    868727
    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 
    891728// List actions to clear object caches on
    892729add_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 
    896730add_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 );
    899731
    900732// List actions to clear super cached pages on, if super cache is installed
  • trunk/bp-blogs/bp-blogs-classes.php

    r2784 r2842  
    279279                        return $paged_blogs;
    280280
    281                 /* Fetch lastest post for each blog. */
    282                 $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.blog_id IN ( {$blog_ids} ) GROUP BY p.blog_id ORDER BY p.date_created DESC" ) );
    283 
    284                 for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
    285                         foreach ( (array)$post_ids as $post ) {
    286                                 if ( $post->blog_id == $paged_blogs[$i]->blog_id ) {
    287                                         $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $post->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY id DESC LIMIT 1" );
    288                                 }
    289                         }
    290                 }
     281                for ( $i = 0; $i < count( $paged_blogs ); $i++ )
     282                        $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $paged_blogs[$i]->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
    291283
    292284                /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
     
    316308}
    317309
    318 /* DEPRECATED - Post DB recording is scheduled for removal. Please use the activity stream to fetch a user's posts. */
    319 Class BP_Blogs_Post {
    320         var $id;
    321         var $user_id;
    322         var $blog_id;
    323         var $post_id;
    324         var $date_created;
    325 
    326         function bp_blogs_post( $id = null, $blog_id = null, $post_id = null ) {
    327                 global $bp, $wpdb;
    328 
    329                 if ( $id || ( !$id && $blog_id && $post_id ) ) {
    330                         $this->id = $id;
    331                         $this->blog_id = $blog_id;
    332                         $this->post_id = $post_id;
    333                         $this->populate();
    334                 }
    335         }
    336 
    337         function populate() {
    338                 global $wpdb, $bp;
    339 
    340                 if ( $this->id )
    341                         $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE id = %d", $this->id ) );
    342                 else
    343                         $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $this->blog_id, $this->post_id ) );
    344 
    345                 $this->id = $post->id;
    346                 $this->user_id = $post->user_id;
    347                 $this->blog_id = $post->blog_id;
    348                 $this->post_id = $post->post_id;
    349                 $this->date_created = $post->date_created;
    350         }
    351 
    352         function save() {
    353                 global $wpdb, $bp;
    354 
    355                 $this->post_id = apply_filters( 'bp_blogs_post_id_before_save', $this->post_id, $this->id );
    356                 $this->blog_id = apply_filters( 'bp_blogs_post_blog_id_before_save', $this->blog_id, $this->id );
    357                 $this->user_id = apply_filters( 'bp_blogs_post_user_id_before_save', $this->user_id, $this->id );
    358                 $this->date_created = apply_filters( 'bp_blogs_post_date_created_before_save', $this->date_created, $this->id );
    359 
    360                 do_action( 'bp_blogs_post_before_save', $this );
    361 
    362                 if ( $this->id ) {
    363                         // Update
    364                         $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_posts} SET post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
    365                 } else {
    366                         // Save
    367                         $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_posts} ( post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, FROM_UNIXTIME(%d) )", $this->post_id, $this->blog_id, $this->user_id, $this->date_created );
    368                 }
    369 
    370                 if ( !$wpdb->query($sql) )
    371                         return false;
    372 
    373                 do_action( 'bp_blogs_post_after_save', $this );
    374 
    375                 if ( $this->id )
    376                         return $this->id;
    377                 else
    378                         return $wpdb->insert_id;
    379         }
    380 
    381         /* Static Functions */
    382 
    383         function delete( $post_id, $blog_id ) {
    384                 global $wpdb, $bp, $current_user;
    385 
    386                 if ( !$bp->blogs )
    387                         bp_blogs_setup_globals();
    388 
    389                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $blog_id, $post_id ) );
    390         }
    391 
    392         function delete_oldest( $user_id = null ) {
    393                 global $wpdb, $bp;
    394 
    395                 if ( !$bp->blogs )
    396                         bp_blogs_setup_globals();
    397 
    398                 if ( !$user_id )
    399                         $user_id = $current_user->ID;
    400 
    401                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
    402         }
    403 
    404         function delete_posts_for_user( $user_id = null ) {
    405                 global $wpdb, $bp;
    406 
    407                 if ( !$bp->blogs )
    408                         bp_blogs_setup_globals();
    409 
    410                 if ( !$user_id )
    411                         $user_id = $bp->loggedin_user->id;
    412 
    413                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
    414         }
    415 
    416         function delete_posts_for_blog( $blog_id ) {
    417                 global $wpdb, $bp;
    418 
    419                 if ( !$bp->blogs )
    420                         bp_blogs_setup_globals();
    421 
    422                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
    423         }
    424 
    425         function get_latest_posts( $blog_id = null, $limit = 5 ) {
    426                 global $wpdb, $bp;
    427 
    428                 if ( !$bp->blogs )
    429                         bp_blogs_setup_globals();
    430 
    431                 if ( $blog_id )
    432                         $blog_sql = $wpdb->prepare( " AND p.blog_id = %d", $blog_id );
    433 
    434                 $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );
    435 
    436                 for ( $i = 0; $i < count($post_ids); $i++ ) {
    437                         $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
    438                 }
    439 
    440                 return $posts;
    441         }
    442 
    443         function get_posts_for_user( $user_id = null ) {
    444                 global $bp, $wpdb;
    445 
    446                 if ( !$bp->blogs )
    447                         bp_blogs_setup_globals();
    448 
    449                 if ( !$user_id )
    450                         $user_id = $bp->displayed_user->id;
    451 
    452                 // Show a logged in user their posts on private blogs, but not anyone else.
    453                 if ( !bp_is_my_profile() ) {
    454                         $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
    455                         $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
    456                 } else {
    457                         $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
    458 
    459                         $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
    460                 }
    461 
    462                 for ( $i = 0; $i < count($post_ids); $i++ ) {
    463                         $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
    464                 }
    465 
    466                 return array( 'posts' => $posts, 'count' => $total_post_count );
    467         }
    468 
    469         function fetch_post_content( $post_object ) {
    470                 // TODO: switch_to_blog() calls are expensive and this needs to be changed.
    471                 switch_to_blog( $post_object->blog_id );
    472                 $post = get_post($post_object->post_id);
    473                 $post->blog_id = $post_object->blog_id;
    474                 restore_current_blog();
    475 
    476                 return $post;
    477         }
    478 
    479         function get_total_recorded_for_user( $user_id = null ) {
    480                 global $bp, $wpdb;
    481 
    482                 if ( !$bp->blogs )
    483                         bp_blogs_setup_globals();
    484 
    485                 if ( !$user_id )
    486                         $user_id = $current_user->ID;
    487 
    488                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
    489         }
    490 
    491         function is_recorded( $post_id, $blog_id, $user_id = null ) {
    492                 global $bp, $wpdb, $current_user;
    493 
    494                 if ( !$bp->blogs )
    495                         bp_blogs_setup_globals();
    496 
    497                 if ( !$user_id )
    498                         $user_id = $current_user->ID;
    499 
    500                 return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$bp->blogs->table_name_blog_posts} WHERE post_id = %d AND blog_id = %d AND user_id = %d", $post_id, $blog_id, $user_id ) );
    501         }
    502 
    503         function total_post_count( $blog_id ) {
    504                 global $bp, $wpdb;
    505 
    506                 if ( !$bp->blogs )
    507                         bp_blogs_setup_globals();
    508 
    509                 if ( !$blog_id )
    510                         return false;
    511 
    512                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
    513         }
    514 
    515         function get_all() {
    516                 global $bp, $wpdb;
    517 
    518                 if ( !$bp->blogs )
    519                         bp_blogs_setup_globals();
    520 
    521                 return $wpdb->get_col( $wpdb->prepare( "SELECT post_id, blog_id FROM " . $bp->blogs->table_name_blog_posts ) );
    522         }
    523 
    524 }
    525 
    526 /* DEPRECATED - Comment DB recording is scheduled for removal. Please use the activity stream to fetch a user's comments. */
    527 Class BP_Blogs_Comment {
    528         var $id;
    529         var $user_id;
    530         var $blog_id;
    531         var $comment_id;
    532         var $comment_post_id;
    533         var $date_created;
    534 
    535         function bp_blogs_comment( $id = false, $blog_id = false, $comment_id = false ) {
    536                 global $bp, $wpdb;
    537 
    538                 if ( !$user_id )
    539                         $user_id = $bp->displayed_user->id;
    540 
    541                 if ( $id || ( !$id && $blog_id && $comment_id ) ) {
    542                         $this->id = $id;
    543                         $this->blog_id = $blog_id;
    544                         $this->comment_id = $comment_id;
    545                         $this->populate();
    546                 }
    547         }
    548 
    549         function populate() {
    550                 global $wpdb, $bp;
    551 
    552                 if ( $this->id )
    553                         $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE id = %d", $this->id ) );
    554                 else
    555                         $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d AND comment_id = %d", (int)$this->blog_id, (int)$this->comment_id ) );
    556 
    557                 $this->comment_id = $comment->comment_id;
    558                 $this->user_id = $comment->user_id;
    559                 $this->blog_id = $comment->blog_id;
    560                 $this->comment_post_id = $comment->comment_post_id;
    561                 $this->date_created = $comment->date_created;
    562         }
    563 
    564         function save() {
    565                 global $wpdb, $bp;
    566 
    567                 $this->comment_id = apply_filters( 'bp_blogs_comment_id_before_save', $this->comment_id, $this->id );
    568                 $this->comment_post_id = apply_filters( 'bp_blogs_comment_post_id_before_save', $this->comment_post_id, $this->id );
    569                 $this->blog_id = apply_filters( 'bp_blogs_comment_blog_id_before_save', $this->blog_id, $this->id );
    570                 $this->user_id = apply_filters( 'bp_blogs_comment_user_id_before_save', $this->user_id, $this->id );
    571                 $this->date_created = apply_filters( 'bp_blogs_comment_date_created_before_save', $this->date_created, $this->id );
    572 
    573                 do_action( 'bp_blogs_comment_before_save', $this );
    574 
    575                 if ( $this->id ) {
    576                         // Update
    577                         $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_comments} SET comment_id = %d, comment_post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
    578                 } else {
    579                         // Save
    580                         $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_comments} ( comment_id, comment_post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created );
    581                 }
    582 
    583                 if ( !$wpdb->query($sql) )
    584                         return false;
    585 
    586                 do_action( 'bp_blogs_comment_after_save', $this );
    587 
    588                 if ( $this->id )
    589                         return $this->id;
    590                 else
    591                         return $wpdb->insert_id;
    592         }
    593 
    594         /* Static Functions */
    595 
    596         function delete( $comment_id, $blog_id ) {
    597                 global $wpdb, $bp, $current_user;
    598 
    599                 if ( !$bp->blogs )
    600                         bp_blogs_setup_globals();
    601 
    602                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d", $comment_id, $blog_id ) );
    603         }
    604 
    605         function delete_oldest( $user_id = null ) {
    606                 global $wpdb, $bp, $current_user;
    607 
    608                 if ( !$bp->blogs )
    609                         bp_blogs_setup_globals();
    610 
    611                 if ( !$user_id )
    612                         $user_id = $current_user->ID;
    613 
    614                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
    615         }
    616 
    617         function delete_comments_for_user( $user_id = null ) {
    618                 global $wpdb, $bp;
    619 
    620                 if ( !$bp->blogs )
    621                         bp_blogs_setup_globals();
    622 
    623                 if ( !$user_id )
    624                         $user_id = $bp->loggedin_user->id;
    625 
    626                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
    627         }
    628 
    629         function delete_comments_for_blog( $blog_id ) {
    630                 global $wpdb, $bp;
    631 
    632                 if ( !$bp->blogs )
    633                         bp_blogs_setup_globals();
    634 
    635                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) );
    636         }
    637 
    638         function get_comments_for_user( $user_id = null ) {
    639                 global $bp, $wpdb;
    640 
    641                 if ( !$bp->blogs )
    642                         bp_blogs_setup_globals();
    643 
    644                 if ( !$user_id )
    645                         $user_id = $bp->displayed_user->id;
    646 
    647                 // Show the logged in user their comments on hidden blogs, but not to anyone else.
    648                 if ( !bp_is_my_profile() ) {
    649                         $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
    650                         $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
    651                 } else {
    652                         $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
    653 
    654                         $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
    655                 }
    656 
    657                 for ( $i = 0; $i < count($comment_ids); $i++ )
    658                         $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]);
    659 
    660                 return array( 'comments' => $comments, 'count' => $total_comment_count );
    661         }
    662 
    663         function fetch_comment_content( $comment_object ) {
    664                 switch_to_blog($comment_object->blog_id);
    665                 $comment = get_comment($comment_object->comment_id);
    666                 $comment->blog_id = $comment_object->blog_id;
    667                 $comment->post = &get_post( $comment->comment_post_ID );
    668                 restore_current_blog();
    669 
    670                 return $comment;
    671         }
    672 
    673         function get_total_recorded_for_user( $user_id = null ) {
    674                 global $bp, $wpdb, $current_user;
    675 
    676                 if ( !$bp->blogs )
    677                         bp_blogs_setup_globals();
    678 
    679                 if ( !$user_id )
    680                         $user_id = $current_user->ID;
    681 
    682                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
    683         }
    684 
    685         function total_comment_count( $blog_id, $post_id ) {
    686                 global $bp, $wpdb;
    687 
    688                 if ( !$bp->blogs )
    689                         bp_blogs_setup_globals();
    690 
    691                 if ( $post_id )
    692                         $post_sql = $wpdb->prepare( " AND comment_post_id = %d", $post_id );
    693 
    694                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) WHERE blog_id = %d{$post_sql}", $blog_id ) );
    695         }
    696 
    697 
    698         function is_recorded( $comment_id, $comment_post_id, $blog_id, $user_id = null ) {
    699                 global $bp, $wpdb, $current_user;
    700 
    701                 if ( !$bp->blogs )
    702                         bp_blogs_setup_globals();
    703 
    704                 if ( !$user_id )
    705                         $user_id = $current_user->ID;
    706 
    707                 return $wpdb->get_var( $wpdb->prepare( "SELECT comment_id FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d AND comment_post_id = %d AND user_id = %d", $comment_id, $blog_id, $comment_post_id, $user_id ) );
    708         }
    709 
    710 }
    711 
    712310?>
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r2822 r2842  
    145145
    146146        $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
    147         return $blogs_template->has_blogs();
     147        return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
    148148}
    149149
  • trunk/bp-core.php

    r2822 r2842  
    3333require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
    3434require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
     35require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
    3536require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
    3637require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
     
    4041require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    4142require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
    42 
    43 /* Multisite includes built in account activation support. */
    44 if ( bp_core_is_multisite() )
    45         require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
    4643
    4744/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
     
    16641661        update_site_option( 'illegal_names', $new );
    16651662}
    1666 
    1667 /**
    1668  * bp_core_email_from_name_filter()
    1669  *
    1670  * Sets the "From" name in emails sent to the name of the site and not "WordPress"
    1671  *
    1672  * @package BuddyPress Core
    1673  * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
    1674  * @return The blog name for the root blog
    1675  */
    1676 function bp_core_email_from_name_filter() {
    1677         return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
    1678 }
    1679 add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
    1680 
    1681 
    1682 /**
    1683  * bp_core_email_from_name_filter()
    1684  *
    1685  * Sets the "From" address in emails sent
    1686  *
    1687  * @package BuddyPress Core
    1688  * @global $current_site Object containing current site metadata
    1689  * @return noreply@sitedomain email address
    1690  */
    1691 function bp_core_email_from_address_filter() {
    1692         $domain = (array) explode( '/', site_url() );
    1693 
    1694         return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
    1695 }
    1696 add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
    16971663
    16981664/**
     
    19721938
    19731939/**
    1974  * bp_core_filter_parent_theme()
    1975  *
    1976  * Remove social network parent theme from the theme list.
    1977  *
    1978  * @package BuddyPress Core
    1979  */
    1980 function bp_core_filter_parent_theme() {
    1981         global $wp_themes, $pagenow;
    1982 
    1983         if ( is_admin() && 'themes.php' == $pagenow )
    1984                 $wp_themes = get_themes();
    1985 
    1986         unset( $wp_themes['BuddyPress Classic Parent'] );
    1987 }
    1988 add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
    1989 
    1990 /**
    1991  * bp_core_allow_default_theme()
    1992  *
    1993  * On multiblog installations you must first allow themes to be activated and show
    1994  * up on the theme selection screen. This function will let the BuddyPress bundled
    1995  * themes show up on the root blog selection screen and bypass this step. It also
    1996  * means that the themes won't show for selection on other blogs.
    1997  *
    1998  * @package BuddyPress Core
    1999  */
    2000 function bp_core_allow_default_theme( $themes ) {
    2001         global $bp, $current_blog;
    2002 
    2003         if ( !is_site_admin() )
    2004                 return $themes;
    2005 
    2006         if ( $current_blog->ID == $bp->root_blog ) {
    2007                 $themes['bp-default'] = 1;
    2008                 $themes['bp-classic'] = 1;
    2009         }
    2010 
    2011         return $themes;
    2012 }
    2013 add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
    2014 
    2015 /**
    20161940 * bp_core_activation_notice()
    20171941 *
     
    20541978add_action( 'admin_notices', 'bp_core_activation_notice' );
    20551979
    2056 /**
    2057  * bp_core_filter_comments()
    2058  *
    2059  * Filter the blog post comments array and insert BuddyPress URLs for users.
    2060  *
    2061  * @package BuddyPress Core
    2062  */
    2063 function bp_core_filter_comments( $comments, $post_id ) {
    2064         global $wpdb;
    2065 
    2066         foreach( (array)$comments as $comment ) {
    2067                 if ( $comment->user_id )
    2068                         $user_ids[] = $comment->user_id;
    2069         }
    2070 
    2071         if ( empty( $user_ids ) )
    2072                 return $comments;
    2073 
    2074         $user_ids = implode( ',', $user_ids );
    2075 
    2076         if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
    2077                 return $comments;
    2078 
    2079         foreach( (array)$userdata as $user )
    2080                 $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
    2081 
    2082         foreach( (array)$comments as $i => $comment ) {
    2083                 if ( !empty( $comment->user_id ) ) {
    2084                         if ( !empty( $users[$comment->user_id] ) )
    2085                                 $comments[$i]->comment_author_url = $users[$comment->user_id];
    2086                 }
    2087         }
    2088 
    2089         return $comments;
    2090 }
    2091 add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
    2092 
    2093 /**
    2094  * bp_core_login_redirect()
    2095  *
    2096  * When a user logs in, always redirect them back to the previous page. NOT the admin area.
    2097  *
    2098  * @package BuddyPress Core
    2099  */
    2100 function bp_core_login_redirect( $redirect_to ) {
    2101         global $bp, $current_blog;
    2102 
    2103         if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
    2104                 return $redirect_to;
    2105 
    2106         if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
    2107                 return $redirect_to;
    2108 
    2109         if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
    2110                 return wp_get_referer();
    2111 
    2112         return $bp->root_domain;
    2113 }
    2114 add_filter( 'login_redirect', 'bp_core_login_redirect' );
    2115 
    2116 
    21171980/********************************************************************************
    21181981 * Custom Actions
  • trunk/bp-core/bp-core-cssjs.php

    r2723 r2842  
    4848        global $current_blog;
    4949
    50         if ( $current_blog->blog_id != BP_ROOT_BLOG )
     50        if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
    5151                return false;
    5252?>
  • trunk/bp-core/bp-core-signup.php

    r2822 r2842  
    11<?php
     2
     3/********************************************************************************
     4 * Screen Functions
     5 *
     6 * Screen functions are the controllers of BuddyPress. They will execute when their
     7 * specific URL is caught. They will first save or manipulate data using business
     8 * functions, then pass on the user to a template file.
     9 */
    210
    311function bp_core_screen_signup() {
     
    1119                bp_core_redirect( $bp->root_domain );
    1220
    13         /***
    14          * For backwards compatibility with the old pre 1.1 two theme system, skip this screen function
    15          * if the user is using the old two theme method.
    16          */
    17         if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
    18                 return false;
    19 
    2021        /* If signups are disabled, just re-direct */
    2122        if ( !bp_get_signup_allowed() )
     
    3334
    3435                /* Check the base account details for problems */
    35                 $account_details = wpmu_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
     36                $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
    3637
    3738                /* If there are errors with account details, set them for display */
     
    7475
    7576                        if ( 'blog' == $active_signup || 'all' == $active_signup ) {
    76                                 $blog_details = wpmu_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
     77                                $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
    7778
    7879                                /* If there are errors with blog details, set them for display */
     
    126127                                $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
    127128
    128                                 /* Finally, sign up the user and/or blog*/
     129                                /* Finally, sign up the user and/or blog */
    129130                                if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
    130                                         wpmu_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
     131                                        bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
    131132                                else {
    132133                                        bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
     
    159160                                $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
    160161                        }
    161                 } else
    162                         $bp->signup->avatar_dir = wp_hash( $bp->signup->username );
     162                } else {
     163                        $user_id = bp_core_get_userid( $_POST['signup_username'] );
     164                        $bp->signup->avatar_dir = wp_hash( $user_id );
     165                }
    163166
    164167                /* Pass the file to the avatar upload handler */
     
    185188                else
    186189                        bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
    187 
    188                 /* If this is a single WP install, move the avatar to the user's folder since there is no activation process to move it. */
    189                 if ( !bp_core_is_multisite() ) {
    190                         $user_id = bp_core_get_userid( $_POST['signup_username'] );
    191 
    192                         if ( !empty( $user_id ) && file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'] ) ) {
    193                                 @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'], BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id );
     190        }
     191        bp_core_load_template( 'registration/register' );
     192}
     193add_action( 'wp', 'bp_core_screen_signup', 3 );
     194
     195function bp_core_screen_activation() {
     196        global $bp, $wpdb;
     197
     198        if ( BP_ACTIVATION_SLUG != $bp->current_component )
     199                return false;
     200
     201        /* Check if an activation key has been passed */
     202        if ( isset( $_GET['key'] ) ) {
     203
     204                require_once( ABSPATH . WPINC . '/registration.php' );
     205
     206                /* Activate the signup */
     207                $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
     208
     209                /* If there was errors, add a message and redirect */
     210                if ( $user->errors ) {
     211                        bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
     212                        bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
     213                }
     214
     215                /* Check for an uploaded avatar and move that to the correct user folder */
     216                if ( bp_core_is_multisite() )
     217                        $hashed_key = wp_hash( $_GET['key'] );
     218                else
     219                        $hashed_key = wp_hash( $user );
     220
     221                /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
     222                if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
     223                        @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
     224
     225                bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
     226
     227                $bp->activation_complete = true;
     228        }
     229
     230        if ( '' != locate_template( array( 'registration/activate' ), false ) )
     231                bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
     232        else
     233                bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
     234}
     235add_action( 'wp', 'bp_core_screen_activation', 3 );
     236
     237
     238/********************************************************************************
     239 * Business Functions
     240 *
     241 * Business functions are where all the magic happens in BuddyPress. They will
     242 * handle the actual saving or manipulation of information. Usually they will
     243 * hand off to a database class for data access, then return
     244 * true or false on success or failure.
     245 */
     246
     247function bp_core_validate_user_signup( $user_name, $user_email ) {
     248        global $wpdb;
     249
     250        $errors = new WP_Error();
     251        $user_email = sanitize_email( $user_email );
     252
     253        if ( empty( $user_name ) )
     254                $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
     255
     256        $maybe = array();
     257        preg_match( "/[a-z0-9]+/", $user_name, $maybe );
     258
     259        $db_illegal_names = get_site_option( 'illegal_names' );
     260        $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
     261
     262        $illegal_names = array_merge( (array)$db_illegal_names, (array)$filtered_illegal_names );
     263        update_site_option( 'illegal_names', $illegal_names );
     264
     265        if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
     266            $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
     267
     268        if( strlen( $user_name ) < 4 )
     269            $errors->add( 'user_name',  __( 'Username must be at least 4 characters', 'buddypress' ) );
     270
     271        if ( strpos( ' ' . $user_name, '_' ) != false )
     272                $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
     273
     274        /* Is the user_name all numeric? */
     275        $match = array();
     276        preg_match( '/[0-9]*/', $user_name, $match );
     277
     278        if ( $match[0] == $user_name )
     279                $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
     280
     281        if ( !is_email( $user_email ) )
     282                $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
     283
     284        $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
     285
     286        if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     287                $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
     288
     289                if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
     290                        $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
     291        }
     292
     293        /* Check if the username has been used already. */
     294        if ( username_exists( $user_name ) )
     295                $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
     296
     297        /* Check if the email address has been used already. */
     298        if ( email_exists( $user_email ) )
     299                $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
     300
     301        $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
     302
     303        /* Apply WPMU legacy filter */
     304        $result = apply_filters( 'wpmu_validate_user_signup', $result );
     305
     306        return apply_filters( 'bp_core_validate_user_signup', $result );
     307}
     308
     309function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
     310        if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
     311                return false;
     312
     313        return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
     314}
     315
     316function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
     317        global $bp, $wpdb;
     318
     319        /* Multisite installs have their own install procedure */
     320        if ( bp_core_is_multisite() ) {
     321                wpmu_signup_user( $user_login, $user_email, $usermeta );
     322
     323        } else {
     324                $errors = new WP_Error();
     325
     326                $user_id = wp_insert_user( array(
     327                        'user_login' => $user_login,
     328                        'user_pass' => $user_password,
     329                        'display_name' => sanitize_title( $user_login ),
     330                        'user_email' => $user_email
     331                ) );
     332
     333                if ( !$user_id ) {
     334                        $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
     335                        return $errors;
     336                }
     337
     338                /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
     339                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
     340
     341                /* Set any profile data */
     342                if ( function_exists( 'xprofile_set_field_data' ) ) {
     343                        if ( !empty( $usermeta['profile_field_ids'] ) ) {
     344                                $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
     345
     346                                foreach( (array)$profile_field_ids as $field_id ) {
     347                                        $current_field = $usermeta["field_{$field_id}"];
     348
     349                                        if ( !empty( $current_field ) )
     350                                                xprofile_set_field_data( $field_id, $user_id, $current_field );
     351                                }
    194352                        }
    195353                }
    196354        }
    197         bp_core_load_template( 'registration/register' );
    198 }
    199 add_action( 'wp', 'bp_core_screen_signup', 3 );
    200 
    201 function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
    202         global $bp;
    203 
    204         if ( bp_core_is_multisite() )
    205                 return wpmu_signup_user( $user_login, $user_email, $usermeta );
    206 
    207         $errors = new WP_Error();
    208 
    209         $user_id = wp_create_user( $user_login, $user_password, $user_email );
    210         if ( !$user_id ) {
    211                 $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
    212                 return $errors;
    213         }
    214 
    215         /* Set any profile data */
    216         if ( function_exists( 'xprofile_set_field_data' ) ) {
    217                 if ( !empty( $usermeta['profile_field_ids'] ) ) {
    218                         $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
    219 
    220                         foreach( (array)$profile_field_ids as $field_id ) {
    221                                 $current_field = $usermeta["field_{$field_id}"];
    222 
    223                                 if ( !empty( $current_field ) )
    224                                         xprofile_set_field_data( $field_id, $user_id, $current_field );
     355        $bp->signup->username = $user_login;
     356
     357        /***
     358         * Now generate an activation key and send an email to the user so they can activate their account
     359         * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
     360         */
     361        if ( !bp_core_is_multisite() ) {
     362                $activation_key = wp_hash( $user_id );
     363                update_usermeta( $user_id, 'activation_key', $activation_key );
     364                bp_core_signup_send_validation_email( $user_id, $activation_key );
     365        }
     366
     367        do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
     368
     369        return $user_id;
     370}
     371
     372function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
     373        if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
     374                return false;
     375
     376        return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
     377}
     378
     379function bp_core_activate_signup( $key ) {
     380        global $wpdb;
     381
     382        $user = false;
     383
     384        /* Multisite installs have their own activation routine */
     385        if ( bp_core_is_multisite() ) {
     386                $user = wpmu_activate_signup( $key );
     387
     388                /* If there was errors, add a message and redirect */
     389                if ( $user->errors ) {
     390                        bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
     391                        bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
     392                }
     393
     394                $user_id = $user['user_id'];
     395
     396                /* Set any profile data */
     397                if ( function_exists( 'xprofile_set_field_data' ) ) {
     398                        if ( !empty( $user['meta']['profile_field_ids'] ) ) {
     399                                $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
     400
     401                                foreach( (array)$profile_field_ids as $field_id ) {
     402                                        $current_field = $user['meta']["field_{$field_id}"];
     403
     404                                        if ( !empty( $current_field ) )
     405                                                xprofile_set_field_data( $field_id, $user_id, $current_field );
     406                                }
    225407                        }
    226408                }
    227         }
     409
     410        } else {
     411                /* Get the user_id based on the $key */
     412                $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
     413
     414                if ( empty( $user_id ) )
     415                        return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     416
     417                /* Change the user's status so they become active */
     418                if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
     419                        return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     420
     421                /* Notify the site admin of a new user registration */
     422                wp_new_user_notification( $user_id );
     423
     424                /* Remove the activation key meta */
     425                delete_usermeta( $user_id, 'activation_key' );
     426        }
     427
     428        /* Update the user_url and display_name */
     429        wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
    228430
    229431        /* Add a last active entry */
    230432        update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    231433
    232         wp_new_user_notification( $user_id, $user_pass );
     434        /* Set the password on multisite installs */
     435        if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
     436                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
     437
     438        /* Delete the total member cache */
    233439        wp_cache_delete( 'bp_total_member_count', 'bp' );
    234440
    235         $bp->signup->username = $user_login;
    236 
    237         do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
     441        do_action( 'bp_core_activated_user', $user_id, $key, $user );
    238442
    239443        return $user_id;
    240444}
     445
     446function bp_core_new_user_activity( $user ) {
     447        if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
     448                return false;
     449
     450        if ( is_array( $user ) )
     451                $user_id = $user['user_id'];
     452        else
     453                $user_id = $user;
     454
     455        if ( empty( $user_id ) )
     456                return false;
     457
     458        $userlink = bp_core_get_userlink( $user_id );
     459
     460        bp_activity_add( array(
     461                'user_id' => $user_id,
     462                'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
     463                'component' => 'profile',
     464                'type' => 'new_member'
     465        ) );
     466}
     467add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
    241468
    242469function bp_core_map_user_registration( $user_id ) {
     
    281508}
    282509
     510function bp_core_signup_send_validation_email( $user_id, $key ) {
     511        $activate_url = bp_get_activation_page() ."?key=$key";
     512        $activate_url = clean_url( $activate_url );
     513        $admin_email = get_site_option( "admin_email" );
     514
     515        if ( empty( $admin_email ) )
     516                $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
     517
     518        $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
     519        $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
     520        $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
     521        $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
     522
     523        /* Send the message */
     524        $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
     525        $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
     526        $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
     527
     528        wp_mail( $to, $subject, $message, $message_headers );
     529}
     530
     531/* Stop user accounts logging in that have not been activated (user_status = 2) */
     532function bp_core_signup_disable_inactive( $auth_obj, $username ) {
     533        global $bp, $wpdb;
     534
     535        if ( !$user_id = bp_core_get_userid( $username ) )
     536                return $auth_obj;
     537
     538        $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
     539
     540        if ( 2 == $user_status )
     541                bp_core_redirect( $bp->root_domain );
     542        else
     543                return $auth_obj;
     544}
     545add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
     546
    283547/* Kill the wp-signup.php if custom registration signup templates are present */
    284548function bp_core_wpsignup_redirect() {
  • trunk/bp-core/bp-core-templatetags.php

    r2822 r2842  
    310310
    311311                // Populate the user if it hasn't been already.
    312                 if ( empty( $members_template->member->profile_data ) )
    313                         $members_template->member = new BP_Core_User( $members_template->member->id );
     312                if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
     313                        $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
    314314
    315315                $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
     
    917917        } else if ( bp_is_activation_page() ) {
    918918                $title = __( 'Activate your Account', 'buddypress' );
     919
     920        } else if ( bp_is_group_create() ) {
     921                $title = __( 'Create a Group', 'buddypress' );
     922
     923        } else if ( bp_is_create_blog() ) {
     924                $title = __( 'Create a Blog', 'buddypress' );
    919925        }
    920926
     
    11841190                extract( $r, EXTR_SKIP );
    11851191
    1186                 if ( !bp_core_is_multisite() && !empty( $_POST['signup_username'] ) ) {
    1187                         $user_id = bp_core_get_userid( $_POST['signup_username'] );
    1188                         return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
     1192                $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
     1193
     1194                if ( empty( $signup_avatar_dir ) ) {
     1195                        if ( empty( $bp->grav_default->user ) ) {
     1196                                $default_grav = 'wavatar';
     1197                        } else if ( 'mystery' == $bp->grav_default->user ) {
     1198                                $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
     1199                        } else {
     1200                                $default_grav = $bp->grav_default->user;
     1201                        }
     1202
     1203                        $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
     1204                        return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    11891205                } else {
    1190                         $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
    1191 
    1192                         if ( empty( $signup_avatar_dir ) ) {
    1193                                 if ( empty( $bp->grav_default->user ) ) {
    1194                                         $default_grav = 'wavatar';
    1195                                 } else if ( 'mystery' == $bp->grav_default->user ) {
    1196                                         $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
    1197                                 } else {
    1198                                         $default_grav = $bp->grav_default->user;
    1199                                 }
    1200 
    1201                                 $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
    1202                                 return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    1203                         } else {
    1204                                 return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
    1205                         }
     1206                        return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
    12061207                }
    12071208        }
     
    12461247
    12471248function bp_registration_needs_activation() {
    1248         return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite() );
     1249        return apply_filters( 'bp_registration_needs_activation', true );
    12491250}
    12501251
  • trunk/bp-core/bp-core-wpabstraction.php

    r2761 r2842  
    9090        }
    9191}
    92 
    93 if ( !function_exists( 'wpmu_validate_user_signup' ) ) {
    94         function wpmu_validate_user_signup( $user_name, $user_email ) {
    95                 global $wpdb;
    96 
    97                 $errors = new WP_Error();
    98 
    99                 $user_email = sanitize_email( $user_email );
    100 
    101                 if ( empty( $user_name ) )
    102                         $errors->add('user_name', __("Please enter a username"));
    103 
    104                 $maybe = array();
    105                 preg_match( "/[a-z0-9]+/", $user_name, $maybe );
    106 
    107                 $illegal_names = get_site_option( "illegal_names" );
    108                 if( is_array( $illegal_names ) == false ) {
    109                         $illegal_names = array(  "www", "web", "root", "admin", "main", "invite", "administrator" );
    110                         add_site_option( "illegal_names", $illegal_names );
    111                 }
    112 
    113                 if ( !validate_username( $user_name ) || in_array( $user_name, $illegal_names ) == true || $user_name != $maybe[0] ) {
    114                     $errors->add('user_name', __("Only lowercase letters and numbers allowed"));
    115                 }
    116 
    117                 if( strlen( $user_name ) < 4 ) {
    118                     $errors->add('user_name',  __("Username must be at least 4 characters"));
    119                 }
    120 
    121                 if ( strpos( " " . $user_name, "_" ) != false )
    122                         $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));
    123 
    124                 // all numeric?
    125                 $match = array();
    126                 preg_match( '/[0-9]*/', $user_name, $match );
    127                 if ( $match[0] == $user_name )
    128                         $errors->add('user_name', __("Sorry, usernames must have letters too!"));
    129 
    130                 if ( !is_email( $user_email ) )
    131                         $errors->add('user_email', __("Please check your email address."));
    132 
    133                 $limited_email_domains = get_site_option( 'limited_email_domains' );
    134                 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
    135                         $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
    136                         if( in_array( $emaildomain, $limited_email_domains ) == false ) {
    137                                 $errors->add('user_email', __("Sorry, that email address is not allowed!"));
    138                         }
    139                 }
    140 
    141                 // Check if the username has been used already.
    142                 if ( username_exists($user_name) )
    143                         $errors->add('user_name', __("Sorry, that username already exists!"));
    144 
    145                 // Check if the email address has been used already.
    146                 if ( email_exists($user_email) )
    147                         $errors->add('user_email', __("Sorry, that email address is already used!"));
    148 
    149                 $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
    150 
    151                 return apply_filters('wpmu_validate_user_signup', $result);
    152         }
    153 }
  • trunk/bp-forums/bp-forums-templatetags.php

    r2761 r2842  
    290290                global $forum_template;
    291291
    292                 if ( !$name = bp_core_get_userlink( $forum_template->topic->poster_id ) )
     292                $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
     293
     294                if ( !$name = bp_core_get_userlink( $poster_id ) )
    293295                        return __( 'Deleted User', 'buddypress' );
    294296
  • trunk/bp-groups.php

    r2822 r2842  
    868868
    869869        if ( $bp->current_component == $bp->groups->slug && 'membership-requests' == $bp->action_variables[0] ) {
     870
     871                /* Ask for a login if the user is coming here via an email notification */
     872                if ( !is_user_logged_in() )
     873                        bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) );
    870874
    871875                if ( !$bp->is_item_admin || 'public' == $bp->groups->current_group->status )
     
    18971901        groups_update_groupmeta( $group_id, 'forum_id', $forum_id );
    18981902
    1899         do_action( 'groups_new_group_forum', $forum, $group_id );
     1903        do_action( 'groups_new_group_forum', $forum_id, $group_id );
    19001904}
    19011905
  • trunk/bp-loader.php

    r2784 r2842  
    55Description: Social networking in a box. Build a social network for your company, school, sports team or niche community all based on the power and flexibility of WordPress.
    66Author: The BuddyPress Community
    7 Version: 1.2.1
     7Version: 1.2.2
    88Author URI: http://buddypress.org/developers/
    99Site Wide Only: true
    1010*/
    1111
    12 define( 'BP_VERSION', '1.2.1' );
     12define( 'BP_VERSION', '1.2.2' );
    1313
    1414/***
    15  * This file will load in each BuddyPress component based on which
    16  * of the components have been activated on the "BuddyPress" admin menu.
     15 * Check if this is the first time BuddyPress has been loaded, or the first time
     16 * since an upgrade. If so, load the install/upgrade routine only.
    1717 */
     18if ( get_site_option( 'bp-db-version' ) < 1210 ) {
     19        require_once( WP_PLUGIN_DIR . '/buddypress/bp-core/bp-core-upgrade.php' );
    1820
    19 require_once( WP_PLUGIN_DIR . '/buddypress/bp-core.php' );
    20 $bp_deactivated = apply_filters( 'bp_deactivated_components', get_site_option( 'bp-deactivated-components' ) );
     21/***
     22 * If the install or upgrade routine is completed and everything is up to date
     23 * continue loading BuddyPress as normal.
     24 */
     25} else {
     26        /***
     27         * This file will load in each BuddyPress component based on which
     28         * of the components have been activated on the "BuddyPress" admin menu.
     29         */
     30        require_once( WP_PLUGIN_DIR . '/buddypress/bp-core.php' );
     31        $bp_deactivated = apply_filters( 'bp_deactivated_components', get_site_option( 'bp-deactivated-components' ) );
    2132
    22 do_action( 'bp_core_loaded' );
     33        do_action( 'bp_core_loaded' );
    2334
    24 /* Activity Streams */
    25 if ( !isset( $bp_deactivated['bp-activity.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-activity.php') )
    26         include( BP_PLUGIN_DIR . '/bp-activity.php' );
     35        /* Activity Streams */
     36        if ( !isset( $bp_deactivated['bp-activity.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-activity.php') )
     37                include( BP_PLUGIN_DIR . '/bp-activity.php' );
    2738
    28 /* Blog Tracking */
    29 if ( !isset( $bp_deactivated['bp-blogs.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-blogs.php') )
    30         include( BP_PLUGIN_DIR . '/bp-blogs.php' );
     39        /* Blog Tracking */
     40        if ( !isset( $bp_deactivated['bp-blogs.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-blogs.php') )
     41                include( BP_PLUGIN_DIR . '/bp-blogs.php' );
    3142
    32 /* bbPress Forum Integration */
    33 if ( !isset( $bp_deactivated['bp-forums.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-forums.php') )
    34         include( BP_PLUGIN_DIR . '/bp-forums.php' );
     43        /* bbPress Forum Integration */
     44        if ( !isset( $bp_deactivated['bp-forums.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-forums.php') )
     45                include( BP_PLUGIN_DIR . '/bp-forums.php' );
    3546
    36 /* Friend Connections */
    37 if ( !isset( $bp_deactivated['bp-friends.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-friends.php') )
    38         include( BP_PLUGIN_DIR . '/bp-friends.php' );
     47        /* Friend Connections */
     48        if ( !isset( $bp_deactivated['bp-friends.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-friends.php') )
     49                include( BP_PLUGIN_DIR . '/bp-friends.php' );
    3950
    40 /* Groups Support */
    41 if ( !isset( $bp_deactivated['bp-groups.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-groups.php') )
    42         include( BP_PLUGIN_DIR . '/bp-groups.php' );
     51        /* Groups Support */
     52        if ( !isset( $bp_deactivated['bp-groups.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-groups.php') )
     53                include( BP_PLUGIN_DIR . '/bp-groups.php' );
    4354
    44 /* Private Messaging */
    45 if ( !isset( $bp_deactivated['bp-messages.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-messages.php') )
    46         include( BP_PLUGIN_DIR . '/bp-messages.php' );
     55        /* Private Messaging */
     56        if ( !isset( $bp_deactivated['bp-messages.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-messages.php') )
     57                include( BP_PLUGIN_DIR . '/bp-messages.php' );
    4758
    48 /* Extended Profiles */
    49 if ( !isset( $bp_deactivated['bp-xprofile.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') )
    50         include( BP_PLUGIN_DIR . '/bp-xprofile.php' );
     59        /* Extended Profiles */
     60        if ( !isset( $bp_deactivated['bp-xprofile.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') )
     61                include( BP_PLUGIN_DIR . '/bp-xprofile.php' );
    5162
    52 /* Allow dependent plugins to hook into BuddyPress in a safe way */
    53 function bp_loaded() {
    54         do_action( 'bp_init' );
     63        /* Allow dependent plugins to hook into BuddyPress in a safe way */
     64        function bp_loaded() {
     65                do_action( 'bp_init' );
     66        }
     67        add_action( 'plugins_loaded', 'bp_loaded' );
    5568}
    56 add_action( 'plugins_loaded', 'bp_loaded' );
    5769
    5870/* Activation Function */
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r2720 r2842  
    803803                }
    804804
     805        form.standard-form a.clear-value {
     806                display: block;
     807                margin-top: 5px;
     808                outline: none;
     809        }
     810
    805811form.standard-form #basic-details-section, form.standard-form #blog-details-section,
    806812form.standard-form #profile-details-section {
  • trunk/bp-themes/bp-default/_inc/global.js

    r2727 r2842  
    12261226        var container = document.getElementById(container);
    12271227
    1228         radioButtons = container.getElementsByTagName('INPUT');
    1229 
    1230         for(var i=0; i<radioButtons.length; i++) {
    1231                 radioButtons[i].checked = '';
     1228        if ( radioButtons = container.getElementsByTagName('INPUT') ) {
     1229                for(var i=0; i<radioButtons.length; i++) {
     1230                        radioButtons[i].checked = '';
     1231                }
     1232        }
     1233
     1234        if ( options = container.getElementsByTagName('OPTION') ) {
     1235                for(var i=0; i<options.length; i++) {
     1236                        options[i].selected = false;
     1237                }
    12321238        }
    12331239
  • trunk/bp-themes/bp-default/functions.php

    r2761 r2842  
    7272/* Filter the dropdown for selecting the page to show on front to include "Activity Stream" */
    7373function bp_dtheme_wp_pages_filter( $page_html ) {
     74        if ( !bp_is_active( 'activity' ) )
     75                return $page_html;
     76
    7477        if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
    7578                return $page_html;
  • trunk/bp-themes/bp-default/members/single/profile/edit.php

    r2558 r2842  
    4848                                                <?php bp_the_profile_field_options() ?>
    4949                                        </select>
     50
     51                                        <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
     52                                                <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a>
     53                                        <?php endif; ?>
    5054
    5155                                <?php endif; ?>
  • trunk/bp-themes/bp-default/style.css

    r2784 r2842  
    33Theme URI: http://buddypress.org/extend/themes/
    44Description: The default theme for BuddyPress.
    5 Version: 1.2.1
     5Version: 1.2.2
    66Author: BuddyPress.org
    77Author URI: http://buddypress.org
  • trunk/bp-xprofile.php

    r2822 r2842  
    324324                }
    325325
    326                 if ( $errors )
     326                if ( !empty( $errors ) )
    327327                        bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
    328328                else {
     
    338338                        }
    339339
    340                         do_action( 'xprofile_updated_profile', $posted_field_ids, $errors );
     340                        do_action( 'xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors );
    341341
    342342                        /* Set the feedback messages */
     
    731731                return false;
    732732
     733        /* If the value is empty, then delete any field data that exists */
     734        if ( empty( $value ) ) {
     735                xprofile_delete_field_data( $field_id, $user_id );
     736                return true;
     737        }
     738
    733739        $field = new BP_XProfile_Field( $field_id );
    734740
     
    776782                $field_id = xprofile_get_field_id_from_name( $field );
    777783
    778         if ( !$field_id )
    779                 return false;
    780 
    781         $field = new BP_XProfile_ProfileData( $field_id );
     784        if ( empty( $field_id ) || empty( $user_id ) )
     785                return false;
     786
     787        $field = new BP_XProfile_ProfileData( $field_id, $user_id );
    782788        return $field->delete();
    783789}
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r2810 r2842  
    343343                global $field;
    344344
    345                 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id );
     345                $array_box = false;
     346                if ( 'multiselectbox' == $field->type )
     347                        $array_box = '[]';
     348
     349                return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id . $array_box );
    346350        }
    347351
     
    370374                                        $html .= '<option value="">--------</option>';
    371375
    372                                 for ( $k = 0; $k < count( $options ); $k++ ) {
    373                                         $option_value = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );
     376                                for ( $k = 0; $k < count($options); $k++ ) {
     377                                        $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ) );
     378                                        $option_values = (array)$option_values;
    374379
    375380                                        /* Check for updated posted values, but errors preventing them from being saved first time */
    376                                         if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
    377                                                 if ( !empty( $_POST['field_' . $field->id] ) )
    378                                                         $option_value = $_POST['field_' . $field->id];
     381                                        foreach( (array)$option_values as $i => $option_value ) {
     382                                                if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
     383                                                        if ( !empty( $_POST['field_' . $field->id] ) )
     384                                                                $option_values[$i] = $_POST['field_' . $field->id];
     385                                                }
    379386                                        }
    380387
    381                                         if ( $option_value == $options[$k]->name || $options[$k]->is_default_option )
     388                                        if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option )
    382389                                                $selected = ' selected="selected"';
    383390                                        else
     
    649656
    650657                /* admin/profile/edit/[group-id] */
    651                 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); 
     658                return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id );
    652659        }
    653660
  • trunk/readme.txt

    r2784 r2842  
    33Tags: buddypress, social networking, activity, profiles, messaging, friends, groups, forums, microblogging, twitter, facebook, mingle, social, community, networks, networking, cms
    44Requires at least: WordPress 2.9.1
    5 Tested up to: WordPress 2.9.1
    6 Stable tag: 1.2.1
     5Tested up to: WordPress 2.9.2
     6Stable tag: 1.2.2
    77
    88== Description ==
Note: See TracChangeset for help on using the changeset viewer.