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);
72 function get_bloginfo($show='') {
78 $output = get_settings('home');
81 $output = get_settings('siteurl');
84 $output = get_settings('blogdescription');
87 $output = get_feed_link('rdf');
90 $output = get_feed_link('rss');
93 $output = get_feed_link('rss2');
96 $output = get_feed_link('atom');
98 case 'comments_rss2_url':
99 $output = get_feed_link('comments_rss2');
102 $output = get_settings('siteurl') .'/xmlrpc.php';
104 case 'stylesheet_url':
105 $output = get_stylesheet_uri();
107 case 'stylesheet_directory':
108 $output = get_stylesheet_directory_uri();
110 case 'template_directory':
112 $output = get_template_directory_uri();
115 $output = get_settings('admin_email');
118 $output = get_settings('blog_charset');
119 if ('' == $output) $output = 'UTF-8';
122 $output = get_option('html_type');
126 $output = $wp_version;
130 $output = get_settings('blogname');
137 function wp_title($sep = '»', $display = true) {
139 global $m, $year, $monthnum, $day, $category_name, $month, $posts;
141 $cat = get_query_var('cat');
142 $p = get_query_var('p');
143 $name = get_query_var('name');
144 $category_name = get_query_var('category_name');
145 $author = get_query_var('author');
146 $author_name = get_query_var('author_name');
148 // If there's a category
149 if ( !empty($cat) ) {
150 // category exclusion
151 if ( !stristr($cat,'-') )
152 $title = get_the_category_by_ID($cat);
154 if ( !empty($category_name) ) {
155 if ( stristr($category_name,'/') ) {
156 $category_name = explode('/',$category_name);
157 if ( $category_name[count($category_name)-1] )
158 $category_name = $category_name[count($category_name)-1]; // no trailing slash
160 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
162 $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
165 // If there's an author
166 if ( !empty($author) ) {
167 $title = get_userdata($author);
168 $title = $title->display_name;
170 if ( !empty($author_name) ) {
171 // We do a direct query here because we don't cache by nicename.
172 $title = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE user_nicename = '$author_name'");
175 // If there's a month
177 $my_year = substr($m, 0, 4);
178 $my_month = $month[substr($m, 4, 2)];
179 $title = "$my_year $sep $my_month";
182 if ( !empty($year) ) {
184 if ( !empty($monthnum) )
185 $title .= " $sep ".$month[zeroise($monthnum, 2)];
187 $title .= " $sep ".zeroise($day, 2);
190 // If there is a post
191 if ( is_single() || is_page() ) {
192 $title = strip_tags($posts[0]->post_title);
193 $title = apply_filters('single_post_title', $title);
200 $title = $prefix . $title;
201 $title = apply_filters('wp_title', $title, $sep);
211 function single_post_title($prefix = '', $display = true) {
213 $p = get_query_var('p');
214 $name = get_query_var('name');
216 if ( intval($p) || '' != $name ) {
218 $p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'");
219 $post = & get_post($p);
220 $title = $post->post_title;
221 $title = apply_filters('single_post_title', $title);
223 echo $prefix.strip_tags($title);
225 return strip_tags($title);
230 function single_cat_title($prefix = '', $display = true ) {
231 $cat = intval( get_query_var('cat') );
232 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
233 $my_cat_name = get_the_category_by_ID($cat);
234 if ( !empty($my_cat_name) ) {
236 echo $prefix.strip_tags($my_cat_name);
238 return strip_tags($my_cat_name);
244 function single_month_title($prefix = '', $display = true ) {
245 global $m, $monthnum, $month, $year;
246 if ( !empty($monthnum) && !empty($year) ) {
248 $my_month = $month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
249 } elseif ( !empty($m) ) {
250 $my_year = substr($m, 0, 4);
251 $my_month = $month[substr($m, 4, 2)];
254 if ( !empty($my_month) && $display )
255 echo $prefix . $my_month . $prefix . $my_year;
261 /* link navigation hack by Orien http://icecode.com/ */
262 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
263 $text = wptexturize($text);
264 $title_text = wp_specialchars($text, 1);
266 if ('link' == $format)
267 return "\t<link rel='archives' title='$title_text' href='$url' />\n";
268 elseif ('option' == $format)
269 return "\t<option value='$url'>$before $text $after</option>\n";
270 elseif ('html' == $format)
271 return "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
273 return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
277 function wp_get_archives($args = '') {
278 parse_str($args, $r);
279 if ( !isset($r['type']) )
281 if ( !isset($r['limit']) )
283 if ( !isset($r['format']) )
284 $r['format'] = 'html';
285 if ( !isset($r['before']) )
287 if ( !isset($r['after']) )
289 if ( !isset($r['show_post_count']) )
290 $r['show_post_count'] = false;
292 get_archives($r['type'], $r['limit'], $r['format'], $r['before'], $r['after'], $r['show_post_count']);
296 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
297 global $month, $wpdb;
302 if ( '' != $limit ) {
303 $limit = (int) $limit;
304 $limit = ' LIMIT '.$limit;
306 // this is what will separate dates on weekly archive links
307 $archive_week_separator = '–';
309 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
310 $archive_date_format_over_ride = 0;
312 // options for daily archive (only if you over-ride the general date format)
313 $archive_day_date_format = 'Y/m/d';
315 // options for weekly archive (only if you over-ride the general date format)
316 $archive_week_start_date_format = 'Y/m/d';
317 $archive_week_end_date_format = 'Y/m/d';
319 if ( !$archive_date_format_over_ride ) {
320 $archive_day_date_format = get_settings('date_format');
321 $archive_week_start_date_format = get_settings('date_format');
322 $archive_week_end_date_format = get_settings('date_format');
325 $add_hours = intval(get_settings('gmt_offset'));
326 $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
328 $now = current_time('mysql');
330 if ( 'monthly' == $type ) {
331 $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);
333 $afterafter = $after;
334 foreach ( $arcresults as $arcresult ) {
335 $url = get_month_link($arcresult->year, $arcresult->month);
336 if ( $show_post_count ) {
337 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
338 $after = ' ('.$arcresult->posts.')' . $afterafter;
340 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
342 echo get_archives_link($url, $text, $format, $before, $after);
345 } elseif ( 'daily' == $type ) {
346 $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);
348 foreach ( $arcresults as $arcresult ) {
349 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
350 $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
351 $text = mysql2date($archive_day_date_format, $date);
352 echo get_archives_link($url, $text, $format, $before, $after);
355 } elseif ( 'weekly' == $type ) {
356 $start_of_week = get_settings('start_of_week');
357 $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);
360 foreach ( $arcresults as $arcresult ) {
361 if ( $arcresult->week != $arc_w_last ) {
362 $arc_year = $arcresult->yr;
363 $arc_w_last = $arcresult->week;
364 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week'));
365 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
366 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
367 $url = sprintf('%s/%s%sm%s%s%sw%s%d', get_settings('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
368 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
369 echo get_archives_link($url, $text, $format, $before, $after);
373 } elseif ( 'postbypost' == $type ) {
374 $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
376 foreach ( $arcresults as $arcresult ) {
377 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
378 $url = get_permalink($arcresult);
379 $arc_title = $arcresult->post_title;
381 $text = strip_tags($arc_title);
383 $text = $arcresult->ID;
384 echo get_archives_link($url, $text, $format, $before, $after);
392 // Used in get_calendar
393 function calendar_week_mod($num) {
395 return ($num - $base*floor($num/$base));
399 function get_calendar($daylength = 1) {
400 global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
402 $now = current_time('mysql');
404 // Quick check. If we have no posts yet published, abort!
406 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now' 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 post_date < '$now'
453 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
454 AND post_status = 'publish'
455 ORDER BY post_date ASC
458 echo '<table id="wp-calendar">
459 <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
463 $day_abbrev = $weekday_initial;
464 if ( $daylength > 1 )
465 $day_abbrev = $weekday_abbrev;
469 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
470 $myweek[]=$weekday[($wdcount+$week_begins)%7];
473 foreach ( $myweek as $wd ) {
474 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
485 echo "\n\t\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
486 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($previous->month, 2)],
487 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $month_abbrev[$month[zeroise($previous->month, 2)]] . '</a></td>';
489 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
492 echo "\n\t\t".'<td class="pad"> </td>';
495 echo "\n\t\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
496 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($next->month, 2)],
497 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $month_abbrev[$month[zeroise($next->month, 2)]] . ' »</a></td>';
499 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
509 // Get days with posts
510 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
511 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
512 AND YEAR(post_date) = '$thisyear'
513 AND post_status = 'publish'
514 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
515 if ( $dayswithposts ) {
516 foreach ( $dayswithposts as $daywith ) {
517 $daywithpost[] = $daywith[0];
520 $daywithpost = array();
525 if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') )
526 $ak_title_separator = "\n";
528 $ak_title_separator = ', ';
530 $ak_titles_for_day = array();
531 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
532 ."FROM $wpdb->posts "
533 ."WHERE YEAR(post_date) = '$thisyear' "
534 ."AND MONTH(post_date) = '$thismonth' "
535 ."AND post_date < '".current_time('mysql')."' "
536 ."AND post_status = 'publish'"
538 if ( $ak_post_titles ) {
539 foreach ( $ak_post_titles as $ak_post_title ) {
540 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
541 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
542 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
543 $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '"', wptexturize($ak_post_title->post_title));
545 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '"', wptexturize($ak_post_title->post_title));
550 // See how much we should pad in the beginning
551 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
553 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>';
555 $daysinmonth = intval(date('t', $unixmonth));
556 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
557 if ( isset($newrow) && $newrow )
558 echo "\n\t</tr>\n\t<tr>\n\t\t";
561 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)) )
562 echo '<td id="today">';
566 if ( in_array($day, $daywithpost) ) // any posts today?
567 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
572 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
576 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
577 if ( $pad != 0 && $pad != 7 )
578 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>';
580 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
584 function allowed_tags() {
587 foreach ( $allowedtags as $tag => $attributes ) {
588 $allowed .= '<'.$tag;
589 if ( 0 < count($attributes) ) {
590 foreach ( $attributes as $attribute => $limits ) {
591 $allowed .= ' '.$attribute.'=""';
596 return htmlentities($allowed);
600 /***** Date/Time tags *****/
603 function the_date_xml() {
605 echo mysql2date('Y-m-d', $post->post_date);
606 //echo ""+$post->post_date;
610 function the_date($d='', $before='', $after='', $echo = true) {
611 global $id, $post, $day, $previousday, $newday;
613 if ( $day != $previousday ) {
614 $the_date .= $before;
616 $the_date .= mysql2date(get_settings('date_format'), $post->post_date);
618 $the_date .= mysql2date($d, $post->post_date);
622 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
630 function the_time( $d = '' ) {
631 echo apply_filters('the_time', get_the_time( $d ), $d);
635 function get_the_time( $d = '' ) {
637 $the_time = get_post_time(get_settings('time_format'));
639 $the_time = get_post_time($d);
640 return apply_filters('get_the_time', $the_time, $d);
644 function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
647 $time = $post->post_date_gmt;
649 $time = $post->post_date;
651 $time = mysql2date($d, $time);
652 return apply_filters('get_the_time', $time, $d, $gmt);
656 function the_modified_time($d = '') {
657 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
661 function get_the_modified_time($d = '') {
663 $the_time = get_post_modified_time(get_settings('time_format'));
665 $the_time = get_post_modified_time($d);
666 return apply_filters('get_the_modified_time', $the_time, $d);
670 function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
674 $time = $post->post_modified_gmt;
676 $time = $post->post_modified;
677 $time = mysql2date($d, $time);
679 return apply_filters('get_the_modified_time', $time, $d, $gmt);
683 function the_weekday() {
684 global $weekday, $id, $post;
685 $the_weekday = $weekday[mysql2date('w', $post->post_date)];
686 $the_weekday = apply_filters('the_weekday', $the_weekday);
691 function the_weekday_date($before='',$after='') {
692 global $weekday, $id, $post, $day, $previousweekday;
693 $the_weekday_date = '';
694 if ( $day != $previousweekday ) {
695 $the_weekday_date .= $before;
696 $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)];
697 $the_weekday_date .= $after;
698 $previousweekday = $day;
700 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
701 echo $the_weekday_date;
704 function rsd_link() {
705 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";