<?php
/*
Plugin Name: Custom List Authors
Plugin URI: http://guff.szub.net/custom-list_authors
Description: szub_list_authors() - extends wp_list_authors.
Version: R1.0.1
Author: Kaf Oseo
Author URI: http://szub.net

    Copyright (c) 2007, 2008 Kaf Oseo (http://szub.net)
    Custom List Authors is released under the GNU General Public License, version 2 (GPL2)
    http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

    This is a WordPress plugin (http://wordpress.org).

~Changelog:
R1.0.1 (Feb-01-2008)
Adds 'link_empty' (boolean) - Display 'authors' without any posts as
links (1) or as plain text (0). Default is 0.

R1.0 (Dec-01-2007)
Adds 'hide_after' (integer) - Hide authors after # of days since last
post. Default is null (does not hide authors).
*/

function custom_list_authors($args '') {
    return 
szub_list_authors($args);
}

function 
timed_list_authors($args '') {
    return 
szub_list_authors($args);
}

function 
szub_list_authors($args '') {
    global 
$wpdb;

    
$defaults = array(
        
'optioncount' => false'exclude_admin' => true,
        
'show_fullname' => false'hide_empty' => true,
        
'feed' => '''feed_image' => '''echo' => true
    
);

    
$r wp_parse_args$args$defaults );
    
extract($rEXTR_SKIP);

    
$return '';

    
$authors $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin "WHERE user_login <> 'admin' " '') . "ORDER BY display_name");

    
$author_count = array();
    foreach ((array) 
$wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count, MAX(post_date) as lastdate FROM $wpdb->posts WHERE post_type = 'post' AND " get_private_posts_cap_sql'post' ) . " GROUP BY post_author") as $row) {
        
$author_count[$row->post_author] = $row->count;
        
$author_last[$row->post_author] = $row->lastdate;
    }

    foreach ( (array) 
$authors as $author ) {

        
$days_since ceil( (date('U') - mysql2date('U'$author_last[$author->ID])) / 86400 );
        if ( 
$hide_after && ($days_since $hide_after) )
            continue;

        if ( 
$link_empty )
            
$hide_empty false;

        
$author get_userdata$author->ID );
        
$posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
        
$name $author->display_name;

        if ( 
$show_fullname && ($author->first_name != '' && $author->last_name != '') )
            
$name "$author->first_name $author->last_name";

        if ( !(
$posts == && $hide_empty) )
            
$return .= '<li>';
        if ( !
$link_empty && $posts == ) {
            if ( !
$hide_empty )
                
$link $name;
        } else {
            
$link '<a href="' get_author_posts_url($author->ID$author->user_nicename) . '" title="' sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' $name '</a>';

            if ( (! empty(
$feed_image)) || (! empty($feed)) ) {
                
$link .= ' ';
                if (empty(
$feed_image))
                    
$link .= '(';
                
$link .= '<a href="' get_author_rss_link(0$author->ID$author->user_nicename) . '"';

                if ( !empty(
$feed) ) {
                    
$title ' title="' $feed '"';
                    
$alt ' alt="' $feed '"';
                    
$name $feed;
                    
$link .= $title;
                }

                
$link .= '>';

                if ( !empty(
$feed_image) )
                    
$link .= "<img src=\"$feed_image\" border=\"0\"$alt$title' />';
                else
                    
$link .= $name;

                
$link .= '</a>';

                if ( empty(
$feed_image) )
                    
$link .= ')';
            }

            if ( 
$optioncount )
                
$link .= ' ('$posts ')';

        }

        if ( !(
$posts == && $hide_empty) )
            
$return .= $link '</li>';
    }
    if ( !
$echo )
        return 
$return;
    echo 
$return;
}

function 
szub_404_author_template($template) {
    
$wp_query;
    if( !
is_author() && get_query_var('author') && (== $wp_query->posts->post) ) {
        return 
get_author_template();
    }
    return 
$template;
}

add_filter('404_template''szub_404_author_template');
?>