Ejemplo n.º 1
0
	function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras ) {
		global $bp;

		$this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
		$this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
		$this->type     = $type;

		if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
			$this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
		else
			$this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );

		if ( !$max || $max >= (int)$this->members['total'] )
			$this->total_member_count = (int)$this->members['total'];
		else
			$this->total_member_count = (int)$max;

		$this->members = $this->members['users'];

		if ( $max ) {
			if ( $max >= count($this->members) ) {
				$this->member_count = count( $this->members );
			} else {
				$this->member_count = (int)$max;
			}
		} else {
			$this->member_count = count( $this->members );
		}

		if ( (int)$this->total_member_count && (int)$this->pag_num ) {
			$this->pag_links = paginate_links( array(
				'base'      => add_query_arg( 'upage', '%#%' ),
				'format'    => '',
				'total'     => ceil( (int)$this->total_member_count / (int)$this->pag_num ),
				'current'   => (int)$this->pag_page,
				'prev_text' => '←',
				'next_text' => '→',
				'mid_size'  => 1
			) );
		}
	}
Ejemplo n.º 2
0
function bp_friends_random_members( $total_members = 5 ) {
	global $bp;

	if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {
		$user_ids = BP_Core_User::get_users( 'random', $total_members );
		wp_cache_set( 'friends_random_users', $user_ids, 'bp' );
	}
?>
	<?php if ( $user_ids['users'] ) { ?>
		<ul class="item-list" id="random-members-list">
		<?php for ( $i = 0; $i < count( $user_ids['users'] ); $i++ ) { ?>
			<li>
				<a href="<?php echo bp_core_get_user_domain( $user_ids['users'][$i]->user_id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->user_id, 'type' => 'thumb' ) ) ?></a>
				<h5><?php echo bp_core_get_userlink( $user_ids['users'][$i]->user_id ) ?></h5>
				<?php if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
					<?php $random_data = xprofile_get_random_profile_data( $user_ids['users'][$i]->user_id, true ); ?>
					<div class="profile-data">
						<p class="field-name"><?php echo $random_data[0]->name ?></p>
						<?php echo $random_data[0]->value ?>
					</div>
				<?php } ?>

				<div class="action">
					<?php if ( function_exists( 'bp_add_friend_button' ) ) { ?>
						<?php bp_add_friend_button( $user_ids['users'][$i]->user_id ) ?>
					<?php } ?>
				</div>
			</li>
		<?php } ?>
		</ul>
	<?php } else { ?>
		<div id="message" class="info">
			<p><?php _e( "There aren't enough site members to show a random sample just yet.", 'buddypress' ) ?></p>
		</div>
	<?php } ?>
<?php
}
 function __construct($type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value)
 {
     global $bp;
     $this->pag_page = !empty($_REQUEST['upage']) ? intval($_REQUEST['upage']) : (int) $page_number;
     $this->pag_num = !empty($_REQUEST['num']) ? intval($_REQUEST['num']) : (int) $per_page;
     $this->type = $type;
     if (isset($_REQUEST['letter']) && '' != $_REQUEST['letter']) {
         $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude);
     } else {
         if (false !== $include) {
             $this->members = BP_Core_User::get_specific_users($include, $this->pag_num, $this->pag_page, $populate_extras);
         } else {
             $this->members = bp_core_get_users(array('type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value));
         }
     }
     if (!$max || $max >= (int) $this->members['total']) {
         $this->total_member_count = (int) $this->members['total'];
     } else {
         $this->total_member_count = (int) $max;
     }
     $this->members = $this->members['users'];
     if ($max) {
         if ($max >= count($this->members)) {
             $this->member_count = count($this->members);
         } else {
             $this->member_count = (int) $max;
         }
     } else {
         $this->member_count = count($this->members);
     }
     if ((int) $this->total_member_count && (int) $this->pag_num) {
         $this->pag_links = paginate_links(array('base' => add_query_arg('upage', '%#%'), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Member pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Member pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
Ejemplo n.º 4
0
/**
 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_messages_autocomplete_results()
{
    // Include everyone in the autocomplete, or just friends?
    if (bp_is_current_component(bp_get_messages_slug())) {
        $autocomplete_all = buddypress()->messages->autocomplete_all;
    }
    $pag_page = 1;
    $limit = (int) $_GET['limit'] ? $_GET['limit'] : apply_filters('bp_autocomplete_max_results', 10);
    // Get the user ids based on the search terms
    if (!empty($autocomplete_all)) {
        $users = BP_Core_User::search_users($_GET['q'], $limit, $pag_page);
        if (!empty($users['users'])) {
            // Build an array with the correct format
            $user_ids = array();
            foreach ($users['users'] as $user) {
                if ($user->id != bp_loggedin_user_id()) {
                    $user_ids[] = $user->id;
                }
            }
            $user_ids = apply_filters('bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit);
        }
    } else {
        if (bp_is_active('friends')) {
            $users = friends_search_friends($_GET['q'], bp_loggedin_user_id(), $limit, 1);
            // Keeping the bp_friends_autocomplete_list filter for backward compatibility
            $users = apply_filters('bp_friends_autocomplete_list', $users, $_GET['q'], $limit);
            if (!empty($users['friends'])) {
                $user_ids = apply_filters('bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit);
            }
        }
    }
    if (!empty($user_ids)) {
        foreach ($user_ids as $user_id) {
            $ud = get_userdata($user_id);
            if (!$ud) {
                continue;
            }
            if (bp_is_username_compatibility_mode()) {
                $username = $ud->user_login;
            } else {
                $username = $ud->user_nicename;
            }
            // Note that the final line break acts as a delimiter for the
            // autocomplete javascript and thus should not be removed
            echo '<span id="link-' . esc_attr($username) . '" href="' . bp_core_get_user_domain($user_id) . '"></span>' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name)) . ' &nbsp;' . bp_core_get_user_displayname($user_id) . ' (' . esc_html($username) . ')' . "\n";
        }
    }
    exit;
}
/**
 * Get a user's friends, in the order in which they joined the site.
 *
 * @since 1.0.0
 *
 * @see BP_Core_User::get_users() for a description of return value.
 *
 * @param int    $user_id  ID of the user whose friends are being retrieved.
 * @param int    $per_page Optional. Number of results to return per page.
 *                         Default: 0 (no pagination; show all results).
 * @param int    $page     Optional. Number of the page of results to return.
 *                         Default: 0 (no pagination; show all results).
 * @param string $filter   Optional. Limit results to those matching a search
 *                         string.
 * @return array See {@link BP_Core_User::get_users()}.
 */
function friends_get_newest($user_id, $per_page = 0, $page = 0, $filter = '')
{
    /**
     * Filters a user's friends listed from newest to oldest.
     *
     * @since 1.2.0
     *
     * @param array {
     *     @type int   $total_users Total number of users matched by query params.
     *     @type array $paged_users The current page of users matched by query params.
     * }
     */
    return apply_filters('friends_get_newest', BP_Core_User::get_users('newest', $per_page, $page, $user_id, $filter));
}
Ejemplo n.º 6
0
function bp_core_widget_whos_online($args)
{
    global $current_blog;
    extract($args);
    $options = get_blog_option($current_blog->blog_id, 'bp_core_widget_whos_online');
    ?>
	<?php 
    echo $before_widget;
    ?>
	<?php 
    echo $before_title . $widget_name . $after_title;
    ?>

	<?php 
    if (!($users = wp_cache_get('online_users', 'bp'))) {
        $users = BP_Core_User::get_online_users($options['max_members']);
        wp_cache_set('online_users', $users, 'bp');
    }
    ?>

	<?php 
    $users = BP_Core_User::get_online_users($options['max_members']);
    ?>

	<?php 
    if ($users['users']) {
        ?>
		<div class="avatar-block">
		<?php 
        foreach ((array) $users['users'] as $user) {
            ?>
			<div class="item-avatar">
				<a href="<?php 
            echo bp_core_get_userurl($user->user_id);
            ?>
" title="<?php 
            bp_fetch_user_fullname($user->user_id, true);
            ?>
"><?php 
            echo bp_core_get_avatar($user->user_id, 1);
            ?>
</a>
			</div>
		<?php 
        }
        ?>
		</div>
			
		<?php 
        if (function_exists('wp_nonce_field')) {
            wp_nonce_field('bp_core_widget_members', '_wpnonce-members');
        }
        ?>

		<input type="hidden" name="bp_core_widget_members_max" id="bp_core_widget_members_max" value="<?php 
        echo attribute_escape($options['max_members']);
        ?>
" />

	<?php 
    } else {
        ?>
		<div class="widget-error">
			<?php 
        _e('There are no users currently online.', 'buddypress');
        ?>
		</div>
	<?php 
    }
    ?>

	<?php 
    echo $after_widget;
    ?>
	
	<div class="clear" style="margin-bottom: 25px"></div>
	
<?php 
}
 function bp_core_members_template($type, $per_page, $max)
 {
     global $bp, $bp_the_member_query;
     $this->pag_page = isset($_REQUEST['upage']) ? intval($_REQUEST['upage']) : 1;
     $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     if (isset($_REQUEST['s']) && '' != $_REQUEST['s'] && $type != 'random') {
         $this->members = BP_Core_User::search_users($_REQUEST['s'], $this->pag_num, $this->pag_page);
     } else {
         if (isset($_REQUEST['letter']) && '' != $_REQUEST['letter']) {
             $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page);
         } else {
             switch ($type) {
                 case 'random':
                     $this->members = BP_Core_User::get_random_users($this->pag_num, $this->pag_page);
                     break;
                 case 'newest':
                     $this->members = BP_Core_User::get_newest_users($this->pag_num, $this->pag_page);
                     break;
                 case 'popular':
                     $this->members = BP_Core_User::get_popular_users($this->pag_num, $this->pag_page);
                     break;
                 case 'online':
                     $this->members = BP_Core_User::get_online_users($this->pag_num, $this->pag_page);
                     break;
                 case 'alphabetical':
                     $this->members = BP_Core_User::get_alphabetical_users($this->pag_num, $this->pag_page);
                     break;
                 case 'active':
                 default:
                     $this->members = BP_Core_User::get_active_users($this->pag_num, $this->pag_page);
                     break;
             }
         }
     }
     if (!$max) {
         $this->total_member_count = (int) $this->members['total'];
     } else {
         $this->total_member_count = (int) $max;
     }
     $this->members = $this->members['users'];
     if ($max) {
         if ($max >= count($this->members)) {
             $this->member_count = count($this->members);
         } else {
             $this->member_count = (int) $max;
         }
     } else {
         $this->member_count = count($this->members);
     }
     $this->pag_links = paginate_links(array('base' => add_query_arg('upage', '%#%'), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => '&laquo;', 'next_text' => '&raquo;', 'mid_size' => 1));
 }
 /**
  * Perform a database query to populate any extra metadata we might need.
  *
  * Different components will hook into the 'bp_user_query_populate_extras'
  * action to loop in the things they want.
  *
  * @since 1.7.0
  *
  * @global WPDB $wpdb Global WordPress database access object.
  */
 public function populate_extras()
 {
     global $wpdb;
     // Bail if no users.
     if (empty($this->user_ids) || empty($this->results)) {
         return;
     }
     // Bail if the populate_extras flag is set to false
     // In the case of the 'popular' sort type, we force
     // populate_extras to true, because we need the friend counts.
     if ('popular' == $this->query_vars['type']) {
         $this->query_vars['populate_extras'] = 1;
     }
     if (!(bool) $this->query_vars['populate_extras']) {
         return;
     }
     // Turn user ID's into a query-usable, comma separated value.
     $user_ids_sql = implode(',', wp_parse_id_list($this->user_ids));
     /**
      * Allows users to independently populate custom extras.
      *
      * Note that anything you add here should query using $user_ids_sql, to
      * avoid running multiple queries per user in the loop.
      *
      * Two BuddyPress components currently do this:
      * - XProfile: To override display names.
      * - Friends:  To set whether or not a user is the current users friend.
      *
      * @see bp_xprofile_filter_user_query_populate_extras()
      * @see bp_friends_filter_user_query_populate_extras()
      *
      * @since 1.7.0
      *
      * @param BP_User_Query $this         Current BP_User_Query instance.
      * @param string        $user_ids_sql Comma-separated string of user IDs.
      */
     do_action_ref_array('bp_user_query_populate_extras', array($this, $user_ids_sql));
     // Fetch last_active data from the activity table.
     $last_activities = BP_Core_User::get_last_activity($this->user_ids);
     // Set a last_activity value for each user, even if it's empty.
     foreach ($this->results as $user_id => $user) {
         $user_last_activity = isset($last_activities[$user_id]) ? $last_activities[$user_id]['date_recorded'] : '';
         $this->results[$user_id]->last_activity = $user_last_activity;
     }
     // Fetch usermeta data
     // We want the three following pieces of info from usermeta:
     // - friend count
     // - latest update.
     $total_friend_count_key = bp_get_user_meta_key('total_friend_count');
     $bp_latest_update_key = bp_get_user_meta_key('bp_latest_update');
     // Total_friend_count must be set for each user, even if its
     // value is 0.
     foreach ($this->results as $uindex => $user) {
         $this->results[$uindex]->total_friend_count = 0;
     }
     // Create, prepare, and run the separate usermeta query.
     $user_metas = $wpdb->get_results($wpdb->prepare("SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", $total_friend_count_key, $bp_latest_update_key));
     // The $members_template global expects the index key to be different
     // from the meta_key in some cases, so we rejig things here.
     foreach ($user_metas as $user_meta) {
         switch ($user_meta->meta_key) {
             case $total_friend_count_key:
                 $key = 'total_friend_count';
                 break;
             case $bp_latest_update_key:
                 $key = 'latest_update';
                 break;
         }
         if (isset($this->results[$user_meta->user_id])) {
             $this->results[$user_meta->user_id]->{$key} = $user_meta->meta_value;
         }
     }
     // When meta_key or meta_value have been passed to the query,
     // fetch the resulting values for use in the template functions.
     if (!empty($this->query_vars['meta_key'])) {
         $meta_sql = array('select' => "SELECT user_id, meta_key, meta_value", 'from' => "FROM {$wpdb->usermeta}", 'where' => $wpdb->prepare("WHERE meta_key = %s", $this->query_vars['meta_key']));
         if (false !== $this->query_vars['meta_value']) {
             $meta_sql['where'] .= $wpdb->prepare(" AND meta_value = %s", $this->query_vars['meta_value']);
         }
         $metas = $wpdb->get_results("{$meta_sql['select']} {$meta_sql['from']} {$meta_sql['where']}");
         if (!empty($metas)) {
             foreach ($metas as $meta) {
                 if (isset($this->results[$meta->user_id])) {
                     $this->results[$meta->user_id]->meta_key = $meta->meta_key;
                     if (!empty($meta->meta_value)) {
                         $this->results[$meta->user_id]->meta_value = $meta->meta_value;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Constructor method.
  *
  * @see BP_User_Query for an in-depth description of parameters.
  *
  * @param string       $type                Sort order.
  * @param int          $page_number         Page of results.
  * @param int          $per_page            Number of results per page.
  * @param int          $max                 Max number of results to return.
  * @param int          $user_id             Limit to friends of a user.
  * @param string       $search_terms        Limit to users matching search terms.
  * @param array        $include             Limit results by these user IDs.
  * @param bool         $populate_extras     Fetch optional extras.
  * @param array        $exclude             Exclude these IDs from results.
  * @param array        $meta_key            Limit to users with a meta_key.
  * @param array        $meta_value          Limit to users with a meta_value (with meta_key).
  * @param string       $page_arg            Optional. The string used as a query parameter in pagination links.
  *                                          Default: 'upage'.
  * @param array|string $member_type         Array or comma-separated string of member types to limit results to.
  * @param array|string $member_type__in     Array or comma-separated string of member types to limit results to.
  * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude
  *                                          from results.
  */
 function __construct($type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '')
 {
     $this->pag_arg = sanitize_key($page_arg);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page_number);
     $this->pag_num = bp_sanitize_pagination_arg('num', $per_page);
     $this->type = $type;
     if (!empty($_REQUEST['letter'])) {
         $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude);
     } else {
         $this->members = bp_core_get_users(array('type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in));
     }
     if (!$max || $max >= (int) $this->members['total']) {
         $this->total_member_count = (int) $this->members['total'];
     } else {
         $this->total_member_count = (int) $max;
     }
     $this->members = $this->members['users'];
     if ($max) {
         if ($max >= count($this->members)) {
             $this->member_count = count($this->members);
         } else {
             $this->member_count = (int) $max;
         }
     } else {
         $this->member_count = count($this->members);
     }
     if ((int) $this->total_member_count && (int) $this->pag_num) {
         $pag_args = array($this->pag_arg => '%#%');
         if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) {
             $base = remove_query_arg('s', wp_get_referer());
         } else {
             $base = '';
         }
         /**
          * Defaults to an empty array to make sure paginate_links()
          * won't add the $page_arg to the links which would break
          * pagination in case JavaScript is disabled.
          */
         $add_args = array();
         if (!empty($search_terms)) {
             $query_arg = bp_core_get_component_search_query_arg('members');
             $add_args[$query_arg] = urlencode($search_terms);
         }
         $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Member pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Member pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args));
     }
 }
Ejemplo n.º 10
0
function invite_anyone_ajax_autocomplete_results()
{
    global $bp;
    $friends = false;
    // Get the friend ids based on the search terms
    $friends = BP_Core_User::search_users($_GET['q'], 500, 1);
    $friends = apply_filters('bp_friends_autocomplete_list', $friends, $_GET['q'], $_GET['limit']);
    if ($friends['users']) {
        foreach ($friends['users'] as $user) {
            if ($user->user_id) {
                // For BP < 1.2
                $user_id = $user->user_id;
            } else {
                $user_id = $user->id;
            }
            $ud = get_userdata($user_id);
            $username = $ud->user_login;
            echo bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'width' => 25, 'height' => 25)) . ' ' . bp_core_get_user_displayname($user->user_id) . ' (' . $username . ')
			';
        }
    }
}
Ejemplo n.º 11
0
 /**
  * Constructor method.
  *
  * @see BP_User_Query for an in-depth description of parameters.
  *
  * @param string $type Sort order.
  * @param int $page_number Page of results.
  * @param int $per_page Number of results per page.
  * @param int $max Max number of results to return.
  * @param int $user_id Limit to friends of a user.
  * @param string $search_terms Limit to users matching search terms.
  * @param array $include Limit results by these user IDs.
  * @param bool $populate_extras Fetch optional extras.
  * @param array $exclude Exclude these IDs from results.
  * @param array $meta_key Limit to users with a meta_key.
  * @param array $meta_value Limit to users with a meta_value (with meta_key).
  * @param array $page_arg Optional. The string used as a query
  *        parameter in pagination links. Default: 'upage'.
  */
 function __construct($type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage')
 {
     $this->pag_page = !empty($_REQUEST[$page_arg]) ? intval($_REQUEST[$page_arg]) : (int) $page_number;
     $this->pag_num = !empty($_REQUEST['num']) ? intval($_REQUEST['num']) : (int) $per_page;
     $this->type = $type;
     if (!empty($_REQUEST['letter'])) {
         $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude);
     } else {
         $this->members = bp_core_get_users(array('type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value));
     }
     if (!$max || $max >= (int) $this->members['total']) {
         $this->total_member_count = (int) $this->members['total'];
     } else {
         $this->total_member_count = (int) $max;
     }
     $this->members = $this->members['users'];
     if ($max) {
         if ($max >= count($this->members)) {
             $this->member_count = count($this->members);
         } else {
             $this->member_count = (int) $max;
         }
     } else {
         $this->member_count = count($this->members);
     }
     if ((int) $this->total_member_count && (int) $this->pag_num) {
         $pag_args = array($page_arg => '%#%');
         if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) {
             $base = remove_query_arg('s', wp_get_referer());
         } else {
             $base = '';
         }
         if (!empty($search_terms)) {
             $pag_args['s'] = $search_terms;
         }
         $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Member pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Member pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
Ejemplo n.º 12
0
function bp_gtm_search_users($search_terms, $limit = 10, $page = 1, $populate_extras = true)
{
    return BP_Core_User::search_users($search_terms, $limit, $page, $populate_extras);
}
Ejemplo n.º 13
0
 /**
  * Find users who match on the value of an xprofile data.
  *
  * @global object $bp Global BuddyPress settings object
  * @global nxtdb $nxtdb NXTClass database object
  * @param string $search_terms The terms to search the profile table value column for.
  * @param integer $limit The limit of results we want.
  * @param integer $page The page we are on for pagination.
  * @param boolean $populate_extras Populate extra user fields?
  * @return array Associative array
  * @static
  */
 function search_users($search_terms, $limit = null, $page = 1, $populate_extras = true)
 {
     global $bp, $nxtdb;
     $pag_sql = $limit && $page ? $nxtdb->prepare(" LIMIT %d, %d", intval(($page - 1) * intval($limit)), intval($limit)) : '';
     $search_terms = like_escape($nxtdb->escape($search_terms));
     $status_sql = bp_core_get_status_sql('u.');
     $total_users_sql = apply_filters('bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM {$nxtdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC", $search_terms);
     $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 {$nxtdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql);
     $total_users = $nxtdb->get_var($total_users_sql);
     $paged_users = $nxtdb->get_results($paged_users_sql);
     /***
      * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
      * 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)
      */
     foreach ((array) $paged_users as $user) {
         $user_ids[] = $user->id;
     }
     $user_ids = $nxtdb->escape(join(',', (array) $user_ids));
     // Add additional data to the returned results
     if ($populate_extras) {
         $paged_users = BP_Core_User::get_user_extras($paged_users, $user_ids);
     }
     return array('users' => $paged_users, 'total' => $total_users);
 }
Ejemplo n.º 14
0
 /**
  * @group last_activity
  */
 public function test_delete_last_activity()
 {
     $u = $this->factory->user->create();
     $time = bp_core_current_time();
     BP_Core_User::update_last_activity($u, $time);
     $a = BP_Core_User::get_last_activity($u);
     $found = isset($a[$u]['date_recorded']) ? $a[$u]['date_recorded'] : '';
     $this->assertEquals($time, $found);
     BP_Core_User::delete_last_activity($u);
     $a = BP_Core_User::get_last_activity($u);
     $found = isset($a[$u]['date_recorded']) ? $a[$u]['date_recorded'] : '';
     $this->assertEquals('', $found);
 }
Ejemplo n.º 15
0
/**
 * Fetch everything in the wp_users table for a user, without any usermeta.
 *
 * @package BuddyPress Core
 * @param user_id The ID of the user.
 * @uses BP_Core_User::get_core_userdata() Performs the query.
 */
function bp_core_get_core_userdata($user_id)
{
    if (empty($user_id)) {
        return false;
    }
    if (!($userdata = wp_cache_get('bp_core_userdata_' . $user_id, 'bp'))) {
        $userdata = BP_Core_User::get_core_userdata($user_id);
        wp_cache_set('bp_core_userdata_' . $user_id, $userdata, 'bp');
    }
    return apply_filters('bp_core_get_core_userdata', $userdata);
}
Ejemplo n.º 16
0
 /**
  * Find users who match on the value of an xprofile data.
  *
  * @global wpdb $wpdb WordPress database object.
  *
  * @param string $search_terms The terms to search the profile table
  *        value column for.
  * @param integer $limit The limit of results we want.
  * @param integer $page The page we are on for pagination.
  * @param boolean $populate_extras Populate extra user fields?
  * @return array Associative array.
  */
 public static function search_users($search_terms, $limit = null, $page = 1, $populate_extras = true)
 {
     global $wpdb;
     $bp = buddypress();
     $user_ids = array();
     $pag_sql = $limit && $page ? $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * intval($limit)), intval($limit)) : '';
     $search_terms_like = '%' . bp_esc_like($search_terms) . '%';
     $status_sql = bp_core_get_status_sql('u.');
     /**
      * Filters the SQL used to query for searched users count.
      *
      * @since BuddyPress (1.0.0)
      *
      * @param string $value SQL statement for the searched users count query.
      */
     $total_users_sql = apply_filters('bp_core_search_users_count_sql', $wpdb->prepare("SELECT COUNT(DISTINCT u.ID) as id FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC", $search_terms_like), $search_terms);
     /**
      * Filters the SQL used to query for searched users.
      *
      * @since BuddyPress (1.0.0)
      *
      * @param string $value SQL statement for the searched users query.
      */
     $paged_users_sql = apply_filters('bp_core_search_users_sql', $wpdb->prepare("SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", $search_terms_like), $search_terms, $pag_sql);
     $total_users = $wpdb->get_var($total_users_sql);
     $paged_users = $wpdb->get_results($paged_users_sql);
     /***
      * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
      * 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)
      */
     foreach ((array) $paged_users as $user) {
         $user_ids[] = $user->id;
     }
     // Add additional data to the returned results
     if ($populate_extras) {
         $paged_users = BP_Core_User::get_user_extras($paged_users, $user_ids);
     }
     return array('users' => $paged_users, 'total' => $total_users);
 }
Ejemplo n.º 17
0
/**
 * bp_core_get_random_member()
 *
 * Returns the user_id for a user based on their username.
 * 
 * @package BuddyPress Core
 * @param $username str Username to check.
 * @global $wpdb WordPress DB access object.
 * @return false on no match
 * @return int the user ID of the matched user.
 */
function bp_core_get_random_member()
{
    global $bp, $wpdb;
    if ($bp->current_component == BP_MEMBERS_SLUG && isset($_GET['random'])) {
        $user = BP_Core_User::get_random_users(1);
        $ud = get_userdata($user['users'][0]->user_id);
        bp_core_redirect($bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login);
    }
}
Ejemplo n.º 18
0
/**
 * Get a user's friends, in the order in which they joined the site.
 *
 * @see BP_Core_User::get_users() for a description of return value.
 *
 * @param int $user_id ID of the user whose friends are being retreived.
 * @param int $per_page Optional. Number of results to return per page.
 *        Default: 0 (no pagination; show all results).
 * @param int $page Optional. Number of the page of results to return.
 *        Default: 0 (no pagination; show all results).
 * @param string $filter Optional. Limit results to those matching a search
 *        string.
 * @return array See {@link BP_Core_User::get_users()}.
 */
function friends_get_newest($user_id, $per_page = 0, $page = 0, $filter = '')
{
    return apply_filters('friends_get_newest', BP_Core_User::get_users('newest', $per_page, $page, $user_id, $filter));
}
    /**
     * Get the last active date of many users at once.
     *
     * @todo Why is this in the Friends component?
     *
     * @param array $user_ids IDs of users whose last_active meta is
     *                        being queried.
     *
     * @return array $retval Array of last_active values + user_ids.
     */
    public static function get_bulk_last_active($user_ids)
    {
        global $wpdb;
        $last_activities = BP_Core_User::get_last_activity($user_ids);
        // Sort and structure as expected in legacy function
        usort($last_activities, create_function('$a, $b', '
			if ( $a["date_recorded"] == $b["date_recorded"] ) {
				return 0;
			}

			return ( strtotime( $a["date_recorded"] ) < strtotime( $b["date_recorded"] ) ) ? 1 : -1;
		'));
        $retval = array();
        foreach ($last_activities as $last_activity) {
            $u = new stdClass();
            $u->last_activity = $last_activity['date_recorded'];
            $u->user_id = $last_activity['user_id'];
            $retval[] = $u;
        }
        return $retval;
    }
/**
 * Delete last_activity data for the user when the user is deleted.
 *
 * @since 1.0.0
 *
 * @param int $user_id The user ID for the user to delete usermeta for.
 */
function bp_core_remove_data($user_id)
{
    // Remove last_activity data.
    BP_Core_User::delete_last_activity($user_id);
    // Flush the cache to remove the user from all cached objects.
    wp_cache_flush();
}
Ejemplo n.º 21
0
 function search_users($search_terms, $limit = null, $page = 1)
 {
     global $wpdb, $bp;
     if (!function_exists('xprofile_install')) {
         return BP_Core_User::get_active_users($limit, $page);
     }
     if ($limit && $page) {
         $pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * $limit), intval($limit));
     }
     like_escape($search_terms);
     $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 pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC", $search_terms);
     $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 pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql);
     $total_users = $wpdb->get_var($total_users_sql);
     $paged_users = $wpdb->get_results($paged_users_sql);
     return array('users' => $paged_users, 'total' => $total_users);
 }
Ejemplo n.º 22
0
/**
 * bp_dtheme_ajax_messages_autocomplete_results()
 *
 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined
 *
 * @global object object $bp Global BuddyPress settings object
 * @return none
 */
function bp_dtheme_ajax_messages_autocomplete_results()
{
    global $bp;
    // Include everyone in the autocomplete, or just friends?
    if ($bp->messages->slug == $bp->current_component) {
        $autocomplete_all = $bp->messages->autocomplete_all;
    }
    $friends = false;
    $pag_page = 1;
    $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters('bp_autocomplete_max_results', 10);
    // Get the user ids based on the search terms
    if (!empty($autocomplete_all)) {
        $users = BP_Core_User::search_users($_GET['q'], $limit, $pag_page);
        if (!empty($users['users'])) {
            // Build an array with the correct format
            $user_ids = array();
            foreach ($users['users'] as $user) {
                if ($user->id != $bp->loggedin_user->id) {
                    $user_ids[] = $user->id;
                }
            }
            $user_ids = apply_filters('bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit);
        }
    } else {
        if (bp_is_active('friends')) {
            $users = friends_search_friends($_GET['q'], $bp->loggedin_user->id, $limit, 1);
            // Keeping the bp_friends_autocomplete_list filter for backward compatibility
            $users = apply_filters('bp_friends_autocomplete_list', $users, $_GET['q'], $limit);
            if (!empty($users['friends'])) {
                $user_ids = apply_filters('bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit);
            }
        }
    }
    if (!empty($user_ids)) {
        foreach ($user_ids as $user_id) {
            $ud = get_userdata($user_id);
            if (!$ud) {
                continue;
            }
            if (bp_is_username_compatibility_mode()) {
                $username = $ud->user_login;
            } else {
                $username = $ud->user_nicename;
            }
            echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain($user_id) . '"></span>' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15)) . ' &nbsp;' . bp_core_get_user_displayname($user_id) . ' (' . $username . ')
			';
        }
    }
}
Ejemplo n.º 23
0
function bp_core_ajax_widget_members()
{
    global $bp;
    check_ajax_referer('bp_core_widget_members');
    switch ($_POST['filter']) {
        case 'newest-members':
            if (!($users = wp_cache_get('newest_users', 'bp'))) {
                $users = BP_Core_User::get_newest_users($_POST['max-members'], 1);
                wp_cache_set('newest_users', $users, 'bp');
            }
            break;
        case 'recently-active-members':
            if (!($users = wp_cache_get('active_users', 'bp'))) {
                $users = BP_Core_User::get_active_users($_POST['max-members'], 1);
                wp_cache_set('active_users', $users, 'bp');
            }
            break;
        case 'popular-members':
            if (!($users = wp_cache_get('popular_users', 'bp'))) {
                $users = BP_Core_User::get_popular_users($_POST['max-members'], 1);
                wp_cache_set('popular_users', $users, 'bp');
            }
            break;
    }
    if ($users['users']) {
        echo '0[[SPLIT]]';
        // return valid result.
        foreach ((array) $users['users'] as $user) {
            ?>
			<li class="vcard">
				<div class="item-avatar">
					<a href="<?php 
            echo bp_core_get_userlink($user->user_id, false, true);
            ?>
"><?php 
            echo bp_core_get_avatar($user->user_id, 1);
            ?>
</a>
				</div>

				<div class="item">
					<div class="item-title"><?php 
            echo bp_core_get_userlink($user->user_id);
            ?>
</div>
					<div class="item-meta">
						<span class="activity">
							<?php 
            if ('newest-members' == $_POST['filter']) {
                echo bp_core_get_last_activity($user->user_registered, __('registered %s ago', 'buddypress'));
            } else {
                if ('recently-active-members' == $_POST['filter']) {
                    echo bp_core_get_last_activity(get_usermeta($user->user_id, 'last_activity'), __('active %s ago', 'buddypress'));
                } else {
                    if ('popular-members' == $_POST['filter']) {
                        if (1 == get_usermeta($user->user_id, 'total_friend_count')) {
                            echo get_usermeta($user->user_id, 'total_friend_count') . __(' friend', 'buddypress');
                        } else {
                            echo get_usermeta($user->user_id, 'total_friend_count') . __(' friends', 'buddypress');
                        }
                    }
                }
            }
            ?>
						</span>
					</div>
				</div>
			</li>
			<?php 
        }
    } else {
        echo "-1[[SPLIT]]<li>" . __("No members matched the current filter.", 'buddypress');
    }
}