Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/14/2009 03:24:05 PM (16 years ago)
Author:
apeatling
Message:

Committing core code support for new default theme.

Removed all deprecated code since it will be released as a separate plugin for backwards compatibility if people need it.

Removed the wire and status updates components since there is no support in the theme for these. If people still want this functionality then I'm sure there is someone in the community that could spend a bit of time and release them as plugins. I'm happy to guide.

Removed a lot of template loop duplication. There are no longer site loops and user loops (e.g. bp_has_site_groups() / bp_has_groups() ). There are now bp_has_members(), bp_has_groups(), bp_has_blogs() and you can pass a "user_id" parameter into these loops to limit results to only that user or users.

Merged activity stream functions. There are no longer functions for bp_activity_get_sitewide() / bp_activity_get_for_user() / bp_activity_get_friends_activity() instead there is simply one function: bp_activity_get() and you can pass in parameters to filter on just friends, for a single user, or anything your heart desires. Actually, filtering is extremely fine grained, so I encourage devs to check out the filter functions.

Lots of other code cleanup.

The new default theme will be committed straight after this. The original default folder will be renamed to bp-classic.

File:
1 edited

Legend:

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

    r2114 r2168  
    2525
    2626    var $last_active;
    27     var $profile_last_updated;
    2827
    2928    /* Extras */
     
    8079        $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
    8180        $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
     81
     82        $this->last_active = bp_core_get_last_activity( get_usermeta( $this->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) );
    8283    }
    8384
     
    106107    /* Static Functions */
    107108
    108     function get_newest_users( $limit = null, $page = 1 ) {
    109         global $wpdb;
     109    function get_users( $type, $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     110        global $wpdb, $bp;
     111
     112        $sql = array();
     113
     114        $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email";
     115
     116        if ( 'active' == $type || 'online' == $type )
     117            $sql['select_active'] = ", um.meta_value as last_activity";
     118
     119        if ( 'popular' == $type )
     120            $sql['select_popular'] = ", um.meta_value as total_friend_count";
     121
     122        if ( 'alphabetical' == $type )
     123            $sql['select_alpha'] = ", pd.value as fullname";
     124
     125        $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
     126
     127        if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
     128            $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
     129
     130        $sql['where'] = "WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0";
     131
     132        if ( 'active' == $type || 'online' == $type )
     133            $sql['where_active'] = "AND um.meta_key = 'last_activity'";
     134
     135        if ( 'popular' == $type )
     136            $sql['where_popular'] = "AND um.meta_key = 'total_friend_count'";
     137
     138        if ( 'online' == $type )
     139            $sql['where_online'] = "AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW()";
     140
     141        if ( 'alphabetical' == $type )
     142            $sql['where_alpha'] = "AND pd.field_id = 1";
     143
     144        if ( $user_id && function_exists( 'friends_install' ) ) {
     145            $friend_ids = friends_get_friend_user_ids( $user_id );
     146            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
     147
     148            $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
     149        }
     150
     151        if ( $search_terms && function_exists( 'xprofile_install' ) ) {
     152            $search_terms = like_escape( $wpdb->escape( $search_terms ) );
     153            $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
     154        }
     155
     156        switch ( $type ) {
     157            case 'active': default:
     158                $sql[] = "ORDER BY um.meta_value DESC";
     159                break;
     160            case 'newest':
     161                $sql[] = "ORDER BY u.user_registered DESC";
     162                break;
     163            case 'alphabetical':
     164                $sql[] = "ORDER BY pd.value ASC";
     165                break;
     166            case 'random':
     167                $sql[] = "ORDER BY rand()";
     168                break;
     169            case 'online':
     170                $sql[] = "ORDER BY FROM_UNIXTIME(um.meta_value) DESC";
     171                break;
     172            case 'popular':
     173                $sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
     174                break;
     175        }
     176
     177        if ( $limit && $page )
     178            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     179
     180        /* Get paginated results */
     181        $paged_users = $wpdb->get_results( $wpdb->prepare( join( ' ', (array)$sql ) ) );
     182
     183    //  var_dump( join( ' ', $sql ) );
     184
     185        /* Re-jig the SQL so we can get the total user count */
     186        unset( $sql['select_main'] );
     187
     188        if ( !empty( $sql['select_active'] ) )
     189            unset( $sql['select_active'] );
     190
     191        if ( !empty( $sql['select_popular'] ) )
     192            unset( $sql['select_popular'] );
     193
     194        if ( !empty( $sql['select_alpha'] ) )
     195            unset( $sql['select_alpha'] );
     196
     197        if ( !empty( $sql['pagination'] ) )
     198            unset( $sql['pagination'] );
     199
     200        array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
     201
     202        /* Get total user results */
     203        $total_users = $wpdb->get_var( $wpdb->prepare( join( ' ', (array)$sql ) ) );
     204
     205        /***
     206         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     207         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     208         */
     209        foreach ( $paged_users as $user )
     210            $user_ids[] = $user->id;
     211
     212        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     213
     214        /* Add additional data to the returned results */
     215        $paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
     216
     217        return array( 'users' => $paged_users, 'total' => $total_users );
     218    }
     219
     220    function get_users_by_letter( $letter, $limit = null, $page = 1 ) {
     221        global $wpdb, $bp;
    110222
    111223        if ( $limit && $page )
    112224            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    113225
    114         $total_users_sql = apply_filters( 'bp_core_newest_users_count_sql', "SELECT COUNT(DISTINCT ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC" );
    115         $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 );
     226        if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
     227            return false;
     228
     229        $letter = like_escape( $wpdb->escape( $letter ) );
     230
     231        $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
     232        $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
    116233
    117234        $total_users = $wpdb->get_var( $total_users_sql );
    118235        $paged_users = $wpdb->get_results( $paged_users_sql );
    119236
     237        /***
     238         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     239         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     240         */
     241        foreach ( $paged_users as $user )
     242            $user_ids[] = $user->id;
     243
     244        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     245
     246        /* Add additional data to the returned results */
     247        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     248
    120249        return array( 'users' => $paged_users, 'total' => $total_users );
    121250    }
    122251
    123     function get_active_users( $limit = null, $page = 1 ) {
    124         global $wpdb;
     252    function get_specific_users( $user_ids, $limit = null, $page = 1 ) {
     253        global $wpdb, $bp;
    125254
    126255        if ( $limit && $page )
    127256            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    128257
    129         $total_users_sql = apply_filters( 'bp_core_active_users_count_sql', "SELECT COUNT(DISTINCT 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" );
    130         $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 );
     258        $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
     259
     260        $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) " ), $wpdb->escape( $user_ids ) );
     261        $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT DISTINCT ID as id, user_registered, user_nicename, user_login, user_email FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) {$pag_sql}" ), $wpdb->escape( $user_ids ) );
    131262
    132263        $total_users = $wpdb->get_var( $total_users_sql );
    133264        $paged_users = $wpdb->get_results( $paged_users_sql );
    134265
     266        /***
     267         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     268         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     269         */
     270        foreach ( $paged_users as $user )
     271            $user_ids[] = $user->id;
     272
     273        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     274
     275        /* Add additional data to the returned results */
     276        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     277
    135278        return array( 'users' => $paged_users, 'total' => $total_users );
    136279    }
    137280
    138     function get_popular_users( $limit = null, $page = 1 ) {
    139         global $wpdb;
    140 
    141         if ( !function_exists('friends_install') )
    142             return false;
     281    function search_users( $search_terms, $limit = null, $page = 1 ) {
     282        global $wpdb, $bp;
    143283
    144284        if ( $limit && $page )
    145285            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    146286
    147         $total_users_sql = apply_filters( 'bp_core_popular_users_count_sql', "SELECT COUNT(DISTINCT 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 = 'total_friend_count' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY CONVERT(um.meta_value, SIGNED) DESC" );
    148         $paged_users_sql = apply_filters( 'bp_core_popular_users_sql', "SELECT DISTINCT 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 = 'total_friend_count' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY CONVERT(um.meta_value, SIGNED) DESC{$pag_sql}", $pag_sql );
     287        $search_terms = like_escape( $wpdb->escape( $search_terms ) );
     288
     289        $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as 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 );
     290        $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email 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{$pag_sql}", $search_terms, $pag_sql );
    149291
    150292        $total_users = $wpdb->get_var( $total_users_sql );
    151293        $paged_users = $wpdb->get_results( $paged_users_sql );
    152294
     295        /***
     296         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     297         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     298         */
     299        foreach ( $paged_users as $user )
     300            $user_ids[] = $user->id;
     301
     302        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     303
     304        /* Add additional data to the returned results */
     305        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     306
    153307        return array( 'users' => $paged_users, 'total' => $total_users );
    154308    }
    155309
    156     function get_random_users( $limit = null, $page = 1 ) {
    157         global $wpdb, $bp;
    158 
    159         if ( $limit && $page )
    160             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    161 
    162         $total_users_sql = apply_filters( 'bp_core_random_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND u.ID != %d ORDER BY RAND() DESC", $bp->loggedin_user->id ) );
    163         $paged_users_sql = apply_filters( 'bp_core_random_users_sql', $wpdb->prepare( "SELECT DISTINCT um.user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND u.ID != %d ORDER BY RAND(){$pag_sql}", $bp->loggedin_user->id ), $pag_sql );
    164 
    165         $total_users = $wpdb->get_var( $total_users_sql );
    166         $paged_users = $wpdb->get_results( $paged_users_sql );
    167 
    168         return array( 'users' => $paged_users, 'total' => $total_users );
    169     }
    170 
    171     function get_online_users( $limit = null, $page = 1 ) {
    172         global $wpdb;
    173 
    174         if ( $limit && $page )
    175             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    176 
    177         $total_users_sql = apply_filters( 'bp_core_online_users_count_sql', "SELECT COUNT(DISTINCT 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 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW() ORDER BY FROM_UNIXTIME(um.meta_value) DESC" );
    178         $paged_users_sql = apply_filters( 'bp_core_online_users_sql', "SELECT DISTINCT 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 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW() ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}", $pag_sql );
    179 
    180         $total_users = $wpdb->get_var( $total_users_sql );
    181         $paged_users = $wpdb->get_results( $paged_users_sql );
    182 
    183         return array( 'users' => $paged_users, 'total' => $total_users );
    184     }
    185 
    186     function get_alphabetical_users( $limit = null, $page = 1 ) {
    187         global $wpdb, $bp;
    188 
    189         if ( !function_exists( 'xprofile_install' ) )
    190             return BP_Core_User::get_active_users( $limit, $page );
    191 
    192         if ( $limit && $page )
    193             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    194 
    195         $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT DISTINCT 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 );
    196         $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT 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{$pag_sql}", $search_terms, $pag_sql );
    197 
    198         $total_users = $wpdb->get_var( $total_users_sql );
    199         $paged_users = $wpdb->get_results( $paged_users_sql );
    200 
    201         return array( 'users' => $paged_users, 'total' => $total_users );
    202     }
    203 
    204     function get_users_by_letter( $letter, $limit = null, $page = 1 ) {
    205         global $wpdb, $bp;
    206 
    207         if ( !function_exists('xprofile_install') )
    208             return BP_Core_User::get_active_users( $limit, $page );
    209 
    210         if ( $limit && $page )
    211             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    212 
    213         if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
    214             return false;
    215 
    216         $letter = like_escape( $wpdb->escape( $letter ) );
    217 
    218         $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
    219         $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
    220 
    221         $total_users = $wpdb->get_var( $total_users_sql );
    222         $paged_users = $wpdb->get_results( $paged_users_sql );
    223 
    224         return array( 'users' => $paged_users, 'total' => $total_users );
    225     }
    226 
    227     function search_users( $search_terms, $limit = null, $page = 1 ) {
    228         global $wpdb, $bp;
    229 
    230         if ( !function_exists('xprofile_install') )
    231             return BP_Core_User::get_active_users( $limit, $page );
    232 
    233         if ( $limit && $page )
    234             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    235 
    236         $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    237 
    238         $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT 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 );
    239         $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT 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{$pag_sql}", $search_terms, $pag_sql );
    240 
    241         $total_users = $wpdb->get_var( $total_users_sql );
    242         $paged_users = $wpdb->get_results( $paged_users_sql );
    243 
    244         return array( 'users' => $paged_users, 'total' => $total_users );
     310    function get_user_extras( $paged_users, $user_ids, $type = false ) {
     311        global $bp, $wpdb;
     312
     313        if ( empty( $user_ids ) )
     314            return $paged_users;
     315
     316        /* Fetch the user's full name */
     317        if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
     318            $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", BP_XPROFILE_FULLNAME_FIELD_NAME ) );
     319            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     320                foreach ( $names as $name ) {
     321                    if ( $name->id == $paged_users[$i]->id )
     322                        $paged_users[$i]->fullname = $name->fullname;
     323                }
     324            }
     325        }
     326
     327        /* Fetch the user's total friend count */
     328        if ( 'popular' != $type ) {
     329            $friend_count = $wpdb->get_results( "SELECT user_id as id, meta_value as total_friend_count FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'total_friend_count' AND user_id IN ( {$user_ids} )" );
     330            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     331                foreach ( $friend_count as $count ) {
     332                    if ( $count->id == $paged_users[$i]->id )
     333                        $paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
     334                }
     335            }
     336        }
     337
     338        /* Fetch the user's last_activity */
     339        if ( 'active' != $type ) {
     340            $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
     341            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     342                foreach ( $user_activity as $activity ) {
     343                    if ( $activity->id == $paged_users[$i]->id )
     344                        $paged_users[$i]->last_activity = (int)$activity->last_activity;
     345                }
     346            }
     347        }
     348
     349        return $paged_users;
    245350    }
    246351}
Note: See TracChangeset for help on using the changeset viewer.