Make WordPress Core

Changeset 2943


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

Code cleanup from Mark Jaquith. fixes #1746

Location:
trunk/wp-includes
Files:
2 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
  • trunk/wp-includes/template-functions-category.php

    r2931 r2943  
    22
    33function get_the_category($id = false) {
    4     global $post, $category_cache;
     4global $post, $category_cache;
    55
    66        if ( !$id )
    77                $id = $post->ID;
    88
    9         if ( ! isset($category_cache[$id]) )
     9        if ( !isset($category_cache[$id]) )
    1010                update_post_category_cache($id);
    1111
    1212        $categories = $category_cache[$id];
    1313
    14         if (!empty($categories))
     14        if ( !empty($categories) )
    1515                sort($categories);
    1616        else
    … …  
    3131                $category_nicename = $category->category_nicename;
    3232
    33                 if ($parent = $category->category_parent)
     33                if ( $parent = $category->category_parent )
    3434                        $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/';
    3535
    … …  
    4141
    4242function get_the_category_list($separator = '', $parents='') {
    43     $categories = get_the_category();
    44     if (empty($categories)) {
    45                         return apply_filters('the_category', __('Uncategorized'), $separator, $parents);
    46     }
    47 
    48     $thelist = '';
    49     if ('' == $separator) {
    50         $thelist .= '<ul class="post-categories">';
    51         foreach ($categories as $category) {
    52             $category->cat_name = $category->cat_name;
    53             $thelist .= "\n\t<li>";
    54             switch(strtolower($parents)) {
    55                 case 'multiple':
    56                     if ($category->category_parent) {
    57                         $thelist .= get_category_parents($category->category_parent, TRUE);
    58                     }
    59                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>';
    60                     break;
    61                 case 'single':
    62                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . ' rel="category tag">';
    63                     if ($category->category_parent) {
    64                         $thelist .= get_category_parents($category->category_parent, FALSE);
    65                     }
    66                     $thelist .= $category->cat_name.'</a></li>';
    67                     break;
    68                 case '':
    69                 default:
    70                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>';
    71             }
    72         }
    73         $thelist .= '</ul>';
    74     } else {
    75         $i = 0;
    76         foreach ($categories as $category) {
    77             $category->cat_name = $category->cat_name;
    78             if (0 < $i) $thelist .= $separator . ' ';
    79             switch(strtolower($parents)) {
    80                 case 'multiple':
    81                     if ($category->category_parent)    $thelist .= get_category_parents($category->category_parent, TRUE);
    82                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>';
    83                     break;
    84                 case 'single':
    85                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">';
    86                     if ($category->category_parent)    $thelist .= get_category_parents($category->category_parent, FALSE);
    87                     $thelist .= "$category->cat_name</a>";
    88                     break;
    89                 case '':
    90                 default:
    91                     $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>';
    92             }
    93             ++$i;
    94         }
    95     }
    96     return apply_filters('the_category', $thelist, $separator, $parents);
     43        $categories = get_the_category();
     44        if (empty($categories))
     45                return apply_filters('the_category', __('Uncategorized'), $separator, $parents);
     46
     47        $thelist = '';
     48        if ( '' == $separator ) {
     49                $thelist .= '<ul class="post-categories">';
     50                foreach ( $categories as $category ) {
     51                        $category->cat_name = $category->cat_name;
     52                        $thelist .= "\n\t<li>";
     53                        switch ( strtolower($parents) ) {
     54                                case 'multiple':
     55                                        if ($category->category_parent)
     56                                                $thelist .= get_category_parents($category->category_parent, TRUE);
     57                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>';
     58                                        break;
     59                                case 'single':
     60                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . ' rel="category tag">';
     61                                        if ($category->category_parent)
     62                                                $thelist .= get_category_parents($category->category_parent, FALSE);
     63                                        $thelist .= $category->cat_name.'</a></li>';
     64                                        break;
     65                                case '':
     66                                default:
     67                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>';
     68                        }
     69                }
     70                $thelist .= '</ul>';
     71        } else {
     72                $i = 0;
     73                foreach ( $categories as $category ) {
     74                        $category->cat_name = $category->cat_name;
     75                        if ( 0 < $i )
     76                                $thelist .= $separator . ' ';
     77                        switch ( strtolower($parents) ) {
     78                                case 'multiple':
     79                                        if ( $category->category_parent )
     80                                                $thelist .= get_category_parents($category->category_parent, TRUE);
     81                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>';
     82                                        break;
     83                                case 'single':
     84                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">';
     85                                        if ( $category->category_parent )
     86                                                $thelist .= get_category_parents($category->category_parent, FALSE);
     87                                        $thelist .= "$category->cat_name</a>";
     88                                        break;
     89                                case '':
     90                                default:
     91                                        $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>';
     92                        }
     93                        ++$i;
     94                }
     95        }
     96        return apply_filters('the_category', $thelist, $separator, $parents);
    9797}
    9898
    … …  
    108108
    109109function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
    110     $chain = '';
    111                 $parent = &get_category($id);
    112     if ($nicename) {
    113         $name = $parent->category_nicename;
    114     } else {
    115         $name = $parent->cat_name;
    116     }
    117     if ($parent->category_parent) $chain .= get_category_parents($parent->category_parent, $link, $separator, $nicename);
    118     if ($link) {
    119         $chain .= '<a href="' . get_category_link($parent->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
    120     } else {
    121         $chain .= $name.$separator;
    122     }
    123     return $chain;
     110        $chain = '';
     111        $parent = &get_category($id);
     112
     113        if ( $nicename )
     114                $name = $parent->category_nicename;
     115        else
     116                $name = $parent->cat_name;
     117
     118        if ( $parent->category_parent )
     119                $chain .= get_category_parents($parent->category_parent, $link, $separator, $nicename);
     120
     121        if ( $link )
     122                $chain .= '<a href="' . get_category_link($parent->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
     123        else
     124                $chain .= $name.$separator;
     125        return $chain;
    124126}
    125127
    … …  
    127129        global $cache_categories;
    128130
    129         if ( ! isset($cache_categories))
     131        if ( !isset($cache_categories) )
    130132                update_category_cache();
    131                
     133
    132134        $c_cache = $cache_categories; // Can't do recursive foreach on a global, have to make a copy
    133135        $chain = '';
    134         foreach ($c_cache as $category){
    135                 if ($category->category_parent == $id){
     136        foreach ( $c_cache as $category ) {
     137                if ( $category->category_parent == $id ) {
    136138                        $chain .= $before.$category->cat_ID.$after;
    137139                        $chain .= get_category_children($category->cat_ID, $before, $after);
    … …  
    143145// Deprecated.
    144146function the_category_ID($echo = true) {
    145     // Grab the first cat in the list.
    146     $categories = get_the_category();
    147     $cat = $categories[0]->cat_ID;
    148    
    149     if ($echo) echo $cat;
    150 
    151     return $cat;
     147        // Grab the first cat in the list.
     148        $categories = get_the_category();
     149        $cat = $categories[0]->cat_ID;
     150
     151        if ( $echo )
     152                echo $cat;
     153
     154        return $cat;
    152155}
    153156
    154157// Deprecated.
    155158function the_category_head($before='', $after='') {
    156     global $currentcat, $previouscat;
    157     // Grab the first cat in the list.
    158     $categories = get_the_category();
    159     $currentcat = $categories[0]->category_id;
    160     if ($currentcat != $previouscat) {
    161         echo $before;
    162         echo get_the_category_by_ID($currentcat);
    163         echo $after;
    164         $previouscat = $currentcat;
    165     }
     159        global $currentcat, $previouscat;
     160        // Grab the first cat in the list.
     161        $categories = get_the_category();
     162        $currentcat = $categories[0]->category_id;
     163        if ( $currentcat != $previouscat ) {
     164                echo $before;
     165                echo get_the_category_by_ID($currentcat);
     166                echo $after;
     167                $previouscat = $currentcat;
     168        }
    166169}
    167170
    168171function category_description($category = 0) {
    169     global $cat;
    170     if (!$category) $category = $cat;
    171                 $category = & get_category($category);
    172     return apply_filters('category_description', $category->category_description, $category->cat_ID);
     172        global $cat;
     173        if ( !$category )
     174                $category = $cat;
     175        $category = & get_category($category);
     176        return apply_filters('category_description', $category->category_description, $category->cat_ID);
    173177}
    174178
    175179// out of the WordPress loop
    176180function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc',
    177         $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE,
    178         $selected=0, $hide=0) {
    179     global $wpdb;
    180     if (($file == 'blah') || ($file == '')) $file = get_settings('home') . '/';
    181     if (!$selected) $selected=$cat;
    182     $sort_column = 'cat_'.$sort_column;
    183 
    184     $query = "
    185         SELECT cat_ID, cat_name, category_nicename,category_parent,
    186         COUNT($wpdb->post2cat.post_id) AS cat_count,
    187         DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
    188         FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id)
    189         LEFT JOIN $wpdb->posts ON (ID = post_id)
    190         WHERE cat_ID > 0
    191         ";
    192     if ($hide) {
    193         $query .= " AND cat_ID != $hide";
    194         $query .= get_category_children($hide, " AND cat_ID != ");
    195     }
    196     $query .=" GROUP BY cat_ID";
    197     if (intval($hide_empty) == 1) $query .= " HAVING cat_count > 0";
    198     $query .= " ORDER BY $sort_column $sort_order, post_date DESC";
    199 
    200     $categories = $wpdb->get_results($query);
    201     echo "<select name='cat' class='postform'>\n";
    202     if (intval($optionall) == 1) {
    203         $all = apply_filters('list_cats', $all);
    204         echo "\t<option value='0'>$all</option>\n";
    205     }
    206     if (intval($optionnone) == 1) echo "\t<option value='-1'>".__('None')."</option>\n";
    207     if ($categories) {
    208         foreach ($categories as $category) {
    209             $cat_name = apply_filters('list_cats', $category->cat_name, $category);
    210             echo "\t<option value=\"".$category->cat_ID."\"";
    211             if ($category->cat_ID == $selected)
    212                 echo ' selected="selected"';
    213             echo '>';
    214             echo $cat_name;
    215             if (intval($optioncount) == 1) echo '&nbsp;&nbsp;('.$category->cat_count.')';
    216             if (intval($optiondates) == 1) echo '&nbsp;&nbsp;'.$category->lastday.'/'.$category->lastmonth;
    217             echo "</option>\n";
    218         }
    219     }
    220     echo "</select>\n";
     181                $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE,
     182                $selected=0, $hide=0) {
     183        global $wpdb;
     184        if ( ($file == 'blah') || ($file == '') )
     185                $file = get_settings('home') . '/';
     186        if ( !$selected )
     187                $selected=$cat;
     188        $sort_column = 'cat_'.$sort_column;
     189
     190        $query = "
     191                SELECT cat_ID, cat_name, category_nicename,category_parent,
     192                COUNT($wpdb->post2cat.post_id) AS cat_count,
     193                DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
     194                FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id)
     195                LEFT JOIN $wpdb->posts ON (ID = post_id)
     196                WHERE cat_ID > 0
     197                ";
     198        if ( $hide ) {
     199                $query .= " AND cat_ID != $hide";
     200                $query .= get_category_children($hide, " AND cat_ID != ");
     201        }
     202        $query .=" GROUP BY cat_ID";
     203        if ( intval($hide_empty) == 1 )
     204                $query .= " HAVING cat_count > 0";
     205        $query .= " ORDER BY $sort_column $sort_order, post_date DESC";
     206
     207        $categories = $wpdb->get_results($query);
     208        echo "<select name='cat' class='postform'>\n";
     209        if ( intval($optionall) == 1 ) {
     210                $all = apply_filters('list_cats', $all);
     211                echo "\t<option value='0'>$all</option>\n";
     212        }
     213        if ( intval($optionnone) == 1 )
     214                echo "\t<option value='-1'>".__('None')."</option>\n";
     215        if ( $categories ) {
     216                foreach ( $categories as $category ) {
     217                        $cat_name = apply_filters('list_cats', $category->cat_name, $category);
     218                        echo "\t<option value=\"".$category->cat_ID."\"";
     219                        if ( $category->cat_ID == $selected )
     220                                echo ' selected="selected"';
     221                        echo '>';
     222                        echo $cat_name;
     223                        if ( intval($optioncount) == 1 )
     224                                echo '&nbsp;&nbsp;('.$category->cat_count.')';
     225                        if ( intval($optiondates) == 1 )
     226                                echo '&nbsp;&nbsp;'.$category->lastday.'/'.$category->lastmonth;
     227                        echo "</option>\n";
     228                }
     229        }
     230        echo "</select>\n";
    221231}
    222232
    … …  
    224234function wp_list_cats($args = '') {
    225235        parse_str($args, $r);
    226         if (!isset($r['optionall'])) $r['optionall'] = 0;
    227     if (!isset($r['all'])) $r['all'] = 'All';
    228         if (!isset($r['sort_column'])) $r['sort_column'] = 'ID';
    229         if (!isset($r['sort_order'])) $r['sort_order'] = 'asc';
    230         if (!isset($r['file'])) $r['file'] = '';
    231         if (!isset($r['list'])) $r['list'] = true;
    232         if (!isset($r['optiondates'])) $r['optiondates'] = 0;
    233         if (!isset($r['optioncount'])) $r['optioncount'] = 0;
    234         if (!isset($r['hide_empty'])) $r['hide_empty'] = 1;
    235         if (!isset($r['use_desc_for_title'])) $r['use_desc_for_title'] = 1;
    236         if (!isset($r['children'])) $r['children'] = true;
    237         if (!isset($r['child_of'])) $r['child_of'] = 0;
    238         if (!isset($r['categories'])) $r['categories'] = 0;
    239         if (!isset($r['recurse'])) $r['recurse'] = 0;
    240         if (!isset($r['feed'])) $r['feed'] = '';
    241         if (!isset($r['feed_image'])) $r['feed_image'] = '';
    242         if (!isset($r['exclude'])) $r['exclude'] = '';
    243         if (!isset($r['hierarchical'])) $r['hierarchical'] = true;
     236        if ( !isset($r['optionall']))
     237                $r['optionall'] = 0;
     238        if ( !isset($r['all']))
     239                $r['all'] = 'All';
     240        if ( !isset($r['sort_column']) )
     241                $r['sort_column'] = 'ID';
     242        if ( !isset($r['sort_order']) )
     243                $r['sort_order'] = 'asc';
     244        if ( !isset($r['file']) )
     245                $r['file'] = '';
     246        if ( !isset($r['list']) )
     247                $r['list'] = true;
     248        if ( !isset($r['optiondates']) )
     249                $r['optiondates'] = 0;
     250        if ( !isset($r['optioncount']) )
     251                $r['optioncount'] = 0;
     252        if ( !isset($r['hide_empty']) )
     253                $r['hide_empty'] = 1;
     254        if ( !isset($r['use_desc_for_title']) )
     255                $r['use_desc_for_title'] = 1;
     256        if ( !isset($r['children']) )
     257                $r['children'] = true;
     258        if ( !isset($r['child_of']) )
     259                $r['child_of'] = 0;
     260        if ( !isset($r['categories']) )
     261                $r['categories'] = 0;
     262        if ( !isset($r['recurse']) )
     263                $r['recurse'] = 0;
     264        if ( !isset($r['feed']) )
     265                $r['feed'] = '';
     266        if ( !isset($r['feed_image']) )
     267                $r['feed_image'] = '';
     268        if ( !isset($r['exclude']) )
     269                $r['exclude'] = '';
     270        if ( !isset($r['hierarchical']) )
     271                $r['hierarchical'] = true;
    244272
    245273        return list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'],   $r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude'], $r['hierarchical']);
    … …  
    249277        global $wpdb, $category_posts;
    250278        // Optiondates now works
    251         if ('' == $file) {
     279        if ( '' == $file )
    252280                $file = get_settings('home') . '/';
    253         }
    254281
    255282        $exclusions = '';
    256         if (!empty($exclude)) {
     283        if ( !empty($exclude) ) {
    257284                $excats = preg_split('/[\s,]+/',$exclude);
    258                 if (count($excats)) {
    259                         foreach ($excats as $excat) {
     285                if ( count($excats) ) {
     286                        foreach ( $excats as $excat ) {
    260287                                $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
    261288                        }
    … …  
    265292        $exclusions = apply_filters('list_cats_exclusions', $exclusions );
    266293
    267         if (intval($categories)==0){
     294        if ( intval($categories) == 0 ) {
    268295                $sort_column = 'cat_'.$sort_column;
    269296
    270                 $query  = "
     297                $query = "
    271298                        SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
    272299                        FROM $wpdb->categories
    … …  
    276303                $categories = $wpdb->get_results($query);
    277304        }
    278         if (!count($category_posts)) {
     305        if ( !count($category_posts) ) {
    279306                $now = current_time('mysql', 1);
    280307                $cat_counts = $wpdb->get_results("      SELECT cat_ID,
    281308                COUNT($wpdb->post2cat.post_id) AS cat_count
    282                 FROM $wpdb->categories 
     309                FROM $wpdb->categories
    283310                INNER JOIN $wpdb->post2cat ON (cat_ID = category_id)
    284311                INNER JOIN $wpdb->posts ON (ID = post_id)
    … …  
    286313                AND post_date_gmt < '$now' $exclusions
    287314                GROUP BY category_id");
    288         if (! empty($cat_counts)) {
    289             foreach ($cat_counts as $cat_count) {
    290                 if (1 != intval($hide_empty) || $cat_count > 0) {
    291                     $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count;
    292                 }
    293             }
    294         }
    295         }
    296        
     315                if ( !empty($cat_counts) ) {
     316                        foreach ( $cat_counts as $cat_count ) {
     317                                if ( 1 != intval($hide_empty) || $cat_count > 0 )
     318                                        $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count;
     319                        }
     320                }
     321        }
     322
    297323        if ( $optiondates ) {
    298324                $cat_dates = $wpdb->get_results("       SELECT category_id,
    299325                UNIX_TIMESTAMP( MAX(post_date) ) AS ts
    300                 FROM $wpdb->posts, $wpdb->post2cat,  $wpdb->categories
     326                FROM $wpdb->posts, $wpdb->post2cat, $wpdb->categories
    301327                WHERE post_status = 'publish' AND post_id = ID $exclusions
    302328                GROUP BY category_id");
    303                 foreach ($cat_dates as $cat_date) {
     329                foreach ( $cat_dates as $cat_date ) {
    304330                        $category_timestamp["$cat_date->category_id"] = $cat_date->ts;
    305331                }
    306332        }
    307        
     333
    308334        $num_found=0;
    309335        $thelist = "";
    310        
    311         foreach ($categories as $category) {
    312                 if ((intval($hide_empty) == 0 || isset($category_posts["$category->cat_ID"])) && (!$hierarchical || $category->category_parent == $child_of) ) {
     336
     337        foreach ( $categories as $category ) {
     338                if ( (intval($hide_empty) == 0 || isset($category_posts["$category->cat_ID"])) && (!$hierarchical || $category->category_parent == $child_of) ) {
    313339                        $num_found++;
    314340                        $link = '<a href="'.get_category_link($category->cat_ID).'" ';
    315                         if ($use_desc_for_title == 0 || empty($category->category_description)) {
     341                        if ( $use_desc_for_title == 0 || empty($category->category_description) )
    316342                                $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"';
    317                         } else {
     343                        else
    318344                                $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"';
    319                         }
    320345                        $link .= '>';
    321346                        $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>';
    322347
    323348                        if ( (! empty($feed_image)) || (! empty($feed)) ) {
    324                                
     349
    325350                                $link .= ' ';
    326351
    327                                 if (empty($feed_image)) {
     352                                if ( empty($feed_image) )
    328353                                        $link .= '(';
    329                                 }
    330 
    331                                 $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename)  . '"';
     354
     355                                $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
    332356
    333357                                if ( !empty($feed) ) {
    334                                         $title =  ' title="' . $feed . '"';
     358                                        $title = ' title="' . $feed . '"';
    335359                                        $alt = ' alt="' . $feed . '"';
    336360                                        $name = $feed;
    … …  
    340364                                $link .= '>';
    341365
    342                                 if (! empty($feed_image)) {
     366                                if ( !empty($feed_image) )
    343367                                        $link .= "<img src='$feed_image' $alt$title" . ' />';
    344                                 } else {
     368                                else
    345369                                        $link .= $name;
    346                                 }
    347                                
     370
    348371                                $link .= '</a>';
    349372
    350                                 if (empty($feed_image)) {
     373                                if (empty($feed_image))
    351374                                        $link .= ')';
    352                                 }
    353                         }
    354 
    355                         if (intval($optioncount) == 1) {
     375                        }
     376
     377                        if ( intval($optioncount) == 1 )
    356378                                $link .= ' ('.intval($category_posts["$category->cat_ID"]).')';
    357                         }
     379
    358380                        if ( $optiondates ) {
    359                                 if ( $optiondates == 1 ) $optiondates = 'Y-m-d';
     381                                if ( $optiondates == 1 )
     382                                        $optiondates = 'Y-m-d';
    360383                                $link .= ' ' . gmdate($optiondates, $category_timestamp["$category->cat_ID"]);
    361384                        }
    362                         if ($list) {
     385
     386                        if ( $list )
    363387                                $thelist .= "\t<li>$link\n";
    364                         } else {
     388                        else
    365389                                $thelist .= "\t$link<br />\n";
    366                         }
    367                         if ($hierarchical && $children) $thelist .= list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical);
    368                         if ($list) $thelist .= "</li>\n";
    369                         }
    370         }
    371         if (!$num_found && !$child_of){
    372                 if ($list) {
     390
     391                        if ($hierarchical && $children)
     392                                $thelist .= list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical);
     393                        if ($list)
     394                                $thelist .= "</li>\n";
     395                }
     396        }
     397        if ( !$num_found && !$child_of ) {
     398                if ( $list ) {
    373399                        $before = '<li>';
    374400                        $after = '</li>';
    … …  
    377403                return;
    378404        }
    379         if ($list && $child_of && $num_found && $recurse) {
     405        if ( $list && $child_of && $num_found && $recurse ) {
    380406                $pre = "\t\t<ul class='children'>";
    381407                $post = "\t\t</ul>\n";
    … …  
    384410        }
    385411        $thelist = $pre . $thelist . $post;
    386         if ($recurse) {
     412        if ( $recurse )
    387413                return $thelist;
    388         }
    389414        echo apply_filters('list_cats', $thelist);
    390415}
    … …  
    393418        global $post, $category_cache;
    394419        $cats = '';
    395         foreach ($category_cache[$post->ID] as $cat) :
     420        foreach ( $category_cache[$post->ID] as $cat ) {
    396421                $cats[] = $cat->cat_ID;
    397         endforeach;
     422        }
    398423
    399424        if ( in_array($category, $cats) )
Note: See TracChangeset for help on using the changeset viewer.