/** * populate() * * Populate the instantiated class with data based on the User ID provided. * * @package BuddyPress Core * @global $userdata WordPress user data for the current logged in user. * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text * @uses bp_core_get_user_email() Returns the email address for the user based on user ID * @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date for a user. */ function populate() { if ( function_exists( 'xprofile_install' ) ) $this->profile_data = $this->get_profile_data(); if ( $this->profile_data ) { $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] ); $this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] ); $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>"; $this->email = esc_attr( $this->profile_data['user_email'] ); } else { $this->user_url = bp_core_get_user_domain( $this->id ); $this->user_link = bp_core_get_userlink( $this->id ); $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) ); $this->email = esc_attr( bp_core_get_user_email( $this->id ) ); } /* Cache a few things that are fetched often */ wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' ); wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' ); wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' ); $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) ); $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) ); $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ); $this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) ); }
/** * populate() * * Populate the instantiated class with data based on the User ID provided. * * @package BuddyPress Core * @global $userdata WordPress user data for the current logged in user. * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text * @uses bp_core_get_user_email() Returns the email address for the user based on user ID * @uses get_usermeta() WordPress function returns the value of passed usermeta name from usermeta table * @uses bp_core_get_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date for a user. */ function populate() { $this->user_url = bp_core_get_userurl($this->id); $this->user_link = bp_core_get_userlink($this->id); $this->fullname = bp_fetch_user_fullname($this->id, false); $this->email = bp_core_get_user_email($this->id); $this->last_active = bp_core_get_last_activity(get_usermeta($this->id, 'last_activity'), __('active %s ago', 'buddypress')); $this->avatar = bp_core_get_avatar($this->id, 2); $this->avatar_thumb = bp_core_get_avatar($this->id, 1); $this->avatar_mini = bp_core_get_avatar($this->id, 1, 25, 25, false); }
/** * @group bp_get_blog_last_active */ public function test_bp_get_blog_last_active_active_format_true() { // Fake the global global $blogs_template; $time = date('Y-m-d h:i:s', time() - 24 * 60 * 60); $blogs_template = new stdClass(); $blogs_template->blog = new stdClass(); $blogs_template->blog->last_activity = $time; $this->assertEquals(bp_core_get_last_activity($time, __('active %s', 'buddypress')), bp_get_blog_last_active(array('active_format' => true))); $blogs_template->blog = null; }
function bp_get_group_member_joined_since() { global $members_template; return apply_filters('bp_get_group_member_joined_since', bp_core_get_last_activity($members_template->member->date_modified, __('joined %s', 'buddypress'))); }
/** * Get the "active [x days ago]" string for a user. * * @param int $user_id ID of the user. Default: displayed user ID. * @return string */ function bp_get_last_activity($user_id = 0) { if (empty($user_id)) { $user_id = bp_displayed_user_id(); } $last_activity = bp_core_get_last_activity(bp_get_user_last_activity($user_id), __('active %s', 'buddypress')); /** * Filters the 'active [x days ago]' string for a user. * * @since 1.5.0 * * @param string $value Formatted 'active [x days ago]' string. */ return apply_filters('bp_get_last_activity', $last_activity); }
/** * Populate the instantiated class with data based on the User ID provided. * * @uses bp_core_get_userurl() Returns the URL with no HTML markup for * a user based on their user id. * @uses bp_core_get_userlink() Returns a HTML formatted link for a * user with the user's full name as the link text. * @uses bp_core_get_user_email() Returns the email address for the * user based on user ID. * @uses bp_get_user_meta() BP function returns the value of passed * usermeta name from usermeta table. * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date * for a user. */ public function populate() { if (bp_is_active('xprofile')) { $this->profile_data = $this->get_profile_data(); } if (!empty($this->profile_data)) { $full_name_field_name = bp_xprofile_fullname_field_name(); $this->user_url = bp_core_get_user_domain($this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login']); $this->fullname = esc_attr($this->profile_data[$full_name_field_name]['field_data']); $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>"; $this->email = esc_attr($this->profile_data['user_email']); } else { $this->user_url = bp_core_get_user_domain($this->id); $this->user_link = bp_core_get_userlink($this->id); $this->fullname = esc_attr(bp_core_get_user_displayname($this->id)); $this->email = esc_attr(bp_core_get_user_email($this->id)); } // Cache a few things that are fetched often wp_cache_set('bp_user_fullname_' . $this->id, $this->fullname, 'bp'); wp_cache_set('bp_user_email_' . $this->id, $this->email, 'bp'); wp_cache_set('bp_user_url_' . $this->id, $this->user_url, 'bp'); $this->avatar = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'full', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->fullname))); $this->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->fullname))); $this->avatar_mini = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->fullname), 'width' => 30, 'height' => 30)); $this->last_active = bp_core_get_last_activity(bp_get_user_last_activity($this->id), __('active %s', 'buddypress')); }
/** * Return the last active date of the current blog in the loop. * * @param array $args { * Array of optional arguments. * @type bool $active_format If true, formatted "Active 5 minutes ago". * If false, formatted "5 minutes ago". * Default: true. * } * @return string Last active date. */ function bp_get_blog_last_active($args = array()) { global $blogs_template; // Parse the activity format $r = bp_parse_args($args, array('active_format' => true)); // Backwards compatibility for anyone forcing a 'true' active_format if (true === $r['active_format']) { $r['active_format'] = __('active %s', 'buddypress'); } // Blog has been posted to at least once if (isset($blogs_template->blog->last_activity)) { // Backwards compatibility for pre 1.5 'ago' strings $last_activity = !empty($r['active_format']) ? bp_core_get_last_activity($blogs_template->blog->last_activity, $r['active_format']) : bp_core_time_since($blogs_template->blog->last_activity); // Blog has never been posted to } else { $last_activity = __('Never active', 'buddypress'); } /** * Filters the last active date of the current blog in the loop. * * @since * * @param string $last_activity Last active date. * @param array $r Array of parsed args used to determine formatting. */ return apply_filters('bp_blog_last_active', $last_activity, $r); }
function bp_get_last_activity($user_id = 0) { global $bp; if (empty($user_id)) { $user_id = $bp->displayed_user->id; } $last_activity = bp_core_get_last_activity(bp_get_user_meta($user_id, 'last_activity', true), __('active %s', 'buddypress')); return apply_filters('bp_get_last_activity', $last_activity); }
function bp_get_the_site_blog_last_active() { global $site_blogs_template; return apply_filters('bp_the_site_blog_last_active', bp_core_get_last_activity(bp_blogs_get_blogmeta($site_blogs_template->blog->blog_id, 'last_activity'), __('active %s ago', 'buddypress'))); }
/** * @since 1.0.0 * * @return mixed|void */ function bp_get_group_member_joined_since() { global $members_template; /** * Filters the joined since time for the current member in the loop. * * @since 1.0.0 * * @param string $value Joined since time. */ return apply_filters('bp_get_group_member_joined_since', bp_core_get_last_activity($members_template->member->date_modified, __('joined %s', 'buddypress'))); }
function groups_ajax_widget_groups_list() { global $bp; check_ajax_referer('groups_widget_groups_list'); switch ($_POST['filter']) { case 'newest-groups': if (!($groups = wp_cache_get('newest_groups', 'bp'))) { $groups = groups_get_newest($_POST['max-groups'], 1); wp_cache_set('newest_groups', $groups, 'bp'); } break; case 'recently-active-groups': if (!($groups = wp_cache_get('active_groups', 'bp'))) { $groups = groups_get_active($_POST['max-groups'], 1); wp_cache_set('active_groups', $groups, 'bp'); } break; case 'popular-groups': if (!($groups = wp_cache_get('popular_groups', 'bp'))) { $groups = groups_get_popular($_POST['max-groups'], 1); wp_cache_set('popular_groups', $groups, 'bp'); } break; } if ($groups['groups']) { echo '0[[SPLIT]]'; // return valid result. foreach ((array) $groups['groups'] as $group_id) { if (!($group = wp_cache_get('groups_group_nouserdata_' . $group_id->group_id, 'bp'))) { $group = new BP_Groups_Group($group_id->group_id, false, false); wp_cache_set('groups_group_nouserdata_' . $group_id->group_id, $group, 'bp'); } ?> <li> <div class="item-avatar"> <?php echo bp_get_group_avatar_thumb($group); ?> </div> <div class="item"> <div class="item-title"><a href="<?php echo bp_get_group_permalink($group); ?> " title="<?php echo bp_get_group_name($group); ?> "><?php echo bp_get_group_name($group); ?> </a></div> <div class="item-meta"> <span class="activity"> <?php if ('newest-groups' == $_POST['filter']) { echo bp_core_get_last_activity($group->date_created, __('created %s ago', 'buddypress')); } else { if ('recently-active-groups' == $_POST['filter']) { echo bp_core_get_last_activity(groups_get_groupmeta($group->id, 'last_activity'), __('active %s ago', 'buddypress')); } else { if ('popular-groups' == $_POST['filter']) { if ($group->total_member_count == 1) { echo $group->total_member_count . __(' member', 'buddypress'); } else { echo $group->total_member_count . __(' members', 'buddypress'); } } } } ?> </span> </div> </div> </li> <?php } } else { echo "-1[[SPLIT]]<li>" . __("No groups matched the current filter.", 'buddypress'); } }
/** * Get the "active [x days ago]" string for a user. * * @param int $user_id ID of the user. Default: displayed user ID. * @return string */ function bp_get_last_activity($user_id = 0) { if (empty($user_id)) { $user_id = bp_displayed_user_id(); } $last_activity = bp_core_get_last_activity(bp_get_user_last_activity($user_id), __('active %s', 'buddypress')); return apply_filters('bp_get_last_activity', $last_activity); }
/** * Return the last active date of the current blog in the loop. * * @param array $args { * Array of optional arguments. * @type bool $active_format If true, formatted "Active 5 minutes * ago". If false, formatted "5 minutes ago". Default: true. * } * @return string Last active date. */ function bp_get_blog_last_active($args = array()) { global $blogs_template; // Parse the activity format $r = bp_parse_args($args, array('active_format' => true)); // Backwards compatibilty for anyone forcing a 'true' active_format if (true === $r['active_format']) { $r['active_format'] = __('active %s', 'buddypress'); } // Blog has been posted to at least once if (isset($blogs_template->blog->last_activity)) { // Backwards compatibility for pre 1.5 'ago' strings $last_activity = !empty($r['active_format']) ? bp_core_get_last_activity($blogs_template->blog->last_activity, $r['active_format']) : bp_core_time_since($blogs_template->blog->last_activity); // Blog has never been posted to } else { $last_activity = __('Never active', 'buddypress'); } return apply_filters('bp_blog_last_active', $last_activity, $r); }
function bp_core_widget_members($args) { global $current_blog, $bp; extract($args); $options = get_blog_option($current_blog->blog_id, 'bp_core_widget_members'); ?> <?php echo $before_widget; ?> <?php echo $before_title . $widget_name . $after_title; ?> <?php if (!($users = wp_cache_get('newest_users', 'bp'))) { $users = BP_Core_User::get_newest_users($options['max_members']); wp_cache_set('newest_users', $users, 'bp'); } ?> <?php if ($users['users']) { ?> <div class="item-options" id="members-list-options"> <img id="ajax-loader-members" src="<?php echo $bp->core->image_base; ?> /ajax-loader.gif" height="7" alt="<?php _e('Loading', 'buddypress'); ?> " style="display: none;" /> <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG; ?> " id="newest-members" class="selected"><?php _e('Newest', 'buddypress'); ?> </a> | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG; ?> " id="recently-active-members"><?php _e('Active', 'buddypress'); ?> </a> | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG; ?> " id="popular-members"><?php _e('Popular', 'buddypress'); ?> </a> </div> <ul id="members-list" class="item-list"> <?php 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 fn"><?php echo bp_core_get_userlink($user->user_id); ?> </div> <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity($user->user_registered, __('registered %s ago', 'buddypress')); ?> </span></div> </div> </li> <?php $counter++; ?> <?php } ?> </ul> <?php if (function_exists('wp_nonce_field')) { wp_nonce_field('bp_core_widget_members', '_wpnonce-members'); } ?> <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo attribute_escape($options['max_members']); ?> " /> <?php } else { ?> <div class="widget-error"> <?php _e('No one has signed up yet!', 'buddypress'); ?> </div> <?php } ?> <?php echo $after_widget; }
function bp_last_activity($user_id = false, $echo = true) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id; } $last_activity = bp_core_get_last_activity(get_usermeta($user_id, 'last_activity'), __('active %s ago', 'buddypress')); if ($echo) { echo apply_filters('bp_last_activity', $last_activity); } else { return apply_filters('bp_last_activity', $last_activity); } }
function bp_get_blog_last_active() { global $blogs_template; return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s ago', 'buddypress' ) ) ); }
/** * Return the joined date for the current member in the group member loop. * * @since 1.0.0 * @since 2.7.0 Added $args as a parameter. * * @param array|string $args { * Array of optional parameters. * * @type bool $relative Optional. If true, returns relative joined date. eg. joined 5 months ago. * If false, returns joined date value from database. Default: true. * } * @return string */ function bp_get_group_member_joined_since($args = array()) { global $members_template; $r = wp_parse_args($args, array('relative' => true)); // We do not want relative time, so return now. // @todo Should the 'bp_get_group_member_joined_since' filter be applied here? if (!$r['relative']) { return esc_attr($members_template->member->date_modified); } /** * Filters the joined since time for the current member in the loop. * * @since 1.0.0 * * @param string $value Joined since time. */ return apply_filters('bp_get_group_member_joined_since', bp_core_get_last_activity($members_template->member->date_modified, __('joined %s', 'buddypress'))); }
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'); } }
function the_invite() { global $group_id; $this->in_the_loop = true; $user_id = $this->next_invite(); $this->invite = new stdClass(); $this->invite->user = $this->invite_data[$user_id]; // This method previously populated the user object with // BP_Core_User. We manually configure BP_Core_User data for // backward compatibility. if (bp_is_active('xprofile')) { $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30)); $this->invite->user->email = $this->invite->user->user_email; $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login); $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress')); if (bp_is_active('groups')) { $total_groups = BP_Groups_Member::total_group_count($user_id); $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } $this->invite->user->total_blogs = null; $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() if (0 == $this->current_invite) { // loop has just started do_action('loop_start'); } }
/** * Sets up the invite to show. * * @since 1.1.0 */ public function the_invite() { global $group_id; $this->in_the_loop = true; $user_id = $this->next_invite(); $this->invite = new stdClass(); $this->invite->user = $this->invite_data[$user_id]; // This method previously populated the user object with // BP_Core_User. We manually configure BP_Core_User data for // backward compatibility. if (bp_is_active('xprofile')) { $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30)); $this->invite->user->email = $this->invite->user->user_email; $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login); $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress')); if (bp_is_active('groups')) { $total_groups = BP_Groups_Member::total_group_count($user_id); $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } $this->invite->user->total_blogs = null; // Global'ed in bp_group_has_invites() $this->invite->group_id = $group_id; // loop has just started if (0 == $this->current_invite) { /** * Fires if the current invite item is the first in the loop. * * @since 1.1.0 * @since 2.3.0 `$this` parameter added. * @since 2.7.0 Action renamed from `loop_start`. * * @param BP_Groups_Invite_Template $this Instance of the current Invites template. */ do_action('group_invitation_loop_start', $this); } }