3 /* Note: these tags go anywhere in the template */
5 function get_header() {
6 do_action( 'get_header' );
7 if ( file_exists( TEMPLATEPATH . '/header.php') )
8 load_template( TEMPLATEPATH . '/header.php');
10 load_template( WP_CONTENT_DIR . '/themes/default/header.php');
14 function get_footer() {
15 do_action( 'get_footer' );
16 if ( file_exists( TEMPLATEPATH . '/footer.php') )
17 load_template( TEMPLATEPATH . '/footer.php');
19 load_template( WP_CONTENT_DIR . '/themes/default/footer.php');
23 function get_sidebar( $name = null ) {
24 do_action( 'get_sidebar' );
25 if ( isset($name) && file_exists( TEMPLATEPATH . "/sidebar-{$name}.php") )
26 load_template( TEMPLATEPATH . "/sidebar-{$name}.php");
27 elseif ( file_exists( TEMPLATEPATH . '/sidebar.php') )
28 load_template( TEMPLATEPATH . '/sidebar.php');
30 load_template( WP_CONTENT_DIR . '/themes/default/sidebar.php');
34 function wp_loginout() {
35 if ( ! is_user_logged_in() )
36 $link = '<a href="' . site_url('wp-login.php', 'login') . '">' . __('Log in') . '</a>';
38 $link = '<a href="' . site_url('wp-login.php?action=logout', 'login') . '">' . __('Log out') . '</a>';
40 echo apply_filters('loginout', $link);
44 function wp_register( $before = '<li>', $after = '</li>' ) {
46 if ( ! is_user_logged_in() ) {
47 if ( get_option('users_can_register') )
48 $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
52 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
55 echo apply_filters('register', $link);
64 function bloginfo($show='') {
65 echo get_bloginfo($show, 'display');
69 * Note: some of these values are DEPRECATED. Meaning they could be
70 * taken out at any time and shouldn't be relied upon. Options
71 * without "// DEPRECATED" are the preferred and recommended ways
72 * to get the information.
74 function get_bloginfo($show = '', $filter = 'raw') {
78 case 'home' : // DEPRECATED
79 case 'siteurl' : // DEPRECATED
80 $output = get_option('home');
83 $output = get_option('siteurl');
86 $output = get_option('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_atom_url':
101 $output = get_feed_link('comments_atom');
103 case 'comments_rss2_url':
104 $output = get_feed_link('comments_rss2');
107 $output = get_option('siteurl') .'/xmlrpc.php';
109 case 'stylesheet_url':
110 $output = get_stylesheet_uri();
112 case 'stylesheet_directory':
113 $output = get_stylesheet_directory_uri();
115 case 'template_directory':
117 $output = get_template_directory_uri();
120 $output = get_option('admin_email');
123 $output = get_option('blog_charset');
124 if ('' == $output) $output = 'UTF-8';
127 $output = get_option('html_type');
131 $output = $wp_version;
134 $output = get_locale();
135 $output = str_replace('_', '-', $output);
137 case 'text_direction':
139 $output = $wp_locale->text_direction;
143 $output = get_option('blogname');
148 if (strpos($show, 'url') === false &&
149 strpos($show, 'directory') === false &&
150 strpos($show, 'home') === false)
153 if ( 'display' == $filter ) {
155 $output = apply_filters('bloginfo_url', $output, $show);
157 $output = apply_filters('bloginfo', $output, $show);
164 function wp_title($sep = '»', $display = true, $seplocation = '') {
165 global $wpdb, $wp_locale, $wp_query;
167 $cat = get_query_var('cat');
168 $tag = get_query_var('tag_id');
169 $category_name = get_query_var('category_name');
170 $author = get_query_var('author');
171 $author_name = get_query_var('author_name');
172 $m = get_query_var('m');
173 $year = get_query_var('year');
174 $monthnum = get_query_var('monthnum');
175 $day = get_query_var('day');
178 // If there's a category
179 if ( !empty($cat) ) {
180 // category exclusion
181 if ( !stristr($cat,'-') )
182 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
183 } elseif ( !empty($category_name) ) {
184 if ( stristr($category_name,'/') ) {
185 $category_name = explode('/',$category_name);
186 if ( $category_name[count($category_name)-1] )
187 $category_name = $category_name[count($category_name)-1]; // no trailing slash
189 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
191 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
193 $title = apply_filters('single_cat_title', $cat->name);
196 if ( !empty($tag) ) {
197 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
198 if ( is_wp_error( $tag ) )
200 if ( ! empty($tag->name) )
201 $title = apply_filters('single_tag_title', $tag->name);
204 // If there's an author
205 if ( !empty($author) ) {
206 $title = get_userdata($author);
207 $title = $title->display_name;
209 if ( !empty($author_name) ) {
210 // We do a direct query here because we don't cache by nicename.
211 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
214 // If there's a month
216 $my_year = substr($m, 0, 4);
217 $my_month = $wp_locale->get_month(substr($m, 4, 2));
218 $my_day = intval(substr($m, 6, 2));
219 $title = "$my_year" . ($my_month ? "$sep $my_month" : "") . ($my_day ? "$sep $my_day" : "");
222 if ( !empty($year) ) {
224 if ( !empty($monthnum) )
225 $title .= " $sep " . $wp_locale->get_month($monthnum);
227 $title .= " $sep " . zeroise($day, 2);
230 // If there is a post
231 if ( is_single() || is_page() ) {
232 $post = $wp_query->get_queried_object();
233 $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
236 // If there's a taxonomy
238 $taxonomy = get_query_var( 'taxonomy' );
239 $tax = get_taxonomy( $taxonomy );
241 $term = $wp_query->get_queried_object();
243 if ( 'right' == $seplocation )
244 $title = "$term $sep $tax";
246 $title = "$tax $sep $term";
250 if ( !empty($title) )
253 // Determines position of the separator
254 if ( 'right' == $seplocation )
255 $title = $title . $prefix;
257 $title = $prefix . $title;
259 $title = apply_filters('wp_title', $title, $sep);
270 function single_post_title($prefix = '', $display = true) {
272 $p = get_query_var('p');
273 $name = get_query_var('name');
275 if ( intval($p) || '' != $name ) {
277 $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
278 $post = & get_post($p);
279 $title = $post->post_title;
280 $title = apply_filters('single_post_title', $title);
282 echo $prefix.strip_tags($title);
284 return strip_tags($title);
289 function single_cat_title($prefix = '', $display = true ) {
290 $cat = intval( get_query_var('cat') );
291 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
292 $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
293 if ( !empty($my_cat_name) ) {
295 echo $prefix.strip_tags($my_cat_name);
297 return strip_tags($my_cat_name);
299 } else if ( is_tag() ) {
300 return single_tag_title($prefix, $display);
305 function single_tag_title($prefix = '', $display = true ) {
309 $tag_id = intval( get_query_var('tag_id') );
311 if ( !empty($tag_id) ) {
312 $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display');
313 if ( is_wp_error( $my_tag ) )
315 $my_tag_name = apply_filters('single_tag_title', $my_tag->name);
316 if ( !empty($my_tag_name) ) {
318 echo $prefix . $my_tag_name;
326 function single_month_title($prefix = '', $display = true ) {
329 $m = get_query_var('m');
330 $year = get_query_var('year');
331 $monthnum = get_query_var('monthnum');
333 if ( !empty($monthnum) && !empty($year) ) {
335 $my_month = $wp_locale->get_month($monthnum);
336 } elseif ( !empty($m) ) {
337 $my_year = substr($m, 0, 4);
338 $my_month = $wp_locale->get_month(substr($m, 4, 2));
341 if ( empty($my_month) )
344 $result = $prefix . $my_month . $prefix . $my_year;
352 /* link navigation hack by Orien http://icecode.com/ */
353 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
354 $text = wptexturize($text);
355 $title_text = attribute_escape($text);
356 $url = clean_url($url);
358 if ('link' == $format)
359 $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
360 elseif ('option' == $format)
361 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
362 elseif ('html' == $format)
363 $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
365 $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
367 $link_html = apply_filters( "get_archives_link", $link_html );
373 function wp_get_archives($args = '') {
374 global $wpdb, $wp_locale;
377 'type' => 'monthly', 'limit' => '',
378 'format' => 'html', 'before' => '',
379 'after' => '', 'show_post_count' => false
382 $r = wp_parse_args( $args, $defaults );
383 extract( $r, EXTR_SKIP );
388 if ( '' != $limit ) {
389 $limit = absint($limit);
390 $limit = ' LIMIT '.$limit;
393 // this is what will separate dates on weekly archive links
394 $archive_week_separator = '–';
396 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
397 $archive_date_format_over_ride = 0;
399 // options for daily archive (only if you over-ride the general date format)
400 $archive_day_date_format = 'Y/m/d';
402 // options for weekly archive (only if you over-ride the general date format)
403 $archive_week_start_date_format = 'Y/m/d';
404 $archive_week_end_date_format = 'Y/m/d';
406 if ( !$archive_date_format_over_ride ) {
407 $archive_day_date_format = get_option('date_format');
408 $archive_week_start_date_format = get_option('date_format');
409 $archive_week_end_date_format = get_option('date_format');
413 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
414 $join = apply_filters('getarchives_join', "", $r);
416 if ( 'monthly' == $type ) {
417 $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
419 $cache = wp_cache_get( 'wp_get_archives' , 'general');
420 if ( !isset( $cache[ $key ] ) ) {
421 $arcresults = $wpdb->get_results($query);
422 $cache[ $key ] = $arcresults;
423 wp_cache_add( 'wp_get_archives', $cache, 'general' );
425 $arcresults = $cache[ $key ];
428 $afterafter = $after;
429 foreach ( $arcresults as $arcresult ) {
430 $url = get_month_link($arcresult->year, $arcresult->month);
431 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
432 if ( $show_post_count )
433 $after = ' ('.$arcresult->posts.')' . $afterafter;
434 echo get_archives_link($url, $text, $format, $before, $after);
437 } elseif ('yearly' == $type) {
438 $query = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";
440 $cache = wp_cache_get( 'wp_get_archives' , 'general');
441 if ( !isset( $cache[ $key ] ) ) {
442 $arcresults = $wpdb->get_results($query);
443 $cache[ $key ] = $arcresults;
444 wp_cache_add( 'wp_get_archives', $cache, 'general' );
446 $arcresults = $cache[ $key ];
449 $afterafter = $after;
450 foreach ($arcresults as $arcresult) {
451 $url = get_year_link($arcresult->year);
452 $text = sprintf('%d', $arcresult->year);
453 if ($show_post_count)
454 $after = ' ('.$arcresult->posts.')' . $afterafter;
455 echo get_archives_link($url, $text, $format, $before, $after);
458 } elseif ( 'daily' == $type ) {
459 $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";
461 $cache = wp_cache_get( 'wp_get_archives' , 'general');
462 if ( !isset( $cache[ $key ] ) ) {
463 $arcresults = $wpdb->get_results($query);
464 $cache[ $key ] = $arcresults;
465 wp_cache_add( 'wp_get_archives', $cache, 'general' );
467 $arcresults = $cache[ $key ];
470 $afterafter = $after;
471 foreach ( $arcresults as $arcresult ) {
472 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
473 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
474 $text = mysql2date($archive_day_date_format, $date);
475 if ($show_post_count)
476 $after = ' ('.$arcresult->posts.')'.$afterafter;
477 echo get_archives_link($url, $text, $format, $before, $after);
480 } elseif ( 'weekly' == $type ) {
481 $start_of_week = get_option('start_of_week');
482 $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit";
484 $cache = wp_cache_get( 'wp_get_archives' , 'general');
485 if ( !isset( $cache[ $key ] ) ) {
486 $arcresults = $wpdb->get_results($query);
487 $cache[ $key ] = $arcresults;
488 wp_cache_add( 'wp_get_archives', $cache, 'general' );
490 $arcresults = $cache[ $key ];
493 $afterafter = $after;
495 foreach ( $arcresults as $arcresult ) {
496 if ( $arcresult->week != $arc_w_last ) {
497 $arc_year = $arcresult->yr;
498 $arc_w_last = $arcresult->week;
499 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
500 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
501 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
502 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
503 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
504 if ($show_post_count)
505 $after = ' ('.$arcresult->posts.')'.$afterafter;
506 echo get_archives_link($url, $text, $format, $before, $after);
510 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
511 ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC ";
512 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
514 $cache = wp_cache_get( 'wp_get_archives' , 'general');
515 if ( !isset( $cache[ $key ] ) ) {
516 $arcresults = $wpdb->get_results($query);
517 $cache[ $key ] = $arcresults;
518 wp_cache_add( 'wp_get_archives', $cache, 'general' );
520 $arcresults = $cache[ $key ];
523 foreach ( $arcresults as $arcresult ) {
524 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
525 $url = get_permalink($arcresult);
526 $arc_title = $arcresult->post_title;
528 $text = strip_tags(apply_filters('the_title', $arc_title));
530 $text = $arcresult->ID;
531 echo get_archives_link($url, $text, $format, $before, $after);
539 // Used in get_calendar
540 function calendar_week_mod($num) {
542 return ($num - $base*floor($num/$base));
546 function get_calendar($initial = true) {
547 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
549 $key = md5( $m . $monthnum . $year );
550 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
551 if ( isset( $cache[ $key ] ) ) {
558 // Quick check. If we have no posts at all, abort!
560 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
565 if ( isset($_GET['w']) )
566 $w = ''.intval($_GET['w']);
568 // week_begins = 0 stands for Sunday
569 $week_begins = intval(get_option('start_of_week'));
571 // Let's figure out when we are
572 if ( !empty($monthnum) && !empty($year) ) {
573 $thismonth = ''.zeroise(intval($monthnum), 2);
574 $thisyear = ''.intval($year);
575 } elseif ( !empty($w) ) {
576 // We need to get the month from MySQL
577 $thisyear = ''.intval(substr($m, 0, 4));
578 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
579 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
580 } elseif ( !empty($m) ) {
581 $thisyear = ''.intval(substr($m, 0, 4));
582 if ( strlen($m) < 6 )
585 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
587 $thisyear = gmdate('Y', current_time('timestamp'));
588 $thismonth = gmdate('m', current_time('timestamp'));
591 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
593 // Get the next and previous month and year with at least one post
594 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
596 WHERE post_date < '$thisyear-$thismonth-01'
597 AND post_type = 'post' AND post_status = 'publish'
598 ORDER BY post_date DESC
600 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
602 WHERE post_date > '$thisyear-$thismonth-01'
603 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
604 AND post_type = 'post' AND post_status = 'publish'
605 ORDER BY post_date ASC
608 echo '<table id="wp-calendar" summary="' . __('Calendar') . '">
609 <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
615 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
616 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
619 foreach ( $myweek as $wd ) {
620 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
621 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
632 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
633 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
634 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
636 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
639 echo "\n\t\t".'<td class="pad"> </td>';
642 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
643 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
644 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
646 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
656 // Get days with posts
657 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
658 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
659 AND YEAR(post_date) = '$thisyear'
660 AND post_type = 'post' AND post_status = 'publish'
661 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
662 if ( $dayswithposts ) {
663 foreach ( $dayswithposts as $daywith ) {
664 $daywithpost[] = $daywith[0];
667 $daywithpost = array();
670 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false)
671 $ak_title_separator = "\n";
673 $ak_title_separator = ', ';
675 $ak_titles_for_day = array();
676 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
677 ."FROM $wpdb->posts "
678 ."WHERE YEAR(post_date) = '$thisyear' "
679 ."AND MONTH(post_date) = '$thismonth' "
680 ."AND post_date < '".current_time('mysql')."' "
681 ."AND post_type = 'post' AND post_status = 'publish'"
683 if ( $ak_post_titles ) {
684 foreach ( $ak_post_titles as $ak_post_title ) {
686 $post_title = apply_filters( "the_title", $ak_post_title->post_title );
687 $post_title = str_replace('"', '"', wptexturize( $post_title ));
689 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
690 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
691 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
692 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
694 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
699 // See how much we should pad in the beginning
700 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
702 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>';
704 $daysinmonth = intval(date('t', $unixmonth));
705 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
706 if ( isset($newrow) && $newrow )
707 echo "\n\t</tr>\n\t<tr>\n\t\t";
710 if ( $day == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)) )
711 echo '<td id="today">';
715 if ( in_array($day, $daywithpost) ) // any posts today?
716 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
721 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
725 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
726 if ( $pad != 0 && $pad != 7 )
727 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>';
729 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
731 $output = ob_get_contents();
734 $cache[ $key ] = $output;
735 wp_cache_set( 'get_calendar', $cache, 'calendar' );
738 function delete_get_calendar_cache() {
739 wp_cache_delete( 'get_calendar', 'calendar' );
741 add_action( 'save_post', 'delete_get_calendar_cache' );
742 add_action( 'delete_post', 'delete_get_calendar_cache' );
743 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
744 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
745 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
748 function allowed_tags() {
751 foreach ( $allowedtags as $tag => $attributes ) {
752 $allowed .= '<'.$tag;
753 if ( 0 < count($attributes) ) {
754 foreach ( $attributes as $attribute => $limits ) {
755 $allowed .= ' '.$attribute.'=""';
760 return htmlentities($allowed);
764 /***** Date/Time tags *****/
767 function the_date_xml() {
769 echo mysql2date('Y-m-d', $post->post_date);
770 //echo ""+$post->post_date;
774 function the_date($d='', $before='', $after='', $echo = true) {
775 global $post, $day, $previousday;
777 if ( $day != $previousday ) {
778 $the_date .= $before;
780 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
782 $the_date .= mysql2date($d, $post->post_date);
786 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
794 function the_modified_date($d = '') {
795 echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
799 function get_the_modified_date($d = '') {
801 $the_time = get_post_modified_time(get_option('date_format'));
803 $the_time = get_post_modified_time($d);
804 return apply_filters('get_the_modified_date', $the_time, $d);
808 function the_time( $d = '' ) {
809 echo apply_filters('the_time', get_the_time( $d ), $d);
813 function get_the_time( $d = '' ) {
815 $the_time = get_post_time(get_option('time_format'));
817 $the_time = get_post_time($d);
818 return apply_filters('get_the_time', $the_time, $d);
822 function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
825 $time = $post->post_date_gmt;
827 $time = $post->post_date;
829 $time = mysql2date($d, $time);
830 return apply_filters('get_post_time', $time, $d, $gmt);
834 function the_modified_time($d = '') {
835 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
839 function get_the_modified_time($d = '') {
841 $the_time = get_post_modified_time(get_option('time_format'));
843 $the_time = get_post_modified_time($d);
844 return apply_filters('get_the_modified_time', $the_time, $d);
848 function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
852 $time = $post->post_modified_gmt;
854 $time = $post->post_modified;
855 $time = mysql2date($d, $time);
857 return apply_filters('get_the_modified_time', $time, $d, $gmt);
861 function the_weekday() {
862 global $wp_locale, $post;
863 $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date));
864 $the_weekday = apply_filters('the_weekday', $the_weekday);
869 function the_weekday_date($before='',$after='') {
870 global $wp_locale, $post, $day, $previousweekday;
871 $the_weekday_date = '';
872 if ( $day != $previousweekday ) {
873 $the_weekday_date .= $before;
874 $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date));
875 $the_weekday_date .= $after;
876 $previousweekday = $day;
878 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
879 echo $the_weekday_date;
883 do_action('wp_head');
886 function wp_footer() {
887 do_action('wp_footer');
890 function rsd_link() {
891 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
894 function wlwmanifest_link() {
895 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
896 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
900 // If the blog is not public, tell robots to go away.
901 if ( '0' == get_option('blog_public') )
902 echo "<meta name='robots' content='noindex,nofollow' />\n";
905 function rich_edit_exists() {
906 global $wp_rich_edit_exists;
907 if ( !isset($wp_rich_edit_exists) )
908 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
909 return $wp_rich_edit_exists;
912 function user_can_richedit() {
913 global $wp_rich_edit, $pagenow;
915 if ( !isset( $wp_rich_edit) ) {
916 if ( get_user_option( 'rich_editing' ) == 'true' &&
917 ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
918 !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
919 && 'comment.php' != $pagenow ) {
920 $wp_rich_edit = true;
922 $wp_rich_edit = false;
926 return apply_filters('user_can_richedit', $wp_rich_edit);
929 function wp_default_editor() {
930 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
931 if ( $user = wp_get_current_user() ) { // look for cookie
932 if ( isset($_COOKIE['wordpress_editor_' . $user->ID]) && in_array($_COOKIE['wordpress_editor_' . $user->ID], array('tinymce', 'html', 'test') ) )
933 $r = $_COOKIE['wordpress_editor_' . $user->ID];
935 return apply_filters( 'wp_default_editor', $r ); // filter
938 function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
939 $rows = get_option('default_post_edit_rows');
940 if (($rows < 3) || ($rows > 100))
943 $rows = "rows='$rows'"; ?>
944 <div id="editor-toolbar">
945 <?php if ( user_can_richedit() ) {
946 $wp_default_editor = wp_default_editor(); ?>
947 <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
948 <?php if ( 'tinymce' == $wp_default_editor ) {
949 add_filter('the_editor_content', 'wp_richedit_pre'); ?>
950 <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('HTML'); ?></a>
951 <a id="edButtonPreview" class="active"><?php _e('Visual'); ?></a>
952 <?php } elseif ( 'html' == $wp_default_editor ) {
953 add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
954 <a id="edButtonHTML" class="active"><?php _e('HTML'); ?></a>
955 <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('Visual'); ?></a>
959 if ( $media_buttons ) { ?>
960 <div id="media-buttons" class="hide-if-no-js">
961 <?php do_action( 'media_buttons' ); ?>
967 <?php wp_print_scripts( 'quicktags' ); ?>
968 <script type="text/javascript">edToolbar()</script>
971 <?php if ( 'html' != $wp_default_editor ) : ?>
972 <script type="text/javascript">
974 if ( typeof tinyMCE != "undefined" )
975 document.getElementById("quicktags").style.display="none";
978 <?php endif; // 'html' != $wp_default_editor
980 $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea class='' $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
981 $the_editor_content = apply_filters('the_editor_content', $content);
983 printf($the_editor, $the_editor_content);
986 <script type="text/javascript">
988 edCanvas = document.getElementById('<?php echo $id; ?>');
989 <?php if ( $prev_id && user_can_richedit() ) : ?>
990 // If tinyMCE is defined.
991 if ( typeof tinyMCE != 'undefined' ) {
992 // This code is meant to allow tabbing from Title to Post (TinyMCE).
993 document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e) {
994 e = e || window.event;
995 if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
996 if ( tinyMCE.activeEditor ) {
997 if ( (jQuery("#post_ID").val() < 1) && (jQuery("#title").val().length > 0) ) { autosave(); }
999 if ( tinyMCE.activeEditor.isHidden() ) return true;
1000 tinyMCE.activeEditor.focus();
1013 function get_search_query() {
1014 return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) );
1017 function the_search_query() {
1018 echo attribute_escape( apply_filters( 'the_search_query', get_search_query() ) );
1021 function language_attributes($doctype = 'html') {
1022 $attributes = array();
1025 if ( $dir = get_bloginfo('text_direction') )
1026 $attributes[] = "dir=\"$dir\"";
1028 if ( $lang = get_bloginfo('language') ) {
1029 if ( get_option('html_type') == 'text/html' || $doctype == 'xhtml' )
1030 $attributes[] = "lang=\"$lang\"";
1032 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1033 $attributes[] = "xml:lang=\"$lang\"";
1036 $output = implode(' ', $attributes);
1037 $output = apply_filters('language_attributes', $output);
1041 function paginate_links( $args = '' ) {
1043 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1044 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1047 'show_all' => false,
1048 'prev_next' => true,
1049 'prev_text' => __('« Previous'),
1050 'next_text' => __('Next »'),
1051 'end_size' => 1, // How many numbers on either end including the end
1052 'mid_size' => 2, // How many numbers to either side of current not including current
1054 'add_args' => false // array of query args to aadd
1057 $args = wp_parse_args( $args, $defaults );
1058 extract($args, EXTR_SKIP);
1060 // Who knows what else people pass in $args
1061 $total = (int) $total;
1064 $current = (int) $current;
1065 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
1066 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
1067 $add_args = is_array($add_args) ? $add_args : false;
1069 $page_links = array();
1073 if ( $prev_next && $current && 1 < $current ) :
1074 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
1075 $link = str_replace('%#%', $current - 1, $link);
1077 $link = add_query_arg( $add_args, $link );
1078 $page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>";
1080 for ( $n = 1; $n <= $total; $n++ ) :
1081 if ( $n == $current ) :
1082 $page_links[] = "<span class='page-numbers current'>$n</span>";
1085 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
1086 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
1087 $link = str_replace('%#%', $n, $link);
1089 $link = add_query_arg( $add_args, $link );
1090 $page_links[] = "<a class='page-numbers' href='" . clean_url($link) . "'>$n</a>";
1092 elseif ( $dots && !$show_all ) :
1093 $page_links[] = "<span class='page-numbers dots'>...</span>";
1098 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
1099 $link = str_replace('%_%', $format, $base);
1100 $link = str_replace('%#%', $current + 1, $link);
1102 $link = add_query_arg( $add_args, $link );
1103 $page_links[] = "<a class='next page-numbers' href='" . clean_url($link) . "'>$next_text</a>";
1110 $r .= "<ul class='page-numbers'>\n\t<li>";
1111 $r .= join("</li>\n\t<li>", $page_links);
1112 $r .= "</li>\n</ul>\n";
1115 $r = join("\n", $page_links);
1121 function wp_admin_css_color($key, $name, $url, $colors = array()) {
1122 global $_wp_admin_css_colors;
1124 if ( !isset($_wp_admin_css_colors) )
1125 $_wp_admin_css_colors = array();
1127 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
1131 * wp_admin_css_uri() - Outputs the URL of a WordPress admin CSS file
1133 * @see WP_Styles::_css_href and its style_loader_src filter.
1135 * @param string $file file relative to wp-admin/ without its ".css" extension.
1138 function wp_admin_css_uri( $file = 'wp-admin' ) {
1139 if ( defined('WP_INSTALLING') ) {
1140 $_file = "./$file.css";
1142 $_file = admin_url("$file.css");
1144 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
1146 return apply_filters( 'wp_admin_css_uri', $_file, $file );
1150 * wp_admin_css() - Enqueues or directly prints a stylesheet link to the specified CSS file.
1152 * "Intelligently" decides to enqueue or to print the CSS file.
1153 * If the wp_print_styles action has *not* yet been called, the CSS file will be enqueued.
1154 * If the wp_print_styles action *has* been called, the CSS link will be printed.
1155 * Printing may be forced by passing TRUE as the $force_echo (second) parameter.
1157 * For backward compatibility with WordPress 2.3 calling method:
1158 * If the $file (first) parameter does not correspond to a registered CSS file, we assume $file is a
1159 * file relative to wp-admin/ without its ".css" extension. A stylesheet link to that generated URL is printed.
1161 * @package WordPress
1164 * @uses $wp_styles WordPress Styles Object
1166 * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
1167 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
1170 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
1172 if ( !is_a($wp_styles, 'WP_Styles') )
1173 $wp_styles = new WP_Styles();
1175 // For backward compatibility
1176 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
1178 if ( $wp_styles->query( $handle ) ) {
1179 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
1180 wp_print_styles( $handle );
1181 else // Add to style queue
1182 wp_enqueue_style( $handle );
1186 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
1187 if ( 'rtl' == get_bloginfo( 'text_direction' ) )
1188 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
1192 * Enqueues the default ThickBox js and css.
1193 * If any of the settings need to be changed, this can be done with another js file
1194 * similar to media-upload.js and theme-preview.js. That file should require array('thickbox')
1195 * to ensure it is loaded after.
1197 function add_thickbox() {
1198 wp_enqueue_script( 'thickbox' );
1199 wp_enqueue_style( 'thickbox' );
1203 * Outputs the XHTML generator that is generated on the wp_head hook.
1205 function wp_generator()
1207 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
1211 * Outputs the generator XML or Comment for RSS, ATOM, etc.
1212 * @param {String} $type The type of generator to return.
1214 function the_generator ( $type ) {
1215 echo apply_filters('the_generator',get_the_generator($type),$type) . "\n";
1219 * Creates the generator XML or Comment for RSS, ATOM, etc.
1220 * @param {String} $type The type of generator to return.
1222 function get_the_generator ( $type ) {
1225 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">' . "\n";
1228 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />' . "\n";
1231 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
1234 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
1237 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
1240 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
1243 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
1246 return apply_filters( "get_the_generator_{$type}", $gen, $type );