/** * Renders the "user_link" dropdown * * @param mixed $values the field values * @param string $name the field name * * @return string */ function renderFieldUserLink($values = array(), $name = 'user_link') { $user_link_options = array('' => '-', 'authorpage' => __('Author Page', 'author-avatars'), 'website' => __('Website', 'author-avatars')); if (AA_is_bp()) { $user_link_options['bp_memberpage'] = __('BP Member Page', 'author-avatars'); } if (AA_is_wpmu()) { $user_link_options['blog'] = __('Blog', 'author-avatars'); } if (AA_is_bbpress()) { $user_link_options['bbpress_memberpage'] = __('BBpress Member Page', 'author-avatars'); } $attributes = array('id' => $this->_getFieldId($name), 'label' => __('Link users to', 'author-avatars') . ': '); $name = $this->_getFieldName($name); return '<p>' . FormHelper::choice($name, $user_link_options, $values, $attributes) . '</p>'; }
/** * 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)); }
/** * 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)); }