Skip to:
Content

BuddyPress.org

Changeset 3300


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (14 years ago)
Author:
djpaul
Message:

Fixed #2676

Location:
trunk
Files:
1 added
99 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2863 r3300  
    55
    66function bp_activity_setup_globals() {
    7     global $bp, $wpdb, $current_blog;
     7    global $bp, $current_blog;
    88
    99    if ( !defined( 'BP_ACTIVITY_SLUG' ) )
    1010        define ( 'BP_ACTIVITY_SLUG', $bp->pages->activity->slug );
    1111
    12     /* For internal identification */
     12    // For internal identification
    1313    $bp->activity->id = 'activity';
    1414    $bp->activity->name = $bp->pages->activity->name;
    1515    $bp->activity->slug = BP_ACTIVITY_SLUG;
    1616
    17     $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity';
    18     $bp->activity->table_name_meta = $wpdb->base_prefix . 'bp_activity_meta';
     17    $bp->activity->table_name      = $bp->table_prefix . 'bp_activity';
     18    $bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta';
     19
    1920    $bp->activity->format_notification_function = 'bp_activity_format_notifications';
    2021
    21     /* Register this in the active components array */
     22    // Register this in the active components array
    2223    $bp->active_components[$bp->activity->slug] = $bp->activity->id;
    2324
     
    4344
    4445    if ( bp_is_active( 'groups' ) )
    45         bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => $bp->groups->name, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
     46        bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
    4647
    4748    bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
     
    9394        return false;
    9495
    95     if ( !is_site_admin() )
     96    if ( !is_super_admin() )
    9697        $bp->is_item_admin = false;
    9798
     
    106107        return false;
    107108
    108     if ( !is_site_admin() )
     109    if ( !is_super_admin() )
    109110        $bp->is_item_admin = false;
    110111
     
    116117    global $bp;
    117118
    118     if ( !is_site_admin() )
     119    if ( !is_super_admin() )
    119120        $bp->is_item_admin = false;
    120121
     
    126127    global $bp;
    127128
    128     if ( !is_site_admin() )
     129    if ( !is_super_admin() )
    129130        $bp->is_item_admin = false;
    130131
     
    173174            bp_core_redirect( $bp->loggedin_user->domain );
    174175        else
    175             bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
     176            bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
    176177    }
    177178
     
    183184function bp_activity_screen_notification_settings() {
    184185    global $bp; ?>
    185     <table class="notification-settings" id="activity-notification-settings">
    186         <tr>
    187             <th class="icon"></th>
    188             <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
    189             <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    190             <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    191         </tr>
    192 
    193         <tr>
    194             <td></td>
    195             <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
    196             <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
    197             <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
    198         </tr>
    199         <tr>
    200             <td></td>
    201             <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
    202             <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
    203             <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
    204         </tr>
    205 
    206         <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
     186    <table class="notification-settings zebra" id="activity-notification-settings">
     187        <thead>
     188            <tr>
     189                <th class="icon"></th>
     190                <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
     191                <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
     192                <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     193            </tr>
     194        </thead>
     195
     196        <tbody>
     197            <tr>
     198                <td></td>
     199                <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
     200                <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
     201                <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
     202            </tr>
     203            <tr>
     204                <td></td>
     205                <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
     206                <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
     207                <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
     208            </tr>
     209
     210            <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
     211        </tbody>
    207212    </table>
    208213<?php
     
    271276
    272277    /* Check access */
    273     if ( !is_site_admin() && $activity->user_id != $bp->loggedin_user->id )
     278    if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
    274279        return false;
    275280
     
    541546
    542547function bp_activity_add( $args = '' ) {
    543     global $bp, $wpdb;
     548    global $bp;
    544549
    545550    $defaults = array(
    546         'id' => false, // Pass an existing activity ID to update an existing entry.
    547 
    548         'action' => '', // The activity action - e.g. "Jon Doe posted an update"
    549         'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
    550 
    551         'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
    552         'type' => false, // The activity type e.g. activity_update, profile_updated
    553         'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
    554 
    555         'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
    556         'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
     551        'id'                => false, // Pass an existing activity ID to update an existing entry.
     552
     553        'action'            => '', // The activity action - e.g. "Jon Doe posted an update"
     554        'content'           => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
     555
     556        'component'         => false, // The name/ID of the component e.g. groups, profile, mycomponent
     557        'type'              => false, // The activity type e.g. activity_update, profile_updated
     558        'primary_link'      => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
     559
     560        'user_id'           => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
     561        'item_id'           => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
    557562        'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
    558         'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
    559         'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
     563        'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
     564        'hide_sitewide'     => false // Should this be hidden on the sitewide activity stream?
    560565    );
    561566
     
    628633
    629634    /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
    630     update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
     635    update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
    631636
    632637    /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
     
    755760        $user_id = $args['user_id'];
    756761
    757     $latest_update = get_usermeta( $user_id, 'bp_latest_update' );
     762    $latest_update = get_user_meta( $user_id, 'bp_latest_update', true );
    758763    if ( !empty( $latest_update ) ) {
    759764        if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
    760             delete_usermeta( $user_id, 'bp_latest_update' );
     765            delete_user_meta( $user_id, 'bp_latest_update' );
    761766    }
    762767
     
    909914
    910915function bp_activity_get_user_favorites( $user_id ) {
    911     $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
     916    $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
    912917    $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
    913918
     
    916921
    917922    $new_favs = array_unique( (array)$new_favs );
    918     update_usermeta( $user_id, 'bp_favorite_activities', $new_favs );
     923    update_user_meta( $user_id, 'bp_favorite_activities', $new_favs );
    919924
    920925    return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
     
    928933
    929934    /* Update the user's personal favorites */
    930     $my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
     935    $my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
    931936    $my_favs[] = $activity_id;
    932937
     
    939944        $fav_count = 1;
    940945
    941     update_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
     946    update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
    942947    bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
    943948
     
    954959
    955960    /* Remove the fav from the user's favs */
    956     $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
     961    $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
    957962    $my_favs = array_flip( (array) $my_favs );
    958963    unset( $my_favs[$activity_id] );
     
    967972    }
    968973
    969     update_usermeta( $user_id, 'bp_favorite_activities', $my_favs );
     974    update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
    970975
    971976    do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
     
    10891094
    10901095    // Remove any usermeta
    1091     delete_usermeta( $user_id, 'bp_latest_update' );
    1092     delete_usermeta( $user_id, 'bp_favorite_activities' );
     1096    delete_user_meta( $user_id, 'bp_latest_update' );
     1097    delete_user_meta( $user_id, 'bp_favorite_activities' );
    10931098
    10941099    do_action( 'bp_activity_remove_data', $user_id );
     
    10981103add_action( 'make_spam_user', 'bp_activity_remove_data' );
    10991104
     1105/**
     1106 * updates_register_activity_actions()
     1107 *
     1108 * Register the activity stream actions for updates
     1109 *
     1110 * @global array $bp
     1111 */
     1112function updates_register_activity_actions() {
     1113    global $bp;
     1114
     1115    bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) );
     1116
     1117    do_action( 'updates_register_activity_actions' );
     1118}
     1119add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' );
    11001120
    11011121/********************************************************************************
     
    11101130    do_action( 'bp_register_activity_actions' );
    11111131}
    1112 add_action( 'plugins_loaded', 'bp_register_activity_actions' );
     1132add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
    11131133
    11141134
  • trunk/bp-activity/bp-activity-classes.php

    r3236 r3300  
    9898        $where_conditions = array();
    9999
     100        /* Searching */
     101        if ( $search_terms ) {
     102            $search_terms = $wpdb->escape( $search_terms );
     103            $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
     104        }
     105
    100106        /* Filtering */
    101107        if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
     
    117123        $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    118124
    119         /* Searching */
    120         if ( $search_terms ) {
    121             $search_terms = $wpdb->escape( $search_terms );
    122 
    123             if ( !empty( $filter['user_id'] ) )
    124                 $where_sql .= ' OR ';
    125             else if ( !empty( $where_conditions ) )
    126                 $where_sql .= ' AND ';
    127 
    128             $where_sql .= "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
    129         }
    130 
    131125        if ( $per_page && $page ) {
    132126            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
    133127            $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) ) );
    134         } else
     128        } else {
    135129            $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}", $select_sql, $from_sql, $where_sql, $sort ) ) );
     130        }
    136131
    137132        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
     
    532527        global $bp, $wpdb;
    533528
    534         return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
     529        return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" ) );
    535530    }
    536531
     
    538533        global $bp;
    539534
    540         if ( !$favorite_activity_entries = get_usermeta( $user_id, 'bp_favorite_activities' ) )
     535        if ( !$favorite_activity_entries = get_user_meta( $user_id, 'bp_favorite_activities', true ) )
    541536            return 0;
    542537
  • trunk/bp-activity/bp-activity-notifications.php

    r3232 r3300  
    55
    66    /* Scan for @username strings in an activity update. Notify each user. */
    7     $pattern = '/[@]+([A-Za-z0-9-_]+)/';
     7    $pattern = '/[@]+([A-Za-z0-9-_\.]+)/';
    88    preg_match_all( $pattern, $content, $usernames );
    99
     
    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
    1818        // Now email the user with the contents of the message (if they have enabled email notifications)
    19         if ( 'no' != get_usermeta( $receiver_user_id, 'notification_activity_new_mention' ) ) {
     19        if ( 'no' != get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    2020            $poster_name = bp_core_get_user_displayname( $poster_user_id );
    2121
     
    2727
    2828            // Set up and send the message
    29             $ud = bp_core_get_core_userdata( $receiver_user_id );
    30             $to = $ud->user_email;
    31             $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
     29            $ud       = bp_core_get_core_userdata( $receiver_user_id );
     30            $to       = $ud->user_email;
     31            $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
     32            $subject  = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
    3233
    3334$message = sprintf( __(
     
    6162    $original_activity = new BP_Activity_Activity( $activity_id );
    6263
    63     if ( $original_activity->user_id != $commenter_id && 'no' != get_usermeta( $original_activity->user_id, 'notification_activity_new_reply' ) ) {
     64    if ( $original_activity->user_id != $commenter_id && 'no' != get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
    6465        $poster_name = bp_core_get_user_displayname( $commenter_id );
    6566        $thread_link = bp_activity_get_permalink( $activity_id );
     
    7071
    7172        // Set up and send the message
    72         $ud = bp_core_get_core_userdata( $original_activity->user_id );
    73         $to = $ud->user_email;
    74         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
     73        $ud       = bp_core_get_core_userdata( $original_activity->user_id );
     74        $to       = $ud->user_email;
     75        $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
     76        $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
    7577
    7678$message = sprintf( __(
     
    103105    $parent_comment = new BP_Activity_Activity( $parent_id );
    104106
    105     if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_usermeta( $parent_comment->user_id, 'notification_activity_new_reply' ) ) {
     107    if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
    106108        $poster_name = bp_core_get_user_displayname( $commenter_id );
    107109        $thread_link = bp_activity_get_permalink( $activity_id );
     
    109111
    110112        // Set up and send the message
    111         $ud = bp_core_get_core_userdata( $parent_comment->user_id );
    112         $to = $ud->user_email;
    113         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
     113        $ud       = bp_core_get_core_userdata( $parent_comment->user_id );
     114        $to       = $ud->user_email;
     115        $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
     116        $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
    114117
    115118        $poster_name = stripslashes( $poster_name );
  • trunk/bp-activity/bp-activity-templatetags.php

    r3263 r3300  
    2626
    2727        // Get an array of the logged in user's favorite activities
    28         $this->my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
     28        $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
    2929
    3030        // Fetch specific activity items based on ID's
    3131        if ( !empty( $include ) )
    3232            $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
     33        // Fetch all activity items
    3334        else
    3435            $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
     
    155156        $primary_id = $bp->groups->current_group->id;
    156157
    157         if ( 'public' != $bp->groups->current_group->status && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     158        if ( 'public' != $bp->groups->current_group->status && ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) || $bp->loggedin_user->is_super_admin ) )
    158159            $show_hidden = true;
    159160    }
     
    201202        // are we displaying user specific activity?
    202203        if ( is_numeric( $user_id ) ) {
    203             $show_hidden = ( $user_id == $bp->loggedin_user->id ) ? 1 : 0;
     204            $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
    204205
    205206            switch ( $scope ) {
     
    275276        global $bp, $activities_template;
    276277
    277         $from_num = bp_core_number_format( intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1 );
    278         $to_num = bp_core_number_format( ( $from_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $from_num + ( $activities_template->pag_num - 1 ) );
     278        $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
     279        $from_num = bp_core_number_format( $start_num );
     280        $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
    279281        $total = bp_core_number_format( $activities_template->total_activity_count );
    280282
    281         return sprintf( __( 'Viewing item %s to %s (of %s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' &nbsp; <span class="ajax-loader"></span>';
     283        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>';
    282284    }
    283285
     
    403405    }
    404406
     407/**
     408 * bp_activity_avatar( $args )
     409 *
     410 * Output the avatar of the user that performed the action
     411 *
     412 * @param array $args
     413 */
    405414function bp_activity_avatar( $args = '' ) {
    406415    echo bp_get_activity_avatar( $args );
    407416}
     417    /**
     418     * bp_get_activity_avatar( $args )
     419     *
     420     * Return the avatar of the user that performed the action
     421     *
     422     * @global array $bp
     423     * @global object $activities_template
     424     * @param array $args optional
     425     * @return string
     426     */
    408427    function bp_get_activity_avatar( $args = '' ) {
    409428        global $bp, $activities_template;
    410429
    411430        $defaults = array(
    412             'type' => 'thumb',
    413             'width' => 20,
     431            'type'   => 'thumb',
     432            'width'  => 20,
    414433            'height' => 20,
    415             'class' => 'avatar',
    416             'alt' => __( 'Avatar', 'buddypress' ),
    417             'email' => false
     434            'class'  => 'avatar',
     435            'alt'    => __( 'Avatar', 'buddypress' ),
     436            'email'  => false
    418437        );
    419438
     
    421440        extract( $r, EXTR_SKIP );
    422441
    423         $item_id = false;
    424         if ( (int)$activities_template->activity->user_id )
    425             $item_id = $activities_template->activity->user_id;
    426         else if ( $activities_template->activity->item_id )
    427             $item_id = $activities_template->activity->item_id;
    428 
    429         $object = 'user';
    430         if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
    431             $object = 'group';
    432         if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
    433             $object = 'blog';
    434 
    435         $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object );
    436 
    437         /* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */
    438         if ( 'user' == $object && empty($email) )
     442        // Primary activity avatar is always a user, but can be modified via a filter
     443        $object  = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, 'user' );
     444        $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $activities_template->activity->user_id );
     445
     446        // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
     447        if ( 'user' == $object && empty( $email ) )
    439448            $email = $activities_template->activity->user_email;
    440449
    441450        return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
     451    }
     452
     453/**
     454 * bp_activity_secondary_avatar( $args )
     455 *
     456 * Output the avatar of the object that action was performed on
     457 *
     458 * @param array $args optional
     459 */
     460function bp_activity_secondary_avatar( $args = '' ) {
     461    echo bp_get_activity_secondary_avatar( $args );
     462}
     463    /**
     464     * bp_get_activity_secondary_avatar( $args )
     465     *
     466     * Return the avatar of the object that action was performed on
     467     *
     468     * @global array $bp
     469     * @global object $activities_template
     470     * @param array $args optional
     471     * @return string
     472     */
     473    function bp_get_activity_secondary_avatar( $args = '' ) {
     474        global $bp, $activities_template;
     475
     476        $defaults = array(
     477            'type'   => 'thumb',
     478            'width'  => 20,
     479            'height' => 20,
     480            'class'  => 'avatar',
     481            'alt'    => __( 'Avatar', 'buddypress' ),
     482            'email'  => false
     483        );
     484
     485        $r = wp_parse_args( $args, $defaults );
     486        extract( $r, EXTR_SKIP );
     487
     488        // Set item_id and object (default to user)
     489        switch ( $activities_template->activity->component ) {
     490            case 'groups' :
     491                $object = 'group';
     492                $item_id = $activities_template->activity->item_id;
     493                break;
     494            case 'blogs' :
     495                $object = 'blog';
     496                $item_id = $activities_template->activity->item_id;
     497                break;
     498            case 'friends' :
     499                $object  = 'user';
     500                $item_id = $activities_template->activity->secondary_item_id;
     501                break;
     502            default :
     503                $object  = 'user';
     504                $item_id = $activities_template->activity->user_id;
     505                $email = $activities_template->activity->user_email;
     506                break;
     507        }
     508
     509        // Allow object and item_id to be filtered
     510        $object  = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
     511        $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
     512
     513        // If we have no item_id or object, there is no avatar to display
     514        if ( empty( $item_id ) || empty( $object ) )
     515            return false;
     516
     517        return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
    442518    }
    443519
     
    449525
    450526        $action = $activities_template->activity->action;
     527
     528        $action = apply_filters( 'bp_get_activity_action_pre_meta', $action, &$activities_template->activity );
    451529
    452530        if ( !empty( $action ) )
     
    498576        global $activities_template, $bp;
    499577
    500         $meta = '<span class="activity-actions">';
     578        /* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */
     579        $content = str_replace( '<span class="time-since">%s</span>', '', $content );
    501580
    502581        /* Insert the time since. */
    503         $meta .= apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( '&nbsp; %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );
     582        $content .= ' ' . apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( '&nbsp; %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );
    504583
    505584        /* Insert the permalink */
    506         $meta .= apply_filters( 'bp_activity_permalink', ' &middot; <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity );
     585        $content .= apply_filters( 'bp_activity_permalink', ' &middot; <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity );
    507586
    508587        /* Add the delete link if the user has permission on this item */
    509         if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_site_admin )
    510              $meta .= apply_filters( 'bp_activity_delete_link', ' &middot; ' . bp_get_activity_delete_link(), &$activities_template->activity );
    511 
    512         $meta .= '</span>';
    513 
    514         return apply_filters( 'bp_insert_activity_meta', $content . ' ' . $meta, $content, $meta );
     588        if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_super_admin )
     589             $content .= apply_filters( 'bp_activity_delete_link', ' &middot; ' . bp_get_activity_delete_link(), &$activities_template->activity );
     590
     591        return apply_filters( 'bp_insert_activity_meta', $content );
    515592    }
    516593
     
    585662
    586663                $content .= '<li id="acomment-' . $comment->id . '">';
    587                 $content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 25, 'height' => 25, 'email' => $comment->user_email ) ) . '</a></div>';
    588                 $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_get_member_name', $comment->user_fullname ) . '</a> &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( strtotime( $comment->date_recorded ) ) );
     664                $content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 20, 'height' => 20, 'email' => $comment->user_email ) ) . '</a></div>';
     665                $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_acomment_name', $comment->user_fullname, $comment ) . '</a> &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $comment->date_recorded ) );
    589666
    590667                /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
     
    593670
    594671                /* Delete link */
    595                 if ( $bp->loggedin_user->is_site_admin || $bp->loggedin_user->id == $comment->user_id )
     672                if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id )
    596673                    $content .= ' &middot; <a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
    597674
     
    739816            $user_id = $bp->displayed_user->id;
    740817
    741         if ( !$update = get_usermeta( $user_id, 'bp_latest_update' ) )
     818        if ( !$update = get_user_meta( $user_id, 'bp_latest_update', true ) )
    742819            return false;
    743820
    744         $latest_update = '&quot;' . trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) . '&quot;';
     821        $latest_update = '&quot;' . apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) ) . '&quot;';
    745822        $latest_update .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
    746823
     
    777854                unset($selected);
    778855
    779             $component = attribute_escape( $component );
     856            $component = esc_attr( $component );
    780857
    781858            switch ( $style ) {
     
    805882            $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
    806883
    807             $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
     884            $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
    808885        }
    809886
     
    811888
    812889        if ( isset( $_GET['afilter'] ) )
    813             $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
     890            $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
    814891
    815892        return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
     
    841918}
    842919    function bp_get_total_mention_count_for_user( $user_id = false ) {
    843         return apply_filters( 'bp_get_total_mention_count_for_user', get_usermeta( $user_id, 'bp_new_mention_count' ) );
     920        return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) );
    844921    }
    845922
  • trunk/bp-activity/feeds/bp-activity-favorites-feed.php

    r2600 r3300  
    1515    xmlns:dc="http://purl.org/dc/elements/1.1/"
    1616    xmlns:atom="http://www.w3.org/2005/Atom"
    17     <?php do_action('bp_activity_mentions_feed'); ?>
     17    <?php do_action('bp_activity_favorites_feed'); ?>
    1818>
    1919
  • trunk/bp-blogs.php

    r3232 r3300  
    1010    global $bp, $wpdb;
    1111
     12    if ( !defined( 'BP_BLOGS_SLUG' ) )
     13        define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );
     14
    1215    /* For internal identification */
    1316    $bp->blogs->id = 'blogs';
     
    4548
    4649    /* Add 'Blogs' to the main navigation */
    47     bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->name, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    48 
    49     $blogs_link = $bp->loggedin_user->domain . $bp->blogs->name . '/';
     50    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
     51
     52    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
    5053
    5154    /* Set up the component options navigation for Blog */
     
    97100}
    98101
    99 function bp_blogs_screen_recent_posts() {
    100     do_action( 'bp_blogs_screen_recent_posts' );
    101     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
    102 }
    103 
    104 function bp_blogs_screen_recent_comments() {
    105     do_action( 'bp_blogs_screen_recent_comments' );
    106     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
    107 }
    108 
    109102function bp_blogs_screen_create_a_blog() {
    110103    global $bp;
     
    164157        'item_id' => false,
    165158        'secondary_item_id' => false,
    166         'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     159        'recorded_time' => bp_core_current_time(),
    167160        'hide_sitewide' => false
    168161    );
     
    179172
    180173    if ( !empty( $content ) )
    181         $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );
     174        $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
    182175
    183176    /* Check for an existing entry and update if one exists. */
     
    245238}
    246239
    247 
    248240function bp_blogs_record_existing_blogs() {
    249241    global $bp, $wpdb;
     
    270262}
    271263
     264/**
     265 * Makes BuddyPress aware of a new site so that it can track its activity.
     266 *
     267 * @global object $bp BuddyPress global settings
     268 * @param int $blog_id
     269 * @param int $user_id
     270 * @param $bool $no_activity ; optional.
     271 * @since 1.0
     272 * @uses BP_Blogs_Blog
     273 */
    272274function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
    273275    global $bp;
     
    290292    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    291293    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    292     bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    293 
    294     /* Only record this activity if the blog is public */
     294    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
     295
     296    // Only record this activity if the blog is public
    295297    if ( (int)$_POST['blog_public'] && !$no_activity ) {
    296         /* Record this in activity streams */
     298        // Record this in activity streams
    297299        bp_blogs_record_activity( array(
    298             'user_id' => $recorded_blog->user_id,
    299             'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%1$s created the blog %2$s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
    300             'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
    301             'type' => 'new_blog',
    302             'item_id' => $recorded_blog->blog_id
     300            'user_id'      => $recorded_blog->user_id,
     301            'action'       => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
     302            'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
     303            'type'         => 'new_blog',
     304            'item_id'      => $recorded_blog->blog_id
    303305        ) );
    304306    }
     
    307309}
    308310add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
     311
     312/**
     313 * bp_blogs_update_option_blogname()
     314 *
     315 * Updates blogname in BuddyPress blogmeta table
     316 *
     317 * @global object $wpdb DB Layer
     318 * @param string $oldvalue Value before save (not used)
     319 * @param string $newvalue Value to change meta to
     320 */
     321function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
     322    global $wpdb;
     323    bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
     324}
     325add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
     326
     327/**
     328 * bp_blogs_update_option_blogdescription()
     329 *
     330 * Updates blogdescription in BuddyPress blogmeta table
     331 *
     332 * @global object $wpdb DB Layer
     333 * @param string $oldvalue Value before save (not used)
     334 * @param string $newvalue Value to change meta to
     335 */
     336function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
     337    global $wpdb;
     338    bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
     339}
     340add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
    309341
    310342function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
     
    317349        $user_id = (int)$post->post_author;
    318350
    319     /* This is to stop infinate loops with Donncha's sitewide tags plugin */
     351    /* This is to stop infinite loops with Donncha's sitewide tags plugin */
    320352    if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
    321353        return false;
     
    325357        return false;
    326358
    327     if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
    328         if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    329 
    330             /* If we're on a multiblog install, record this post */
    331             if ( bp_core_is_multisite() ) {
    332                 $recorded_post = new BP_Blogs_Post;
    333                 $recorded_post->user_id = $user_id;
    334                 $recorded_post->blog_id = $blog_id;
    335                 $recorded_post->post_id = $post_id;
    336                 $recorded_post->date_created = strtotime( $post->post_date );
    337 
    338                 $recorded_post_id = $recorded_post->save();
    339 
    340                 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    341             }
    342 
    343             if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    344                 /* Record this in activity streams */
    345                 $post_permalink = get_permalink( $post_id );
    346 
    347                 $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    348                 $activity_content = $post->post_content;
    349 
    350                 bp_blogs_record_activity( array(
    351                     'user_id' => (int)$post->post_author,
    352                     'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
    353                     'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
    354                     'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    355                     'type' => 'new_blog_post',
    356                     'item_id' => $blog_id,
    357                     'secondary_item_id' => $post_id,
    358                     'recorded_time' => $post->post_date_gmt
    359                 ));
    360             }
    361         }
    362     } else {
    363         $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    364 
    365         /* Delete the recorded post if the status is not published or it is password protected */
    366         if ( 'publish' != $post->post_status || '' != $post->post_password ) {
    367             return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
    368 
    369         /* If the post author has changed, delete the post and re-add it. */
    370         } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
    371             // Delete the existing recorded post
    372             bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
    373 
    374             // Re-record the post with the new author.
    375             bp_blogs_record_post( $post_id );
    376         }
    377 
    378         bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    379 
     359    if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    380360        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    381             /* Now re-record the post in the activity streams */
     361            /* Record this in activity streams */
    382362            $post_permalink = get_permalink( $post_id );
    383363
    384             $activity_action = sprintf( __( '%1$s wrote a new blog post: %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     364            $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    385365            $activity_content = $post->post_content;
    386366
     
    394374                'secondary_item_id' => $post_id,
    395375                'recorded_time' => $post->post_date_gmt
    396             ) );
     376            ));
    397377        }
    398     }
    399 
    400     bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    401 
    402     do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
     378    } else
     379        bp_blogs_remove_post( $post_id, $blog_id );
     380
     381    bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     382
     383    do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
    403384}
    404385add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    405386
     387/**
     388 * bp_blogs_record_comment()
     389 *
     390 * Record blog comment activity. Checks if blog is public and post is not
     391 * password protected.
     392 *
     393 * @global object $wpdb
     394 * @global $bp $bp
     395 * @param int $comment_id
     396 * @param bool $is_approved
     397 * @return mixed
     398 */
    406399function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    407400    global $wpdb, $bp;
     
    436429    // If blog is public allow activity to be posted
    437430    if ( get_blog_option( $blog_id, 'blog_public' ) ) {
     431
    438432        // Get activity related links
    439433        $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
     
    441435
    442436        // 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;
     437        $activity_action    = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     438        $activity_content   = $recorded_comment->comment_content;
    445439
    446440        // Record in activity streams
     
    523517add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    524518
    525 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
     519function bp_blogs_remove_post( $post_id, $blog_id = false ) {
    526520    global $current_blog, $bp;
    527521
     
    531525        $blog_id = (int)$current_blog->blog_id;
    532526
    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 
    539527    // Delete activity stream item
    540528    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
     
    546534function bp_blogs_remove_comment( $comment_id ) {
    547535    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 );
    551536
    552537    // Delete activity stream item
     
    585570    /* If this is regular blog, delete all data for that blog. */
    586571    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 );
    589572
    590573    // Delete activity stream item
     
    599582}
    600583
    601 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
    602 function bp_blogs_get_posts_for_user( $user_id ) {
    603     return BP_Blogs_Post::get_posts_for_user( $user_id );
    604 }
    605 
    606 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
    607 function bp_blogs_get_comments_for_user( $user_id ) {
    608     return BP_Blogs_Comment::get_comments_for_user( $user_id );
    609 }
    610 
    611 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
    612     global $bp;
    613 
    614     if ( !is_numeric( $limit ) )
    615         $limit = 5;
    616 
    617     return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
    618 }
    619 
    620584function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
    621585    return BP_Blogs_Blog::get_all( $limit, $page );
     
    626590}
    627591
    628 function bp_blogs_get_all_posts( $limit = null, $page = null ) {
    629     return BP_Blogs_Post::get_all( $limit, $page );
    630 }
    631 
    632 function bp_blogs_total_post_count( $blog_id ) {
    633     return BP_Blogs_Post::total_post_count( $blog_id );
    634 }
    635 
    636 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
    637     return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    638 }
    639 
    640592function bp_blogs_is_blog_hidden( $blog_id ) {
    641593    return BP_Blogs_Blog::is_hidden( $blog_id );
     
    648600        $blog = bp_blogs_get_random_blogs( 1, 1 );
    649601
    650         bp_core_redirect( get_blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );
     602        bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
    651603    }
    652604}
     
    664616    global $wpdb, $bp;
    665617
    666     if ( !is_numeric( $blog_id ) )
     618    if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
    667619        return false;
    668620
     
    692644    $blog_id = (int) $blog_id;
    693645
    694     if ( !$blog_id )
     646    if ( !$blog_id || !bp_core_is_multisite() )
    695647        return false;
    696648
     
    724676    global $wpdb, $bp;
    725677
    726     if ( !is_numeric( $blog_id ) )
     678    if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
    727679        return false;
    728680
     
    754706
    755707function bp_blogs_remove_data( $user_id ) {
     708    if ( !bp_core_is_multisite() )
     709        return false;
     710
    756711    /* If this is regular blog, delete all data for that blog. */
    757712    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 );
    760713
    761714    do_action( 'bp_blogs_remove_data', $user_id );
    762715}
    763 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 );
    764 add_action( 'delete_user', 'bp_blogs_remove_data', 1 );
     716add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
     717add_action( 'delete_user', 'bp_blogs_remove_data' );
     718add_action( 'make_spam_user', 'bp_blogs_remove_data' );
    765719
    766720
     
    789743}
    790744
    791 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
    792     wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
    793 }
    794 
    795 function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
    796     bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
    797 
    798     /* Clear the sitewide activity cache */
    799     wp_cache_delete( 'sitewide_activity', 'bp' );
    800 }
    801 
    802 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
    803     wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
    804 }
    805 
    806 function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
    807     bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
    808 
    809     /* Clear the sitewide activity cache */
    810     wp_cache_delete( 'sitewide_activity', 'bp' );
    811 }
    812 
    813745// List actions to clear object caches on
    814746add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
    815 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
    816 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
    817 
    818747add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
    819 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
    820 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    821748
    822749// List actions to clear super cached pages on, if super cache is installed
  • trunk/bp-blogs/bp-blogs-classes.php

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

    r3263 r3300  
    2222
    2323        $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
    24         $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     24        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    2525
    2626        if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
     
    3737
    3838        if ( $max ) {
    39             if ( $max >= count( $this->blogs ) ) {
     39            if ( $max >= count($this->blogs) ) {
    4040                $this->blog_count = count( $this->blogs );
    4141            } else {
     
    148148
    149149    $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
    150     return $blogs_template->has_blogs();
     150    return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
    151151}
    152152
     
    166166    global $bp, $blogs_template;
    167167
    168     $from_num = bp_core_number_format( intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1 );
    169     $to_num = bp_core_number_format( ( $from_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $from_num + ( $blogs_template->pag_num - 1 ) );
     168    $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
     169    $from_num = bp_core_number_format( $start_num );
     170    $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
    170171    $total = bp_core_number_format( $blogs_template->total_blog_count );
    171172
    172     echo sprintf( __( 'Viewing blog %s to %s (of %s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
     173    echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
    173174    <span class="ajax-loader"></span><?php
    174175}
     
    270271function bp_blog_hidden_fields() {
    271272    if ( isset( $_REQUEST['s'] ) ) {
    272         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
     273        echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
    273274    }
    274275
    275276    if ( isset( $_REQUEST['letter'] ) ) {
    276         echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
     277        echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    277278    }
    278279
    279280    if ( isset( $_REQUEST['blogs_search'] ) ) {
    280         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
     281        echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
    281282    }
    282283}
     
    347348
    348349            <input type="hidden" name="stage" value="gimmeanotherblog" />
    349             <?php do_action( "signup_hidden_fields" ); ?>
     350            <?php do_action( 'signup_hidden_fields' ); ?>
    350351
    351352            <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
     
    364365
    365366    // Blog name
    366     if( 'no' == constant( "VHOST" ) )
     367    if( !is_subdomain_install() )
    367368        echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
    368369    else
     
    373374    <?php }
    374375
    375     if( 'no' == constant( "VHOST" ) ) {
     376    if ( !is_subdomain_install() )
    376377        echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
    377     } else {
     378    else
    378379        echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
    379     }
     380
    380381    if ( !is_user_logged_in() ) {
    381382        print '(<strong>' . __( 'Your address will be ' , 'buddypress');
    382         if( 'no' == constant( "VHOST" ) ) {
     383
     384        if ( !is_subdomain_install() ) {
    383385            print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
    384386        } else {
    385387            print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
    386388        }
     389
    387390        echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
    388391    }
     
    476479
    477480function bp_blogs_blog_tabs() {
    478     global $bp;
     481    global $bp, $groups_template;
    479482
    480483    // Don't show these tabs on a user's own profile
  • trunk/bp-blogs/bp-blogs-widgets.php

    r2698 r3300  
    2222        global $bp;
    2323
    24         extract( $args );
     24        extract( $args );
    2525
    2626        echo $before_widget;
    27         echo $before_title
    28            . $widget_name
    29            . $after_title; ?>
     27        echo $before_title . $widget_name . $after_title;
    3028
    31         <?php
    3229        if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
    3330            $instance['max_posts'] = 10; ?>
     
    8178        ?>
    8279
    83         <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo attribute_escape( $max_posts ); ?>" style="width: 30%" /></label></p>
     80        <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
    8481    <?php
    8582    }
  • trunk/bp-core.php

    r3242 r3300  
    3030require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
    3131require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
     32require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
    3233require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
    3334require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
     
    6566 */
    6667function bp_core_setup_globals() {
    67     global $bp, $wpdb;
     68    global $bp;
    6869    global $current_user, $current_component, $current_action, $current_blog;
    6970    global $displayed_user_id, $bp_pages;
     
    7273    $current_user = wp_get_current_user();
    7374
     75    /* Get the base database prefix */
     76    $bp->table_prefix = bp_core_get_table_prefix();
     77
    7478    /* The domain for the root of the site where the main blog resides */
    7579    $bp->root_domain = bp_core_get_root_domain();
    76 
    77     /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
    78     $bp->active_components = array();
    7980
    8081    /* The names of the core WordPress pages used to display BuddyPress content */
     
    9596    $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );
    9697
    97     /* is_site_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
    98     $bp->loggedin_user->is_site_admin = is_site_admin();
     98    /* is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
     99    $bp->loggedin_user->is_super_admin = is_super_admin();
     100    $bp->loggedin_user->is_site_admin  = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6
    99101
    100102    /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
     
    141143    $bp->bp_options_nav = array();
    142144
     145    /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
     146    $bp->active_components = array();
     147
    143148    /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
    144     $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
     149    $bp->grav_default->user  = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
    145150    $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
    146     $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
     151    $bp->grav_default->blog  = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
    147152
    148153    /* Fetch the full name for the logged in and current user */
    149     $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
     154    $bp->loggedin_user->fullname  = bp_core_get_user_displayname( $bp->loggedin_user->id );
    150155    $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
    151156
     
    154159       generic variable so it can be used by other components. It can also be modified, so when viewing a group
    155160       'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
    156     $bp->is_item_admin = bp_is_my_profile();
     161    $bp->is_item_admin = bp_user_has_access();
    157162
    158163    /* Used to determine if the logged in user is a moderator for the current content. */
    159164    $bp->is_item_mod = false;
    160165
    161     $bp->core->table_name_notifications = $wpdb->base_prefix . 'bp_notifications';
     166    $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
    162167
    163168    if ( !$bp->current_component && $bp->displayed_user->id )
     
    169174
    170175/**
     176 * bp_core_get_table_prefix()
     177 *
     178 * Allow filtering of database prefix. Intended for use in multinetwork installations.
     179 *
     180 * @global object $wpdb WordPress database object
     181 * @return string Filtered database prefix
     182 */
     183function bp_core_get_table_prefix() {
     184    global $wpdb;
     185
     186    return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
     187}
     188
     189/**
    171190 * bp_core_define_slugs()
    172191 *
     
    188207    if ( !defined( 'BP_ACTIVATION_SLUG' ) )
    189208        define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );
     209
     210    if ( !defined( 'BP_SEARCH_SLUG' ) )
     211        define( 'BP_SEARCH_SLUG', 'search' );
    190212}
    191213add_action( 'bp_setup_globals', 'bp_core_define_slugs' );
     
    231253}
    232254
    233 
    234255/**
    235256 * bp_core_admin_menu_init()
     
    238259 *
    239260 * @package BuddyPress Core
    240  * @uses is_site_admin() returns true if the current user is a site admin, false if not
     261 * @uses is_super_admin() returns true if the current user is a site admin, false if not
    241262 */
    242263function bp_core_admin_menu_init() {
    243     if ( !is_site_admin() )
     264    if ( !is_super_admin() )
    244265        return false;
    245266
     
    255276 * @package BuddyPress Core
    256277 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    257  * @global $wpdb WordPress DB access object.
    258  * @uses is_site_admin() returns true if the current user is a site admin, false if not
     278 * @uses is_super_admin() returns true if the current user is a site admin, false if not
    259279 * @uses add_submenu_page() WP function to add a submenu item
    260280 */
    261281function bp_core_add_admin_menu() {
    262     if ( !is_site_admin() )
     282    if ( !is_super_admin() )
    263283        return false;
    264284
     
    280300add_action( 'admin_menu', 'bp_core_add_admin_menu' );
    281301
     302/**
     303 * bp_core_is_root_component()
     304 *
     305 * Checks to see if a component's URL should be in the root, not under a member page:
     306 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
     307 *
     308 * @package BuddyPress Core
     309 * @return true if root component, else false.
     310 */
     311function bp_core_is_root_component( $component_name ) {
     312    global $bp;
     313
     314    foreach ( (array) $bp->pages as $key => $page ) {
     315        if ( $key == $component_name || $page->slug == $component_name )
     316            return true;
     317    }
     318
     319    return false;
     320}
    282321
    283322/**
     
    380419 */
    381420function bp_core_action_set_spammer_status() {
    382     global $bp, $wpdb;
    383 
    384     if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
     421    global $bp, $wpdb, $wp_version;
     422
     423    if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
    385424        return false;
    386425
     
    390429
    391430        /* Get the functions file */
    392         if ( file_exists( ABSPATH . 'wp-admin/includes/mu.php' ) && bp_core_is_multisite() )
    393             require( ABSPATH . 'wp-admin/includes/mu.php' );
     431        if ( bp_core_is_multisite() )
     432            require_once( ABSPATH . 'wp-admin/includes/ms.php' );
    394433
    395434        if ( 'mark-spammer' == $bp->current_action )
     
    446485    global $bp;
    447486
    448     if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
     487    if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
    449488        return false;
    450489
     
    462501        }
    463502
    464         do_action( 'bp_core_action_set_spammer_status', $errors );
     503        do_action( 'bp_core_action_delete_user', $errors );
    465504
    466505        if ( $errors )
     
    472511add_action( 'wp', 'bp_core_action_delete_user', 3 );
    473512
     513
    474514/********************************************************************************
    475515 * Business Functions
     
    496536        'search_terms' => false, // Limit to users that match these search terms
    497537
     538        'include' => false, // Pass comma separated list of user_ids to limit to only these users
    498539        'per_page' => 20, // The number of results to return per page
    499540        'page' => 1, // The page to return if limiting per page
     
    504545    extract( $params, EXTR_SKIP );
    505546
    506     return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $search_terms, $populate_extras ), &$params );
     547    return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
    507548}
    508549
     
    516557 * @global $current_user WordPress global variable containing current logged in user information
    517558 * @param user_id The ID of the user.
    518  * @uses get_usermeta() WordPress function to get the usermeta for a user.
     559 * @uses get_user_meta() WordPress function to get the usermeta for a user.
    519560 */
    520561function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
     
    574615
    575616    if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
    576         $domain = get_blog_option( $current_blog->blog_id, 'siteurl' );
     617        $domain = get_blog_option( $current_blog->blog_id, 'home' );
    577618    else
    578         $domain = get_blog_option( BP_ROOT_BLOG, 'siteurl' );
     619        $domain = get_blog_option( BP_ROOT_BLOG, 'home' );
    579620
    580621    return apply_filters( 'bp_core_get_root_domain', $domain );
     
    626667
    627668    /* If this is for site admins only and the user is not one, don't create the subnav item */
    628     if ( $site_admin_only && !is_site_admin() )
     669    if ( $site_admin_only && !is_super_admin() )
    629670        return false;
    630671
     
    647688     * looking at their own profile, don't create the nav item.
    648689     */
    649     if ( !$show_for_displayed_user && !bp_is_my_profile() )
     690    if ( !$show_for_displayed_user && !bp_user_has_access() )
    650691        return false;
    651692
     
    654695     * default subnav function so we can display a directory or something else.
    655696     */
    656     if ( !$bp->displayed_user->id )
     697    if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
    657698        return;
    658699
     
    773814
    774815    /* If this is for site admins only and the user is not one, don't create the subnav item */
    775     if ( $site_admin_only && !is_site_admin() )
     816    if ( $site_admin_only && !is_super_admin() )
    776817        return false;
    777818
     
    868909    global $bp;
    869910
    870     if ( $function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) {
    871         if ( !is_object( $function[0] ) )
    872             remove_action( 'wp', $function, 3 );
     911    $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
     912
     913    if ( $screen_function ) {
     914        if ( !is_object( $screen_function[0] ) )
     915            remove_action( 'wp', $screen_function, 3 );
    873916        else
    874             remove_action( 'wp', array( &$function[0], $function[1] ), 3 );
     917            remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
    875918    }
    876919
     
    898941/**
    899942 * bp_core_get_random_member()
     943 *
     944 * Returns the user_id for a user based on their username.
     945 *
     946 * @package BuddyPress Core
     947 * @param $username str Username to check.
     948 * @return false on no match
     949 * @return int the user ID of the matched user.
     950 */
     951function bp_core_get_random_member() {
     952    global $bp;
     953
     954    if ( isset( $_GET['random-member'] ) ) {
     955        $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
     956        bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
     957    }
     958}
     959add_action( 'wp', 'bp_core_get_random_member' );
     960
     961/**
     962 * bp_core_get_userid()
    900963 *
    901964 * Returns the user_id for a user based on their username.
     
    907970 * @return int the user ID of the matched user.
    908971 */
    909 function bp_core_get_random_member() {
    910     global $bp, $wpdb;
    911 
    912     if ( isset( $_GET['random-member'] ) ) {
    913         $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
    914         bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
    915     }
    916 }
    917 add_action( 'wp', 'bp_core_get_random_member' );
    918 
    919 /**
    920  * bp_core_get_userid()
    921  *
    922  * Returns the user_id for a user based on their username.
    923  *
    924  * @package BuddyPress Core
    925  * @param $username str Username to check.
    926  * @global $wpdb WordPress DB access object.
    927  * @return false on no match
    928  * @return int the user ID of the matched user.
    929  */
    930972function bp_core_get_userid( $username ) {
    931973    global $wpdb;
    932974
    933     if ( !empty( $username ) )
    934         return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
     975    if ( empty( $username ) )
     976        return false;
     977
     978    return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
    935979}
    936980
     
    11191163    }
    11201164
    1121     return apply_filters( 'bp_core_get_user_displayname', $fullname );
     1165    return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );
    11221166}
    11231167add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
     
    12151259
    12161260/**
    1217  * bp_core_format_time()
    1218  */
    1219 function bp_core_format_time( $time, $just_date = false ) {
    1220     if ( !$time )
    1221         return false;
    1222 
    1223     $date = date( "F j, Y ", $time );
    1224 
    1225     if ( !$just_date ) {
    1226         $date .= __('at', 'buddypress') . date( ' g:iA', $time );
    1227     }
    1228 
    1229     return $date;
     1261 * bp_core_current_time()
     1262 *
     1263 * Get the current GMT time to save into the DB
     1264 *
     1265 * @package BuddyPress Core
     1266 * @since 1.2.6
     1267 */
     1268function bp_core_current_time( $gmt = true ) {
     1269    // Get current time in MYSQL format
     1270    $current_time = current_time( 'mysql', $gmt );
     1271
     1272    return apply_filters( 'bp_core_current_time', $current_time );
    12301273}
    12311274
     
    12831326    @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
    12841327}
    1285 add_action( 'bp_init', 'bp_core_setup_message' );
    1286 
     1328add_action( 'wp', 'bp_core_setup_message', 2 );
    12871329
    12881330/**
     
    13021344    ?>
    13031345        <div id="message" class="<?php echo $type; ?>">
    1304             <p><?php echo stripslashes( attribute_escape( $bp->template_message ) ); ?></p>
     1346            <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>
    13051347        </div>
    13061348    <?php
     
    13261368 */
    13271369function bp_core_time_since( $older_date, $newer_date = false ) {
     1370
    13281371    // array of time period chunks
    13291372    $chunks = array(
    1330     array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
    1331     array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
    1332     array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
    1333     array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
    1334     array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
    1335     array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
    1336     array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
     1373        array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
     1374        array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
     1375        array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
     1376        array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
     1377        array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
     1378        array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
     1379        array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
    13371380    );
    13381381
     
    13461389    /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
    13471390    /* $newer_date will have a value if we want to work out time elapsed between two known dates */
    1348     $newer_date = ( !$newer_date ) ? gmmktime( gmdate( 'H' ), gmdate( 'i' ), gmdate( 's' ), gmdate( 'n' ), gmdate( 'j' ), gmdate( 'Y' ) ) : $newer_date;
     1391    $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
    13491392
    13501393    /* Difference in seconds */
     
    13811424        if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
    13821425            /* Add to output var */
    1383             $output .= ( 1 == $count2 ) ? _c( ',|Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _c( ',|Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
     1426            $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
    13841427        }
    13851428    }
     
    14011444 * @package BuddyPress Core
    14021445 * @global $userdata WordPress user data for the current logged in user.
    1403  * @uses update_usermeta() WordPress function to update user metadata in the usermeta table.
     1446 * @uses update_user_meta() WordPress function to update user metadata in the usermeta table.
    14041447 */
    14051448function bp_core_record_activity() {
     
    14091452        return false;
    14101453
    1411     $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' );
     1454    $activity = get_user_meta( $bp->loggedin_user->id, 'last_activity', true );
    14121455
    14131456    if ( !is_numeric( $activity ) )
    14141457        $activity = strtotime( $activity );
    14151458
    1416     if ( '' == $activity || strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+5 minutes', $activity ) )
    1417         update_usermeta( $bp->loggedin_user->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     1459    // Get current time
     1460    $current_time = bp_core_current_time();
     1461
     1462    if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
     1463        update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time );
    14181464}
    14191465add_action( 'wp_head', 'bp_core_record_activity' );
     
    14461492        return $number;
    14471493
    1448     return apply_filters( 'bp_core_bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
     1494    return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
    14491495}
    14501496
     
    14741520 *
    14751521 * @package BuddyPress Core
    1476  * @global $comment WordPress comment global for the current comment.
    1477  * @uses bp_core_get_userlink_by_email() Fetches a userlink via email address.
     1522 *
     1523 * @global $bp $bp
     1524 * @global object $current_site
     1525 * @return string
    14781526 */
    14791527function bp_core_get_site_path() {
     
    14931541            unset( $site_path[2] );
    14941542
    1495             $site_path = '/' . implode( '/', $site_path ) . '/';
     1543            if ( !count( $site_path ) )
     1544                $site_path = '/';
     1545            else
     1546                $site_path = '/' . implode( '/', $site_path ) . '/';
    14961547        }
    14971548    }
     
    15361587
    15371588    if ( bp_core_is_multisite() )
    1538         $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys})" );
     1589        $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );
    15391590    else
    15401591        $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
     
    15631614
    15641615    // Make sure we don't call status_header() in bp_core_do_catch_uri()
    1565     // as this conflicts with wp_redirect()
     1616    // as this conflicts with wp_redirect()
    15661617    $bp_no_status_set = true;
    15671618
     
    16161667
    16171668/**
    1618  * bp_core_email_from_name_filter()
    1619  *
    1620  * Sets the "From" name in emails sent to the name of the site and not "WordPress"
    1621  *
    1622  * @package BuddyPress Core
    1623  * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
    1624  * @return The blog name for the root blog
    1625  */
    1626 function bp_core_email_from_name_filter() {
    1627     return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
    1628 }
    1629 add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
    1630 
    1631 
    1632 /**
    1633  * bp_core_email_from_name_filter()
    1634  *
    1635  * Sets the "From" address in emails sent
    1636  *
    1637  * @package BuddyPress Core
    1638  * @global $current_site Object containing current site metadata
    1639  * @return noreply@sitedomain email address
    1640  */
    1641 function bp_core_email_from_address_filter() {
    1642     $domain = (array) explode( '/', site_url() );
    1643 
    1644     return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
    1645 }
    1646 add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
    1647 
    1648 /**
    16491669 * bp_core_delete_account()
    16501670 *
     
    16531673 * @package BuddyPress Core
    16541674 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    1655  * @uses is_site_admin() Checks to see if the user is a site administrator.
     1675 * @uses is_super_admin() Checks to see if the user is a site administrator.
    16561676 * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
    16571677 * @uses wp_delete_user() Deletes a user from the system on singlesite installs.
     
    17441764function bp_core_ucfirst( $str ) {
    17451765    if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
    1746         $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
    1747         return $fc.mb_substr( $str, 1 );
     1766        $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
     1767        return $fc.mb_substr( $str, 1 );
    17481768    } else {
    17491769        return ucfirst( $str );
     
    17921812 */
    17931813function bp_core_print_generation_time() {
    1794     global $wpdb;
    1795     ?>
     1814?>
    17961815
    17971816<!-- Generated in <?php timer_stop(1); ?> seconds. (<?php echo get_num_queries(); ?> q) -->
     
    18661885    $user = get_userdatabylogin( $username );
    18671886
    1868     if ( (int)$user->spam )
     1887    if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
    18691888        bp_core_redirect( $bp->root_domain );
    18701889    else
     
    18801899 * @package BuddyPress Core
    18811900 * @param $user_id The user id for the user to delete usermeta for
    1882  * @uses delete_usermeta() deletes a row from the wp_usermeta table based on meta_key
     1901 * @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key
    18831902 */
    18841903function bp_core_remove_data( $user_id ) {
    18851904    /* Remove usermeta */
    1886     delete_usermeta( $user_id, 'last_activity' );
     1905    delete_user_meta( $user_id, 'last_activity' );
    18871906
    18881907    /* Flush the cache to remove the user from all cached objects */
    18891908    wp_cache_flush();
    18901909}
    1891 add_action( 'wpmu_delete_user', 'bp_core_remove_data', 1 );
    1892 add_action( 'delete_user', 'bp_core_remove_data', 1 );
    1893 add_action( 'make_spam_user', 'bp_core_remove_data', 1 );
     1910add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
     1911add_action( 'delete_user', 'bp_core_remove_data' );
     1912add_action( 'make_spam_user', 'bp_core_remove_data' );
    18941913
    18951914/**
     
    19071926        load_textdomain( 'buddypress', $mofile );
    19081927}
    1909 add_action ( 'plugins_loaded', 'bp_core_load_buddypress_textdomain', 5 );
     1928add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 );
    19101929
    19111930function bp_core_add_ajax_hook() {
     
    19291948
    19301949/**
    1931  * bp_core_filter_parent_theme()
    1932  *
    1933  * Remove social network parent theme from the theme list.
    1934  *
    1935  * @package BuddyPress Core
    1936  */
    1937 function bp_core_filter_parent_theme() {
    1938     global $wp_themes, $pagenow;
    1939 
    1940     if ( is_admin() && 'themes.php' == $pagenow )
    1941         $wp_themes = get_themes();
    1942 
    1943     unset( $wp_themes['BuddyPress Classic Parent'] );
    1944 }
    1945 add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
    1946 
    1947 /**
    1948  * bp_core_allow_default_theme()
    1949  *
    1950  * On multiblog installations you must first allow themes to be activated and show
    1951  * up on the theme selection screen. This function will let the BuddyPress bundled
    1952  * themes show up on the root blog selection screen and bypass this step. It also
    1953  * means that the themes won't show for selection on other blogs.
    1954  *
    1955  * @package BuddyPress Core
    1956  */
    1957 function bp_core_allow_default_theme( $themes ) {
    1958     global $bp, $current_blog;
    1959 
    1960     if ( !is_site_admin() )
    1961         return $themes;
    1962 
    1963     if ( $current_blog->ID == $bp->root_blog ) {
    1964         $themes['bp-default'] = 1;
    1965         $themes['bp-classic'] = 1;
    1966     }
    1967 
    1968     return $themes;
    1969 }
    1970 add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
    1971 
    1972 /**
    19731950 * bp_core_activation_notice()
    19741951 *
     
    19851962        return false;
    19861963
    1987     if ( !is_site_admin() )
     1964    if ( !is_super_admin() )
    19881965        return false;
    19891966
     
    20111988add_action( 'admin_notices', 'bp_core_activation_notice' );
    20121989
    2013 
    2014 /**
    2015  * bp_core_filter_comments()
    2016  *
    2017  * Filter the blog post comments array and insert BuddyPress URLs for users.
    2018  *
    2019  * @package BuddyPress Core
    2020  */
    2021 function bp_core_filter_comments( $comments, $post_id ) {
    2022     global $wpdb;
    2023 
    2024     foreach( (array)$comments as $comment ) {
    2025         if ( $comment->user_id )
    2026             $user_ids[] = $comment->user_id;
    2027     }
    2028 
    2029     if ( empty( $user_ids ) )
    2030         return $comments;
    2031 
    2032     $user_ids = implode( ',', $user_ids );
    2033 
    2034     if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
    2035         return $comments;
    2036 
    2037     foreach( (array)$userdata as $user )
    2038         $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
    2039 
    2040     foreach( (array)$comments as $i => $comment ) {
    2041         if ( !empty( $comment->user_id ) ) {
    2042             if ( !empty( $users[$comment->user_id] ) )
    2043                 $comments[$i]->comment_author_url = $users[$comment->user_id];
     1990/**
     1991 * bp_core_activate_site_options()
     1992 *
     1993 * When switching from single to multisite we need to copy blog options to
     1994 * site options.
     1995 *
     1996 * @package BuddyPress Core
     1997 */
     1998function bp_core_activate_site_options( $keys = array() ) {
     1999    global $bp;
     2000
     2001    if ( !empty( $keys ) && is_array( $keys ) ) {
     2002        $errors = false;
     2003
     2004        foreach ( $keys as $key => $default ) {
     2005            if ( empty( $bp->site_options[ $key ] ) ) {
     2006                $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
     2007
     2008                if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
     2009                    $errors = true;
     2010            }
    20442011        }
    2045     }
    2046 
    2047     return $comments;
    2048 }
    2049 add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
    2050 
    2051 
    2052 /**
    2053  * bp_core_login_redirect()
    2054  *
    2055  * When a user logs in, always redirect them back to the previous page. NOT the admin area.
    2056  *
    2057  * @package BuddyPress Core
    2058  */
    2059 function bp_core_login_redirect( $redirect_to ) {
    2060     global $bp, $current_blog;
    2061 
    2062     if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
    2063         return $redirect_to;
    2064 
    2065     if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
    2066         return $redirect_to;
    2067 
    2068     if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
    2069         return wp_get_referer();
    2070 
    2071     return $bp->root_domain;
    2072 }
    2073 add_filter( 'login_redirect', 'bp_core_login_redirect' );
    2074 
     2012
     2013        if ( empty( $errors ) )
     2014            return true;
     2015    }
     2016
     2017    return false;
     2018}
    20752019
    20762020/********************************************************************************
     
    20802024 * hook in to.
    20812025 */
    2082 
    2083 /* Allow core components and dependent plugins to set globals */
     2026 
     2027/**
     2028 * bp_include()
     2029 *
     2030 * Allow plugins to include their files ahead of core filters
     2031 */
     2032function bp_include() {
     2033    do_action( 'bp_include' );
     2034}
     2035add_action( 'bp_loaded', 'bp_include', 2 );
     2036
     2037/**
     2038 * bp_setup_root_components()
     2039 *
     2040 * Allow core components and dependent plugins to set root components
     2041 */
     2042function bp_setup_root_components() {
     2043    do_action( 'bp_setup_root_components' );
     2044}
     2045add_action( 'bp_loaded', 'bp_setup_root_components', 2 );
     2046
     2047/**
     2048 * bp_setup_globals()
     2049 *
     2050 * Allow core components and dependent plugins to set globals
     2051 */
    20842052function bp_setup_globals() {
    20852053    do_action( 'bp_setup_globals' );
    20862054}
    2087 add_action( 'plugins_loaded', 'bp_setup_globals', 5 );
    2088 
    2089 /* Allow core components and dependent plugins to set root components */
    2090 function bp_setup_root_components() {
    2091     do_action( 'bp_setup_root_components' );
    2092 }
    2093 add_action( 'plugins_loaded', 'bp_setup_root_components', 2 );
    2094 
    2095 /* Allow core components and dependent plugins to set their nav */
     2055add_action( 'bp_loaded', 'bp_setup_globals', 6 );
     2056
     2057/**
     2058 * bp_setup_nav()
     2059 *
     2060 * Allow core components and dependent plugins to set their nav
     2061 */
    20962062function bp_setup_nav() {
    20972063    do_action( 'bp_setup_nav' );
     
    20992065add_action( 'bp_loaded', 'bp_setup_nav', 8 );
    21002066
    2101 /* Allow core components and dependent plugins to register widgets */
     2067/**
     2068 * bp_setup_widgets()
     2069 *
     2070 * Allow core components and dependent plugins to register widgets
     2071 */
    21022072function bp_setup_widgets() {
    21032073    do_action( 'bp_register_widgets' );
    21042074}
    2105 add_action( 'plugins_loaded', 'bp_setup_widgets' );
     2075add_action( 'bp_loaded', 'bp_setup_widgets', 8 );
     2076
     2077/**
     2078 * bp_init()
     2079 *
     2080 * Allow components to initialize themselves cleanly
     2081 */
     2082function bp_init() {
     2083    do_action( 'bp_init' );
     2084}
     2085add_action( 'bp_loaded', 'bp_init' );
    21062086
    21072087
     
    21122092 * actions throughout BuddyPress.
    21132093 */
     2094
     2095/**
     2096 * bp_core_add_global_group()
     2097 *
     2098 * Add's 'bp' to global group of network wide cachable objects
     2099 *
     2100 * @package BuddyPress Core
     2101 */
     2102function bp_core_add_global_group() {
     2103    wp_cache_init();
     2104
     2105    if ( function_exists( 'wp_cache_add_global_groups' ) )
     2106        wp_cache_add_global_groups( array( 'bp' ) );
     2107}
     2108add_action( 'init', 'bp_core_add_global_group' );
    21142109
    21152110/**
     
    21842179    update_site_option( 'bp-pages', $page_ids );
    21852180}
    2186 
    2187 function bp_core_is_root_component( $component_name ) {
    2188     global $bp;
    2189 
    2190     foreach ( (array) $bp->pages as $key => $page ) {
    2191         if ( $key == $component_name || $page->slug == $component_name )
    2192             return true;
    2193     }
    2194 
    2195     return false;
    2196 }
    2197 
    21982181?>
  • trunk/bp-core/bp-core-adminbar.php

    r3232 r3300  
    109109    }
    110110
    111     echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">';
     111    echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/">';
    112112
    113113    _e( 'My Blogs', 'buddypress' );
  • trunk/bp-core/bp-core-avatars.php

    r3232 r3300  
    479479function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
    480480    global $pagenow;
    481 
     481   
    482482    // Do not filter if inside WordPress options page
    483483    if ( 'options-discussion.php' == $pagenow )
    484484        return $avatar;
    485 
     485   
    486486    // If passed an object, assume $user->user_id
    487487    if ( is_object( $user ) )
  • trunk/bp-core/bp-core-catchuri.php

    r3234 r3300  
    4343    }
    4444
     45    // Ajax or not?
    4546    if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
    4647        $path = bp_core_referrer();
    4748    else
    48         $path = clean_url( $_SERVER['REQUEST_URI'] );
     49        $path = esc_url( $_SERVER['REQUEST_URI'] );
    4950
    5051    $path = apply_filters( 'bp_uri', $path );
    5152
    52     // Firstly, take GET variables off the URL to avoid problems,
    53     // they are still registered in the global $_GET variable */
     53    // Take GET variables off the URL to avoid problems,
     54    // they are still registered in the global $_GET variable
    5455    $noget = substr( $path, 0, strpos( $path, '?' ) );
    55     if ( $noget != '' ) $path = $noget;
    56 
    57     /* Fetch the current URI and explode each part separated by '/' into an array */
     56    if ( $noget != '' )
     57        $path = $noget;
     58
     59    // Fetch the current URI and explode each part separated by '/' into an array
    5860    $bp_uri = explode( "/", $path );
    5961
    60     /* Loop and remove empties */
     62    // Loop and remove empties
    6163    foreach ( (array)$bp_uri as $key => $uri_chunk )
    6264        if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
    6365
    64     if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
    65         /* If we are running BuddyPress on any blog, not just a root blog, we need to first
    66            shift off the blog name if we are running a subdirectory install of WPMU. */
    67         if ( $current_blog->path != '/' )
    68             array_shift( $bp_uri );
    69     }
    70 
    71     /* Set the indexes, these are incresed by one if we are not on a VHOST install */
    72     $component_index = 0;
    73     $action_index = $component_index + 1;
    74 
    75     /* Get site path items */
     66    // Running off blog other than root
     67    if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
     68 
     69        // Any subdirectory names must be removed from $bp_uri.
     70        // This includes two cases: (1) when WP is installed in a subdirectory,
     71        // and (2) when BP is running on secondary blog of a subdirectory
     72        // multisite installation. Phew!
     73        if ( $chunks = explode( '/', $current_blog->path ) ) {
     74            foreach( $chunks as $key => $chunk ) {
     75                $bkey = array_search( $chunk, $bp_uri );
     76 
     77                if ( $bkey !== false )
     78                    unset( $bp_uri[$bkey] );
     79 
     80                $bp_uri = array_values( $bp_uri );
     81            }
     82        }
     83    }
     84
     85    // Set the indexes, these are incresed by one if we are not on a VHOST install
     86    $component_index    = 0;
     87    $action_index       = $component_index + 1;
     88
     89    // Get site path items
    7690    $paths = explode( '/', bp_core_get_site_path() );
    7791
    78     /* Take empties off the end of path */
     92    // Take empties off the end of path
    7993    if ( empty( $paths[count($paths) - 1] ) )
    8094        array_pop( $paths );
    8195
    82     /* Take empties off the start of path */
     96    // Take empties off the start of path
    8397    if ( empty( $paths[0] ) )
    8498        array_shift( $paths );
     
    90104    }
    91105
    92     /* Reset the keys by merging with an empty array */
    93     $bp_uri = array_merge( array(), $bp_uri );
    94     $bp_unfiltered_uri = $bp_uri;
    95 
    96     /* Find a match within registered BuddyPress controlled WP pages (check members first) */
     106    // Reset the keys by merging with an empty array
     107    $bp_uri             = array_merge( array(), $bp_uri );
     108    $bp_unfiltered_uri  = $bp_uri;
     109
     110    // Find a match within registered BuddyPress controlled WP pages (check members first)
    97111    foreach ( (array)$bp_pages as $page_key => $bp_page ) {
    98112        if ( in_array( $bp_page->name, (array)$bp_uri ) ) {
    99             /* Match found, now match the slug to make sure. */
     113            // Match found, now match the slug to make sure.
    100114            $uri_chunks = explode( '/', $bp_page->slug );
    101115
     
    120134    }
    121135
    122     /* This is not a BuddyPress page, so just return. */
     136    // This is not a BuddyPress page, so just return.
    123137    if ( in_array( 0, (array) $matches ) )
    124138        return false;
    125139
    126     /* Find the offset */
     140    // Find the offset
    127141    $uri_offset = 0;
    128142    $slug = explode( '/', $match->slug );
     
    133147    }
    134148
    135     /* Global the unfiltered offset to use in bp_core_load_template() */
     149    // Global the unfiltered offset to use in bp_core_load_template()
    136150    $bp_unfiltered_uri_offset = $uri_offset;
    137151
    138     /* This is a members page so lets check if we have a displayed member */
     152    // This is a members page so lets check if we have a displayed member
    139153    if ( 'members' == $match->key ) {
    140154        if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
     
    146160            $uri_offset = $uri_offset + 2;
    147161
    148             /* Remove everything from the URI up to the offset and take it from there. */
     162            // Remove everything from the URI up to the offset and take it from there.
    149163            for ( $i = 0; $i < $uri_offset; $i++ )
    150164                unset( $bp_uri[$i] );
     
    154168    }
    155169
    156     /* Reset the keys by merging with an empty array */
     170    // Reset the keys by merging with an empty array
    157171    $bp_uri = array_merge( array(), $bp_uri );
    158172
    159     /* Set the current component */
     173    // Set the current component
    160174    if ( empty( $current_component ) ) {
    161175        for ( $i = 0; $i <= $uri_offset; $i++ ) {
     
    170184        $i = 1;
    171185
    172     /* Set the current action */
     186    // Set the current action
    173187    $current_action = $bp_uri[$i];
    174188
    175     /* Unset the current_component and action from action_variables */
     189    // Unset the current_component and action from action_variables
    176190    for ( $j = 0; $j <= $i; $j++ )
    177191        unset( $bp_uri[$j] );
    178192
    179     /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
     193    // Set the entire URI as the action variables, we will unset the current_component and action in a second
    180194    $action_variables = $bp_uri;
    181195
    182     /* Remove the username from action variables if this is not a VHOST install */
     196    // Remove the username from action variables if this is not a VHOST install
    183197    if ( 'no' == VHOST && !$is_root_component )
    184198        array_shift($bp_uri);
    185199
    186     /* Reset the keys by merging with an empty array */
     200    // Reset the keys by merging with an empty array
    187201    $action_variables = array_merge( array(), $action_variables );
    188 
    189     //var_dump($current_component, $current_action, $bp_uri);
    190202}
    191 add_action( 'plugins_loaded', 'bp_core_set_uri_globals', 3 );
     203add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
    192204
    193205/**
  • trunk/bp-core/bp-core-classes.php

    r3267 r3300  
    5151     * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
    5252     * @uses bp_core_get_user_email() Returns the email address for the user based on user ID
    53      * @uses get_usermeta() WordPress function returns the value of passed usermeta name from usermeta table
     53     * @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table
    5454     * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user
    5555     * @uses bp_profile_last_updated_date() Returns the last updated date for a user.
     
    6161        if ( $this->profile_data ) {
    6262            $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
    63             $this->fullname = attribute_escape( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );
     63            $this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );
    6464            $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>";
    65             $this->email = attribute_escape( $this->profile_data['user_email'] );
     65            $this->email = esc_attr( $this->profile_data['user_email'] );
    6666        } else {
    6767            $this->user_url = bp_core_get_user_domain( $this->id );
    6868            $this->user_link = bp_core_get_userlink( $this->id );
    69             $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );
    70             $this->email = attribute_escape( bp_core_get_user_email( $this->id ) );
     69            $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) );
     70            $this->email = esc_attr( bp_core_get_user_email( $this->id ) );
    7171        }
    7272
     
    8080        $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
    8181
    82         $this->last_active = bp_core_get_last_activity( get_usermeta( $this->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) );
     82        $this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) );
    8383    }
    8484
     
    107107    /* Static Functions */
    108108
    109     function get_users( $type, $limit = null, $page = 1, $user_id = false, $search_terms = false, $populate_extras = true ) {
     109    function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) {
    110110        global $wpdb, $bp;
    111111
    112112        $sql = array();
    113113
    114         $sql['select_main'] = "SELECT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
     114        $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
    115115
    116116        if ( 'active' == $type || 'online' == $type )
     
    125125        $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
    126126
     127        if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
     128            $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
     129
    127130        $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
    128131
     
    134137
    135138        if ( 'online' == $type )
    136             $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= NOW()";
     139            $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
    137140
    138141        if ( 'alphabetical' == $type )
    139142            $sql['where_alpha'] = "AND pd.field_id = 1";
    140143
    141         if ( $user_id && function_exists( 'friends_install' ) ) {
     144        if ( $include ) {
     145            if ( is_array( $include ) )
     146                $uids = $wpdb->escape( implode( ',', (array)$include ) );
     147            else
     148                $uids = $wpdb->escape( $include );
     149
     150            if ( !empty( $uids ) )
     151                $sql['where_users'] = "AND u.ID IN ({$uids})";
     152        }
     153
     154        else if ( $user_id && function_exists( 'friends_install' ) ) {
    142155            $friend_ids = friends_get_friend_user_ids( $user_id );
    143156            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
     
    151164        }
    152165
    153         if ( $search_terms ) {
     166        if ( $search_terms && function_exists( 'xprofile_install' ) ) {
    154167            $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    155             $sql['where_searchterms'] = "AND u.display_name LIKE '%%$search_terms%%'";
     168            $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
    156169        }
    157170
     
    164177                break;
    165178            case 'alphabetical':
    166                 $sql[] = "ORDER BY u.display_name ASC";
     179                $sql[] = "ORDER BY pd.value ASC";
    167180                break;
    168181            case 'random':
     
    178191
    179192        /* Get paginated results */
    180         $paged_users = $wpdb->get_results( join( ' ', (array)$sql ) );
     193        $paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array)$sql ), $sql );
     194        $paged_users     = $wpdb->get_results( $paged_users_sql );
    181195
    182196        /* Re-jig the SQL so we can get the total user count */
     
    198212
    199213        /* Get total user results */
    200         $total_users = $wpdb->get_var( join( ' ', (array)$sql ) );
     214        $total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array)$sql ), $sql );
     215        $total_users     = $wpdb->get_var( $total_users_sql );
    201216
    202217        /***
     
    223238            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    224239
    225         if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
    226             return false;
     240        // Multibyte compliance
     241        if ( function_exists( 'mb_strlen' ) ) {
     242            if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
     243                return false;
     244            }
     245        } else {
     246            if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) {
     247                return false;
     248            }
     249        }
    227250
    228251        $letter = like_escape( $wpdb->escape( $letter ) );
     
    318341        /* Fetch the user's full name */
    319342        if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
     343            /* Ensure xprofile globals are set */
     344            if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
     345                xprofile_setup_globals();
     346
    320347            $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 ) );
    321348            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     
    436463        if ( $this->id ) {
    437464            // Update
    438             $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = FROM_UNIXTIME(%d), is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
     465            $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
    439466        } else {
    440467            // Save
    441             $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
     468            $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
    442469        }
    443470
  • trunk/bp-core/bp-core-cssjs.php

    r3280 r3300  
    3939    <style type="text/css">
    4040        ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo BP_PLUGIN_URL . '/bp-core/images/admin_menu_icon.png' ?> ) !important; background-position: -1px -32px; }
    41         ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a { background-position: -1px 0; }
     41        ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a, ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a { background-position: -1px 0; }
    4242        ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
    4343    </style>
     
    5050    global $current_blog;
    5151
    52     if ( $current_blog->blog_id != BP_ROOT_BLOG )
     52    if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
    5353        return false;
    5454?>
     
    8383    global $bp;
    8484
    85     $image = apply_filters( 'bp_inline_cropper_image', getimagesize( $bp->avatar_admin->image->dir ) );
     85    $image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) );
    8686    $aspect_ratio = 1;
    8787
    88     /* Calculate Aspect Ratio */
     88    // Calculate Aspect Ratio
    8989    if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
    9090        $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
  • trunk/bp-core/bp-core-filters.php

    r2941 r3300  
    3333 */
    3434function bp_core_email_from_name_filter() {
    35     return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
     35    return apply_filters( 'bp_core_email_from_name_filter', wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ) );
    3636}
    3737add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
     
    6666    global $bp, $current_blog;
    6767
    68     if ( !is_site_admin() )
     68    if ( !is_super_admin() )
    6969        return $themes;
    7070
     
    142142 * Replace the generated password in the welcome email.
    143143 * This will not filter when the site admin registers a user.
     144 *
     145 * @uses locate_template To see if custom registration files exist
     146 * @param string $welcome_email Complete email passed through WordPress
     147 * @return string Filtered $welcome_email with 'PASSWORD' replaced by [User Set]
    144148 */
    145149function bp_core_filter_user_welcome_email( $welcome_email ) {
     
    148152        return $welcome_email;
    149153
     154    // [User Set] Replaces 'PASSWORD' in welcome email; Represents value set by user
    150155    return str_replace( 'PASSWORD', __( '[User Set]', 'buddypress' ), $welcome_email );
    151156}
     
    158163 * Replace the generated password in the welcome email.
    159164 * This will not filter when the site admin registers a user.
     165 *
     166 * @uses locate_template To see if custom registration files exist
     167 * @param string $welcome_email Complete email passed through WordPress
     168 * @param integer $blog_id ID of the blog user is joining
     169 * @param integer $user_id ID of the user joining
     170 * @param string $password Password of user
     171 * @return string Filtered $welcome_email with $password replaced by [User Set]
    160172 */
    161173function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) {
     
    164176        return $welcome_email;
    165177
     178    // [User Set] Replaces $password in welcome email; Represents value set by user
    166179    return str_replace( $password, __( '[User Set]', 'buddypress' ), $welcome_email );
    167180}
     
    175188    // Send email with activation link.
    176189    $activate_url = bp_get_activation_page() ."?key=$key";
    177     $activate_url = clean_url($activate_url);
     190    $activate_url = esc_url($activate_url);
    178191
    179192    $admin_email = get_site_option( "admin_email" );
     
    184197    $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
    185198    $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    186     $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s", 'buddypress' ), $activate_url, clean_url("http://{$domain}{$path}" ) );
    187     $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), clean_url('http://' . $domain . $path));
     199    $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s", 'buddypress' ), $activate_url, esc_url("http://{$domain}{$path}" ) );
     200    $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), esc_url('http://' . $domain . $path));
    188201
    189202    /* Send the message */
     
    204217
    205218    $activate_url = bp_get_activation_page() ."?key=$key";
    206     $activate_url = clean_url($activate_url);
     219    $activate_url = esc_url($activate_url);
    207220    $admin_email = get_site_option( "admin_email" );
    208221
     
    216229    $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
    217230    $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    218     $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, clean_url("http://{$domain}{$path}" ) );
     231    $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, esc_url( "http://{$domain}{$path}" ) );
    219232    $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
    220233
  • trunk/bp-core/bp-core-notifications.php

    r2576 r3300  
    55
    66    if ( !$date_notified )
    7         $date_notified = time();
     7        $date_notified = bp_core_current_time();
    88
    99    $notification = new BP_Core_Notification;
  • trunk/bp-core/bp-core-settings.php

    r2717 r3300  
    2222    bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
    2323
    24     if ( !is_site_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )
     24    if ( !is_super_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )
    2525        bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) );
    2626}
    27 add_action( 'wp', 'bp_core_add_settings_nav', 2 );
    28 add_action( 'admin_menu', 'bp_core_add_settings_nav', 2 );
     27add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' );
    2928
    3029/**** GENERAL SETTINGS ****/
     
    8887    <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
    8988        <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
    90         <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />
     89        <input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" />
    9190
    9291        <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
     
    9594
    9695        <div class="submit">
    97             <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     96            <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
    9897        </div>
    9998
     
    115114        if ( $_POST['notifications'] ) {
    116115            foreach ( (array)$_POST['notifications'] as $key => $value ) {
    117                 update_usermeta( (int)$current_user->id, $key, $value );
     116                update_user_meta( (int)$current_user->id, $key, $value );
    118117            }
    119118        }
     
    148147
    149148        <div class="submit">
    150             <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     149            <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
    151150        </div>
    152151
     
    190189
    191190        <div class="submit">
    192             <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &rarr;" id="delete-account-button" name="delete-account-button" /></p>
     191            <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &rarr;" id="delete-account-button" name="delete-account-button" />
    193192        </div>
    194193
  • trunk/bp-core/bp-core-signup.php

    r3277 r3300  
    181181
    182182            /* Make sure we include the jQuery jCrop file for image cropping */
    183             add_action( 'wp', 'bp_core_add_jquery_cropper' );
     183            add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    184184        }
    185185    }
  • trunk/bp-core/bp-core-templatetags.php

    r3286 r3300  
    3030            $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page, $populate_extras );
    3131        else
    32             $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 ) );
     32            $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 ) );
    3333
    3434        if ( !$max || $max >= (int)$this->members['total'] )
     
    126126    $search_terms = false;
    127127
    128     /* User filtering */
     128    // User filtering
    129129    if ( !empty( $bp->displayed_user->id ) )
    130130        $user_id = $bp->displayed_user->id;
    131131
    132     /* Pass a filter if ?s= is set. */
    133     if ( $_REQUEST['s'] )
     132    // Pass a filter if ?s= is set.
     133    if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
    134134        $search_terms = $_REQUEST['s'];
    135135
     
    157157    }
    158158
    159     /* Make sure we return no members if we looking at friendship requests and there are none. */
     159    // Make sure we return no members if we looking at friendship requests and there are none.
    160160    if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
    161161        return false;
    162162
    163163    $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
    164 
    165     return $members_template->has_members();
     164    return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
    166165}
    167166
     
    182181        global $bp, $members_template;
    183182
    184         $from_num = bp_core_number_format( intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1 );
    185         $to_num = bp_core_number_format( ( $from_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $from_num + ( $members_template->pag_num - 1) );
     183        $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
     184        $from_num = bp_core_number_format( $start_num );
     185        $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
    186186        $total = bp_core_number_format( $members_template->total_member_count );
    187187
     
    195195            $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
    196196
    197         return apply_filters( 'bp_members_pagination_count', $pag );
     197        return apply_filters( 'bp_members_pagination_count', $pag . '<span class="ajax-loader"></span>' );
    198198    }
    199199
     
    207207    }
    208208
     209/**
     210 * bp_member_user_id()
     211 *
     212 * Echo id from bp_get_member_user_id()
     213 *
     214 * @uses bp_get_member_user_id()
     215 */
    209216function bp_member_user_id() {
    210217    echo bp_get_member_user_id();
    211218}
     219    /**
     220     * bp_get_member_user_id()
     221     *
     222     * Get the id of the user in a members loop
     223     *
     224     * @global object $members_template
     225     * @return string Members id
     226     */
    212227    function bp_get_member_user_id() {
    213228        global $members_template;
     
    215230        return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
    216231    }
     232
     233/**
     234 * bp_member_user_nicename()
     235 *
     236 * Echo nicename from bp_get_member_user_nicename()
     237 *
     238 * @uses bp_get_member_user_nicename()
     239 */
     240function bp_member_user_nicename() {
     241    echo bp_get_member_user_nicename();
     242}
     243    /**
     244     * bp_get_member_user_nicename()
     245     *
     246     * Get the nicename of the user in a members loop
     247     *
     248     * @global object $members_template
     249     * @return string Members nicename
     250     */
     251    function bp_get_member_user_nicename() {
     252        global $members_template;
     253        return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
     254    }
     255
     256/**
     257 * bp_member_user_login()
     258 *
     259 * Echo login from bp_get_member_user_login()
     260 *
     261 * @uses bp_get_member_user_login()
     262 */
     263function bp_member_user_login() {
     264    echo bp_get_member_user_login();
     265}
     266    /**
     267     * bp_get_member_user_login()
     268     *
     269     * Get the login of the user in a members loop
     270     *
     271     * @global object $members_template
     272     * @return string Members login
     273     */
     274    function bp_get_member_user_login() {
     275        global $members_template;
     276        return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
     277    }
     278
     279/**
     280 * bp_member_user_email()
     281 *
     282 * Echo email address from bp_get_member_user_email()
     283 *
     284 * @uses bp_get_member_user_email()
     285 */
     286function bp_member_user_email() {
     287    echo bp_get_member_user_email();
     288}
     289    /**
     290     * bp_get_member_user_email()
     291     *
     292     * Get the email address of the user in a members loop
     293     *
     294     * @global object $members_template
     295     * @return string Members email address
     296     */
     297    function bp_get_member_user_email() {
     298        global $members_template;
     299        return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
     300    }
     301
     302function bp_member_is_loggedin_user() {
     303    global $bp, $members_template;
     304    return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
     305}
    217306
    218307function bp_member_avatar( $args = '' ) {
     
    315404
    316405        // Populate the user if it hasn't been already.
    317         if ( empty( $members_template->member->profile_data ) )
    318             $members_template->member = new BP_Core_User( $members_template->member->id );
     406        if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
     407            $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
    319408
    320409        $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
     
    329418        global $members_template;
    330419
    331         $registered = attribute_escape( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
     420        $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
    332421
    333422        return apply_filters( 'bp_member_last_active', $registered );
     
    346435function bp_member_hidden_fields() {
    347436    if ( isset( $_REQUEST['s'] ) ) {
    348         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
     437        echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';
    349438    }
    350439
    351440    if ( isset( $_REQUEST['letter'] ) ) {
    352         echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
     441        echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    353442    }
    354443
    355444    if ( isset( $_REQUEST['members_search'] ) ) {
    356         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
     445        echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
    357446    }
    358447}
     
    367456    ?>
    368457    <form action="" method="get" id="search-members-form">
    369         <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $search_value ) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
     458        <label><input type="text" name="s" id="members_search" value="<?php echo esc_attr( $search_value ) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
    370459        <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
    371460    </form>
     
    517606        $bp->bp_options_title = __( 'Options', 'buddypress' );
    518607
    519     echo apply_filters( 'bp_get_options_title', attribute_escape( $bp->bp_options_title ) );
     608    echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) );
    520609}
    521610
     
    575664
    576665        $defaults = array(
    577             'type' => 'thumb',
    578             'width' => false,
    579             'height' => false
     666            'type'      => 'thumb',
     667            'width'     => false,
     668            'height'    => false,
     669            'html'      => true
    580670        );
    581671
     
    583673        extract( $r, EXTR_SKIP );
    584674
    585         return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
     675        return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
    586676    }
    587677
     
    593683
    594684        $defaults = array(
    595             'type' => 'thumb',
    596             'width' => false,
    597             'height' => false
     685            'type'      => 'thumb',
     686            'width'     => false,
     687            'height'    => false,
     688            'html'      => true
    598689        );
    599690
     
    601692        extract( $r, EXTR_SKIP );
    602693
    603         return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
     694        return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
    604695    }
    605696
     
    641732}
    642733
    643 function bp_is_my_profile() {
    644     global $bp;
    645 
    646     if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
    647         return true;
    648 
    649     return false;
    650 }
    651 function bp_is_home() { return bp_is_my_profile(); }
    652 
    653 function bp_get_loggedin_user_link() {
    654     global $bp;
    655 
    656     return $bp->loggedin_user->domain;
    657 }
    658 
    659 function bp_get_displayed_user_link() {
    660     global $bp;
    661 
    662     return $bp->displayed_user->domain;
    663 }
    664 
    665 function bp_last_activity( $user_id = false, $echo = true ) {
    666     global $bp;
    667 
    668     if ( !$user_id )
    669         $user_id = $bp->displayed_user->id;
    670 
    671     $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );
    672 
    673     if ( $echo )
    674         echo apply_filters( 'bp_last_activity', $last_activity );
    675     else
    676         return apply_filters( 'bp_last_activity', $last_activity );
    677 }
    678 
    679 function bp_user_firstname() {
    680     echo bp_get_user_firstname();
    681 }
    682     function bp_get_user_firstname( $name = false ) {
    683         global $bp;
    684 
    685         if ( !$name )
    686             $name = $bp->loggedin_user->fullname;
    687 
    688         $fullname = (array)explode( ' ', $name );
    689 
    690         return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
    691     }
    692 
    693 function bp_user_link() {
    694     global $bp;
    695 
    696     echo apply_filters( 'bp_the_avatar_thumbnail', $bp->displayed_user->domain );
    697 }
    698 
    699734function bp_core_get_wp_profile() {
    700735    global $bp;
     
    706741    <h4><?php _e( 'My Profile' ) ?></h4>
    707742
    708     <table class="wp-profile-fields">
     743    <table class="wp-profile-fields zebra">
    709744        <?php if ( $ud->display_name ) { ?>
    710745        <tr id="wp_displayname">
     
    784819
    785820function bp_format_time( $time, $just_date = false ) {
    786     $date = date( get_option('date_format'), $time );
    787 
     821    if ( !$time )
     822        return false;
     823
     824    // Get GMT offset from root blog
     825    $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
     826
     827    // Calculate offset time
     828    $time_offset = $time + ( $root_blog_offset * 3600 );
     829
     830    // Current date (January 1, 2010)
     831    $date = date( 'F j, Y ', $time_offset );
     832
     833    // Should we show the time also?
    788834    if ( !$just_date ) {
    789         $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
     835        // Current time (9:50pm)
     836        $time = date( ' g:ia', $time_offset );
     837
     838        // Return string formatted with date and time
     839        $date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time );
    790840    }
    791841
     
    833883}
    834884
    835 function bp_loggedinuser_link() {
    836     global $bp;
    837 
    838     if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) ) {
    839         echo apply_filters( 'bp_loggedinuser_link', $link );
    840     }
    841 }
    842 
    843885function bp_get_plugin_sidebar() {
    844886    locate_template( array( 'plugin-sidebar.php' ), true );
    845887}
    846888
    847 function bp_is_blog_page() {
    848     global $bp, $is_member_page, $wp_query;
    849 
    850     if ( $wp_query->is_home && !$bp->is_directory )
    851         return true;
    852 
    853     if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
    854         return true;
    855 
    856     return false;
    857 }
    858 
    859889function bp_page_title() {
    860890    echo bp_get_page_title();
     
    864894    global $bp, $post, $wp_query, $current_blog;
    865895
    866     if ( is_front_page() || !bp_current_component() || ( is_home() && bp_is_page( 'home' ) ) ) {
     896    if ( is_front_page() || ( is_home() && bp_is_page( 'home' ) ) ) {
    867897        $title = __( 'Home', 'buddypress' );
    868898
     
    886916
    887917    } else if ( $bp->is_directory ) {
    888         $title = get_the_title();
     918        if ( !$bp->current_component )
     919            $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
     920        else
     921            $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
    889922
    890923    } else if ( bp_is_register_page() ) {
    891 
    892924        $title = __( 'Create an Account', 'buddypress' );
    893925
    894926    } else if ( bp_is_activation_page() ) {
    895927        $title = __( 'Activate your Account', 'buddypress' );
     928
     929    } else if ( bp_is_group_create() ) {
     930        $title = __( 'Create a Group', 'buddypress' );
     931
     932    } else if ( bp_is_create_blog() ) {
     933        $title = __( 'Create a Blog', 'buddypress' );
    896934    }
    897935
     
    952990    }
    953991
     992/**
     993 * bp_search_form_available()
     994 *
     995 * Only show the search form if there are available objects to search for.
     996 *
     997 * @global array $bp
     998 * @uses function_exists
     999 * @uses bp_core_is_multisite()
     1000 * @return bool Filterable result
     1001 */
     1002function bp_search_form_enabled() {
     1003    global $bp;
     1004
     1005    if ( function_exists( 'xprofile_install' )
     1006         || function_exists( 'groups_install' )
     1007         || ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
     1008         || ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
     1009        ) {
     1010        $search_enabled = true;
     1011    } else {
     1012        $search_enabled = false;
     1013    }
     1014
     1015    return apply_filters( 'bp_search_form_enabled', $search_enabled );
     1016}
     1017
    9541018function bp_search_form_action() {
    9551019    global $bp;
     
    9591023
    9601024function bp_search_form_type_select() {
     1025    global $bp;
     1026
    9611027    // Eventually this won't be needed and a page will be built to integrate all search results.
    9621028    $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
     
    10131079function bp_custom_profile_sidebar_boxes() {
    10141080    do_action( 'bp_custom_profile_sidebar_boxes' );
    1015 }
    1016 
    1017 function bp_is_directory() {
    1018     global $bp;
    1019 
    1020     return $bp->is_directory;
    10211081}
    10221082
     
    12251285
    12261286function bp_registration_needs_activation() {
    1227     return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite() );
     1287    return apply_filters( 'bp_registration_needs_activation', true );
    12281288}
    12291289
     
    12681328   also means we dont have to use the $bp variable in the template (looks messy) */
    12691329
     1330function bp_last_activity( $user_id = false, $echo = true ) {
     1331    global $bp;
     1332
     1333    if ( !$user_id )
     1334        $user_id = $bp->displayed_user->id;
     1335
     1336    $last_activity = bp_core_get_last_activity( get_user_meta( $user_id, 'last_activity', true ), __('active %s ago', 'buddypress') );
     1337
     1338    if ( $echo )
     1339        echo apply_filters( 'bp_last_activity', $last_activity );
     1340    else
     1341        return apply_filters( 'bp_last_activity', $last_activity );
     1342}
     1343
     1344function bp_user_has_access() {
     1345    global $bp;
     1346
     1347    if ( is_super_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
     1348        $has_access = true;
     1349    else
     1350        $has_access = false;
     1351
     1352    return apply_filters( 'bp_user_has_access', $has_access );
     1353}
     1354
     1355function bp_user_firstname() {
     1356    echo bp_get_user_firstname();
     1357}
     1358    function bp_get_user_firstname( $name = false ) {
     1359        global $bp;
     1360
     1361        // Try to get displayed user
     1362        if ( empty( $name ) )
     1363            $name = $bp->displayed_user->fullname;
     1364
     1365        // Fall back on logged in user
     1366        if ( empty( $name ) )
     1367            $name = $bp->loggedin_user->fullname;
     1368
     1369        $fullname = (array)explode( ' ', $name );
     1370
     1371        return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
     1372    }
     1373
     1374function bp_loggedin_user_link() {
     1375    echo bp_get_loggedin_user_link();
     1376}
     1377    function bp_get_loggedin_user_link() {
     1378        global $bp;
     1379
     1380        return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
     1381    }
     1382
     1383/* @todo Deprecate incorrectly named function? */
     1384function bp_loggedinuser_link() {
     1385    global $bp;
     1386
     1387    if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
     1388        echo apply_filters( 'bp_loggedin_user_link', $link );
     1389}
     1390
     1391function bp_displayed_user_link() {
     1392    echo bp_get_displayed_user_link();
     1393}
     1394    function bp_get_displayed_user_link() {
     1395        global $bp;
     1396
     1397        return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
     1398    }
     1399    function bp_user_link() { bp_displayed_user_link(); } // Deprecated.
     1400
    12701401function bp_displayed_user_id() {
    12711402    global $bp;
     
    13501481        global $bp;
    13511482
    1352         return $bp->root_domain;
     1483        return apply_filters( 'bp_get_root_domain', $bp->root_domain );
    13531484    }
    13541485
    13551486/* Template is_() functions to determine the current page */
     1487
     1488function bp_is_blog_page() {
     1489    global $bp, $is_member_page, $wp_query;
     1490
     1491    if ( $wp_query->is_home && !$bp->is_directory )
     1492        return true;
     1493
     1494    if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
     1495        return true;
     1496
     1497    return false;
     1498}
     1499
     1500function bp_is_my_profile() {
     1501    global $bp;
     1502
     1503    if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
     1504        $my_profile = true;
     1505    else
     1506        $my_profile = false;
     1507
     1508    return apply_filters( 'bp_is_my_profile', $my_profile );
     1509}
     1510function bp_is_home() { return bp_is_my_profile(); }
    13561511
    13571512function bp_is_front_page() {
     
    13651520
    13661521function bp_is_activity_front_page() {
    1367     return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == bp_core_get_site_path() );
     1522    global $current_blog;
     1523
     1524    if ( bp_core_is_main_site() )
     1525        $path = bp_core_get_site_path();
     1526    else
     1527        $path = $current_blog->path;
     1528
     1529    return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == $path );
     1530}
     1531
     1532function bp_is_directory() {
     1533    global $bp;
     1534
     1535    return $bp->is_directory;
    13681536}
    13691537
  • trunk/bp-core/bp-core-widgets.php

    r3263 r3300  
    5959            </ul>
    6060            <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members' ); ?>
    61             <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo attribute_escape( $instance['max_members'] ); ?>" />
     61            <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo esc_attr( $instance['max_members'] ); ?>" />
    6262
    6363        <?php else: ?>
     
    8585        ?>
    8686
    87         <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
     87        <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
    8888    <?php
    8989    }
     
    139139        ?>
    140140
    141         <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
     141        <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
    142142    <?php
    143143    }
     
    154154        global $bp;
    155155
    156         extract( $args );
     156        extract( $args );
    157157
    158158        echo $before_widget;
     
    193193        ?>
    194194
    195         <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
     195        <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
    196196    <?php
    197197    }
     
    209209            $type = 'newest';
    210210            break;
     211
    211212        case 'recently-active-members':
    212213            $type = 'active';
    213214            break;
     215
    214216        case 'popular-members':
    215217            if ( bp_is_active( 'friends' ) )
  • trunk/bp-core/bp-core-wpabstraction.php

    r3284 r3300  
    2323
    2424    return true;
     25}
     26
     27/**
     28 * bp_core_is_main_site
     29 *
     30 * Checks if current blog is root blog of site
     31 *
     32 * @since 1.2.6
     33 * @package BuddyPress
     34 *
     35 * @param int $blog_id optional blog id to test (default current blog)
     36 * @return bool True if not multisite or $blog_id is main site
     37 */
     38function bp_core_is_main_site( $blog_id = '' ) {
     39    global $current_site, $current_blog;
     40
     41    if ( !bp_core_is_multisite() )
     42        return true;
     43
     44    if ( empty( $blog_id ) )
     45        $blog_id = $current_blog->blog_id;
     46
     47    return $blog_id == $current_site->blog_id;
    2548}
    2649
     
    7497}
    7598
    76 if ( !function_exists( 'wpmu_validate_user_signup' ) ) {
    77     function wpmu_validate_user_signup( $user_name, $user_email ) {
    78         global $wpdb;
     99if ( !function_exists( 'is_subdomain_install' ) ) {
     100    function is_subdomain_install() {
     101        if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) )
     102            return true;
    79103
    80         $errors = new WP_Error();
    81 
    82         $user_email = sanitize_email( $user_email );
    83 
    84         if ( empty( $user_name ) )
    85             $errors->add('user_name', __("Please enter a username"));
    86 
    87         $maybe = array();
    88         preg_match( "/[a-z0-9]+/", $user_name, $maybe );
    89 
    90         $illegal_names = get_site_option( "illegal_names" );
    91         if( is_array( $illegal_names ) == false ) {
    92             $illegal_names = array(  "www", "web", "root", "admin", "main", "invite", "administrator" );
    93             add_site_option( "illegal_names", $illegal_names );
    94         }
    95 
    96         if ( !validate_username( $user_name ) || in_array( $user_name, $illegal_names ) == true || $user_name != $maybe[0] ) {
    97             $errors->add('user_name', __("Only lowercase letters and numbers allowed"));
    98         }
    99 
    100         if( strlen( $user_name ) < 4 ) {
    101             $errors->add('user_name',  __("Username must be at least 4 characters"));
    102         }
    103 
    104         if ( strpos( " " . $user_name, "_" ) != false )
    105             $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));
    106 
    107         // all numeric?
    108         $match = array();
    109         preg_match( '/[0-9]*/', $user_name, $match );
    110         if ( $match[0] == $user_name )
    111             $errors->add('user_name', __("Sorry, usernames must have letters too!"));
    112 
    113         if ( !is_email( $user_email ) )
    114             $errors->add('user_email', __("Please check your email address."));
    115 
    116         $limited_email_domains = get_site_option( 'limited_email_domains' );
    117         if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
    118             $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
    119             if( in_array( $emaildomain, $limited_email_domains ) == false ) {
    120                 $errors->add('user_email', __("Sorry, that email address is not allowed!"));
    121             }
    122         }
    123 
    124         // Check if the username has been used already.
    125         if ( username_exists($user_name) )
    126             $errors->add('user_name', __("Sorry, that username already exists!"));
    127 
    128         // Check if the email address has been used already.
    129         if ( email_exists($user_email) )
    130             $errors->add('user_email', __("Sorry, that email address is already used!"));
    131 
    132         $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
    133 
    134         return apply_filters('wpmu_validate_user_signup', $result);
     104        return false;
    135105    }
    136106}
     107
     108// Deprecated - 1.2.6
     109if ( !function_exists( 'is_site_admin' ) ) {
     110    function is_site_admin( $user_id = false ) {
     111        return is_super_admin( $user_id );
     112    }
     113}
     114
    137115?>
  • trunk/bp-forums.php

    r3232 r3300  
    11<?php
     2
    23/* Define the parent forum ID */
    34if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
    45    define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
    56
     7if ( !defined( 'BP_FORUMS_SLUG' ) )
     8    define( 'BP_FORUMS_SLUG', 'forums' );
     9
    610if ( !defined( 'BB_PATH' ) )
    711    require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' );
     
    1317    global $bp;
    1418
    15     if ( !defined( 'BP_FORUMS_SLUG' ) )
    16         define ( 'BP_FORUMS_SLUG', $bp->pages->forums->slug );
    17 
    1819    /* For internal identification */
    1920    $bp->forums->id = 'forums';
    20     $bp->forums->name = $bp->pages->forums->name;
    21     $bp->forums->slug = BP_FORUMS_SLUG;
    2221
    2322    $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
    2423    $bp->forums->bbconfig = $bp->site_options['bb-config-location'];
     24    $bp->forums->slug = BP_FORUMS_SLUG;
    2525
    2626    /* Register this in the active components array */
     
    4040}
    4141
     42function bp_forums_setup_root_component() {
     43    /* Register 'forums' as a root component */
     44    bp_core_add_root_component( BP_FORUMS_SLUG );
     45}
     46add_action( 'bp_setup_root_components', 'bp_forums_setup_root_component' );
     47
    4248function bp_forums_directory_forums_setup() {
    4349    global $bp;
    4450
    4551    if ( $bp->current_component == $bp->forums->slug ) {
    46         if ( (int) $bp->site_options['bp-disable-forum-directory'] || !bp_is_active( 'groups' ) )
     52        if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
    4753            return false;
    4854
     
    6369            if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
    6470                /* Auto join this user if they are not yet a member of this group */
    65                 if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     71                if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    6672                    groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
    6773
     
    7379
    7480                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
     81                } else {
     82                    bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
    7583                }
    7684            }
     
    8795    global $bp;
    8896
    89     if ( !is_site_admin() )
     97    if ( !is_super_admin() )
    9098        return false;
    9199
     
    119127
    120128    return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
     129}
     130
     131function bp_forums_update_forum( $args = '' ) {
     132    do_action( 'bbpress_init' );
     133
     134    $defaults = array(
     135        'forum_id'          => '',
     136        'forum_name'        => '',
     137        'forum_desc'        => '',
     138        'forum_slug'        => '',
     139        'forum_parent_id'   => BP_FORUMS_PARENT_FORUM_ID,
     140        'forum_order'       => false,
     141        'forum_is_category' => 0
     142    );
     143
     144    $r = wp_parse_args( $args, $defaults );
     145    extract( $r, EXTR_SKIP );
     146
     147    return bb_update_forum( array( 'forum_id' => (int)$forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
    121148}
    122149
     
    356383
    357384    /* Fetch fullname for the topic's last poster */
    358     if ( bp_is_active( 'xprofile' ) ) {
     385    if ( function_exists( 'xprofile_install' ) ) {
    359386        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
    360387        for ( $i = 0; $i < count( $topics ); $i++ ) {
     
    441468        $post_position = $post->post_position;
    442469
    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 )
     470    $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 ) );
     471
     472    if ( $post_id )
    446473        do_action( 'bp_forums_new_post', $post_id );
    447474
    448     return $post;
     475    return $post_id;
    449476}
    450477
     
    474501
    475502    /* Fetch fullname for each poster. */
    476     if ( bp_is_active( 'xprofile' ) ) {
     503    if ( function_exists( 'xprofile_install' ) ) {
    477504        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
    478505        for ( $i = 0; $i < count( $posts ); $i++ ) {
     
    501528    global $bp, $wp_roles, $bb_table_prefix;
    502529
    503     $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' );
     530    $bb_cap = get_user_meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities', true );
    504531
    505532    if ( empty( $bb_cap ) )
  • trunk/bp-forums/bp-forums-admin.php

    r2665 r3300  
    122122
    123123function bp_forums_bbpress_install() {
    124     global $wpdb, $bbdb;
     124    global $wpdb, $bbdb, $bp;
    125125
    126126    check_admin_referer( 'bp_forums_new_install_init' );
     
    141141            "define( 'BB_LOGGED_I"          => array( "'put your unique phrase here'",  "'" . addslashes( LOGGED_IN_KEY ) . "'" ),
    142142            "define( 'BB_NONCE_KE"          => array( "'put your unique phrase here'",  "'" . addslashes( NONCE_KEY ) . "'" ),
    143             "\$bb_table_prefix = '"         => array( "'bb_'",                          "'" . $wpdb->base_prefix . "bb_'" ),
     143            "\$bb_table_prefix = '"         => array( "'bb_'",                          "'" . $bp->table_prefix . "bb_'" ),
    144144            "define( 'BB_LANG', '"          => array( "''",                             "'" . WPLANG . "'" )
    145145        )
     
    154154
    155155    $file = substr( $file, 0, -2 );
    156     $file .= "\n" .   '$bb->custom_user_table = "' . $wpdb->users . '";';
    157     $file .= "\n" .   '$bb->custom_user_meta_table = "' . $wpdb->usermeta . '";';
    158     $file .= "\n\n" . '$bb->uri = "' . BP_PLUGIN_URL . '/bp-forums/bbpress/";';
    159     $file .= "\n" .   '$bb->name = "' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '";';
     156    $file .= "\n" .   '$bb->custom_user_table = \'' . $wpdb->users . '\';';
     157    $file .= "\n" .   '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
     158    $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
     159    $file .= "\n" .   '$bb->name = \'' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
    160160
    161161    if ( bp_core_is_multisite() )
     
    163163
    164164    if ( defined( 'AUTH_SALT' ) )
    165         $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', "' . addslashes( AUTH_SALT ) . '");';
     165        $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
    166166
    167167    if ( defined( 'LOGGED_IN_SALT' ) )
    168         $file .= "\n" .   'define(\'BB_LOGGED_IN_SALT\', "' . addslashes( LOGGED_IN_SALT ) . '");';
     168        $file .= "\n" .   'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
    169169
    170170    if ( defined( 'SECURE_AUTH_SALT' ) )
    171         $file .= "\n" .   'define(\'BB_SECURE_AUTH_SALT\', "' . addslashes( SECURE_AUTH_SALT ) . '");';
     171        $file .= "\n" .   'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
    172172
    173173    $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
  • trunk/bp-forums/bp-forums-bbpress.php

    r2209 r3300  
    6666    /* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
    6767    if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
    68         require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
     68        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    6969
    7070    require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
    7171
    7272    if ( is_object( $wp_roles ) ) {
    73         $bb_roles =& $wp_roles;
     73        $bb_roles = $wp_roles;
    7474        bb_init_roles( $bb_roles );
    7575    }
     
    104104        $site_admins = get_site_option( 'site_admins', array('admin') );
    105105        foreach ( (array)$site_admins as $site_admin )
    106             update_usermeta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
     106            update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
    107107
    108108        // Create the first forum.
     
    131131        extract( $args, EXTR_SKIP );
    132132
    133         return update_usermeta( $id, $meta_key, $meta_value );
     133        return update_user_meta( $id, $meta_key, $meta_value );
    134134    }
    135135}
  • trunk/bp-forums/bp-forums-filters.php

    r2770 r3300  
    33/* Apply WordPress defined filters */
    44add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
    5 add_filter( 'bp_forums_bbconfig_location', 'attribute_escape', 1 );
     5add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 );
    66
    77add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
    88add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
    99add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
     10
     11add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
     12add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
     13add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
    1014
    1115add_filter( 'bp_get_the_topic_title', 'wptexturize' );
     
    3135add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
    3236add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
     37add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
    3338
    3439add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
     
    8489    }
    8590
     91/**
     92 * bp_forums_add_forum_topic_to_page_title( $title )
     93 *
     94 * Append forum topic to page title
     95 *
     96 * @global object $bp
     97 * @param string $title
     98 * @return string
     99 */
     100function bp_forums_add_forum_topic_to_page_title( $title ) {
     101    global $bp;
     102
     103    if ( $bp->current_action == 'forum' && $bp->action_variables[0] == 'topic' ) {
     104        if ( bp_has_forum_topic_posts() ) {
     105            $title .= ' &#124; ' . bp_get_the_topic_title();
     106        }
     107    }
     108
     109    return $title;
     110}
     111add_filter( 'bp_page_title', 'bp_forums_add_forum_topic_to_page_title' );
     112
    86113?>
  • trunk/bp-forums/bp-forums-templatetags.php

    r3247 r3300  
    77    var $topic;
    88
     9    var $forum_id;
     10
    911    var $in_the_loop;
    1012
     
    2628        $this->type         = $type;
    2729        $this->search_terms = $search_terms;
     30        $this->forum_id     = $forum_id;
    2831
    2932        switch ( $type ) {
     
    4851
    4952        if ( !(int)$this->topics ) {
    50             $this->topic_count = 0;
     53            $this->topic_count       = 0;
    5154            $this->total_topic_count = 0;
    5255        } else {
     
    6063            }
    6164
    62             if ( !$max || $max >= $topic_count )
     65            if ( !$max || $max >= $topic_count ) {
    6366                $this->total_topic_count = $topic_count;
    64             else
     67            } else {
    6568                $this->total_topic_count = (int)$max;
     69            }
    6670
    6771            if ( $max ) {
    68                 if ( $max >= count( $this->topics ) ) {
     72                if ( $max >= count($this->topics) ) {
    6973                    $this->topic_count = count( $this->topics );
    7074                } else {
     
    99103                'base'      => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
    100104                'format'    => '',
    101                 'total'     => ceil( (int)$this->total_topic_count / (int)$this->pag_num ),
     105                'total'     => ceil( (int)$this->total_topic_count / (int)$this->pag_num),
    102106                'current'   => $this->pag_page,
    103107                'prev_text' => '&larr;',
     
    259263
    260264        $post = bb_get_first_post( (int)$forum_template->topic->topic_id, false );
    261         return apply_filters( 'bp_get_the_topic_text', attribute_escape( $post->post_text ) );
     265        return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) );
    262266    }
    263267
     
    295299        global $forum_template;
    296300
    297         if ( !$name = bp_core_get_userlink( $forum_template->topic->poster_id ) )
     301        $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
     302
     303        if ( !$name = bp_core_get_userlink( $poster_id ) )
    298304            return __( 'Deleted User', 'buddypress' );
    299305
     
    467473        global $forum_template;
    468474
    469         return $forum_template->topic->topic_posts;
     475        return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
    470476    }
    471477
     
    557563        $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
    558564
    559         if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
     565        if ( $bp->is_item_admin || $bp->is_item_mod || is_super_admin() ) {
    560566            if ( 0 == (int)$forum_template->topic->topic_sticky )
    561567                $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
     
    592598            $class .= ' closed';
    593599
    594         return trim( $class );
     600        return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
    595601    }
    596602
     
    670676        global $bp, $forum_template;
    671677
    672         $from_num = bp_core_number_format( intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1 );
    673         $to_num = bp_core_number_format( ( $from_num + ( $forum_template->pag_num - 1  ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 ) );
     678        $start_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
     679        $from_num = bp_core_number_format( $start_num );
     680        $to_num = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1  ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) );
    674681        $total = bp_core_number_format( $forum_template->total_topic_count );
    675682
     
    678685            $pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms );
    679686
    680         return apply_filters( 'bp_get_forum_pagination_count', sprintf( __( 'Viewing topic %s to %s (of %s total topics%s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) );
     687        return apply_filters( 'bp_get_forum_pagination_count', sprintf( __( 'Viewing topic %s to %s (of %s total topics%s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) . '<span class="ajax-loader"></span>' );
    681688    }
    682689
     
    697704    var $post;
    698705
     706    var $forum_id;
    699707    var $topic_id;
    700708    var $topic;
     
    712720    var $order;
    713721
    714     function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {
     722    function BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ) {
    715723        global $bp, $current_user, $forum_template;
    716724
     
    721729        $this->topic_id        = $topic_id;
    722730        $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
     731        $this->forum_id        = $forum_template->topic->forum_id;
    723732
    724733        $this->posts           = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) );
    725734
    726735        if ( !$this->posts ) {
    727             $this->post_count = 0;
     736            $this->post_count       = 0;
    728737            $this->total_post_count = 0;
    729738        } else {
    730             if ( !$max || $max >= (int) $forum_template->topic->topic_posts ) {
    731                 $this->total_post_count = (int) $forum_template->topic->topic_posts;
     739            if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) {
     740                $this->total_post_count = (int)$forum_template->topic->topic_posts;
    732741            } else {
    733742                $this->total_post_count = (int)$max;
     
    814823        'topic_id' => false,
    815824        'per_page' => 15,
    816         'max' => false
     825        'max'      => false,
     826        'order'    => 'ASC'
    817827    );
    818828
     
    823833        $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );
    824834
    825     if ( is_numeric( $topic_id ) )
    826         $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max );
    827     else
     835    if ( is_numeric( $topic_id ) ) {
     836        $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order );
     837
     838        // Current topic forum_id needs to match current_group forum_id
     839        if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) )
     840            return false;
     841
     842    } else {
    828843        return false;
     844    }
    829845
    830846    return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
     
    857873
    858874        return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) );
     875    }
     876
     877function bp_the_topic_post_css_class() {
     878    echo bp_get_the_topic_post_css_class();
     879}
     880
     881    function bp_get_the_topic_post_css_class() {
     882        global $topic_template;
     883
     884        $class = false;
     885
     886        if ( $topic_template->current_post % 2 == 1 )
     887            $class .= 'alt';
     888
     889        if ( 1 == (int)$topic_template->post->post_status )
     890            $class .= ' deleted';
     891
     892        if ( 0 == (int)$topic_template->post->post_status )
     893            $class .= ' open';
     894
     895        return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
    859896    }
    860897
     
    936973            $query_vars = '?' . $_SERVER['QUERY_STRING'];
    937974
    938         $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
     975        $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
    939976        $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a> | ';
    940977
     
    949986
    950987        $post = bp_forums_get_post( $bp->action_variables[4] );
    951         return apply_filters( 'bp_get_the_topic_post_edit_text', attribute_escape( $post->post_text ) );
     988        return apply_filters( 'bp_get_the_topic_post_edit_text', esc_attr( $post->post_text ) );
    952989    }
    953990
     
    9641001    global $bp, $topic_template;
    9651002
    966     $from_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
    967     $to_num = ( $from_num + ( $topic_template->pag_num - 1  ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 );
    968 
    969     echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %d to %d (%d total posts)', 'buddypress' ), $from_num, $to_num, $topic_template->total_post_count ) );
     1003    $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
     1004    $from_num = bp_core_number_format( $start_num );
     1005    $to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1  ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) );
     1006    $total = bp_core_number_format( $topic_template->total_post_count );
     1007
     1008    echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %1$s to %2$s (%3$s total posts)', 'buddypress' ), $from_num, $to_num, $total ) );
    9701009?>
    9711010    <span class="ajax-loader"></span>
     
    9911030?>
    9921031    <form action="" method="get" id="search-forums-form">
    993         <label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($search_value) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
     1032        <label><input type="text" name="s" id="forums_search" value="<?php echo esc_attr($search_value) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
    9941033        <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
    9951034    </form>
     
    10391078        global $topic_template;
    10401079
    1041         return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
     1080        return apply_filters( 'bp_get_forum_action', $bp->root_domain . esc_attr( $_SERVER['REQUEST_URI'] ) );
    10421081    }
    10431082
     
    10481087        global $bp;
    10491088
    1050         return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
     1089        return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . esc_attr( $_SERVER['REQUEST_URI'] ) );
    10511090    }
    10521091
  • trunk/bp-friends.php

    r3232 r3300  
    11<?php
     2
     3define ( 'BP_FRIENDS_DB_VERSION', '1800' );
     4
     5/* Define the slug for the component */
     6if ( !defined( 'BP_FRIENDS_SLUG' ) )
     7    define ( 'BP_FRIENDS_SLUG', 'friends' );
     8
    29require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );
    310require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );
    411
    512function friends_setup_globals() {
    6     global $bp, $wpdb;
    7 
    8     if ( !defined( 'BP_FRIENDS_SLUG' ) )
    9         define( 'BP_FRIENDS_SLUG', 'friends' );
     13    global $bp;
    1014
    1115    /* For internal identification */
    1216    $bp->friends->id = 'friends';
    1317
    14     $bp->friends->table_name = $wpdb->base_prefix . 'bp_friends';
     18    $bp->friends->slug = BP_FRIENDS_SLUG;
     19
     20    $bp->friends->table_name = $bp->table_prefix . 'bp_friends';
     21
    1522    $bp->friends->format_notification_function = 'friends_format_notifications';
    16     $bp->friends->slug = BP_FRIENDS_SLUG;
    1723
    1824    /* Register this in the active components array */
     
    103109function friends_screen_notification_settings() {
    104110    global $current_user; ?>
    105     <table class="notification-settings" id="friends-notification-settings">
    106         <tr>
    107             <th class="icon"></th>
    108             <th class="title"><?php _e( 'Friends', 'buddypress' ) ?></th>
    109             <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    110             <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    111         </tr>
    112         <tr>
    113             <td></td>
    114             <td><?php _e( 'A member sends you a friendship request', 'buddypress' ) ?></td>
    115             <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_request') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_request') ) { ?>checked="checked" <?php } ?>/></td>
    116             <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" value="no" <?php if ( get_usermeta( $current_user->id,'notification_friends_friendship_request') == 'no' ) { ?>checked="checked" <?php } ?>/></td>
    117         </tr>
    118         <tr>
    119             <td></td>
    120             <td><?php _e( 'A member accepts your friendship request', 'buddypress' ) ?></td>
    121             <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_accepted') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td>
    122             <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td>
    123         </tr>
    124 
    125         <?php do_action( 'friends_screen_notification_settings' ); ?>
     111    <table class="notification-settings zebra" id="friends-notification-settings">
     112        <thead>
     113            <tr>
     114                <th class="icon"></th>
     115                <th class="title"><?php _e( 'Friends', 'buddypress' ) ?></th>
     116                <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
     117                <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     118            </tr>
     119        </thead>
     120
     121        <tbody>
     122            <tr>
     123                <td></td>
     124                <td><?php _e( 'A member sends you a friendship request', 'buddypress' ) ?></td>
     125                <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) ) { ?>checked="checked" <?php } ?>/></td>
     126                <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" value="no" <?php if ( get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) == 'no' ) { ?>checked="checked" <?php } ?>/></td>
     127            </tr>
     128            <tr>
     129                <td></td>
     130                <td><?php _e( 'A member accepts your friendship request', 'buddypress' ) ?></td>
     131                <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) ) { ?>checked="checked" <?php } ?>/></td>
     132                <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) ) { ?>checked="checked" <?php } ?>/></td>
     133            </tr>
     134
     135            <?php do_action( 'friends_screen_notification_settings' ); ?>
     136        </tbody>
    126137    </table>
    127138<?php
     
    237248        'item_id' => false,
    238249        'secondary_item_id' => false,
    239         'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     250        'recorded_time' => bp_core_current_time(),
    240251        'hide_sitewide' => false
    241252    );
     
    318329    $friendship->is_confirmed = 0;
    319330    $friendship->is_limited = 0;
    320     $friendship->date_created = time();
     331    $friendship->date_created = bp_core_current_time();
    321332
    322333    if ( $force_accept )
     
    372383        friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
    373384
    374         /* Remove the friend request notice */
     385        // Remove the friend request notice
    375386        bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
    376387
    377         /* Add a friend accepted notice for the initiating user */
     388        // Add a friend accepted notice for the initiating user
    378389        bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' );
    379390
     
    381392        $friend_link = bp_core_get_userlink( $friendship->friend_user_id );
    382393
    383         /* Record in activity streams for the initiator */
     394        // Record in activity streams for the initiator
    384395        friends_record_activity( array(
    385             'user_id' => $friendship->initiator_user_id,
    386             'type' => 'friendship_created',
    387             'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship ),
    388             'item_id' => $friendship_id
     396            'user_id'           => $friendship->initiator_user_id,
     397            'type'              => 'friendship_created',
     398            'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship ),
     399            'item_id'           => $friendship_id,
     400            'secondary_item_id' => $friendship->friend_user_id
    389401        ) );
    390402
    391         /* Record in activity streams for the friend */
     403        // Record in activity streams for the friend
    392404        friends_record_activity( array(
    393             'user_id' => $friendship->friend_user_id,
    394             'type' => 'friendship_created',
    395             'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), &$friendship ),
    396             'item_id' => $friendship_id,
    397             'hide_sitewide' => true /* We've already got the first entry site wide */
     405            'user_id'           => $friendship->friend_user_id,
     406            'type'              => 'friendship_created',
     407            'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), &$friendship ),
     408            'item_id'           => $friendship_id,
     409            'secondary_item_id' => $friendship->initiator_user_id,
     410            'hide_sitewide'     => true // We've already got the first entry site wide
    398411        ) );
    399412
    400         /* Send the email notification */
     413        // Send the email notification
    401414        require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
    402415        friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
     
    444457
    445458    if ( !$count = wp_cache_get( 'bp_total_friend_count_' . $user_id, 'bp' ) ) {
    446         $count = get_usermeta( $user_id, 'total_friend_count' );
     459        $count = get_user_meta( $user_id, 'total_friend_count', true );
    447460        if ( empty( $count ) ) $count = 0;
    448461        wp_cache_set( 'bp_total_friend_count_' . $user_id, $count, 'bp' );
     
    547560function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {
    548561    if ( 'add' == $status ) {
    549         update_usermeta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count' ) + 1 );
    550         update_usermeta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count' ) + 1 );
     562        update_user_meta( $initiator_user_id, 'total_friend_count', (int)get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
     563        update_user_meta( $friend_user_id, 'total_friend_count', (int)get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 );
    551564    } else {
    552         update_usermeta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count' ) - 1 );
    553         update_usermeta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count' ) - 1 );
     565        update_user_meta( $initiator_user_id, 'total_friend_count', (int)get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 );
     566        update_user_meta( $friend_user_id, 'total_friend_count', (int)get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 );
    554567    }
    555568}
     
    559572
    560573    /* Remove usermeta */
    561     delete_usermeta( $user_id, 'total_friend_count' );
     574    delete_user_meta( $user_id, 'total_friend_count' );
    562575
    563576    /* Remove friendship requests FROM user */
     
    566579    do_action( 'friends_remove_data', $user_id );
    567580}
    568 add_action( 'wpmu_delete_user', 'friends_remove_data', 1 );
    569 add_action( 'delete_user', 'friends_remove_data', 1 );
    570 add_action( 'make_spam_user', 'friends_remove_data', 1 );
     581add_action( 'wpmu_delete_user', 'friends_remove_data' );
     582add_action( 'delete_user', 'friends_remove_data' );
     583add_action( 'make_spam_user', 'friends_remove_data' );
    571584
    572585
     
    595608    global $bp;
    596609
    597     if ( isset($_GET['new']) )
    598         bp_core_delete_notifications_for_user_by_type( $bp->displayed_user->id, $bp->friends->id, 'friendship_accepted' );
     610    if ( isset( $_GET['new'] ) )
     611        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
    599612}
    600613add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
  • trunk/bp-friends/bp-friends-classes.php

    r2919 r3300  
    6161        if ( $this->id ) {
    6262            // Update
    63             $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = FROM_UNIXTIME(%d) ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
     63            $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
    6464        } else {
    6565            // Save
    66             $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
     66            $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
    6767            $this->id = $wpdb->insert_id;
    6868        }
     
    127127        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
    128128
    129         if ( !$count )
     129        // Do not update meta if user has never had friends
     130        if ( !$count && !get_user_meta( $user_id, 'total_friend_count', true ) )
    130131            return 0;
    131132
    132         update_usermeta( $user_id, 'total_friend_count', $count );
    133         return $count;
     133        update_user_meta( $user_id, 'total_friend_count', (int)$count );
     134        return (int)$count;
    134135    }
    135136
     
    202203        global $wpdb, $bp;
    203204
    204         return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE id = %d AND friend_user_id = %d", time(), $friendship_id, $bp->loggedin_user->id ) );
     205        return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, $bp->loggedin_user->id ) );
    205206    }
    206207
     
    315316        global $wpdb, $bp;
    316317
     318        // Get friends of $user_id
     319        $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     320
     321        // Delete all friendships related to $user_id
    317322        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) );
    318323
    319324        // Delete friend request notifications for members who have a notification from this user.
    320325        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) );
     326
     327        // Loop through friend_ids and update their counts
     328        foreach ( (array)$friend_ids as $friend_id ) {
     329            BP_Friends_Friendship::total_friend_count( $friend_id );
     330        }
    321331    }
    322332}
  • trunk/bp-friends/bp-friends-notifications.php

    r2941 r3300  
    66    $initiator_name = bp_core_get_user_displayname( $initiator_id );
    77
    8     if ( 'no' == get_usermeta( (int)$friend_id, 'notification_friends_friendship_request' ) )
     8    if ( 'no' == get_user_meta( (int)$friend_id, 'notification_friends_friendship_request', true ) )
    99        return false;
    1010
     
    1818
    1919    // Set up and send the message
    20     $to = $ud->user_email;
    21     $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name );
     20    $to       = $ud->user_email;
     21    $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
     22    $subject  = '[' . $sitename . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name );
    2223
    2324    $message = sprintf( __(
     
    4849    $friend_name = bp_core_get_user_displayname( $friend_id );
    4950
    50     if ( 'no' == get_usermeta( (int)$initiator_id, 'notification_friends_friendship_accepted' ) )
     51    if ( 'no' == get_user_meta( (int)$initiator_id, 'notification_friends_friendship_accepted', true ) )
    5152        return false;
    5253
     
    5758
    5859    // Set up and send the message
    59     $to = $ud->user_email;
    60     $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name );
     60    $to       = $ud->user_email;
     61    $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
     62    $subject  = '[' . $sitename . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name );
    6163
    6264    $message = sprintf( __(
  • trunk/bp-friends/bp-friends-templatetags.php

    r3263 r3300  
    105105        <form action="<?php echo $action ?>" id="friend-search-form" method="post">
    106106
    107         <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
    108         <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
    109 
    110         <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
    111         <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />
     107            <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
     108            <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
     109
     110            <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
     111            <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( $bp->displayed_user->id ) ?>" />
    112112
    113113        </form>
  • trunk/bp-groups.php

    r3273 r3300  
    1616    $bp->groups->slug = BP_GROUPS_SLUG;
    1717
    18     $bp->groups->table_name = $wpdb->base_prefix . 'bp_groups';
    19     $bp->groups->table_name_members = $wpdb->base_prefix . 'bp_groups_members';
    20     $bp->groups->table_name_groupmeta = $wpdb->base_prefix . 'bp_groups_groupmeta';
     18    $bp->groups->table_name           = $bp->table_prefix . 'bp_groups';
     19    $bp->groups->table_name_members   = $bp->table_prefix . 'bp_groups_members';
     20    $bp->groups->table_name_groupmeta = $bp->table_prefix . 'bp_groups_groupmeta';
     21
    2122    $bp->groups->format_notification_function = 'groups_format_notifications';
    2223
     
    3738    $bp->groups->valid_status = apply_filters( 'groups_valid_status', array( 'public', 'private', 'hidden' ) );
    3839
     40    // Auto join group when non group member performs group activity
     41    $bp->groups->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) ? false : true;
     42
    3943    do_action( 'groups_setup_globals' );
    4044}
     
    4448    global $bp;
    4549
    46     if ( $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {
     50    if ( $bp->current_component == $bp->groups->slug && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {
    4751
    4852        /* This is a single group page. */
     
    5155
    5256        /* Using "item" not "group" for generic support in other components. */
    53         if ( is_site_admin() )
     57        if ( is_super_admin() )
    5458            $bp->is_item_admin = 1;
    5559        else
     
    100104
    101105            if ( !$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group Avatar', 'buddypress' ) ) ) )
    102                 $bp->bp_options_avatar = '<img src="' . attribute_escape( $group->avatar_full ) . '" class="avatar" alt="' . attribute_escape( $group->name ) . '" />';
     106                $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />';
    103107
    104108            $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
     
    106110            // If this is a private or hidden group, does the user have access?
    107111            if ( 'private' == $bp->groups->current_group->status || 'hidden' == $bp->groups->current_group->status ) {
    108                 if ( $bp->groups->current_group->is_user_member && is_user_logged_in() || is_site_admin() )
     112                if ( $bp->groups->current_group->is_user_member && is_user_logged_in() || is_super_admin() )
    109113                    $bp->groups->current_group->user_has_access = true;
    110114                else
     
    128132
    129133            // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
    130             if ( !is_site_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' )
     134            if ( !is_super_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' )
    131135                bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) );
    132136
     
    166170
    167171    /* Don't show this menu to non site admins or if you're viewing your own profile */
    168     if ( !is_site_admin() )
     172    if ( !is_super_admin() )
    169173        return false;
    170174    ?>
     
    226230
    227231            groups_record_activity( array(
    228                 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . attribute_escape( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),
     232                'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),
    229233                'type' => 'joined_group',
    230234                'item_id' => $group->id
     
    292296
    293297                /* Auto join this user if they are not yet a member of this group */
    294                 if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     298                if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    295299                    groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
    296300
     
    470474
    471475                /* Auto join this user if they are not yet a member of this group */
    472                 if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     476                if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    473477                    groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
    474478
     
    492496
    493497    if ( $bp->is_single_item ) {
     498        /* Refresh the group member count meta */
     499        groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) );
     500
    494501        do_action( 'groups_screen_group_members', $bp->groups->current_group->id );
    495502        bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
     
    711718            $status = $bp->action_variables[2];
    712719
    713             /* Check the nonce first. */
     720            // Check the nonce first.
    714721            if ( !check_admin_referer( 'groups_promote_member' ) )
    715722                return false;
    716723
    717724            // Promote a user.
    718             if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) {
     725            if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) )
    719726                bp_core_add_message( __( 'There was an error when promoting that user, please try again', 'buddypress' ), 'error' );
    720             } else {
     727            else
    721728                bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) );
    722             }
    723729
    724730            do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id );
     
    730736            $user_id = $bp->action_variables[2];
    731737
    732             /* Check the nonce first. */
     738            // Check the nonce first.
    733739            if ( !check_admin_referer( 'groups_demote_member' ) )
    734740                return false;
    735741
    736742            // Demote a user.
    737             if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) ) {
     743            if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
    738744                bp_core_add_message( __( 'There was an error when demoting that user, please try again', 'buddypress' ), 'error' );
    739             } else {
     745            else
    740746                bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) );
    741             }
    742747
    743748            do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id );
     
    749754            $user_id = $bp->action_variables[2];
    750755
    751             /* Check the nonce first. */
     756            // Check the nonce first.
    752757            if ( !check_admin_referer( 'groups_ban_member' ) )
    753758                return false;
    754759
    755760            // Ban a user.
    756             if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) ) {
     761            if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
    757762                bp_core_add_message( __( 'There was an error when banning that user, please try again', 'buddypress' ), 'error' );
    758             } else {
     763            else
    759764                bp_core_add_message( __( 'User banned successfully', 'buddypress' ) );
    760             }
    761765
    762766            do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );
     
    768772            $user_id = $bp->action_variables[2];
    769773
    770             /* Check the nonce first. */
     774            // Check the nonce first.
    771775            if ( !check_admin_referer( 'groups_unban_member' ) )
    772776                return false;
    773777
    774778            // Remove a ban for user.
    775             if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) ) {
     779            if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) )
    776780                bp_core_add_message( __( 'There was an error when unbanning that user, please try again', 'buddypress' ), 'error' );
    777             } else {
     781            else
    778782                bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) );
    779             }
    780783
    781784            do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id );
     
    784787        }
    785788
     789        if ( 'remove' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
     790            $user_id = $bp->action_variables[2];
     791
     792            // Check the nonce first.
     793            if ( !check_admin_referer( 'groups_remove_member' ) )
     794                return false;
     795
     796            // Remove a user.
     797            if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) )
     798                bp_core_add_message( __( 'There was an error removing that user from the group, please try again', 'buddypress' ), 'error' );
     799            else
     800                bp_core_add_message( __( 'User removed successfully', 'buddypress' ) );
     801
     802            do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id );
     803
     804            bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
     805        }
     806
    786807        do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id );
    787808
     
    795816
    796817    if ( $bp->current_component == $bp->groups->slug && 'membership-requests' == $bp->action_variables[0] ) {
     818
     819        /* Ask for a login if the user is coming here via an email notification */
     820        if ( !is_user_logged_in() )
     821            bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) );
    797822
    798823        if ( !$bp->is_item_admin || 'public' == $bp->groups->current_group->status )
     
    850875    if ( $bp->current_component == $bp->groups->slug && 'delete-group' == $bp->action_variables[0] ) {
    851876
    852         if ( !$bp->is_item_admin && !is_site_admin() )
     877        if ( !$bp->is_item_admin && !is_super_admin() )
    853878            return false;
    854879
     
    881906function groups_screen_notification_settings() {
    882907    global $current_user; ?>
    883     <table class="notification-settings" id="groups-notification-settings">
    884         <tr>
    885             <th class="icon"></th>
    886             <th class="title"><?php _e( 'Groups', 'buddypress' ) ?></th>
    887             <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    888             <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    889         </tr>
    890         <tr>
    891             <td></td>
    892             <td><?php _e( 'A member invites you to join a group', 'buddypress' ) ?></td>
    893             <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_invite') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_invite') ) { ?>checked="checked" <?php } ?>/></td>
    894             <td class="no"><input type="radio" name="notifications[notification_groups_invite]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_invite') ) { ?>checked="checked" <?php } ?>/></td>
    895         </tr>
    896         <tr>
    897             <td></td>
    898             <td><?php _e( 'Group information is updated', 'buddypress' ) ?></td>
    899             <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_group_updated') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_group_updated') ) { ?>checked="checked" <?php } ?>/></td>
    900             <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_group_updated') ) { ?>checked="checked" <?php } ?>/></td>
    901         </tr>
    902         <tr>
    903             <td></td>
    904             <td><?php _e( 'You are promoted to a group administrator or moderator', 'buddypress' ) ?></td>
    905             <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_admin_promotion') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_admin_promotion') ) { ?>checked="checked" <?php } ?>/></td>
    906             <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_admin_promotion') ) { ?>checked="checked" <?php } ?>/></td>
    907         </tr>
    908         <tr>
    909             <td></td>
    910             <td><?php _e( 'A member requests to join a private group for which you are an admin', 'buddypress' ) ?></td>
    911             <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_membership_request') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_membership_request') ) { ?>checked="checked" <?php } ?>/></td>
    912             <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_membership_request') ) { ?>checked="checked" <?php } ?>/></td>
    913         </tr>
    914 
    915         <?php do_action( 'groups_screen_notification_settings' ); ?>
     908    <table class="notification-settings zebra" id="groups-notification-settings">
     909        <thead>
     910            <tr>
     911                <th class="icon"></th>
     912                <th class="title"><?php _e( 'Groups', 'buddypress' ) ?></th>
     913                <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
     914                <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     915            </tr>
     916        </thead>
     917
     918        <tbody>
     919            <tr>
     920                <td></td>
     921                <td><?php _e( 'A member invites you to join a group', 'buddypress' ) ?></td>
     922                <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_invite', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_invite', true ) ) { ?>checked="checked" <?php } ?>/></td>
     923                <td class="no"><input type="radio" name="notifications[notification_groups_invite]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_invite', true ) ) { ?>checked="checked" <?php } ?>/></td>
     924            </tr>
     925            <tr>
     926                <td></td>
     927                <td><?php _e( 'Group information is updated', 'buddypress' ) ?></td>
     928                <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) ) { ?>checked="checked" <?php } ?>/></td>
     929                <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) ) { ?>checked="checked" <?php } ?>/></td>
     930            </tr>
     931            <tr>
     932                <td></td>
     933                <td><?php _e( 'You are promoted to a group administrator or moderator', 'buddypress' ) ?></td>
     934                <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) ) { ?>checked="checked" <?php } ?>/></td>
     935                <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) ) { ?>checked="checked" <?php } ?>/></td>
     936            </tr>
     937            <tr>
     938                <td></td>
     939                <td><?php _e( 'A member requests to join a private group for which you are an admin', 'buddypress' ) ?></td>
     940                <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) ) { ?>checked="checked" <?php } ?>/></td>
     941                <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) ) { ?>checked="checked" <?php } ?>/></td>
     942            </tr>
     943
     944            <?php do_action( 'groups_screen_notification_settings' ); ?>
     945        </tbody>
    916946    </table>
    917947<?php
     
    9821012            }
    9831013
    984             if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title($_POST['group-name']) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) {
     1014            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) {
    9851015                bp_core_add_message( __( 'There was an error