source: trunk/www.guidonia.net/wp/wp-includes/general-template.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 67.0 KB
Line 
1<?php
2/**
3 * General template tags that can go anywhere in a template.
4 *
5 * @package WordPress
6 * @subpackage Template
7 */
8
9/**
10 * Load header template.
11 *
12 * Includes the header template for a theme or if a name is specified then a
13 * specialised header will be included. If the theme contains no header.php file
14 * then the header from the default theme will be included.
15 *
16 * For the parameter, if the file is called "header-special.php" then specify
17 * "special".
18 *
19 * @uses locate_template()
20 * @since 1.5.0
21 * @uses do_action() Calls 'get_header' action.
22 *
23 * @param string $name The name of the specialised header.
24 */
25function get_header( $name = null ) {
26 do_action( 'get_header', $name );
27
28 $templates = array();
29 if ( isset($name) )
30 $templates[] = "header-{$name}.php";
31
32 $templates[] = "header.php";
33
34 if ('' == locate_template($templates, true))
35 load_template( get_theme_root() . '/default/header.php');
36}
37
38/**
39 * Load footer template.
40 *
41 * Includes the footer template for a theme or if a name is specified then a
42 * specialised footer will be included. If the theme contains no footer.php file
43 * then the footer from the default theme will be included.
44 *
45 * For the parameter, if the file is called "footer-special.php" then specify
46 * "special".
47 *
48 * @uses locate_template()
49 * @since 1.5.0
50 * @uses do_action() Calls 'get_footer' action.
51 *
52 * @param string $name The name of the specialised footer.
53 */
54function get_footer( $name = null ) {
55 do_action( 'get_footer', $name );
56
57 $templates = array();
58 if ( isset($name) )
59 $templates[] = "footer-{$name}.php";
60
61 $templates[] = "footer.php";
62
63 if ('' == locate_template($templates, true))
64 load_template( get_theme_root() . '/default/footer.php');
65}
66
67/**
68 * Load sidebar template.
69 *
70 * Includes the sidebar template for a theme or if a name is specified then a
71 * specialised sidebar will be included. If the theme contains no sidebar.php
72 * file then the sidebar from the default theme will be included.
73 *
74 * For the parameter, if the file is called "sidebar-special.php" then specify
75 * "special".
76 *
77 * @uses locate_template()
78 * @since 1.5.0
79 * @uses do_action() Calls 'get_sidebar' action.
80 *
81 * @param string $name The name of the specialised sidebar.
82 */
83function get_sidebar( $name = null ) {
84 do_action( 'get_sidebar', $name );
85
86 $templates = array();
87 if ( isset($name) )
88 $templates[] = "sidebar-{$name}.php";
89
90 $templates[] = "sidebar.php";
91
92 if ('' == locate_template($templates, true))
93 load_template( get_theme_root() . '/default/sidebar.php');
94}
95
96/**
97 * Display search form.
98 *
99 * Will first attempt to locate the searchform.php file in either the child or
100 * the parent, then load it. If it doesn't exist, then the default search form
101 * will be displayed. The default search form is HTML, which will be displayed.
102 * There is a filter applied to the search form HTML in order to edit or replace
103 * it. The filter is 'get_search_form'.
104 *
105 * This function is primarily used by themes which want to hardcode the search
106 * form into the sidebar and also by the search widget in WordPress.
107 *
108 * There is also an action that is called whenever the function is run called,
109 * 'get_search_form'. This can be useful for outputting JavaScript that the
110 * search relies on or various formatting that applies to the beginning of the
111 * search. To give a few examples of what it can be used for.
112 *
113 * @since 2.7.0
114 */
115function get_search_form() {
116 do_action( 'get_search_form' );
117
118 $search_form_template = locate_template(array('searchform.php'));
119 if ( '' != $search_form_template ) {
120 require($search_form_template);
121 return;
122 }
123
124 $form = '<form role="search" method="get" id="searchform" action="' . get_option('home') . '/" >
125 <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
126 <input type="text" value="' . esc_attr(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
127 <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
128 </div>
129 </form>';
130
131 echo apply_filters('get_search_form', $form);
132}
133
134/**
135 * Display the Log In/Out link.
136 *
137 * Displays a link, which allows the user to navigate to the Log In page to log in
138 * or log out depending on whether or not they are currently logged in.
139 *
140 * @since 1.5.0
141 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
142 *
143 * @param string $redirect Optional path to redirect to on login/logout.
144 */
145function wp_loginout($redirect = '') {
146 if ( ! is_user_logged_in() )
147 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
148 else
149 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
150
151 echo apply_filters('loginout', $link);
152}
153
154/**
155 * Returns the Log Out URL.
156 *
157 * Returns the URL that allows the user to log out of the site
158 *
159 * @since 2.7
160 * @uses wp_nonce_url() To protect against CSRF
161 * @uses site_url() To generate the log in URL
162 * @uses apply_filters() calls 'logout_url' hook on final logout url
163 *
164 * @param string $redirect Path to redirect to on logout.
165 */
166function wp_logout_url($redirect = '') {
167 $args = array( 'action' => 'logout' );
168 if ( !empty($redirect) ) {
169 $args['redirect_to'] = $redirect;
170 }
171
172 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
173 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
174
175 return apply_filters('logout_url', $logout_url, $redirect);
176}
177
178/**
179 * Returns the Log In URL.
180 *
181 * Returns the URL that allows the user to log in to the site
182 *
183 * @since 2.7
184 * @uses site_url() To generate the log in URL
185 * @uses apply_filters() calls 'login_url' hook on final login url
186 *
187 * @param string $redirect Path to redirect to on login.
188 */
189function wp_login_url($redirect = '') {
190 $login_url = site_url('wp-login.php', 'login');
191
192 if ( !empty($redirect) ) {
193 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
194 }
195
196 return apply_filters('login_url', $login_url, $redirect);
197}
198
199/**
200 * Returns the Lost Password URL.
201 *
202 * Returns the URL that allows the user to retrieve the lost password
203 *
204 * @since 2.8.0
205 * @uses site_url() To generate the lost password URL
206 * @uses apply_filters() calls 'lostpassword_url' hook on the lostpassword url
207 *
208 * @param string $redirect Path to redirect to on login.
209 */
210function wp_lostpassword_url($redirect = '') {
211 $args = array( 'action' => 'lostpassword' );
212 if ( !empty($redirect) ) {
213 $args['redirect_to'] = $redirect;
214 }
215
216 $lostpassword_url = add_query_arg($args, site_url('wp-login.php', 'login'));
217 return apply_filters('lostpassword_url', $lostpassword_url, $redirect);
218}
219
220/**
221 * Display the Registration or Admin link.
222 *
223 * Display a link which allows the user to navigate to the registration page if
224 * not logged in and registration is enabled or to the dashboard if logged in.
225 *
226 * @since 1.5.0
227 * @uses apply_filters() Calls 'register' hook on register / admin link content.
228 *
229 * @param string $before Text to output before the link (defaults to <li>).
230 * @param string $after Text to output after the link (defaults to </li>).
231 */
232function wp_register( $before = '<li>', $after = '</li>' ) {
233
234 if ( ! is_user_logged_in() ) {
235 if ( get_option('users_can_register') )
236 $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
237 else
238 $link = '';
239 } else {
240 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
241 }
242
243 echo apply_filters('register', $link);
244}
245
246/**
247 * Theme container function for the 'wp_meta' action.
248 *
249 * The 'wp_meta' action can have several purposes, depending on how you use it,
250 * but one purpose might have been to allow for theme switching.
251 *
252 * @since 1.5.0
253 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
254 * @uses do_action() Calls 'wp_meta' hook.
255 */
256function wp_meta() {
257 do_action('wp_meta');
258}
259
260/**
261 * Display information about the blog.
262 *
263 * @see get_bloginfo() For possible values for the parameter.
264 * @since 0.71
265 *
266 * @param string $show What to display.
267 */
268function bloginfo($show='') {
269 echo get_bloginfo($show, 'display');
270}
271
272/**
273 * Retrieve information about the blog.
274 *
275 * Some show parameter values are deprecated and will be removed in future
276 * versions. Care should be taken to check the function contents and know what
277 * the deprecated blog info options are. Options without "// DEPRECATED" are
278 * the preferred and recommended ways to get the information.
279 *
280 * The possible values for the 'show' parameter are listed below.
281 * <ol>
282 * <li><strong>url<strong> - Blog URI to homepage.</li>
283 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
284 * <li><strong>description</strong> - Secondary title</li>
285 * </ol>
286 *
287 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
288 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
289 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
290 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
291 *
292 * There are many other options and you should check the function contents:
293 * {@source 32 37}
294 *
295 * @since 0.71
296 *
297 * @param string $show Blog info to retrieve.
298 * @param string $filter How to filter what is retrieved.
299 * @return string Mostly string values, might be empty.
300 */
301function get_bloginfo($show = '', $filter = 'raw') {
302
303 switch($show) {
304 case 'url' :
305 case 'home' : // DEPRECATED
306 case 'siteurl' : // DEPRECATED
307 $output = get_option('home');
308 break;
309 case 'wpurl' :
310 $output = get_option('siteurl');
311 break;
312 case 'description':
313 $output = get_option('blogdescription');
314 break;
315 case 'rdf_url':
316 $output = get_feed_link('rdf');
317 break;
318 case 'rss_url':
319 $output = get_feed_link('rss');
320 break;
321 case 'rss2_url':
322 $output = get_feed_link('rss2');
323 break;
324 case 'atom_url':
325 $output = get_feed_link('atom');
326 break;
327 case 'comments_atom_url':
328 $output = get_feed_link('comments_atom');
329 break;
330 case 'comments_rss2_url':
331 $output = get_feed_link('comments_rss2');
332 break;
333 case 'pingback_url':
334 $output = get_option('siteurl') .'/xmlrpc.php';
335 break;
336 case 'stylesheet_url':
337 $output = get_stylesheet_uri();
338 break;
339 case 'stylesheet_directory':
340 $output = get_stylesheet_directory_uri();
341 break;
342 case 'template_directory':
343 case 'template_url':
344 $output = get_template_directory_uri();
345 break;
346 case 'admin_email':
347 $output = get_option('admin_email');
348 break;
349 case 'charset':
350 $output = get_option('blog_charset');
351 if ('' == $output) $output = 'UTF-8';
352 break;
353 case 'html_type' :
354 $output = get_option('html_type');
355 break;
356 case 'version':
357 global $wp_version;
358 $output = $wp_version;
359 break;
360 case 'language':
361 $output = get_locale();
362 $output = str_replace('_', '-', $output);
363 break;
364 case 'text_direction':
365 global $wp_locale;
366 $output = $wp_locale->text_direction;
367 break;
368 case 'name':
369 default:
370 $output = get_option('blogname');
371 break;
372 }
373
374 $url = true;
375 if (strpos($show, 'url') === false &&
376 strpos($show, 'directory') === false &&
377 strpos($show, 'home') === false)
378 $url = false;
379
380 if ( 'display' == $filter ) {
381 if ( $url )
382 $output = apply_filters('bloginfo_url', $output, $show);
383 else
384 $output = apply_filters('bloginfo', $output, $show);
385 }
386
387 return $output;
388}
389
390/**
391 * Display or retrieve page title for all areas of blog.
392 *
393 * By default, the page title will display the separator before the page title,
394 * so that the blog title will be before the page title. This is not good for
395 * title display, since the blog title shows up on most tabs and not what is
396 * important, which is the page that the user is looking at.
397 *
398 * There are also SEO benefits to having the blog title after or to the 'right'
399 * or the page title. However, it is mostly common sense to have the blog title
400 * to the right with most browsers supporting tabs. You can achieve this by
401 * using the seplocation parameter and setting the value to 'right'. This change
402 * was introduced around 2.5.0, in case backwards compatibility of themes is
403 * important.
404 *
405 * @since 1.0.0
406 *
407 * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
408 * @param bool $display Optional, default is true. Whether to display or retrieve title.
409 * @param string $seplocation Optional. Direction to display title, 'right'.
410 * @return string|null String on retrieve, null when displaying.
411 */
412function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
413 global $wpdb, $wp_locale, $wp_query;
414
415 $cat = get_query_var('cat');
416 $tag = get_query_var('tag_id');
417 $category_name = get_query_var('category_name');
418 $author = get_query_var('author');
419 $author_name = get_query_var('author_name');
420 $m = get_query_var('m');
421 $year = get_query_var('year');
422 $monthnum = get_query_var('monthnum');
423 $day = get_query_var('day');
424 $search = get_query_var('s');
425 $title = '';
426
427 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
428
429 // If there's a category
430 if ( !empty($cat) ) {
431 // category exclusion
432 if ( !stristr($cat,'-') )
433 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
434 } elseif ( !empty($category_name) ) {
435 if ( stristr($category_name,'/') ) {
436 $category_name = explode('/',$category_name);
437 if ( $category_name[count($category_name)-1] )
438 $category_name = $category_name[count($category_name)-1]; // no trailing slash
439 else
440 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
441 }
442 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
443 if ( $cat )
444 $title = apply_filters('single_cat_title', $cat->name);
445 }
446
447 if ( !empty($tag) ) {
448 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
449 if ( is_wp_error( $tag ) )
450 return $tag;
451 if ( ! empty($tag->name) )
452 $title = apply_filters('single_tag_title', $tag->name);
453 }
454
455 // If there's an author
456 if ( !empty($author) ) {
457 $title = get_userdata($author);
458 $title = $title->display_name;
459 }
460 if ( !empty($author_name) ) {
461 // We do a direct query here because we don't cache by nicename.
462 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
463 }
464
465 // If there's a month
466 if ( !empty($m) ) {
467 $my_year = substr($m, 0, 4);
468 $my_month = $wp_locale->get_month(substr($m, 4, 2));
469 $my_day = intval(substr($m, 6, 2));
470 $title = "$my_year" . ($my_month ? "$t_sep$my_month" : "") . ($my_day ? "$t_sep$my_day" : "");
471 }
472
473 if ( !empty($year) ) {
474 $title = $year;
475 if ( !empty($monthnum) )
476 $title .= "$t_sep" . $wp_locale->get_month($monthnum);
477 if ( !empty($day) )
478 $title .= "$t_sep" . zeroise($day, 2);
479 }
480
481 // If there is a post
482 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
483 $post = $wp_query->get_queried_object();
484 $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
485 }
486
487 // If there's a taxonomy
488 if ( is_tax() ) {
489 $taxonomy = get_query_var( 'taxonomy' );
490 $tax = get_taxonomy( $taxonomy );
491 $tax = $tax->label;
492 $term = $wp_query->get_queried_object();
493 $term = $term->name;
494 $title = "$tax$t_sep$term";
495 }
496
497 //If it's a search
498 if ( is_search() ) {
499 /* translators: 1: separator, 2: search phrase */
500 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
501 }
502
503 if ( is_404() ) {
504 $title = __('Page not found');
505 }
506
507 $prefix = '';
508 if ( !empty($title) )
509 $prefix = " $sep ";
510
511 // Determines position of the separator and direction of the breadcrumb
512 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
513 $title_array = explode( $t_sep, $title );
514 $title_array = array_reverse( $title_array );
515 $title = implode( " $sep ", $title_array ) . $prefix;
516 } else {
517 $title_array = explode( $t_sep, $title );
518 $title = $prefix . implode( " $sep ", $title_array );
519 }
520
521 $title = apply_filters('wp_title', $title, $sep, $seplocation);
522
523 // Send it out
524 if ( $display )
525 echo $title;
526 else
527 return $title;
528
529}
530
531/**
532 * Display or retrieve page title for post.
533 *
534 * This is optimized for single.php template file for displaying the post title.
535 * Only useful for posts, does not support pages for example.
536 *
537 * It does not support placing the separator after the title, but by leaving the
538 * prefix parameter empty, you can set the title separator manually. The prefix
539 * does not automatically place a space between the prefix, so if there should
540 * be a space, the parameter value will need to have it at the end.
541 *
542 * @since 0.71
543 * @uses $wpdb
544 *
545 * @param string $prefix Optional. What to display before the title.
546 * @param bool $display Optional, default is true. Whether to display or retrieve title.
547 * @return string|null Title when retrieving, null when displaying or failure.
548 */
549function single_post_title($prefix = '', $display = true) {
550 global $wpdb;
551 $p = get_query_var('p');
552 $name = get_query_var('name');
553
554 if ( intval($p) || '' != $name ) {
555 if ( !$p )
556 $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
557 $post = & get_post($p);
558 $title = $post->post_title;
559 $title = apply_filters('single_post_title', $title);
560 if ( $display )
561 echo $prefix.strip_tags($title);
562 else
563 return strip_tags($title);
564 }
565}
566
567/**
568 * Display or retrieve page title for category archive.
569 *
570 * This is useful for category template file or files, because it is optimized
571 * for category page title and with less overhead than {@link wp_title()}.
572 *
573 * It does not support placing the separator after the title, but by leaving the
574 * prefix parameter empty, you can set the title separator manually. The prefix
575 * does not automatically place a space between the prefix, so if there should
576 * be a space, the parameter value will need to have it at the end.
577 *
578 * @since 0.71
579 *
580 * @param string $prefix Optional. What to display before the title.
581 * @param bool $display Optional, default is true. Whether to display or retrieve title.
582 * @return string|null Title when retrieving, null when displaying or failure.
583 */
584function single_cat_title($prefix = '', $display = true ) {
585 $cat = intval( get_query_var('cat') );
586 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
587 $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
588 if ( !empty($my_cat_name) ) {
589 if ( $display )
590 echo $prefix.strip_tags($my_cat_name);
591 else
592 return strip_tags($my_cat_name);
593 }
594 } else if ( is_tag() ) {
595 return single_tag_title($prefix, $display);
596 }
597}
598
599/**
600 * Display or retrieve page title for tag post archive.
601 *
602 * Useful for tag template files for displaying the tag page title. It has less
603 * overhead than {@link wp_title()}, because of its limited implementation.
604 *
605 * It does not support placing the separator after the title, but by leaving the
606 * prefix parameter empty, you can set the title separator manually. The prefix
607 * does not automatically place a space between the prefix, so if there should
608 * be a space, the parameter value will need to have it at the end.
609 *
610 * @since 2.3.0
611 *
612 * @param string $prefix Optional. What to display before the title.
613 * @param bool $display Optional, default is true. Whether to display or retrieve title.
614 * @return string|null Title when retrieving, null when displaying or failure.
615 */
616function single_tag_title($prefix = '', $display = true ) {
617 if ( !is_tag() )
618 return;
619
620 $tag_id = intval( get_query_var('tag_id') );
621
622 if ( !empty($tag_id) ) {
623 $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display');
624 if ( is_wp_error( $my_tag ) )
625 return false;
626 $my_tag_name = apply_filters('single_tag_title', $my_tag->name);
627 if ( !empty($my_tag_name) ) {
628 if ( $display )
629 echo $prefix . $my_tag_name;
630 else
631 return $my_tag_name;
632 }
633 }
634}
635
636/**
637 * Display or retrieve page title for post archive based on date.
638 *
639 * Useful for when the template only needs to display the month and year, if
640 * either are available. Optimized for just this purpose, so if it is all that
641 * is needed, should be better than {@link wp_title()}.
642 *
643 * It does not support placing the separator after the title, but by leaving the
644 * prefix parameter empty, you can set the title separator manually. The prefix
645 * does not automatically place a space between the prefix, so if there should
646 * be a space, the parameter value will need to have it at the end.
647 *
648 * @since 0.71
649 *
650 * @param string $prefix Optional. What to display before the title.
651 * @param bool $display Optional, default is true. Whether to display or retrieve title.
652 * @return string|null Title when retrieving, null when displaying or failure.
653 */
654function single_month_title($prefix = '', $display = true ) {
655 global $wp_locale;
656
657 $m = get_query_var('m');
658 $year = get_query_var('year');
659 $monthnum = get_query_var('monthnum');
660
661 if ( !empty($monthnum) && !empty($year) ) {
662 $my_year = $year;
663 $my_month = $wp_locale->get_month($monthnum);
664 } elseif ( !empty($m) ) {
665 $my_year = substr($m, 0, 4);
666 $my_month = $wp_locale->get_month(substr($m, 4, 2));
667 }
668
669 if ( empty($my_month) )
670 return false;
671
672 $result = $prefix . $my_month . $prefix . $my_year;
673
674 if ( !$display )
675 return $result;
676 echo $result;
677}
678
679/**
680 * Retrieve archive link content based on predefined or custom code.
681 *
682 * The format can be one of four styles. The 'link' for head element, 'option'
683 * for use in the select element, 'html' for use in list (either ol or ul HTML
684 * elements). Custom content is also supported using the before and after
685 * parameters.
686 *
687 * The 'link' format uses the link HTML element with the <em>archives</em>
688 * relationship. The before and after parameters are not used. The text
689 * parameter is used to describe the link.
690 *
691 * The 'option' format uses the option HTML element for use in select element.
692 * The value is the url parameter and the before and after parameters are used
693 * between the text description.
694 *
695 * The 'html' format, which is the default, uses the li HTML element for use in
696 * the list HTML elements. The before parameter is before the link and the after
697 * parameter is after the closing link.
698 *
699 * The custom format uses the before parameter before the link ('a' HTML
700 * element) and the after parameter after the closing link tag. If the above
701 * three values for the format are not used, then custom format is assumed.
702 *
703 * @since 1.0.0
704 * @author Orien
705 * @link http://icecode.com/ link navigation hack by Orien
706 *
707 * @param string $url URL to archive.
708 * @param string $text Archive text description.
709 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
710 * @param string $before Optional.
711 * @param string $after Optional.
712 * @return string HTML link content for archive.
713 */
714function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
715 $text = wptexturize($text);
716 $title_text = esc_attr($text);
717 $url = esc_url($url);
718
719 if ('link' == $format)
720 $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
721 elseif ('option' == $format)
722 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
723 elseif ('html' == $format)
724 $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
725 else // custom
726 $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
727
728 $link_html = apply_filters( "get_archives_link", $link_html );
729
730 return $link_html;
731}
732
733/**
734 * Display archive links based on type and format.
735 *
736 * The 'type' argument offers a few choices and by default will display monthly
737 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
738 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
739 * same archive link list, the difference between the two is that 'alpha'
740 * will order by post title and 'postbypost' will order by post date.
741 *
742 * The date archives will logically display dates with links to the archive post
743 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
744 * the post titles.
745 *
746 * The 'limit' argument will only display a limited amount of links, specified
747 * by the 'limit' integer value. By default, there is no limit. The
748 * 'show_post_count' argument will show how many posts are within the archive.
749 * By default, the 'show_post_count' argument is set to false.
750 *
751 * For the 'format', 'before', and 'after' arguments, see {@link
752 * get_archives_link()}. The values of these arguments have to do with that
753 * function.
754 *
755 * @since 1.2.0
756 *
757 * @param string|array $args Optional. Override defaults.
758 */
759function wp_get_archives($args = '') {
760 global $wpdb, $wp_locale;
761
762 $defaults = array(
763 'type' => 'monthly', 'limit' => '',
764 'format' => 'html', 'before' => '',
765 'after' => '', 'show_post_count' => false,
766 'echo' => 1
767 );
768
769 $r = wp_parse_args( $args, $defaults );
770 extract( $r, EXTR_SKIP );
771
772 if ( '' == $type )
773 $type = 'monthly';
774
775 if ( '' != $limit ) {
776 $limit = absint($limit);
777 $limit = ' LIMIT '.$limit;
778 }
779
780 // this is what will separate dates on weekly archive links
781 $archive_week_separator = '&#8211;';
782
783 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
784 $archive_date_format_over_ride = 0;
785
786 // options for daily archive (only if you over-ride the general date format)
787 $archive_day_date_format = 'Y/m/d';
788
789 // options for weekly archive (only if you over-ride the general date format)
790 $archive_week_start_date_format = 'Y/m/d';
791 $archive_week_end_date_format = 'Y/m/d';
792
793 if ( !$archive_date_format_over_ride ) {
794 $archive_day_date_format = get_option('date_format');
795 $archive_week_start_date_format = get_option('date_format');
796 $archive_week_end_date_format = get_option('date_format');
797 }
798
799 //filters
800 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
801 $join = apply_filters('getarchives_join', "", $r);
802
803 $output = '';
804
805 if ( 'monthly' == $type ) {
806 $query = "SELECT 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";
807 $key = md5($query);
808 $cache = wp_cache_get( 'wp_get_archives' , 'general');
809 if ( !isset( $cache[ $key ] ) ) {
810 $arcresults = $wpdb->get_results($query);
811 $cache[ $key ] = $arcresults;
812 wp_cache_add( 'wp_get_archives', $cache, 'general' );
813 } else {
814 $arcresults = $cache[ $key ];
815 }
816 if ( $arcresults ) {
817 $afterafter = $after;
818 foreach ( (array) $arcresults as $arcresult ) {
819 $url = get_month_link( $arcresult->year, $arcresult->month );
820 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
821 if ( $show_post_count )
822 $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
823 $output .= get_archives_link($url, $text, $format, $before, $after);
824 }
825 }
826 } elseif ('yearly' == $type) {
827 $query = "SELECT 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";
828 $key = md5($query);
829 $cache = wp_cache_get( 'wp_get_archives' , 'general');
830 if ( !isset( $cache[ $key ] ) ) {
831 $arcresults = $wpdb->get_results($query);
832 $cache[ $key ] = $arcresults;
833 wp_cache_add( 'wp_get_archives', $cache, 'general' );
834 } else {
835 $arcresults = $cache[ $key ];
836 }
837 if ($arcresults) {
838 $afterafter = $after;
839 foreach ( (array) $arcresults as $arcresult) {
840 $url = get_year_link($arcresult->year);
841 $text = sprintf('%d', $arcresult->year);
842 if ($show_post_count)
843 $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
844 $output .= get_archives_link($url, $text, $format, $before, $after);
845 }
846 }
847 } elseif ( 'daily' == $type ) {
848 $query = "SELECT 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";
849 $key = md5($query);
850 $cache = wp_cache_get( 'wp_get_archives' , 'general');
851 if ( !isset( $cache[ $key ] ) ) {
852 $arcresults = $wpdb->get_results($query);
853 $cache[ $key ] = $arcresults;
854 wp_cache_add( 'wp_get_archives', $cache, 'general' );
855 } else {
856 $arcresults = $cache[ $key ];
857 }
858 if ( $arcresults ) {
859 $afterafter = $after;
860 foreach ( (array) $arcresults as $arcresult ) {
861 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
862 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
863 $text = mysql2date($archive_day_date_format, $date);
864 if ($show_post_count)
865 $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
866 $output .= get_archives_link($url, $text, $format, $before, $after);
867 }
868 }
869 } elseif ( 'weekly' == $type ) {
870 $start_of_week = get_option('start_of_week');
871 $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";
872 $key = md5($query);
873 $cache = wp_cache_get( 'wp_get_archives' , 'general');
874 if ( !isset( $cache[ $key ] ) ) {
875 $arcresults = $wpdb->get_results($query);
876 $cache[ $key ] = $arcresults;
877 wp_cache_add( 'wp_get_archives', $cache, 'general' );
878 } else {
879 $arcresults = $cache[ $key ];
880 }
881 $arc_w_last = '';
882 $afterafter = $after;
883 if ( $arcresults ) {
884 foreach ( (array) $arcresults as $arcresult ) {
885 if ( $arcresult->week != $arc_w_last ) {
886 $arc_year = $arcresult->yr;
887 $arc_w_last = $arcresult->week;
888 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
889 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
890 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
891 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
892 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
893 if ($show_post_count)
894 $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
895 $output .= get_archives_link($url, $text, $format, $before, $after);
896 }
897 }
898 }
899 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
900 $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
901 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
902 $key = md5($query);
903 $cache = wp_cache_get( 'wp_get_archives' , 'general');
904 if ( !isset( $cache[ $key ] ) ) {
905 $arcresults = $wpdb->get_results($query);
906 $cache[ $key ] = $arcresults;
907 wp_cache_add( 'wp_get_archives', $cache, 'general' );
908 } else {
909 $arcresults = $cache[ $key ];
910 }
911 if ( $arcresults ) {
912 foreach ( (array) $arcresults as $arcresult ) {
913 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
914 $url = get_permalink($arcresult);
915 $arc_title = $arcresult->post_title;
916 if ( $arc_title )
917 $text = strip_tags(apply_filters('the_title', $arc_title));
918 else
919 $text = $arcresult->ID;
920 $output .= get_archives_link($url, $text, $format, $before, $after);
921 }
922 }
923 }
924 }
925 if ( $echo )
926 echo $output;
927 else
928 return $output;
929}
930
931/**
932 * Get number of days since the start of the week.
933 *
934 * @since 1.5.0
935 * @usedby get_calendar()
936 *
937 * @param int $num Number of day.
938 * @return int Days since the start of the week.
939 */
940function calendar_week_mod($num) {
941 $base = 7;
942 return ($num - $base*floor($num/$base));
943}
944
945/**
946 * Display calendar with days that have posts as links.
947 *
948 * The calendar is cached, which will be retrieved, if it exists. If there are
949 * no posts for the month, then it will not be displayed.
950 *
951 * @since 1.0.0
952 *
953 * @param bool $initial Optional, default is true. Use initial calendar names.
954 */
955function get_calendar($initial = true) {
956 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
957
958 $cache = array();
959 $key = md5( $m . $monthnum . $year );
960 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
961 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
962 echo $cache[ $key ];
963 return;
964 }
965 }
966
967 if ( !is_array($cache) )
968 $cache = array();
969
970 // Quick check. If we have no posts at all, abort!
971 if ( !$posts ) {
972 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
973 if ( !$gotsome ) {
974 $cache[ $key ] = '';
975 wp_cache_set( 'get_calendar', $cache, 'calendar' );
976 return;
977 }
978 }
979
980 ob_start();
981 if ( isset($_GET['w']) )
982 $w = ''.intval($_GET['w']);
983
984 // week_begins = 0 stands for Sunday
985 $week_begins = intval(get_option('start_of_week'));
986
987 // Let's figure out when we are
988 if ( !empty($monthnum) && !empty($year) ) {
989 $thismonth = ''.zeroise(intval($monthnum), 2);
990 $thisyear = ''.intval($year);
991 } elseif ( !empty($w) ) {
992 // We need to get the month from MySQL
993 $thisyear = ''.intval(substr($m, 0, 4));
994 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
995 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
996 } elseif ( !empty($m) ) {
997 $thisyear = ''.intval(substr($m, 0, 4));
998 if ( strlen($m) < 6 )
999 $thismonth = '01';
1000 else
1001 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1002 } else {
1003 $thisyear = gmdate('Y', current_time('timestamp'));
1004 $thismonth = gmdate('m', current_time('timestamp'));
1005 }
1006
1007 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1008
1009 // Get the next and previous month and year with at least one post
1010 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1011 FROM $wpdb->posts
1012 WHERE post_date < '$thisyear-$thismonth-01'
1013 AND post_type = 'post' AND post_status = 'publish'
1014 ORDER BY post_date DESC
1015 LIMIT 1");
1016 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1017 FROM $wpdb->posts
1018 WHERE post_date > '$thisyear-$thismonth-01'
1019 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
1020 AND post_type = 'post' AND post_status = 'publish'
1021 ORDER BY post_date ASC
1022 LIMIT 1");
1023
1024 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1025 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1026 echo '<table id="wp-calendar" summary="' . __('Calendar') . '">
1027 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1028 <thead>
1029 <tr>';
1030
1031 $myweek = array();
1032
1033 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1034 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1035 }
1036
1037 foreach ( $myweek as $wd ) {
1038 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1039 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
1040 }
1041
1042 echo '
1043 </tr>
1044 </thead>
1045
1046 <tfoot>
1047 <tr>';
1048
1049 if ( $previous ) {
1050 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
1051 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
1052 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
1053 } else {
1054 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
1055 }
1056
1057 echo "\n\t\t".'<td class="pad">&nbsp;</td>';
1058
1059 if ( $next ) {
1060 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
1061 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
1062 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
1063 } else {
1064 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
1065 }
1066
1067 echo '
1068 </tr>
1069 </tfoot>
1070
1071 <tbody>
1072 <tr>';
1073
1074 // Get days with posts
1075 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1076 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
1077 AND YEAR(post_date) = '$thisyear'
1078 AND post_type = 'post' AND post_status = 'publish'
1079 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1080 if ( $dayswithposts ) {
1081 foreach ( (array) $dayswithposts as $daywith ) {
1082 $daywithpost[] = $daywith[0];
1083 }
1084 } else {
1085 $daywithpost = array();
1086 }
1087
1088 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false)
1089 $ak_title_separator = "\n";
1090 else
1091 $ak_title_separator = ', ';
1092
1093 $ak_titles_for_day = array();
1094 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
1095 ."FROM $wpdb->posts "
1096 ."WHERE YEAR(post_date) = '$thisyear' "
1097 ."AND MONTH(post_date) = '$thismonth' "
1098 ."AND post_date < '".current_time('mysql')."' "
1099 ."AND post_type = 'post' AND post_status = 'publish'"
1100 );
1101 if ( $ak_post_titles ) {
1102 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1103
1104 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title ) );
1105
1106 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1107 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1108 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1109 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1110 else
1111 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1112 }
1113 }
1114
1115
1116 // See how much we should pad in the beginning
1117 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1118 if ( 0 != $pad )
1119 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
1120
1121 $daysinmonth = intval(date('t', $unixmonth));
1122 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1123 if ( isset($newrow) && $newrow )
1124 echo "\n\t</tr>\n\t<tr>\n\t\t";
1125 $newrow = false;
1126
1127 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)) )
1128 echo '<td id="today">';
1129 else
1130 echo '<td>';
1131
1132 if ( in_array($day, $daywithpost) ) // any posts today?
1133 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
1134 else
1135 echo $day;
1136 echo '</td>';
1137
1138 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1139 $newrow = true;
1140 }
1141
1142 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1143 if ( $pad != 0 && $pad != 7 )
1144 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
1145
1146 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
1147
1148 $output = ob_get_contents();
1149 ob_end_clean();
1150 echo $output;
1151 $cache[ $key ] = $output;
1152 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1153}
1154
1155/**
1156 * Purge the cached results of get_calendar.
1157 *
1158 * @see get_calendar
1159 * @since 2.1.0
1160 */
1161function delete_get_calendar_cache() {
1162 wp_cache_delete( 'get_calendar', 'calendar' );
1163}
1164add_action( 'save_post', 'delete_get_calendar_cache' );
1165add_action( 'delete_post', 'delete_get_calendar_cache' );
1166add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1167add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1168add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1169
1170/**
1171 * Display all of the allowed tags in HTML format with attributes.
1172 *
1173 * This is useful for displaying in the comment area, which elements and
1174 * attributes are supported. As well as any plugins which want to display it.
1175 *
1176 * @since 1.0.1
1177 * @uses $allowedtags
1178 *
1179 * @return string HTML allowed tags entity encoded.
1180 */
1181function allowed_tags() {
1182 global $allowedtags;
1183 $allowed = '';
1184 foreach ( (array) $allowedtags as $tag => $attributes ) {
1185 $allowed .= '<'.$tag;
1186 if ( 0 < count($attributes) ) {
1187 foreach ( $attributes as $attribute => $limits ) {
1188 $allowed .= ' '.$attribute.'=""';
1189 }
1190 }
1191 $allowed .= '> ';
1192 }
1193 return htmlentities($allowed);
1194}
1195
1196/***** Date/Time tags *****/
1197
1198/**
1199 * Outputs the date in iso8601 format for xml files.
1200 *
1201 * @since 1.0.0
1202 */
1203function the_date_xml() {
1204 global $post;
1205 echo mysql2date('Y-m-d', $post->post_date, false);
1206}
1207
1208/**
1209 * Display or Retrieve the date the post was written.
1210 *
1211 * Will only output the date if the current post's date is different from the
1212 * previous one output.
1213 *
1214 * @since 0.71
1215 *
1216 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1217 * @param string $before Optional. Output before the date.
1218 * @param string $after Optional. Output after the date.
1219 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1220 * @return string|null Null if displaying, string if retrieving.
1221 */
1222function the_date($d='', $before='', $after='', $echo = true) {
1223 global $post, $day, $previousday;
1224 $the_date = '';
1225 if ( $day != $previousday ) {
1226 $the_date .= $before;
1227 if ( $d=='' )
1228 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
1229 else
1230 $the_date .= mysql2date($d, $post->post_date);
1231 $the_date .= $after;
1232 $previousday = $day;
1233
1234 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
1235 if ( $echo )
1236 echo $the_date;
1237 else
1238 return $the_date;
1239 }
1240}
1241
1242/**
1243 * Display the date on which the post was last modified.
1244 *
1245 * @since 2.1.0
1246 *
1247 * @param string $d Optional. PHP date format.
1248 * @return string
1249 */
1250function the_modified_date($d = '') {
1251 echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
1252}
1253
1254/**
1255 * Retrieve the date on which the post was last modified.
1256 *
1257 * @since 2.1.0
1258 *
1259 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1260 * @return string
1261 */
1262function get_the_modified_date($d = '') {
1263 if ( '' == $d )
1264 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1265 else
1266 $the_time = get_post_modified_time($d, null, null, true);
1267 return apply_filters('get_the_modified_date', $the_time, $d);
1268}
1269
1270/**
1271 * Display the time at which the post was written.
1272 *
1273 * @since 0.71
1274 *
1275 * @param string $d Either 'G', 'U', or php date format.
1276 */
1277function the_time( $d = '' ) {
1278 echo apply_filters('the_time', get_the_time( $d ), $d);
1279}
1280
1281/**
1282 * Retrieve the time at which the post was written.
1283 *
1284 * @since 1.5.0
1285 *
1286 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1287 * @param int|object $post Optional post ID or object. Default is global $post object.
1288 * @return string
1289 */
1290function get_the_time( $d = '', $post = null ) {
1291 $post = get_post($post);
1292
1293 if ( '' == $d )
1294 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1295 else
1296 $the_time = get_post_time($d, false, $post, true);
1297 return apply_filters('get_the_time', $the_time, $d, $post);
1298}
1299
1300/**
1301 * Retrieve the time at which the post was written.
1302 *
1303 * @since 2.0.0
1304 *
1305 * @param string $d Either 'G', 'U', or php date format.
1306 * @param bool $gmt Whether of not to return the gmt time.
1307 * @param int|object $post Optional post ID or object. Default is global $post object.
1308 * @param bool $translate Whether to translate the time string or not
1309 * @return string
1310 */
1311function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
1312 $post = get_post($post);
1313
1314 if ( $gmt )
1315 $time = $post->post_date_gmt;
1316 else
1317 $time = $post->post_date;
1318
1319 $time = mysql2date($d, $time, $translate);
1320 return apply_filters('get_post_time', $time, $d, $gmt);
1321}
1322
1323/**
1324 * Display the time at which the post was last modified.
1325 *
1326 * @since 2.0.0
1327 *
1328 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1329 */
1330function the_modified_time($d = '') {
1331 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
1332}
1333
1334/**
1335 * Retrieve the time at which the post was last modified.
1336 *
1337 * @since 2.0.0
1338 *
1339 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1340 * @return string
1341 */
1342function get_the_modified_time($d = '') {
1343 if ( '' == $d )
1344 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1345 else
1346 $the_time = get_post_modified_time($d, null, null, true);
1347 return apply_filters('get_the_modified_time', $the_time, $d);
1348}
1349
1350/**
1351 * Retrieve the time at which the post was last modified.
1352 *
1353 * @since 2.0.0
1354 *
1355 * @param string $d Either 'G', 'U', or php date format.
1356 * @param bool $gmt Whether of not to return the gmt time.
1357 * @param int|object $post A post_id or post object
1358 * @param bool translate Whether to translate the result or not
1359 * @return string Returns timestamp
1360 */
1361function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1362 $post = get_post($post);
1363
1364 if ( $gmt )
1365 $time = $post->post_modified_gmt;
1366 else
1367 $time = $post->post_modified;
1368 $time = mysql2date($d, $time, $translate);
1369
1370 return apply_filters('get_post_modified_time', $time, $d, $gmt);
1371}
1372
1373/**
1374 * Display the weekday on which the post was written.
1375 *
1376 * @since 0.71
1377 * @uses $wp_locale
1378 * @uses $post
1379 */
1380function the_weekday() {
1381 global $wp_locale, $post;
1382 $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1383 $the_weekday = apply_filters('the_weekday', $the_weekday);
1384 echo $the_weekday;
1385}
1386
1387/**
1388 * Display the weekday on which the post was written.
1389 *
1390 * Will only output the weekday if the current post's weekday is different from
1391 * the previous one output.
1392 *
1393 * @since 0.71
1394 *
1395 * @param string $before output before the date.
1396 * @param string $after output after the date.
1397 */
1398function the_weekday_date($before='',$after='') {
1399 global $wp_locale, $post, $day, $previousweekday;
1400 $the_weekday_date = '';
1401 if ( $day != $previousweekday ) {
1402 $the_weekday_date .= $before;
1403 $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1404 $the_weekday_date .= $after;
1405 $previousweekday = $day;
1406 }
1407 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
1408 echo $the_weekday_date;
1409}
1410
1411/**
1412 * Fire the wp_head action
1413 *
1414 * @since 1.2.0
1415 * @uses do_action() Calls 'wp_head' hook.
1416 */
1417function wp_head() {
1418 do_action('wp_head');
1419}
1420
1421/**
1422 * Fire the wp_footer action
1423 *
1424 * @since 1.5.1
1425 * @uses do_action() Calls 'wp_footer' hook.
1426 */
1427function wp_footer() {
1428 do_action('wp_footer');
1429}
1430
1431/**
1432 * Enable/disable automatic general feed link outputting.
1433 *
1434 * @since 2.8.0
1435 *
1436 * @param boolean $add Add or remove links. Defaults to true.
1437 */
1438function automatic_feed_links( $add = true ) {
1439 if ( $add )
1440 add_action( 'wp_head', 'feed_links', 2 );
1441 else {
1442 remove_action( 'wp_head', 'feed_links', 2 );
1443 remove_action( 'wp_head', 'feed_links_extra', 3 );
1444 }
1445}
1446
1447/**
1448 * Display the links to the general feeds.
1449 *
1450 * @since 2.8.0
1451 *
1452 * @param array $args Optional arguments.
1453 */
1454function feed_links( $args ) {
1455 $defaults = array(
1456 /* translators: Separator between blog name and feed type in feed links */
1457 'separator' => _x('&raquo;', 'feed link'),
1458 /* translators: 1: blog title, 2: separator (raquo) */
1459 'feedtitle' => __('%1$s %2$s Feed'),
1460 /* translators: %s: blog title, 2: separator (raquo) */
1461 'comstitle' => __('%1$s %2$s Comments Feed'),
1462 );
1463
1464 $args = wp_parse_args( $args, $defaults );
1465
1466 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
1467 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
1468}
1469
1470/**
1471 * Display the links to the extra feeds such as category feeds.
1472 *
1473 * @since 2.8.0
1474 *
1475 * @param array $args Optional arguments.
1476 */
1477function feed_links_extra( $args ) {
1478 $defaults = array(
1479 /* translators: Separator between blog name and feed type in feed links */
1480 'separator' => _x('&raquo;', 'feed link'),
1481 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
1482 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
1483 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
1484 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
1485 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
1486 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
1487 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
1488 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
1489 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
1490 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
1491 );
1492
1493 $args = wp_parse_args( $args, $defaults );
1494
1495 if ( is_single() || is_page() ) {
1496 $post = &get_post( $id = 0 );
1497
1498 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
1499 $title = esc_attr(sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) ));
1500 $href = get_post_comments_feed_link( $post->ID );
1501 }
1502 } elseif ( is_category() ) {
1503 $cat_id = intval( get_query_var('cat') );
1504
1505 $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], get_cat_name( $cat_id ) ));
1506 $href = get_category_feed_link( $cat_id );
1507 } elseif ( is_tag() ) {
1508 $tag_id = intval( get_query_var('tag_id') );
1509 $tag = get_tag( $tag_id );
1510
1511 $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $tag->name ));
1512 $href = get_tag_feed_link( $tag_id );
1513 } elseif ( is_author() ) {
1514 $author_id = intval( get_query_var('author') );
1515
1516 $title = esc_attr(sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ));
1517 $href = get_author_feed_link( $author_id );
1518 } elseif ( is_search() ) {
1519 $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query() ));
1520 $href = get_search_feed_link();
1521 }
1522
1523 if ( isset($title) && isset($href) )
1524 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . '" />' . "\n";
1525}
1526
1527/**
1528 * Display the link to the Really Simple Discovery service endpoint.
1529 *
1530 * @link http://archipelago.phrasewise.com/rsd
1531 * @since 2.0.0
1532 */
1533function rsd_link() {
1534 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
1535}
1536
1537/**
1538 * Display the link to the Windows Live Writer manifest file.
1539 *
1540 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
1541 * @since 2.3.1
1542 */
1543function wlwmanifest_link() {
1544 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
1545 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
1546}
1547
1548/**
1549 * Display a noindex meta tag if required by the blog configuration.
1550 *
1551 * If a blog is marked as not being public then the noindex meta tag will be
1552 * output to tell web robots not to index the page content.
1553 *
1554 * @since 2.1.0
1555 */
1556function noindex() {
1557 // If the blog is not public, tell robots to go away.
1558 if ( '0' == get_option('blog_public') )
1559 echo "<meta name='robots' content='noindex,nofollow' />\n";
1560}
1561
1562/**
1563 * Determine if TinyMCE is available.
1564 *
1565 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
1566 *
1567 * @since 2.1.0
1568 *
1569 * @return bool Whether of not TinyMCE exists.
1570 */
1571function rich_edit_exists() {
1572 global $wp_rich_edit_exists;
1573 if ( !isset($wp_rich_edit_exists) )
1574 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
1575 return $wp_rich_edit_exists;
1576}
1577
1578/**
1579 * Whether or not the user should have a WYSIWIG editor.
1580 *
1581 * Checks that the user requires a WYSIWIG editor and that the editor is
1582 * supported in the users browser.
1583 *
1584 * @since 2.0.0
1585 *
1586 * @return bool
1587 */
1588function user_can_richedit() {
1589 global $wp_rich_edit, $pagenow;
1590
1591 if ( !isset( $wp_rich_edit) ) {
1592 if ( get_user_option( 'rich_editing' ) == 'true' &&
1593 ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
1594 !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
1595 && 'comment.php' != $pagenow ) {
1596 $wp_rich_edit = true;
1597 } else {
1598 $wp_rich_edit = false;
1599 }
1600 }
1601
1602 return apply_filters('user_can_richedit', $wp_rich_edit);
1603}
1604
1605/**
1606 * Find out which editor should be displayed by default.
1607 *
1608 * Works out which of the two editors to display as the current editor for a
1609 * user.
1610 *
1611 * @since 2.5.0
1612 *
1613 * @return string Either 'tinymce', or 'html', or 'test'
1614 */
1615function wp_default_editor() {
1616 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
1617 if ( $user = wp_get_current_user() ) { // look for cookie
1618 $ed = get_user_setting('editor', 'tinymce');
1619 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
1620 }
1621 return apply_filters( 'wp_default_editor', $r ); // filter
1622}
1623
1624/**
1625 * Display visual editor forms: TinyMCE, or HTML, or both.
1626 *
1627 * The amount of rows the text area will have for the content has to be between
1628 * 3 and 100 or will default at 12. There is only one option used for all users,
1629 * named 'default_post_edit_rows'.
1630 *
1631 * If the user can not use the rich editor (TinyMCE), then the switch button
1632 * will not be displayed.
1633 *
1634 * @since 2.1.0
1635 *
1636 * @param string $content Textarea content.
1637 * @param string $id HTML ID attribute value.
1638 * @param string $prev_id HTML ID name for switching back and forth between visual editors.
1639 * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
1640 * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
1641 */
1642function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
1643 $rows = get_option('default_post_edit_rows');
1644 if (($rows < 3) || ($rows > 100))
1645 $rows = 12;
1646
1647 if ( !current_user_can( 'upload_files' ) )
1648 $media_buttons = false;
1649
1650 $richedit = user_can_richedit();
1651 $class = '';
1652
1653 if ( $richedit || $media_buttons ) { ?>
1654 <div id="editor-toolbar">
1655<?php
1656 if ( $richedit ) {
1657 $wp_default_editor = wp_default_editor(); ?>
1658 <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
1659<?php if ( 'html' == $wp_default_editor ) {
1660 add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
1661 <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1662 <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1663<?php } else {
1664 $class = " class='theEditor'";
1665 add_filter('the_editor_content', 'wp_richedit_pre'); ?>
1666 <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1667 <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1668<?php }
1669 }
1670
1671 if ( $media_buttons ) { ?>
1672 <div id="media-buttons" class="hide-if-no-js">
1673<?php do_action( 'media_buttons' ); ?>
1674 </div>
1675<?php
1676 } ?>
1677 </div>
1678<?php
1679 }
1680?>
1681 <div id="quicktags"><?php
1682 wp_print_scripts( 'quicktags' ); ?>
1683 <script type="text/javascript">edToolbar()</script>
1684 </div>
1685
1686<?php
1687 $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
1688 $the_editor_content = apply_filters('the_editor_content', $content);
1689
1690 printf($the_editor, $the_editor_content);
1691
1692?>
1693 <script type="text/javascript">
1694 edCanvas = document.getElementById('<?php echo $id; ?>');
1695 </script>
1696<?php
1697}
1698
1699/**
1700 * Retrieve the contents of the search WordPress query variable.
1701 *
1702 * @since 2.3.0
1703 *
1704 * @return string
1705 */
1706function get_search_query() {
1707 return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) );
1708}
1709
1710/**
1711 * Display the contents of the search query variable.
1712 *
1713 * The search query string is passed through {@link esc_attr()}
1714 * to ensure that it is safe for placing in an html attribute.
1715 *
1716 * @uses attr
1717 * @since 2.1.0
1718 */
1719function the_search_query() {
1720 echo esc_attr( apply_filters( 'the_search_query', get_search_query() ) );
1721}
1722
1723/**
1724 * Display the language attributes for the html tag.
1725 *
1726 * Builds up a set of html attributes containing the text direction and language
1727 * information for the page.
1728 *
1729 * @since 2.1.0
1730 *
1731 * @param string $doctype The type of html document (xhtml|html).
1732 */
1733function language_attributes($doctype = 'html') {
1734 $attributes = array();
1735 $output = '';
1736
1737 if ( $dir = get_bloginfo('text_direction') )
1738 $attributes[] = "dir=\"$dir\"";
1739
1740 if ( $lang = get_bloginfo('language') ) {
1741 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
1742 $attributes[] = "lang=\"$lang\"";
1743
1744 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1745 $attributes[] = "xml:lang=\"$lang\"";
1746 }
1747
1748 $output = implode(' ', $attributes);
1749 $output = apply_filters('language_attributes', $output);
1750 echo $output;
1751}
1752
1753/**
1754 * Retrieve paginated link for archive post pages.
1755 *
1756 * Technically, the function can be used to create paginated link list for any
1757 * area. The 'base' argument is used to reference the url, which will be used to
1758 * create the paginated links. The 'format' argument is then used for replacing
1759 * the page number. It is however, most likely and by default, to be used on the
1760 * archive post pages.
1761 *
1762 * The 'type' argument controls format of the returned value. The default is
1763 * 'plain', which is just a string with the links separated by a newline
1764 * character. The other possible values are either 'array' or 'list'. The
1765 * 'array' value will return an array of the paginated link list to offer full
1766 * control of display. The 'list' value will place all of the paginated links in
1767 * an unordered HTML list.
1768 *
1769 * The 'total' argument is the total amount of pages and is an integer. The
1770 * 'current' argument is the current page number and is also an integer.
1771 *
1772 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
1773 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
1774 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
1775 * and the '%#%' is also required. The '%#%' will be replaced with the page
1776 * number.
1777 *
1778 * You can include the previous and next links in the list by setting the
1779 * 'prev_next' argument to true, which it is by default. You can set the
1780 * previous text, by using the 'prev_text' argument. You can set the next text
1781 * by setting the 'next_text' argument.
1782 *
1783 * If the 'show_all' argument is set to true, then it will show all of the pages
1784 * instead of a short list of the pages near the current page. By default, the
1785 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
1786 * arguments. The 'end_size' argument is how many numbers on either the start
1787 * and the end list edges, by default is 1. The 'mid_size' argument is how many
1788 * numbers to either side of current page, but not including current page.
1789 *
1790 * It is possible to add query vars to the link by using the 'add_args' argument
1791 * and see {@link add_query_arg()} for more information.
1792 *
1793 * @since 2.1.0
1794 *
1795 * @param string|array $args Optional. Override defaults.
1796 * @return array|string String of page links or array of page links.
1797 */
1798function paginate_links( $args = '' ) {
1799 $defaults = array(
1800 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1801 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1802 'total' => 1,
1803 'current' => 0,
1804 'show_all' => false,
1805 'prev_next' => true,
1806 'prev_text' => __('&laquo; Previous'),
1807 'next_text' => __('Next &raquo;'),
1808 'end_size' => 1,
1809 'mid_size' => 2,
1810 'type' => 'plain',
1811 'add_args' => false, // array of query args to add
1812 'add_fragment' => ''
1813 );
1814
1815 $args = wp_parse_args( $args, $defaults );
1816 extract($args, EXTR_SKIP);
1817
1818 // Who knows what else people pass in $args
1819 $total = (int) $total;
1820 if ( $total < 2 )
1821 return;
1822 $current = (int) $current;
1823 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
1824 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
1825 $add_args = is_array($add_args) ? $add_args : false;
1826 $r = '';
1827 $page_links = array();
1828 $n = 0;
1829 $dots = false;
1830
1831 if ( $prev_next && $current && 1 < $current ) :
1832 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
1833 $link = str_replace('%#%', $current - 1, $link);
1834 if ( $add_args )
1835 $link = add_query_arg( $add_args, $link );
1836 $link .= $add_fragment;
1837 $page_links[] = "<a class='prev page-numbers' href='" . esc_url($link) . "'>$prev_text</a>";
1838 endif;
1839 for ( $n = 1; $n <= $total; $n++ ) :
1840 $n_display = number_format_i18n($n);
1841 if ( $n == $current ) :
1842 $page_links[] = "<span class='page-numbers current'>$n_display</span>";
1843 $dots = true;
1844 else :
1845 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
1846 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
1847 $link = str_replace('%#%', $n, $link);
1848 if ( $add_args )
1849 $link = add_query_arg( $add_args, $link );
1850 $link .= $add_fragment;
1851 $page_links[] = "<a class='page-numbers' href='" . esc_url($link) . "'>$n_display</a>";
1852 $dots = true;
1853 elseif ( $dots && !$show_all ) :
1854 $page_links[] = "<span class='page-numbers dots'>...</span>";
1855 $dots = false;
1856 endif;
1857 endif;
1858 endfor;
1859 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
1860 $link = str_replace('%_%', $format, $base);
1861 $link = str_replace('%#%', $current + 1, $link);
1862 if ( $add_args )
1863 $link = add_query_arg( $add_args, $link );
1864 $link .= $add_fragment;
1865 $page_links[] = "<a class='next page-numbers' href='" . esc_url($link) . "'>$next_text</a>";
1866 endif;
1867 switch ( $type ) :
1868 case 'array' :
1869 return $page_links;
1870 break;
1871 case 'list' :
1872 $r .= "<ul class='page-numbers'>\n\t<li>";
1873 $r .= join("</li>\n\t<li>", $page_links);
1874 $r .= "</li>\n</ul>\n";
1875 break;
1876 default :
1877 $r = join("\n", $page_links);
1878 break;
1879 endswitch;
1880 return $r;
1881}
1882
1883/**
1884 * Registers an admin colour scheme css file.
1885 *
1886 * Allows a plugin to register a new admin colour scheme. For example:
1887 * <code>
1888 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
1889 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
1890 * </code>
1891 *
1892 * @since 2.5.0
1893 *
1894 * @param string $key The unique key for this theme.
1895 * @param string $name The name of the theme.
1896 * @param string $url The url of the css file containing the colour scheme.
1897 * @param array @colors An array of CSS color definitions which are used to give the user a feel for the theme.
1898 */
1899function wp_admin_css_color($key, $name, $url, $colors = array()) {
1900 global $_wp_admin_css_colors;
1901
1902 if ( !isset($_wp_admin_css_colors) )
1903 $_wp_admin_css_colors = array();
1904
1905 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
1906}
1907
1908/**
1909 * Display the URL of a WordPress admin CSS file.
1910 *
1911 * @see WP_Styles::_css_href and its style_loader_src filter.
1912 *
1913 * @since 2.3.0
1914 *
1915 * @param string $file file relative to wp-admin/ without its ".css" extension.
1916 */
1917function wp_admin_css_uri( $file = 'wp-admin' ) {
1918 if ( defined('WP_INSTALLING') ) {
1919 $_file = "./$file.css";
1920 } else {
1921 $_file = admin_url("$file.css");
1922 }
1923 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
1924
1925 return apply_filters( 'wp_admin_css_uri', $_file, $file );
1926}
1927
1928/**
1929 * Enqueues or directly prints a stylesheet link to the specified CSS file.
1930 *
1931 * "Intelligently" decides to enqueue or to print the CSS file. If the
1932 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
1933 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
1934 * be printed. Printing may be forced by passing TRUE as the $force_echo
1935 * (second) parameter.
1936 *
1937 * For backward compatibility with WordPress 2.3 calling method: If the $file
1938 * (first) parameter does not correspond to a registered CSS file, we assume
1939 * $file is a file relative to wp-admin/ without its ".css" extension. A
1940 * stylesheet link to that generated URL is printed.
1941 *
1942 * @package WordPress
1943 * @since 2.3.0
1944 * @uses $wp_styles WordPress Styles Object
1945 *
1946 * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
1947 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
1948 */
1949function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
1950 global $wp_styles;
1951 if ( !is_a($wp_styles, 'WP_Styles') )
1952 $wp_styles = new WP_Styles();
1953
1954 // For backward compatibility
1955 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
1956
1957 if ( $wp_styles->query( $handle ) ) {
1958 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
1959 wp_print_styles( $handle );
1960 else // Add to style queue
1961 wp_enqueue_style( $handle );
1962 return;
1963 }
1964
1965 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
1966 if ( 'rtl' == get_bloginfo( 'text_direction' ) )
1967 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
1968}
1969
1970/**
1971 * Enqueues the default ThickBox js and css.
1972 *
1973 * If any of the settings need to be changed, this can be done with another js
1974 * file similar to media-upload.js and theme-preview.js. That file should
1975 * require array('thickbox') to ensure it is loaded after.
1976 *
1977 * @since 2.5.0
1978 */
1979function add_thickbox() {
1980 wp_enqueue_script( 'thickbox' );
1981 wp_enqueue_style( 'thickbox' );
1982}
1983
1984/**
1985 * Display the XHTML generator that is generated on the wp_head hook.
1986 *
1987 * @since 2.5.0
1988 */
1989function wp_generator() {
1990 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
1991}
1992
1993/**
1994 * Display the generator XML or Comment for RSS, ATOM, etc.
1995 *
1996 * Returns the correct generator type for the requested output format. Allows
1997 * for a plugin to filter generators overall the the_generator filter.
1998 *
1999 * @since 2.5.0
2000 * @uses apply_filters() Calls 'the_generator' hook.
2001 *
2002 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2003 */
2004function the_generator( $type ) {
2005 echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
2006}
2007
2008/**
2009 * Creates the generator XML or Comment for RSS, ATOM, etc.
2010 *
2011 * Returns the correct generator type for the requested output format. Allows
2012 * for a plugin to filter generators on an individual basis using the
2013 * 'get_the_generator_{$type}' filter.
2014 *
2015 * @since 2.5.0
2016 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
2017 *
2018 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2019 * @return string The HTML content for the generator.
2020 */
2021function get_the_generator( $type ) {
2022 switch ($type) {
2023 case 'html':
2024 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2025 break;
2026 case 'xhtml':
2027 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2028 break;
2029 case 'atom':
2030 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2031 break;
2032 case 'rss2':
2033 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2034 break;
2035 case 'rdf':
2036 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2037 break;
2038 case 'comment':
2039 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2040 break;
2041 case 'export':
2042 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
2043 break;
2044 }
2045 return apply_filters( "get_the_generator_{$type}", $gen, $type );
2046}
2047
2048?>
Note: See TracBrowser for help on using the repository browser.