Make WordPress Core


Ignore:
Timestamp:
10/12/2005 05:01:50 PM (20 years ago)
Author:
ryan
Message:

Code cleanup from Mark Jaquith. fixes #1746

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-author.php

    r2858 r2943  
    22
    33function get_the_author($idmode = '') {
    4     global $authordata;
    5     return apply_filters('the_author', $authordata->display_name);
     4    global $authordata;
     5    return apply_filters('the_author', $authordata->display_name);
    66}
    77
    88function the_author($idmode = '', $echo = true) {
    9     if ($echo) echo get_the_author($idmode);
     9    if ( $echo )
     10        echo get_the_author($idmode);
    1011    return get_the_author($idmode);
    1112}
    1213
    1314function get_the_author_description() {
    14     global $authordata;
    15     return $authordata->user_description;
     15    global $authordata;
     16    return $authordata->user_description;
    1617}
    1718function the_author_description() {
    18     echo get_the_author_description();
     19    echo get_the_author_description();
    1920}
    2021
    2122function get_the_author_login() {
    22     global $id,$authordata;    return $authordata->user_login;
    23 }
     23    global $authordata;
     24    return $authordata->user_login;
     25}
     26
    2427function the_author_login() {
    25     echo get_the_author_login();
     28    echo get_the_author_login();
    2629}
    2730
    2831function get_the_author_firstname() {
    29     global $id,$authordata;    return $authordata->first_name;
     32    global $authordata;
     33    return $authordata->first_name;
    3034}
    3135function the_author_firstname() {
    32     echo get_the_author_firstname();
     36    echo get_the_author_firstname();
    3337}
    3438
    3539function get_the_author_lastname() {
    36     global $id,$authordata;    return $authordata->last_name;
    37 }
     40    global $authordata;
     41    return $authordata->last_name;
     42}
     43
    3844function the_author_lastname() {
    39     echo get_the_author_lastname();
     45    echo get_the_author_lastname();
    4046}
    4147
    4248function get_the_author_nickname() {
    43     global $id,$authordata;    return $authordata->nickname;
    44 }
     49    global $authordata;
     50    return $authordata->nickname;
     51}
     52
    4553function the_author_nickname() {
    46     echo get_the_author_nickname();
     54    echo get_the_author_nickname();
    4755}
    4856
    4957function get_the_author_ID() {
    50     global $id,$authordata;    return $authordata->ID;
     58    global $authordata;
     59    return $authordata->ID;
    5160}
    5261function the_author_ID() {
    53     echo get_the_author_id();
     62    echo get_the_author_id();
    5463}
    5564
     
    6473
    6574function get_the_author_url() {
    66     global $id,$authordata;    return $authordata->user_url;
    67 }
     75    global $authordata;
     76    return $authordata->user_url;
     77}
     78
    6879function the_author_url() {
    69     echo get_the_author_url();
     80    echo get_the_author_url();
    7081}
    7182
    7283function get_the_author_icq() {
    73     global $id,$authordata;    return $authordata->icq;
    74 }
     84    global $authordata;
     85    return $authordata->icq;
     86}
     87
    7588function the_author_icq() {
    76     echo get_the_author_icq();
     89    echo get_the_author_icq();
    7790}
    7891
    7992function get_the_author_aim() {
    80     global $id,$authordata;    return str_replace(' ', '+', $authordata->aim);
    81 }
     93    global $authordata;
     94    return str_replace(' ', '+', $authordata->aim);
     95}
     96
    8297function the_author_aim() {
    83     echo get_the_author_aim();
     98    echo get_the_author_aim();
    8499}
    85100
    86101function get_the_author_yim() {
    87     global $id,$authordata;    return $authordata->yim;
    88 }
     102    global $authordata;
     103    return $authordata->yim;
     104}
     105
    89106function the_author_yim() {
    90     echo get_the_author_yim();
     107    echo get_the_author_yim();
    91108}
    92109
    93110function get_the_author_msn() {
    94     global $id,$authordata;    return $authordata->msn;
    95 }
     111    global $authordata;
     112    return $authordata->msn;
     113}
     114
    96115function the_author_msn() {
    97     echo get_the_author_msn();
     116    echo get_the_author_msn();
    98117}
    99118
    100119function get_the_author_posts() {
    101     global $id,$post;
    102     $posts=get_usernumposts($post->post_author);
     120    global $post;
     121    $posts = get_usernumposts($post->post_author);
    103122    return $posts;
    104123}
     124
    105125function the_author_posts() {
    106     echo get_the_author_posts();
     126    echo get_the_author_posts();
    107127}
    108128
    109129/* the_author_posts_link() requires no get_, use get_author_link() */
    110130function the_author_posts_link($idmode='') {
    111     global $id, $authordata;
    112 
    113     echo '<a href="' . get_author_link(0, $authordata->ID, $authordata->user_nicename) . '" title="' . sprintf(__("Posts by %s"), wp_specialchars(the_author($idmode, false))) . '">' . the_author($idmode, false) . '</a>';
    114 }
    115 
     131    global $authordata;
     132
     133    echo '<a href="' . get_author_link(0, $authordata->ID, $authordata->user_nicename) . '" title="' . sprintf(__("Posts by %s"), wp_specialchars(the_author($idmode, false))) . '">' . the_author($idmode, false) . '</a>';
     134}
    116135
    117136function get_author_link($echo = false, $author_id, $author_nicename) {
    118137    global $wpdb, $wp_rewrite, $post, $cache_userdata;
    119     $auth_ID = $author_id;
    120     $link = $wp_rewrite->get_author_permastruct();
    121    
    122     if (empty($link)) {
    123         $file = get_settings('home') . '/';
    124         $link = $file . '?author=' . $auth_ID;
    125     } else {
    126         if ('' == $author_nicename) $author_nicename = $cache_userdata[$author_id]->user_nicename;
    127                 $link = str_replace('%author%', $author_nicename, $link);
    128                 $link = get_settings('home') . trailingslashit($link);
    129     }
    130 
    131         $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    132     if ($echo) echo $link;
    133     return $link;
     138    $auth_ID = $author_id;
     139    $link = $wp_rewrite->get_author_permastruct();
     140
     141    if ( empty($link) ) {
     142        $file = get_settings('home') . '/';
     143        $link = $file . '?author=' . $auth_ID;
     144    } else {
     145        if ( '' == $author_nicename )
     146            $author_nicename = $cache_userdata[$author_id]->user_nicename;
     147        $link = str_replace('%author%', $author_nicename, $link);
     148        $link = get_settings('home') . trailingslashit($link);
     149    }
     150
     151    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
     152
     153    if ( $echo )
     154        echo $link;
     155    return $link;
    134156}
    135157
    136158function wp_list_authors($args = '') {
    137159    parse_str($args, $r);
    138     if (!isset($r['optioncount'])) $r['optioncount'] = false;
    139     if (!isset($r['exclude_admin'])) $r['exclude_admin'] = true;
    140     if (!isset($r['show_fullname'])) $r['show_fullname'] = false;
    141     if (!isset($r['hide_empty'])) $r['hide_empty'] = true;
    142     if (!isset($r['feed'])) $r['feed'] = '';
    143     if (!isset($r['feed_image'])) $r['feed_image'] = '';
     160
     161    if ( !isset($r['optioncount']) )
     162        $r['optioncount'] = false;
     163    if ( !isset($r['exclude_admin']) )
     164        $r['exclude_admin'] = true;
     165    if ( !isset($r['show_fullname']) )
     166        $r['show_fullname'] = false;
     167    if ( !isset($r['hide_empty']) )
     168        $r['hide_empty'] = true;
     169    if ( !isset($r['feed']) )
     170        $r['feed'] = '';
     171    if ( !isset($r['feed_image']) )
     172        $r['feed_image'] = '';
    144173
    145174    list_authors($r['optioncount'], $r['exclude_admin'], $r['show_fullname'], $r['hide_empty'], $r['feed'], $r['feed_image']);
     
    147176
    148177function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true, $feed = '', $feed_image = '') {
    149     global $wpdb;
    150 
    151     $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name";
    152     $authors = $wpdb->get_results($query);
    153 
    154     foreach($authors as $author) {
     178    global $wpdb;
     179    $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name";
     180    $authors = $wpdb->get_results($query);
     181
     182    foreach ( $authors as $author ) {
    155183        $author = get_userdata( $author->ID );
    156         $posts = get_usernumposts($author->ID);
    157         $name = $author->nickname;
    158 
    159         if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
    160             $name = "$author->first_name $author->last_name";
    161         }
    162        
    163         if (! ($posts == 0 && $hide_empty)) echo "<li>";
    164         if ($posts == 0) {
    165             if ( !$hide_empty )
     184        $posts = get_usernumposts($author->ID);
     185        $name = $author->nickname;
     186
     187        if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
     188            $name = "$author->first_name $author->last_name";
     189
     190        if ( !($posts == 0 && $hide_empty) )
     191            echo "<li>";
     192        if ( $posts == 0 ) {
     193            if ( !$hide_empty )
    166194                $link = $name;
    167         } else {
    168             $link = '<a href="' . get_author_link(0, $author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), wp_specialchars($author->display_name)) . '">' . $name . '</a>';
    169 
    170             if ( (! empty($feed_image)) || (! empty($feed)) ) {
    171                
    172                 $link .= ' ';
    173 
    174                 if (empty($feed_image)) {
    175                     $link .= '(';
    176                 }
    177 
    178                 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename)  . '"';
    179 
    180                 if (! empty($feed)) {
    181                     $title =  ' title="' . $feed . '"';
    182                     $alt = ' alt="' . $feed . '"';
    183                     $name = $feed;
    184                     $link .= $title;
    185                 }
    186 
    187                 $link .= '>';
    188 
    189                 if (! empty($feed_image)) {
    190                     $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />';
    191                 } else {
    192                     $link .= $name;
    193                 }
    194                
    195                 $link .= '</a>';
    196 
    197                 if (empty($feed_image)) {
    198                     $link .= ')';
    199                 }
    200             }
    201 
    202             if ($optioncount) {
    203                 $link .= ' ('. $posts . ')';
    204             }
    205         }
    206 
    207         if (! ($posts == 0 && $hide_empty)) echo "$link</li>";
    208     }
     195        } else {
     196            $link = '<a href="' . get_author_link(0, $author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), wp_specialchars($author->display_name)) . '">' . $name . '</a>';
     197
     198            if ( (! empty($feed_image)) || (! empty($feed)) ) {
     199                $link .= ' ';
     200                if (empty($feed_image))
     201                    $link .= '(';
     202                $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
     203
     204                if ( !empty($feed) ) {
     205                    $title = ' title="' . $feed . '"';
     206                    $alt = ' alt="' . $feed . '"';
     207                    $name = $feed;
     208                    $link .= $title;
     209                }
     210
     211                $link .= '>';
     212
     213                if ( !empty($feed_image) )
     214                    $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />';
     215                else
     216                    $link .= $name;
     217
     218                $link .= '</a>';
     219
     220                if ( empty($feed_image) )
     221                    $link .= ')';
     222            }
     223
     224            if ( $optioncount )
     225                $link .= ' ('. $posts . ')';
     226
     227        }
     228
     229        if ( !($posts == 0 && $hide_empty) )
     230            echo "$link</li>";
     231    }
    209232}
    210233
Note: See TracChangeset for help on using the changeset viewer.