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() {
30 if ( ! is_user_logged_in() )
31 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
33 $link = '<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
35 echo apply_filters('loginout', $link);
39 function wp_register( $before = '<li>', $after = '</li>' ) {
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;
47 $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
50 echo apply_filters('register', $link);
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);
67 $info = apply_filters('bloginfo_url', $info, $show);
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) {
140 global $wpdb, $posts, $month;
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');
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
165 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
167 $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
168 $title = apply_filters('single_cat_title', $title);
171 // If there's an author
172 if ( !empty($author) ) {
173 $title = get_userdata($author);
174 $title = $title->display_name;
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'");
181 // If there's a month
183 $my_year = substr($m, 0, 4);
184 $my_month = $month[substr($m, 4, 2)];
185 $title = "$my_year $sep $my_month";
188 if ( !empty($year) ) {
190 if ( !empty($monthnum) )
191 $title .= " $sep ".$month[zeroise($monthnum, 2)];
193 $title .= " $sep ".zeroise($day, 2);
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);
203 if ( !empty($title) )
206 $title = $prefix . $title;
207 $title = apply_filters('wp_title', $title, $sep);
217 function single_post_title($prefix = '', $display = true) {
219 $p = get_query_var('p');
220 $name = get_query_var('name');
222 if ( intval($p) || '' != $name ) {
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);
229 echo $prefix.strip_tags($title);
231 return strip_tags($title);
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) ) {
242 echo $prefix.strip_tags($my_cat_name);
244 return strip_tags($my_cat_name);
250 function single_month_title($prefix = '', $display = true ) {
253 $m = (int) get_query_var('m');
254 $year = (int) get_query_var('year');
255 $monthnum = (int) get_query_var('monthnum');
257 if ( !empty($monthnum) && !empty($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)];
265 if ( !empty($my_month) && $display )
266 echo $prefix . $my_month . $prefix . $my_year;
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);
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";
284 return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
288 function wp_get_archives($args = '') {
289 parse_str($args, $r);
290 if ( !isset($r['type']) )
292 if ( !isset($r['limit']) )
294 if ( !isset($r['format']) )
295 $r['format'] = 'html';
296 if ( !isset($r['before']) )
298 if ( !isset($r['after']) )
300 if ( !isset($r['show_post_count']) )
301 $r['show_post_count'] = false;
303 get_archives($r['type'], $r['limit'], $r['format'], $r['before'], $r['after'], $r['show_post_count']);
307 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
308 global $month, $wpdb;
313 if ( '' != $limit ) {
314 $limit = (int) $limit;
315 $limit = ' LIMIT '.$limit;
317 // this is what will separate dates on weekly archive links
318 $archive_week_separator = '–';
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;
323 // options for daily archive (only if you over-ride the general date format)
324 $archive_day_date_format = 'Y/m/d';
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';
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');
336 $add_hours = intval(get_settings('gmt_offset'));
337 $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
339 $now = current_time('mysql');
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);
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 = ' ('.$arcresult->posts.')' . $afterafter;
351 $text = sprintf(__('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);
353 echo get_archives_link($url, $text, $format, $before, $after);
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);
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);
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);
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, '&', '=', $arcresult->week);
379 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
380 echo get_archives_link($url, $text, $format, $before, $after);
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);
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;
392 $text = strip_tags($arc_title);
394 $text = $arcresult->ID;
395 echo get_archives_link($url, $text, $format, $before, $after);
403 // Used in get_calendar
404 function calendar_week_mod($num) {
406 return ($num - $base*floor($num/$base));
410 function get_calendar($daylength = 1) {
411 global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
413 $now = current_time('mysql');
415 // Quick check. If we have no posts yet published, abort!
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");
422 if ( isset($_GET['w']) )
423 $w = ''.intval($_GET['w']);
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));
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 )
445 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
447 $thisyear = gmdate('Y', current_time('timestamp'));
448 $thismonth = gmdate('m', current_time('timestamp'));
451 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
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
456 WHERE post_date < '$thisyear-$thismonth-01'
457 AND post_status = 'publish'
458 ORDER BY post_date DESC
460 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
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
469 echo '<table id="wp-calendar">
470 <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
474 $day_abbrev = $weekday_initial;
475 if ( $daylength > 1 )
476 $day_abbrev = $weekday_abbrev;
480 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
481 $myweek[]=$weekday[($wdcount+$week_begins)%7];
484 foreach ( $myweek as $wd ) {
485 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
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))) . '">« ' . $month_abbrev[$month[zeroise($previous->month, 2)]] . '</a></td>';
500 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
503 echo "\n\t\t".'<td class="pad"> </td>';
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)]] . ' »</a></td>';
510 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
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];
531 $daywithpost = array();
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";
539 $ak_title_separator = ', ';
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'"
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('"', '"', wptexturize($ak_post_title->post_title));
556 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '"', wptexturize($ak_post_title->post_title));
561 // See how much we should pad in the beginning
562 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
564 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>';
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";
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">';
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>";
583 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
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.'"> </td>';
591 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
595 function allowed_tags() {
598 foreach ( $allowedtags as $tag => $attributes ) {
599 $allowed .= '<'.$tag;
600 if ( 0 < count($attributes) ) {
601 foreach ( $attributes as $attribute => $limits ) {
602 $allowed .= ' '.$attribute.'=""';
607 return htmlentities($allowed);
611 /***** Date/Time tags *****/
614 function the_date_xml() {
616 echo mysql2date('Y-m-d', $post->post_date);
617 //echo ""+$post->post_date;
621 function the_date($d='', $before='', $after='', $echo = true) {
622 global $id, $post, $day, $previousday, $newday;
624 if ( $day != $previousday ) {
625 $the_date .= $before;
627 $the_date .= mysql2date(get_settings('date_format'), $post->post_date);
629 $the_date .= mysql2date($d, $post->post_date);
633 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
641 function the_time( $d = '' ) {
642 echo apply_filters('the_time', get_the_time( $d ), $d);
646 function get_the_time( $d = '' ) {
648 $the_time = get_post_time(get_settings('time_format'));
650 $the_time = get_post_time($d);
651 return apply_filters('get_the_time', $the_time, $d);
655 function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
658 $time = $post->post_date_gmt;
660 $time = $post->post_date;
662 $time = mysql2date($d, $time);
663 return apply_filters('get_the_time', $time, $d, $gmt);
667 function the_modified_time($d = '') {
668 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
672 function get_the_modified_time($d = '') {
674 $the_time = get_post_modified_time(get_settings('time_format'));
676 $the_time = get_post_modified_time($d);
677 return apply_filters('get_the_modified_time', $the_time, $d);
681 function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
685 $time = $post->post_modified_gmt;
687 $time = $post->post_modified;
688 $time = mysql2date($d, $time);
690 return apply_filters('get_the_modified_time', $time, $d, $gmt);
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);
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;
711 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
712 echo $the_weekday_date;
715 function rsd_link() {
716 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";