3 /* Note: these tags go anywhere in the template */
5 function get_header() {
6 if ( file_exists( TEMPLATEPATH . '/header.php') )
7 load_template( TEMPLATEPATH . '/header.php');
9 load_template( ABSPATH . 'wp-content/themes/default/header.php');
13 function get_footer() {
14 if ( file_exists( TEMPLATEPATH . '/footer.php') )
15 load_template( TEMPLATEPATH . '/footer.php');
17 load_template( ABSPATH . 'wp-content/themes/default/footer.php');
21 function get_sidebar() {
22 if ( file_exists( TEMPLATEPATH . '/sidebar.php') )
23 load_template( TEMPLATEPATH . '/sidebar.php');
25 load_template( ABSPATH . 'wp-content/themes/default/sidebar.php');
29 function wp_loginout() {
31 get_currentuserinfo();
34 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
36 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
38 echo apply_filters('loginout', $link);
42 function wp_register( $before = '<li>', $after = '</li>' ) {
45 get_currentuserinfo();
47 if ( '' == $user_ID && get_settings('users_can_register') )
48 $link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
49 elseif ( '' == $user_ID && !get_settings('users_can_register') )
52 $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
54 echo apply_filters('register', $link);
63 function bloginfo($show='') {
64 $info = get_bloginfo($show);
65 if ( ! (strstr($info, 'url') || strstr($info, 'directory')) ) {
66 $info = apply_filters('bloginfo', $info, $show);
67 $info = convert_chars($info);
74 function get_bloginfo($show='') {
80 $output = get_settings('home');
83 $output = get_settings('siteurl');
86 $output = get_settings('blogdescription');
89 $output = get_feed_link('rdf');
92 $output = get_feed_link('rss');
95 $output = get_feed_link('rss2');
98 $output = get_feed_link('atom');
100 case 'comments_rss2_url':
101 $output = get_feed_link('comments_rss2');
104 $output = get_settings('siteurl') .'/xmlrpc.php';
106 case 'stylesheet_url':
107 $output = get_stylesheet_uri();
109 case 'stylesheet_directory':
110 $output = get_stylesheet_directory_uri();
112 case 'template_directory':
114 $output = get_template_directory_uri();
117 $output = get_settings('admin_email');
120 $output = get_settings('blog_charset');
121 if ('' == $output) $output = 'UTF-8';
124 $output = get_option('html_type');
128 $output = $wp_version;
132 $output = get_settings('blogname');
139 function wp_title($sep = '»', $display = true) {
141 global $m, $year, $monthnum, $day, $category_name, $month, $posts;
143 $cat = get_query_var('cat');
144 $p = get_query_var('p');
145 $name = get_query_var('name');
146 $category_name = get_query_var('category_name');
147 $author = get_query_var('author');
148 $author_name = get_query_var('author_name');
150 // If there's a category
151 if ( !empty($cat) ) {
152 // category exclusion
153 if ( !stristr($cat,'-') )
154 $title = get_the_category_by_ID($cat);
156 if ( !empty($category_name) ) {
157 if ( stristr($category_name,'/') ) {
158 $category_name = explode('/',$category_name);
159 if ( $category_name[count($category_name)-1] )
160 $category_name = $category_name[count($category_name)-1]; // no trailing slash
162 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
164 $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
167 // If there's an author
168 if ( !empty($author) ) {
169 $title = get_userdata($author);
170 $title = $title->display_name;
172 if ( !empty($author_name) ) {
173 // We do a direct query here because we don't cache by nicename.
174 $title = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE user_nicename = '$author_name'");
177 // If there's a month
179 $my_year = substr($m, 0, 4);
180 $my_month = $month[substr($m, 4, 2)];
181 $title = "$my_year $sep $my_month";
184 if ( !empty($year) ) {
186 if ( !empty($monthnum) )
187 $title .= " $sep ".$month[zeroise($monthnum, 2)];
189 $title .= " $sep ".zeroise($day, 2);
192 // If there is a post
193 if ( is_single() || is_page() ) {
194 $title = strip_tags($posts[0]->post_title);
195 $title = apply_filters('single_post_title', $title);
202 $title = $prefix . $title;
203 $title = apply_filters('wp_title', $title, $sep);
213 function single_post_title($prefix = '', $display = true) {
215 $p = get_query_var('p');
216 $name = get_query_var('name');
218 if ( intval($p) || '' != $name ) {
220 $p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'");
221 $post = & get_post($p);
222 $title = $post->post_title;
223 $title = apply_filters('single_post_title', $title);
225 echo $prefix.strip_tags($title);
227 return strip_tags($title);
232 function single_cat_title($prefix = '', $display = true ) {
233 $cat = intval( get_query_var('cat') );
234 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
235 $my_cat_name = get_the_category_by_ID($cat);
236 if ( !empty($my_cat_name) ) {
238 echo $prefix.strip_tags($my_cat_name);
240 return strip_tags($my_cat_name);
246 function single_month_title($prefix = '', $display = true ) {
247 global $m, $monthnum, $month, $year;
248 if ( !empty($monthnum) && !empty($year) ) {
250 $my_month = $month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
251 } elseif ( !empty($m) ) {
252 $my_year = substr($m, 0, 4);
253 $my_month = $month[substr($m, 4, 2)];
256 if ( !empty($my_month) && $display )
257 echo $prefix . $my_month . $prefix . $my_year;
263 /* link navigation hack by Orien http://icecode.com/ */
264 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
265 $text = wptexturize($text);
266 $title_text = wp_specialchars($text, 1);
268 if ('link' == $format)
269 return "\t<link rel='archives' title='$title_text' href='$url' />\n";
270 elseif ('option' == $format)
271 return "\t<option value='$url'>$before $text $after</option>\n";
272 elseif ('html' == $format)
273 return "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
275 return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
279 function wp_get_archives($args = '') {
280 parse_str($args, $r);
281 if ( !isset($r['type']) )
283 if ( !isset($r['limit']) )
285 if ( !isset($r['format']) )
286 $r['format'] = 'html';
287 if ( !isset($r['before']) )
289 if ( !isset($r['after']) )
291 if ( !isset($r['show_post_count']) )
292 $r['show_post_count'] = false;
294 get_archives($r['type'], $r['limit'], $r['format'], $r['before'], $r['after'], $r['show_post_count']);
298 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
299 global $month, $wpdb;
304 if ( '' != $limit ) {
305 $limit = (int) $limit;
306 $limit = ' LIMIT '.$limit;
308 // this is what will separate dates on weekly archive links
309 $archive_week_separator = '–';
311 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
312 $archive_date_format_over_ride = 0;
314 // options for daily archive (only if you over-ride the general date format)
315 $archive_day_date_format = 'Y/m/d';
317 // options for weekly archive (only if you over-ride the general date format)
318 $archive_week_start_date_format = 'Y/m/d';
319 $archive_week_end_date_format = 'Y/m/d';
321 if ( !$archive_date_format_over_ride ) {
322 $archive_day_date_format = get_settings('date_format');
323 $archive_week_start_date_format = get_settings('date_format');
324 $archive_week_end_date_format = get_settings('date_format');
327 $add_hours = intval(get_settings('gmt_offset'));
328 $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
330 $now = current_time('mysql');
332 if ( 'monthly' == $type ) {
333 $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);
335 $afterafter = $after;
336 foreach ( $arcresults as $arcresult ) {
337 $url = get_month_link($arcresult->year, $arcresult->month);
338 if ( $show_post_count ) {
339 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
340 $after = ' ('.$arcresult->posts.')' . $afterafter;
342 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
344 echo get_archives_link($url, $text, $format, $before, $after);
347 } elseif ( 'daily' == $type ) {
348 $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);
350 foreach ( $arcresults as $arcresult ) {
351 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
352 $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
353 $text = mysql2date($archive_day_date_format, $date);
354 echo get_archives_link($url, $text, $format, $before, $after);
357 } elseif ( 'weekly' == $type ) {
358 $start_of_week = get_settings('start_of_week');
359 $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);
362 foreach ( $arcresults as $arcresult ) {
363 if ( $arcresult->week != $arc_w_last ) {
364 $arc_year = $arcresult->yr;
365 $arc_w_last = $arcresult->week;
366 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week'));
367 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
368 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
369 $url = sprintf('%s/%s%sm%s%s%sw%s%d', get_settings('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
370 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
371 echo get_archives_link($url, $text, $format, $before, $after);
375 } elseif ( 'postbypost' == $type ) {
376 $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
378 foreach ( $arcresults as $arcresult ) {
379 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
380 $url = get_permalink($arcresult);
381 $arc_title = $arcresult->post_title;
383 $text = strip_tags($arc_title);
385 $text = $arcresult->ID;
386 echo get_archives_link($url, $text, $format, $before, $after);
394 // Used in get_calendar
395 function calendar_week_mod($num) {
397 return ($num - $base*floor($num/$base));
401 function get_calendar($daylength = 1) {
402 global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
404 // Quick check. If we have no posts at all, abort!
406 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
411 if ( isset($_GET['w']) )
412 $w = ''.intval($_GET['w']);
414 // week_begins = 0 stands for Sunday
415 $week_begins = intval(get_settings('start_of_week'));
416 $add_hours = intval(get_settings('gmt_offset'));
417 $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
419 // Let's figure out when we are
420 if ( !empty($monthnum) && !empty($year) ) {
421 $thismonth = ''.zeroise(intval($monthnum), 2);
422 $thisyear = ''.intval($year);
423 } elseif ( !empty($w) ) {
424 // We need to get the month from MySQL
425 $thisyear = ''.intval(substr($m, 0, 4));
426 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
427 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
428 } elseif ( !empty($m) ) {
429 $calendar = substr($m, 0, 6);
430 $thisyear = ''.intval(substr($m, 0, 4));
431 if ( strlen($m) < 6 )
434 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
436 $thisyear = gmdate('Y', current_time('timestamp') + get_settings('gmt_offset') * 3600);
437 $thismonth = gmdate('m', current_time('timestamp') + get_settings('gmt_offset') * 3600);
440 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
442 // Get the next and previous month and year with at least one post
443 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
445 WHERE post_date < '$thisyear-$thismonth-01'
446 AND post_status = 'publish'
447 ORDER BY post_date DESC
449 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
451 WHERE post_date > '$thisyear-$thismonth-01'
452 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
453 AND post_status = 'publish'
454 ORDER BY post_date ASC
457 echo '<table id="wp-calendar">
458 <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
462 $day_abbrev = $weekday_initial;
463 if ( $daylength > 1 )
464 $day_abbrev = $weekday_abbrev;
468 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
469 $myweek[]=$weekday[($wdcount+$week_begins)%7];
472 foreach ( $myweek as $wd ) {
473 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
484 echo "\n\t\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
485 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($previous->month, 2)],
486 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $month_abbrev[$month[zeroise($previous->month, 2)]] . '</a></td>';
488 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
491 echo "\n\t\t".'<td class="pad"> </td>';
494 echo "\n\t\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
495 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($next->month, 2)],
496 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $month_abbrev[$month[zeroise($next->month, 2)]] . ' »</a></td>';
498 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
508 // Get days with posts
509 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
510 FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
511 AND YEAR(post_date) = $thisyear
512 AND post_status = 'publish'
513 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
514 if ( $dayswithposts ) {
515 foreach ( $dayswithposts as $daywith ) {
516 $daywithpost[] = $daywith[0];
519 $daywithpost = array();
524 if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') )
525 $ak_title_separator = "\n";
527 $ak_title_separator = ', ';
529 $ak_titles_for_day = array();
530 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
531 ."FROM $wpdb->posts "
532 ."WHERE YEAR(post_date) = '$thisyear' "
533 ."AND MONTH(post_date) = '$thismonth' "
534 ."AND post_date < '".current_time('mysql')."' "
535 ."AND post_status = 'publish'"
537 if ( $ak_post_titles ) {
538 foreach ( $ak_post_titles as $ak_post_title ) {
539 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
540 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
541 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
542 $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '"', wptexturize($ak_post_title->post_title));
544 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '"', wptexturize($ak_post_title->post_title));
549 // See how much we should pad in the beginning
550 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
552 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>';
554 $daysinmonth = intval(date('t', $unixmonth));
555 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
556 if ( isset($newrow) && $newrow )
557 echo "\n\t</tr>\n\t<tr>\n\t\t";
560 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)) )
561 echo '<td id="today">';
565 if ( in_array($day, $daywithpost) ) // any posts today?
566 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
571 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
575 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
576 if ( $pad != 0 && $pad != 7 )
577 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>';
579 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
583 function allowed_tags() {
586 foreach ( $allowedtags as $tag => $attributes ) {
587 $allowed .= '<'.$tag;
588 if ( 0 < count($attributes) ) {
589 foreach ( $attributes as $attribute => $limits ) {
590 $allowed .= ' '.$attribute.'=""';
595 return htmlentities($allowed);
599 /***** Date/Time tags *****/
602 function the_date_xml() {
604 echo mysql2date('Y-m-d', $post->post_date);
605 //echo ""+$post->post_date;
609 function the_date($d='', $before='', $after='', $echo = true) {
610 global $id, $post, $day, $previousday, $newday;
612 if ( $day != $previousday ) {
613 $the_date .= $before;
615 $the_date .= mysql2date(get_settings('date_format'), $post->post_date);
617 $the_date .= mysql2date($d, $post->post_date);
621 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
629 function the_time( $d = '' ) {
630 echo apply_filters('the_time', get_the_time( $d ), $d);
634 function get_the_time( $d = '' ) {
636 $the_time = get_post_time(get_settings('time_format'));
638 $the_time = get_post_time($d);
639 return apply_filters('get_the_time', $the_time, $d);
643 function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
646 $time = $post->post_date_gmt;
648 $time = $post->post_date;
650 $time = mysql2date($d, $time);
651 return apply_filters('get_the_time', $time, $d, $gmt);
655 function the_modified_time($d = '') {
656 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
660 function get_the_modified_time($d = '') {
662 $the_time = get_post_modified_time(get_settings('time_format'));
664 $the_time = get_post_modified_time($d);
665 return apply_filters('get_the_modified_time', $the_time, $d);
669 function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
673 $time = $post->post_modified_gmt;
675 $time = $post->post_modified;
676 $time = mysql2date($d, $time);
678 return apply_filters('get_the_modified_time', $time, $d, $gmt);
682 function the_weekday() {
683 global $weekday, $id, $post;
684 $the_weekday = $weekday[mysql2date('w', $post->post_date)];
685 $the_weekday = apply_filters('the_weekday', $the_weekday);
690 function the_weekday_date($before='',$after='') {
691 global $weekday, $id, $post, $day, $previousweekday;
692 $the_weekday_date = '';
693 if ( $day != $previousweekday ) {
694 $the_weekday_date .= $before;
695 $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)];
696 $the_weekday_date .= $after;
697 $previousweekday = $day;
699 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
700 echo $the_weekday_date;
703 function rsd_link() {
704 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";