/**
  * Constructor
  */
 function AuthorAvatarsSitewideAdminPanel()
 {
     // only init on wpmu sites...
     if (AA_is_wpmu()) {
         $this->init();
     }
 }
 /**
  * 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;
 }
 /**
  * Builds the html body for the tinymce popup
  *
  * @access private
  * @return string Popup body
  */
 function render_tinymce_popup_body()
 {
     require_once 'AuthorAvatarsForm.class.php';
     $form = new AuthorAvatarsForm();
     // BASIC TAB
     $basic_left = $form->renderFieldShortcodeType();
     $basic_left .= '<div class="fields_type_show_avatar">';
     $basic_left .= $form->renderFieldUsers();
     $basic_left .= $form->renderFieldEmail();
     $basic_left .= $form->renderFieldAlignment();
     $basic_left .= $form->renderFieldDisplayOptions();
     $basic_left .= $form->renderFieldUserLink('');
     $basic_left .= '</div>';
     $basic_left .= '<div class="fields_type_authoravatars">';
     $basic_left .= $form->renderFieldRoles(array('administrator', 'editor'));
     $basic_left .= $form->renderFieldDisplayOptions();
     $basic_left .= $form->renderFieldUserLink('authorpage');
     $basic_left .= '</div>';
     $basic_right = $form->renderFieldAvatarSize();
     $basic_right .= $form->renderFieldMaxBioLength();
     $basic_tab = $form->renderTabStart(__('Basic', 'author-avatars'));
     $basic_tab .= $form->renderColumns($basic_left, $basic_right);
     $basic_tab .= $form->renderTabEnd();
     // ADVANCED TAB
     $adv_left = $form->renderFieldOrder('display_name');
     $adv_left .= $form->renderFieldSortDirection('asc');
     $adv_left .= $form->renderFieldLimit();
     $adv_left .= $form->renderPageLimit();
     $adv_left .= $form->renderFieldMinPostCount();
     $adv_left .= $form->renderFieldHiddenUsers();
     $adv_right = '';
     if (AA_is_wpmu()) {
         global $blog_id;
         // default value: current blog
         $adv_right .= $form->renderFieldBlogs($blog_id);
     }
     $adv_right .= $form->renderFieldGroupBy();
     $advanced_tab = $form->renderTabStart(__('Advanced', 'author-avatars'));
     $advanced_tab .= $form->renderColumns($adv_left, $adv_right);
     $advanced_tab .= $form->renderTabEnd();
     $tabs = $basic_tab . $advanced_tab;
     $html = '<div class="aa-tabs">' . $form->renderTabList() . $tabs . '</div>';
     $html .= "\n\t" . '<div class="mceActionPanel"> ' . AA_donateButton();
     $html .= "\n\t" . '<div style="float: left">';
     $html .= "\n\t" . '<input type="button" id="cancel" name="cancel" value="' . __("Cancel") . '" onclick="tinyMCEPopup.close();" />';
     $html .= "\n\t" . '</div>';
     $html .= "\n\t" . '<div style="float: right">';
     $html .= "\n\t" . '<input type="submit" id="insert" name="insert" value="' . __("Insert") . '" onclick="insertAuthorAvatarsCode();" />';
     $html .= "\n\t" . '</div>';
     $html .= "\n\t" . '</div>';
     echo '<body class="tinymce_popup">' . $html . "\n" . '</body>';
 }
 /**
  * Builds the widget control form.
  *
  * @access protected
  *
  * @param $instance Array of widget options. If empty then we're creating a new widget.
  *
  * @return void
  */
 function form($instance)
 {
     $instance = array_merge($this->defaults, $instance);
     require_once 'AuthorAvatarsForm.class.php';
     $form = new AuthorAvatarsForm();
     $form->setFieldIdCallback(array($this, 'get_field_id'));
     $form->setFieldNameCallback(array($this, 'get_field_name'));
     // widget title
     $widget_title = '<p>' . FormHelper::input('text', $this->get_field_name('title'), $instance['title'], array('label' => '<strong>' . __('Title', 'author-avatars') . ':</strong> ', 'class' => 'widefat', 'id' => $this->get_field_id('title'))) . '</p>';
     // BASIC TAB
     $basic_left = $widget_title;
     $basic_left .= $form->renderFieldRoles($instance['roles']);
     $basic_left .= $form->renderFieldUserLink($instance['display']['user_link'], 'display][user_link');
     $basic_right = $form->renderFieldDisplayOptions($instance['display']);
     $basic_right .= $form->renderFieldAvatarSize($instance['display']['avatar_size'], 'display][avatar_size');
     $basic_right .= '<div class="avatar_donate">' . AA_donateButton('link') . '</div>';
     $basic = '<h5>' . __('Basic', 'author-avatars') . '</h5>';
     $basic .= $form->renderColumns($basic_left, $basic_right);
     // ADVANCED TAB
     $adv_left = $form->renderFieldOrder($instance['display']['order'], 'display][order');
     $adv_left .= $form->renderFieldSortDirection($instance['display']['sort_direction'], 'display][sort_direction');
     $adv_left .= $form->renderFieldLimit($instance['display']['limit'], 'display][limit');
     $adv_left .= $form->renderFieldMinPostCount($instance['display']['min_post_count'], 'display][min_post_count');
     $adv_left .= $form->renderFieldHiddenUsers($instance['hiddenusers']);
     $adv_right = "";
     // incase we don't have any blogs
     if (AA_is_wpmu() && !empty($instance['blogs'])) {
         $adv_right .= $form->renderFieldBlogs($instance['blogs']);
     }
     $adv_right .= $form->renderFieldGroupBy($instance['group_by']);
     $advanced = '<h5>' . __('Advanced', 'author-avatars') . '</h5>';
     $advanced .= $form->renderColumns($adv_left, $adv_right);
     echo '<div class="aa-widget-control-panel">' . $basic . $advanced . '</div>';
     // hidden "submit=1" field (do we still need this?, FIXME)
     echo FormHelper::input('hidden', $this->get_field_name('submit'), '1', array('id' => $this->get_field_id('submit')));
 }
 /**
  * Returns true if we are on a wpmu site and the current blog is allowed to show users from multiple blogs.
  *
  * @access public
  *
  * @param $blog The id of the blog to check. If empty then the current blog id is used.
  *
  * @return boolean True if we are allowed to use blog selection on the blog...
  */
 function blog_selection_allowed($blog = false)
 {
     // check that we are on a wpmu enabled blog:
     if (!AA_is_wpmu()) {
         return false;
     }
     // if $blog is empty use current blog id
     if (!$blog) {
         global $blog_id;
         $blog = $blog_id;
     }
     return $this->blog_filters_is_active($blog);
 }
 /**
  * Group the given set of users if set in field "group_by"
  *
  * @param Array of WP_User objects, by reference
  *
  * @access private
  * @return void
  */
 function _group(&$users)
 {
     if (empty($this->group_by)) {
         return;
     }
     switch ($this->group_by) {
         case 'blog':
             if (AA_is_wpmu()) {
                 $users_new = array();
                 global $wpdb;
                 $pattern = '/' . $wpdb->base_prefix . '([0-9]+)_capabilities/';
                 foreach ($users as $user) {
                     $key = $user->meta_key;
                     $matches = array();
                     // blog id 1
                     if ($key == $wpdb->base_prefix . 'capabilities') {
                         $users_new[1][] = $user;
                     } else {
                         if (preg_match($pattern, $key, $matches) > 0) {
                             $users_new[$matches[1]][] = $user;
                         }
                     }
                 }
                 if (!empty($users_new)) {
                     $users = $users_new;
                 }
             }
             break;
     }
 }
 /**
  * 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>';
 }
 /**
  * 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;
 }
 /**
  * The shortcode handler for the [authoravatars] shortcode.
  */
 function shortcode_handler($atts, $content = null)
 {
     require_once 'UserList.class.php';
     $this->userlist = new UserList();
     $settings = AA_settings();
     // roles
     $roles = array();
     // default value: no restriction -> all users
     if (!empty($atts['roles'])) {
         if (!is_array($atts['roles'])) {
             $roles = explode(',', $atts['roles']);
         } else {
             $roles = $atts['roles'];
         }
         $roles = array_map('trim', $roles);
     }
     $this->userlist->roles = $roles;
     // blogs
     $blogs = array();
     // default value: empty -> only current blog
     if ($settings->blog_selection_allowed() && !empty($atts['blogs'])) {
         if (strtolower($atts['blogs']) == 'all') {
             $blogs = array(-1);
         } else {
             if (!is_array($atts['blogs'])) {
                 $blogs = explode(',', $atts['blogs']);
             } else {
                 $blogs = array_map('trim', $blogs);
             }
             $blogs = array_map('intval', $blogs);
         }
     }
     $this->userlist->blogs = $blogs;
     // grouping
     $group_by = '';
     if (isset($atts['group_by'])) {
         if (AA_is_wpmu() && $atts['group_by'] == 'blog') {
             $group_by = 'blog';
         }
     }
     $this->userlist->group_by = $group_by;
     // hidden users
     $hiddenusers = array();
     // default value: no restriction -> all users
     if (!empty($atts['hiddenusers'])) {
         if (!is_array($atts['hiddenusers'])) {
             $hiddenusers = explode(',', $atts['hiddenusers']);
         }
     }
     $this->userlist->hiddenusers = array_map('trim', $hiddenusers);
     // just these users
     $onlyusers = array();
     // default value: no restriction -> all users
     if (!empty($atts['onlyusers'])) {
         if (!is_array($atts['onlyusers'])) {
             $onlyusers = explode(',', $atts['onlyusers']);
         }
     }
     $this->userlist->onlyusers = array_map('trim', $onlyusers);
     // link to author page? (deprecated)
     if (isset($atts['link_to_authorpage']) && strlen($atts['link_to_authorpage']) > 0) {
         // by default always true, has to be set explicitly to not link the users
         $set_to_false = $atts['link_to_authorpage'] == 'false' || (bool) $atts['link_to_authorpage'] == false;
         if ($set_to_false) {
             $this->userlist->user_link = false;
         }
     }
     if (!empty($atts['user_link'])) {
         $this->userlist->user_link = $atts['user_link'];
     }
     $display = array();
     if (!empty($atts['display'])) {
         if (!is_array($atts['display'])) {
             $display = explode(',', $atts['display']);
         } else {
             $display = $atts['display'];
         }
     }
     $display = apply_filters('aa_shortcode_display_list', $display);
     // support for all style shortcode
     $default_display_options = array('show_name', 'show_postcount', 'show_email', 'show_biography', 'show_last_post', 'show_bbpress_post_count');
     // loop the old name=true settings and add them to the new array format
     foreach ($default_display_options as $default_display_option) {
         if (isset($atts[$default_display_option]) && strlen($atts[$default_display_option]) > 0) {
             if (true == $atts[$default_display_option] && !in_array($default_display_option, $display)) {
                 $display[] = $default_display_option;
             }
         }
     }
     // the defaults array and set the globals if found
     foreach ($default_display_options as $default_display_option) {
         if (in_array($default_display_option, $display)) {
             $this->userlist->{$default_display_option} = true;
         } else {
             $this->userlist->{$default_display_option} = false;
         }
     }
     $this->userlist->display_extra = array_diff($display, $default_display_options);
     //var_dump($this->userlist->display_extra);
     // avatar size
     if (!empty($atts['avatar_size'])) {
         $size = intval($atts['avatar_size']);
         if ($size > 0) {
             $this->userlist->avatar_size = $size;
         }
     }
     // max. number of avatars
     if (!empty($atts['limit'])) {
         $limit = intval($atts['limit']);
         if ($limit > 0) {
             $this->userlist->limit = $limit;
         }
     }
     // max. number of avatars
     $this->userlist->bio_length = -1;
     if (!empty($atts['max_bio_length'])) {
         $bio_length = intval($atts['max_bio_length']);
         if (0 < $bio_length) {
             $this->userlist->bio_length = $bio_length;
         }
     }
     // min. number of posts
     if (!empty($atts['min_post_count'])) {
         $min_post_count = intval($atts['min_post_count']);
         if (0 < $min_post_count) {
             $this->userlist->min_post_count = $min_post_count;
         }
     }
     // get page size
     if (!empty($atts['page_size'])) {
         $page_size = intval($atts['page_size']);
         if (0 < $page_size) {
             $this->userlist->page_size = $page_size;
         }
     }
     // get page size
     if (!empty($atts['aa_page'])) {
         $page_size = intval($atts['aa_page']);
         if (0 < $page_size) {
             $this->userlist->aa_page = $page_size;
         }
     } elseif (isset($_REQUEST['aa_page']) && is_numeric($_REQUEST['aa_page'])) {
         $page_size = intval($_REQUEST['aa_page']);
         if (0 < $page_size) {
             $this->userlist->aa_page = $page_size;
         }
     }
     // display order
     $sort_direction = 'asc';
     if (!empty($atts['order'])) {
         $order = $atts['order'];
         if (strpos($order, ',') !== false) {
             list($order, $sort_direction) = explode(',', $order, 2);
         }
         $this->userlist->order = $order;
     }
     if (!empty($atts['sort_direction'])) {
         $sort_direction = $atts['sort_direction'];
     }
     $valid_directions = array('asc', 'ascending', 'desc', 'descending');
     if (in_array($sort_direction, $valid_directions)) {
         $this->userlist->sort_direction = $sort_direction;
     }
     // render as a list?
     if (isset($atts['render_as_list'])) {
         $set_to_false = $atts['render_as_list'] == 'false';
         if (!$set_to_false) {
             $this->userlist->use_list_template();
         }
     }
     return '<div class="shortcode-author-avatars">' . $this->userlist->get_output() . $content . $this->userlist->pagingHTML . '</div>';
 }
 /**
  * The shortcode handler for the [authoravatars] shortcode.
  */
 function shortcode_handler($atts, $content = null)
 {
     require_once 'UserList.class.php';
     $this->userlist = new UserList();
     $settings = AA_settings();
     // roles
     $roles = array();
     // default value: no restriction -> all users
     if (!empty($atts['roles'])) {
         if (!is_array($atts['roles'])) {
             $roles = explode(',', $atts['roles']);
         } else {
             $roles = $atts['roles'];
         }
         $roles = array_map('trim', $roles);
     }
     $this->userlist->roles = $roles;
     // blogs
     $blogs = array();
     // default value: empty -> only current blog
     if ($settings->blog_selection_allowed() && !empty($atts['blogs'])) {
         if (strtolower($atts['blogs']) == 'all') {
             $blogs = array(-1);
         } else {
             if (!is_array($atts['blogs'])) {
                 $blogs = explode(',', $atts['blogs']);
             } else {
                 $blogs = array_map('trim', $blogs);
             }
             $blogs = array_map('intval', $blogs);
         }
     }
     $this->userlist->blogs = $blogs;
     // grouping
     $group_by = '';
     if (isset($atts['group_by'])) {
         if (AA_is_wpmu() && $atts['group_by'] == 'blog') {
             $group_by = 'blog';
         }
     }
     $this->userlist->group_by = $group_by;
     // hidden users
     $hiddenusers = array();
     // default value: no restriction -> all users
     if (!empty($atts['hiddenusers'])) {
         if (!is_array($atts['hiddenusers'])) {
             $hiddenusers = explode(',', $atts['hiddenusers']);
         }
     }
     $this->userlist->hiddenusers = array_map('trim', $hiddenusers);
     // just these users
     $onlyusers = array();
     // default value: no restriction -> all users
     if (!empty($atts['onlyusers'])) {
         if (!is_array($atts['onlyusers'])) {
             $onlyusers = explode(',', $atts['onlyusers']);
         }
     }
     $this->userlist->onlyusers = array_map('trim', $onlyusers);
     // link to author page? (deprecated)
     if (isset($atts['link_to_authorpage']) && strlen($atts['link_to_authorpage']) > 0) {
         // by default always true, has to be set explicitly to not link the users
         $set_to_false = $atts['link_to_authorpage'] == 'false' || (bool) $atts['link_to_authorpage'] == false;
         if ($set_to_false) {
             $this->userlist->user_link = false;
         }
     }
     if (!empty($atts['user_link'])) {
         $this->userlist->user_link = $atts['user_link'];
     }
     // show author name?
     if (isset($atts['show_name']) && strlen($atts['show_name']) > 0) {
         $set_to_false = $atts['show_name'] == 'false';
         if ($set_to_false) {
             $this->userlist->show_name = false;
         } else {
             $this->userlist->show_name = true;
         }
     }
     // show post count?
     if (isset($atts['show_postcount']) && strlen($atts['show_postcount']) > 0) {
         $set_to_false = $atts['show_postcount'] == 'false';
         if ($set_to_false) {
             $this->userlist->show_postcount = false;
         } else {
             $this->userlist->show_postcount = true;
         }
     }
     // show email?
     if (isset($atts['show_email']) && strlen($atts['show_email']) > 0) {
         $set_to_false = $atts['show_email'] == 'false';
         if ($set_to_false) {
             $this->userlist->show_email = false;
         } else {
             $this->userlist->show_email = true;
         }
     }
     // show biography?
     if (isset($atts['show_biography']) && strlen($atts['show_biography']) > 0) {
         $set_to_false = $atts['show_biography'] == 'false';
         if ($set_to_false) {
             $this->userlist->show_biography = false;
         } else {
             $this->userlist->show_biography = true;
         }
     }
     // show show_bbpress_post_count?
     if (isset($atts['show_bbpress_post_count']) && strlen($atts['show_bbpress_post_count']) > 0) {
         $set_to_false = $atts['show_bbpress_post_count'] == 'false';
         if ($set_to_false) {
             $this->userlist->show_bbpress_post_count = false;
         } else {
             $this->userlist->show_bbpress_post_count = true;
         }
     }
     // avatar size
     if (!empty($atts['avatar_size'])) {
         $size = intval($atts['avatar_size']);
         if ($size > 0) {
             $this->userlist->avatar_size = $size;
         }
     }
     // max. number of avatars
     if (!empty($atts['limit'])) {
         $limit = intval($atts['limit']);
         if ($limit > 0) {
             $this->userlist->limit = $limit;
         }
     }
     // min. number of posts
     if (!empty($atts['min_post_count'])) {
         $min_post_count = intval($atts['min_post_count']);
         if ($min_post_count > 0) {
             $this->userlist->min_post_count = $min_post_count;
         }
     }
     // get page size
     if (!empty($atts['page_size'])) {
         $page_size = intval($atts['page_size']);
         if ($page_size > 0) {
             $this->userlist->page_size = $page_size;
         }
     }
     // get page size
     if (!empty($atts['aa_page'])) {
         $page_size = intval($atts['aa_page']);
         if ($page_size > 0) {
             $this->userlist->aa_page = $page_size;
         }
     } elseif (isset($_REQUEST['aa_page']) && is_numeric($_REQUEST['aa_page'])) {
         $page_size = intval($_REQUEST['aa_page']);
         if ($page_size > 0) {
             $this->userlist->aa_page = $page_size;
         }
     }
     // display order
     $sort_direction = 'asc';
     if (!empty($atts['order'])) {
         $order = $atts['order'];
         if (strpos($order, ',') !== false) {
             list($order, $sort_direction) = explode(',', $order, 2);
         }
         $this->userlist->order = $order;
     }
     if (!empty($atts['sort_direction'])) {
         $sort_direction = $atts['sort_direction'];
     }
     $valid_directions = array('asc', 'ascending', 'desc', 'descending');
     if (in_array($sort_direction, $valid_directions)) {
         $this->userlist->sort_direction = $sort_direction;
     }
     // render as a list?
     if (isset($atts['render_as_list'])) {
         $set_to_false = $atts['render_as_list'] == 'false';
         if (!$set_to_false) {
             $this->userlist->use_list_template();
         }
     }
     return '<div class="shortcode-author-avatars">' . $this->userlist->get_output() . $content . $this->userlist->pagingHTML . '</div>';
 }