<?php
get_header();
if (!$kippis_is_smartphone) get_sidebar('left');
?>
      <div id="content">
      <?php
      if (have_posts()) {
        ?>
        <article>
          <div id="author-info" class="article">
          <?php
            the_post();
            $display_author_info = empty($wp_query->query_vars['paged']);
            ?>
            <header class="page-header">
              <h1 class="page-title author">
              <?php
                printf(__('Author: %s','kippis'),'<span class="vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '" title="' . esc_attr(get_the_author()) . '" rel="me">' . get_the_author() . '</a></span>');
              ?>
              </h1>
            </header>
            <?php
            rewind_posts();
            if ($display_author_info) {
              $user = new WP_User(get_the_author_meta('ID'));
              $author_is_admin    = !empty($user->allcaps['administrator']);
              $author_avatar      = get_avatar(get_the_author_meta('user_email'),apply_filters('kippis_author_bio_avatar_size',60));
              $author_description = nl2br(get_the_author_meta('description'));
              if ((!$author_is_admin) && ((!empty($author_avatar)) || (!empty($author_description)))) {
                ?>
                  <?php
                    if (!empty($author_avatar)) {
                      echo '<div id="author-avatar">'
                         .   $author_avatar
                         . '</div>'
                         ;
                    }
                    if (!empty($author_description)) {
                      echo '<div id="author-description">'
                       //.   '<h3>' . sprintf(__('About %s','kippis'),get_the_author()) . '</h3>'
                         .   $author_description
                         . '</div>'
                         ;
                    }
                    $author_posts = $wpdb->get_var("select count(*) from $wpdb->posts where post_author = '" . get_the_author_meta('ID') . "' and post_type = 'post' and post_status = 'publish'");
                    if ((int)$author_posts > 0) {
                      echo '<div class="author-num-posts">'
                         .   '<b>' . sprintf(__('Posts: %s',HYDRA_TXT),number_format_i18n($author_posts)) . '</b>'
                         . '</div>'
                         ;
                    }
                    $categories = $wpdb->get_results("SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug"
                                                  . " FROM $wpdb->posts as posts"
                                                  . " LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID"
                                                  . " LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id"
                                                  . " LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id"
                                                  . " WHERE posts.post_status = 'publish' AND posts.post_author = '$author' AND tax.taxonomy = 'category'"
                                                  . " ORDER BY terms.name ASC");
                    $tags = $wpdb->get_results("SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug"
                                             . " FROM $wpdb->posts as posts"
                                             . " LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID"
                                             . " LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id"
                                             . " LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id"
                                             . " WHERE posts.post_status = 'publish' AND posts.post_author = '19' AND tax.taxonomy = 'post_tag'"
                                             );
                    if (!empty($categories)) {
                      echo '<div class="author-categories"><b>' . __('Categories','kippis') . ':</b>';
                      foreach($categories as $category) {
                        echo ' <a href="' . get_category_link($category->ID) . '" title="' . $category->name . '">' . $category->name . '</a>';
                      }
                      echo '</div>';
                    }
                    if (!empty($tags)) {
                      echo '<div class="author-categories"><b>' . __('Tags','kippis') . ':</b>';
                      foreach($tags as $tag) {
                        echo ' <a href="' . get_tag_link($tag->ID) . '" title="' . $tag->name . '">' . $tag->name . '</a>';
                      }
                      echo '</div>';
                    }

                    $subscribe_to = sprintf(__('Subscribe to posts by %s','kippis'),get_the_author());
                    echo '<div class="author-rss">'
                       .   '<a href="' . get_author_feed_link(get_the_author_meta('ID')) . '" title="' . $subscribe_to . '">'
                       .   '<img src="' . get_template_directory_uri() . '/pix/rss.png' . '" class="icon32 alignleft" />'
                       .   '<p>' . $subscribe_to . '</p>'
                       .   '</a>'
                       . '</div>'
                       ;
                  ?>
                <?php
              }
            }
          ?>
          </div><!-- #author-info .article -->
        </article>
        <?php
        kippis_content_nav('nav-above');
        //echo '<header class="page-header">'
        //   .   '<h1 class="page-title author">' . sprintf(__('Posts by %s','kippis'),get_the_author()) . '</h1>';
        //   . '</header>'
        //   ;
        while (have_posts()) {
          the_post();
          get_template_part('content',get_post_format());
        }
        kippis_content_nav('nav-below');
      }  // if (have_posts()) {
      else {
        ?>
        <div id="post-0" class="article post no-results not-found">
          <header class="entry-header">
            <h1 class="entry-title"><?php _e('Nothing Found','kippis'); ?></h1>
          </header>
          <div class="entry-content">
            <p><?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.','kippis'); ?></p>
            <?php get_search_form(); ?>
          </div>
        </div>
        <?php
      }
      ?>
      </div><!-- #content -->
<?php
if ($kippis_is_smartphone) get_sidebar('left');
get_sidebar('right');
get_footer();

