]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/template-functions-general.php
Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-includes / template-functions-general.php
1 <?php
2
3 /* Note: these tags go anywhere in the template */
4
5 function get_header() {
6         if ( file_exists( TEMPLATEPATH . '/header.php') )
7                 load_template( TEMPLATEPATH . '/header.php');
8         else
9                 load_template( ABSPATH . 'wp-content/themes/default/header.php');
10 }
11
12
13 function get_footer() {
14         if ( file_exists( TEMPLATEPATH . '/footer.php') )
15                 load_template( TEMPLATEPATH . '/footer.php');
16         else
17                 load_template( ABSPATH . 'wp-content/themes/default/footer.php');
18 }
19
20
21 function get_sidebar() {
22         if ( file_exists( TEMPLATEPATH . '/sidebar.php') )
23                 load_template( TEMPLATEPATH . '/sidebar.php');
24         else
25                 load_template( ABSPATH . 'wp-content/themes/default/sidebar.php');
26 }
27
28
29 function wp_loginout() {
30         if ( ! is_user_logged_in() )
31                 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
32         else
33                 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
34
35         echo apply_filters('loginout', $link);
36 }
37
38
39 function wp_register( $before = '<li>', $after = '</li>' ) {
40
41         if ( ! is_user_logged_in() ) {
42                 if ( get_settings('users_can_register') )
43                         $link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
44                 else
45                         $link = '';
46         } else {
47                 $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
48         }
49
50         echo apply_filters('register', $link);
51 }
52
53
54 function wp_meta() {
55         do_action('wp_meta');
56 }
57
58
59 function bloginfo($show='') {
60         $info = get_bloginfo($show);
61         if (!strstr($show, 'url') && //don't filter URLs
62                 !strstr($show, 'directory') &&
63                 !strstr($show, 'home')) {
64                 $info = apply_filters('bloginfo', $info, $show);
65                 $info = convert_chars($info);
66         } else {
67                 $info = apply_filters('bloginfo_url', $info, $show);
68         }
69
70         echo $info;
71 }
72
73
74 function get_bloginfo($show='') {
75
76         switch($show) {
77                 case 'url' :
78                 case 'home' :
79                 case 'siteurl' :
80                         $output = get_settings('home');
81                         break;
82                 case 'wpurl' :
83                         $output = get_settings('siteurl');
84                         break;
85                 case 'description':
86                         $output = get_settings('blogdescription');
87                         break;
88                 case 'rdf_url':
89                         $output = get_feed_link('rdf');
90                         break;
91                 case 'rss_url':
92                         $output = get_feed_link('rss');
93                         break;
94                 case 'rss2_url':
95                         $output = get_feed_link('rss2');
96                         break;
97                 case 'atom_url':
98                         $output = get_feed_link('atom');
99                         break;
100                 case 'comments_rss2_url':
101                         $output = get_feed_link('comments_rss2');
102                         break;
103                 case 'pingback_url':
104                         $output = get_settings('siteurl') .'/xmlrpc.php';
105                         break;
106                 case 'stylesheet_url':
107                         $output = get_stylesheet_uri();
108                         break;
109                 case 'stylesheet_directory':
110                         $output = get_stylesheet_directory_uri();
111                         break;
112                 case 'template_directory':
113                 case 'template_url':
114                         $output = get_template_directory_uri();
115                         break;
116                 case 'admin_email':
117                         $output = get_settings('admin_email');
118                         break;
119                 case 'charset':
120                         $output = get_settings('blog_charset');
121                         if ('' == $output) $output = 'UTF-8';
122                         break;
123                 case 'html_type' :
124                         $output = get_option('html_type');
125                         break;
126                 case 'version':
127                         global $wp_version;
128                         $output = $wp_version;
129                         break;
130                 case 'name':
131                 default:
132                         $output = get_settings('blogname');
133                         break;
134         }
135         return $output;
136 }
137
138
139 function wp_title($sep = '&raquo;', $display = true) {
140         global $wpdb, $posts, $month;
141
142         $cat = get_query_var('cat');
143         $p = get_query_var('p');
144         $name = get_query_var('name');
145         $category_name = get_query_var('category_name');
146         $author = get_query_var('author');
147         $author_name = get_query_var('author_name');
148         $m = (int) get_query_var('m');
149         $year = (int) get_query_var('year');
150         $monthnum = (int) get_query_var('monthnum');
151         $day = (int) get_query_var('day');
152         $title = '';
153
154         // If there's a category
155         if ( !empty($cat) ) {
156                         // category exclusion
157                         if ( !stristr($cat,'-') )
158                                 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
159         } elseif ( !empty($category_name) ) {
160                 if ( stristr($category_name,'/') ) {
161                                 $category_name = explode('/',$category_name);
162                                 if ( $category_name[count($category_name)-1] )
163                                         $category_name = $category_name[count($category_name)-1]; // no trailing slash
164                                 else
165                                         $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
166                 }
167                 $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
168                 $title = apply_filters('single_cat_title', $title);
169         }
170
171         // If there's an author
172         if ( !empty($author) ) {
173                 $title = get_userdata($author);
174                 $title = $title->display_name;
175         }
176         if ( !empty($author_name) ) {
177                 // We do a direct query here because we don't cache by nicename.
178                 $title = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE user_nicename = '$author_name'");
179         }
180
181         // If there's a month
182         if ( !empty($m) ) {
183                 $my_year = substr($m, 0, 4);
184                 $my_month = $month[substr($m, 4, 2)];
185                 $title = "$my_year $sep $my_month";
186         }
187
188         if ( !empty($year) ) {
189                 $title = $year;
190                 if ( !empty($monthnum) )
191                         $title .= " $sep ".$month[zeroise($monthnum, 2)];
192                 if ( !empty($day) )
193                         $title .= " $sep ".zeroise($day, 2);
194         }
195
196         // If there is a post
197         if ( is_single() || is_page() ) {
198                 $title = strip_tags($posts[0]->post_title);
199                 $title = apply_filters('single_post_title', $title);
200         }
201
202         $prefix = '';
203         if ( !empty($title) )
204                 $prefix = " $sep ";
205
206         $title = $prefix . $title;
207         $title = apply_filters('wp_title', $title, $sep);
208
209         // Send it out
210         if ( $display )
211                 echo $title;
212         else
213                 return $title;
214 }
215
216
217 function single_post_title($prefix = '', $display = true) {
218         global $wpdb;
219         $p = get_query_var('p');
220         $name = get_query_var('name');
221
222         if ( intval($p) || '' != $name ) {
223                 if ( !$p )
224                         $p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'");
225                 $post = & get_post($p);
226                 $title = $post->post_title;
227                 $title = apply_filters('single_post_title', $title);
228                 if ( $display )
229                         echo $prefix.strip_tags($title);
230                 else
231                         return strip_tags($title);
232         }
233 }
234
235
236 function single_cat_title($prefix = '', $display = true ) {
237         $cat = intval( get_query_var('cat') );
238         if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
239                 $my_cat_name = get_the_category_by_ID($cat);
240                 if ( !empty($my_cat_name) ) {
241                         if ( $display )
242                                 echo $prefix.strip_tags($my_cat_name);
243                         else
244                                 return strip_tags($my_cat_name);
245                 }
246         }
247 }
248
249
250 function single_month_title($prefix = '', $display = true ) {
251         global $month;
252
253         $m = (int) get_query_var('m');
254         $year = (int) get_query_var('year');
255         $monthnum = (int) get_query_var('monthnum');
256
257         if ( !empty($monthnum) && !empty($year) ) {
258                 $my_year = $year;
259                 $my_month = $month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
260         } elseif ( !empty($m) ) {
261                 $my_year = substr($m, 0, 4);
262                 $my_month = $month[substr($m, 4, 2)];
263         }
264
265         if ( !empty($my_month) && $display )
266                 echo $prefix . $my_month . $prefix . $my_year;
267         else
268                 return $monthnum;
269 }
270
271
272 /* link navigation hack by Orien http://icecode.com/ */
273 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
274         $text = wptexturize($text);
275         $title_text = attribute_escape($text);
276
277         if ('link' == $format)
278                 return "\t<link rel='archives' title='$title_text' href='$url' />\n";
279         elseif ('option' == $format)
280                 return "\t<option value='$url'>$before $text $after</option>\n";
281         elseif ('html' == $format)
282                 return "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
283         else // custom
284                 return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
285 }
286
287
288 function wp_get_archives($args = '') {
289         parse_str($args, $r);
290         if ( !isset($r['type']) )
291                 $r['type'] = '';
292         if ( !isset($r['limit']) )
293                 $r['limit'] = '';
294         if ( !isset($r['format']) )
295                 $r['format'] = 'html';
296         if ( !isset($r['before']) )
297                 $r['before'] = '';
298         if ( !isset($r['after']) )
299                 $r['after'] = '';
300         if ( !isset($r['show_post_count']) )
301                 $r['show_post_count'] = false;
302
303         get_archives($r['type'], $r['limit'], $r['format'], $r['before'], $r['after'], $r['show_post_count']);
304 }
305
306
307 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
308         global $month, $wpdb;
309
310         if ( '' == $type )
311                 $type = 'monthly';
312
313         if ( '' != $limit ) {
314                 $limit = (int) $limit;
315                 $limit = ' LIMIT '.$limit;
316         }
317         // this is what will separate dates on weekly archive links
318         $archive_week_separator = '&#8211;';
319
320         // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
321         $archive_date_format_over_ride = 0;
322
323         // options for daily archive (only if you over-ride the general date format)
324         $archive_day_date_format = 'Y/m/d';
325
326         // options for weekly archive (only if you over-ride the general date format)
327         $archive_week_start_date_format = 'Y/m/d';
328         $archive_week_end_date_format   = 'Y/m/d';
329
330         if ( !$archive_date_format_over_ride ) {
331                 $archive_day_date_format = get_settings('date_format');
332                 $archive_week_start_date_format = get_settings('date_format');
333                 $archive_week_end_date_format = get_settings('date_format');
334         }
335
336         $add_hours = intval(get_settings('gmt_offset'));
337         $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
338
339         $now = current_time('mysql');
340
341         if ( 'monthly' == $type ) {
342                 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
343                 if ( $arcresults ) {
344                         $afterafter = $after;
345                         foreach ( $arcresults as $arcresult ) {
346                                 $url    = get_month_link($arcresult->year,      $arcresult->month);
347                                 if ( $show_post_count ) {
348                                         $text = sprintf(__('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);
349                                         $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
350                                 } else {
351                                         $text = sprintf(__('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);
352                                 }
353                                 echo get_archives_link($url, $text, $format, $before, $after);
354                         }
355                 }
356         } elseif ( 'daily' == $type ) {
357                 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
358                 if ( $arcresults ) {
359                         foreach ( $arcresults as $arcresult ) {
360                                 $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
361                                 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
362                                 $text = mysql2date($archive_day_date_format, $date);
363                                 echo get_archives_link($url, $text, $format, $before, $after);
364                         }
365                 }
366         } elseif ( 'weekly' == $type ) {
367                 $start_of_week = get_settings('start_of_week');
368                 $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
369                 $arc_w_last = '';
370                 if ( $arcresults ) {
371                                 foreach ( $arcresults as $arcresult ) {
372                                         if ( $arcresult->week != $arc_w_last ) {
373                                                 $arc_year = $arcresult->yr;
374                                                 $arc_w_last = $arcresult->week;
375                                                 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week'));
376                                                 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
377                                                 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
378                                                 $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);
379                                                 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
380                                                 echo get_archives_link($url, $text, $format, $before, $after);
381                                         }
382                                 }
383                 }
384         } elseif ( 'postbypost' == $type ) {
385                 $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
386                 if ( $arcresults ) {
387                         foreach ( $arcresults as $arcresult ) {
388                                 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
389                                         $url  = get_permalink($arcresult);
390                                         $arc_title = $arcresult->post_title;
391                                         if ( $arc_title )
392                                                 $text = strip_tags($arc_title);
393                                         else
394                                                 $text = $arcresult->ID;
395                                         echo get_archives_link($url, $text, $format, $before, $after);
396                                 }
397                         }
398                 }
399         }
400 }
401
402
403 // Used in get_calendar
404 function calendar_week_mod($num) {
405         $base = 7;
406         return ($num - $base*floor($num/$base));
407 }
408
409
410 function get_calendar($daylength = 1) {
411         global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
412
413         $now = current_time('mysql');
414
415         // Quick check. If we have no posts yet published, abort!
416         if ( !$posts ) {
417                 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now' ORDER BY post_date DESC LIMIT 1");
418                 if ( !$gotsome )
419                         return;
420         }
421
422         if ( isset($_GET['w']) )
423                 $w = ''.intval($_GET['w']);
424
425         // week_begins = 0 stands for Sunday
426         $week_begins = intval(get_settings('start_of_week'));
427         $add_hours = intval(get_settings('gmt_offset'));
428         $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
429
430         // Let's figure out when we are
431         if ( !empty($monthnum) && !empty($year) ) {
432                 $thismonth = ''.zeroise(intval($monthnum), 2);
433                 $thisyear = ''.intval($year);
434         } elseif ( !empty($w) ) {
435                 // We need to get the month from MySQL
436                 $thisyear = ''.intval(substr($m, 0, 4));
437                 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
438                 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
439         } elseif ( !empty($m) ) {
440                 $calendar = substr($m, 0, 6);
441                 $thisyear = ''.intval(substr($m, 0, 4));
442                 if ( strlen($m) < 6 )
443                                 $thismonth = '01';
444                 else
445                                 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
446         } else {
447                 $thisyear = gmdate('Y', current_time('timestamp'));
448                 $thismonth = gmdate('m', current_time('timestamp'));
449         }
450
451         $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
452
453         // Get the next and previous month and year with at least one post
454         $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
455                 FROM $wpdb->posts
456                 WHERE post_date < '$thisyear-$thismonth-01'
457                 AND post_status = 'publish'
458                         ORDER BY post_date DESC
459                         LIMIT 1");
460         $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
461                 FROM $wpdb->posts
462                 WHERE post_date >       '$thisyear-$thismonth-01'
463                 AND post_date < '$now'
464                 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
465                 AND post_status = 'publish' 
466                         ORDER   BY post_date ASC
467                         LIMIT 1");
468
469         echo '<table id="wp-calendar">
470         <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
471         <thead>
472         <tr>';
473
474         $day_abbrev = $weekday_initial;
475         if ( $daylength > 1 )
476                 $day_abbrev = $weekday_abbrev;
477
478         $myweek = array();
479
480         for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
481                 $myweek[]=$weekday[($wdcount+$week_begins)%7];
482         }
483
484         foreach ( $myweek as $wd ) {
485                 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
486         }
487
488         echo '
489         </tr>
490         </thead>
491
492         <tfoot>
493         <tr>';
494
495         if ( $previous ) {
496                 echo "\n\t\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
497                 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($previous->month, 2)],
498                         date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $month_abbrev[$month[zeroise($previous->month, 2)]] . '</a></td>';
499         } else {
500                 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
501         }
502
503         echo "\n\t\t".'<td class="pad">&nbsp;</td>';
504
505         if ( $next ) {
506                 echo "\n\t\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
507                 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($next->month, 2)],
508                         date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $month_abbrev[$month[zeroise($next->month, 2)]] . ' &raquo;</a></td>';
509         } else {
510                 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
511         }
512
513         echo '
514         </tr>
515         </tfoot>
516
517         <tbody>
518         <tr>';
519
520         // Get days with posts
521         $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
522                 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
523                 AND YEAR(post_date) = '$thisyear'
524                 AND post_status = 'publish'
525                 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
526         if ( $dayswithposts ) {
527                 foreach ( $dayswithposts as $daywith ) {
528                         $daywithpost[] = $daywith[0];
529                 }
530         } else {
531                 $daywithpost = array();
532         }
533
534
535
536         if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') )
537                 $ak_title_separator = "\n";
538         else
539                 $ak_title_separator = ', ';
540
541         $ak_titles_for_day = array();
542         $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
543                 ."FROM $wpdb->posts "
544                 ."WHERE YEAR(post_date) = '$thisyear' "
545                 ."AND MONTH(post_date) = '$thismonth' "
546                 ."AND post_date < '".current_time('mysql')."' "
547                 ."AND post_status = 'publish'"
548         );
549         if ( $ak_post_titles ) {
550                 foreach ( $ak_post_titles as $ak_post_title ) {
551                                 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
552                                         $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
553                                 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
554                                         $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
555                                 else
556                                         $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
557                 }
558         }
559
560
561         // See how much we should pad in the beginning
562         $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
563         if ( 0 != $pad )
564                 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
565
566         $daysinmonth = intval(date('t', $unixmonth));
567         for ( $day = 1; $day <= $daysinmonth; ++$day ) {
568                 if ( isset($newrow) && $newrow )
569                         echo "\n\t</tr>\n\t<tr>\n\t\t";
570                 $newrow = false;
571
572                 if ( $day == gmdate('j', (time() + (get_settings('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_settings('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_settings('gmt_offset') * 3600)) )
573                         echo '<td id="today">';
574                 else
575                         echo '<td>';
576
577                 if ( in_array($day, $daywithpost) ) // any posts today?
578                                 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
579                 else
580                         echo $day;
581                 echo '</td>';
582
583                 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
584                         $newrow = true;
585         }
586
587         $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
588         if ( $pad != 0 && $pad != 7 )
589                 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
590
591         echo "\n\t</tr>\n\t</tbody>\n\t</table>";
592 }
593
594
595 function allowed_tags() {
596         global $allowedtags;
597         $allowed = '';
598         foreach ( $allowedtags as $tag => $attributes ) {
599                 $allowed .= '<'.$tag;
600                 if ( 0 < count($attributes) ) {
601                         foreach ( $attributes as $attribute => $limits ) {
602                                 $allowed .= ' '.$attribute.'=""';
603                         }
604                 }
605                 $allowed .= '> ';
606         }
607         return htmlentities($allowed);
608 }
609
610
611 /***** Date/Time tags *****/
612
613
614 function the_date_xml() {
615         global $post;
616         echo mysql2date('Y-m-d', $post->post_date);
617         //echo ""+$post->post_date;
618 }
619
620
621 function the_date($d='', $before='', $after='', $echo = true) {
622         global $id, $post, $day, $previousday, $newday;
623         $the_date = '';
624         if ( $day != $previousday ) {
625                 $the_date .= $before;
626                 if ( $d=='' )
627                         $the_date .= mysql2date(get_settings('date_format'), $post->post_date);
628                 else
629                         $the_date .= mysql2date($d, $post->post_date);
630                 $the_date .= $after;
631                 $previousday = $day;
632         }
633         $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
634         if ( $echo )
635                 echo $the_date;
636         else
637                 return $the_date;
638 }
639
640
641 function the_time( $d = '' ) {
642         echo apply_filters('the_time', get_the_time( $d ), $d);
643 }
644
645
646 function get_the_time( $d = '' ) {
647         if ( '' == $d )
648                 $the_time = get_post_time(get_settings('time_format'));
649         else
650                 $the_time = get_post_time($d);
651         return apply_filters('get_the_time', $the_time, $d);
652 }
653
654
655 function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
656         global $post;
657         if ( $gmt )
658                 $time = $post->post_date_gmt;
659         else
660                 $time = $post->post_date;
661
662         $time = mysql2date($d, $time);
663         return apply_filters('get_the_time', $time, $d, $gmt);
664 }
665
666
667 function the_modified_time($d = '') {
668         echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
669 }
670
671
672 function get_the_modified_time($d = '') {
673         if ( '' == $d )
674                 $the_time = get_post_modified_time(get_settings('time_format'));
675         else
676                 $the_time = get_post_modified_time($d);
677         return apply_filters('get_the_modified_time', $the_time, $d);
678 }
679
680
681 function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
682         global $post;
683
684         if ( $gmt )
685                 $time = $post->post_modified_gmt;
686         else
687                 $time = $post->post_modified;
688         $time = mysql2date($d, $time);
689
690         return apply_filters('get_the_modified_time', $time, $d, $gmt);
691 }
692
693
694 function the_weekday() {
695         global $weekday, $id, $post;
696         $the_weekday = $weekday[mysql2date('w', $post->post_date)];
697         $the_weekday = apply_filters('the_weekday', $the_weekday);
698         echo $the_weekday;
699 }
700
701
702 function the_weekday_date($before='',$after='') {
703         global $weekday, $id, $post, $day, $previousweekday;
704         $the_weekday_date = '';
705         if ( $day != $previousweekday ) {
706                 $the_weekday_date .= $before;
707                 $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)];
708                 $the_weekday_date .= $after;
709                 $previousweekday = $day;
710         }
711         $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
712         echo $the_weekday_date;
713 }
714
715 function rsd_link() {
716         echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
717 }
718
719 ?>