function get_user_label() { if ($this->lifestream->is_buddypress) { return $this->lifestream->get_anchor_html(htmlspecialchars($this->event->owner), htmlspecialchars(bp_core_get_userurl($this->event->owner_id))); } return $this->event->owner; }
/** * 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); }
/** * The shortcode handler for the [show_avatar] shortcode. * * Example: [show_avatar id=pbearne@tycoelectronics.com avatar_size=30 align=right] */ function shortcode_handler($atts, $content = null) { $extraClass = ""; $hrefStart = ""; $name = ""; $bio = ""; $style = ""; $email = ""; $link = ""; $id = ''; // get id or email if (!empty($atts['id'])) { $id = preg_replace('[^\\w\\.\\@\\-]', '', $atts['id']); } if (empty($id) && !empty($atts['email'])) { $id = preg_replace('[^\\w\\.\\@\\-]', '', $atts['email']); } // get avatar size $avatar_size = false; if (!empty($atts['avatar_size'])) { $avatar_size = intval($atts['avatar_size']); } // get alignment if (!empty($atts['align'])) { switch ($atts['align']) { case 'left': $style = "float: left; margin-right: 10px;"; break; case 'right': $style = "float: right; margin-left: 10px;"; break; case 'center': $style = "text-align: center; width: 100%;"; break; } } if (!empty($id)) { $avatar = get_avatar($id, $avatar_size); } else { $avatar = __("[show_author shortcode: please set id/email attribute]"); } // is there an user link request if (!empty($atts['user_link']) || !empty($atts['show_biography']) || !empty($atts['show_postcount']) || !empty($atts['show_name']) || !empty($atts['show_email'])) { // try to fetch user profile $isUser = true; if (!is_numeric($id)) { if (email_exists($id)) { $id = email_exists($id); } else { $isUser = false; } } if ($isUser) { $all_meta_for_user = get_user_meta($id); if (count($all_meta_for_user) == 0) { $isUser = false; } } if ($isUser) { if (!empty($atts['user_link'])) { switch ($atts['user_link']) { case 'authorpage': $link = get_author_posts_url($id); break; case 'website': $link = get_the_author_meta('user_url', $id); if (empty($link) || $link == 'http://') { $link = false; } break; case 'blog': if (AA_is_wpmu()) { $blog = get_active_blog_for_user($id); if (!empty($blog->siteurl)) { $link = $blog->siteurl; } } break; case 'bp_memberpage': if (function_exists('bp_core_get_user_domain')) { $link = bp_core_get_user_domain($id); } elseif (function_exists('bp_core_get_userurl')) { // BP versions < 1.1 $link = bp_core_get_userurl($id); } break; case 'bbpress_memberpage': if (function_exists('bbp_get_user_profile_url')) { $link = bbp_get_user_profile_url($id); } if (empty($link) || $link == 'http://') { $link = false; } break; } if ($link) { $hrefStart = '<a href="' . $link . '">'; } } if (!empty($atts['show_name'])) { $name = '<br />' . get_the_author_meta('display_name', $id); $extraClass .= ' with-name'; } if (!empty($atts['show_email'])) { $userEmail = get_the_author_meta('user_email', $id); $email = "<div class='email'><a href='mailto:" . $userEmail . "''>" . $userEmail . "</a></div>"; if (empty($email)) { $extraClass .= 'email-missing'; } else { $extraClass .= ' with-email'; } } if (!empty($atts['show_postcount'])) { require_once 'UserList.class.php'; $this->userlist = new UserList(); $name .= ' (' . ($postcount = $this->userlist->get_user_postcount($id) . ')'); } if (!empty($atts['show_bbpress_post_count'])) { if (function_exists('bbp_get_user_topic_count_raw')) { $BBPRESS_postcount = bbp_get_user_topic_count_raw($id) + bbp_get_user_reply_count_raw($id); $name .= ' (' . ($postcount = $BBPRESS_postcount . ')'); } } if (!empty($atts['show_biography'])) { $bio = get_the_author_meta('description', $id); if (!empty($atts['show_name'])) { $bio = '<div class="bio">' . $bio . '</div>'; } if (empty($bio)) { $extraClass .= 'biography-missing'; } else { $extraClass .= ' with-biography'; } } } } $hrefend = ''; if (!empty($hrefStart)) { $hrefend = '</a>'; } if (!empty($style)) { $style = ' style="' . $style . '"'; } return '<div class="shortcode-show-avatar ' . $extraClass . '"' . $style . '>' . $hrefStart . $avatar . $name . $hrefend . $bio . $email . '</div>' . $content; }
/** * bp_gameful_format_notifications() * * The format notification function will take DB entries for notifications and format them * so that they can be displayed and read on the screen. * * Notifications are "screen" notifications, that is, they appear on the notifications menu * in the site wide navigation bar. They are not for email notifications. * * * The recording is done by using bp_core_add_notification() which you can search for in this file for * examples of usage. */ function bp_gameful_format_notifications($action, $item_id, $secondary_item_id, $total_items) { global $bp; switch ($action) { case 'level_up': /* In this case, $item_id is the user ID of the user who sent the high five. */ /*** * We don't want a whole list of similar notifications in a users list, so we group them. * If the user has more than one action from the same component, they are counted and the * notification is rendered differently. */ if ((int) $total_items > 1) { return apply_filters('bp_gameful_multiple_level_up_notification', '<a href="' . $bp->loggedin_user->domain . $bp->gameful->slug . '/screen-one/" title="' . __('Multiple Level Ups', 'bp-gameful') . '">' . sprintf(__('%d new level ups!', 'bp-gameful'), (int) $total_items) . '</a>', $total_items); } else { $user_fullname = bp_core_get_user_displayname($item_id, false); $user_url = bp_core_get_userurl($item_id); return apply_filters('bp_gameful_single_level_up_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname . '\'s profile">' . sprintf(__('%s sent you a level up!', 'bp-gameful'), $user_fullname) . '</a>', $user_fullname); } break; } do_action('bp_gameful_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return false; }
/** * Formats the given user as html. * * @param WP_User $user The user to format (object of type WP_User). * * @uses apply_filters() Calls 'aa_user_template' hook * @return String html */ function format_user($user) { $tpl_vars = array('{class}' => '', '{user}' => ''); $avatar_size = intval($this->avatar_size); if (!$avatar_size) { $avatar_size = false; } $name = ""; if ($this->show_name) { $name = $user->display_name; } $alt = $title = $name; $divcss = array('user'); if ($this->show_name) { $divcss[] = 'with-name'; } $link = false; $link_type = $this->user_link; // always use 'website' for commentators $type = isset($user->type) ? $user->type : null; if ($user->user_id == -1 && "guest-author" != $type) { $link_type = 'website'; } switch ($link_type) { case 'authorpage': if ("guest-author" == $type) { $link = get_author_posts_url($user->user_id, $user->user_nicename); } else { $link = get_author_posts_url($user->user_id); } break; case 'website': if ("guest-author" == $type) { $link = get_the_author_meta('url', $user->ID); } else { $link = $user->user_url; if (empty($link) || $link == 'http://') { $link = false; } } break; case 'blog': if (AA_is_wpmu()) { $blog = get_active_blog_for_user($user->user_id); if (!empty($blog->siteurl)) { $link = $blog->siteurl; } } break; case 'bp_memberpage': if (function_exists('bp_core_get_user_domain')) { $link = bp_core_get_user_domain($user->user_id); } elseif (function_exists('bp_core_get_userurl')) { // BP versions < 1.1 $link = bp_core_get_userurl($user->user_id); } break; case 'bbpress_memberpage': if (function_exists('bbp_get_user_profile_url')) { $link = bbp_get_user_profile_url($user->user_id); } if (empty($link) || $link == 'http://') { $link = false; } break; case 'last_post': $recent = get_posts(array('author' => $user->user_id, 'orderby' => 'date', 'order' => 'desc', 'numberposts' => 1)); $link = get_permalink($recent[0]->ID); break; case 'last_post_all': $last_post = get_most_recent_post_of_user($user->user_id); $link = get_permalink($last_post['post_id']); break; } if ($this->show_postcount) { $postcount = 0; if ($user->user_id == -1 && "guest-author" != $type) { $postcount = $this->get_comment_count($user->user_email); $title .= ' (' . sprintf(_n("%d comment", "%d comments", $postcount, 'author-avatars'), $postcount) . ')'; } else { // this is passing 1 for coauthors if ("guest-author" == $type && $user->linked_account) { $linked_user = get_user_by('login', $user->linked_account); // fetch the linked account and show thats count $postcount = $this->get_user_postcount($linked_user->ID); } else { $postcount = $this->get_user_postcount($user->user_id); } $title .= ' (' . sprintf(_n("%d post", "%d posts", $postcount, 'author-avatars'), $postcount) . ')'; } $name .= sprintf(apply_filters('aa_post_count', ' (%d)', $postcount), $postcount); } if ($this->show_bbpress_post_count && AA_is_bbpress()) { $BBPRESS_postcount = 0; if (function_exists('bbp_get_user_topic_count_raw')) { $BBPRESS_postcount = bbp_get_user_topic_count_raw($user->user_id) + bbp_get_user_reply_count_raw($user->user_id); $title .= ' (' . sprintf(_n("%d BBPress post", "%d BBPress posts", $BBPRESS_postcount, 'author-avatars'), $BBPRESS_postcount) . ')'; } $name .= sprintf(' (%d)', $BBPRESS_postcount); } $biography = false; if ($this->show_biography) { if ("guest-author" != $type && $user->user_id > 0) { $biography = get_the_author_meta('description', $user->user_id); } else { $biography = isset($user->description) ? $user->description : ''; } $biography = apply_filters('aa_user_biography_filter', $biography); // trim $biography to bio_length if (0 < $this->bio_length) { $biography = $this->truncate_html(wpautop($biography, true), apply_filters('aa_user_bio_length', $this->bio_length)); } else { $biography = wpautop($biography, true); } $divcss[] = 'with-biography bio-length-' . $this->bio_length; $name = '<strong>' . $name . '</strong>'; if (empty($biography)) { $divcss[] = 'biography-missing'; } } $show_last_post = false; if ($this->show_last_post) { $show_last_post = $this->aa_get_last_post($user->user_id); /** * Filter the users last post. * * @since 1.8.6.0 * * @param string $show_last_post The HTML link to users last post. * @param object The Current user object. */ $show_last_post = apply_filters('aa_user_show_last_post_filter', $show_last_post, $user); $divcss[] = 'with-last-post'; if (empty($show_last_post)) { $divcss[] = 'last-post-missing'; } } $email = false; if ($this->show_email && $user->user_email) { $userEmail = $user->user_email; /** * Filter the title tag content for an admin page. * * @since 1.8.6.0 * * @param string The mailto href for sprintf the $1$s is where the email is inserted. * @param string $userEmail The Email to be inserted. * @param object The Current user object. */ $email = sprintf(apply_filters('aa_user_email_url_template', '<a href="mailto:%1$s">%1$s</a>', $userEmail, $user), $userEmail); $divcss[] = 'with-email'; if (empty($email)) { $divcss[] = 'email-missing'; } } if ($user->user_id == -1) { // use email for commentators $avatar = get_avatar($user->user_email, $avatar_size); } else { // if on buddypress install use BP function if (function_exists('bp_core_fetch_avatar')) { $avatar = bp_core_fetch_avatar(array('item_id' => $user->user_id, 'width' => $avatar_size, 'height' => $avatar_size, 'type' => 'full', 'alt' => $alt, 'title' => $title)); } else { // call the standard avatar function $avatar = get_avatar($user->user_id, $avatar_size); } } /* Strip all existing links (a tags) from the get_avatar() code to * remove e.g. the link which is added by the add-local-avatar plugin * @see http://wordpress.org/support/topic/309878 */ if (!empty($link)) { $avatar = preg_replace('@<\\s*\\/?\\s*[aA]\\s*.*?>@', '', $avatar); } // the buddypress code if (!function_exists('bp_core_fetch_avatar')) { /* strip alt and title parameter */ $avatar = preg_replace('@alt=["\'][\\w]*["\'] ?@', '', $avatar); $avatar = preg_replace('@title=["\'][\\w]*["\'] ?@', '', $avatar); /* insert alt and title parameters */ if (!stripos($avatar, 'title=')) { $avatar = preg_replace('@ ?\\/>@', ' title="' . $title . '" />', $avatar); } if (!stripos($avatar, 'alt=')) { $avatar = preg_replace('@ ?\\/>@', ' alt="' . $alt . '" />', $avatar); } } $html = ''; /** * filter the span that holds the avatar * * @param string The sprintf template. * @param string @title The value passed to the title attr in span. * @param string @avatar The HTML returned from get_avatar() etc. * @param object $user The user object */ $html .= sprintf(apply_filters('aa_user_avatar_template', '<span class="avatar" title="%s">%s</span>', $title, $avatar, $user), $title, $avatar); if ($this->show_name || $this->show_bbpress_post_count || $this->show_postcount) { /** * filter the span that contains the users name * * @param string The sprintf template. * @param string $name The value (users name) passed into the span * @param object $user The user object */ $html .= sprintf(apply_filters('aa_user_name_template', '<span class="name">%s</span>', $name, $user), $name); } if ($link) { /** * filter the href that wrap's avatar and users name * * @param string The sprintf template. * @param string $link The href value. * @param string $title The value for the href title * @param string $html The HTML with avatar and name * @param object $user The user object */ $html = sprintf(apply_filters('aa_user_link_template', '<a href="%s" title="%s">%s</a>', $link, $title, $html, $user), $link, $title, $html); } if ($email) { /** * filter that wrap's the email link in a div * * @param string The sprintf template. * @param string $email The HTML containing the mailto href and email string. * @param object $user The user object */ $html .= sprintf(apply_filters('aa_user_email_template', '<div class="email">%s</div>', $email, $user), $email); } if ($biography) { /** * filter that wrap's the BIO text in a div * * @param string The sprintf template. * @param string $biography The Bio text. * @param object $user The user object */ $html .= sprintf(apply_filters('aa_user_biography_template', '<div class="biography">%s</div>', $biography, $user), $biography); } if ($show_last_post) { /** * filter that wrap's the last post link in a div * * @param string The sprintf template. * @param string $show_last_post The last post link. * @param object $user The user object */ $html .= sprintf(apply_filters('aa_user_last_post_template', '<div class="show_last_post">%s</div>', $show_last_post, $user), $show_last_post); } if (!empty($this->display_extra)) { /** * filter the extra HTML block before its appended * * @param string $extra extra HTML / string. * @param object $user The user object */ $html .= apply_filters('aa_user_display_extra', $this->display_extra, $user); } $tpl_vars['{class}'] = implode($divcss, ' '); /** * filter on the complete HTML for the user * * @param string $html The generated HTML. * @param object $user the user object */ $tpl_vars['{user}'] = apply_filters('aa_user_final_content', $html, $user); /** * filter the outer HTML template * * @param string $html The outer user template. * @param object $user the user object */ return str_replace(array_keys($tpl_vars), $tpl_vars, apply_filters('aa_user_template', $this->user_template, $user)); }
function groups_format_notifications($action, $item_id, $secondary_item_id, $total_items) { global $bp; switch ($action) { case 'new_membership_request': $group_id = $secondary_item_id; $requesting_user_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $group_link = bp_get_group_permalink($group); if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_new_membership_requests_notification', '<a href="' . $group_link . '/admin/membership-requests/" title="' . __('Group Membership Requests', 'buddypress') . '">' . sprintf(__('%d new membership requests for the group "%s"', 'buddypress'), (int) $total_items, $group->name) . '</a>', $group_link, $total_items, $group->name); } else { $user_fullname = bp_core_global_user_fullname($requesting_user_id); return apply_filters('bp_groups_single_new_membership_request_notification', '<a href="' . $group_link . '/admin/membership-requests/" title="' . $user_fullname . ' requests group membership">' . sprintf(__('%s requests membership for the group "%s"', 'buddypress'), $user_fullname, $group->name) . '</a>', $group_link, $user_fullname, $group->name); } break; case 'membership_request_accepted': $group_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $group_link = bp_get_group_permalink($group) . '/?new'; if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_membership_request_accepted_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '" title="' . __('Groups', 'buddypress') . '">' . sprintf(__('%d accepted group membership requests', 'buddypress'), (int) $total_items, $group->name) . '</a>', $total_items, $group_name); } else { return apply_filters('bp_groups_single_membership_request_accepted_notification', '<a href="' . $group_link . '">' . sprintf(__('Membership for group "%s" accepted'), $group->name) . '</a>', $group_link, $group->name); } break; case 'membership_request_rejected': $group_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $group_link = bp_get_group_permalink($group) . '/?new'; if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_membership_request_rejected_notification', '<a href="' . site_url() . '/' . BP_MEMBERS_SLUG . '/' . $bp->groups->slug . '" title="' . __('Groups', 'buddypress') . '">' . sprintf(__('%d rejected group membership requests', 'buddypress'), (int) $total_items, $group->name) . '</a>', $total_items, $group->name); } else { return apply_filters('bp_groups_single_membership_request_rejected_notification', '<a href="' . $group_link . '">' . sprintf(__('Membership for group "%s" rejected'), $group->name) . '</a>', $group_link, $group->name); } break; case 'member_promoted_to_admin': $group_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $group_link = bp_get_group_permalink($group) . '/?new'; if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_member_promoted_to_admin_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '" title="' . __('Groups', 'buddypress') . '">' . sprintf(__('You were promoted to an admin in %d groups', 'buddypress'), (int) $total_items) . '</a>', $total_items); } else { return apply_filters('bp_groups_single_member_promoted_to_admin_notification', '<a href="' . $group_link . '">' . sprintf(__('You were promoted to an admin in the group %s'), $group->name) . '</a>', $group_link, $group->name); } break; case 'member_promoted_to_mod': $group_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $group_link = bp_get_group_permalink($group) . '/?new'; if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_member_promoted_to_mod_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '" title="' . __('Groups', 'buddypress') . '">' . sprintf(__('You were promoted to a mod in %d groups', 'buddypress'), (int) $total_items) . '</a>', $total_items); } else { return apply_filters('bp_groups_single_member_promoted_to_mod_notification', '<a href="' . $group_link . '">' . sprintf(__('You were promoted to a mod in the group %s'), $group->name) . '</a>', $group_link, $group->name); } break; case 'group_invite': $group_id = $item_id; $group = new BP_Groups_Group($group_id, false, false); $user_url = bp_core_get_userurl($user_id); if ((int) $total_items > 1) { return apply_filters('bp_groups_multiple_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites" title="' . __('Group Invites', 'buddypress') . '">' . sprintf(__('You have %d new group invitations', 'buddypress'), (int) $total_items) . '</a>', $total_items); } else { return apply_filters('bp_groups_single_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites" title="' . __('Group Invites', 'buddypress') . '">' . sprintf(__('You have an invitation to the group: %s', 'buddypress'), $group->name) . '</a>', $group->name); } break; } do_action('groups_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return false; }
function friends_format_notifications($action, $item_id, $secondary_item_id, $total_items) { global $bp; switch ($action) { case 'friendship_accepted': if ((int) $total_items > 1) { return apply_filters('bp_friends_multiple_friendship_accepted_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/my-friends/newest" title="' . __('My Friends', 'buddypress') . '">' . sprintf(__('%d friends accepted your friendship requests', 'buddypress'), (int) $total_items) . '</a>', (int) $total_items); } else { $user_fullname = bp_core_global_user_fullname($item_id); $user_url = bp_core_get_userurl($item_id); return apply_filters('bp_friends_single_friendship_accepted_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname . '\'s profile">' . sprintf(__('%s accepted your friendship request', 'buddypress'), $user_fullname) . '</a>', $user_fullname); } break; case 'friendship_request': if ((int) $total_items > 1) { return apply_filters('bp_friends_multiple_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests" title="' . __('Friendship requests', 'buddypress') . '">' . sprintf(__('You have %d pending friendship requests', 'buddypress'), (int) $total_items) . '</a>', $total_items); } else { $user_fullname = bp_core_global_user_fullname($item_id); $user_url = bp_core_get_userurl($item_id); return apply_filters('bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests" title="' . __('Friendship requests', 'buddypress') . '">' . sprintf(__('You have a friendship request from %s', 'buddypress'), $user_fullname) . '</a>', $user_fullname); } break; } do_action('friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return false; }
/** * bp_core_get_userlink() * * Returns a HTML formatted link for a user with the user's full name as the link text. * eg: <a href="http://andy.domain.com/">Andy Peatling</a> * Optional parameters will return just the name, or just the URL, or disable "You" text when * user matches the logged in user. * * [NOTES: This function needs to be cleaned up or split into separate functions] * * @package BuddyPress Core * @param $uid int User ID to check. * @param $no_anchor bool Disable URL and HTML and just return full name. Default false. * @param $just_link bool Disable full name and HTML and just return the URL text. Default false. * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false. * @global $userdata WordPress user data for the current logged in user. * @uses get_userdata() WordPress function to fetch the userdata for a user ID * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID. * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID * @return false on no match * @return str The link text based on passed parameters. */ function bp_core_get_userlink($user_id, $no_anchor = false, $just_link = false, $deprecated = false, $with_s = false) { global $userdata; $ud = get_userdata($user_id); if (!$ud) { return false; } if (function_exists('bp_fetch_user_fullname')) { $display_name = bp_fetch_user_fullname($user_id, false); if ($with_s) { $display_name = sprintf(__("%s's", 'buddypress'), $display_name); } } else { $display_name = $ud->display_name; } // if ( $user_id == $userdata->ID && !$no_you ) // $display_name = 'You'; if ($no_anchor) { return $display_name; } if (!($url = bp_core_get_userurl($user_id))) { return false; } if ($just_link) { return $url; } return '<a href="' . $url . '">' . $display_name . '</a>'; }
/** * The shortcode handler for the [show_avatar] shortcode. * * Example: [show_avatar id=pbearne@tycoelectronics.com avatar_size=30 align=right] */ function shortcode_handler($atts, $content = null) { $extraClass = ''; $hrefStart = ''; $name = ''; $bio = ''; $last_post = ''; $style = ''; $email = ''; $link = ''; $id = ''; // get id or email if (!empty($atts['id'])) { $id = preg_replace('[^\\w\\.\\@\\-]', '', $atts['id']); } if (empty($id) && !empty($atts['email'])) { $id = preg_replace('[^\\w\\.\\@\\-]', '', $atts['email']); } // get avatar size $bio_length = -1; if (!empty($atts['max_bio_length'])) { $bio_length = intval($atts['max_bio_length']); } // get avatar size $avatar_size = false; if (!empty($atts['avatar_size'])) { $avatar_size = intval($atts['avatar_size']); } // get alignment if (!empty($atts['align'])) { switch ($atts['align']) { case 'left': $style = "float: left; margin-right: 10px;"; break; case 'right': $style = "float: right; margin-left: 10px;"; break; case 'center': $style = "text-align: center; width: 100%;"; break; } } if (!empty($id)) { $avatar = get_avatar($id, $avatar_size); } else { $avatar = __("[show_author shortcode: please set id/email attribute]"); } // is there an user link request if (!empty($atts['user_link']) || !empty($atts['show_biography']) || !empty($atts['show_postcount']) || !empty($atts['show_name']) || !empty($atts['show_email'])) { // try to fetch user profile $isUser = true; if (!is_numeric($id)) { if (email_exists($id)) { $id = email_exists($id); } else { $isUser = false; } } if ($isUser) { $all_meta_for_user = get_user_meta($id); if (count($all_meta_for_user) == 0) { $isUser = false; } } if ($isUser) { if (!empty($atts['user_link'])) { switch ($atts['user_link']) { case 'authorpage': $link = get_author_posts_url($id); break; case 'website': $link = get_the_author_meta('user_url', $id); if (empty($link) || $link == 'http://') { $link = false; } break; case 'blog': if (AA_is_wpmu()) { $blog = get_active_blog_for_user($id); if (!empty($blog->siteurl)) { $link = $blog->siteurl; } } break; case 'bp_memberpage': if (function_exists('bp_core_get_user_domain')) { $link = bp_core_get_user_domain($id); } elseif (function_exists('bp_core_get_userurl')) { // BP versions < 1.1 $link = bp_core_get_userurl($id); } break; case 'bbpress_memberpage': if (function_exists('bbp_get_user_profile_url')) { $link = bbp_get_user_profile_url($id); } if (empty($link) || $link == 'http://') { $link = false; } break; case 'last_post': $recent = get_posts(array('author' => $id, 'orderby' => 'date', 'order' => 'desc', 'numberposts' => 1)); $link = get_permalink($recent[0]->ID); break; case 'last_post_filtered': $recent = get_posts(array('author' => $id, 'orderby' => 'date', 'order' => 'desc', 'numberposts' => 1)); $link = get_permalink($recent[0]->ID); break; case 'last_post_all': $last_post = get_most_recent_post_of_user($id); $link = get_permalink($last_post['post_id']); break; } if ($link) { $hrefStart = '<a href="' . $link . '">'; } } if (!empty($atts['show_name'])) { $name = '<br />' . get_the_author_meta('display_name', $id); $extraClass .= ' with-name'; } if (!empty($atts['show_email'])) { $userEmail = get_the_author_meta('user_email', $id); $email = "<div class='email'><a href='mailto:" . $userEmail . "''>" . $userEmail . "</a></div>"; if (empty($email)) { $extraClass .= 'email-missing'; } else { $extraClass .= ' with-email'; } } if (!empty($atts['show_postcount'])) { $name .= ' (' . ($postcount = $this->userlist->get_user_postcount($id) . ')'); } if (!empty($atts['show_bbpress_post_count'])) { if (function_exists('bbp_get_user_topic_count_raw')) { $BBPRESS_postcount = bbp_get_user_topic_count_raw($id) + bbp_get_user_reply_count_raw($id); $name .= ' (' . ($postcount = $BBPRESS_postcount . ')'); } } if (!empty($atts['show_biography'])) { $biography = get_the_author_meta('description', $id); if (0 < $bio_length) { $biography = $this->userlist->truncate_html(wpautop($biography, true), apply_filters('aa_user_bio_length', $bio_length)); } else { $biography = wpautop($biography, true); } if (!empty($atts['show_name'])) { $bio = '<div class="bio bio-length-' . $atts['max_bio_length'] . '">' . $biography . '</div>'; } if (empty($bio)) { $extraClass .= ' biography-missing'; } else { $extraClass .= ' with-biography bio-length-' . $bio_length; } } // show last_post? if (isset($atts['show_last_post']) && strlen($atts['show_last_post']) > 0) { $last_post = '<div class="last_post">' . $this->userlist->aa_get_last_post($id) . '</div>'; if (empty($last_post)) { $extraClass .= ' last-post-missing'; } else { $extraClass .= ' with-last-post'; } } } } $hrefend = ''; if (!empty($hrefStart)) { $hrefend = '</a>'; } if (!empty($style)) { $style = ' style="' . $style . '"'; } return '<div class="shortcode-show-avatar ' . $extraClass . '"' . $style . '>' . $hrefStart . $avatar . $name . $last_post . $hrefend . $bio . $email . '</div>' . $content; }
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_random_users($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_userurl($user_ids['users'][$i]->user_id); ?> "><?php echo bp_core_get_avatar($user_ids['users'][$i]->user_id, 1); ?> </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 } }
/** * Formats the given user as html. * * @param WP_User $user The user to format (object of type WP_User). * * @uses apply_filters() Calls 'aa_user_template' hook * @return String html */ function format_user($user) { $tpl_vars = array('{class}' => '', '{user}' => ''); $avatar_size = intval($this->avatar_size); if (!$avatar_size) { $avatar_size = false; } $name = ""; if ($this->show_name) { $name = $user->display_name; } $alt = $title = $name; $divcss = array('user'); if ($this->show_name) { $divcss[] = 'with-name'; } $link = false; $link_type = $this->user_link; // always use 'website' for commentators $type = isset($user->type) ? $user->type : null; if ($user->user_id == -1 && "guest-author" != $type) { $link_type = 'website'; } switch ($link_type) { case 'authorpage': if ("guest-author" == $type) { $link = get_author_posts_url($user->user_id, $user->user_nicename); } else { $link = get_author_posts_url($user->user_id); } break; case 'website': if ("guest-author" == $type) { $link = get_the_author_meta('url', $user->ID); } else { $link = $user->user_url; if (empty($link) || $link == 'http://') { $link = false; } } break; case 'blog': if (AA_is_wpmu()) { $blog = get_active_blog_for_user($user->user_id); if (!empty($blog->siteurl)) { $link = $blog->siteurl; } } break; case 'bp_memberpage': if (function_exists('bp_core_get_user_domain')) { $link = bp_core_get_user_domain($user->user_id); } elseif (function_exists('bp_core_get_userurl')) { // BP versions < 1.1 $link = bp_core_get_userurl($user->user_id); } break; case 'bbpress_memberpage': if (function_exists('bbp_get_user_profile_url')) { $link = bbp_get_user_profile_url($user->user_id); } if (empty($link) || $link == 'http://') { $link = false; } break; } if ($this->show_postcount) { $postcount = 0; if ($user->user_id == -1 && "guest-author" != $type) { $postcount = $this->get_comment_count($user->user_email); $title .= ' (' . sprintf(_n("%d comment", "%d comments", $postcount, 'author-avatars'), $postcount) . ')'; } else { // this is passing 1 for coauthors if ("guest-author" == $type && $user->linked_account) { $linked_user = get_user_by('login', $user->linked_account); // fetch the linked account and show thats count $postcount = $this->get_user_postcount($linked_user->ID); } else { $postcount = $this->get_user_postcount($user->user_id); } $title .= ' (' . sprintf(_n("%d post", "%d posts", $postcount, 'author-avatars'), $postcount) . ')'; } $name .= sprintf(' (%d)', $postcount); } if ($this->show_bbpress_post_count && AA_is_bbpress()) { $BBPRESS_postcount = 0; if (function_exists('bbp_get_user_topic_count_raw')) { $BBPRESS_postcount = bbp_get_user_topic_count_raw($user->user_id) + bbp_get_user_reply_count_raw($user->user_id); $title .= ' (' . sprintf(_n("%d BBPress post", "%d BBPress posts", $BBPRESS_postcount, 'author-avatars'), $BBPRESS_postcount) . ')'; } $name .= sprintf(' (%d)', $BBPRESS_postcount); } $biography = false; if ($this->show_biography) { if ("guest-author" != $type && $user->user_id > 0) { $biography = get_the_author_meta('description', $user->user_id); } else { $biography = isset($user->description) ? $user->description : ''; } $biography = apply_filters('aa_user_biography_filter', $biography); $divcss[] = 'with-biography'; $name = '<strong>' . $name . '</strong>'; if (empty($biography)) { $divcss[] = 'biography-missing'; } } $email = false; if ($this->show_email && $user->user_email) { $userEmail = $user->user_email; $email = "<a href='mailto:" . $userEmail . "''>" . $userEmail . "</a>"; $divcss[] = 'with-email'; if (empty($email)) { $divcss[] = 'email-missing'; } } if ($user->user_id == -1) { // use email for commentators $avatar = get_avatar($user->user_email, $avatar_size); } else { if (function_exists('bp_core_fetch_avatar')) { $avatar = bp_core_fetch_avatar(array('item_id' => $user->user_id, 'width' => $avatar_size, 'height' => $avatar_size, 'type' => 'full', 'alt' => $alt, 'title' => $title)); } else { $avatar = get_avatar($user->user_id, $avatar_size); } } /* Strip all existing links (a tags) from the get_avatar() code to * remove e.g. the link which is added by the add-local-avatar plugin * @see http://wordpress.org/support/topic/309878 */ if (!empty($link)) { $avatar = preg_replace('@<\\s*\\/?\\s*[aA]\\s*.*?>@', '', $avatar); } if (!function_exists('bp_core_fetch_avatar')) { /* strip alt and title parameter */ $avatar = preg_replace('@alt=["\'][\\w]*["\'] ?@', '', $avatar); $avatar = preg_replace('@title=["\'][\\w]*["\'] ?@', '', $avatar); /* insert alt and title parameters */ if (!stripos($avatar, 'title=')) { $avatar = preg_replace('@ ?\\/>@', ' title="' . $title . '" />', $avatar); } if (!stripos($avatar, 'alt=')) { $avatar = preg_replace('@ ?\\/>@', ' alt="' . $alt . '" />', $avatar); } } $html = ''; $html .= sprintf(apply_filters('aa_user_avatar_template', '<span class="avatar" title="%s">%s</span>', $title, $avatar), $title, $avatar); if ($this->show_name || $this->show_bbpress_post_count || $this->show_postcount) { $html .= sprintf(apply_filters('aa_user_name_template', '<span class="name">%s</span>', $name), $name); } if ($link) { $html = sprintf(apply_filters('aa_user_link_template', '<a href="%s" title="%s">%s</a>', $link, $title, $html), $link, $title, $html); } if ($email) { $html .= sprintf(apply_filters('aa_user_email_template', '<div class="email">%s</div>', $email), $email); } if ($biography) { $html .= sprintf(apply_filters('aa_user_biography_template', '<div class="biography">%s</div>', $biography), $biography); } $tpl_vars['{class}'] = implode($divcss, ' '); $tpl_vars['{user}'] = apply_filters('aa_user_final_content', $html, $user); return str_replace(array_keys($tpl_vars), $tpl_vars, apply_filters('aa_user_template', $this->user_template, $user)); }
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 }