Skip to:
Content

BuddyPress.org

Changeset 2077


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (15 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

Location:
trunk
Files:
118 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2002 r2077  
    1414/* Include deprecated functions if settings allow */
    1515if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    16     require ( BP_PLUGIN_DIR . '/bp-activity/deprecated/bp-activity-deprecated.php' );   
    17    
     16    require ( BP_PLUGIN_DIR . '/bp-activity/deprecated/bp-activity-deprecated.php' );
     17
    1818function bp_activity_install() {
    1919    global $wpdb, $bp;
    20    
     20
    2121    if ( !empty($wpdb->charset) )
    2222        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    23    
     23
    2424    $sql[] = "CREATE TABLE {$bp->activity->table_name} (
    2525                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    4141    require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
    4242    dbDelta($sql);
    43    
     43
    4444    /* Drop the old sitewide and user activity tables */
    4545    $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->base_prefix}bp_activity_user_activity" );
    4646    $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->base_prefix}bp_activity_sitewide" );
    47    
     47
    4848    /* TODO: Rename the old user activity cached table */
    4949    //$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
     
    5757    /* Internal identifier */
    5858    $bp->activity->id = 'activity';
    59    
     59
    6060    $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity_user_activity_cached';
    6161    $bp->activity->slug = BP_ACTIVITY_SLUG;
    62        
     62
    6363    /* Register this in the active components array */
    6464    $bp->active_components[$bp->activity->slug] = $bp->activity->id;
    65    
     65
    6666    do_action( 'bp_activity_setup_globals' );
    6767}
     
    6969add_action( 'admin_menu', 'bp_activity_setup_globals', 2 );
    7070
    71 function bp_activity_check_installed() {   
     71function bp_activity_check_installed() {
    7272    global $wpdb, $bp;
    73    
     73
    7474    if ( get_site_option('bp-activity-db-version') < BP_ACTIVITY_DB_VERSION )
    7575        bp_activity_install();
     
    100100        } else {
    101101            $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    102             $bp->bp_options_title = $bp->displayed_user->fullname; 
     102            $bp->bp_options_title = $bp->displayed_user->fullname;
    103103        }
    104104    }
     
    120120function bp_activity_screen_my_activity() {
    121121    do_action( 'bp_activity_screen_my_activity' );
    122     bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'activity/just-me' ) );   
     122    bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'activity/just-me' ) );
    123123}
    124124
    125125function bp_activity_screen_friends_activity() {
    126126    do_action( 'bp_activity_screen_friends_activity' );
    127     bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'activity/my-friends' ) );   
     127    bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'activity/my-friends' ) );
    128128}
    129129
     
    148148    /* Check the nonce */
    149149    check_admin_referer( 'bp_activity_delete_link' );
    150    
     150
    151151    $activity_id = $bp->action_variables[0];
    152    
     152
    153153    /* Check access */
    154154    if ( !is_site_admin() ) {
    155155        $activity = new BP_Activity_Activity( $activity_id );
    156        
     156
    157157        if ( $activity->user_id != $bp->loggedin_user->id )
    158158            return false;
    159159    }
    160    
     160
    161161    /* Now delete the activity item */
    162162    if ( bp_activity_delete_by_activity_id( $activity_id ) )
     
    164164    else
    165165        bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
    166        
     166
    167167    do_action( 'bp_activity_action_delete_activity', $activity_id );
    168    
     168
    169169    bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    170170}
     
    187187
    188188function bp_activity_action_personal_feed() {
    189     global $bp, $wp_query; 
     189    global $bp, $wp_query;
    190190
    191191    if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
    192192        return false;
    193    
     193
    194194    $wp_query->is_404 = false;
    195195    status_header( 200 );
     
    206206        return false;
    207207
    208     $wp_query->is_404 = false; 
     208    $wp_query->is_404 = false;
    209209    status_header( 200 );
    210210
    211211    include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
    212     die;   
     212    die;
    213213}
    214214add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
     
    226226function bp_activity_add( $args = '' ) {
    227227    global $bp, $wpdb;
    228    
     228
    229229    $defaults = array(
    230230        'content' => false, // The content of the activity item
     
    232232        'component_name' => false, // The name/ID of the component e.g. groups, profile, mycomponent
    233233        'component_action' => false, // The component action e.g. new_wire_post, profile_updated
    234        
     234
    235235        '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.
    236236        'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id, or wire_post_id
     
    242242    $r = wp_parse_args( $args, $defaults );
    243243    extract( $r, EXTR_SKIP );
    244    
     244
    245245    /* Insert the "time-since" placeholder */
    246246    if ( $content )
     
    257257    $activity->date_recorded = $recorded_time;
    258258    $activity->hide_sitewide = $hide_sitewide;
    259    
     259
    260260    if ( !$activity->save() )
    261261        return false;
    262262
    263263    do_action( 'bp_activity_add', $args );
    264    
     264
    265265    return true;
    266266}
     
    296296    do_action( 'bp_activity_delete_by_activity_id', $activity_id );
    297297
    298     return true;   
     298    return true;
    299299}
    300300
     
    316316
    317317    do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component_name );
    318    
     318
    319319    return true;
    320320}
     
    322322function bp_activity_add_timesince_placeholder( $content ) {
    323323    /* Check a time-since span doesn't already exist */
    324     if ( false === strpos( $content, '<span class="time-since">' ) ) {     
     324    if ( false === strpos( $content, '<span class="time-since">' ) ) {
    325325        if ( !$pos = strpos( $content, '<blockquote' ) ) {
    326326            if ( !$pos = strpos( $content, '<div' ) ) {
     
    331331        }
    332332    }
    333    
     333
    334334    if ( (int) $pos ) {
    335335        $before = substr( $content, 0, (int) $pos );
    336336        $after = substr( $content, (int) $pos, strlen( $content ) );
    337        
     337
    338338        $content = $before . ' <span class="time-since">%s</span>' . $after;
    339339    }
     
    342342}
    343343
    344 function bp_activity_set_action( $component_id, $key, $value ) { 
    345     global $bp; 
    346 
    347     if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) 
    348         return false; 
    349 
    350     $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array( 
    351         'key' => $key, 
    352         'value' => $value 
    353     ), $component_id, $key, $value ); 
    354 } 
    355 
    356 function bp_activity_get_action( $component_id, $key ) { 
    357     global $bp; 
    358 
    359     if ( empty( $component_id ) || empty( $key ) ) 
    360         return false; 
    361 
    362     return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key ); 
    363 } 
     344function bp_activity_set_action( $component_id, $key, $value ) {
     345    global $bp;
     346
     347    if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
     348        return false;
     349
     350    $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
     351        'key' => $key,
     352        'value' => $value
     353    ), $component_id, $key, $value );
     354}
     355
     356function bp_activity_get_action( $component_id, $key ) {
     357    global $bp;
     358
     359    if ( empty( $component_id ) || empty( $key ) )
     360        return false;
     361
     362    return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
     363}
    364364
    365365function bp_activity_check_exists_by_content( $content ) {
     
    389389    // Clear the user's activity from the sitewide stream and clear their activity tables
    390390    BP_Activity_Activity::delete_for_user( $user_id );
    391    
     391
    392392    do_action( 'bp_activity_remove_data', $user_id );
    393393}
     
    398398/* Ordering function - don't call this directly */
    399399function bp_activity_order_by_date( $a, $b ) {
    400     return apply_filters( 'bp_activity_order_by_date', strcasecmp( $b['date_recorded'], $a['date_recorded'] ) );   
     400    return apply_filters( 'bp_activity_order_by_date', strcasecmp( $b['date_recorded'], $a['date_recorded'] ) );
    401401}
    402402
  • trunk/bp-activity/bp-activity-classes.php

    r2036 r2077  
    1111    var $date_recorded;
    1212    var $hide_sitewide = false;
    13    
     13
    1414    function bp_activity_activity( $id = false ) {
    1515        global $bp;
    16        
     16
    1717        if ( $id ) {
    1818            $this->id = $id;
     
    2020        }
    2121    }
    22    
     22
    2323    function populate() {
    2424        global $wpdb, $bp;
    25        
     25
    2626        $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
    27        
     27
    2828        $this->id = $activity->id;
    2929        $this->item_id = $activity->item_id;
     
    3737        $this->hide_sitewide = $activity->hide_sitewide;
    3838    }
    39    
     39
    4040    function save() {
    4141        global $wpdb, $bp, $current_user;
    42        
     42
    4343        do_action( 'bp_activity_before_save', $this );
    4444
    4545        if ( !$this->component_name || !$this->component_action )
    4646            return false;
    47        
     47
    4848        /***
    4949         * Before v1.1 of BuddyPress, activity content was calculated at a later point. This is no longer the
     
    5454                if ( !$fetched_content = call_user_func( $bp->{$this->component_name}->format_activity_function, $this->item_id, $this->user_id, $this->component_action, $this->secondary_item_id, $this->for_secondary_user ) )
    5555                    return false;
    56                
     56
    5757                $this->content = $fetched_content['content'];
    5858                $this->primary_link = $fetched_content['primary_link'];
    5959            }
    6060        }
    61        
     61
    6262        if ( !$this->primary_link )
    6363            $this->primary_link = $bp->loggedin_user->domain;
    64        
     64
    6565        if ( $existing_activity_id = $this->exists() )
    6666            BP_Activity_Activity::delete_by_activity_id( $existing_activity_id );
    67        
     67
    6868        /* If we have an existing ID, update the activity item, otherwise insert it. */
    6969        if ( $this->id ) {
     
    8181        return false;
    8282    }
    83    
     83
    8484    function exists() {
    8585        global $wpdb, $bp;
    86        
     86
    8787        /* This doesn't seem to be working correctly at the moment, so it is disabled [TODO] */
    8888        return false;
    89        
     89
    9090        /* If we have an item id, try and match on that, if not do a content match */
    9191        if ( $this->item_id ) {
    9292            if ( $this->secondary_item_id )
    9393                $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id );
    94                
    95             return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );     
     94
     95            return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );
    9696        } else {
    97             return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );             
    98         }
    99     }
    100    
    101     /* Static Functions */ 
     97            return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );
     98        }
     99    }
     100
     101    /* Static Functions */
    102102
    103103    function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
     
    106106        if ( $secondary_item_id )
    107107            $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id );
    108        
     108
    109109        if ( $component_action )
    110110            $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
    111        
     111
    112112        if ( $user_id )
    113113            $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id );
     
    115115        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
    116116    }
    117    
     117
    118118    function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
    119119        return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
     
    122122    function delete_by_activity_id( $activity_id ) {
    123123        global $bp, $wpdb;
    124        
     124
    125125        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE id = %d", $activity_id ) );
    126126    }
    127    
     127
    128128    function delete_by_content( $user_id, $content, $component_name, $component_action ) {
    129129        global $bp, $wpdb;
    130        
    131         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) );       
    132     }
    133    
     130
     131        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) );
     132    }
     133
    134134    function delete_for_user_by_component( $user_id, $component_name ) {
    135135        global $bp, $wpdb;
    136        
    137         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) );       
    138     }
    139    
     136
     137        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) );
     138    }
     139
    140140    function delete_for_user( $user_id ) {
    141141        global $wpdb, $bp;
     
    143143        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) );
    144144    }
    145    
     145
    146146    function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) {
    147147        global $wpdb, $bp;
    148                
     148
    149149        if ( $limit && $page )
    150150            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    152152        if ( $max_items )
    153153            $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
    154        
     154
    155155        /* Sort out filtering */
    156156        if ( $filter )
    157157            $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    158        
     158
    159159        if ( $limit && $page && $max_items )
    160160            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) );
    161161        else
    162162            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) );
    163        
     163
    164164        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) );
    165        
     165
    166166        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    167167    }
    168    
     168
    169169    function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
    170170        global $wpdb, $bp;
    171        
     171
    172172        // TODO: Max items per friend not yet implemented.
    173        
     173
    174174        if ( !function_exists('friends_get_friend_user_ids') )
    175175            return false;
     
    177177        if ( $limit && $page )
    178178            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    179        
     179
    180180        if ( $max_items )
    181181            $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
     
    189189        if ( !$friend_ids )
    190190            return false;
    191            
     191
    192192        $friend_ids = implode( ',', $friend_ids );
    193        
     193
    194194        if ( $limit && $page && $max_items )
    195             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql"  ) ); 
     195            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql"  ) );
    196196        else
    197             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) );           
    198 
    199         $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 
    200        
     197            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) );
     198
     199        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
     200
    201201        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    202202    }
    203    
     203
    204204    function get_sitewide_activity( $max, $limit, $page, $filter ) {
    205205        global $wpdb, $bp;
    206        
     206
    207207        if ( $limit && $page )
    208208            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    209        
     209
    210210        if ( $max )
    211211            $max_sql = $wpdb->prepare( "LIMIT %d", $max );
    212            
     212
    213213        /* Sort out filtering */
    214214        if ( $filter )
     
    224224        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    225225    }
    226    
     226
    227227    function get_recorded_component_names() {
    228228        global $wpdb, $bp;
    229        
     229
    230230        return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component_name FROM {$bp->activity->table_name} ORDER BY component_name ASC" ) );
    231231    }
    232    
     232
    233233    function get_sitewide_items_for_feed( $limit = 35 ) {
    234234        global $wpdb, $bp;
    235        
     235
    236236        $activities = bp_activity_get_sitewide_activity( $limit );
    237237        for ( $i = 0; $i < count($activities); $i++ ) {
     
    244244        }
    245245
    246         return $activity_feed; 
    247     }
    248    
     246        return $activity_feed;
     247    }
     248
    249249    function get_filter_sql( $filter_array ) {
    250250        global $wpdb;
    251        
     251
    252252        if ( !empty( $filter_array['object'] ) ) {
    253253            $object_filter = explode( ',', $filter_array['object'] );
    254254            $object_sql = ' AND ( ';
    255            
     255
    256256            $counter = 1;
    257257            foreach( (array) $object_filter as $object ) {
    258258                $object_sql .= $wpdb->prepare( "component_name = %s", trim( $object ) );
    259                
     259
    260260                if ( $counter != count( $object_filter ) )
    261261                    $object_sql .= ' || ';
    262                
     262
    263263                $counter++;
    264264            }
    265            
     265
    266266            $object_sql .= ' )';
    267267        }
     
    270270            $action_filter = explode( ',', $filter_array['action'] );
    271271            $action_sql = ' AND ( ';
    272            
     272
    273273            $counter = 1;
    274274            foreach( (array) $action_filter as $action ) {
    275275                $action_sql .= $wpdb->prepare( "component_action = %s", trim( $action ) );
    276                
     276
    277277                if ( $counter != count( $action_filter ) )
    278278                    $action_sql .= ' || ';
    279                
     279
    280280                $counter++;
    281281            }
    282            
     282
    283283            $action_sql .= ' )';
    284284        }
     
    287287            $pid_filter = explode( ',', $filter_array['primary_id'] );
    288288            $pid_sql = ' AND ( ';
    289            
     289
    290290            $counter = 1;
    291291            foreach( (array) $pid_filter as $pid ) {
    292292                $pid_sql .= $wpdb->prepare( "item_id = %s", trim( $pid ) );
    293                
     293
    294294                if ( $counter != count( $pid_filter ) )
    295295                    $pid_sql .= ' || ';
    296                
     296
    297297                $counter++;
    298298            }
    299            
     299
    300300            $pid_sql .= ' )';
    301301        }
     
    304304            $sid_filter = explode( ',', $filter_array['secondary_id'] );
    305305            $sid_sql = ' AND ( ';
    306            
     306
    307307            $counter = 1;
    308308            foreach( (array) $sid_filter as $sid ) {
    309309                $sid_sql .= $wpdb->prepare( "secondary_item_id = %s", trim( $sid ) );
    310                
     310
    311311                if ( $counter != count( $sid_filter ) )
    312312                    $sid_sql .= ' || ';
    313                
     313
    314314                $counter++;
    315315            }
    316            
     316
    317317            $sid_sql .= ' )';
    318318        }
    319        
     319
    320320        return $object_sql . $action_sql . $pid_sql . $sid_sql;
    321321    }
    322    
     322
    323323    function get_last_updated() {
    324324        global $bp, $wpdb;
    325        
     325
    326326        return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
    327327    }
    328    
     328
    329329    function check_exists_by_content( $content ) {
    330330        global $wpdb, $bp;
  • trunk/bp-activity/bp-activity-filters.php

    r2055 r2077  
    1515function bp_activity_filter_kses( $content ) {
    1616    global $allowedtags;
    17    
     17
    1818    $activity_allowedtags = $allowedtags;
    1919    $activity_allowedtags['span'] = array();
    2020    $activity_allowedtags['span']['class'] = array();
    2121    $activity_allowedtags['a']['class'] = array();
    22     $activity_allowedtags['img'] = array(); 
     22    $activity_allowedtags['img'] = array();
    2323    $activity_allowedtags['img']['src'] = array();
    2424    $activity_allowedtags['img']['alt'] = array();
  • trunk/bp-activity/bp-activity-templatetags.php

    r2071 r2077  
    88    var $activity;
    99    var $activity_type;
    10    
     10
    1111    var $in_the_loop;
    12    
     12
    1313    var $pag_page;
    1414    var $pag_num;
     
    2626        if ( $type == 'sitewide' )
    2727            $this->activities = bp_activity_get_sitewide_activity( $max, $this->pag_num, $this->pag_page, $filter );
    28        
     28
    2929        if ( $type == 'personal' )
    3030            $this->activities = bp_activity_get_user_activity( $user_id, $max, $this->pag_num, $this->pag_page, $filter );
     
    3232        if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) )
    3333            $this->activities = bp_activity_get_friends_activity( $user_id, $max, false, $this->pag_num, $this->pag_page, $filter );
    34        
     34
    3535        if ( !$max || $max >= (int)$this->activities['total'] )
    3636            $this->total_activity_count = (int)$this->activities['total'];
    3737        else
    3838            $this->total_activity_count = (int)$max;
    39        
     39
    4040        $this->activities = $this->activities['activities'];
    41        
     41
    4242        if ( $max ) {
    4343            if ( $max >= count($this->activities) )
     
    4848            $this->activity_count = count($this->activities);
    4949        }
    50        
     50
    5151        $this->full_name = $bp->displayed_user->fullname;
    5252
     
    6363        }
    6464    }
    65    
     65
    6666    function has_activities() {
    6767        if ( $this->activity_count )
    6868            return true;
    69        
     69
    7070        return false;
    7171    }
    72    
     72
    7373    function next_activity() {
    7474        $this->current_activity++;
    7575        $this->activity = $this->activities[$this->current_activity];
    76        
     76
    7777        return $this->activity;
    7878    }
    79    
     79
    8080    function rewind_activities() {
    8181        $this->current_activity = -1;
     
    8484        }
    8585    }
    86    
    87     function user_activities() { 
     86
     87    function user_activities() {
    8888        if ( $this->current_activity + 1 < $this->activity_count ) {
    8989            return true;
     
    9797        return false;
    9898    }
    99    
     99
    100100    function the_activity() {
    101101        global $activity;
     
    103103        $this->in_the_loop = true;
    104104        $this->activity = $this->next_activity();
    105        
     105
    106106        if ( is_array( $this->activity ) )
    107107            $this->activity = (object) $this->activity;
     
    114114function bp_has_activities( $args = '' ) {
    115115    global $bp, $activities_template;
    116    
     116
    117117    /* Note: any params used for filtering can be a single value, or multiple values comma separated. */
    118    
     118
    119119    $defaults = array(
    120120        'type' => 'sitewide',
     
    138138            $per_page = $max;
    139139    }
    140    
     140
    141141    if ( isset( $_GET['afilter'] ) )
    142142        $filter = array( 'object' => $_GET['afilter'] );
    143143    else
    144144        $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
    145    
    146     $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter );       
     145
     146    $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter );
    147147    return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
    148148}
     
    160160function bp_activity_pagination_count() {
    161161    global $bp, $activities_template;
    162    
     162
    163163    $from_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
    164164    $to_num = ( $from_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $from_num + ( $activities_template->pag_num - 1) ;
     
    173173    function bp_get_activity_pagination_links() {
    174174        global $activities_template;
    175        
     175
    176176        return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
    177177    }
     
    179179function bp_activities_title() {
    180180    global $bp_activity_title;
    181    
     181
    182182    echo bp_get_activities_title();
    183183}
     
    190190function bp_activities_no_activity() {
    191191    global $bp_activity_no_activity;
    192    
     192
    193193    echo bp_get_activities_no_activity();
    194194}
    195195    function bp_get_activities_no_activity() {
    196196        global $bp_activity_no_activity;
    197        
     197
    198198        return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
    199199    }
     
    218218            'height' => 20,
    219219            'class' => 'avatar',
    220             'alt' => __( 'Avatar', 'buddypress' ) 
     220            'alt' => __( 'Avatar', 'buddypress' )
    221221        );
    222222
    223223        $r = wp_parse_args( $args, $defaults );
    224224        extract( $r, EXTR_SKIP );
    225        
     225
    226226        $item_id = false;
    227227        if ( (int)$activities_template->activity->user_id )
     
    235235        if ( $bp->blogs->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id )
    236236            $object = 'blog';
    237        
     237
    238238        $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component_name, $object );
    239        
     239
    240240        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 ) ) );
    241241    }
     
    248248
    249249        if ( bp_is_home() && $activities_template->activity_type == 'personal' )
    250             $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name );                       
     250            $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name );
    251251        else
    252252            $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name, true, false, false );
     
    254254        /* Add 'the_content' filter to activity to allow existing plugins to replace text as they would on post text. (extra smilies etc) */
    255255        $content = apply_filters( 'the_content', $content );
    256        
     256
    257257        return apply_filters( 'bp_get_activity_content', $content );
    258258    }
     
    260260function bp_activity_content_filter( $content, $date_recorded, $full_name, $insert_time = true, $filter_words = true, $filter_you = true ) {
    261261    global $activities_template, $bp;
    262    
     262
    263263    if ( !$content )
    264264        return false;
    265        
     265
    266266    /* Split the content so we don't evaluate and replace text on content we don't want to */
    267267    $content = explode( '%s', $content );
     
    273273    if ( $insert_time )
    274274        $content[0] = bp_activity_insert_time_since( $content[0], $date_recorded );
    275    
     275
    276276    // The "You" and "Your" conversion is only done in english, if a translation file is present
    277277    // then do not translate as it causes problems in other languages.
     
    284284        /* Remove the 'You' and replace if with the persons name */
    285285        if ( $filter_you && $full_name != '' ) {
    286             $content[0] = preg_replace( "/{$full_name}[<]/", 'You<', $content[0], 1 );             
     286            $content[0] = preg_replace( "/{$full_name}[<]/", 'You<', $content[0], 1 );
    287287        }
    288288    }
     
    290290    /* Add the delete link if the user has permission on this item */
    291291    if ( ( $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || is_site_admin() )
    292         $content[1] = '</span> <span class="activity-delete-link">' . bp_get_activity_delete_link() . '</span>' . $content[1]; 
    293    
     292        $content[1] = '</span> <span class="activity-delete-link">' . bp_get_activity_delete_link() . '</span>' . $content[1];
     293
    294294    $content_new = '';
    295    
     295
    296296    for ( $i = 0; $i < count($content); $i++ )
    297297        $content_new .= $content[$i];
    298    
     298
    299299    return apply_filters( 'bp_activity_content_filter', $content_new );
    300300}
     
    306306    // Make sure we don't have any URL encoding in links when trying to insert the time.
    307307    $content = urldecode($content);
    308    
     308
    309309    return apply_filters( 'bp_activity_insert_time_since', @sprintf( $content, @sprintf( __( '&nbsp; %s ago', 'buddypress' ), bp_core_time_since( strtotime( $date ) ) ) ) );
    310310}
     
    315315    function bp_get_activity_css_class() {
    316316        global $activities_template;
    317        
     317
    318318        return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component_name );
    319319    }
     
    333333    function bp_get_activity_filter_links( $args = false ) {
    334334        global $activities_template, $bp;
    335        
     335
    336336        $defaults = array(
    337337            'style' => 'list'
     
    340340        $r = wp_parse_args( $args, $defaults );
    341341        extract( $r, EXTR_SKIP );
    342        
     342
    343343        /* Fetch the names of components that have activity recorded in the DB */
    344344        $component_names = BP_Activity_Activity::get_recorded_component_names();
    345        
     345
    346346        if ( !$component_names )
    347347            return false;
    348        
     348
    349349        foreach ( (array) $component_names as $component_name ) {
    350350            if ( isset( $_GET['afilter'] ) && $component_name == $_GET['afilter'] )
     
    352352            else
    353353                unset($selected);
    354            
     354
     355            $component_name = attribute_escape( $component_name );
     356
    355357            $component_name = attribute_escape( $component_name );
    356358
     
    372374                break;
    373375            }
    374            
     376
    375377            $link = add_query_arg( 'afilter', $component_name );
    376378            $link = remove_query_arg( 'acpage' , $link );
    377379
    378380            $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component_name );
    379            
     381
    380382            /* Make sure all core internal component names are translatable */
    381383            $translatable_component_names = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
    382            
     384
    383385            $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component_name, 'buddypress' ) ) . '</a>' . $after;
    384386        }
     
    388390        if ( isset( $_GET['afilter'] ) )
    389391            $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
    390        
    391         return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
     392
     393        return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
    392394    }
    393395
     
    410412            return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/feed' );
    411413        else
    412             return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' );       
     414            return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' );
    413415    }
    414416
     
    421423        global $activities_template;
    422424
    423         return apply_filters( 'bp_get_activity_feed_item_title', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );   
     425        return apply_filters( 'bp_get_activity_feed_item_title', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
    424426    }
    425427
     
    453455
    454456function bp_activity_feed_item_description() {
    455     echo bp_get_activity_feed_item_description();   
     457    echo bp_get_activity_feed_item_description();
    456458}
    457459    function bp_get_activity_feed_item_description() {
    458460        global $activities_template;
    459461
    460         return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $activities_template->activity->content ), ENT_COMPAT, 'UTF-8' ) );   
     462        return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $activities_template->activity->content ), ENT_COMPAT, 'UTF-8' ) );
    461463    }
    462464
  • trunk/bp-activity/bp-activity-widgets.php

    r1926 r2077  
    1414    function widget($args, $instance) {
    1515        global $bp;
    16        
     16
    1717        extract( $args );
    18        
     18
    1919        echo $before_widget;
    2020        echo $before_title
    21            . $widget_name . 
    22              ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>' 
     21           . $widget_name .
     22             ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
    2323           . $after_title; ?>
    24    
     24
    2525    <?php if ( bp_has_activities( 'type=sitewide&max=' . $instance['max_items'] . '&per_page=' . $instance['per_page'] ) ) : ?>
    2626
     
    3030                    <?php bp_activity_pagination_count() ?>
    3131                </div>
    32        
     32
    3333                <div class="pagination-links" id="activity-pag">
    3434                    &nbsp; <?php bp_activity_pagination_links() ?>
    3535                </div>
    3636            </div>
    37        
     37
    3838            <ul id="activity-filter-links">
    3939                <?php bp_activity_filter_links() ?>
    4040            </ul>
    4141        <?php endif; ?>
    42        
     42
    4343        <ul id="site-wide-stream" class="activity-list">
    4444        <?php while ( bp_activities() ) : bp_the_activity(); ?>
     
    4949                    </div>
    5050                <?php endif; ?>
    51                
     51
    5252                <?php bp_activity_content() ?>
    5353            </li>
     
    6161        </div>
    6262    <?php endif;?>
    63    
     63
    6464    <?php echo $after_widget; ?>
    6565    <?php
  • trunk/bp-activity/deprecated/bp-activity-deprecated.php

    r1909 r2077  
    44 *
    55 * This file contains functions that are deprecated.
    6  * You should not under any circumstance use these functions as they are 
     6 * You should not under any circumstance use these functions as they are
    77 * either no longer valid, or have been replaced with something much more awesome.
    88 *
     
    1313 * Of course, things will still work if you use these functions but you will
    1414 * be the laughing stock of the BuddyPress community. We will all point and laugh at
    15  * you. You'll also be making things harder for yourself in the long run, 
     15 * you. You'll also be making things harder for yourself in the long run,
    1616 * and you will miss out on lovely performance and functionality improvements.
    17  * 
     17 *
    1818 * If you've checked you are not using any deprecated functions and finished your little
    1919 * dance, you can add the following line to your wp-config.php file to prevent any of
     
    2525function bp_activity_deprecated_globals() {
    2626    global $bp;
    27    
     27
    2828    /* If we are using a BuddyPress 1.1+ theme ignore this. */
    2929    if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
     
    3232    $bp->activity->image_base = BP_PLUGIN_URL . '/bp-activity/images';
    3333}
    34 add_action( 'plugins_loaded', 'bp_activity_deprecated_globals', 5 );   
     34add_action( 'plugins_loaded', 'bp_activity_deprecated_globals', 5 );
    3535add_action( 'admin_menu', 'bp_activity_deprecated_globals', 2 );
    3636
     
    3838function bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id = false, $user_id = false, $secondary_user_id = false, $recorded_time = false ) {
    3939    global $bp, $wpdb;
    40    
     40
    4141    if ( !$user_id )
    4242        $user_id = $bp->loggedin_user->id;
     
    4444    if ( !$recorded_time )
    4545        $recorded_time = time();
    46    
     46
    4747    $args = compact( 'user_id', 'content', 'component_name', 'component_action', 'item_id', 'secondary_item_id', 'recorded_time' );
    4848    bp_activity_add( $args );
    49    
     49
    5050    if ( $secondary_user_id  ) {
    5151        $hide_sitewide = true;
     
    5353        bp_activity_add( $args );
    5454    }
    55    
     55
    5656    do_action( 'bp_activity_record', $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
    57    
     57
    5858    return true;
    5959}
    6060
    6161/* DEPRECATED - use bp_activity_delete_by_item_id() */
    62 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 
     62function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) {
    6363    if ( !bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component_name' => $component_name, 'component_action' => $component_action, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) ) )
    6464        return false;
    65        
     65
    6666    do_action( 'bp_activity_delete', $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    67    
     67
    6868    return true;
    6969}
     
    7272function bp_activity_get_list( $user_id, $title, $no_activity, $limit = false ) {
    7373    global $bp_activity_user_id, $bp_activity_limit, $bp_activity_title, $bp_activity_no_activity;
    74    
     74
    7575    $bp_activity_user_id = $user_id;
    7676    $bp_activity_limit = $limit;
    7777    $bp_activity_title = $title;
    7878    $bp_activity_no_activity = $no_activity;
    79    
     79
    8080    locate_template( array( '/activity/activity-list.php' ), true );
    8181}
     
    8787    if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
    8888        return $template;
    89        
     89
    9090    /* Enqueue the structure CSS file to give basic positional formatting for components */
    91     wp_enqueue_style( 'bp-activity-structure', BP_PLUGIN_URL . '/bp-activity/deprecated/css/structure.css' );   
     91    wp_enqueue_style( 'bp-activity-structure', BP_PLUGIN_URL . '/bp-activity/deprecated/css/structure.css' );
    9292}
    9393add_action( 'bp_styles', 'bp_activity_add_structure_css' );
  • trunk/bp-blogs.php

    r2055 r2077  
    1313/* Include deprecated functions if settings allow */
    1414if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    15     require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' ); 
    16    
     15    require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' );
     16
    1717function bp_blogs_install() {
    1818    global $wpdb, $bp;
    19    
     19
    2020    if ( !empty($wpdb->charset) )
    2121        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    22    
     22
    2323    $sql[] = "CREATE TABLE {$bp->blogs->table_name} (
    2424                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    5252                KEY comment_post_id (comment_post_id)
    5353             ) {$charset_collate};";
    54    
     54
    5555    $sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
    5656            id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    6161            KEY meta_key (meta_key)
    6262           ) {$charset_collate};";
    63        
    64    
     63
     64
    6565    require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    6666
     
    6969    // On first installation - record all existing blogs in the system.
    7070    if ( !(int)get_site_option( 'bp-blogs-first-install') ) {
    71        
     71
    7272        bp_blogs_record_existing_blogs();
    7373        add_site_option( 'bp-blogs-first-install', 1 );
    74        
     74
    7575    } else {
    76        
    77         // Import blog titles and descriptions into the blogmeta table 
     76
     77        // Import blog titles and descriptions into the blogmeta table
    7878        if ( get_site_option( 'bp-blogs-version' ) <= '0.1.5' ) {
    7979            $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $bp->blogs->table_name ) );
     
    8282                $name = get_blog_option( $blog_ids[$i], 'blogname' );
    8383                $desc = get_blog_option( $blog_ids[$i], 'blogdescription' );
    84                
     84
    8585                bp_blogs_update_blogmeta( $blog_ids[$i], 'name', $name );
    8686                bp_blogs_update_blogmeta( $blog_ids[$i], 'description', $desc );
     
    8888            }
    8989        }
    90        
    91     }
    92    
     90
     91    }
     92
    9393    update_site_option( 'bp-blogs-db-version', BP_BLOGS_DB_VERSION );
    9494}
    9595
    96 function bp_blogs_check_installed() {   
     96function bp_blogs_check_installed() {
    9797    global $wpdb, $bp, $userdata;
    98    
     98
    9999    if ( is_site_admin() ) {
    100100        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     
    107107function bp_blogs_setup_globals() {
    108108    global $bp, $wpdb;
    109    
     109
    110110    /* For internal identification */
    111111    $bp->blogs->id = 'blogs';
    112    
     112
    113113    $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
    114114    $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts';
     
    117117    $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
    118118    $bp->blogs->slug = BP_BLOGS_SLUG;
    119    
     119
    120120    /* Register this in the active components array */
    121121    $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
     
    123123    do_action( 'bp_blogs_setup_globals' );
    124124}
    125 add_action( 'plugins_loaded', 'bp_blogs_setup_globals', 5 );   
     125add_action( 'plugins_loaded', 'bp_blogs_setup_globals', 5 );
    126126add_action( 'admin_menu', 'bp_blogs_setup_globals', 2 );
    127127
     
    136136 *
    137137 * Adds "Blog" to the navigation arrays for the current and logged in user.
    138  * 
     138 *
    139139 * @package BuddyPress Blogs
    140140 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    143143function bp_blogs_setup_nav() {
    144144    global $bp;
    145    
     145
    146146    /* Add 'Blogs' to the main navigation */
    147147    bp_core_new_nav_item( array( 'name' => __( 'Blogs', 'buddypress' ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    148    
     148
    149149    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
    150    
     150
    151151    /* Add the subnav items to the blogs nav item */
    152152    bp_core_new_subnav_item( array( 'name' => __( 'My Blogs', 'buddypress' ), 'slug' => 'my-blogs', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_my_blogs', 'position' => 10, 'item_css_id' => 'my-blogs-list' ) );
     
    159159        if ( bp_is_home() ) {
    160160            if ( function_exists('xprofile_setup_nav') ) {
    161                 $bp->bp_options_title = __('My Blogs', 'buddypress'); 
     161                $bp->bp_options_title = __('My Blogs', 'buddypress');
    162162            }
    163163        } else {
    164164            /* If we are not viewing the logged in user, set up the current users avatar and name */
    165165            $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    166             $bp->bp_options_title = $bp->displayed_user->fullname; 
     166            $bp->bp_options_title = $bp->displayed_user->fullname;
    167167        }
    168168    }
    169    
     169
    170170    do_action( 'bp_blogs_setup_nav' );
    171171}
     
    178178    if ( $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
    179179        $bp->is_directory = true;
    180        
     180
    181181        do_action( 'bp_blogs_directory_blogs_setup' );
    182182        bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'directories/blogs/index' ) );
     
    196196function bp_blogs_screen_my_blogs() {
    197197    do_action( 'bp_blogs_screen_my_blogs' );
    198     bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) );   
     198    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) );
    199199}
    200200
     
    224224function bp_blogs_register_activity_actions() {
    225225    global $bp;
    226    
     226
    227227    if ( !function_exists( 'bp_activity_set_action' ) )
    228228        return false;
     
    238238function bp_blogs_record_activity( $args = '' ) {
    239239    global $bp;
    240    
     240
    241241    if ( !function_exists( 'bp_activity_add' ) )
    242242        return false;
    243        
     243
    244244    /* Because blog, comment, and blog post code execution happens before anything else
    245245       we may need to manually instantiate the activity component globals */
    246246    if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
    247247        bp_activity_setup_globals();
    248        
     248
    249249    $defaults = array(
    250250        'user_id' => $bp->loggedin_user->id,
     
    260260
    261261    $r = wp_parse_args( $args, $defaults );
    262     extract( $r, EXTR_SKIP );   
    263    
     262    extract( $r, EXTR_SKIP );
     263
    264264    return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    265265}
     
    268268    if ( function_exists('bp_activity_delete_by_item_id') ) {
    269269        extract($args);
    270        
    271         bp_activity_delete_by_item_id( array( 
    272             'item_id' => $item_id, 
     270
     271        bp_activity_delete_by_item_id( array(
     272            'item_id' => $item_id,
    273273            'component_name' => $component_name,
    274             'component_action' => $component_action, 
     274            'component_action' => $component_action,
    275275            'user_id' => $user_id,
    276276            'secondary_item_id' => $secondary_item_id
     
    292292
    293293    $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE public = 1 AND mature = 0 AND spam = 0 AND deleted = 0" ) );
    294    
     294
    295295    if ( $blog_ids ) {
    296296        foreach( $blog_ids as $blog_id ) {
     
    311311function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = true ) {
    312312    global $bp;
    313    
     313
    314314    if ( !$user_id )
    315315        $user_id = $bp->loggedin_user->id;
    316    
     316
    317317    $name = get_blog_option( $blog_id, 'blogname' );
    318318    $description = get_blog_option( $blog_id, 'blogdescription' );
    319    
     319
    320320    $recorded_blog = new BP_Blogs_Blog;
    321321    $recorded_blog->user_id = $user_id;
     
    323323
    324324    $recorded_blog_id = $recorded_blog->save();
    325    
     325
    326326    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    327327    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    328328    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', time() );
    329    
     329
    330330    /* Only record this activity if the blog is public */
    331331    if ( (int)$_POST['blog_public'] || !$no_activity ) {
     
    333333        bp_blogs_record_activity( array(
    334334            'user_id' => $recorded_blog->user_id,
    335             'content' => apply_filters( 'bp_blogs_activity_created_blog', sprintf( __( '%s created the blog %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 ), 
     335            'content' => apply_filters( 'bp_blogs_activity_created_blog', sprintf( __( '%s created the blog %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 ),
    336336            'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
    337337            'component_action' => 'new_blog',
     
    339339        ) );
    340340    }
    341    
     341
    342342    do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded );
    343343}
     
    346346function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
    347347    global $bp, $wpdb;
    348    
     348
    349349    $post_id = (int)$post_id;
    350350    $blog_id = (int)$wpdb->blogid;
    351    
     351
    352352    if ( !$user_id )
    353353        $user_id = (int)$post->post_author;
    354    
    355354    /* This is to stop infinate loops with Donncha's sitewide tags plugin */
    356355    if ( (int)get_site_option( 'tags_blog_id' ) == (int)$blog_id )
    357356        return false;
    358    
     357
    359358    /* Don't record this if it's not a post */
    360359    if ( $post->post_type != 'post' )
    361360        return false;
    362    
     361
    363362    if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
    364363        if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    365            
     364
    366365            $recorded_post = new BP_Blogs_Post;
    367366            $recorded_post->user_id = $user_id;
     
    369368            $recorded_post->post_id = $post_id;
    370369            $recorded_post->date_created = strtotime( $post->post_date );
    371            
     370
    372371            $recorded_post_id = $recorded_post->save();
    373            
     372
    374373            bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', time() );
    375374
     
    380379                $activity_content = 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>' );
    381380                $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
    382            
     381
    383382                bp_blogs_record_activity( array(
    384383                    'user_id' => (int)$post->post_author,
    385                     'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 
     384                    'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ),
    386385                    'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    387386                    'component_action' => 'new_blog_post',
     
    399398        /* Delete the recorded post if the status is not published or it is password protected */
    400399        if ( 'publish' != $post->post_status || '' != $post->post_password ) {
    401             return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );         
    402        
     400            return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
     401
    403402        /* If the post author has changed, delete the post and re-add it. */
    404403        } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
    405404            // Delete the existing recorded post
    406405            bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
    407            
     406
    408407            // Re-record the post with the new author.
    409             bp_blogs_record_post( $post_id );               
     408            bp_blogs_record_post( $post_id );
    410409        }
    411410
    412411        if ( (int)get_blog_option( $blog_id, 'blog_public' ) ) {
    413             /* Now re-record the post in the activity streams */       
     412            /* Now re-record the post in the activity streams */
    414413            $post_permalink = bp_post_get_permalink( $post, $blog_id );
    415414
    416415            $activity_content = 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>' );
    417416            $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
    418        
     417
    419418            /* Record this in activity streams */
    420419            bp_blogs_record_activity( array(
    421420                'user_id' => (int)$post->post_author,
    422                 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 
     421                'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ),
    423422                'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    424423                'component_action' => 'new_blog_post',
     
    435434function bp_blogs_record_comment( $comment_id, $is_approved ) {
    436435    global $wpdb, $bp;
    437    
     436
    438437    if ( !$is_approved )
    439438        return false;
    440        
     439
    441440    $comment = get_comment($comment_id);
    442441    $comment->post = get_post( $comment->comment_post_ID );
    443    
     442
    444443    /* Get the user_id from the author email. */
    445444    $user = get_user_by_email( $comment->comment_author_email );
    446445    $user_id = (int)$user->ID;
    447    
     446
    448447    if ( !$user_id )
    449448        return false;
     
    457456
    458457    $recorded_commment_id = $recorded_comment->save();
    459    
     458
    460459    bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', time() );
    461460
     
    463462        /* Record in activity streams */
    464463        $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id );
    465         $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );         
     464        $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    466465        $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>';
    467466
     
    469468        bp_blogs_record_activity( array(
    470469            'user_id' => $recorded_comment->user_id,
    471             'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 
     470            'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    472471            'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    473472            'component_action' => 'new_blog_comment',
     
    484483function bp_blogs_approve_comment( $comment_id, $comment_status ) {
    485484    global $bp, $wpdb;
    486    
     485
    487486    if ( 'approve' != $comment_status )
    488487        return false;
     
    491490    $comment = get_comment($comment_id);
    492491    $comment->post = get_post( $comment->comment_post_ID );
    493    
     492
    494493    bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) );
    495494
     
    497496        /* Record in activity streams */
    498497        $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id );
    499         $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );           
     498        $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    500499        $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>';
    501500
     
    503502        bp_blogs_record_activity( array(
    504503            'user_id' => $recorded_comment->user_id,
    505             'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 
     504            'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    506505            'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    507506            'component_action' => 'new_blog_comment',
    508507            'item_id' => $comment_id,
    509508            'secondary_item_id' => $recorded_comment->blog_id,
    510             'recorded_time' =>  $recorded_comment->date_created 
     509            'recorded_time' =>  $recorded_comment->date_created
    511510        ) );
    512511    }
     
    516515function bp_blogs_unapprove_comment( $comment_id, $comment_status ) {
    517516    if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status )
    518         bp_blogs_remove_comment( $comment_id );     
     517        bp_blogs_remove_comment( $comment_id );
    519518}
    520519add_action( 'wp_set_comment_status', 'bp_blogs_unapprove_comment', 10, 2 );
     
    538537
    539538    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    540    
     539
    541540    // Delete activity stream item
    542541    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) );
    543    
     542
    544543    do_action( 'bp_blogs_remove_blog', $blog_id );
    545544}
     
    548547function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
    549548    global $current_user;
    550    
     549
    551550    $blog_id = (int)$blog_id;
    552551    $user_id = (int)$user_id;
     
    565564
    566565    $post_id = (int)$post_id;
    567    
     566
    568567    if ( !$blog_id )
    569568        $blog_id = (int)$current_blog->blog_id;
    570    
     569
    571570    if ( !$existing_post )
    572571        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
     
    574573    // Delete post from the bp_blogs table
    575574    BP_Blogs_Post::delete( $post_id, $blog_id );
    576        
     575
    577576    // Delete activity stream item
    578577    bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) );
     
    586585
    587586    $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
    588     BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid ); 
     587    BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
    589588
    590589    // Delete activity stream item
     
    597596function bp_blogs_remove_data_for_blog( $blog_id ) {
    598597    global $bp;
    599    
     598
    600599    /* If this is regular blog, delete all data for that blog. */
    601600    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    602     BP_Blogs_Post::delete_posts_for_blog( $blog_id );       
     601    BP_Blogs_Post::delete_posts_for_blog( $blog_id );
    603602    BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
    604603
     
    624623function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
    625624    global $bp;
    626    
     625
    627626    if ( !is_numeric( $limit ) )
    628627        $limit = 5;
    629    
     628
    630629    return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
    631630}
     
    645644function bp_blogs_total_post_count( $blog_id ) {
    646645    return BP_Blogs_Post::total_post_count( $blog_id );
    647 } 
     646}
    648647
    649648function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
    650649    return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
    651 } 
     650}
    652651
    653652function bp_blogs_is_blog_hidden( $blog_id ) {
     
    657656function bp_blogs_redirect_to_random_blog() {
    658657    global $bp, $wpdb;
    659    
     658
    660659    if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
    661660        $blog = bp_blogs_get_random_blog();
     
    676675function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
    677676    global $wpdb, $bp;
    678    
     677
    679678    if ( !is_numeric( $blog_id ) )
    680679        return false;
    681        
     680
    682681    $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
    683682
    684683    if ( is_array($meta_value) || is_object($meta_value) )
    685684        $meta_value = serialize($meta_value);
    686        
     685
    687686    $meta_value = trim( $meta_value );
    688687
    689688    if ( !$meta_key ) {
    690         $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );     
     689        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
    691690    } else if ( $meta_value ) {
    692691        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
     
    694693        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
    695694    }
    696    
     695
    697696    // TODO need to look into using this.
    698697    // wp_cache_delete($group_id, 'groups');
     
    703702function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
    704703    global $wpdb, $bp;
    705    
     704
    706705    $blog_id = (int) $blog_id;
    707706
     
    711710    if ( !empty($meta_key) ) {
    712711        $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
    713        
     712
    714713        // TODO need to look into using this.
    715714        //$user = wp_cache_get($user_id, 'users');
    716        
     715
    717716        // Check the cached user object
    718717        //if ( false !== $user && isset($user->$meta_key) )
     
    741740function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
    742741    global $wpdb, $bp;
    743    
     742
    744743    if ( !is_numeric( $blog_id ) )
    745744        return false;
    746    
     745
    747746    $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
    748747
    749748    if ( is_string($meta_value) )
    750749        $meta_value = stripslashes($wpdb->escape($meta_value));
    751        
     750
    752751    $meta_value = maybe_serialize($meta_value);
    753752
     
    757756
    758757    $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
    759    
     758
    760759    if ( !$cur ) {
    761760        $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) );
     
    775774    /* If this is regular blog, delete all data for that blog. */
    776775    BP_Blogs_Blog::delete_blogs_for_user( $user_id );
    777     BP_Blogs_Post::delete_posts_for_user( $user_id );       
     776    BP_Blogs_Post::delete_posts_for_user( $user_id );
    778777    BP_Blogs_Comment::delete_comments_for_user( $user_id );
    779778
  • trunk/bp-core.php

    r2059 r2077  
    44define( 'BP_CORE_DB_VERSION', '1800' );
    55
    6 /*** 
    7  * Define the path and url of the BuddyPress plugins directory. 
    8  * It is important to use plugins_url() core function to obtain 
    9  * the correct scheme used (http or https). 
     6/***
     7 * Define the path and url of the BuddyPress plugins directory.
     8 * It is important to use plugins_url() core function to obtain
     9 * the correct scheme used (http or https).
    1010 */
    1111define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' );
     
    6666if ( !defined( 'BP_HOME_BLOG_SLUG' ) )
    6767    define( 'BP_HOME_BLOG_SLUG', 'blog' );
    68    
     68
     69/* Register BuddyPress themes contained within the theme folder */
     70if ( function_exists( 'register_theme_folder' ) )
     71    register_theme_folder( 'buddypress/bp-themes' );
     72
    6973/* Register BuddyPress themes contained within the theme folder */
    7074if ( function_exists( 'register_theme_folder' ) )
     
    9498    global $displayed_user_id;
    9599    global $action_variables;
    96    
     100
    97101    $current_user = wp_get_current_user();
    98102
    99     /* The domain for the root of the site where the main blog resides */   
     103    /* The domain for the root of the site where the main blog resides */
    100104    $bp->root_domain = bp_core_get_root_domain();
    101    
     105
    102106    /* The user ID of the user who is currently logged in. */
    103107    $bp->loggedin_user->id = $current_user->ID;
     
    105109    /* The domain for the user currently logged in. eg: http://domain.com/members/andy */
    106110    $bp->loggedin_user->domain = bp_core_get_user_domain($current_user->ID);
    107    
     111
    108112    /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
    109113    $bp->displayed_user->id = $displayed_user_id;
    110    
     114
    111115    /* The domain for the user currently being displayed */
    112116    $bp->displayed_user->domain = bp_core_get_user_domain($displayed_user_id);
    113    
     117
    114118    /* The component being used eg: http://domain.com/members/andy/ [profile] */
    115119    $bp->current_component = $current_component; // type: string
    116    
     120
    117121    /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */
    118122    $bp->current_action = $current_action; // type: string
    119    
     123
    120124    /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */
    121125    $bp->action_variables = $action_variables; // type: array
    122    
     126
    123127    /* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/
    124128    $bp->current_item = ''; // type: string
     
    135139    /* Sets up the array container for the component navigation rendered by bp_get_nav() */
    136140    $bp->bp_nav = array();
    137    
     141
    138142    /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
    139143    $bp->bp_options_nav = array();
    140    
     144
    141145    /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */
    142146    $bp->bp_options_title = '';
    143    
     147
    144148    /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */
    145149    $bp->bp_options_avatar = '';
    146    
     150
    147151    /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
    148152    $bp->active_components = array();
    149    
     153
    150154    /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
    151155    $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', get_site_option( 'user-avatar-default' ) );
    152156    $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
    153157    $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
    154    
     158
    155159    /* Fetch the full name for the logged in and current user */
    156160    $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
     
    162166       'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
    163167    $bp->is_item_admin = bp_is_home();
    164    
     168
    165169    /* Used to determine if the logged in user is a moderator for the current content. */
    166170    $bp->is_item_mod = false;
     
    170174    if ( !$bp->current_component )
    171175        $bp->current_component = $bp->default_component;
    172    
     176
    173177    do_action( 'bp_core_setup_globals' );
    174178}
     
    183187 *
    184188 * For example: http://example.org/search or http://example.org/members
    185  * 
     189 *
    186190 * @package BuddyPress Core
    187191 * @uses bp_core_add_root_component() Adds a slug to the root components global variable.
     
    202206 *
    203207 * Installs the core DB tables for BuddyPress.
    204  * 
     208 *
    205209 * @package BuddyPress Core
    206210 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    211215function bp_core_install() {
    212216    global $wpdb, $bp;
    213    
     217
    214218    if ( !empty($wpdb->charset) )
    215219        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    216    
     220
    217221    $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (
    218222                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    235239    require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
    236240    dbDelta( $sql );
    237    
     241
    238242    /* Add names of root components to the banned blog list to avoid conflicts */
    239243    bp_core_add_illegal_names();
    240    
     244
    241245    update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
    242246}
     
    246250 *
    247251 * Checks to make sure the database tables are set up for the core component.
    248  * 
     252 *
    249253 * @package BuddyPress Core
    250254 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    260264    if ( !is_site_admin() )
    261265        return false;
    262    
     266
    263267    require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' );
    264268
     
    273277 *
    274278 * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
    275  * 
     279 *
    276280 * @package BuddyPress Core
    277281 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    281285 */
    282286function bp_core_add_admin_menu() {
    283     global $wpdb, $bp, $menu;
    284    
    285287    if ( !is_site_admin() )
    286288        return false;
    287        
     289
    288290    /* Add the administration tab under the "Site Admin" tab for site administrators */
    289291    bp_core_add_admin_menu_page( array(
     
    294296        'position' => 2
    295297    ) );
    296    
     298
    297299    add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
    298300    add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
     
    305307 * Checks to see if a component's URL should be in the root, not under a member page:
    306308 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
    307  * 
     309 *
    308310 * @package BuddyPress Core
    309311 * @return true if root component, else false.
     
    319321 *
    320322 * Sets up the profile navigation item if the Xprofile component is not installed.
    321  * 
     323 *
    322324 * @package BuddyPress Core
    323325 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    329331function bp_core_setup_nav() {
    330332    global $bp;
    331    
    332     /*** 
     333
     334    /***
    333335     * If the extended profiles component is disabled, we need to revert to using the
    334336     * built in WordPress profile information
     
    340342
    341343        /* Add 'Profile' to the main navigation */
    342         bp_core_new_nav_item( array( 
     344        bp_core_new_nav_item( array(
    343345            'name' => __('Profile', 'buddypress'),
    344346            'slug' => $bp->core->profile->slug,
     
    349351
    350352        $profile_link = $bp->loggedin_user->domain . '/profile/';
    351        
     353
    352354        /* Add the subnav items to the profile */
    353355        bp_core_new_subnav_item( array(
     
    358360            'screen_function' => 'bp_core_catch_profile_uri'
    359361        ) );
    360        
     362
    361363
    362364        if ( 'profile' == $bp->current_component ) {
     
    365367            } else {
    366368                $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    367                 $bp->bp_options_title = $bp->displayed_user->fullname; 
     369                $bp->bp_options_title = $bp->displayed_user->fullname;
    368370            }
    369371        }
    370     }   
     372    }
    371373}
    372374add_action( 'plugins_loaded', 'bp_core_setup_nav' );
     
    397399 * Listens to the $bp component and action variables to determine if the user is viewing the members
    398400 * directory page. If they are, it will set up the directory and load the members directory template.
    399  * 
     401 *
    400402 * @package BuddyPress Core
    401403 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    421423 * this action will fire and mark or unmark the user and their blogs as spam.
    422424 * Must be a site admin for this function to run.
    423  * 
     425 *
    424426 * @package BuddyPress Core
    425427 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    427429function bp_core_action_set_spammer_status() {
    428430    global $bp;
    429    
     431
    430432    if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id )
    431433        return false;
    432            
     434
    433435    if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
    434436        /* Check the nonce */
     
    437439        /* Get the functions file */
    438440        require( ABSPATH . 'wp-admin/includes/mu.php' );
    439        
     441
    440442        if ( 'mark-spammer' == $bp->current_action )
    441443            $is_spam = 1;
     
    445447        /* Get the blogs for the user */
    446448        $blogs = get_blogs_of_user( $bp->displayed_user->id, true );
    447    
     449
    448450        foreach ( (array) $blogs as $key => $details ) {
    449451            /* Do not mark the main or current root blog as spam */
    450             if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 
    451                 continue; 
    452        
     452            if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
     453                continue;
     454
    453455            /* Update the blog status */
    454456            update_blog_status( $details->userblog_id, 'spam', $is_spam );
    455        
     457
    456458            /* Fire the standard WPMU hook */
    457459            do_action( 'make_spam_blog', $details->userblog_id );
    458460        }
    459    
     461
    460462        /* Finally, mark this user as a spammer */
    461463        update_user_status( $bp->displayed_user->id, 'spam', $is_spam, 1 );
    462        
     464
    463465        if ( $is_spam )
    464466            bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
    465467        else
    466468            bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
    467            
     469
    468470        do_action( 'bp_core_action_set_spammer_status' );
    469        
     471
    470472        bp_core_redirect( wp_get_referer() );
    471473    }
     
    477479 *
    478480 * Allows a site admin to delete a user from the adminbar menu.
    479  * 
     481 *
    480482 * @package BuddyPress Core
    481483 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    483485function bp_core_action_delete_user() {
    484486    global $bp;
    485    
     487
    486488    if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id )
    487489        return false;
    488            
     490
    489491    if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
    490492        /* Check the nonce */
     
    492494
    493495        $errors = false;
    494        
     496
    495497        if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
    496498            bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );
     
    499501            $errors = true;
    500502        }
    501        
     503
    502504        do_action( 'bp_core_action_set_spammer_status', $errors );
    503        
     505
    504506        if ( $errors )
    505507            bp_core_redirect( $bp->displayed_user->domain );
     
    525527 * Returns the domain for the passed user:
    526528 * e.g. http://domain.com/members/andy/
    527  * 
     529 *
    528530 * @package BuddyPress Core
    529531 * @global $current_user WordPress global variable containing current logged in user information
     
    533535function bp_core_get_user_domain( $user_id ) {
    534536    global $bp;
    535    
     537
    536538    if ( !$user_id ) return;
    537    
     539
    538540    $ud = get_userdata($user_id);
    539    
     541
    540542    if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    541543        $username = $ud->user_login;
    542544    else
    543545        $username = $ud->user_nicename;
    544    
     546
    545547    /* If we are using a members slug, include it. */
    546548    if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
    547549        return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/' );
    548550    else
    549         return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' );       
     551        return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' );
    550552}
    551553
     
    555557 * Returns the domain for the root blog.
    556558 * eg: http://domain.com/ OR https://domain.com
    557  * 
     559 *
    558560 * @package BuddyPress Core
    559561 * @uses get_blog_option() WordPress function to fetch blog meta.
     
    562564function bp_core_get_root_domain() {
    563565    global $current_blog;
    564    
     566
    565567    if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
    566568        $domain = get_blog_option( $current_blog->blog_id, 'siteurl' );
     
    576578 * Returns the user id for the user that is currently being displayed.
    577579 * eg: http://andy.domain.com/ or http://domain.com/andy/
    578  * 
     580 *
    579581 * @package BuddyPress Core
    580582 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
     
    590592 *
    591593 * Adds a navigation item to the main navigation array used in BuddyPress themes.
    592  * 
     594 *
    593595 * @package BuddyPress Core
    594596 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    614616    if ( empty($name) || empty($slug) )
    615617        return false;
    616            
     618
    617619    /* If this is for site admins only and the user is not one, don't create the subnav item */
    618620    if ( $site_admin_only && !is_site_admin() )
    619621        return false;
    620    
     622
    621623    if ( empty( $item_css_id ) )
    622624        $item_css_id = $slug;
     
    637639    if ( !$show_for_displayed_user && !bp_is_home() )
    638640        return false;
    639        
     641
    640642    /***
    641643     * If we are not viewing a user, and this is a root component, don't attach the
     
    660662 *
    661663 * Modify the default subnav item to load when a top level nav item is clicked.
    662  * 
     664 *
    663665 * @package BuddyPress Core
    664666 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    666668function bp_core_new_nav_default( $args = '' ) {
    667669    global $bp;
    668    
     670
    669671    $defaults = array(
    670672        'parent_slug' => false, // Slug of the parent
     
    692694 * We can only sort nav items by their position integer at a later point in time, once all
    693695 * plugins have registered their navigation items.
    694  * 
     696 *
    695697 * @package BuddyPress Core
    696698 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    698700function bp_core_sort_nav_items() {
    699701    global $bp;
    700    
     702
    701703    if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
    702704        return false;
    703    
     705
    704706    foreach ( $bp->bp_nav as $slug => $nav_item ) {
    705707        if ( empty( $temp[$nav_item['position']]) )
     
    710712                $nav_item['position']++;
    711713            } while ( !empty( $temp[$nav_item['position']] ) );
    712            
     714
    713715            $temp[$nav_item['position']] = $nav_item;
    714716        }
    715717    }
    716    
     718
    717719    ksort( $temp );
    718     $bp->bp_nav = &$temp; 
     720    $bp->bp_nav = &$temp;
    719721}
    720722add_action( 'wp_head', 'bp_core_sort_nav_items' );
     
    724726 *
    725727 * Removes a navigation item from the main navigation array.
    726  * 
     728 *
    727729 * @package BuddyPress Core
    728730 * @param $slug The slug of the sub navigation item.
     
    738740 *
    739741 * Adds a navigation item to the sub navigation array used in BuddyPress themes.
    740  * 
     742 *
    741743 * @package BuddyPress Core
    742744 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    756758        'screen_function' => false // The name of the function to run when clicked
    757759    );
    758    
     760
    759761    $r = wp_parse_args( $args, $defaults );
    760762    extract( $r, EXTR_SKIP );
     
    763765    if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
    764766        return false;
    765    
     767
    766768    /* If this is for site admins only and the user is not one, don't create the subnav item */
    767769    if ( $site_admin_only && !is_site_admin() )
    768770        return false;
    769    
     771
    770772    if ( empty( $item_css_id ) )
    771773        $item_css_id = $slug;
    772    
     774
    773775    $bp->bp_options_nav[$parent_slug][$slug] = array(
    774776        'name' => $name,
     
    779781        'user_has_access' => $user_has_access
    780782    );
    781        
     783
    782784    if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
    783785        if ( !is_object( $screen_function[0] ) )
     
    793795    if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
    794796        return false;
    795    
     797
    796798    foreach ( $bp->bp_options_nav as $parent_slug => $subnav_items ) {
    797799        if ( !is_array( $subnav_items ) )
    798800            continue;
    799        
     801
    800802        foreach ( $subnav_items as $subnav_item ) {
    801803            if ( empty( $temp[$subnav_item['position']]) )
     
    806808                    $subnav_item['position']++;
    807809                } while ( !empty( $temp[$subnav_item['position']] ) );
    808            
     810
    809811                $temp[$subnav_item['position']] = $subnav_item;
    810812            }
     
    821823 *
    822824 * Removes a navigation item from the sub navigation array used in BuddyPress themes.
    823  * 
     825 *
    824826 * @package BuddyPress Core
    825827 * @param $parent_id The id of the parent navigation item.
     
    828830function bp_core_remove_subnav_item( $parent_id, $slug ) {
    829831    global $bp;
    830    
     832
    831833    unset( $bp->bp_options_nav[$parent_id][$slug] );
    832834}
     
    836838 *
    837839 * Clear the subnav items for a specific nav item.
    838  * 
     840 *
    839841 * @package BuddyPress Core
    840842 * @param $parent_id The id of the parent navigation item.
     
    856858 * Loads:
    857859 *   wp-content/member-themes/[activated_theme]/profile/edit-profile.php
    858  * 
     860 *
    859861 * @package BuddyPress Core
    860862 * @param $username str Username to check.
     
    883885 *           http://community.domain.com/members/andy/friends
    884886 *           http://domain.com/wpmu/members/andy/friends
    885  * 
     887 *
    886888 * @package BuddyPress Core
    887889 * @param $slug str The slug of the component
     
    898900 *
    899901 * Returns the user_id for a user based on their username.
    900  * 
     902 *
    901903 * @package BuddyPress Core
    902904 * @param $username str Username to check.
     
    907909function bp_core_get_random_member() {
    908910    global $bp, $wpdb;
    909    
     911
    910912    if ( isset( $_GET['random-member'] ) ) {
    911913        $user = BP_Core_User::get_random_users(1);
    912        
     914
    913915        $ud = get_userdata( $user['users'][0]->user_id );
    914        
    915         bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) );     
     916
     917        bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) );
    916918    }
    917919}
     
    922924 *
    923925 * Returns the user_id for a user based on their username.
    924  * 
     926 *
    925927 * @package BuddyPress Core
    926928 * @param $username str Username to check.
     
    931933function bp_core_get_userid( $username ) {
    932934    global $wpdb;
    933    
     935
    934936    if ( !empty( $username ) )
    935         return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 
     937        return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
    936938}
    937939
     
    940942 *
    941943 * Returns the username for a user based on their user id.
    942  * 
     944 *
    943945 * @package BuddyPress Core
    944946 * @param $uid int User ID to check.
     
    950952function bp_core_get_username( $uid ) {
    951953    global $userdata;
    952    
     954
    953955    if ( $uid == $userdata->ID )
    954956        $username =  __( 'You', 'buddypress' );
    955    
     957
    956958    if ( !$ud = get_userdata($uid) )
    957959        return false;
    958        
    959     $username = $ud->user_login;   
     960
     961    $username = $ud->user_login;
    960962
    961963    return apply_filters( 'bp_core_get_username', $username );
     
    966968 *
    967969 * Returns the URL with no HTML markup for a user based on their user id.
    968  * 
     970 *
    969971 * @package BuddyPress Core
    970972 * @param $uid int User ID to check.
     
    976978function bp_core_get_userurl( $uid ) {
    977979    global $bp;
    978    
     980
    979981    if ( !is_numeric($uid) )
    980982        return false;
     
    987989 *
    988990 * Returns the email address for the user based on user ID
    989  * 
     991 *
    990992 * @package BuddyPress Core
    991993 * @param $uid int User ID to check.
     
    10051007 * eg: <a href="http://andy.domain.com/">Andy Peatling</a>
    10061008 * Optional parameters will return just the name, or just the URL, or disable "You" text when
    1007  * user matches the logged in user. 
     1009 * user matches the logged in user.
    10081010 *
    10091011 * [NOTES: This function needs to be cleaned up or split into separate functions]
    1010  * 
     1012 *
    10111013 * @package BuddyPress Core
    10121014 * @param $uid int User ID to check.
     
    10231025function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $deprecated = false, $with_s = false ) {
    10241026    global $userdata;
    1025    
     1027
    10261028    $ud = get_userdata($user_id);
    1027    
     1029
    10281030    if ( !$ud )
    10291031        return false;
    10301032
    1031     if ( function_exists('bp_fetch_user_fullname') ) { 
     1033    if ( function_exists('bp_fetch_user_fullname') ) {
    10321034        $display_name = bp_core_get_user_displayname( $user_id );
    1033        
     1035
    10341036        if ( $with_s )
    10351037            $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name );
    1036            
     1038
    10371039    } else {
    10381040        $display_name = $ud->display_name;
    10391041    }
    1040    
     1042
    10411043    if ( $no_anchor )
    10421044        return $display_name;
     
    10441046    if ( !$url = bp_core_get_userurl($user_id) )
    10451047        return false;
    1046        
     1048
    10471049    if ( $just_link )
    10481050        return $url;
    10491051
    1050     return '<a href="' . $url . '">' . $display_name . '</a>'; 
     1052    return '<a href="' . $url . '">' . $display_name . '</a>';
    10511053}
    10521054
     
    10571059 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
    10581060 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
    1059  * 
     1061 *
    10601062 * @package BuddyPress Core
    10611063 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    10681070function bp_core_get_user_displayname( $user_id ) {
    10691071    global $bp;
    1070    
     1072
    10711073    if ( !$user_id )
    10721074        return false;
    1073        
     1075
    10741076    if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
    10751077        if ( function_exists('xprofile_install') ) {
     
    10881090        } else {
    10891091            $ud = get_userdata($user_id);
    1090            
     1092
    10911093            if ( !empty( $ud->display_name ) )
    10921094                $fullname = $ud->display_name;
     
    10941096                $fullname = $ud->user_nicename;
    10951097        }
    1096        
     1098
    10971099        wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
    10981100    }
    1099    
     1101
    11001102    return apply_filters( 'bp_core_get_user_displayname', $fullname );
    11011103}
     
    11091111 *
    11101112 * Returns the user link for the user based on user email address
    1111  * 
     1113 *
    11121114 * @package BuddyPress Core
    11131115 * @param $email str The email address for the user.
     
    11251127 *
    11261128 * Returns the user link for the user based on user's username
    1127  * 
     1129 *
    11281130 * @package BuddyPress Core
    11291131 * @param $username str The username for the user.
     
    11331135function bp_core_get_userlink_by_username( $username ) {
    11341136    global $wpdb;
    1135    
    1136     $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 
     1137
     1138    $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
    11371139    return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
    11381140}
     
    11491151function bp_core_is_user_spammer( $user_id ) {
    11501152    global $wpdb;
    1151    
    1152     return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 
     1153
     1154    return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) );
    11531155}
    11541156
     
    11641166function bp_core_is_user_deleted( $user_id ) {
    11651167    global $wpdb;
    1166    
    1167     return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) );   
     1168
     1169    return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) );
    11681170}
    11691171
     
    11741176    if ( !$time )
    11751177        return false;
    1176        
     1178
    11771179    $date = date( "F j, Y ", $time );
    1178    
     1180
    11791181    if ( !$just_date ) {
    11801182        $date .= __('at', 'buddypress') . date( ' g:iA', $time );
    11811183    }
    1182    
     1184
    11831185    return $date;
    11841186}
     
    11891191 *
    11901192 * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
    1191  * 
     1193 *
    11921194 * @package BuddyPress Core
    11931195 */
    11941196function bp_core_add_message( $message, $type = false ) {
    11951197    global $bp;
    1196    
     1198
    11971199    if ( !$type )
    11981200        $type = 'success';
    1199    
     1201
    12001202    /* Send the values to the cookie for page reload display */
    12011203    @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
    12021204    @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
    1203    
     1205
    12041206    /***
    12051207     * Send the values to the $bp global so we can still output messages
     
    12181220 * After the message is displayed, it removes the message vars from the cookie so that the message
    12191221 * is not shown to the user multiple times.
    1220  * 
     1222 *
    12211223 * @package BuddyPress Core
    12221224 * @global $bp_message The message text
     
    12291231    if ( empty( $bp->template_message ) )
    12301232        $bp->template_message = $_COOKIE['bp-message'];
    1231    
     1233
    12321234    if ( empty( $bp->template_message_type ) )
    12331235        $bp->template_message_type = $_COOKIE['bp-message-type'];
    12341236
    12351237    add_action( 'template_notices', 'bp_core_render_message' );
    1236    
     1238
    12371239    @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
    12381240    @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
     
    12451247 * Renders a feedback message (either error or success message) to the theme template.
    12461248 * The hook action 'template_notices' is used to call this function, it is not called directly.
    1247  * 
     1249 *
    12481250 * @package BuddyPress Core
    12491251 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    12511253function bp_core_render_message() {
    12521254    global $bp;
    1253    
     1255
    12541256    if ( $bp->template_message ) {
    12551257        $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
     
    12601262    <?php
    12611263        do_action( 'bp_core_render_message' );
    1262     }   
     1264    }
    12631265}
    12641266
     
    12671269 *
    12681270 * Based on function created by Dunstan Orchard - http://1976design.com
    1269  * 
     1271 *
    12701272 * This function will return an English representation of the time elapsed
    12711273 * since a given date.
     
    12731275 * eg: 4 days
    12741276 * eg: 4 weeks and 6 days
    1275  * 
     1277 *
    12761278 * @package BuddyPress Core
    12771279 * @param $older_date int Unix timestamp of date you want to calculate the time since for
     
    12911293    array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
    12921294    );
    1293    
     1295
    12941296    $older_date = strtotime( gmdate( 'Y-m-d H:i:s', $older_date ) );
    12951297
     
    12971299    /* $newer_date will have a value if we want to work out time elapsed between two known dates */
    12981300    $newer_date = ( !$newer_date ) ? ( strtotime( gmdate( 'Y-m-d H:i:s' ) ) + ( 60*60*0 ) ) : $newer_date;
    1299    
     1301
    13001302    /* Difference in seconds */
    13011303    $since = $newer_date - $older_date;
    1302    
     1304
    13031305    if ( 0 > $since )
    13041306        return __( '[Use GMT Timezone]', 'buddypress' );
     
    13271329        $seconds2 = $chunks[$i + 1][0];
    13281330        $name2 = $chunks[$i + 1][1];
    1329        
     1331
    13301332        //if ( $chunks[$i + 1][1] == __( 'second', 'buddypress' ) ) return $output;
    1331    
     1333
    13321334        if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
    13331335            /* Add to output var */
     
    13491351 * show the length of time since the user was last active.
    13501352 * This function will update that time as a usermeta setting for the user every 5 minutes.
    1351  * 
     1353 *
    13521354 * @package BuddyPress Core
    13531355 * @global $userdata WordPress user data for the current logged in user.
     
    13561358function bp_core_record_activity() {
    13571359    global $bp;
    1358    
     1360
    13591361    if ( !is_user_logged_in() )
    13601362        return false;
    1361    
     1363
    13621364    $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' );
    1363    
     1365
    13641366    if ( '' == $activity || time() >= strtotime( '+5 minutes', $activity ) )
    13651367        update_usermeta( $bp->loggedin_user->id, 'last_activity', time() );
     
    13721374 *
    13731375 * Formats last activity based on time since date given.
    1374  * 
     1376 *
    13751377 * @package BuddyPress Core
    13761378 * @param last_activity_date The date of last activity.
     
    13841386    } else {
    13851387        if ( strstr( $last_activity_date, '-' ) ) {
    1386             $last_active = bp_core_time_since( strtotime( $last_activity_date ) ); 
     1388            $last_active = bp_core_time_since( strtotime( $last_activity_date ) );
    13871389        } else {
    1388             $last_active = bp_core_time_since( $last_activity_date ); 
     1390            $last_active = bp_core_time_since( $last_activity_date );
    13891391        }
    1390        
     1392
    13911393        $last_active = sprintf( $string, $last_active );
    13921394    }
    1393    
     1395
    13941396    return $last_active;
    13951397}
     
    14001402 *
    14011403 * Fetch every post that is authored by the given user for the current blog.
    1402  * 
     1404 *
    14031405 * @package BuddyPress Core
    14041406 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    14081410function bp_core_get_all_posts_for_user( $user_id = null ) {
    14091411    global $bp, $wpdb;
    1410    
     1412
    14111413    if ( !$user_id )
    14121414        $user_id = $bp->displayed_user->id;
    1413    
     1415
    14141416    return $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) );
    14151417}
     
    14201422 *
    14211423 * Get the path of of the current site.
    1422  * 
     1424 *
    14231425 * @package BuddyPress Core
    14241426 * @global $comment WordPress comment global for the current comment.
     
    14271429function bp_core_get_site_path() {
    14281430    global $current_site;
    1429    
     1431
    14301432    return $current_site->path;
    14311433}
     
    14351437 *
    14361438 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
    1437  * 
     1439 *
    14381440 * @package BuddyPress Core
    14391441 * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
     
    14431445function bp_core_redirect( $location, $status = 302 ) {
    14441446    global $bp_no_status_set;
    1445    
    1446     // Make sure we don't call status_header() in bp_core_do_catch_uri() 
     1447
     1448    // Make sure we don't call status_header() in bp_core_do_catch_uri()
    14471449    // as this conflicts with wp_redirect()
    14481450    $bp_no_status_set = true;
    1449    
     1451
    14501452    wp_redirect( $location, $status );
    14511453    die;
     
    14561458 *
    14571459 * Returns the referrer URL without the http(s)://
    1458  * 
     1460 *
    14591461 * @package BuddyPress Core
    14601462 * @return The referrer URL
     
    14731475 *
    14741476 * For example, it would stop someone creating a blog with the slug "groups".
    1475  * 
     1477 *
    14761478 * @package BuddyPress Core
    14771479 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    14791481function bp_core_add_illegal_names() {
    14801482    global $bp;
    1481    
     1483
    14821484    $current = maybe_unserialize( get_site_option( 'illegal_names' ) );
    14831485    $bp_illegal_names = $bp->root_components;
    1484    
     1486
    14851487    if ( is_array( $current ) ) {
    14861488        foreach( $bp_illegal_names as $bp_illegal_name ) {
     
    15011503 *
    15021504 * Sets the "From" name in emails sent to the name of the site and not "WordPress"
    1503  * 
     1505 *
    15041506 * @package BuddyPress Core
    15051507 * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
     
    15161518 *
    15171519 * Sets the "From" address in emails sent
    1518  * 
     1520 *
    15191521 * @package BuddyPress Core
    15201522 * @global $current_site Object containing current site metadata
     
    15321534 *
    15331535 * Allows a user to completely remove their account from the system
    1534  * 
     1536 *
    15351537 * @package BuddyPress Core
    15361538 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    15641566 *
    15651567 * A javascript free implementation of the search functions in BuddyPress
    1566  * 
     1568 *
    15671569 * @package BuddyPress Core
    15681570 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    15751577        $search_terms = $_POST['search-terms'];
    15761578        $search_which = $_POST['search-which'];
    1577        
     1579
    15781580        if ( !$slug || empty( $slug ) ) {
    15791581            switch ( $search_which ) {
     
    15961598            }
    15971599        }
    1598        
     1600
    15991601        $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms );
    1600        
     1602
    16011603        bp_core_redirect( $search_url );
    16021604    }
     
    16071609/**
    16081610 * bp_core_ucfirst()
    1609  * 
     1611 *
    16101612 * Localization safe ucfirst() support.
    1611  * 
     1613 *
    16121614 * @package BuddyPress Core
    16131615 */
     
    16151617    if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
    16161618        $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
    1617         return $fc.mb_substr( $str, 1 );   
     1619        return $fc.mb_substr( $str, 1 );
    16181620    } else {
    16191621        return ucfirst( $str );
     
    16241626/**
    16251627 * bp_core_strip_username_spaces()
    1626  * 
     1628 *
    16271629 * Strips spaces from usernames that are created using add_user() and wp_insert_user()
    1628  * 
     1630 *
    16291631 * @package BuddyPress Core
    16301632 */
     
    16371639/**
    16381640 * bp_core_clear_cache()
    1639  * REQUIRES WP-SUPER-CACHE 
    1640  * 
     1641 * REQUIRES WP-SUPER-CACHE
     1642 *
    16411643 * When wp-super-cache is installed this function will clear cached pages
    16421644 * so that success/error messages are not cached, or time sensitive content.
    1643  * 
     1645 *
    16441646 * @package BuddyPress Core
    16451647 */
    16461648function bp_core_clear_cache() {
    16471649    global $cache_path, $cache_filename;
    1648    
     1650
    16491651    if ( function_exists( 'prune_super_cache' ) ) {
    16501652        do_action( 'bp_core_clear_cache' );
    1651        
    1652         return prune_super_cache( $cache_path, true );     
     1653
     1654        return prune_super_cache( $cache_path, true );
    16531655    }
    16541656}
     
    16561658/**
    16571659 * bp_core_print_generation_time()
    1658  * 
     1660 *
    16591661 * Prints the generation time in the footer of the site.
    1660  * 
     1662 *
    16611663 * @package BuddyPress Core
    16621664 */
     
    16711673/**
    16721674 * bp_core_add_admin_menu_page()
    1673  * 
     1675 *
    16741676 * A better version of add_admin_menu_page() that allows positioning of menus.
    1675  * 
     1677 *
    16761678 * @package BuddyPress Core
    16771679 */
     
    16911693    $r = wp_parse_args( $args, $defaults );
    16921694    extract( $r, EXTR_SKIP );
    1693    
     1695
    16941696    $file = plugin_basename( $file );
    16951697
     
    17081710        $position++;
    17091711    } while ( !empty( $menu[$position] ) );
    1710    
     1712
    17111713    $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    17121714
     
    17211723 * When a user logs in, check if they have been marked as a spammer. If then simply
    17221724 * redirect them to the home page and stop them from logging in.
    1723  * 
     1725 *
    17241726 * @package BuddyPress Core
    17251727 * @param $username The username of the user
     
    17281730function bp_core_boot_spammer( $auth_obj, $username ) {
    17291731    global $bp;
    1730    
     1732
    17311733    $user = get_userdatabylogin( $username );
    17321734
     
    17401742 *
    17411743 * Deletes usermeta for the user when the user is deleted.
    1742  * 
     1744 *
    17431745 * @package BuddyPress Core
    17441746 * @param $user_id The user id for the user to delete usermeta for
     
    17581760/**
    17591761 * bp_load_buddypress_textdomain()
    1760  * 
     1762 *
    17611763 * Load the buddypress translation file for current language
    1762  * 
     1764 *
    17631765 * @package BuddyPress Core
    17641766 */
     
    17661768    $locale = apply_filters( 'buddypress_locale', get_locale() );
    17671769    $mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo";
    1768    
     1770
    17691771    if ( file_exists( $mofile ) )
    17701772        load_textdomain( 'buddypress', $mofile );
     
    17811783/**
    17821784 * bp_core_update_message()
    1783  * 
     1785 *
    17841786 * Add an extra update message to the update plugin notification.
    1785  * 
     1787 *
    17861788 * @package BuddyPress Core
    17871789 */
     
    17931795/**
    17941796 * bp_core_clear_user_object_cache()
    1795  * 
     1797 *
    17961798 * Clears all cached objects for a user, or a user is part of.
    1797  * 
     1799 *
    17981800 * @package BuddyPress Core
    17991801 */
  • trunk/bp-core/bp-core-activation.php

    r2025 r2077  
    33function bp_core_screen_activation() {
    44    global $bp, $wpdb;
    5    
     5
    66    if ( BP_ACTIVATION_SLUG != $bp->current_component )
    77        return false;
    8        
     8
    99    /* If we are using a BuddyPress 1.0 theme ignore this. */
    1010    if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
    1111        return false;
    12        
     12
    1313    /* Check if an activation key has been passed */
    1414    if ( isset( $_GET['key'] ) ) {
    15        
     15
    1616        require_once( ABSPATH . WPINC . '/registration.php' );
    17        
     17
    1818        /* Activate the signup */
    1919        $signup = apply_filters( 'bp_core_activate_account', wpmu_activate_signup( $_GET['key'] ) );
    20        
     20
    2121        /* If there was errors, add a message and redirect */
    2222        if ( $signup->errors ) {
     
    2424            bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
    2525        }
    26        
     26
    2727        /* Set the password */
    2828        if ( !empty( $signup['meta']['password'] ) )
    2929            $wpdb->update( $wpdb->users, array( 'user_pass' => $signup['meta']['password'] ), array( 'ID' => $signup['user_id'] ), array( '%s' ), array( '%d' ) );
    30        
    31         /* Set any profile data */ 
     30
     31        /* Set any profile data */
    3232        if ( function_exists( 'xprofile_set_field_data' ) ) {
    33            
     33
    3434            if ( !empty( $signup['meta']['profile_field_ids'] ) ) {
    3535                $profile_field_ids = explode( ',', $signup['meta']['profile_field_ids'] );
    36            
     36
    3737                foreach( $profile_field_ids as $field_id ) {
    3838                    $current_field = $signup['meta']["field_{$field_id}"];
    39                
     39
    4040                    if ( !empty( $current_field ) )
    4141                        xprofile_set_field_data( $field_id, $signup['user_id'], $current_field );
    4242                }
    4343            }
    44            
     44
    4545        }
    46        
     46
    4747        /* Check for an uploaded avatar and move that to the correct user folder */
    4848        $hashed_key = wp_hash( $_GET['key'] );
    49        
     49
    5050        /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
    5151        if ( file_exists( WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/signups/' . $hashed_key ) ) {
    5252            @rename( WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/signups/' . $hashed_key, WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/' . $signup['user_id'] );
    5353        }
    54        
     54
    5555        /* Record the new user in the activity streams */
    5656        if ( function_exists( 'bp_activity_add' ) ) {
    5757            $userlink = bp_core_get_userlink( $signup['user_id'] );
    58            
     58
    5959            bp_activity_add( array(
    6060                'user_id' => $signup['user_id'],
     
    6262                'primary_link' => apply_filters( 'bp_core_actiivty_registered_member_primary_link', $userlink ),
    6363                'component_name' => 'profile',
    64                 'component_action' => 'new_member' 
     64                'component_action' => 'new_member'
    6565            ) );
    6666        }
     
    6868        do_action( 'bp_core_account_activated', &$signup, $_GET['key'] );
    6969        bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
    70        
     70
    7171        $bp->activation_complete = true;
    7272    }
    73    
     73
    7474    if ( '' != locate_template( array( 'registration/activate' ), false ) )
    75         bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );     
     75        bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
    7676    else
    77         bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );     
     77        bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
    7878}
    7979add_action( 'wp', 'bp_core_screen_activation', 3 );
     
    9191    if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) )
    9292        return true;
    93    
     93
    9494    return false;
    9595}
  • trunk/bp-core/bp-core-admin.php

    r2029 r2077  
    44    global $wpdb, $bp, $current_blog;
    55?>
    6    
     6
    77    <?php
    88    if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) {
    99        if ( !check_admin_referer('bp-admin') )
    1010            return false;
    11        
     11
    1212        // Settings form submitted, now save the settings.
    1313        foreach ( $_POST['bp-admin'] as $key => $value ) {
    14            
     14
    1515            if ( function_exists( 'xprofile_install' ) ) {
    1616                if ( 'bp-xprofile-base-group-name' == $key ) {
    1717                    $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE name = %s AND id = 1", $value, stripslashes( get_site_option('bp-xprofile-base-group-name') ) ) );
    1818                }
    19                
     19
    2020                if ( 'bp-xprofile-fullname-field-name' == $key ) {
    2121                    $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET name = %s WHERE name = %s AND group_id = 1", $value, stripslashes( get_site_option('bp-xprofile-fullname-field-name') ) ) );
    2222                }
    2323            }
    24            
     24
    2525            update_site_option( $key, $value );
    2626        }
    2727    }
    2828    ?>
    29    
     29
    3030    <div class="wrap">
    31        
     31
    3232        <h2><?php _e( 'BuddyPress Settings', 'buddypress' ) ?></h2>
    3333
     
    3939
    4040        <form action="" method="post" id="bp-admin-form">
    41        
     41
    4242            <table class="form-table">
    4343            <tbody>
     
    4747                    <td>
    4848                        <input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" />
    49                     </td>           
     49                    </td>
    5050                </tr>
    5151                <tr>
     
    6060                        <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    6161                        <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    62                     </td>           
     62                    </td>
    6363                </tr>
    6464                <?php endif; ?>
     
    6868                        <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    6969                        <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    70                     </td>           
     70                    </td>
    7171                </tr>
    7272                <tr>
     
    8383                        <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( (int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    8484                        <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( !(int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    85                     </td>           
    86                 </tr>
    87                 <?php } ?>             
     85                    </td>
     86                </tr>
     87                <?php } ?>
    8888                <tr>
    8989                    <th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
     
    9191                        <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    9292                        <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) || '' == get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    93                     </td>           
     93                    </td>
    9494                </tr>
    9595                <?php if ( function_exists( 'bp_forums_setup') ) : ?>
     
    9999                        <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    100100                        <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) || '' == get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    101                     </td>           
    102                 </tr>               
    103                 <?php endif; ?>
    104                
     101                    </td>
     102                </tr>
     103                <?php endif; ?>
     104
    105105                <?php $themes = bp_core_get_buddypress_themes() ?>
    106106                <?php if ( $themes ) : ?>
     
    109109                        <td>
    110110                                <select name="bp-admin[active-member-theme]" id="active-member-theme">
    111                                 <?php 
    112                                 for ( $i = 0; $i < count($themes); $i++ ) { 
     111                                <?php
     112                                for ( $i = 0; $i < count($themes); $i++ ) {
    113113                                    if ( $themes[$i]['template'] == get_site_option( 'active-member-theme' ) ) {
    114114                                        $selected = ' selected="selected"';
     
    120120                                <?php } ?>
    121121                            </select>
    122                         </td>           
     122                        </td>
    123123                    </tr>
    124124                <?php else : ?>
     
    129129                    <?php endif; ?>
    130130                <?php endif; ?>
    131                            
     131
    132132                <tr>
    133133                    <th scope="row"><?php _e( 'Default User Avatar', 'buddypress' ) ?></th>
     
    147147
    148148            <?php do_action( 'bp_core_admin_screen' ) ?>
    149            
     149
    150150            <p class="submit">
    151151                <input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
     
    153153
    154154            <?php wp_nonce_field( 'bp-admin' ) ?>
    155        
     155
    156156        </form>
    157        
     157
    158158    </div>
    159    
    160 <?php 
     159
     160<?php
    161161}
    162162
     
    164164    global $wpdb, $bp;
    165165?>
    166    
     166
    167167    <?php
    168168    if ( isset( $_POST['bp-admin-component-submit'] ) && isset( $_POST['bp_components'] ) ) {
    169169        if ( !check_admin_referer('bp-admin-component-setup') )
    170170            return false;
    171        
     171
    172172        // Settings form submitted, now save the settings.
    173173        foreach ( $_POST['bp_components'] as $key => $value ) {
    174174            if ( !(int) $value )
    175                 $disabled[$key] = 1;   
     175                $disabled[$key] = 1;
    176176        }
    177177        update_site_option( 'bp-deactivated-components', $disabled );
    178178    }
    179179    ?>
    180    
     180
    181181    <div class="wrap">
    182        
     182
    183183        <h2><?php _e( 'BuddyPress Component Setup', 'buddypress' ) ?></h2>
    184        
     184
    185185        <?php if ( isset( $_POST['bp-admin-component-submit'] ) ) : ?>
    186186            <div id="message" class="updated fade">
     
    188188            </div>
    189189        <?php endif; ?>
    190    
     190
    191191        <form action="" method="post" id="bp-admin-component-form">
    192        
     192
    193193            <p>
    194             <?php _e( 
    195                 'By default, all BuddyPress components are enabled. You can selectively disable any of the 
     194            <?php _e(
     195                'By default, all BuddyPress components are enabled. You can selectively disable any of the
    196196                components by using the form below. Your BuddyPress installation will continue to function, however
    197197                the features of the disabled components will no longer be accessible to
     
    199199                ', 'buddypress' )?>
    200200            </p>
    201            
     201
    202202            <?php $disabled_components = get_site_option( 'bp-deactivated-components' ); ?>
    203            
     203
    204204            <table class="form-table" style="width: 80%">
    205205            <tbody>
     
    210210                        <input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
    211211                        <input type="radio" name="bp_components[bp-activity.php]" value="0"<?php if ( isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    212                     </td>           
     212                    </td>
    213213                </tr>
    214214                <?php endif; ?>
     
    219219                        <input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    220220                        <input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    221                     </td>           
     221                    </td>
    222222                </tr>
    223223                <?php endif; ?>
     
    228228                        <input type="radio" name="bp_components[bp-forums.php]" value="1"<?php if ( !isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    229229                        <input type="radio" name="bp_components[bp-forums.php]" value="0"<?php if ( isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    230                     </td>           
     230                    </td>
    231231                </tr>
    232232                <?php endif; ?>
     
    237237                        <input type="radio" name="bp_components[bp-friends.php]" value="1"<?php if ( !isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    238238                        <input type="radio" name="bp_components[bp-friends.php]" value="0"<?php if ( isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    239                     </td>           
     239                    </td>
    240240                </tr>
    241241                <?php endif; ?>
     
    246246                        <input type="radio" name="bp_components[bp-groups.php]" value="1"<?php if ( !isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    247247                        <input type="radio" name="bp_components[bp-groups.php]" value="0"<?php if ( isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    248                     </td>           
     248                    </td>
    249249                </tr>
    250250                <?php endif; ?>
     
    255255                        <input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    256256                        <input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    257                     </td>           
     257                    </td>
    258258                </tr>
    259259                <?php endif; ?>
     
    264264                        <input type="radio" name="bp_components[bp-wire.php]" value="1"<?php if ( !isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    265265                        <input type="radio" name="bp_components[bp-wire.php]" value="0"<?php if ( isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    266                     </td>           
     266                    </td>
    267267                </tr>
    268268                <?php endif; ?>
     
    287287            </tbody>
    288288            </table>
    289            
     289
    290290            <p class="submit">
    291291                <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
    292292            </p>
    293            
     293
    294294            <?php wp_nonce_field( 'bp-admin-component-setup' ) ?>
    295        
     295
    296296        </form>
    297297
    298298    </div>
    299    
    300 <?php 
     299
     300<?php
    301301}
    302302
  • trunk/bp-core/bp-core-adminbar.php

    r1905 r2077  
    33function bp_core_admin_bar() {
    44    global $bp, $wpdb, $current_blog, $doing_admin_bar;
    5    
     5
    66    if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
    77        return false;
    8    
     8
    99    $doing_admin_bar = true;
    10    
     10
    1111    if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
    1212        return false;
     
    1818
    1919    echo '<ul class="main-nav">';
    20    
     20
    2121    // **** Do bp-adminbar-menus Actions ********
    2222    do_action( 'bp_adminbar_menus' );
     
    2929function bp_adminbar_logo() {
    3030    global $bp;
    31    
     31
    3232    echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>';
    3333}
     
    3737    global $bp;
    3838
    39     if ( !is_user_logged_in() ) {   
     39    if ( !is_user_logged_in() ) {
    4040        echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
    41        
     41
    4242        // Show "Sign Up" link if user registrations are allowed
    4343        if ( get_site_option( 'registration' ) != 'none' && get_site_option( 'registration' ) != 'blog' ) {
     
    5555
    5656    if ( is_user_logged_in() ) {
    57        
     57
    5858        echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
    59    
     59
    6060        echo __( 'My Account', 'buddypress' ) . '</a>';
    6161        echo '<ul>';
    62    
     62
    6363        /* Loop through each navigation item */
    6464        $counter = 0;
    6565        foreach( $bp->bp_nav as $nav_item ) {
    6666            $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
    67            
     67
    6868            echo '<li' . $alt . '>';
    6969            echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
    70            
     70
    7171            if ( is_array( $bp->bp_options_nav[$nav_item['css_id']] ) ) {
    7272                echo '<ul>';
     
    7575                foreach( $bp->bp_options_nav[$nav_item['css_id']] as $subnav_item ) {
    7676                    $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
    77                     echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>';               
     77                    echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>';
    7878                    $sub_counter++;
    7979                }
    8080                echo '</ul>';
    8181            }
    82        
     82
    8383            echo '</li>';
    84            
     84
    8585            $counter++;
    8686        }
    87    
     87
    8888        $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
    8989
    90         if ( function_exists('wp_logout_url') ) { 
    91             echo '<li' . $alt . '><a id="bp-admin-logout" href="' . wp_logout_url(site_url()) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';                   
    92         } else { 
    93             echo '<li' . $alt . '><a id="bp-admin-logout" href="' . site_url() . '/wp-login.php?action=logout&amp;redirect_to=' . site_url() . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 
    94         } 
    95              
     90        if ( function_exists('wp_logout_url') ) {
     91            echo '<li' . $alt . '><a id="bp-admin-logout" href="' . wp_logout_url(site_url()) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
     92        } else {
     93            echo '<li' . $alt . '><a id="bp-admin-logout" href="' . site_url() . '/wp-login.php?action=logout&amp;redirect_to=' . site_url() . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
     94        }
     95
    9696        echo '</ul>';
    9797        echo '</li>';
     
    101101// return a string indicating user's role in that blog
    102102function get_blog_role_for_user( $user, $blog ) {
    103    
     103
    104104    // If the user is a site admin, just display admin.
    105     if ( is_site_admin() ) 
     105    if ( is_site_admin() )
    106106        return __( 'Admin', 'buddypress');
    107    
     107
    108108    $roles = get_usermeta( $user, 'wp_' . $blog . '_capabilities' );
    109109
    110110    if ( isset( $roles['subscriber'] ) )
    111         $role = __( 'Subscriber', 'buddypress' ); 
     111        $role = __( 'Subscriber', 'buddypress' );
    112112    elseif  ( isset( $roles['contributor'] ) )
    113113        $role = __( 'Contributor', 'buddypress' );
     
    120120    else
    121121        return false;
    122    
     122
    123123    return $role;
    124124}
     
    127127function bp_adminbar_blogs_menu() {
    128128    if ( is_user_logged_in() ) {
    129         global $bp; 
    130    
     129        global $bp;
     130
    131131        if ( function_exists('bp_blogs_install') ) {
    132            
     132
    133133            if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id, 'bp' ) ) {
    134134                $blogs = get_blogs_of_user( $bp->loggedin_user->id );
     
    137137
    138138            echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">';
    139            
     139
    140140            _e( 'My Blogs', 'buddypress' );
    141            
     141
    142142            echo '</a>';
    143    
    144             echo '<ul>';           
     143
     144            echo '<ul>';
    145145            if ( is_array( $blogs )) {
    146        
     146
    147147                $counter = 0;
    148148                foreach( $blogs as $blog ) {
     
    157157                        echo '<li><a href="' . $blog->siteurl  . '/wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>';
    158158                        echo '<li class="alt"><a href="' . $blog->siteurl  . '/wp-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>';
    159                         echo '<li><a href="' . $blog->siteurl  . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>';                   
    160                         if ( 'Admin' == $role ) {   
    161                             echo '<li class="alt"><a href="' . $blog->siteurl  . '/wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>'; 
    162                         }                   
    163                         echo '</ul>';                   
     159                        echo '<li><a href="' . $blog->siteurl  . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>';
     160                        if ( 'Admin' == $role ) {
     161                            echo '<li class="alt"><a href="' . $blog->siteurl  . '/wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>';
     162                        }
     163                        echo '</ul>';
    164164                    }
    165165                    echo '</li>';
     
    167167                }
    168168            }
    169    
     169
    170170            $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
    171            
     171
    172172            if ( bp_blog_signup_enabled() ) {
    173173                echo '<li' . $alt . '>';
     
    175175                echo '</li>';
    176176            }
    177            
     177
    178178            echo '</ul>';
    179179            echo '</li>';
    180180        }
    181181    }
    182 }   
     182}
    183183
    184184// **** "Notifications" Menu *********
    185 function bp_adminbar_notifications_menu() { 
     185function bp_adminbar_notifications_menu() {
    186186    if ( is_user_logged_in() ) {
    187187        global $bp;
    188        
     188
    189189        echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
    190190        _e( 'Notifications', 'buddypress' );
    191    
     191
    192192        if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
    193193            <span><?php echo count($notifications) ?></span>
    194194        <?php
    195195        }
    196        
     196
    197197        echo '</a>';
    198198        echo '<ul>';
    199        
     199
    200200        if ( $notifications ) { ?>
    201201            <?php $counter = 0; ?>
     
    209209        <?php
    210210        }
    211        
     211
    212212        echo '</ul>';
    213213        echo '</li>';
     
    218218function bp_adminbar_authors_menu() {
    219219    global $current_blog;
    220    
     220
    221221    if ( $current_blog->blog_id > 1 ) {
    222         $authors = get_users_of_blog(); 
    223    
     222        $authors = get_users_of_blog();
     223
    224224        if ( is_array( $authors ) ) {
    225225            /* This is a blog, render a menu with links to all authors */
     
    227227            _e('Blog Authors', 'buddypress');
    228228            echo '</a>';
    229        
     229
    230230            echo '<ul class="author-list">';
    231231            foreach( $authors as $author ) {
     
    246246    }
    247247}
    248    
     248
    249249// **** "Random" Menu (visible when not logged in) ********
    250 function bp_adminbar_random_menu() { 
     250function bp_adminbar_random_menu() {
    251251    global $bp; ?>
    252252    <li class="align-right" id="bp-adminbar-visitrandom-menu">
     
    261261            <?php if ( function_exists('bp_blogs_install') ) : ?>
    262262            <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
    263            
     263
    264264            <?php endif; ?>
    265            
     265
    266266            <?php do_action( 'bp_adminbar_random_menu' ) ?>
    267267        </ul>
  • trunk/bp-core/bp-core-avatars.php

    r2069 r2077  
    3232if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
    3333    define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' );
    34    
     34
    3535function bp_core_fetch_avatar( $args = '' ) {
    3636    global $bp, $current_blog;
    37    
     37
    3838    $defaults = array(
    3939        'item_id' => false,
     
    4141        'type' => 'thumb',
    4242        'avatar_dir' => false,
    43         'width' => false, 
     43        'width' => false,
    4444        'height' => false,
    4545        'class' => 'avatar',
     
    5050
    5151    $params = wp_parse_args( $args, $defaults );
    52     extract( $params, EXTR_SKIP ); 
     52    extract( $params, EXTR_SKIP );
    5353
    5454    if ( !$item_id ) {
     
    5959        else if ( 'blog' == $object )
    6060            $item_id = $current_blog->id;
    61            
     61
    6262        $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
    63    
     63
    6464        if ( !$item_id ) return false;
    6565    }
    66        
     66
    6767    if ( !$avatar_dir ) {
    6868        if ( 'user' == $object )
     
    7272        else if ( 'blog' == $object )
    7373            $avatar_dir = 'blog-avatars';
    74            
     74
    7575        $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
    76        
    77         if ( !$avatar_dir ) return false;       
    78     }
    79    
     76
     77        if ( !$avatar_dir ) return false;
     78    }
     79
    8080    if ( !$css_id )
    81         $css_id = $object . '-' . $item_id . '-avatar'; 
    82    
     81        $css_id = $object . '-' . $item_id . '-avatar';
     82
    8383    if ( $width )
    8484        $html_width = " width='{$width}'";
    8585    else
    8686        $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
    87        
     87
    8888    if ( $height )
    8989        $html_height = " height='{$height}'";
    9090    else
    9191        $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
    92    
    93     $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 
    94     $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );   
     92
     93    $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
     94    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    9595
    9696    /****
     
    116116    }
    117117
    118     /* If no avatars have been uploaded for this item, display a gravatar */   
     118    /* If no avatars have been uploaded for this item, display a gravatar */
    119119    if ( !file_exists( $avatar_url ) && !$no_grav ) {
    120        
    121120        if ( empty( $bp->grav_default->{$object} ) )
    122121            $default_grav = 'wavatar';
     
    129128        else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH;
    130129        else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH;
    131        
     130
    132131        if ( 'user' == $object ) {
    133132            $ud = get_userdata( $item_id );
     
    136135            $grav_email = "{$item_id}-{$object}@{$bp->root_domain}";
    137136        }
    138    
    139         $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );   
     137
     138        $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );
    140139        $gravatar = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    141        
     140
    142141        return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
    143    
    144142    } else if ( !file_exists( $avatar_url ) && $no_grav )
    145143        return false;
    146    
    147144}
    148145
    149146function bp_core_delete_existing_avatar( $args = '' ) {
    150147    global $bp;
    151    
     148
    152149    $defaults = array(
    153150        'item_id' => false,
     
    157154
    158155    $args = wp_parse_args( $args, $defaults );
    159     extract( $args, EXTR_SKIP );   
    160    
     156    extract( $args, EXTR_SKIP );
     157
    161158    if ( !$item_id ) {
    162159        if ( 'user' == $object )
     
    166163        else if ( 'blog' == $object )
    167164            $item_id = $current_blog->id;
    168            
     165
    169166        $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
    170    
     167
    171168        if ( !$item_id ) return false;
    172169    }
    173        
     170
    174171    if ( !$avatar_dir ) {
    175172        if ( 'user' == $object )
     
    179176        else if ( 'blog' == $object )
    180177            $avatar_dir = 'blog-avatars';
    181            
     178
    182179        $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
    183        
    184         if ( !$avatar_dir ) return false;       
     180
     181        if ( !$avatar_dir ) return false;
    185182    }
    186183
     
    193190    }
    194191
    195     $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );   
     192    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    196193
    197194    if ( !file_exists( $avatar_folder_dir ) )
     
    201198        while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    202199            if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
    203                 @unlink( $avatar_folder_dir . '/' . $avatar_file );             
     200                @unlink( $avatar_folder_dir . '/' . $avatar_file );
    204201        }
    205202    }
     
    215212function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
    216213    global $bp;
    217    
     214
    218215    require_once( ABSPATH . '/wp-admin/includes/image.php' );
    219216    require_once( ABSPATH . '/wp-admin/includes/file.php' );
    220    
     217
    221218    $uploadErrors = array(
    222         0 => __("There is no error, the file uploaded with success", 'buddypress'), 
    223         1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE), 
     219        0 => __("There is no error, the file uploaded with success", 'buddypress'),
     220        1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
    224221        2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
    225222        3 => __("The uploaded file was only partially uploaded", 'buddypress'),
     
    232229        return false;
    233230    }
    234    
     231
    235232    if ( !bp_core_check_avatar_size( $file ) ) {
    236233        bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
    237234        return false;
    238235    }
    239    
     236
    240237    if ( !bp_core_check_avatar_type( $file ) ) {
    241238        bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
    242239        return false;
    243240    }
    244    
     241
    245242    // Filter the upload location
    246243    add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
    247    
     244
    248245    $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
    249246
     
    253250        return false;
    254251    }
    255        
     252
    256253    // Resize the image down to something manageable and then delete the original
    257254    if ( getimagesize( $bp->avatar_admin->original['file'] ) > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
    258255        $bp->avatar_admin->resized = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
    259256    }
    260    
     257
    261258    $bp->avatar_admin->image = new stdClass;
    262    
    263     // We only want to handle one image after resize. 
     259
     260    // We only want to handle one image after resize.
    264261    if ( empty( $bp->avatar_admin->resized ) )
    265262        $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file'];
     
    268265        @unlink( $bp->avatar_admin->original['file'] );
    269266    }
    270    
     267
    271268    /* Set the url value for the image */
    272269    $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $bp->avatar_admin->image->dir );
     
    277274function bp_core_avatar_handle_crop( $args = '' ) {
    278275    global $bp;
    279    
     276
    280277    $defaults = array(
    281278        'object' => 'user',
     
    297294    if ( !file_exists( WP_CONTENT_DIR . '/' . $original_file ) )
    298295        return false;
    299            
     296
    300297    if ( !$item_id )
    301         $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir ); 
     298        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir );
    302299    else
    303300        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
     
    305302    if ( !file_exists( $avatar_folder_dir ) )
    306303        return false;
    307    
     304
    308305    require_once( ABSPATH . '/wp-admin/includes/image.php' );
    309306    require_once( ABSPATH . '/wp-admin/includes/file.php' );
     
    311308    /* Delete the existing avatar files for the object */
    312309    bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
    313    
     310
    314311    /* Make sure we at least have a width and height for cropping */
    315312    if ( !(int)$crop_w )
    316313        $crop_w = BP_AVATAR_FULL_WIDTH;
    317    
     314
    318315    if ( !(int)$crop_h )
    319316        $crop_h = BP_AVATAR_FULL_HEIGHT;
     
    322319    $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
    323320    $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
    324            
     321
    325322    /* Crop the image */
    326323    $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
     
    337334    if ( is_object ( $id_or_email ) )
    338335        $id_or_email = $id_or_email->user_id;
    339    
     336
    340337    $bp_avatar = bp_core_fetch_avatar( array( 'no_grav' => true, 'item_id' => $id_or_email, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
    341338
     
    347344    if ( $file['error'] )
    348345        return false;
    349    
     346
    350347    return true;
    351348}
     
    354351    if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
    355352        return false;
    356    
     353
    357354    return true;
    358355}
     
    361358    if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
    362359        return false;
    363    
     360
    364361    return true;
    365362}
  • trunk/bp-core/bp-core-catchuri.php

    r2027 r2077  
    1717 *   - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
    1818 *   - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
    19  * 
     19 *
    2020 *  Example:
    2121 *    - http://domain.com/members/andy/profile/edit/group/5/
     
    2323 *    - $bp->current_action: string 'edit'
    2424 *    - $bp->action_variables: array ['group', 5]
    25  * 
     25 *
    2626 * @package BuddyPress Core
    2727 */
     
    3232    global $bp_unfiltered_uri;
    3333    global $bp, $current_blog;
    34    
     34
    3535    if ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    3636        /* Only catch URI's on the root blog if we are not running BP on multiple blogs */
     
    6464            array_shift( $bp_uri );
    6565    }
    66    
     66
    6767    /* Set the indexes, these are incresed by one if we are not on a VHOST install */
    6868    $component_index = 0;
    6969    $action_index = $component_index + 1;
    70    
     70
    7171    // If this is a WordPress page, return from the function.
    7272    if ( is_page( $bp_uri[$component_index] ) )
    7373        return false;
    74    
     74
    7575    /* Get site path items */
    7676    $paths = explode( '/', bp_core_get_site_path() );
     
    9393    $bp_uri = array_merge( array(), $bp_uri );
    9494    $bp_unfiltered_uri = $bp_uri;
    95    
     95
    9696    /* If we are under anything with a members slug, set the correct globals */
    9797    if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
    9898        $is_member_page = true;
    99         $is_root_component = true;     
     99        $is_root_component = true;
    100100    }
    101101
    102102    /* Catch a member page and set the current member ID */
    103     if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {     
    104         if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {   
     103    if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
     104        if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
    105105            // We are within a member page, set up user id globals
    106106            $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[1] );
     
    108108            unset($bp_uri[0]);
    109109            unset($bp_uri[1]);
    110        
     110
    111111            /* Reset the keys by merging with an empty array */
    112112            $bp_uri = array_merge( array(), $bp_uri );
     
    116116            $is_member_page = true;
    117117            $is_root_component = true;
    118        
     118
    119119            // We are within a member page, set up user id globals
    120120            $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[0] );
    121                
     121
    122122            unset($bp_uri[0]);
    123123
     
    126126        }
    127127    }
    128    
     128
    129129    if ( !isset($is_root_component) )
    130130        $is_root_component = in_array( $bp_uri[0], $bp->root_components );
     
    137137    /* Set the current component */
    138138    $current_component = $bp_uri[$component_index];
    139    
     139
    140140    /* Set the current action */
    141141    $current_action = $bp_uri[$action_index];
    142    
     142
    143143    /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
    144144    $action_variables = $bp_uri;
     
    151151    if ( 'no' == VHOST && !$is_root_component )
    152152        array_shift($action_variables);
    153    
     153
    154154    /* Reset the keys by merging with an empty array */
    155155    $action_variables = array_merge( array(), $action_variables );
     
    162162 * bp_catch_uri()
    163163 *
    164  * Takes either a single page name or array of page names and 
     164 * Takes either a single page name or array of page names and
    165165 * loads the first template file that can be found.
    166166 *
    167167 * Please don't call this function directly anymore, use: bp_core_load_template()
    168  * 
     168 *
    169169 * @package BuddyPress Core
    170170 * @global $bp_path BuddyPress global containing the template file names to use.
     
    174174function bp_catch_uri( $pages, $skip_blog_check = false ) {
    175175    global $bp_path, $bp_skip_blog_check;
    176    
     176
    177177    $bp_skip_blog_check = $skip_blog_check;
    178178
     
    189189 *
    190190 * Loads the first template file found based on the $bp_path global.
    191  * 
     191 *
    192192 * @package BuddyPress Core
    193193 * @global $bp_path BuddyPress global containing the template file names to use.
     
    198198    global $bp_no_status_set;
    199199    global $wp_query;
    200    
    201     /* Can be a single template or an array of templates */ 
     200
     201    /* Can be a single template or an array of templates */
    202202    $templates = $bp_path;
    203    
     203
    204204    /* Don't hijack any URLs on blog pages */
    205205    if ( bp_is_blog_page() ) {
     
    214214        status_header( 200 );
    215215        $wp_query->is_404 = false;
    216        
     216
    217217        if ( $bp->current_component != BP_HOME_BLOG_SLUG )
    218218            $wp_query->is_page = true;
    219219    }
    220    
     220
    221221    foreach ( (array)$templates as $template )
    222222        $filtered_templates[] = $template . '.php';
    223    
     223
    224224    if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
    225225        load_template( apply_filters( 'bp_load_template', $located_template ) );
     
    269269 * If the extended profiles component is not installed we still need
    270270 * to catch the /profile URI's and display whatever we have installed.
    271  * 
     271 *
    272272 */
    273273function bp_core_catch_profile_uri() {
    274274    global $bp;
    275    
     275
    276276    if ( !function_exists('xprofile_install') )
    277277        bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'profile/index' ) );
  • trunk/bp-core/bp-core-classes.php

    r2055 r2077  
    33 * BP_Core_User class can be used by any component. It will fetch useful
    44 * details for any user when provided with a user_id.
    5  * 
     5 *
    66 * Example:
    77 *    $user = new BP_Core_User( $user_id );
     
    1010 *    $user_status = $user->status;
    1111 *    etc.
    12  * 
     12 *
    1313 * @package BuddyPress Core
    1414 */
     
    2020    var $fullname;
    2121    var $email;
    22    
     22
    2323    var $user_url;
    2424    var $user_link;
    25    
     25
    2626    var $last_active;
    2727    var $profile_last_updated;
     
    3131    var $total_blogs;
    3232    var $total_groups;
    33    
     33
    3434    function bp_core_user( $user_id, $populate_extras = false ) {
    3535        if ( $user_id ) {
    3636            $this->id = $user_id;
    3737            $this->populate();
    38            
     38
    3939            if ( $populate_extras )
    4040                $this->populate_extras();
    4141        }
    42     } 
    43    
     42    }
     43
    4444    /**
    4545     * populate()
    4646     *
    4747     * Populate the instantiated class with data based on the User ID provided.
    48      * 
     48     *
    4949     * @package BuddyPress Core
    5050     * @global $userdata WordPress user data for the current logged in user.
     
    5959        $this->user_url = bp_core_get_userurl( $this->id );
    6060        $this->user_link = bp_core_get_userlink( $this->id );
    61        
     61
    6262        $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );
    6363        $this->email = attribute_escape( bp_core_get_user_email( $this->id ) );
     
    6868        $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
    6969    }
    70    
     70
    7171    function populate_extras() {
    7272        global $bp;
    73        
    74         if ( function_exists('friends_install') ) { 
     73
     74        if ( function_exists('friends_install') ) {
    7575            $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
    7676
     
    8080                else
    8181                    $this->total_friends .= ' ' . __( 'friends', 'buddypress' );
    82            
     82
    8383                $this->total_friends = '<a href="' . $this->user_url . $bp->friends->slug . '" title="' . sprintf( __( "%s's friend list", 'buddypress' ), $this->fullname ) . '">' . $this->total_friends . '</a>';
    8484            }
    8585        }
    8686
    87         if ( function_exists('bp_blogs_install') ) {       
     87        if ( function_exists('bp_blogs_install') ) {
    8888            if ( $this->total_blogs ) {
    8989                if ( 1 == $this->total_blogs )
    9090                    $this->total_blogs .= ' ' . __( 'blog', 'buddypress' );
    9191                else
    92                     $this->total_blogs .= ' ' . __( 'blogs', 'buddypress' );           
    93                
     92                    $this->total_blogs .= ' ' . __( 'blogs', 'buddypress' );
     93
    9494                $this->total_blogs = '<a href="' . $this->user_url . $bp->blogs->slug . '" title="' . sprintf( __( "%s's blog list", 'buddypress' ), $this->fullname ) . '">' . $this->total_blogs . '</a>';
    9595            }
    9696        }
    97        
     97
    9898        if ( function_exists('groups_install') ) {
    9999            $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
    100            
     100
    101101            if ( $this->total_groups ) {
    102102                if ( 1 == $this->total_groups )
     
    109109        }
    110110    }
    111    
     111
    112112    /* Static Functions */
    113    
     113
    114114    function get_newest_users( $limit = null, $page = 1 ) {
    115115        global $wpdb;
    116        
    117         if ( $limit && $page )
    118             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    119        
     116
     117        if ( $limit && $page )
     118            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     119
    120120        $total_users_sql = apply_filters( 'bp_core_newest_users_count_sql', "SELECT DISTINCT count(ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC" );
    121121        $paged_users_sql = apply_filters( 'bp_core_newest_users_sql', "SELECT DISTINCT ID as user_id, DATE_ADD( user_registered, INTERVAL " . get_option('gmt_offset') . " HOUR ) as user_registered FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC{$pag_sql}", $pag_sql );
    122        
    123         $total_users = $wpdb->get_var( $total_users_sql );
    124         $paged_users = $wpdb->get_results( $paged_users_sql );
    125        
    126         return array( 'users' => $paged_users, 'total' => $total_users );
    127     }
    128    
     122
     123        $total_users = $wpdb->get_var( $total_users_sql );
     124        $paged_users = $wpdb->get_results( $paged_users_sql );
     125
     126        return array( 'users' => $paged_users, 'total' => $total_users );
     127    }
     128
    129129    function get_active_users( $limit = null, $page = 1 ) {
    130130        global $wpdb;
     
    135135        $total_users_sql = apply_filters( 'bp_core_active_users_count_sql', "SELECT DISTINCT count(um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC" );
    136136        $paged_users_sql = apply_filters( 'bp_core_active_users_sql', "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}", $pag_sql );
    137        
    138         $total_users = $wpdb->get_var( $total_users_sql );
    139         $paged_users = $wpdb->get_results( $paged_users_sql );
    140        
     137
     138        $total_users = $wpdb->get_var( $total_users_sql );
     139        $paged_users = $wpdb->get_results( $paged_users_sql );
     140
    141141        return array( 'users' => $paged_users, 'total' => $total_users );
    142142    }
     
    144144    function get_popular_users( $limit = null, $page = 1 ) {
    145145        global $wpdb;
    146                
     146
    147147        if ( !function_exists('friends_install') )
    148148            return false;
    149        
     149
    150150        if ( $limit && $page )
    151151            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    156156        $total_users = $wpdb->get_var( $total_users_sql );
    157157        $paged_users = $wpdb->get_results( $paged_users_sql );
    158        
    159         return array( 'users' => $paged_users, 'total' => $total_users );
    160     }
    161    
     158
     159        return array( 'users' => $paged_users, 'total' => $total_users );
     160    }
     161
    162162    function get_random_users( $limit = null, $page = 1 ) {
    163163        global $wpdb, $bp;
    164        
     164
    165165        if ( $limit && $page )
    166166            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    171171        $total_users = $wpdb->get_var( $total_users_sql );
    172172        $paged_users = $wpdb->get_results( $paged_users_sql );
    173        
    174         return array( 'users' => $paged_users, 'total' => $total_users );
    175     }
    176    
     173
     174        return array( 'users' => $paged_users, 'total' => $total_users );
     175    }
     176
    177177    function get_online_users( $limit = null, $page = 1 ) {
    178178        global $wpdb;
    179        
     179
    180180        if ( $limit && $page )
    181181            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    189189        return array( 'users' => $paged_users, 'total' => $total_users );
    190190    }
    191    
     191
    192192    function get_alphabetical_users( $limit = null, $page = 1 ) {
    193193        global $wpdb, $bp;
     
    195195        if ( !function_exists( 'xprofile_install' ) )
    196196            return BP_Core_User::get_active_users( $limit, $page );
    197        
     197
    198198        if ( $limit && $page )
    199199            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    207207        return array( 'users' => $paged_users, 'total' => $total_users );
    208208    }
    209    
     209
    210210    function get_users_by_letter( $letter, $limit = null, $page = 1 ) {
    211211        global $wpdb, $bp;
    212        
     212
    213213        if ( !function_exists('xprofile_install') )
    214214            return BP_Core_User::get_active_users( $limit, $page );
    215        
    216         if ( $limit && $page )
    217             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    218        
     215
     216        if ( $limit && $page )
     217            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     218
    219219        if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
    220220            return false;
    221        
     221
    222222        $letter = like_escape( $wpdb->escape( $letter ) );
    223223
     
    227227        $total_users = $wpdb->get_var( $total_users_sql );
    228228        $paged_users = $wpdb->get_results( $paged_users_sql );
    229        
    230         return array( 'users' => $paged_users, 'total' => $total_users );
    231     }
    232    
     229
     230        return array( 'users' => $paged_users, 'total' => $total_users );
     231    }
     232
    233233    function search_users( $search_terms, $limit = null, $page = 1 ) {
    234234        global $wpdb, $bp;
    235        
     235
    236236        if ( !function_exists('xprofile_install') )
    237237            return BP_Core_User::get_active_users( $limit, $page );
    238        
    239         if ( $limit && $page )
    240             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    241        
    242         $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 
     238
     239        if ( $limit && $page )
     240            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     241
     242        $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    243243
    244244        $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT DISTINCT count(u.ID) as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
     
    247247        $total_users = $wpdb->get_var( $total_users_sql );
    248248        $paged_users = $wpdb->get_results( $paged_users_sql );
    249        
     249
    250250        return array( 'users' => $paged_users, 'total' => $total_users );
    251251    }
     
    256256 * BP_Core_Notification class can be used by any component.
    257257 * It will handle the fetching, saving and deleting of a user notification.
    258  * 
     258 *
    259259 * @package BuddyPress Core
    260260 */
     
    269269    var $date_notified;
    270270    var $is_new;
    271    
     271
    272272    function bp_core_notification( $id = false ) {
    273273        if ( $id ) {
     
    276276        }
    277277    }
    278    
     278
    279279    function populate() {
    280280        global $wpdb, $bp;
    281        
     281
    282282        if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
    283283            $this->item_id = $notification->item_id;
     
    289289            $this->is_new = $notification->is_new;
    290290        }
    291     }   
    292    
     291    }
     292
    293293    function save() {
    294294        global $wpdb, $bp;
    295        
     295
    296296        if ( $this->id ) {
    297297            // Update
     
    310310
    311311    /* Static functions */
    312    
     312
    313313    function check_access( $user_id, $notification_id ) {
    314314        global $wpdb, $bp;
    315        
     315
    316316        return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
    317317    }
    318    
     318
    319319    function get_all_for_user( $user_id ) {
    320320        global $wpdb, $bp;
     
    322322        return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
    323323    }
    324    
     324
    325325    function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
    326326        global $wpdb, $bp;
    327        
     327
    328328        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
    329329    }
    330    
     330
    331331    function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
    332332        global $wpdb, $bp;
    333        
     333
    334334        if ( $secondary_item_id )
    335335            $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
    336        
     336
    337337        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
    338338    }
    339    
     339
    340340    function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
    341341        global $wpdb, $bp;
    342        
     342
    343343        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
    344344    }
    345    
     345
    346346    function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
    347347        global $wpdb, $bp;
    348        
     348
    349349        if ( $component_action )
    350350            $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
    351        
     351
    352352        if ( $secondary_item_id )
    353353            $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
    354        
     354
    355355        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
    356356    }
    357 }   
     357}
    358358
    359359
  • trunk/bp-core/bp-core-cssjs.php

    r2069 r2077  
    55 *
    66 * Add the CSS needed for the admin bar on blogs (other than the root) and in the admin area.
    7  * 
     7 *
    88 * @package BuddyPress Core
    99 * @uses get_option() Selects a site setting from the DB.
     
    1111function bp_core_add_admin_bar_css() {
    1212    global $current_blog;
    13    
     13
    1414    if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
    1515        return false;
     
    3232 *
    3333 * Add the minor JS needed for the admin bar.
    34  * 
     34 *
    3535 * @package BuddyPress Core
    3636 * @uses get_option() Selects a site setting from the DB.
     
    4646 *
    4747 * Add a hover-able icon to the "BuddyPress" wp-admin area menu.
    48  * 
     48 *
    4949 * @package BuddyPress Core
    5050 */
     
    6060}
    6161add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
    62    
     62
    6363function bp_core_confirmation_js() {
    6464?>
     
    7272 *
    7373 * Makes sure the jQuery jCrop library is loaded.
    74  * 
     74 *
    7575 * @package BuddyPress Core
    7676 */
    7777function bp_core_add_jquery_cropper() {
    7878    wp_enqueue_script( 'jcrop', array( 'jquery' ) );
    79     add_action( 'wp_head', 'bp_core_add_cropper_inline_js' ); 
    80     add_action( 'wp_head', 'bp_core_add_cropper_inline_css' ); 
     79    add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
     80    add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
    8181}
    8282
     
    8585 *
    8686 * Adds the inline JS needed for the cropper to work on a per-page basis.
    87  * 
     87 *
    8888 * @package BuddyPress Core
    8989 */
    9090function bp_core_add_cropper_inline_js() {
    9191    global $bp;
    92    
     92
    9393    $image = apply_filters( 'bp_inline_cropper_image', getimagesize( $bp->avatar_admin->image->dir ) );
    9494
    95     $aspect_ratio = 1; 
    96    
     95    $aspect_ratio = 1;
     96
    9797    /* Calculate Aspect Ratio */
    98     if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) ) 
     98    if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
    9999         $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
    100100?>
     
    131131                });
    132132            }
    133         }   
     133        }
    134134    </script>
    135135<?php
     
    140140 *
    141141 * Adds the inline CSS needed for the cropper to work on a per-page basis.
    142  * 
     142 *
    143143 * @package BuddyPress Core
    144144 */
     
    166166 *
    167167 * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
    168  * 
     168 *
    169169 * @package BuddyPress Core
    170170 */
    171171function bp_core_add_ajax_url_js() {
    172172    global $bp;
    173    
    174     echo 
     173
     174    echo
    175175'<script type="text/javascript">var ajaxurl = "' . $bp->root_domain . str_replace( 'index.php', 'wp-load.php', $_SERVER['SCRIPT_NAME'] ) . '";</script>
    176176';
     
    182182 *
    183183 * Overrides the theme's admin bar CSS to hide the adminbar if disabled.
    184  * 
     184 *
    185185 * @package BuddyPress Core
    186186 */
    187 function bp_core_override_adminbar_css() { 
     187function bp_core_override_adminbar_css() {
    188188    if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) {
    189189    ?>
  • trunk/bp-core/bp-core-notifications.php

    r1905 r2077  
    33function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
    44    global $bp;
    5    
     5
    66    if ( !$date_notified )
    77        $date_notified = time();
    8        
     8
    99    $notification = new BP_Core_Notification;
    1010    $notification->item_id = $item_id;
     
    1717    if ( $secondary_item_id )
    1818        $notification->secondary_item_id = $secondary_item_id;
    19    
     19
    2020    if ( !$notification->save() )
    2121        return false;
    22    
     22
    2323    return true;
    2424}
     
    2727    if ( !bp_core_check_notification_access( $bp->loggedin_user->id, $id ) )
    2828        return false;
    29    
     29
    3030    return BP_Core_Notification::delete( $id );
    3131}
    3232
    3333function bp_core_get_notification( $id ) {
    34     return new BP_Core_Notification( $id ); 
     34    return new BP_Core_Notification( $id );
    3535}
    3636
    3737function bp_core_get_notifications_for_user( $user_id ) {
    3838    global $bp;
    39    
     39
    4040    $notifications = BP_Core_Notification::get_all_for_user( $user_id );
    41    
     41
    4242    /* Group notifications by component and component_action and provide totals */
    4343    for ( $i = 0; $i < count($notifications); $i++ ) {
    4444        $notification = $notifications[$i];
    45        
     45
    4646        $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
    4747    }
    48    
     48
    4949    if ( !$grouped_notifications )
    5050        return false;
    51    
     51
    5252    /* Calculated a renderable outcome for each notification type */
    5353    foreach ( $grouped_notifications as $component_name => $action_arrays ) {
    5454        if ( !$action_arrays )
    5555            continue;
    56        
     56
    5757        foreach ( $action_arrays as $component_action_name => $component_action_items ) {
    5858            $action_item_count = count($component_action_items);
    59            
     59
    6060            if ( $action_item_count < 1 )
    6161                continue;
     
    6565            }
    6666        }
    67     }   
    68    
     67    }
     68
    6969    return $renderable;
    7070}
     
    8989    if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) )
    9090        return false;
    91    
     91
    9292    return true;
    9393}
  • trunk/bp-core/bp-core-settings.php

    r2059 r2077  
    33if ( !defined( 'BP_SETTINGS_SLUG' ) )
    44    define( 'BP_SETTINGS_SLUG', 'settings' );
    5    
     5
    66function bp_core_add_settings_nav() {
    77    global $bp;
    8    
     8
    99    /* Set up settings as a sudo-component for identification and nav selection */
    1010    $bp->settings->id = 'settings';
    1111    $bp->settings->slug = BP_SETTINGS_SLUG;
    12    
     12
    1313    /* Register this in the active components array */
    1414    $bp->active_components[$bp->settings->slug] = $bp->settings->id;
     
    1818
    1919    $settings_link = $bp->loggedin_user->domain . 'settings/';
    20    
     20
    2121    bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_home() ) );
    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_home() ) );
    23    
     23
    2424    if ( !is_site_admin() && !(int) get_site_option( '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_home() ) );
     
    3232function bp_core_screen_general_settings() {
    3333    global $current_user, $bp_settings_updated, $pass_error;
    34    
     34
    3535    $bp_settings_updated = false;
    3636    $pass_error = false;
    37    
     37
    3838    if ( isset($_POST['submit']) ) {
    3939        check_admin_referer('bp_settings_general');
    40        
     40
    4141        require_once( WPINC . '/registration.php' );
    42        
     42
    4343        // Form has been submitted and nonce checks out, lets do it.
    44        
     44
    4545        if ( $_POST['email'] != '' )
    4646            $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
     
    5656            unset( $current_user->user_pass );
    5757        }
    58        
     58
    5959        if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
    6060            $bp_settings_updated = true;
    6161    }
    62    
     62
    6363    add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
    6464    add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
    65    
     65