' . __( 'No users found.', 'author-avatars' ) . '
' );
} elseif ( ! empty( $this->group_by ) ) {
return $this->format_groups( $this->page_users( $users ) );
} else {
return $this->format_users( $this->page_users( $users ) );
}
}
/**
* Formats a grouped list of users
*
* @param array $groups Array of an array of users. The array keys are used to retrieve the group name (see _group_name())
*
* @uses apply_filters() Calls 'aa_userlist_group_wrapper_template' hook
* @uses apply_filters() Calls 'aa_userlist_group_template' hook
* @return String the html formatted list of grouped users
*/
function format_groups( $groups ) {
$html = '';
foreach ( $groups as $id => $group_users ) {
$tpl_vars = array(
'{name}' => $this->_group_name( $id ),
'{group}' => $this->format_users( $group_users ),
);
$html .= str_replace( array_keys( $tpl_vars ), $tpl_vars, apply_filters( 'aa_userlist_group_template', $this->group_template ) );
}
return str_replace( '{groups}', $html, apply_filters( 'aa_userlist_group_wrapper_template', $this->group_wrapper_template ) );
}
/**
* Formats a list of users
*
* @param $users array An array of users.
*
* @uses apply_filters() Calls 'aa_userlist_template' hook
* @return mixed | String the html formatted list of users
*/
function format_users( $users ) {
$html = '';
foreach ( $users as $user ) {
$html .= $this->format_user( $user );
}
return str_replace( '{users}', $html, apply_filters( 'aa_userlist_template', $this->userlist_template ) );
}
/**
* pages the list of users
*
* @param $users array $groups An array of users.
*
* @return array list of users
*/
function page_users( $users ) {
if ( empty( $this->page_size ) ) {
return $users;
}
$this->setup_page_users_ajax();
$page_size = $this->page_size;
if ( $this->aa_page > 0 ) {
$offset = $this->aa_page * $page_size;
// so we can't try to slice more than the array test offset is not more than array length
// and is show the last page posiable
if ( $offset >= count( $users ) ) {
$offset = count( $users ) - $page_size;
}
} else {
$offset = 0;
}
$this->pagingHTML = '';
return array_slice( $users, $offset, $page_size );
}
/**
* Ajax to update pages the list of users
*
*
* @return void
*/
function setup_page_users_ajax() {
// create axjax calls
wp_register_script( 'author-avatars-shortcode-paging', plugins_url( '../js/AuthorAvatarsShortcode.paging.ajax.js', __FILE__ ), array( 'jquery-ui-core' ), '', true );
// pass values to JS
$params = array(
'hiddenusers' => $this->hiddenusers,
'whitelistusers' => $this->whitelistusers,
'blogs' => $this->blogs,
'roles' => $this->roles,
'group_by' => $this->group_by,
'user_link' => $this->user_link,
'show_name' => $this->show_name,
'show_nickname' => $this->show_nickname,
'show_postcount' => $this->show_postcount,
'show_bbpress_post_count' => $this->show_bbpress_post_count,
'show_biography' => $this->show_biography,
'bio_length' => $this->bio_length,
'show_last_post' => $this->show_last_post,
'show_email' => $this->show_email,
'contact_links' => $this->contact_links,
'avatar_size' => $this->avatar_size,
'limit' => $this->limit,
'min_post_count' => $this->min_post_count,
'page_size' => $this->page_size,
'order' => $this->order,
'sort_direction' => $this->sort_direction,
'postCommentNonce' => wp_create_nonce( 'author-avatars-shortcode-paging-nonce' ),
'action' => 'AA_shortcode_paging',
'aa_page' => 0,
'ajax_url' => admin_url( 'admin-ajax.php' ),
);
wp_enqueue_script( 'author-avatars-shortcode-paging' );
wp_localize_script( 'author-avatars-shortcode-paging', 'shortCodeValues', $params );
}
/**
* Formats the given user as html.
*
* @param $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 = '';
$divcss = array( 'user' );
if ( $this->show_name ) {
$name = $user->display_name;
$divcss[] = 'with-name';
$divcss = apply_filters( 'aa_show_name_css', $divcss, $user->display_name );
}
if ( $this->show_nickname ) {
$nickname = get_the_author_meta( 'nickname', $user->user_id );
$divcss[] = 'nickname-group-' . strtolower( substr( $nickname, 0, 1 ) );
if( $this->show_name ) {
$nickname = sprintf( apply_filters( 'AA_nickname_with_name_wrap', ' (%s)' ), $nickname );
}
$name .= $nickname;
$divcss[] = 'with-nickname';
}
$alt = $title = $name;
$link = false;
$link_types = explode( ',', $this->user_link );
foreach ( $link_types as $link_type ) {
// always use 'website' for commentators
$type = ( isset( $user->type ) ) ? $user->type : null;
if ( - 1 === $user->user_id && 'guest-author' != $type ) {
$link_type = 'website';
$divcss[] = 'user-0';
} else {
if ( 'guest-author' === $type ) {
$divcss[] = 'guest-author-' . $user->user_id;
} else {
$divcss[] = 'user-' . $user->user_id;
}
}
switch ( $link_type ) {
case 'website':
if ( 'guest-author' === $type ) {
$link = get_the_author_meta( 'url', $user->user_id );
} else {
$link = $user->user_url;
if ( empty( $link ) || 'http://' === $link ) {
$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 'um_profile':
if ( function_exists( 'um_user_profile_url' ) ) {
um_fetch_user( $user->user_id );
$link = um_user_profile_url();
um_reset_user();
}
if ( empty( $link ) || 'http://' === $link ) {
$link = false;
}
break;
case 'bbpress_memberpage':
if ( function_exists( 'bbp_get_user_profile_url' ) ) {
$link = bbp_get_user_profile_url( $user->user_id );
}
if ( empty( $link ) || 'http://' === $link ) {
$link = false;
}
break;
case 'last_post':
$recent = get_posts( array(
'author' => $user->user_id,
'orderby' => 'date',
'order' => 'desc',
'numberposts' => 1,
) );
if ( ! empty( $recent ) ) {
$link = get_permalink( $recent[0]->ID );
break;
}
// fall throught if no last post to author page
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 'last_post_all':
$last_post = get_most_recent_post_of_user( $user->user_id );
$link = get_permalink( $last_post['post_id'] );
break;
default:
$maybe_link = get_the_author_meta( $link_type, $user->user_id );
if ( '' !== $maybe_link && is_valid_url( $maybe_link ) ) {
$link = esc_url_raw( $maybe_link );
}
}
//exit look if we have a link
if ( false !== $link ) {
break;
}
}
if ( $this->show_postcount ) {
if ( - 1 == $user->user_id && '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', '