Skip to:
Content

BuddyPress.org

Changeset 3232


Ignore:
Timestamp:
09/06/2010 04:24:57 PM (14 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

Location:
trunk
Files:
41 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r2951 r3232  
    3535            $this->component = $row->component;
    3636            $this->type = $row->type;
    37             $this->action = $row->action;
     37            $this->action = $row->type;
    3838            $this->content = $row->content;
    3939            $this->date_recorded = $row->date_recorded;
  • trunk/bp-activity/bp-activity-notifications.php

    r2941 r3232  
    1313
    1414    foreach( (array)$usernames as $username ) {
    15         if ( !$receiver_user_id = bp_core_get_userid( $username ) )
     15        if ( !$receiver_user_id = bp_core_get_userid($username) )
    1616            continue;
    1717
  • trunk/bp-activity/bp-activity-templatetags.php

    r2944 r3232  
    275275        $total = bp_core_number_format( $activities_template->total_activity_count );
    276276
    277         return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' &nbsp; <span class="ajax-loader"></span>';
     277        return sprintf( __( 'Viewing item %s to %s (of %s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' &nbsp; <span class="ajax-loader"></span>';
    278278    }
    279279
  • trunk/bp-blogs.php

    r2946 r3232  
    1010    global $bp, $wpdb;
    1111
    12     if ( !defined( 'BP_BLOGS_SLUG' ) )
    13         define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );
    14 
    1512    /* For internal identification */
    1613    $bp->blogs->id = 'blogs';
    17     $bp->blogs->name = $bp->pages->blogs->name;
     14
    1815    $bp->blogs->slug = BP_BLOGS_SLUG;
    1916
    20     $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
    21     $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
     17    $bp->blogs->table_name          = $bp->table_prefix . 'bp_user_blogs';
     18    $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta';
     19
    2220    $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
    2321
     
    9795    do_action( 'bp_blogs_screen_my_blogs' );
    9896    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
     97}
     98
     99function bp_blogs_screen_recent_posts() {
     100    do_action( 'bp_blogs_screen_recent_posts' );
     101    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
     102}
     103
     104function bp_blogs_screen_recent_comments() {
     105    do_action( 'bp_blogs_screen_recent_comments' );
     106    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
    99107}
    100108
     
    237245}
    238246
     247
    239248function bp_blogs_record_existing_blogs() {
    240249    global $bp, $wpdb;
     
    308317        $user_id = (int)$post->post_author;
    309318
    310     /* This is to stop infinite loops with Donncha's sitewide tags plugin */
     319    /* This is to stop infinate loops with Donncha's sitewide tags plugin */
    311320    if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    312321        return false;
     
    316325        return false;
    317326
    318     if ( 'publish' == $post->post_status && '' == $post->post_password ) {
     327    if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
     328        if ( 'publish' == $post->post_status && '' == $post->post_password ) {
     329
     330            /* If we're on a multiblog install, record this post */
     331            if ( bp_core_is_multisite() ) {
     332                $recorded_post = new BP_Blogs_Post;
     333                $recorded_post->user_id = $user_id;
     334                $recorded_post->blog_id = $blog_id;
     335                $recorded_post->post_id = $post_id;
     336                $recorded_post->date_created = strtotime( $post->post_date );
     337
     338                $recorded_post_id = $recorded_post->save();
     339
     340                bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     341            }
     342
     343            if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
     344                /* Record this in activity streams */
     345                $post_permalink = get_permalink( $post_id );
     346
     347                $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     348                $activity_content = $post->post_content;
     349
     350                bp_blogs_record_activity( array(
     351                    'user_id' => (int)$post->post_author,
     352                    'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
     353                    'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
     354                    'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
     355                    'type' => 'new_blog_post',
     356                    'item_id' => $blog_id,
     357                    'secondary_item_id' => $post_id,
     358                    'recorded_time' => $post->post_date_gmt
     359                ));
     360            }
     361        }
     362    } else {
     363        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
     364
     365        /* Delete the recorded post if the status is not published or it is password protected */
     366        if ( 'publish' != $post->post_status || '' != $post->post_password ) {
     367            return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
     368
     369        /* If the post author has changed, delete the post and re-add it. */
     370        } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
     371            // Delete the existing recorded post
     372            bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
     373
     374            // Re-record the post with the new author.
     375            bp_blogs_record_post( $post_id );
     376        }
     377
    319378        bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    320379
    321380        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    322             /* Record this in activity streams */
     381            /* Now re-record the post in the activity streams */
    323382            $post_permalink = get_permalink( $post_id );
    324383
     
    335394                'secondary_item_id' => $post_id,
    336395                'recorded_time' => $post->post_date_gmt
    337             ));
     396            ) );
    338397        }
    339     } else
    340         bp_blogs_remove_post( $post_id, $blog_id );
     398    }
    341399
    342400    bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    343401
    344     do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
     402    do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
    345403}
    346404add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
     
    349407    global $wpdb, $bp;
    350408
    351     $comment = get_comment($comment_id);
    352 
    353     if ( !$is_approved )
    354         return false;
    355 
    356     $comment->post = get_post( $comment->comment_post_ID );
    357 
    358     /* Get the user_id from the author email. */
    359     $user = get_user_by_email( $comment->comment_author_email );
     409    // Get the users comment
     410    $recorded_comment = get_comment( $comment_id );
     411
     412    // Don't record activity if the comment hasn't been approved
     413    if ( !$is_approved || !$recorded_comment->comment_approved )
     414        return false;
     415
     416    // Don't record activity if no email address has been included
     417    if ( empty( $recorded_comment->comment_author_email ) )
     418        return false;
     419
     420    // Get the user_id from the comment author email.
     421    $user = get_user_by_email( $recorded_comment->comment_author_email );
    360422    $user_id = (int)$user->ID;
    361423
    362     if ( !$user_id )
    363         return false;
    364 
    365     /* If this is a password protected post, don't record the comment */
    366     if ( !empty( $post->post_password ) )
    367         return false;
    368 
    369     if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    370         /* Record in activity streams */
    371         $comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
    372         $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    373         $activity_content = $comment->comment_content;
    374 
    375         /* Record this in activity streams */
     424    // If there's no registered user id, don't record activity
     425    if ( empty( $user_id ) )
     426        return false;
     427
     428    // Get blog and post data
     429    $blog_id = (int)$wpdb->blogid;
     430    $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
     431
     432    // If this is a password protected post, don't record the comment
     433    if ( !empty( $recorded_comment->post->post_password ) )
     434        return false;
     435
     436    // If blog is public allow activity to be posted
     437    if ( get_blog_option( $blog_id, 'blog_public' ) ) {
     438        // Get activity related links
     439        $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
     440        $comment_link   = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
     441
     442        // Prepare to record in activity streams
     443        $activity_action        = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     444        $activity_content       = $recorded_comment->comment_content;
     445
     446        // Record in activity streams
    376447        bp_blogs_record_activity( array(
    377             'user_id' => $user_id,
    378             'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),
    379             'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    380             'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    381             'type' => 'new_blog_comment',
    382             'item_id' => $wpdb->blogid,
     448            'user_id'           => $user_id,
     449            'action'            => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
     450            'content'           => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
     451            'primary_link'      => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
     452            'type'              => 'new_blog_comment',
     453            'item_id'           => $blog_id,
    383454            'secondary_item_id' => $comment_id,
    384             'recorded_time' => $comment->comment_date_gmt
     455            'recorded_time'     => $recorded_comment->comment_date_gmt
    385456        ) );
    386     }
    387 
    388     bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     457
     458        // Update the blogs last active date
     459        bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     460    }
    389461
    390462    return $recorded_comment;
     
    451523add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    452524
    453 function bp_blogs_remove_post( $post_id, $blog_id = false ) {
     525function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
    454526    global $current_blog, $bp;
    455527
     
    459531        $blog_id = (int)$current_blog->blog_id;
    460532
     533    if ( !$existing_post )
     534        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
     535
     536    // Delete post from the bp_blogs table
     537    BP_Blogs_Post::delete( $post_id, $blog_id );
     538
    461539    // Delete activity stream item
    462540    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    468546function bp_blogs_remove_comment( $comment_id ) {
    469547    global $wpdb, $bp;
     548
     549    $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
     550    BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
    470551
    471552    // Delete activity stream item
     
    504585    /* If this is regular blog, delete all data for that blog. */
    505586    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
     587    BP_Blogs_Post::delete_posts_for_blog( $blog_id );
     588    BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
    506589
    507590    // Delete activity stream item
     
    516599}
    517600
     601/* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
     602function bp_blogs_get_posts_for_user( $user_id ) {
     603    return BP_Blogs_Post::get_posts_for_user( $user_id );
     604}
     605
     606/* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
     607function bp_blogs_get_comments_for_user( $user_id ) {
     608    return BP_Blogs_Comment::get_comments_for_user( $user_id );
     609}
     610
     611function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
     612    global $bp;
     613
     614    if ( !is_numeric( $limit ) )
     615        $limit = 5;
     616
     617    return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
     618}
     619
    518620function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    519621    return BP_Blogs_Blog::get_all( $limit, $page );
     
    522624function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
    523625    return BP_Blogs_Blog::get( 'random', $limit, $page );
     626}
     627
     628function bp_blogs_get_all_posts( $limit = null, $page = null ) {
     629    return BP_Blogs_Post::get_all( $limit, $page );
     630}
     631
     632function bp_blogs_total_post_count( $blog_id ) {
     633    return BP_Blogs_Post::total_post_count( $blog_id );
     634}
     635
     636function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
     637    return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    524638}
    525639
     
    640754
    641755function bp_blogs_remove_data( $user_id ) {
    642     if ( !bp_core_is_multisite() )
    643         return false;
    644 
    645756    /* If this is regular blog, delete all data for that blog. */
    646757    BP_Blogs_Blog::delete_blogs_for_user( $user_id );
     758    BP_Blogs_Post::delete_posts_for_user( $user_id );
     759    BP_Blogs_Comment::delete_comments_for_user( $user_id );
    647760
    648761    do_action( 'bp_blogs_remove_data', $user_id );
    649762}
    650 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
    651 add_action( 'delete_user', 'bp_blogs_remove_data' );
    652 add_action( 'make_spam_user', 'bp_blogs_remove_data' );
     763add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 );
     764add_action( 'delete_user', 'bp_blogs_remove_data', 1 );
    653765
    654766
     
    677789}
    678790
     791function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
     792    wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
     793}
     794
     795function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
     796    bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
     797
     798    /* Clear the sitewide activity cache */
     799    wp_cache_delete( 'sitewide_activity', 'bp' );
     800}
     801
     802function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
     803    wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
     804}
     805
     806function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
     807    bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
     808
     809    /* Clear the sitewide activity cache */
     810    wp_cache_delete( 'sitewide_activity', 'bp' );
     811}
     812
    679813// List actions to clear object caches on
    680814add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
     815add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
     816add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
     817
    681818add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
     819add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
     820add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    682821
    683822// List actions to clear super cached pages on, if super cache is installed
  • trunk/bp-blogs/bp-blogs-classes.php

    r2842 r3232  
    279279            return $paged_blogs;
    280280
    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" );
     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        }
    283291
    284292        /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
     
    308316}
    309317
     318/* DEPRECATED - Post DB recording is scheduled for removal. Please use the activity stream to fetch a user's posts. */
     319Class 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. */
     527Class 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
    310712?>
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r2944 r3232  
    145145
    146146    $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
    147     return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
     147    return $blogs_template->has_blogs();
    148148}
    149149
     
    167167    $total = bp_core_number_format( $blogs_template->total_blog_count );
    168168
    169     echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
     169    echo sprintf( __( 'Viewing blog %s to %s (of %s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
    170170    <span class="ajax-loader"></span><?php
    171171}
  • trunk/bp-core.php

    r2978 r3232  
    3030require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
    3131require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
    32 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
    3332require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
    3433require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
     
    3837require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    3938require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
     39
     40/* Multisite includes built in account activation support. */
     41if ( bp_core_is_multisite() )
     42    require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
    4043
    4144/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
     
    229232    }
    230233
    231 
    232234    return apply_filters( 'bp_core_get_page_names', $pages );
    233235}
     236
    234237
    235238/**
     
    463466        }
    464467
    465         do_action( 'bp_core_action_delete_user', $errors );
     468        do_action( 'bp_core_action_set_spammer_status', $errors );
    466469
    467470        if ( $errors )
     
    497500        'search_terms' => false, // Limit to users that match these search terms
    498501
    499         'include' => false, // Pass comma separated list of user_ids to limit to only these users
    500502        'per_page' => 20, // The number of results to return per page
    501503        'page' => 1, // The page to return if limiting per page
     
    506508    extract( $params, EXTR_SKIP );
    507509
    508     return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
     510    return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $search_terms, $populate_extras ), &$params );
    509511}
    510512
     
    898900}
    899901
    900 
    901902/**
    902903 * bp_core_get_random_member()
     
    934935    global $wpdb;
    935936
    936     if ( empty( $username ) )
    937         return false;
    938 
    939     return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
     937    if ( !empty( $username ) )
     938        return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
    940939}
    941940
     
    12901289add_action( 'bp_init', 'bp_core_setup_message' );
    12911290
     1291
    12921292/**
    12931293 * bp_core_render_message()
     
    13311331function bp_core_time_since( $older_date, $newer_date = false ) {
    13321332    // array of time period chunks
    1333 
    13341333    $chunks = array(
    13351334    array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
     
    14511450        return $number;
    14521451
    1453     return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
     1452    return apply_filters( 'bp_core_bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
    14541453}
    14551454
     
    14981497            unset( $site_path[2] );
    14991498
    1500             if ( !count( $site_path ) )
    1501                 $site_path = '/';
    1502             else
    1503                 $site_path = '/' . implode( '/', $site_path ) . '/';
     1499            $site_path = '/' . implode( '/', $site_path ) . '/';
    15041500        }
    15051501    }
     
    15071503    return apply_filters( 'bp_core_get_site_path', $site_path );
    15081504}
     1505
    15091506/**
    15101507 * bp_core_get_site_options()
     
    16231620
    16241621/**
     1622 * bp_core_email_from_name_filter()
     1623 *
     1624 * Sets the "From" name in emails sent to the name of the site and not "WordPress"
     1625 *
     1626 * @package BuddyPress Core
     1627 * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
     1628 * @return The blog name for the root blog
     1629 */
     1630function bp_core_email_from_name_filter() {
     1631    return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
     1632}
     1633add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
     1634
     1635
     1636/**
     1637 * bp_core_email_from_name_filter()
     1638 *
     1639 * Sets the "From" address in emails sent
     1640 *
     1641 * @package BuddyPress Core
     1642 * @global $current_site Object containing current site metadata
     1643 * @return noreply@sitedomain email address
     1644 */
     1645function bp_core_email_from_address_filter() {
     1646    $domain = (array) explode( '/', site_url() );
     1647
     1648    return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
     1649}
     1650add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
     1651
     1652/**
    16251653 * bp_core_delete_account()
    16261654 *
     
    16351663 */
    16361664function bp_core_delete_account( $user_id = false ) {
    1637     global $bp, $wpdb;
     1665    global $bp, $wp_version;
    16381666
    16391667    if ( !$user_id )
     
    16441672        return false;
    16451673
     1674    /* Site admins cannot be deleted */
     1675    if ( is_super_admin( bp_core_get_username( $user_id ) ) )
     1676        return false;
     1677
    16461678    /* Specifically handle multi-site environment */
    16471679    if ( bp_core_is_multisite() ) {
    1648         /* Site admins cannot be deleted */
    1649         if ( is_site_admin( bp_core_get_username( $user_id ) ) )
    1650             return false;
    1651 
    1652         require_once( ABSPATH . '/wp-admin/includes/mu.php' );
     1680        if ( $wp_version >= '3.0' )
     1681            require_once( ABSPATH . '/wp-admin/includes/ms.php' );
     1682        else
     1683            require_once( ABSPATH . '/wp-admin/includes/mu.php' );
     1684
    16531685        require_once( ABSPATH . '/wp-admin/includes/user.php' );
    16541686
    16551687        return wpmu_delete_user( $user_id );
    1656     }
    16571688
    16581689    /* Single site user deletion */
    1659     require_once( ABSPATH . '/wp-admin/includes/user.php' );
    1660     return wp_delete_user( $user_id );
    1661 }
    1662 
     1690    } else {
     1691        require_once( ABSPATH . '/wp-admin/includes/user.php' );
     1692        return wp_delete_user( $user_id );
     1693    }
     1694}
    16631695
    16641696/**
     
    17671799    ?>
    17681800
    1769 <!-- Generated in <?php timer_stop(1); ?> seconds. -->
     1801<!-- Generated in <?php timer_stop(1); ?> seconds. (<?php echo get_num_queries(); ?> q) -->
    17701802
    17711803    <?php
     
    18381870    $user = get_userdatabylogin( $username );
    18391871
    1840     if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
     1872    if ( (int)$user->spam )
    18411873        bp_core_redirect( $bp->root_domain );
    18421874    else
     
    18611893    wp_cache_flush();
    18621894}
    1863 add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
    1864 add_action( 'delete_user', 'bp_core_remove_data' );
    1865 add_action( 'make_spam_user', 'bp_core_remove_data' );
     1895add_action( 'wpmu_delete_user', 'bp_core_remove_data', 1 );
     1896add_action( 'delete_user', 'bp_core_remove_data', 1 );
     1897add_action( 'make_spam_user', 'bp_core_remove_data', 1 );
    18661898
    18671899/**
     
    18991931}
    19001932add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
     1933
     1934/**
     1935 * bp_core_filter_parent_theme()
     1936 *
     1937 * Remove social network parent theme from the theme list.
     1938 *
     1939 * @package BuddyPress Core
     1940 */
     1941function bp_core_filter_parent_theme() {
     1942    global $wp_themes, $pagenow;
     1943
     1944    if ( is_admin() && 'themes.php' == $pagenow )
     1945        $wp_themes = get_themes();
     1946
     1947    unset( $wp_themes['BuddyPress Classic Parent'] );
     1948}
     1949add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
     1950
     1951/**
     1952 * bp_core_allow_default_theme()
     1953 *
     1954 * On multiblog installations you must first allow themes to be activated and show
     1955 * up on the theme selection screen. This function will let the BuddyPress bundled
     1956 * themes show up on the root blog selection screen and bypass this step. It also
     1957 * means that the themes won't show for selection on other blogs.
     1958 *
     1959 * @package BuddyPress Core
     1960 */
     1961function bp_core_allow_default_theme( $themes ) {
     1962    global $bp, $current_blog;
     1963
     1964    if ( !is_site_admin() )
     1965        return $themes;
     1966
     1967    if ( $current_blog->ID == $bp->root_blog ) {
     1968        $themes['bp-default'] = 1;
     1969        $themes['bp-classic'] = 1;
     1970    }
     1971
     1972    return $themes;
     1973}
     1974add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
    19011975
    19021976/**
     
    19412015add_action( 'admin_notices', 'bp_core_activation_notice' );
    19422016
     2017
     2018/**
     2019 * bp_core_filter_comments()
     2020 *
     2021 * Filter the blog post comments array and insert BuddyPress URLs for users.
     2022 *
     2023 * @package BuddyPress Core
     2024 */
     2025function bp_core_filter_comments( $comments, $post_id ) {
     2026    global $wpdb;
     2027
     2028    foreach( (array)$comments as $comment ) {
     2029        if ( $comment->user_id )
     2030            $user_ids[] = $comment->user_id;
     2031    }
     2032
     2033    if ( empty( $user_ids ) )
     2034        return $comments;
     2035
     2036    $user_ids = implode( ',', $user_ids );
     2037
     2038    if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
     2039        return $comments;
     2040
     2041    foreach( (array)$userdata as $user )
     2042        $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
     2043
     2044    foreach( (array)$comments as $i => $comment ) {
     2045        if ( !empty( $comment->user_id ) ) {
     2046            if ( !empty( $users[$comment->user_id] ) )
     2047                $comments[$i]->comment_author_url = $users[$comment->user_id];
     2048        }
     2049    }
     2050
     2051    return $comments;
     2052}
     2053add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
     2054
     2055
     2056/**
     2057 * bp_core_login_redirect()
     2058 *
     2059 * When a user logs in, always redirect them back to the previous page. NOT the admin area.
     2060 *
     2061 * @package BuddyPress Core
     2062 */
     2063function bp_core_login_redirect( $redirect_to ) {
     2064    global $bp, $current_blog;
     2065
     2066    if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
     2067        return $redirect_to;
     2068
     2069    if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
     2070        return $redirect_to;
     2071
     2072    if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
     2073        return wp_get_referer();
     2074
     2075    return $bp->root_domain;
     2076}
     2077add_filter( 'login_redirect', 'bp_core_login_redirect' );
     2078
     2079
    19432080/********************************************************************************
    19442081 * Custom Actions
     
    19642101    do_action( 'bp_setup_nav' );
    19652102}
    1966 add_action( 'plugins_loaded', 'bp_setup_nav' );
    1967 add_action( 'admin_menu', 'bp_setup_nav' );
     2103add_action( 'bp_loaded', 'bp_setup_nav', 8 );
    19682104
    19692105/* Allow core components and dependent plugins to register widgets */
  • trunk/bp-core/admin/bp-core-upgrade.php

    r2881 r3232  
    236236            </div>
    237237
     238
     239            <?php if ( bp_core_is_multisite() ) : ?>
    238240            <div class="component">
    239241                <h5><?php _e( "Blog Tracking", 'buddypress' ) ?></h5>
     
    245247
    246248                <img src="<?php echo plugins_url( 'buddypress/screenshot-7.gif' ) ?>" alt="Activity Streams" />
    247                 <p><?php _e( "Track new blogs, new posts and new comments across your entire blog network.", 'buddypress' ) ?></p>
     249                    <p><?php _e( "Track new blogs, new posts and new comments across your entire blog network.", 'buddypress' ) ?></p>
    248250            </div>
     251            <?php endif; ?>
    249252        </div>
    250253
  • trunk/bp-core/bp-core-adminbar.php

    r2946 r3232  
    77        return false;
    88
    9     if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
     9    if ( (int)$bp->site_options['hide-loggedout-adminbar'] && !is_user_logged_in() )
    1010        return false;
    1111
  • trunk/bp-core/bp-core-avatars.php

    r2946 r3232  
    4040
    4141    if ( !defined( 'BP_AVATAR_DEFAULT' ) )
    42         define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-xprofile/images/none.gif' );
     42        define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
    4343
    4444    if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
    45         define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' );
    46 }
    47 add_action( 'bp_init', 'bp_core_set_avatar_constants' );
    48 
     45        define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
     46}
     47add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
     48
     49/**
     50 * bp_core_fetch_avatar()
     51 *
     52 * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
     53 * default, but can be extended to include your own custom components too.
     54 *
     55 * @global object $bp
     56 * @global object $current_blog
     57 * @param array $args Determine the output of this function
     58 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
     59 */
    4960function bp_core_fetch_avatar( $args = '' ) {
    5061    global $bp, $current_blog;
    5162
     63    // Set a few default variables
     64    $def_object     = 'user';
     65    $def_type       = 'thumb';
     66    $def_class      = 'avatar';
     67    $def_alt        = __( 'Avatar Image', 'buddypress' );
     68
     69    // Set the default variables array
    5270    $defaults = array(
    53         'item_id' => false,
    54         'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
    55         'type' => 'thumb',
    56         'avatar_dir' => false,
    57         'width' => false,
    58         'height' => false,
    59         'class' => 'avatar',
    60         'css_id' => false,
    61         'alt' => __( 'Avatar Image', 'buddypress' ),
    62         'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
    63         'no_grav' => false // If there is no avatar found, return false instead of a grav?
     71        'item_id'       => false,
     72        'object'        => $def_object, // user/group/blog/custom type (if you use filters)
     73        'type'          => $def_type,   // thumb or full
     74        'avatar_dir'    => false,       // Specify a custom avatar directory for your object
     75        'width'         => false,       // Custom width (int)
     76        'height'        => false,       // Custom height (int)
     77        'class'         => $def_class,  // Custom <img> class (string)
     78        'css_id'        => false,       // Custom <img> ID (string)
     79        'alt'           => $def_alt,    // Custom <img> alt (string)
     80        'email'         => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
     81        'no_grav'       => false,       // If there is no avatar found, return false instead of a grav?
     82        'html'          => true         // Wrap the return img URL in <img />
    6483    );
    6584
     85    // Compare defaults to passed and extract
    6686    $params = wp_parse_args( $args, $defaults );
    6787    extract( $params, EXTR_SKIP );
    6888
     89    // Set item_id if not passed
    6990    if ( !$item_id ) {
    7091        if ( 'user' == $object )
     
    80101    }
    81102
     103    // Set avatar_dir if not passed (uses $object)
    82104    if ( !$avatar_dir ) {
    83105        if ( 'user' == $object )
     
    93115    }
    94116
    95     /* Add an identifying class to each item */
     117    // Add an identifying class to each item
    96118    $class .= ' ' . $object . '-' . $item_id . '-avatar';
    97119
    98     if ( !empty($css_id) )
     120    // Set CSS ID if passed
     121    if ( !empty( $css_id ) )
    99122        $css_id = " id='{$css_id}'";
    100123
     124    // Set avatar width
    101125    if ( $width )
    102126        $html_width = " width='{$width}'";
     
    104128        $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
    105129
     130    // Set avatar height
    106131    if ( $height )
    107132        $html_height = " height='{$height}'";
     
    109134        $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
    110135
    111     $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', str_replace( WP_CONTENT_DIR, BP_AVATAR_URL, BP_AVATAR_UPLOAD_PATH ) . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
     136    // Set avatar URL and DIR based on prepopulated constants
     137    $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', BP_AVATAR_URL . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    112138    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    113139
     
    117143     * or thumbnail image.
    118144     */
    119     $avatar_name = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
     145    $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
    120146    $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
    121147    $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
    122148
     149    // Check for directory
    123150    if ( file_exists( $avatar_folder_dir ) ) {
     151
     152        // Open directory
    124153        if ( $av_dir = opendir( $avatar_folder_dir ) ) {
     154
     155            // Stash files in an array once to check for one that matches
     156            $avatar_files = array();
    125157            while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    126                 if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_group_avatar_name}/", $avatar_file ) )
    127                     $avatar_url = $avatar_folder_url . '/' . $avatar_file;
     158                // Only add files to the array (skip directories)
     159                if ( 2 < strlen( $avatar_file ) )
     160                    $avatar_files[] = $avatar_file;
     161            }
     162
     163            // Check for array
     164            if ( 0 < count( $avatar_files ) ) {
     165
     166                // Check for current avatar
     167                foreach( $avatar_files as $key => $value ) {
     168                    if ( strpos ( $value, $avatar_size )!== false )
     169                        $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     170                }
     171
     172                // Legacy avatar check
     173                if ( !isset( $avatar_url ) ) {
     174                    foreach( $avatar_files as $key => $value ) {
     175                        if ( strpos ( $value, $legacy_user_avatar_name )!== false )
     176                            $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     177                    }
     178
     179                    // Legacy group avatar check
     180                    if ( !isset( $avatar_url ) ) {
     181                        foreach( $avatar_files as $key => $value ) {
     182                            if ( strpos ( $value, $legacy_group_avatar_name )!== false )
     183                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     184                        }
     185                    }
     186                }
    128187            }
    129188        }
    130         closedir($av_dir);
    131 
    132         if ( $avatar_url )
    133             return apply_filters( 'bp_core_fetch_avatar', "<img src='{$avatar_url}' alt='{$alt}' class='{$class}'{$css_id}{$html_width}{$html_height} />", $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    134     }
    135 
    136     /* If no avatars have been uploaded for this item, display a gravatar */
     189
     190        // Close the avatar directory
     191        closedir( $av_dir );
     192
     193        // If we found a locally uploaded avatar
     194        if ( $avatar_url ) {
     195
     196            // Return it wrapped in an <img> element
     197            if ( true === $html ) {
     198                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     199
     200            // ...or only the URL
     201            } else {
     202                return apply_filters( 'bp_core_fetch_avatar_url', $avatar_url );
     203            }
     204        }
     205    }
     206
     207    // If no avatars could be found, try to display a gravatar
     208
     209    // Skips gravatar check if $no_grav is passed
    137210    if ( !$no_grav ) {
     211
     212        // Set gravatar size
     213        if ( $width )
     214            $grav_size = $width;
     215        else if ( 'full' == $type )
     216            $grav_size = BP_AVATAR_FULL_WIDTH;
     217        else if ( 'thumb' == $type )
     218            $grav_size = BP_AVATAR_THUMB_WIDTH;
     219
     220        // Set gravatar type
    138221        if ( empty( $bp->grav_default->{$object} ) )
    139222            $default_grav = 'wavatar';
    140223        else if ( 'mystery' == $bp->grav_default->{$object} )
    141             $default_grav = apply_filters( 'bp_core_mysteryman_src', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
     224            $default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
    142225        else
    143226            $default_grav = $bp->grav_default->{$object};
    144227
    145         if ( $width ) $grav_size = $width;
    146         else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH;
    147         else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH;
    148 
     228        // Set gravatar object
    149229        if ( empty( $email ) ) {
    150230            if ( 'user' == $object ) {
     
    155235        }
    156236
     237        // Set host based on if using ssl
    157238        if ( is_ssl() )
    158239            $host = 'https://secure.gravatar.com/avatar/';
     
    160241            $host = 'http://www.gravatar.com/avatar/';
    161242
    162         $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
    163         $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( $email ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    164 
    165         return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' class='{$class}'{$css_id}{$html_width}{$html_height} />", $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     243        // Filter gravatar vars
     244        $email      = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
     245        $gravatar   = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
     246
     247        // Return gravatar wrapped in <img />
     248        if ( true === $html )
     249            return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     250
     251        // ...or only return the gravatar URL
     252        else
     253            return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
     254
    166255    } else {
    167256        return apply_filters( 'bp_core_fetch_avatar', false, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     
    275364    }
    276365
    277     /* Resize the image down to something manageable and then delete the original */
    278     if ( getimagesize( $bp->avatar_admin->original['file'] ) > BP_AVATAR_ORIGINAL_MAX_WIDTH )
    279         $bp->avatar_admin->resized = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
    280 
    281     $bp->avatar_admin->image = new stdClass;
     366    /* Get image size */
     367    $size = @getimagesize( $bp->avatar_admin->original['file'] );
     368
     369    /* Check image size and shrink if too large */
     370    if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
     371        $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
     372
     373        /* Check for thumbnail creation errors */
     374        if ( is_wp_error( $thumb ) ) {
     375            bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
     376            return false;
     377        }
     378
     379        /* Thumbnail is good so proceed */
     380        $bp->avatar_admin->resized = $thumb;
     381    }
    282382
    283383    /* We only want to handle one image after resize. */
    284384    if ( empty( $bp->avatar_admin->resized ) )
    285         $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file'];
     385        $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
    286386    else {
    287         $bp->avatar_admin->image->dir = $bp->avatar_admin->resized;
     387        $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
    288388        @unlink( $bp->avatar_admin->original['file'] );
    289389    }
    290390
    291391    /* Set the url value for the image */
    292     $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, BP_AVATAR_URL, $bp->avatar_admin->image->dir );
     392    $bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
    293393
    294394    return true;
     
    323423        return false;
    324424
    325     if ( !file_exists( WP_CONTENT_DIR . '/' . $original_file ) )
     425    $original_file = BP_AVATAR_UPLOAD_PATH . $original_file;
     426
     427    if ( !file_exists( $original_file ) )
    326428        return false;
    327429
    328430    if ( !$item_id )
    329         $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir );
     431        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
    330432    else
    331433        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
     
    352454
    353455    /* Crop the image */
    354     $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
    355     $thumb_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
     456    $full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
     457    $thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
    356458
    357459    /* Remove the original */
    358     @unlink( WP_CONTENT_DIR . $original_file );
     460    @unlink( $original_file );
    359461
    360462    return true;
    361463}
    362464
    363 // Override internal "get_avatar()" function to use our own where possible
     465/**
     466 * bp_core_fetch_avatar_filter()
     467 *
     468 * Attempts to filter get_avatar function and let BuddyPress have a go
     469 * at finding an avatar that may have been uploaded locally.
     470 *
     471 * @global array $authordata
     472 * @param string $avatar The result of get_avatar from before-filter
     473 * @param int|string|object $user A user ID, email address, or comment object
     474 * @param int $size Size of the avatar image (thumb/full)
     475 * @param string $default URL to a default image to use if no avatar is available
     476 * @param string $alt Alternate text to use in image tag. Defaults to blank
     477 * @return <type>
     478 */
    364479function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
    365     global $authordata;
    366 
     480    global $pagenow;
     481
     482    // Do not filter if inside WordPress options page
     483    if ( 'options-discussion.php' == $pagenow )
     484        return $avatar;
     485
     486    // If passed an object, assume $user->user_id
    367487    if ( is_object( $user ) )
    368488        $id = $user->user_id;
     489
     490    // If passed a number, assume it was a $user_id
    369491    else if ( is_numeric( $user ) )
    370492        $id = $user;
    371     else
    372         $id = $authordata->ID;
    373 
     493
     494    // If passed a string and that string returns a user, get the $id
     495    else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
     496        $id = $user_by_email->ID;
     497
     498    // If somehow $id hasn't been assigned, return the result of get_avatar
    374499    if ( empty( $id ) )
    375         return $avatar;
    376 
     500        return !empty( $avatar ) ? $avatar : $default;
     501
     502    // Let BuddyPress handle the fetching of the avatar
    377503    $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
    378504
     505    // If BuddyPress found an avatar, use it. If not, use the result of get_avatar
    379506    return ( !$bp_avatar ) ? $avatar : $bp_avatar;
    380507}
     
    402529}
    403530
     531/**
     532 * bp_core_avatar_upload_path()
     533 *
     534 * Returns the absolute upload path for the WP installation
     535 *
     536 * @global object $current_blog Current blog information
     537 * @uses wp_upload_dir To get upload directory info
     538 * @return string Absolute path to WP upload directory
     539 */
    404540function bp_core_avatar_upload_path() {
    405     if ( bp_core_is_multisite() )
    406         $path = ABSPATH . get_blog_option( BP_ROOT_BLOG, 'upload_path' );
    407     else {
    408         if ( !$path = get_option( 'upload_path' ) )
    409             $path = WP_CONTENT_DIR . '/uploads';
    410         else
    411             $path = ABSPATH . $path;
    412     }
    413 
    414     return apply_filters( 'bp_core_avatar_upload_path', $path );
    415 }
    416 
     541    global $current_blog;
     542
     543    // Get upload directory information from current site
     544    $upload_dir = wp_upload_dir();
     545
     546    // If multisite, and current blog does not match root blog, make adjustments
     547    if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
     548        $upload_dir['basedir'] = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
     549
     550    return apply_filters( 'bp_core_avatar_upload_path', $upload_dir['basedir'] );
     551}
     552
     553/**
     554 * bp_core_avatar_url()
     555 *
     556 * Returns the raw base URL for root site upload location
     557 *
     558 * @global object $current_blog Current blog information
     559 * @uses wp_upload_dir To get upload directory info
     560 * @return string Full URL to current upload location
     561 */
    417562function bp_core_avatar_url() {
    418     if ( !bp_core_is_multisite() )
    419         return WP_CONTENT_URL;
    420 
    421     return apply_filters( 'bp_core_avatar_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) );
     563    global $current_blog;
     564
     565    // Get upload directory information from current site
     566    $upload_dir = wp_upload_dir();
     567
     568    // If multisite, and current blog does not match root blog, make adjustments
     569    if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
     570        $upload_dir['baseurl'] = str_replace( get_blog_option( $current_blog->blog_id, 'home' ) , get_blog_option( BP_ROOT_BLOG, 'home' ), $upload_dir['baseurl'] );
     571
     572    return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
    422573}
    423574
  • trunk/bp-core/bp-core-classes.php

    r3023 r3232  
    107107    /* Static Functions */
    108108
    109     function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) {
     109    function get_users( $type, $limit = null, $page = 1, $user_id = false, $search_terms = false, $populate_extras = true ) {
    110110        global $wpdb, $bp;
    111111
     
    134134
    135135        if ( 'online' == $type )
    136             $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
     136            $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= NOW()";
    137137
    138138        if ( 'alphabetical' == $type )
    139139            $sql['where_alpha'] = "AND pd.field_id = 1";
    140140
    141         if ( $include ) {
    142             if ( is_array( $include ) )
    143                 $uids = $wpdb->escape( implode( ',', (array)$include ) );
    144             else
    145                 $uids = $wpdb->escape( $include );
    146 
    147             if ( !empty( $uids ) )
    148                 $sql['where_users'] = "AND u.ID IN ({$uids})";
    149         }
    150 
    151         else if ( $user_id && function_exists( 'friends_install' ) ) {
     141        if ( $user_id && function_exists( 'friends_install' ) ) {
    152142            $friend_ids = friends_get_friend_user_ids( $user_id );
    153143            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
     
    261251    }
    262252
     253    function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
     254        global $wpdb, $bp;
     255
     256        if ( $limit && $page )
     257            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     258
     259        $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
     260        $status_sql = bp_core_get_status_sql();
     261
     262        $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql} AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) " ), $wpdb->escape( $user_ids ) );
     263        $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT DISTINCT ID as id, user_registered, user_nicename, user_login, user_email FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql} AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) {$pag_sql}" ), $wpdb->escape( $user_ids ) );
     264
     265        $total_users = $wpdb->get_var( $total_users_sql );
     266        $paged_users = $wpdb->get_results( $paged_users_sql );
     267
     268        /***
     269         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     270         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     271         */
     272
     273        /* Add additional data to the returned results */
     274        if ( $populate_extras )
     275            $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     276
     277
     278        return array( 'users' => $paged_users, 'total' => $total_users );
     279    }
     280
    263281    function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
    264282        global $wpdb, $bp;
     
    300318        /* Fetch the user's full name */
    301319        if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
    302             /* Ensure xprofile globals are set */
    303             if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
    304                 xprofile_setup_globals();
    305 
    306320            $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", BP_XPROFILE_FULLNAME_FIELD_NAME ) );
    307321            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
  • trunk/bp-core/bp-core-cssjs.php

    r2946 r3232  
    4848    global $current_blog;
    4949
    50     if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
     50    if ( $current_blog->blog_id != BP_ROOT_BLOG )
    5151        return false;
    5252?>
     
    175175    global $bp;
    176176
    177     if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) {
     177    if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( $bp->site_options['hide-loggedout-adminbar'] && !is_user_logged_in() ) ) {
    178178    ?>
    179179<style type="text/css">body { padding-top: 0 !important; } #wp-admin-bar { display: none; }</style>
  • trunk/bp-core/bp-core-signup.php

    r2946 r3232  
    181181
    182182            /* Make sure we include the jQuery jCrop file for image cropping */
    183             add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
     183            add_action( 'wp', 'bp_core_add_jquery_cropper' );
    184184        }
    185185    }
     
    256256 */
    257257
     258/**
     259 * bp_core_flush_illegal_names()
     260 *
     261 * Flush illegal names by getting and setting 'illegal_names' site option
     262 */
     263function bp_core_flush_illegal_names() {
     264    $illegal_names = get_site_option( 'illegal_names' );
     265    update_site_option( 'illegal_names', $illegal_names );
     266}
     267
     268/**
     269 * bp_core_illegal_names()
     270 *
     271 * Filter the illegal_names site option and make sure it includes a few
     272 * specific BuddyPress and Multi-site slugs
     273 *
     274 * @param array|string $value Illegal names from field
     275 * @param array|string $oldvalue The value as it is currently
     276 * @return array Merged and unique array of illegal names
     277 */
     278function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
     279
     280    // Make sure $value is array
     281    if ( empty( $value ) )
     282        $db_illegal_names = array();
     283    if ( is_array( $value ) )
     284        $db_illegal_names = $value;
     285    elseif ( is_string( $value ) )
     286        $db_illegal_names = implode( ' ', $names );
     287
     288    // Add our slugs to the array and allow them to be filtered
     289    $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_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
     290
     291    // Merge the arrays together
     292    $merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
     293
     294    // Remove duplicates
     295    $illegal_names = array_unique( (array)$merged_names );
     296
     297    return apply_filters( 'bp_core_illegal_names', $illegal_names );
     298}
     299add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
     300
     301/**
     302 * bp_core_validate_user_signup()
     303 *
     304 * Validate a user name and email address when creating a new user.
     305 *
     306 * @global object $wpdb DB Layer
     307 * @param string $user_name Username to validate
     308 * @param string $user_email Email address to validate
     309 * @return array Results of user validation including errors, if any
     310 */
    258311function bp_core_validate_user_signup( $user_name, $user_email ) {
    259     global $wpdb, $bp;
     312    global $wpdb;
    260313
    261314    $errors = new WP_Error();
     
    268321    preg_match( "/[a-z0-9]+/", $user_name, $maybe );
    269322
    270     $db_illegal_names = get_site_option( 'illegal_names' );
    271     $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 ) );
    272 
    273     /* Safely merge our illegal names into existing site_option */
    274     $common_names           = array_intersect( (array)$db_illegal_names, (array)$filtered_illegal_names );
    275     $diff_names             = array_diff( (array)$db_illegal_names, (array)$filtered_illegal_names );
    276     $illegal_names          = array_merge( (array)$diff_names, (array)$common_names );
    277 
    278     update_site_option( 'illegal_names', $illegal_names );
    279 
    280     if ( in_array( $user_name, (array)$illegal_names ) )
    281         $errors->add( 'user_name', __( 'Sorry, that username is not allowed', 'buddypress' ) );
    282 
    283     if ( !validate_username( $user_name ) || $user_name != $maybe[0] )
     323    // Make sure illegal names include BuddyPress slugs and values
     324    bp_core_flush_illegal_names();
     325
     326    if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
    284327        $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
    285328
     
    382425        if ( !bp_core_is_multisite() ) {
    383426            $activation_key = wp_hash( $user_id );
    384             update_usermeta( $user_id, 'activation_key', $activation_key );
     427            update_user_meta( $user_id, 'activation_key', $activation_key );
    385428            bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
    386429        }
     
    445488
    446489        /* Remove the activation key meta */
    447         delete_usermeta( $user_id, 'activation_key' );
     490        delete_user_meta( $user_id, 'activation_key' );
    448491    }
    449492
     
    452495
    453496    /* Add a last active entry */
    454     update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     497    update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
    455498
    456499    /* Set the password on multisite installs */
     
    495538
    496539    /* Add a last active entry */
    497     update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     540    update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
    498541
    499542    /* Add the user's fullname to Xprofile */
    500543    if ( function_exists( 'xprofile_set_field_data' ) ) {
    501         $firstname = get_usermeta( $user_id, 'first_name' );
    502         $lastname = ' ' . get_usermeta( $user_id, 'last_name' );
     544        $firstname = get_user_meta( $user_id, 'first_name', true );
     545        $lastname = ' ' . get_user_meta( $user_id, 'last_name', true );
    503546        $name = $firstname . $lastname;
    504547
    505548        if ( empty( $name ) || ' ' == $name )
    506             $name = get_usermeta( $user_id, 'nickname' );
     549            $name = get_user_meta( $user_id, 'nickname', true );
    507550
    508551        xprofile_set_field_data( 1, $user_id, $name );
     
    523566        @wp_mkdir_p( $path );
    524567
    525     $newurl = str_replace( BP_AVATAR_UPLOAD_PATH, BP_AVATAR_URL, $path );
     568    $newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
    526569    $newburl = $newurl;
    527570    $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
     
    532575function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
    533576    $activate_url = bp_get_activation_page() ."?key=$key";
    534     $activate_url = clean_url( $activate_url );
     577    $activate_url = esc_url( $activate_url );
    535578    $admin_email = get_site_option( "admin_email" );
    536579
  • trunk/bp-core/bp-core-templatetags.php

    r2950 r3232  
    2727        if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
    2828            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
    29         } else {
    30             $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
     29        }
     30        else if ( false !== $include ) {
     31            $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page, $populate_extras );
     32        }
     33        else {
     34            $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
    3135        }
    3236
     
    160164
    161165    $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
    162     return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
     166
     167    return $members_template->has_members();
    163168}
    164169
     
    312317
    313318        // Populate the user if it hasn't been already.
    314         if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
    315             $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
     319        if ( empty( $members_template->member->profile_data ) )
     320            $members_template->member = new BP_Core_User( $members_template->member->id );
    316321
    317322        $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
     
    676681function bp_is_home() { return bp_is_my_profile(); }
    677682
     683function bp_get_loggedin_user_link() {
     684    global $bp;
     685
     686    return $bp->loggedin_user->domain;
     687}
     688
     689function bp_get_displayed_user_link() {
     690    global $bp;
     691
     692    return $bp->displayed_user->domain;
     693}
     694
    678695function bp_last_activity( $user_id = false, $echo = true ) {
    679696    global $bp;
     
    690707}
    691708
    692 function bp_user_firstname( $name = false ) {
    693     echo bp_get_user_firstname( $name );
     709function bp_user_firstname() {
     710    echo bp_get_user_firstname();
    694711}
    695712    function bp_get_user_firstname( $name = false ) {
     
    708725
    709726    echo apply_filters( 'bp_the_avatar_thumbnail', $bp->displayed_user->domain );
    710 }
    711 
    712 function bp_get_loggedin_user_link() {
    713     global $bp;
    714 
    715     return $bp->loggedin_user->domain;
    716 }
    717 
    718 function bp_get_displayed_user_link() {
    719     global $bp;
    720 
    721     return $bp->displayed_user->domain;
    722727}
    723728
     
    919924    } else if ( bp_is_activation_page() ) {
    920925        $title = __( 'Activate your Account', 'buddypress' );
    921 
    922     } else if ( bp_is_group_create() ) {
    923         $title = __( 'Create a Group', 'buddypress' );
    924 
    925     } else if ( bp_is_create_blog() ) {
    926         $title = __( 'Create a Blog', 'buddypress' );
    927926    }
    928927
     
    990989
    991990function bp_search_form_type_select() {
    992     global $bp;
    993 
    994991    // Eventually this won't be needed and a page will be built to integrate all search results.
    995992    $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
     
    11801177
    11811178function bp_signup_avatar( $args = '' ) {
    1182     echo bp_get_signup_avatar( $args = '' );
     1179    echo bp_get_signup_avatar( $args );
    11831180}
    11841181    function bp_get_signup_avatar( $args = '' ) {
     
    12061203
    12071204            $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
    1208             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 . '" />';
     1205            $gravatar_img = '<img src="' . $gravatar_url . md5( strtolower( $_POST['signup_email'] ) ) . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    12091206        } else {
    1210             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 ) ) );
     1207            $gravatar_img = 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 ) );
    12111208        }
     1209
     1210        return apply_filters( 'bp_get_signup_avatar', $gravatar_img );
    12121211    }
    12131212
     
    12511250
    12521251function bp_registration_needs_activation() {
    1253     return apply_filters( 'bp_registration_needs_activation', true );
     1252    return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite() );
    12541253}
    12551254
  • trunk/bp-core/bp-core-wpabstraction.php

    r2925 r3232  
    9090    }
    9191}
     92
     93if ( !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}
     154?>
  • trunk/bp-forums.php

    r2925 r3232  
    441441        $post_position = $post->post_position;
    442442
    443     $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
    444 
    445     if ( $post_id )
     443    $post = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
     444
     445    if ( $post )
    446446        do_action( 'bp_forums_new_post', $post_id );
    447447
    448     return $post_id;
     448    return $post;
    449449}
    450450
  • trunk/bp-forums/bp-forums-templatetags.php

    r2950 r3232  
    290290        global $forum_template;
    291291
    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 ) )
     292        if ( !$name = bp_core_get_userlink( $forum_template->topic->poster_id ) )
    295293            return __( 'Deleted User', 'buddypress' );
    296294
     
    464462        global $forum_template;
    465463
    466         return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
     464        return $forum_template->topic->topic_posts;
    467465    }
    468466
  • trunk/bp-friends.php

    r2946 r3232  
    566566    do_action( 'friends_remove_data', $user_id );
    567567}
    568 add_action( 'wpmu_delete_user', 'friends_remove_data' );
    569 add_action( 'delete_user', 'friends_remove_data' );
    570 add_action( 'make_spam_user', 'friends_remove_data' );
     568add_action( 'wpmu_delete_user', 'friends_remove_data', 1 );
     569add_action( 'delete_user', 'friends_remove_data', 1 );
     570add_action( 'make_spam_user', 'friends_remove_data', 1 );
    571571
    572572
     
    595595    global $bp;
    596596
    597     if ( isset( $_GET['new'] ) )
    598         bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
     597    if ( isset($_GET['new']) )
     598        bp_core_delete_notifications_for_user_by_type( $bp->displayed_user->id, $bp->friends->id, 'friendship_accepted' );
    599599}
    600600add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
  • trunk/bp-groups.php

    r2946 r3232  
    492492
    493493    if ( $bp->is_single_item ) {
    494         /* Refresh the group member count meta */
    495         groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) );
    496 
    497494        do_action( 'groups_screen_group_members', $bp->groups->current_group->id );
    498495        bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
     
    798795
    799796    if ( $bp->current_component == $bp->groups->slug && 'membership-requests' == $bp->action_variables[0] ) {
    800 
    801         /* Ask for a login if the user is coming here via an email notification */
    802         if ( !is_user_logged_in() )
    803             bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) );
    804797
    805798        if ( !$bp->is_item_admin || 'public' == $bp->groups->current_group->status )
     
    16531646}
    16541647
    1655 function groups_get_total_member_count( $group_id ) {
    1656     return BP_Groups_Group::get_total_member_count( $group_id );
    1657 }
    1658 
    16591648/*** Group Fetching, Filtering & Searching  *************************************/
    16601649
     
    18141803    groups_update_groupmeta( $group_id, 'forum_id', $forum_id );
    18151804
    1816     do_action( 'groups_new_group_forum', $forum_id, $group_id );
     1805    do_action( 'groups_new_group_forum', $forum, $group_id );
    18171806}
    18181807
     
    24172406    do_action( 'groups_remove_data_for_user', $user_id );
    24182407}
    2419 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
    2420 add_action( 'delete_user', 'groups_remove_data_for_user' );
    2421 add_action( 'make_spam_user', 'groups_remove_data_for_user' );
     2408add_action( 'wpmu_delete_user', 'groups_remove_data_for_user', 1 );
     2409add_action( 'delete_user', 'groups_remove_data_for_user', 1 );
     2410add_action( 'make_spam_user', 'groups_remove_data_for_user', 1 );
    24222411
    24232412
  • trunk/bp-groups/bp-groups-classes.php

    r2989 r3232  
    634634        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
    635635
    636         $group_count = get_usermeta( $this->user_id, 'total_group_count' );
     636        $group_count = get_user_meta( $this->user_id, 'total_group_count', true );
    637637        if ( !empty( $group_count ) )
    638             update_usermeta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
     638            update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
    639639
    640640        return $this->save();
     
    648648
    649649        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
    650         update_usermeta( $this->user_id, 'total_group_count', (int)get_usermeta( $this->user_id, 'total_group_count' ) + 1 );
     650        update_user_meta( $this->user_id, 'total_group_count', (int)get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
    651651
    652652        return $this->save();
     
    656656        $this->inviter_id = 0;
    657657        $this->is_confirmed = 1;
    658         $this->date_modified = gmdate( "Y-m-d H:i:s" );
     658        $this->date_modified = bp_core_current_time();
    659659    }
    660660
    661661    function accept_request() {
    662662        $this->is_confirmed = 1;
    663         $this->date_modified = gmdate( "Y-m-d H:i:s" );
     663        $this->date_modified = bp_core_current_time();
     664    }
     665
     666    function remove( $user_id, $group_id ) {
     667        global $wpdb, $bp;
     668
     669        $sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id );
     670
     671        if ( !$result = $wpdb->query( $sql ) )
     672            return false;
     673
     674        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
     675
     676        $group_count = get_user_meta( $this->user_id, 'total_group_count', true );
     677        if ( !empty( $group_count ) )
     678            update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
     679
     680        return $result;
    664681    }
    665682
     
    758775            $user_id = $bp->displayed_user->id;
    759776
    760         if ( $user_id != $bp->loggedin_user->id && !is_site_admin() ) {
     777        if ( $user_id != $bp->loggedin_user->id && !is_super_admin() ) {
    761778            return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    762779        } else {
     
    795812    }
    796813
     814    function delete_request( $user_id, $group_id ) {
     815        global $wpdb, $bp;
     816
     817        if ( !$user_id )
     818            return false;
     819
     820        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
     821    }
     822
    797823    function check_is_admin( $user_id, $group_id ) {
    798824        global $wpdb, $bp;
     
    829855
    830856        return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     857    }
     858
     859    /**
     860     * Is the specified user the creator of the group?
     861     *
     862     * @global object $bp BuddyPress global settings
     863     * @global wpdb $wpdb WordPress database object
     864     * @param int $user_id
     865     * @param int $group_id
     866     * @since 1.2.6
     867     */
     868    function check_is_creator( $user_id, $group_id ) {
     869        global $bp, $wpdb;
     870
     871        if ( !$user_id )
     872            return false;
     873
     874        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
    831875    }
    832876
     
    888932
    889933        if ( bp_is_active( 'xprofile' ) )
    890             $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, pd.value as display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u, {$bp->profile->table_name_data} pd WHERE u.ID = m.user_id AND u.ID = pd.user_id AND pd.field_id = 1 AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
     934            $members = $wpdb->get_results( $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, pd.value as display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u, {$bp->profile->table_name_data} pd WHERE u.ID = m.user_id AND u.ID = pd.user_id AND pd.field_id = 1 AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) );
    891935        else
    892             $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
     936            $members = $wpdb->get_results( $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) );
    893937
    894938        if ( !$members )
     
    898942            $total_member_count = count($members);
    899943        else
    900             $total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql}", $group_id ) ) );
     944            $total_member_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql}", $group_id ) );
    901945
    902946        /* Fetch whether or not the user is a friend */
     
    904948        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    905949
    906         if ( bp_is_active( 'friends' ) ) {
     950        if ( function_exists( 'friends_install' ) ) {
    907951            $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
    908952            for ( $i = 0; $i < count( $members ); $i++ ) {
     
    923967    }
    924968
     969    /**
     970     * Delete all group membership information for the specified user
     971     *
     972     * @global object $bp BuddyPress global settings
     973     * @global wpdb $wpdb WordPress database object
     974     * @param int $user_id
     975     * @since 1.0
     976     * @uses BP_Groups_Member
     977     */
    925978    function delete_all_for_user( $user_id ) {
    926         global $wpdb, $bp;
     979        global $bp, $wpdb;
     980
     981        // Get all the group ids for the current user's groups and update counts
     982        $group_ids = BP_Groups_Member::get_group_ids( $user_id );
     983        foreach ( $group_ids['groups'] as $group_id ) {
     984            groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
     985
     986            // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync
     987            if ( groups_is_user_admin( $user_id, $group_id ) && count( groups_get_group_admins( $group_id ) ) < 2 && groups_is_user_creator( $user_id, $group_id ) )
     988                groups_delete_group( $group_id );
     989        }
    927990
    928991        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id ) );
     
    9941057        global $bp;
    9951058
    996         /* When we are viewing a single group, add the group extension nav item */
    997         if ( $this->visbility == 'public' || ( $this->visbility != 'public' && $bp->groups->current_group->user_has_access ) ) {
    998             if ( $this->enable_nav_item ) {
    999                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
    1000                     bp_core_new_subnav_item( array( 'name' => ( !$this->nav_item_name ) ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => BP_GROUPS_SLUG, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array( &$this, '_display_hook' ), 'user_has_access' => $this->enable_nav_item ) );
    1001 
    1002                 /* When we are viewing the extension display page, set the title and options title */
    1003                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
    1004                     add_action( 'bp_template_content_header', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1005                     add_action( 'bp_template_title', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1006                 }
    1007             }
    1008 
    1009             /* Hook the group home widget */
    1010             if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
    1011                 add_action( $this->display_hook, array( &$this, 'widget_display' ) );
    1012         }
    1013 
    10141059        if ( $this->enable_create_step ) {
    1015             /* Insert the group creation step for the new group extension */
     1060            // Insert the group creation step for the new group extension
    10161061            $bp->groups->group_creation_steps[$this->slug] = array( 'name' => $this->name, 'slug' => $this->slug, 'position' => $this->create_step_position );
    10171062
    1018             /* Attach the group creation step display content action */
     1063            // Attach the group creation step display content action
    10191064            add_action( 'groups_custom_create_steps', array( &$this, 'create_screen' ) );
    10201065
    1021             /* Attach the group creation step save content action */
     1066            // Attach the group creation step save content action
    10221067            add_action( 'groups_create_group_step_save_' . $this->slug, array( &$this, 'create_screen_save' ) );
    10231068        }
    10241069
    1025         /* Construct the admin edit tab for the new group extension */
     1070        // Construct the admin edit tab for the new group extension
    10261071        if ( $this->enable_edit_item ) {
    1027             add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', 'if ( "' . attribute_escape( $this->slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . $bp->root_domain . '/' . $bp->groups->slug . '/{$group_slug}/admin/' . attribute_escape( $this->slug ) . '\">' . attribute_escape( $this->name ) . '</a></li>";' ), 10, 2 );
    1028 
    1029             /* Catch the edit screen and forward it to the plugin template */
     1072            add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', 'if ( "' . esc_attr( $this->slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . $bp->root_domain . '/' . $bp->groups->slug . '/{$group_slug}/admin/' . esc_attr( $this->slug ) . '\">' . esc_attr( $this->name ) . '</a></li>";' ), 10, 2 );
     1073
     1074            // Make sure user has access
     1075            if ( !$bp->is_item_admin )
     1076                return false;
     1077
     1078            // Catch the edit screen and forward it to the plugin template
    10301079            if ( $bp->current_component == $bp->groups->slug && 'admin' == $bp->current_action && $this->slug == $bp->action_variables[0] ) {
    1031                 $this->edit_screen_save();
     1080                add_action( 'wp', array( &$this, 'edit_screen_save' ) );
    10321081                add_action( 'groups_custom_edit_steps', array( &$this, 'edit_screen' ) );
    10331082
     
    10411090            }
    10421091        }
     1092
     1093        // When we are viewing a single group, add the group extension nav item
     1094        if ( $this->visibility == 'public' || ( $this->visibility != 'public' && $bp->groups->current_group->user_has_access ) ) {
     1095            if ( $this->enable_nav_item ) {
     1096                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
     1097                    bp_core_new_subnav_item( array( 'name' => ( !$this->nav_item_name ) ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => BP_GROUPS_SLUG, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array( &$this, '_display_hook' ), 'user_has_access' => $this->enable_nav_item ) );
     1098
     1099                // When we are viewing the extension display page, set the title and options title
     1100                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
     1101                    add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
     1102                    add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
     1103                }
     1104            }
     1105
     1106            // Hook the group home widget
     1107            if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
     1108                add_action( $this->display_hook, array( &$this, 'widget_display' ) );
     1109        }
    10431110    }
    10441111
     
    10551122        return false;
    10561123
    1057     /* Register the group extension on the plugins_loaded action so we have access to all plugins */
    1058     add_action( 'init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "pre_get_posts", array( &$extension, "_register" ) );' ) );
     1124    /* Register the group extension on the bp_init action so we have access to all plugins */
     1125    add_action( 'bp_init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "wp", array( &$extension, "_register" ), 2 );' ), 11 );
    10591126}
    10601127
  • trunk/bp-groups/bp-groups-templatetags.php

    r2950 r3232  
    14131413        $total = bp_core_number_format( $members_template->total_member_count );
    14141414
    1415         return apply_filters( 'bp_get_group_member_pagination_count', sprintf( __( 'Viewing members %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total ) );
     1415        return apply_filters( 'bp_get_group_member_pagination_count', sprintf( __( 'Viewing members %s to %s (of %s members)', 'buddypress' ), $from_num, $to_num, $total ) );
    14161416    }
    14171417
  • trunk/bp-loader.php

    r2925 r3232  
    77Version: 1.3-bleeding
    88Author URI: http://buddypress.org/developers/
    9 Network: true
    109*/
    1110
     
    6261        include( BP_PLUGIN_DIR . '/bp-xprofile.php' );
    6362
    64     /* Allow dependent plugins to hook into BuddyPress in a safe way */
     63    /**
     64    * bp_loaded()
     65    *
     66    * Allow dependent plugins and core actions to attach themselves in a safe way.
     67    *
     68    * See bp-core.php for the following core actions:
     69    *      - bp_init|bp_setup_globals|bp_setup_root_components|bp_setup_nav|bp_register_widgets
     70    */
    6571    function bp_loaded() {
    66         do_action( 'bp_init' );
     72        do_action( 'bp_loaded' );
    6773    }
    68     add_action( 'plugins_loaded', 'bp_loaded' );
     74    add_action( 'plugins_loaded', 'bp_loaded', 20 );
    6975}
    7076
  • trunk/bp-messages/bp-messages-notifications.php

    r2941 r3232  
    3434', 'buddypress' ), $sender_name, $subject, $content, $message_link );
    3535
    36         $email_content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     36        $content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    3737
    3838        /* Send the message */
  • trunk/bp-messages/bp-messages-templatetags.php

    r2944 r3232  
    313313    $total = bp_core_number_format( $messages_template->total_thread_count );
    314314
    315     echo sprintf( __( 'Viewing message %1$s to %2$s (of %3$s messages)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
     315    echo sprintf( __( 'Viewing message %s to %s (of %s messages)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
    316316    <span class="ajax-loader"></span><?php
    317317}
  • trunk/bp-themes/bp-default/_inc/css/default.css

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

    r2925 r3232  
    169169                if ( 'fav' == type ) {
    170170                    if ( !jq('div.item-list-tabs li#activity-favorites').length )
    171                         jq('div.item-list-tabs ul li#activity-mentions').before( '<li id="activity-favorites"><a href="#">' + bp_terms_my_favs + ' (<span>0</span>)</a></li>');
     171                        jq('div.item-list-tabs ul li#activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' (<span>0</span>)</a></li>');
    172172
    173173                    target.removeClass('fav');
     
    229229        /* Load more updates at the end of the page */
    230230        if ( target.parent().attr('class') == 'load-more' ) {
    231             jq("li.load-more").addClass('loading');
     231            jq("#content li.load-more").addClass('loading');
    232232
    233233            if ( null == jq.cookie('bp-activity-oldestpage') )
     
    243243            function(response)
    244244            {
    245                 jq("li.load-more").removeClass('loading');
     245                jq("#content li.load-more").removeClass('loading');
    246246                jq.cookie( 'bp-activity-oldestpage', oldest_page, {path: '/'} );
    247                 jq("ul.activity-list").append(response.contents);
     247                jq("#content ul.activity-list").append(response.contents);
    248248
    249249                target.parent().hide();
     
    461461    jq('span.highlight span').click( function() {
    462462        if ( !jq('div.help').length ) {
    463             jq(this).parent().after( '<div id="message" class="info help"><p>' + bp_terms_mention_explain + '</p></div>' );
     463            jq(this).parent().after( '<div id="message" class="info help"><p>' + BP_DTheme.mention_explain + '</p></div>' );
    464464            jq('div.help').hide().slideDown(200);
    465465        } else {
     
    713713                button.fadeOut( 100, function() {
    714714                    if ( jq(this).hasClass('accept') ) {
    715                         jq(this).html( bp_terms_accepted ).fadeIn(50);
     715                        jq(this).html( BP_DTheme.accepted ).fadeIn(50);
    716716                        jq(this).addClass('accepted');
    717717                    } else {
    718                         jq(this).html( bp_terms_rejected ).fadeIn(50);
     718                        jq(this).html( BP_DTheme.rejected ).fadeIn(50);
    719719                        jq(this).addClass('rejected');
    720720                    }
     
    820820    /** Alternate Highlighting ******************************************/
    821821
    822     jq('table tr, div.message-box, ul#topic-post-list li').each( function(i) {
    823         if ( i % 2 != 1 )
     822    jq('body#bp-default table.zebra tbody tr').mouseover( function() {
     823        jq(this).addClass('over');
     824    }).mouseout( function() {
     825        jq(this).removeClass('over');
     826    });
     827
     828    jq('body#bp-default table.zebra tbody tr:odd').addClass('alt');
     829
     830    jq('div.message-box').each( function(i) {
     831        if ( i % 2 == 1 )
    824832            jq(this).addClass('alt');
    825833    });
     
    957965
    958966    /* Bulk delete messages */
    959     jq("a#delete_inbox_messages").click( function() {
     967    jq("a#delete_inbox_messages, a#delete_sentbox_messages").click( function() {
    960968        checkboxes_tosend = '';
    961969        checkboxes = jq("#message-threads tr td input[type='checkbox']");
     
    990998
    991999            jq('div#message').hide().slideDown(150);
    992             jq("a#delete_inbox_messages").removeClass('loading');
     1000            jq("a#delete_inbox_messages, a#delete_sentbox_messages").removeClass('loading');
    9931001        });
    9941002        return false;
     
    10781086        return false;
    10791087
    1080     if ( jq.query.get('s') )
     1088    if ( jq.query.get('s') && !search_terms )
    10811089        search_terms = jq.query.get('s');
    10821090
     
    11591167            jq(this).html(response.contents);
    11601168            jq(this).fadeIn(100);
     1169
     1170            /* Selectively hide comments */
     1171            bp_dtheme_hide_comments();
    11611172        });
    11621173
     
    11661177
    11671178        jq('div.item-list-tabs li.selected').removeClass('loading');
    1168 
    1169         /* Selectively hide comments */
    1170         bp_dtheme_hide_comments();
    11711179
    11721180    }, 'json' );
     
    11981206
    11991207                if ( !i )
    1200                     jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + bp_terms_show_all_comments + '">' + bp_terms_show_all + ' ' + comment_count + ' ' + bp_terms_comments + '</a></li>' );
     1208                    jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_all + ' ' + comment_count + ' ' + BP_DTheme.comments + '</a></li>' );
    12011209            }
    12021210        });
  • trunk/bp-themes/bp-default/blogs/create.php

    r2925 r3232  
    11<?php get_header() ?>
    22
    3     <?php do_action( 'bp_before_directory_blogs_content' ) ?>
     3    <?php do_action( 'bp_before_directory_groups_content' ) ?>
    44
    55    <div id="content">
     
    3131    <?php locate_template( array( 'sidebar.php' ), true ) ?>
    3232
    33     <?php do_action( 'bp_after_directory_blogs_content' ) ?>
     33    <?php do_action( 'bp_after_directory_groups_content' ) ?>
    3434
    3535<?php get_footer() ?>
  • trunk/bp-themes/bp-default/comments.php

    r2946 r3232  
    2020
    2121            <span class="title"><?php the_title() ?></span>
    22             <h3 id="comments"><?php comments_number( '', '', $numComments );?></h3>
     22            <h3 id="comments"><?php comments_number( 'No Comments', 'One Comment', $numComments . ' Comments' );?></h3>
    2323
    2424            <?php do_action( 'bp_before_blog_comment_list' ) ?>
  • trunk/bp-themes/bp-default/forums/forums-loop.php

    r2925 r3232  
     1<?php /* Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter() */ ?>
     2
     3<?php do_action( 'bp_before_forums_loop' ) ?>
     4
    15<?php if ( bp_has_forum_topics( bp_ajax_querystring( 'forums' ) ) ) : ?>
    26
    3     <div class="pagination">
     7    <div id="pag-top" class="pagination">
    48
    5         <div id="post-count" class="pag-count">
    6             <?php if ( bp_is_group_forum() && is_user_logged_in() ) : ?>
    7                 <a href="#post-new" class="button"><?php _e( 'New Topic', 'buddypress' ) ?></a> &nbsp;
    8             <?php endif; ?>
    9 
     9        <div class="pag-count" id="topic-count-top">
    1010            <?php bp_forum_pagination_count() ?>
    1111        </div>
    1212
    13         <div class="pagination-links" id="topic-pag">
     13        <div class="pagination-links" id="topic-pag-top">
    1414            <?php bp_forum_pagination() ?>
    1515        </div>
     
    1919    <?php do_action( 'bp_before_directory_forums_list' ) ?>
    2020
    21     <table class="forum">
     21    <table class="forum zebra">
     22        <thead>
     23            <tr>
     24                <th id="th-title"><?php _e( 'Topic Title', 'buddypress' ) ?></th>
     25                <th id="th-poster"><?php _e( 'Latest Poster', 'buddypress' ) ?></th>
    2226
    23         <tr>
    24             <th id="th-title"><?php _e( 'Topic Title', 'buddypress' ) ?></th>
    25             <th id="th-poster"><?php _e( 'Latest Poster', 'buddypress' ) ?></th>
     27                <?php if ( !bp_is_group_forum() ) : ?>
     28                    <th id="th-group"><?php _e( 'Posted In Group', 'buddypress' ) ?></th>
     29                <?php endif; ?>
    2630
    27             <?php if ( !bp_is_group_forum() ) : ?>
    28                 <th id="th-group"><?php _e( 'Posted In Group', 'buddypress' ) ?></th>
    29             <?php endif; ?>
     31                <th id="th-postcount"><?php _e( 'Posts', 'buddypress' ) ?></th>
     32                <th id="th-freshness"><?php _e( 'Freshness', 'buddypress' ) ?></th>
    3033
    31             <th id="th-postcount"><?php _e( 'Posts', 'buddypress' ) ?></th>
    32             <th id="th-freshness"><?php _e( 'Freshness', 'buddypress' ) ?></th>
     34                <?php do_action( 'bp_directory_forums_extra_cell_head' ) ?>
    3335
    34             <?php do_action( 'bp_directory_forums_extra_cell_head' ) ?>
     36            </tr>
     37        </thead>
    3538
    36         </tr>
     39        <tbody>
    3740
    38         <?php while ( bp_forum_topics() ) : bp_the_forum_topic(); ?>
     41            <?php while ( bp_forum_topics() ) : bp_the_forum_topic(); ?>
    3942
    40         <tr class="<?php bp_the_topic_css_class() ?>">
    41             <td class="td-title">
    42                 <a class="topic-title" href="<?php bp_the_topic_permalink() ?>" title="<?php bp_the_topic_title() ?> - <?php _e( 'Permalink', 'buddypress' ) ?>">
    43                     <?php bp_the_topic_title() ?>
    44                 </a>
    45             </td>
    46             <td class="td-poster">
    47                 <a href="<?php bp_the_topic_permalink() ?>"><?php bp_the_topic_last_poster_avatar( 'type=thumb&width=20&height=20' ) ?></a>
    48                 <div class="poster-name"><?php bp_the_topic_last_poster_name() ?></div>
    49             </td>
     43            <tr class="<?php bp_the_topic_css_class() ?>">
     44                <td class="td-title">
     45                    <a class="topic-title" href="<?php bp_the_topic_permalink() ?>" title="<?php bp_the_topic_title() ?> - <?php _e( 'Permalink', 'buddypress' ) ?>">
     46                        <?php bp_the_topic_title() ?>
     47                    </a>
     48                </td>
     49                <td class="td-poster">
     50                    <a href="<?php bp_the_topic_permalink() ?>"><?php bp_the_topic_last_poster_avatar( 'type=thumb&width=20&height=20' ) ?></a>
     51                    <div class="poster-name"><?php bp_the_topic_last_poster_name() ?></div>
     52                </td>
    5053
    51             <?php if ( !bp_is_group_forum() ) : ?>
    52                 <td class="td-group">
    53                     <a href="<?php bp_the_topic_object_permalink() ?>"><?php bp_the_topic_object_avatar( 'type=thumb&width=20&height=20' ) ?></a>
    54                     <div class="object-name"><a href="<?php bp_the_topic_object_permalink() ?>" title="<?php bp_the_topic_object_name() ?>"><?php bp_the_topic_object_name() ?></a></div>
     54                <?php if ( !bp_is_group_forum() ) : ?>
     55                    <td class="td-group">
     56                        <a href="<?php bp_the_topic_object_permalink() ?>"><?php bp_the_topic_object_avatar( 'type=thumb&width=20&height=20' ) ?></a>
     57                        <div class="object-name"><a href="<?php bp_the_topic_object_permalink() ?>" title="<?php bp_the_topic_object_name() ?>"><?php bp_the_topic_object_name() ?></a></div>
     58                    </td>
     59                <?php endif; ?>
     60
     61                <td class="td-postcount">
     62                    <?php bp_the_topic_total_posts() ?>
    5563                </td>
    56             <?php endif; ?>
     64                <td class="td-freshness">
     65                    <?php bp_the_topic_time_since_last_post() ?>
     66                </td>
    5767
    58             <td class="td-postcount">
    59                 <?php bp_the_topic_total_posts() ?>
    60             </td>
    61             <td class="td-freshness">
    62                 <?php bp_the_topic_time_since_last_post() ?>
    63             </td>
     68                <?php do_action( 'bp_directory_forums_extra_cell' ) ?>
     69            </tr>
    6470
    65             <?php do_action( 'bp_directory_forums_extra_cell' ) ?>
    66         </tr>
     71            <?php do_action( 'bp_directory_forums_extra_row' ) ?>
    6772
    68         <?php do_action( 'bp_directory_forums_extra_row' ) ?>
     73            <?php endwhile; ?>
    6974
    70         <?php endwhile; ?>
    71 
     75        </tbody>
    7276    </table>
    7377
    7478    <?php do_action( 'bp_after_directory_forums_list' ) ?>
     79
     80    <div id="pag-bottom" class="pagination">
     81
     82        <div class="pag-count" id="topic-count-bottom">
     83            <?php bp_forum_pagination_count() ?>
     84        </div>
     85
     86        <div class="pagination-links" id="topic-pag-bottom">
     87            <?php bp_forum_pagination() ?>
     88        </div>
     89
     90    </div>
    7591
    7692<?php else: ?>
     
    8197
    8298<?php endif;?>
     99
     100<?php do_action( 'bp_after_forums_loop' ) ?>
  • trunk/bp-themes/bp-default/forums/index.php

    r2925 r3232  
    11<?php get_header() ?>
     2
     3    <?php do_action( 'bp_before_directory_forums_content' ) ?>
    24
    35    <div id="content">
     
    57
    68        <form action="" method="post" id="forums-search-form" class="dir-form">
    7 
    89            <h3><?php _e( 'Group Forums Directory', 'buddypress' ) ?><?php if ( is_user_logged_in() ) : ?> &nbsp;<a class="button" href="#new-topic" id="new-topic-button"><?php _e( 'New Topic', 'buddypress' ) ?></a><?php endif; ?></h3>
    9 
    10             <?php do_action( 'bp_before_directory_forums_content' ) ?>
    1110
    1211            <div id="forums-dir-search" class="dir-search">
  • trunk/bp-themes/bp-default/functions.php

    r2842 r3232  
    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 
    7774    if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
    7875        return $page_html;
  • trunk/bp-themes/bp-default/groups/index.php

    r2925 r3232  
    1515            <div class="item-list-tabs">
    1616                <ul>
    17                     <li class="selected" id="groups-all"><a href="<?php echo bp_get_root_domain() . '/' . BP_GROUPS_SLUG ?>"><?php printf( __( 'All Groups (%s)', 'buddypress' ), bp_get_total_group_count() ) ?></a></li>
     17                    <li class="selected" id="groups-all"><a href="<?php bp_root_domain() ?>"><?php printf( __( 'All Groups (%s)', 'buddypress' ), bp_get_total_group_count() ) ?></a></li>
    1818
    1919                    <?php if ( is_user_logged_in() && bp_get_total_group_count_for_user( bp_loggedin_user_id() ) ) : ?>
  • trunk/bp-themes/bp-default/members/single/home.php

    r2925 r3232  
    1515                        <?php bp_get_displayed_user_nav() ?>
    1616
    17                         <?php do_action( 'bp_member_options_nav' ) ?>
     17                        <?php do_action( 'bp_members_directory_member_types' ) ?>
    1818                    </ul>
    1919                </div>
  • trunk/bp-themes/bp-default/members/single/profile/edit.php

    r2842 r3232  
    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; ?>
    5450
    5551                <?php endif; ?>
  • trunk/bp-themes/bp-default/sidebar.php

    r2925 r3232  
    3838        </p>
    3939
    40         <form name="login-form" id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login_post' ) ?>" method="post">
     40        <form name="login-form" id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login' ) ?>" method="post">
    4141            <label><?php _e( 'Username', 'buddypress' ) ?><br />
    4242            <input type="text" name="log" id="sidebar-user-login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" /></label>
  • trunk/bp-xprofile.php

    r2946 r3232  
    1616 * @uses site_url() Returns the site URL
    1717 */
     18
    1819function xprofile_setup_globals() {
    1920    global $bp, $wpdb;
     
    136137            <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    137138<?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?>
    138 
    139139            <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li>
    140140<?php else : ?>
     
    235235        }
    236236
    237         if ( !empty( $errors ) )
     237        if ( $errors )
    238238            bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
    239239        else {
     
    249249            }
    250250
    251             do_action( 'xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors );
     251            do_action( 'xprofile_updated_profile', $posted_field_ids, $errors );
    252252
    253253            /* Set the feedback messages */
     
    642642        return false;
    643643
    644     /* If the value is empty, then delete any field data that exists */
    645     if ( empty( $value ) ) {
    646         xprofile_delete_field_data( $field_id, $user_id );
    647         return true;
    648     }
    649 
    650644    $field = new BP_XProfile_Field( $field_id );
    651645
     
    693687        $field_id = xprofile_get_field_id_from_name( $field );
    694688
    695     if ( empty( $field_id ) || empty( $user_id ) )
    696         return false;
    697 
    698     $field = new BP_XProfile_ProfileData( $field_id, $user_id );
     689    if ( !$field_id )
     690        return false;
     691
     692    $field = new BP_XProfile_ProfileData( $field_id );
    699693    return $field->delete();
    700694}
     
    882876    BP_XProfile_ProfileData::delete_data_for_user( $user_id );
    883877
    884     /* delete any avatar files. */
    885     @unlink( get_usermeta( $user_id, 'bp_core_avatar_v1_path' ) );
    886     @unlink( get_usermeta( $user_id, 'bp_core_avatar_v2_path' ) );
    887 
    888     /* unset the usermeta for avatars from the usermeta table. */
    889     delete_usermeta( $user_id, 'bp_core_avatar_v1' );
    890     delete_usermeta( $user_id, 'bp_core_avatar_v1_path' );
    891     delete_usermeta( $user_id, 'bp_core_avatar_v2' );
    892     delete_usermeta( $user_id, 'bp_core_avatar_v2_path' );
     878    // delete any avatar files.
     879    @unlink( get_user_meta( $user_id, 'bp_core_avatar_v1_path', true ) );
     880    @unlink( get_user_meta( $user_id, 'bp_core_avatar_v2_path', true ) );
     881
     882    // unset the usermeta for avatars from the usermeta table.
     883    delete_user_meta( $user_id, 'bp_core_avatar_v1' );
     884    delete_user_meta( $user_id, 'bp_core_avatar_v1_path' );
     885    delete_user_meta( $user_id, 'bp_core_avatar_v2' );
     886    delete_user_meta( $user_id, 'bp_core_avatar_v2_path' );
    893887}
    894888add_action( 'wpmu_delete_user', 'xprofile_remove_data' );
  • trunk/bp-xprofile/admin/css/admin.css

    r2887 r3232  
    141141            margin: 0 0 1em 0;
    142142        }
    143    
     143
    144144            ul.forTab li label {
    145145                display: block;
    146146            }
    147    
     147
    148148            ul.forTab li input {
    149149                font-size: 1.4em;
    150150            }
    151    
     151
    152152    p.success { background: green;}
    153     p.err { 
     153    p.err {
    154154        border-top: 2px solid red;
    155155        border-bottom: 2px solid red;
     
    158158        width: 40%;
    159159    }
    160    
     160
    161161    span.desc, span.signup-description {
    162162        display: block;
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r2887 r3232  
    121121                    } /* End For */ ?>
    122122                </div>
    123 <?php 
     123<?php
    124124                else :
    125125?>
     
    330330function xprofile_admin_field( $admin_field, $admin_group ) {
    331331    global $field;
    332    
     332
    333333    $field = $admin_field;
    334334?>
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r2883 r3232  
    549549                           <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo attribute_escape( $options[$i]->name ); ?>" />
    550550                           <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?>
    551 <?php 
     551<?php
    552552                    if ( $j != 1 && $options[$i]->id != -1 ) : ?>
    553553                            <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r2911 r3232  
    343343        global $field;
    344344
    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 );
     345        return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id );
    350346    }
    351347
     
    375371
    376372                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;
     373                    $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
    379374
    380375                    /* Check for updated posted values, but errors preventing them from being saved first time */
    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                         }
     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];
    386379                    }
    387380
  • trunk/readme.txt

    r2925 r3232  
    11=== Plugin Name ===
    2 Contributors: apeatling
     2Contributors: apeatling, johnjamesjacoby, mrmaz
    33Tags: buddypress, social networking, activity, profiles, messaging, friends, groups, forums, microblogging, twitter, facebook, mingle, social, community, networks, networking, cms
    4 Requires at least: 2.9.1
    5 Tested up to: 2.9.2
    6 Stable tag: 1.2.3
     4Requires at least: 3.0
     5Tested up to: 3.0.1
     6Stable tag: 1.2.5.2
    77
    88== Description ==
     
    124124== Upgrade Notice ==
    125125
    126 = 1.2.2.1 =
    127 Fixes a bug where new account activation emails would not be sent correctly. Important upgrade.
     126= 1.2.5.1 =
     127Fixes 'Mark user as spam' and 'Delete user' issues. Important upgrade.
    128128
    129129== Changelog ==
Note: See TracChangeset for help on using the changeset viewer.