Skip to:
Content

BuddyPress.org

Changeset 1356


Ignore:
Timestamp:
04/20/2009 10:56:00 AM (15 years ago)
Author:
apeatling
Message:

Fixes #680

Location:
trunk
Files:
3 edited

Legend:

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

    r1351 r1356  
    142142        global $wpdb, $bp;
    143143       
     144        // TODO: Optimize this function.
     145       
    144146        if ( !$user_id )
    145147            $user_id = $bp->loggedin_user->id;
    146148       
    147149        like_escape($filter);
    148         $usermeta_table = $wpdb->prefix . 'usermeta';
    149150       
    150151        if ( $limit && $page )
     
    156157        // Get all the user ids for the current user's friends.
    157158        $fids = implode( ',', $friend_ids );
     159       
     160        if ( empty($fids) )
     161            return false;
    158162
    159163        // filter the user_ids based on the search criteria.
    160164        if ( function_exists('xprofile_install') ) {
    161             $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ($fids) AND value LIKE '$filter%%'" );
    162         } else {
    163             $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM $usermeta_table WHERE user_id IN ($fids) AND meta_key = 'nickname' AND meta_value LIKE '$filter%%'" );
    164         }
    165 
    166         $filtered_friends = $wpdb->get_results( $sql, ARRAY_A );   
    167 
    168         if ( !$filtered_friends )
    169             return false;
    170 
    171         // Get the total number of friendships
    172         $total_friends = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->friends->table_name} WHERE (friend_user_id IN ($filtered_fids) AND initiator_user_id = %d) OR (initiator_user_id IN ($filtered_fids) AND friend_user_id = %d)", $user_id, $user_id ) );
    173        
    174         return array( 'friends' => $filtered_friends, 'total' => $total_friends );
    175     }
    176        
     165            $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ($fids) AND value LIKE '$filter%%' {$pag_sql}" );
     166            $total_sql = $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->profile->table_name_data} WHERE user_id IN ($fids) AND value LIKE '$filter%%'" );
     167        } else {
     168            $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " WHERE user_id IN ($fids) AND meta_key = 'nickname' AND meta_value LIKE '$filter%%' {$pag_sql}" );
     169            $total_sql = $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM " . CUSTOM_USER_META_TABLE . " WHERE user_id IN ($fids) AND meta_key = 'nickname' AND meta_value LIKE '$filter%%'" );
     170        }
     171
     172        $filtered_friend_ids = $wpdb->get_results($sql);   
     173        $total_friend_ids = $wpdb->get_var($sql);   
     174       
     175        if ( !$filtered_friend_ids )
     176            return false;
     177
     178        return array( 'friends' => $filtered_friend_ids, 'total' => (int)$total_friend_ids );
     179    }
     180           
    177181    function check_is_friend( $loggedin_userid, $possible_friend_userid ) {
    178182        global $wpdb, $bp;
  • trunk/bp-friends/bp-friends-templatetags.php

    r1238 r1356  
    101101        $this->in_the_loop = true;
    102102        $this->friendship = $this->next_friendship();
    103        
     103
    104104        if ( 'requests' == $bp->current_action ) {
    105105            $this->friendship = new BP_Friends_Friendship( $this->friendship );
     106            $this->friendship->user_id = ( $this->friendship->friend_user_id == $bp->loggedin_user->id ) ?  $this->friendship->initiator_user_id : $this->friendship->friend_user_id;
    106107        } else {
    107108            $this->friendship = (object) $this->friendship;
    108            
     109
    109110            if ( !$this->friendship->friend = wp_cache_get( 'bp_user_' . $this->friendship->user_id, 'bp' ) ) {
    110111                $this->friendship->friend = new BP_Core_User( $this->friendship->user_id );
     
    112113            }
    113114        }
    114        
     115
    115116        if ( 0 == $this->current_friendship ) // loop has just started
    116117            do_action('loop_start');
     
    263264    </form>
    264265<?php
     266}
     267
     268function bp_friends_is_filtered() {
     269    if ( isset( $_POST['friend-search-box'] ) )
     270        return true;
     271   
     272    return false;
    265273}
    266274
  • trunk/bp-themes/buddypress-member/friends/friends-loop.php

    r1052 r1356  
    2424    <?php else: ?>
    2525
    26         <div id="message" class="info">
    27             <p><?php bp_word_or_name( __( "Your friends list is currently empty", 'buddypress' ), __( "%s's friends list is currently empty", 'buddypress' ) ) ?></p>
    28         </div>
     26        <?php if ( bp_friends_is_filtered() ) : ?>
     27            <div id="message" class="info">
     28                <p><?php _e( "No friends matched your search filter terms", 'buddypress' ) ?></p>
     29            </div>         
     30        <?php else : ?>
     31            <div id="message" class="info">
     32                <p><?php bp_word_or_name( __( "Your friends list is currently empty", 'buddypress' ), __( "%s's friends list is currently empty", 'buddypress' ) ) ?></p>
     33            </div>
     34        <?php endif; ?>
    2935       
    30         <?php if ( bp_is_home() ) : ?>
     36        <?php if ( bp_is_home() && !bp_friends_is_filtered() ) : ?>
    3137            <h3><?php _e( 'Why not make friends with some of these members?', 'buddypress' ) ?></h3>
    3238            <?php bp_friends_random_members() ?>
Note: See TracChangeset for help on using the changeset viewer.