Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 06:56:42 PM (17 years ago)
Author:
apeatling
Message:

Merging last few trunk changes and stripping all whitespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1/bp-core/bp-core-classes.php

    r2052 r2076  
    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
Note: See TracChangeset for help on using the changeset viewer.