]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/template-functions-general.php
Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-includes / template-functions-general.php
index b52b4167b8adf0d252efe6ed93295e6f1b42fcfc..bc7ee04d2d06fb78dfd84f57eab255ea219ab6fe 100644 (file)
@@ -27,10 +27,7 @@ function get_sidebar() {
 
 
 function wp_loginout() {
-       global $user_ID;
-       get_currentuserinfo();
-
-       if ('' == $user_ID)
+       if ( ! is_user_logged_in() )
                $link = '<a href="' . get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
        else
                $link = '<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
@@ -40,16 +37,15 @@ function wp_loginout() {
 
 
 function wp_register( $before = '<li>', $after = '</li>' ) {
-       global $user_ID;
-
-       get_currentuserinfo();
 
-       if ( '' == $user_ID && get_settings('users_can_register') )
-               $link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
-       elseif ( '' == $user_ID && !get_settings('users_can_register') )
-               $link = '';
-       else
+       if ( ! is_user_logged_in() ) {
+               if ( get_settings('users_can_register') )
+                       $link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
+               else
+                       $link = '';
+       } else {
                $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
+       }
 
        echo apply_filters('register', $link);
 }
@@ -62,9 +58,13 @@ function wp_meta() {
 
 function bloginfo($show='') {
        $info = get_bloginfo($show);
-       if ( ! (strstr($info, 'url') || strstr($info, 'directory')) ) {
+       if (!strstr($show, 'url') && //don't filter URLs
+               !strstr($show, 'directory') &&
+               !strstr($show, 'home')) {
                $info = apply_filters('bloginfo', $info, $show);
                $info = convert_chars($info);
+       } else {
+               $info = apply_filters('bloginfo_url', $info, $show);
        }
 
        echo $info;
@@ -137,8 +137,7 @@ function get_bloginfo($show='') {
 
 
 function wp_title($sep = '&raquo;', $display = true) {
-       global $wpdb;
-       global $m, $year, $monthnum, $day, $category_name, $month, $posts;
+       global $wpdb, $posts, $month;
 
        $cat = get_query_var('cat');
        $p = get_query_var('p');
@@ -146,14 +145,18 @@ function wp_title($sep = '&raquo;', $display = true) {
        $category_name = get_query_var('category_name');
        $author = get_query_var('author');
        $author_name = get_query_var('author_name');
+       $m = (int) get_query_var('m');
+       $year = (int) get_query_var('year');
+       $monthnum = (int) get_query_var('monthnum');
+       $day = (int) get_query_var('day');
+       $title = '';
 
        // If there's a category
        if ( !empty($cat) ) {
                        // category exclusion
                        if ( !stristr($cat,'-') )
-                               $title = get_the_category_by_ID($cat);
-       }
-       if ( !empty($category_name) ) {
+                               $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
+       } elseif ( !empty($category_name) ) {
                if ( stristr($category_name,'/') ) {
                                $category_name = explode('/',$category_name);
                                if ( $category_name[count($category_name)-1] )
@@ -162,6 +165,7 @@ function wp_title($sep = '&raquo;', $display = true) {
                                        $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
                }
                $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
+               $title = apply_filters('single_cat_title', $title);
        }
 
        // If there's an author
@@ -196,7 +200,7 @@ function wp_title($sep = '&raquo;', $display = true) {
        }
 
        $prefix = '';
-       if ( isset($title) )
+       if ( !empty($title) )
                $prefix = " $sep ";
 
        $title = $prefix . $title;
@@ -244,7 +248,12 @@ function single_cat_title($prefix = '', $display = true ) {
 
 
 function single_month_title($prefix = '', $display = true ) {
-       global $m, $monthnum, $month, $year;
+       global $month;
+
+       $m = (int) get_query_var('m');
+       $year = (int) get_query_var('year');
+       $monthnum = (int) get_query_var('monthnum');
+
        if ( !empty($monthnum) && !empty($year) ) {
                $my_year = $year;
                $my_month = $month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
@@ -263,7 +272,7 @@ function single_month_title($prefix = '', $display = true ) {
 /* link navigation hack by Orien http://icecode.com/ */
 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
        $text = wptexturize($text);
-       $title_text = wp_specialchars($text, 1);
+       $title_text = attribute_escape($text);
 
        if ('link' == $format)
                return "\t<link rel='archives' title='$title_text' href='$url' />\n";
@@ -336,10 +345,10 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
                        foreach ( $arcresults as $arcresult ) {
                                $url    = get_month_link($arcresult->year,      $arcresult->month);
                                if ( $show_post_count ) {
-                                       $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
+                                       $text = sprintf(__('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);
                                        $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
                                } else {
-                                       $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
+                                       $text = sprintf(__('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);
                                }
                                echo get_archives_link($url, $text, $format, $before, $after);
                        }
@@ -349,7 +358,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
                if ( $arcresults ) {
                        foreach ( $arcresults as $arcresult ) {
                                $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
-                               $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
+                               $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
                                $text = mysql2date($archive_day_date_format, $date);
                                echo get_archives_link($url, $text, $format, $before, $after);
                        }
@@ -366,7 +375,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
                                                $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week'));
                                                $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
                                                $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
-                                               $url  = sprintf('%s/%s%sm%s%s%sw%s%d', get_settings('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
+                                               $url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_settings('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
                                                $text = $arc_week_start . $archive_week_separator . $arc_week_end;
                                                echo get_archives_link($url, $text, $format, $before, $after);
                                        }
@@ -401,9 +410,11 @@ function calendar_week_mod($num) {
 function get_calendar($daylength = 1) {
        global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
 
-       // Quick check. If we have no posts at all, abort!
+       $now = current_time('mysql');
+
+       // Quick check. If we have no posts yet published, abort!
        if ( !$posts ) {
-               $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
+               $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now' ORDER BY post_date DESC LIMIT 1");
                if ( !$gotsome )
                        return;
        }
@@ -433,8 +444,8 @@ function get_calendar($daylength = 1) {
                else
                                $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
        } else {
-               $thisyear = gmdate('Y', current_time('timestamp') + get_settings('gmt_offset') * 3600);
-               $thismonth = gmdate('m', current_time('timestamp') + get_settings('gmt_offset') * 3600);
+               $thisyear = gmdate('Y', current_time('timestamp'));
+               $thismonth = gmdate('m', current_time('timestamp'));
        }
 
        $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
@@ -449,6 +460,7 @@ function get_calendar($daylength = 1) {
        $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
                FROM $wpdb->posts
                WHERE post_date >       '$thisyear-$thismonth-01'
+               AND post_date < '$now'
                AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
                AND post_status = 'publish' 
                        ORDER   BY post_date ASC
@@ -507,8 +519,8 @@ function get_calendar($daylength = 1) {
 
        // Get days with posts
        $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
-               FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
-               AND YEAR(post_date) = $thisyear
+               FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
+               AND YEAR(post_date) = '$thisyear'
                AND post_status = 'publish'
                AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
        if ( $dayswithposts ) {