]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/general-template.php
WordPress 3.9
[autoinstalls/wordpress.git] / wp-includes / general-template.php
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.
14  *
15  * For the parameter, if the file is called "header-special.php" then specify
16  * "special".
17  *
18  * @since 1.5.0
19  *
20  * @uses locate_template()
21  *
22  * @param string $name The name of the specialised header.
23  */
24 function get_header( $name = null ) {
25         /**
26          * Fires before the header template file is loaded.
27          *
28          * The hook allows a specific header template file to be used in place of the
29          * default header template file. If your file is called header-new.php,
30          * you would specify the filename in the hook as get_header( 'new' ).
31          *
32          * @since 2.1.0
33          * @since 2.8.0 $name parameter added.
34          *
35          * @param string $name Name of the specific header file to use.
36          */
37         do_action( 'get_header', $name );
38
39         $templates = array();
40         $name = (string) $name;
41         if ( '' !== $name )
42                 $templates[] = "header-{$name}.php";
43
44         $templates[] = 'header.php';
45
46         // Backward compat code will be removed in a future release
47         if ('' == locate_template($templates, true))
48                 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
49 }
50
51 /**
52  * Load footer template.
53  *
54  * Includes the footer template for a theme or if a name is specified then a
55  * specialised footer will be included.
56  *
57  * For the parameter, if the file is called "footer-special.php" then specify
58  * "special".
59  *
60  * @since 1.5.0
61  *
62  * @uses locate_template()
63  *
64  * @param string $name The name of the specialised footer.
65  */
66 function get_footer( $name = null ) {
67         /**
68          * Fires before the footer template file is loaded.
69          *
70          * The hook allows a specific footer template file to be used in place of the
71          * default footer template file. If your file is called footer-new.php,
72          * you would specify the filename in the hook as get_footer( 'new' ).
73          *
74          * @since 2.1.0
75          * @since 2.8.0 $name parameter added.
76          *
77          * @param string $name Name of the specific footer file to use.
78          */
79         do_action( 'get_footer', $name );
80
81         $templates = array();
82         $name = (string) $name;
83         if ( '' !== $name )
84                 $templates[] = "footer-{$name}.php";
85
86         $templates[] = 'footer.php';
87
88         // Backward compat code will be removed in a future release
89         if ('' == locate_template($templates, true))
90                 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
91 }
92
93 /**
94  * Load sidebar template.
95  *
96  * Includes the sidebar template for a theme or if a name is specified then a
97  * specialised sidebar will be included.
98  *
99  * For the parameter, if the file is called "sidebar-special.php" then specify
100  * "special".
101  *
102  * @since 1.5.0
103  *
104  * @uses locate_template()
105  *
106  * @param string $name The name of the specialised sidebar.
107  */
108 function get_sidebar( $name = null ) {
109         /**
110          * Fires before the sidebar template file is loaded.
111          *
112          * The hook allows a specific sidebar template file to be used in place of the
113          * default sidebar template file. If your file is called sidebar-new.php,
114          * you would specify the filename in the hook as get_sidebar( 'new' ).
115          *
116          * @since 2.2.0
117          * @since 2.8.0 $name parameter added.
118          *
119          * @param string $name Name of the specific sidebar file to use.
120          */
121         do_action( 'get_sidebar', $name );
122
123         $templates = array();
124         $name = (string) $name;
125         if ( '' !== $name )
126                 $templates[] = "sidebar-{$name}.php";
127
128         $templates[] = 'sidebar.php';
129
130         // Backward compat code will be removed in a future release
131         if ('' == locate_template($templates, true))
132                 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
133 }
134
135 /**
136  * Load a template part into a template
137  *
138  * Makes it easy for a theme to reuse sections of code in a easy to overload way
139  * for child themes.
140  *
141  * Includes the named template part for a theme or if a name is specified then a
142  * specialised part will be included. If the theme contains no {slug}.php file
143  * then no template will be included.
144  *
145  * The template is included using require, not require_once, so you may include the
146  * same template part multiple times.
147  *
148  * For the $name parameter, if the file is called "{slug}-special.php" then specify
149  * "special".
150  *
151  * @since 3.0.0
152  *
153  * @uses locate_template()
154  *
155  * @param string $slug The slug name for the generic template.
156  * @param string $name The name of the specialised template.
157  */
158 function get_template_part( $slug, $name = null ) {
159         /**
160          * Fires before the specified template part file is loaded.
161          *
162          * The dynamic portion of the hook name, $slug, refers to the slug name
163          * for the generic template part.
164          *
165          * @since 3.0.0
166          *
167          * @param string $slug The slug name for the generic template.
168          * @param string $name The name of the specialized template.
169          */
170         do_action( "get_template_part_{$slug}", $slug, $name );
171
172         $templates = array();
173         $name = (string) $name;
174         if ( '' !== $name )
175                 $templates[] = "{$slug}-{$name}.php";
176
177         $templates[] = "{$slug}.php";
178
179         locate_template($templates, true, false);
180 }
181
182 /**
183  * Display search form.
184  *
185  * Will first attempt to locate the searchform.php file in either the child or
186  * the parent, then load it. If it doesn't exist, then the default search form
187  * will be displayed. The default search form is HTML, which will be displayed.
188  * There is a filter applied to the search form HTML in order to edit or replace
189  * it. The filter is 'get_search_form'.
190  *
191  * This function is primarily used by themes which want to hardcode the search
192  * form into the sidebar and also by the search widget in WordPress.
193  *
194  * There is also an action that is called whenever the function is run called,
195  * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
196  * search relies on or various formatting that applies to the beginning of the
197  * search. To give a few examples of what it can be used for.
198  *
199  * @since 2.7.0
200  *
201  * @param boolean $echo Default to echo and not return the form.
202  * @return string|null String when retrieving, null when displaying or if searchform.php exists.
203  */
204 function get_search_form( $echo = true ) {
205         /**
206          * Fires before the search form is retrieved, at the start of get_search_form().
207          *
208          * @since 2.7.0 as 'get_search_form' action.
209          * @since 3.6.0
210          *
211          * @link https://core.trac.wordpress.org/ticket/19321
212          */
213         do_action( 'pre_get_search_form' );
214
215         $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
216
217         /**
218          * Filter the HTML format of the search form.
219          *
220          * @since 3.6.0
221          *
222          * @param string $format The type of markup to use in the search form.
223          *                       Accepts 'html5', 'xhtml'.
224          */
225         $format = apply_filters( 'search_form_format', $format );
226
227         $search_form_template = locate_template( 'searchform.php' );
228         if ( '' != $search_form_template ) {
229                 ob_start();
230                 require( $search_form_template );
231                 $form = ob_get_clean();
232         } else {
233                 if ( 'html5' == $format ) {
234                         $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
235                                 <label>
236                                         <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
237                                         <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
238                                 </label>
239                                 <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
240                         </form>';
241                 } else {
242                         $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
243                                 <div>
244                                         <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
245                                         <input type="text" value="' . get_search_query() . '" name="s" id="s" />
246                                         <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
247                                 </div>
248                         </form>';
249                 }
250         }
251
252         /**
253          * Filter the HTML output of the search form.
254          *
255          * @since 2.7.0
256          *
257          * @param string $form The search form HTML output.
258          */
259         $result = apply_filters( 'get_search_form', $form );
260
261         if ( null === $result )
262                 $result = $form;
263
264         if ( $echo )
265                 echo $result;
266         else
267                 return $result;
268 }
269
270 /**
271  * Display the Log In/Out link.
272  *
273  * Displays a link, which allows users to navigate to the Log In page to log in
274  * or log out depending on whether they are currently logged in.
275  *
276  * @since 1.5.0
277  *
278  * @param string $redirect Optional path to redirect to on login/logout.
279  * @param boolean $echo Default to echo and not return the link.
280  * @return string|null String when retrieving, null when displaying.
281  */
282 function wp_loginout($redirect = '', $echo = true) {
283         if ( ! is_user_logged_in() )
284                 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
285         else
286                 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
287
288         if ( $echo ) {
289                 /**
290                  * Filter the HTML output for the Log In/Log Out link.
291                  *
292                  * @since 1.5.0
293                  *
294                  * @param string $link The HTML link content.
295                  */
296                 echo apply_filters( 'loginout', $link );
297         } else {
298                 /** This filter is documented in wp-includes/general-template.php */
299                 return apply_filters( 'loginout', $link );
300         }
301 }
302
303 /**
304  * Returns the Log Out URL.
305  *
306  * Returns the URL that allows the user to log out of the site.
307  *
308  * @since 2.7.0
309  *
310  * @uses wp_nonce_url() To protect against CSRF.
311  * @uses site_url() To generate the log out URL.
312  *
313  * @param string $redirect Path to redirect to on logout.
314  * @return string A log out URL.
315  */
316 function wp_logout_url($redirect = '') {
317         $args = array( 'action' => 'logout' );
318         if ( !empty($redirect) ) {
319                 $args['redirect_to'] = urlencode( $redirect );
320         }
321
322         $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
323         $logout_url = wp_nonce_url( $logout_url, 'log-out' );
324
325         /**
326          * Filter the logout URL.
327          *
328          * @since 2.8.0
329          *
330          * @param string $logout_url The Log Out URL.
331          * @param string $redirect   Path to redirect to on logout.
332          */
333         return apply_filters( 'logout_url', $logout_url, $redirect );
334 }
335
336 /**
337  * Returns the Log In URL.
338  *
339  * Returns the URL that allows the user to log in to the site.
340  *
341  * @since 2.7.0
342  *
343  * @uses site_url() To generate the log in URL.
344  *
345  * @param string $redirect Path to redirect to on login.
346  * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
347  * @return string A log in URL.
348  */
349 function wp_login_url($redirect = '', $force_reauth = false) {
350         $login_url = site_url('wp-login.php', 'login');
351
352         if ( !empty($redirect) )
353                 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
354
355         if ( $force_reauth )
356                 $login_url = add_query_arg('reauth', '1', $login_url);
357
358         /**
359          * Filter the login URL.
360          *
361          * @since 2.8.0
362          *
363          * @param string $login_url The login URL.
364          * @param string $redirect  The path to redirect to on login, if supplied.
365          */
366         return apply_filters( 'login_url', $login_url, $redirect );
367 }
368
369 /**
370  * Returns the user registration URL.
371  *
372  * Returns the URL that allows the user to register on the site.
373  *
374  * @since 3.6.0
375  *
376  * @uses site_url() To generate the registration URL.
377  *
378  * @return string User registration URL.
379  */
380 function wp_registration_url() {
381         /**
382          * Filter the user registration URL.
383          *
384          * @since 3.6.0
385          *
386          * @param string $register The user registration URL.
387          */
388         return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
389 }
390
391 /**
392  * Provides a simple login form for use anywhere within WordPress. By default, it echoes
393  * the HTML immediately. Pass array('echo'=>false) to return the string instead.
394  *
395  * @since 3.0.0
396  *
397  * @param array $args Configuration options to modify the form output.
398  * @return string|null String when retrieving, null when displaying.
399  */
400 function wp_login_form( $args = array() ) {
401         $defaults = array(
402                 'echo' => true,
403                 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
404                 'form_id' => 'loginform',
405                 'label_username' => __( 'Username' ),
406                 'label_password' => __( 'Password' ),
407                 'label_remember' => __( 'Remember Me' ),
408                 'label_log_in' => __( 'Log In' ),
409                 'id_username' => 'user_login',
410                 'id_password' => 'user_pass',
411                 'id_remember' => 'rememberme',
412                 'id_submit' => 'wp-submit',
413                 'remember' => true,
414                 'value_username' => '',
415                 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
416         );
417
418         /**
419          * Filter the default login form output arguments.
420          *
421          * @since 3.0.0
422          *
423          * @see wp_login_form()
424          *
425          * @param array $defaults An array of default login form arguments.
426          */
427         $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
428
429         /**
430          * Filter content to display at the top of the login form.
431          *
432          * The filter evaluates just following the opening form tag element.
433          *
434          * @since 3.0.0
435          *
436          * @param string $content Content to display. Default empty.
437          * @param array  $args    Array of login form arguments.
438          */
439         $login_form_top = apply_filters( 'login_form_top', '', $args );
440
441         /**
442          * Filter content to display in the middle of the login form.
443          *
444          * The filter evaluates just following the location where the 'login-password'
445          * field is displayed.
446          *
447          * @since 3.0.0
448          *
449          * @param string $content Content to display. Default empty.
450          * @param array  $args    Array of login form arguments.
451          */
452         $login_form_middle = apply_filters( 'login_form_middle', '', $args );
453
454         /**
455          * Filter content to display at the bottom of the login form.
456          *
457          * The filter evaluates just preceding the closing form tag element.
458          *
459          * @since 3.0.0
460          *
461          * @param string $content Content to display. Default empty.
462          * @param array  $args    Array of login form arguments.
463          */
464         $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
465
466         $form = '
467                 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
468                         ' . $login_form_top . '
469                         <p class="login-username">
470                                 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
471                                 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
472                         </p>
473                         <p class="login-password">
474                                 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
475                                 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
476                         </p>
477                         ' . $login_form_middle . '
478                         ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
479                         <p class="login-submit">
480                                 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
481                                 <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
482                         </p>
483                         ' . $login_form_bottom . '
484                 </form>';
485
486         if ( $args['echo'] )
487                 echo $form;
488         else
489                 return $form;
490 }
491
492 /**
493  * Returns the Lost Password URL.
494  *
495  * Returns the URL that allows the user to retrieve the lost password
496  *
497  * @since 2.8.0
498  *
499  * @uses site_url() To generate the lost password URL
500  *
501  * @param string $redirect Path to redirect to on login.
502  * @return string Lost password URL.
503  */
504 function wp_lostpassword_url( $redirect = '' ) {
505         $args = array( 'action' => 'lostpassword' );
506         if ( !empty($redirect) ) {
507                 $args['redirect_to'] = $redirect;
508         }
509
510         $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
511
512         /**
513          * Filter the Lost Password URL.
514          *
515          * @since 2.8.0
516          *
517          * @param string $lostpassword_url The lost password page URL.
518          * @param string $redirect         The path to redirect to on login.
519          */
520         return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
521 }
522
523 /**
524  * Display the Registration or Admin link.
525  *
526  * Display a link which allows the user to navigate to the registration page if
527  * not logged in and registration is enabled or to the dashboard if logged in.
528  *
529  * @since 1.5.0
530  *
531  * @param string $before Text to output before the link (defaults to <li>).
532  * @param string $after Text to output after the link (defaults to </li>).
533  * @param boolean $echo Default to echo and not return the link.
534  * @return string|null String when retrieving, null when displaying.
535  */
536 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
537
538         if ( ! is_user_logged_in() ) {
539                 if ( get_option('users_can_register') )
540                         $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
541                 else
542                         $link = '';
543         } else {
544                 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
545         }
546
547         if ( $echo ) {
548                 /**
549                  * Filter the HTML link to the Registration or Admin page.
550                  *
551                  * Users are sent to the admin page if logged-in, or the registration page
552                  * if enabled and logged-out.
553                  *
554                  * @since 1.5.0
555                  *
556                  * @param string $link The HTML code for the link to the Registration or Admin page.
557                  */
558                 echo apply_filters( 'register', $link );
559         } else {
560                 /** This filter is documented in wp-includes/general-template.php */
561                 return apply_filters( 'register', $link );
562         }
563 }
564
565 /**
566  * Theme container function for the 'wp_meta' action.
567  *
568  * The 'wp_meta' action can have several purposes, depending on how you use it,
569  * but one purpose might have been to allow for theme switching.
570  *
571  * @since 1.5.0
572  *
573  * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
574  */
575 function wp_meta() {
576         /**
577          * Fires before displaying echoed content in the sidebar.
578          *
579          * @since 1.5.0
580          */
581         do_action( 'wp_meta' );
582 }
583
584 /**
585  * Display information about the blog.
586  *
587  * @see get_bloginfo() For possible values for the parameter.
588  * @since 0.71
589  *
590  * @param string $show What to display.
591  */
592 function bloginfo( $show='' ) {
593         echo get_bloginfo( $show, 'display' );
594 }
595
596 /**
597  * Retrieve information about the blog.
598  *
599  * Some show parameter values are deprecated and will be removed in future
600  * versions. These options will trigger the _deprecated_argument() function.
601  * The deprecated blog info options are listed in the function contents.
602  *
603  * The possible values for the 'show' parameter are listed below.
604  * <ol>
605  * <li><strong>url</strong> - Blog URI to homepage.</li>
606  * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
607  * <li><strong>description</strong> - Secondary title</li>
608  * </ol>
609  *
610  * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
611  * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
612  * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
613  * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
614  *
615  * @since 0.71
616  *
617  * @param string $show Blog info to retrieve.
618  * @param string $filter How to filter what is retrieved.
619  * @return string Mostly string values, might be empty.
620  */
621 function get_bloginfo( $show = '', $filter = 'raw' ) {
622
623         switch( $show ) {
624                 case 'home' : // DEPRECATED
625                 case 'siteurl' : // DEPRECATED
626                         _deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url'  ) );
627                 case 'url' :
628                         $output = home_url();
629                         break;
630                 case 'wpurl' :
631                         $output = site_url();
632                         break;
633                 case 'description':
634                         $output = get_option('blogdescription');
635                         break;
636                 case 'rdf_url':
637                         $output = get_feed_link('rdf');
638                         break;
639                 case 'rss_url':
640                         $output = get_feed_link('rss');
641                         break;
642                 case 'rss2_url':
643                         $output = get_feed_link('rss2');
644                         break;
645                 case 'atom_url':
646                         $output = get_feed_link('atom');
647                         break;
648                 case 'comments_atom_url':
649                         $output = get_feed_link('comments_atom');
650                         break;
651                 case 'comments_rss2_url':
652                         $output = get_feed_link('comments_rss2');
653                         break;
654                 case 'pingback_url':
655                         $output = site_url( 'xmlrpc.php' );
656                         break;
657                 case 'stylesheet_url':
658                         $output = get_stylesheet_uri();
659                         break;
660                 case 'stylesheet_directory':
661                         $output = get_stylesheet_directory_uri();
662                         break;
663                 case 'template_directory':
664                 case 'template_url':
665                         $output = get_template_directory_uri();
666                         break;
667                 case 'admin_email':
668                         $output = get_option('admin_email');
669                         break;
670                 case 'charset':
671                         $output = get_option('blog_charset');
672                         if ('' == $output) $output = 'UTF-8';
673                         break;
674                 case 'html_type' :
675                         $output = get_option('html_type');
676                         break;
677                 case 'version':
678                         global $wp_version;
679                         $output = $wp_version;
680                         break;
681                 case 'language':
682                         $output = get_locale();
683                         $output = str_replace('_', '-', $output);
684                         break;
685                 case 'text_direction':
686                         //_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()'  ) );
687                         if ( function_exists( 'is_rtl' ) ) {
688                                 $output = is_rtl() ? 'rtl' : 'ltr';
689                         } else {
690                                 $output = 'ltr';
691                         }
692                         break;
693                 case 'name':
694                 default:
695                         $output = get_option('blogname');
696                         break;
697         }
698
699         $url = true;
700         if (strpos($show, 'url') === false &&
701                 strpos($show, 'directory') === false &&
702                 strpos($show, 'home') === false)
703                 $url = false;
704
705         if ( 'display' == $filter ) {
706                 if ( $url ) {
707                         /**
708                          * Filter the URL returned by get_bloginfo().
709                          *
710                          * @since 2.0.5
711                          *
712                          * @param mixed $output The URL returned by bloginfo().
713                          * @param mixed $show   Type of information requested.
714                          */
715                         $output = apply_filters( 'bloginfo_url', $output, $show );
716                 } else {
717                         /**
718                          * Filter the site information returned by get_bloginfo().
719                          *
720                          * @since 0.71
721                          *
722                          * @param mixed $output The requested non-URL site information.
723                          * @param mixed $show   Type of information requested.
724                          */
725                         $output = apply_filters( 'bloginfo', $output, $show );
726                 }
727         }
728
729         return $output;
730 }
731
732 /**
733  * Display or retrieve page title for all areas of blog.
734  *
735  * By default, the page title will display the separator before the page title,
736  * so that the blog title will be before the page title. This is not good for
737  * title display, since the blog title shows up on most tabs and not what is
738  * important, which is the page that the user is looking at.
739  *
740  * There are also SEO benefits to having the blog title after or to the 'right'
741  * or the page title. However, it is mostly common sense to have the blog title
742  * to the right with most browsers supporting tabs. You can achieve this by
743  * using the seplocation parameter and setting the value to 'right'. This change
744  * was introduced around 2.5.0, in case backwards compatibility of themes is
745  * important.
746  *
747  * @since 1.0.0
748  *
749  * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
750  * @param bool $display Optional, default is true. Whether to display or retrieve title.
751  * @param string $seplocation Optional. Direction to display title, 'right'.
752  * @return string|null String on retrieve, null when displaying.
753  */
754 function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
755         global $wpdb, $wp_locale;
756
757         $m = get_query_var('m');
758         $year = get_query_var('year');
759         $monthnum = get_query_var('monthnum');
760         $day = get_query_var('day');
761         $search = get_query_var('s');
762         $title = '';
763
764         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
765
766         // If there is a post
767         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
768                 $title = single_post_title( '', false );
769         }
770
771         // If there's a post type archive
772         if ( is_post_type_archive() ) {
773                 $post_type = get_query_var( 'post_type' );
774                 if ( is_array( $post_type ) )
775                         $post_type = reset( $post_type );
776                 $post_type_object = get_post_type_object( $post_type );
777                 if ( ! $post_type_object->has_archive )
778                         $title = post_type_archive_title( '', false );
779         }
780
781         // If there's a category or tag
782         if ( is_category() || is_tag() ) {
783                 $title = single_term_title( '', false );
784         }
785
786         // If there's a taxonomy
787         if ( is_tax() ) {
788                 $term = get_queried_object();
789                 if ( $term ) {
790                         $tax = get_taxonomy( $term->taxonomy );
791                         $title = single_term_title( $tax->labels->name . $t_sep, false );
792                 }
793         }
794
795         // If there's an author
796         if ( is_author() ) {
797                 $author = get_queried_object();
798                 if ( $author )
799                         $title = $author->display_name;
800         }
801
802         // Post type archives with has_archive should override terms.
803         if ( is_post_type_archive() && $post_type_object->has_archive )
804                 $title = post_type_archive_title( '', false );
805
806         // If there's a month
807         if ( is_archive() && !empty($m) ) {
808                 $my_year = substr($m, 0, 4);
809                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
810                 $my_day = intval(substr($m, 6, 2));
811                 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
812         }
813
814         // If there's a year
815         if ( is_archive() && !empty($year) ) {
816                 $title = $year;
817                 if ( !empty($monthnum) )
818                         $title .= $t_sep . $wp_locale->get_month($monthnum);
819                 if ( !empty($day) )
820                         $title .= $t_sep . zeroise($day, 2);
821         }
822
823         // If it's a search
824         if ( is_search() ) {
825                 /* translators: 1: separator, 2: search phrase */
826                 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
827         }
828
829         // If it's a 404 page
830         if ( is_404() ) {
831                 $title = __('Page not found');
832         }
833
834         $prefix = '';
835         if ( !empty($title) )
836                 $prefix = " $sep ";
837
838         // Determines position of the separator and direction of the breadcrumb
839         if ( 'right' == $seplocation ) { // sep on right, so reverse the order
840                 $title_array = explode( $t_sep, $title );
841                 $title_array = array_reverse( $title_array );
842                 $title = implode( " $sep ", $title_array ) . $prefix;
843         } else {
844                 $title_array = explode( $t_sep, $title );
845                 $title = $prefix . implode( " $sep ", $title_array );
846         }
847
848         /**
849          * Filter the text of the page title.
850          *
851          * @since 2.0.0
852          *
853          * @param string $title       Page title.
854          * @param string $sep         Title separator.
855          * @param string $seplocation Location of the separator (left or right).
856          */
857         $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
858
859         // Send it out
860         if ( $display )
861                 echo $title;
862         else
863                 return $title;
864
865 }
866
867 /**
868  * Display or retrieve page title for post.
869  *
870  * This is optimized for single.php template file for displaying the post title.
871  *
872  * It does not support placing the separator after the title, but by leaving the
873  * prefix parameter empty, you can set the title separator manually. The prefix
874  * does not automatically place a space between the prefix, so if there should
875  * be a space, the parameter value will need to have it at the end.
876  *
877  * @since 0.71
878  *
879  * @param string $prefix Optional. What to display before the title.
880  * @param bool $display Optional, default is true. Whether to display or retrieve title.
881  * @return string|null Title when retrieving, null when displaying or failure.
882  */
883 function single_post_title($prefix = '', $display = true) {
884         $_post = get_queried_object();
885
886         if ( !isset($_post->post_title) )
887                 return;
888
889         /**
890          * Filter the page title for a single post.
891          *
892          * @since 0.71
893          *
894          * @param string $_post_title The single post page title.
895          * @param object $_post       The current queried object as returned by get_queried_object().
896          */
897         $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
898         if ( $display )
899                 echo $prefix . $title;
900         else
901                 return $prefix . $title;
902 }
903
904 /**
905  * Display or retrieve title for a post type archive.
906  *
907  * This is optimized for archive.php and archive-{$post_type}.php template files
908  * for displaying the title of the post type.
909  *
910  * @since 3.1.0
911  *
912  * @param string $prefix Optional. What to display before the title.
913  * @param bool $display Optional, default is true. Whether to display or retrieve title.
914  * @return string|null Title when retrieving, null when displaying or failure.
915  */
916 function post_type_archive_title( $prefix = '', $display = true ) {
917         if ( ! is_post_type_archive() )
918                 return;
919
920         $post_type = get_query_var( 'post_type' );
921         if ( is_array( $post_type ) )
922                 $post_type = reset( $post_type );
923
924         $post_type_obj = get_post_type_object( $post_type );
925
926         /**
927          * Filter the post type archive title.
928          *
929          * @since 3.1.0
930          *
931          * @param string $post_type_name Post type 'name' label.
932          * @param string $post_type      Post type.
933          */
934         $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
935
936         if ( $display )
937                 echo $prefix . $title;
938         else
939                 return $prefix . $title;
940 }
941
942 /**
943  * Display or retrieve page title for category archive.
944  *
945  * This is useful for category template file or files, because it is optimized
946  * for category page title and with less overhead than {@link wp_title()}.
947  *
948  * It does not support placing the separator after the title, but by leaving the
949  * prefix parameter empty, you can set the title separator manually. The prefix
950  * does not automatically place a space between the prefix, so if there should
951  * be a space, the parameter value will need to have it at the end.
952  *
953  * @since 0.71
954  *
955  * @param string $prefix Optional. What to display before the title.
956  * @param bool $display Optional, default is true. Whether to display or retrieve title.
957  * @return string|null Title when retrieving, null when displaying or failure.
958  */
959 function single_cat_title( $prefix = '', $display = true ) {
960         return single_term_title( $prefix, $display );
961 }
962
963 /**
964  * Display or retrieve page title for tag post archive.
965  *
966  * Useful for tag template files for displaying the tag page title. It has less
967  * overhead than {@link wp_title()}, because of its limited implementation.
968  *
969  * It does not support placing the separator after the title, but by leaving the
970  * prefix parameter empty, you can set the title separator manually. The prefix
971  * does not automatically place a space between the prefix, so if there should
972  * be a space, the parameter value will need to have it at the end.
973  *
974  * @since 2.3.0
975  *
976  * @param string $prefix Optional. What to display before the title.
977  * @param bool $display Optional, default is true. Whether to display or retrieve title.
978  * @return string|null Title when retrieving, null when displaying or failure.
979  */
980 function single_tag_title( $prefix = '', $display = true ) {
981         return single_term_title( $prefix, $display );
982 }
983
984 /**
985  * Display or retrieve page title for taxonomy term archive.
986  *
987  * Useful for taxonomy term template files for displaying the taxonomy term page title.
988  * It has less overhead than {@link wp_title()}, because of its limited implementation.
989  *
990  * It does not support placing the separator after the title, but by leaving the
991  * prefix parameter empty, you can set the title separator manually. The prefix
992  * does not automatically place a space between the prefix, so if there should
993  * be a space, the parameter value will need to have it at the end.
994  *
995  * @since 3.1.0
996  *
997  * @param string $prefix Optional. What to display before the title.
998  * @param bool $display Optional, default is true. Whether to display or retrieve title.
999  * @return string|null Title when retrieving, null when displaying or failure.
1000  */
1001 function single_term_title( $prefix = '', $display = true ) {
1002         $term = get_queried_object();
1003
1004         if ( !$term )
1005                 return;
1006
1007         if ( is_category() ) {
1008                 /**
1009                  * Filter the category archive page title.
1010                  *
1011                  * @since 2.0.10
1012                  *
1013                  * @param string $term_name Category name for archive being displayed.
1014                  */
1015                 $term_name = apply_filters( 'single_cat_title', $term->name );
1016         } elseif ( is_tag() ) {
1017                 /**
1018                  * Filter the tag archive page title.
1019                  *
1020                  * @since 2.3.0
1021                  *
1022                  * @param string $term_name Tag name for archive being displayed.
1023                  */
1024                 $term_name = apply_filters( 'single_tag_title', $term->name );
1025         } elseif ( is_tax() ) {
1026                 /**
1027                  * Filter the custom taxonomy archive page title.
1028                  *
1029                  * @since 3.1.0
1030                  *
1031                  * @param string $term_name Term name for archive being displayed.
1032                  */
1033                 $term_name = apply_filters( 'single_term_title', $term->name );
1034         } else {
1035                 return;
1036         }
1037
1038         if ( empty( $term_name ) )
1039                 return;
1040
1041         if ( $display )
1042                 echo $prefix . $term_name;
1043         else
1044                 return $prefix . $term_name;
1045 }
1046
1047 /**
1048  * Display or retrieve page title for post archive based on date.
1049  *
1050  * Useful for when the template only needs to display the month and year, if
1051  * either are available. Optimized for just this purpose, so if it is all that
1052  * is needed, should be better than {@link wp_title()}.
1053  *
1054  * It does not support placing the separator after the title, but by leaving the
1055  * prefix parameter empty, you can set the title separator manually. The prefix
1056  * does not automatically place a space between the prefix, so if there should
1057  * be a space, the parameter value will need to have it at the end.
1058  *
1059  * @since 0.71
1060  *
1061  * @param string $prefix Optional. What to display before the title.
1062  * @param bool $display Optional, default is true. Whether to display or retrieve title.
1063  * @return string|null Title when retrieving, null when displaying or failure.
1064  */
1065 function single_month_title($prefix = '', $display = true ) {
1066         global $wp_locale;
1067
1068         $m = get_query_var('m');
1069         $year = get_query_var('year');
1070         $monthnum = get_query_var('monthnum');
1071
1072         if ( !empty($monthnum) && !empty($year) ) {
1073                 $my_year = $year;
1074                 $my_month = $wp_locale->get_month($monthnum);
1075         } elseif ( !empty($m) ) {
1076                 $my_year = substr($m, 0, 4);
1077                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
1078         }
1079
1080         if ( empty($my_month) )
1081                 return false;
1082
1083         $result = $prefix . $my_month . $prefix . $my_year;
1084
1085         if ( !$display )
1086                 return $result;
1087         echo $result;
1088 }
1089
1090 /**
1091  * Retrieve archive link content based on predefined or custom code.
1092  *
1093  * The format can be one of four styles. The 'link' for head element, 'option'
1094  * for use in the select element, 'html' for use in list (either ol or ul HTML
1095  * elements). Custom content is also supported using the before and after
1096  * parameters.
1097  *
1098  * The 'link' format uses the link HTML element with the <em>archives</em>
1099  * relationship. The before and after parameters are not used. The text
1100  * parameter is used to describe the link.
1101  *
1102  * The 'option' format uses the option HTML element for use in select element.
1103  * The value is the url parameter and the before and after parameters are used
1104  * between the text description.
1105  *
1106  * The 'html' format, which is the default, uses the li HTML element for use in
1107  * the list HTML elements. The before parameter is before the link and the after
1108  * parameter is after the closing link.
1109  *
1110  * The custom format uses the before parameter before the link ('a' HTML
1111  * element) and the after parameter after the closing link tag. If the above
1112  * three values for the format are not used, then custom format is assumed.
1113  *
1114  * @since 1.0.0
1115  *
1116  * @param string $url URL to archive.
1117  * @param string $text Archive text description.
1118  * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1119  * @param string $before Optional.
1120  * @param string $after Optional.
1121  * @return string HTML link content for archive.
1122  */
1123 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
1124         $text = wptexturize($text);
1125         $url = esc_url($url);
1126
1127         if ('link' == $format)
1128                 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
1129         elseif ('option' == $format)
1130                 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
1131         elseif ('html' == $format)
1132                 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
1133         else // custom
1134                 $link_html = "\t$before<a href='$url'>$text</a>$after\n";
1135
1136         /**
1137          * Filter the archive link content.
1138          *
1139          * @since 2.6.0
1140          *
1141          * @param string $link_html The archive HTML link content.
1142          */
1143         $link_html = apply_filters( 'get_archives_link', $link_html );
1144
1145         return $link_html;
1146 }
1147
1148 /**
1149  * Display archive links based on type and format.
1150  *
1151  * The 'type' argument offers a few choices and by default will display monthly
1152  * archive links. The other options for values are 'daily', 'weekly', 'monthly',
1153  * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
1154  * same archive link list, the difference between the two is that 'alpha'
1155  * will order by post title and 'postbypost' will order by post date.
1156  *
1157  * The date archives will logically display dates with links to the archive post
1158  * page. The 'postbypost' and 'alpha' values for 'type' argument will display
1159  * the post titles.
1160  *
1161  * The 'limit' argument will only display a limited amount of links, specified
1162  * by the 'limit' integer value. By default, there is no limit. The
1163  * 'show_post_count' argument will show how many posts are within the archive.
1164  * By default, the 'show_post_count' argument is set to false.
1165  *
1166  * For the 'format', 'before', and 'after' arguments, see {@link
1167  * get_archives_link()}. The values of these arguments have to do with that
1168  * function.
1169  *
1170  * @since 1.2.0
1171  *
1172  * @param string|array $args Optional. Override defaults.
1173  * @return string|null String when retrieving, null when displaying.
1174  */
1175 function wp_get_archives($args = '') {
1176         global $wpdb, $wp_locale;
1177
1178         $defaults = array(
1179                 'type' => 'monthly', 'limit' => '',
1180                 'format' => 'html', 'before' => '',
1181                 'after' => '', 'show_post_count' => false,
1182                 'echo' => 1, 'order' => 'DESC',
1183         );
1184
1185         $r = wp_parse_args( $args, $defaults );
1186         extract( $r, EXTR_SKIP );
1187
1188         if ( '' == $type )
1189                 $type = 'monthly';
1190
1191         if ( '' != $limit ) {
1192                 $limit = absint($limit);
1193                 $limit = ' LIMIT '.$limit;
1194         }
1195
1196         $order = strtoupper( $order );
1197         if ( $order !== 'ASC' )
1198                 $order = 'DESC';
1199
1200         // this is what will separate dates on weekly archive links
1201         $archive_week_separator = '&#8211;';
1202
1203         // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
1204         $archive_date_format_over_ride = 0;
1205
1206         // options for daily archive (only if you over-ride the general date format)
1207         $archive_day_date_format = 'Y/m/d';
1208
1209         // options for weekly archive (only if you over-ride the general date format)
1210         $archive_week_start_date_format = 'Y/m/d';
1211         $archive_week_end_date_format   = 'Y/m/d';
1212
1213         if ( !$archive_date_format_over_ride ) {
1214                 $archive_day_date_format = get_option('date_format');
1215                 $archive_week_start_date_format = get_option('date_format');
1216                 $archive_week_end_date_format = get_option('date_format');
1217         }
1218
1219         /**
1220          * Filter the SQL WHERE clause for retrieving archives.
1221          *
1222          * @since 2.2.0
1223          *
1224          * @param string $sql_where Portion of SQL query containing the WHERE clause.
1225          * @param array  $r         An array of default arguments.
1226          */
1227         $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
1228
1229         /**
1230          * Filter the SQL JOIN clause for retrieving archives.
1231          *
1232          * @since 2.2.0
1233          *
1234          * @param string $sql_join Portion of SQL query containing JOIN clause.
1235          * @param array  $r        An array of default arguments.
1236          */
1237         $join = apply_filters( 'getarchives_join', '', $r );
1238
1239         $output = '';
1240
1241         $last_changed = wp_cache_get( 'last_changed', 'posts' );
1242         if ( ! $last_changed ) {
1243                 $last_changed = microtime();
1244                 wp_cache_set( 'last_changed', $last_changed, 'posts' );
1245         }
1246
1247         if ( 'monthly' == $type ) {
1248                 $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 $order $limit";
1249                 $key = md5( $query );
1250                 $key = "wp_get_archives:$key:$last_changed";
1251                 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1252                         $results = $wpdb->get_results( $query );
1253                         wp_cache_set( $key, $results, 'posts' );
1254                 }
1255                 if ( $results ) {
1256                         $afterafter = $after;
1257                         foreach ( (array) $results as $result ) {
1258                                 $url = get_month_link( $result->year, $result->month );
1259                                 /* translators: 1: month name, 2: 4-digit year */
1260                                 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
1261                                 if ( $show_post_count )
1262                                         $after = '&nbsp;('.$result->posts.')' . $afterafter;
1263                                 $output .= get_archives_link($url, $text, $format, $before, $after);
1264                         }
1265                 }
1266         } elseif ('yearly' == $type) {
1267                 $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 $order $limit";
1268                 $key = md5( $query );
1269                 $key = "wp_get_archives:$key:$last_changed";
1270                 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1271                         $results = $wpdb->get_results( $query );
1272                         wp_cache_set( $key, $results, 'posts' );
1273                 }
1274                 if ( $results ) {
1275                         $afterafter = $after;
1276                         foreach ( (array) $results as $result) {
1277                                 $url = get_year_link($result->year);
1278                                 $text = sprintf('%d', $result->year);
1279                                 if ($show_post_count)
1280                                         $after = '&nbsp;('.$result->posts.')' . $afterafter;
1281                                 $output .= get_archives_link($url, $text, $format, $before, $after);
1282                         }
1283                 }
1284         } elseif ( 'daily' == $type ) {
1285                 $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 $order $limit";
1286                 $key = md5( $query );
1287                 $key = "wp_get_archives:$key:$last_changed";
1288                 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1289                         $results = $wpdb->get_results( $query );
1290                         $cache[ $key ] = $results;
1291                         wp_cache_set( $key, $results, 'posts' );
1292                 }
1293                 if ( $results ) {
1294                         $afterafter = $after;
1295                         foreach ( (array) $results as $result ) {
1296                                 $url    = get_day_link($result->year, $result->month, $result->dayofmonth);
1297                                 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
1298                                 $text = mysql2date($archive_day_date_format, $date);
1299                                 if ($show_post_count)
1300                                         $after = '&nbsp;('.$result->posts.')'.$afterafter;
1301                                 $output .= get_archives_link($url, $text, $format, $before, $after);
1302                         }
1303                 }
1304         } elseif ( 'weekly' == $type ) {
1305                 $week = _wp_mysql_week( '`post_date`' );
1306                 $query = "SELECT DISTINCT $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, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
1307                 $key = md5( $query );
1308                 $key = "wp_get_archives:$key:$last_changed";
1309                 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1310                         $results = $wpdb->get_results( $query );
1311                         wp_cache_set( $key, $results, 'posts' );
1312                 }
1313                 $arc_w_last = '';
1314                 $afterafter = $after;
1315                 if ( $results ) {
1316                                 foreach ( (array) $results as $result ) {
1317                                         if ( $result->week != $arc_w_last ) {
1318                                                 $arc_year = $result->yr;
1319                                                 $arc_w_last = $result->week;
1320                                                 $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
1321                                                 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
1322                                                 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
1323                                                 $url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week);
1324                                                 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
1325                                                 if ($show_post_count)
1326                                                         $after = '&nbsp;('.$result->posts.')'.$afterafter;
1327                                                 $output .= get_archives_link($url, $text, $format, $before, $after);
1328                                         }
1329                                 }
1330                 }
1331         } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
1332                 $orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';
1333                 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1334                 $key = md5( $query );
1335                 $key = "wp_get_archives:$key:$last_changed";
1336                 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1337                         $results = $wpdb->get_results( $query );
1338                         wp_cache_set( $key, $results, 'posts' );
1339                 }
1340                 if ( $results ) {
1341                         foreach ( (array) $results as $result ) {
1342                                 if ( $result->post_date != '0000-00-00 00:00:00' ) {
1343                                         $url  = get_permalink( $result );
1344                                         if ( $result->post_title ) {
1345                                                 /** This filter is documented in wp-includes/post-template.php */
1346                                                 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1347                                         } else {
1348                                                 $text = $result->ID;
1349                                         }
1350                                         $output .= get_archives_link($url, $text, $format, $before, $after);
1351                                 }
1352                         }
1353                 }
1354         }
1355         if ( $echo )
1356                 echo $output;
1357         else
1358                 return $output;
1359 }
1360
1361 /**
1362  * Get number of days since the start of the week.
1363  *
1364  * @since 1.5.0
1365  *
1366  * @param int $num Number of day.
1367  * @return int Days since the start of the week.
1368  */
1369 function calendar_week_mod($num) {
1370         $base = 7;
1371         return ($num - $base*floor($num/$base));
1372 }
1373
1374 /**
1375  * Display calendar with days that have posts as links.
1376  *
1377  * The calendar is cached, which will be retrieved, if it exists. If there are
1378  * no posts for the month, then it will not be displayed.
1379  *
1380  * @since 1.0.0
1381  * @uses calendar_week_mod()
1382  *
1383  * @param bool $initial Optional, default is true. Use initial calendar names.
1384  * @param bool $echo Optional, default is true. Set to false for return.
1385  * @return string|null String when retrieving, null when displaying.
1386  */
1387 function get_calendar($initial = true, $echo = true) {
1388         global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1389
1390         $cache = array();
1391         $key = md5( $m . $monthnum . $year );
1392         if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
1393                 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
1394                         if ( $echo ) {
1395                                 /** This filter is documented in wp-includes/general-template.php */
1396                                 echo apply_filters( 'get_calendar', $cache[$key] );
1397                                 return;
1398                         } else {
1399                                 /** This filter is documented in wp-includes/general-template.php */
1400                                 return apply_filters( 'get_calendar', $cache[$key] );
1401                         }
1402                 }
1403         }
1404
1405         if ( !is_array($cache) )
1406                 $cache = array();
1407
1408         // Quick check. If we have no posts at all, abort!
1409         if ( !$posts ) {
1410                 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1411                 if ( !$gotsome ) {
1412                         $cache[ $key ] = '';
1413                         wp_cache_set( 'get_calendar', $cache, 'calendar' );
1414                         return;
1415                 }
1416         }
1417
1418         if ( isset($_GET['w']) )
1419                 $w = ''.intval($_GET['w']);
1420
1421         // week_begins = 0 stands for Sunday
1422         $week_begins = intval(get_option('start_of_week'));
1423
1424         // Let's figure out when we are
1425         if ( !empty($monthnum) && !empty($year) ) {
1426                 $thismonth = ''.zeroise(intval($monthnum), 2);
1427                 $thisyear = ''.intval($year);
1428         } elseif ( !empty($w) ) {
1429                 // We need to get the month from MySQL
1430                 $thisyear = ''.intval(substr($m, 0, 4));
1431                 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
1432                 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1433         } elseif ( !empty($m) ) {
1434                 $thisyear = ''.intval(substr($m, 0, 4));
1435                 if ( strlen($m) < 6 )
1436                                 $thismonth = '01';
1437                 else
1438                                 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1439         } else {
1440                 $thisyear = gmdate('Y', current_time('timestamp'));
1441                 $thismonth = gmdate('m', current_time('timestamp'));
1442         }
1443
1444         $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1445         $last_day = date('t', $unixmonth);
1446
1447         // Get the next and previous month and year with at least one post
1448         $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1449                 FROM $wpdb->posts
1450                 WHERE post_date < '$thisyear-$thismonth-01'
1451                 AND post_type = 'post' AND post_status = 'publish'
1452                         ORDER BY post_date DESC
1453                         LIMIT 1");
1454         $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1455                 FROM $wpdb->posts
1456                 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1457                 AND post_type = 'post' AND post_status = 'publish'
1458                         ORDER BY post_date ASC
1459                         LIMIT 1");
1460
1461         /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1462         $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1463         $calendar_output = '<table id="wp-calendar">
1464         <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1465         <thead>
1466         <tr>';
1467
1468         $myweek = array();
1469
1470         for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1471                 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1472         }
1473
1474         foreach ( $myweek as $wd ) {
1475                 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1476                 $wd = esc_attr($wd);
1477                 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1478         }
1479
1480         $calendar_output .= '
1481         </tr>
1482         </thead>
1483
1484         <tfoot>
1485         <tr>';
1486
1487         if ( $previous ) {
1488                 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), 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>';
1489         } else {
1490                 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
1491         }
1492
1493         $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
1494
1495         if ( $next ) {
1496                 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), 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>';
1497         } else {
1498                 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
1499         }
1500
1501         $calendar_output .= '
1502         </tr>
1503         </tfoot>
1504
1505         <tbody>
1506         <tr>';
1507
1508         // Get days with posts
1509         $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1510                 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1511                 AND post_type = 'post' AND post_status = 'publish'
1512                 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1513         if ( $dayswithposts ) {
1514                 foreach ( (array) $dayswithposts as $daywith ) {
1515                         $daywithpost[] = $daywith[0];
1516                 }
1517         } else {
1518                 $daywithpost = array();
1519         }
1520
1521         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
1522                 $ak_title_separator = "\n";
1523         else
1524                 $ak_title_separator = ', ';
1525
1526         $ak_titles_for_day = array();
1527         $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
1528                 ."FROM $wpdb->posts "
1529                 ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
1530                 ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
1531                 ."AND post_type = 'post' AND post_status = 'publish'"
1532         );
1533         if ( $ak_post_titles ) {
1534                 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1535
1536                                 /** This filter is documented in wp-includes/post-template.php */
1537                                 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
1538
1539                                 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1540                                         $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1541                                 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1542                                         $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1543                                 else
1544                                         $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1545                 }
1546         }
1547
1548         // See how much we should pad in the beginning
1549         $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1550         if ( 0 != $pad )
1551                 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
1552
1553         $daysinmonth = intval(date('t', $unixmonth));
1554         for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1555                 if ( isset($newrow) && $newrow )
1556                         $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1557                 $newrow = false;
1558
1559                 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
1560                         $calendar_output .= '<td id="today">';
1561                 else
1562                         $calendar_output .= '<td>';
1563
1564                 if ( in_array($day, $daywithpost) ) // any posts today?
1565                                 $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
1566                 else
1567                         $calendar_output .= $day;
1568                 $calendar_output .= '</td>';
1569
1570                 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1571                         $newrow = true;
1572         }
1573
1574         $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1575         if ( $pad != 0 && $pad != 7 )
1576                 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
1577
1578         $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1579
1580         $cache[ $key ] = $calendar_output;
1581         wp_cache_set( 'get_calendar', $cache, 'calendar' );
1582
1583         if ( $echo ) {
1584                 /**
1585                  * Filter the HTML calendar output.
1586                  *
1587                  * @since 3.0.0
1588                  *
1589                  * @param string $calendar_output HTML output of the calendar.
1590                  */
1591                 echo apply_filters( 'get_calendar', $calendar_output );
1592         } else {
1593                 /** This filter is documented in wp-includes/general-template.php */
1594                 return apply_filters( 'get_calendar', $calendar_output );
1595         }
1596
1597 }
1598
1599 /**
1600  * Purge the cached results of get_calendar.
1601  *
1602  * @see get_calendar
1603  * @since 2.1.0
1604  */
1605 function delete_get_calendar_cache() {
1606         wp_cache_delete( 'get_calendar', 'calendar' );
1607 }
1608 add_action( 'save_post', 'delete_get_calendar_cache' );
1609 add_action( 'delete_post', 'delete_get_calendar_cache' );
1610 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1611 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1612
1613 /**
1614  * Display all of the allowed tags in HTML format with attributes.
1615  *
1616  * This is useful for displaying in the comment area, which elements and
1617  * attributes are supported. As well as any plugins which want to display it.
1618  *
1619  * @since 1.0.1
1620  * @uses $allowedtags
1621  *
1622  * @return string HTML allowed tags entity encoded.
1623  */
1624 function allowed_tags() {
1625         global $allowedtags;
1626         $allowed = '';
1627         foreach ( (array) $allowedtags as $tag => $attributes ) {
1628                 $allowed .= '<'.$tag;
1629                 if ( 0 < count($attributes) ) {
1630                         foreach ( $attributes as $attribute => $limits ) {
1631                                 $allowed .= ' '.$attribute.'=""';
1632                         }
1633                 }
1634                 $allowed .= '> ';
1635         }
1636         return htmlentities($allowed);
1637 }
1638
1639 /***** Date/Time tags *****/
1640
1641 /**
1642  * Outputs the date in iso8601 format for xml files.
1643  *
1644  * @since 1.0.0
1645  */
1646 function the_date_xml() {
1647         echo mysql2date( 'Y-m-d', get_post()->post_date, false );
1648 }
1649
1650 /**
1651  * Display or Retrieve the date the current post was written (once per date)
1652  *
1653  * Will only output the date if the current post's date is different from the
1654  * previous one output.
1655  *
1656  * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
1657  * function is called several times for each post.
1658  *
1659  * HTML output can be filtered with 'the_date'.
1660  * Date string output can be filtered with 'get_the_date'.
1661  *
1662  * @since 0.71
1663  *
1664  * @uses get_the_date()
1665  * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1666  * @param string $before Optional. Output before the date.
1667  * @param string $after Optional. Output after the date.
1668  * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1669  * @return string|null Null if displaying, string if retrieving.
1670  */
1671 function the_date( $d = '', $before = '', $after = '', $echo = true ) {
1672         global $currentday, $previousday;
1673
1674         if ( $currentday != $previousday ) {
1675                 $the_date = $before . get_the_date( $d ) . $after;
1676                 $previousday = $currentday;
1677
1678                 /**
1679                  * Filter the date a post was published for display.
1680                  *
1681                  * @since 0.71
1682                  *
1683                  * @param string $the_date The formatted date string.
1684                  * @param string $d        PHP date format. Defaults to 'date_format' option
1685                  *                         if not specified.
1686                  * @param string $before   HTML output before the date.
1687                  * @param string $after    HTML output after the date.
1688                  */
1689                 $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
1690
1691                 if ( $echo )
1692                         echo $the_date;
1693                 else
1694                         return $the_date;
1695         }
1696
1697         return null;
1698 }
1699
1700 /**
1701  * Retrieve the date on which the post was written.
1702  *
1703  * Unlike the_date() this function will always return the date.
1704  * Modify output with 'get_the_date' filter.
1705  *
1706  * @since 3.0.0
1707  *
1708  * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
1709  * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
1710  * @return string Date the current post was written.
1711  */
1712 function get_the_date( $d = '', $post = null ) {
1713         $post = get_post( $post );
1714
1715         if ( '' == $d ) {
1716                 $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
1717         } else {
1718                 $the_date = mysql2date( $d, $post->post_date );
1719         }
1720
1721         /**
1722          * Filter the date a post was published.
1723          *
1724          * @since 3.0.0
1725          *
1726          * @param string      $the_date The formatted date.
1727          * @param string      $d        PHP date format. Defaults to 'date_format' option
1728          *                              if not specified.
1729          * @param int|WP_Post $post     The post object or ID.
1730          */
1731         return apply_filters( 'get_the_date', $the_date, $d, $post );
1732 }
1733
1734 /**
1735  * Display the date on which the post was last modified.
1736  *
1737  * @since 2.1.0
1738  *
1739  * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1740  * @param string $before Optional. Output before the date.
1741  * @param string $after Optional. Output after the date.
1742  * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1743  * @return string|null Null if displaying, string if retrieving.
1744  */
1745 function the_modified_date($d = '', $before='', $after='', $echo = true) {
1746
1747         $the_modified_date = $before . get_the_modified_date($d) . $after;
1748
1749         /**
1750          * Filter the date a post was last modified for display.
1751          *
1752          * @since 2.1.0
1753          *
1754          * @param string $the_modified_date The last modified date.
1755          * @param string $d                 PHP date format. Defaults to 'date_format' option
1756          *                                  if not specified.
1757          * @param string $before            HTML output before the date.
1758          * @param string $after             HTML output after the date.
1759          */
1760         $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
1761
1762         if ( $echo )
1763                 echo $the_modified_date;
1764         else
1765                 return $the_modified_date;
1766
1767 }
1768
1769 /**
1770  * Retrieve the date on which the post was last modified.
1771  *
1772  * @since 2.1.0
1773  *
1774  * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1775  * @return string
1776  */
1777 function get_the_modified_date($d = '') {
1778         if ( '' == $d )
1779                 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1780         else
1781                 $the_time = get_post_modified_time($d, null, null, true);
1782
1783         /**
1784          * Filter the date a post was last modified.
1785          *
1786          * @since 2.1.0
1787          *
1788          * @param string $the_time The formatted date.
1789          * @param string $d        PHP date format. Defaults to value specified in
1790          *                         'date_format' option.
1791          */
1792         return apply_filters( 'get_the_modified_date', $the_time, $d );
1793 }
1794
1795 /**
1796  * Display the time at which the post was written.
1797  *
1798  * @since 0.71
1799  *
1800  * @param string $d Either 'G', 'U', or php date format.
1801  */
1802 function the_time( $d = '' ) {
1803         /**
1804          * Filter the time a post was written for display.
1805          *
1806          * @since 0.71
1807          *
1808          * @param string $get_the_time The formatted time.
1809          * @param string $d            The time format. Accepts 'G', 'U',
1810          *                             or php date format.
1811          */
1812         echo apply_filters( 'the_time', get_the_time( $d ), $d );
1813 }
1814
1815 /**
1816  * Retrieve the time at which the post was written.
1817  *
1818  * @since 1.5.0
1819  *
1820  * @param string      $d    Optional. Format to use for retrieving the time the post
1821  *                          was written. Either 'G', 'U', or php date format defaults
1822  *                          to the value specified in the time_format option. Default empty.
1823  * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
1824  * @return string|int Formatted date string, or Unix timestamp.
1825  */
1826 function get_the_time( $d = '', $post = null ) {
1827         $post = get_post($post);
1828
1829         if ( '' == $d )
1830                 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1831         else
1832                 $the_time = get_post_time($d, false, $post, true);
1833
1834         /**
1835          * Filter the time a post was written.
1836          *
1837          * @since 1.5.0
1838          *
1839          * @param string      $the_time The formatted time.
1840          * @param string      $d        Format to use for retrieving the time the post was written.
1841          *                              Accepts 'G', 'U', or php date format value specified
1842          *                              in 'time_format' option. Default empty.
1843          * @param int|WP_Post $post     WP_Post object or ID.
1844          */
1845         return apply_filters( 'get_the_time', $the_time, $d, $post );
1846 }
1847
1848 /**
1849  * Retrieve the time at which the post was written.
1850  *
1851  * @since 2.0.0
1852  *
1853  * @param string      $d         Optional. Format to use for retrieving the time the post
1854  *                               was written. Either 'G', 'U', or php date format. Default 'U'.
1855  * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
1856  * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
1857  * @param bool        $translate Whether to translate the time string. Default false.
1858  * @return string|int Formatted date string, or Unix timestamp.
1859  */
1860 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1861         $post = get_post($post);
1862
1863         if ( $gmt )
1864                 $time = $post->post_date_gmt;
1865         else
1866                 $time = $post->post_date;
1867
1868         $time = mysql2date($d, $time, $translate);
1869
1870         /**
1871          * Filter the localized time a post was written.
1872          *
1873          * @since 2.6.0
1874          *
1875          * @param string $time The formatted time.
1876          * @param string $d    Format to use for retrieving the time the post was written.
1877          *                     Accepts 'G', 'U', or php date format. Default 'U'.
1878          * @param bool   $gmt  Whether to retrieve the GMT time. Default false.
1879          */
1880         return apply_filters( 'get_post_time', $time, $d, $gmt );
1881 }
1882
1883 /**
1884  * Display the time at which the post was last modified.
1885  *
1886  * @since 2.0.0
1887  *
1888  * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1889  */
1890 function the_modified_time($d = '') {
1891         /**
1892          * Filter the localized time a post was last modified, for display.
1893          *
1894          * @since 2.0.0
1895          *
1896          * @param string $get_the_modified_time The formatted time.
1897          * @param string $d                     The time format. Accepts 'G', 'U',
1898          *                                      or php date format. Defaults to value
1899          *                                      specified in 'time_format' option.
1900          */
1901         echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
1902 }
1903
1904 /**
1905  * Retrieve the time at which the post was last modified.
1906  *
1907  * @since 2.0.0
1908  *
1909  * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1910  * @return string
1911  */
1912 function get_the_modified_time($d = '') {
1913         if ( '' == $d )
1914                 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1915         else
1916                 $the_time = get_post_modified_time($d, null, null, true);
1917
1918         /**
1919          * Filter the localized time a post was last modified.
1920          *
1921          * @since 2.0.0
1922          *
1923          * @param string $the_time The formatted time.
1924          * @param string $d        Format to use for retrieving the time the post was
1925          *                         written. Accepts 'G', 'U', or php date format. Defaults
1926          *                         to value specified in 'time_format' option.
1927          */
1928         return apply_filters( 'get_the_modified_time', $the_time, $d );
1929 }
1930
1931 /**
1932  * Retrieve the time at which the post was last modified.
1933  *
1934  * @since 2.0.0
1935  *
1936  * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
1937  * @param bool $gmt Optional, default is false. Whether to return the gmt time.
1938  * @param int|object $post Optional, default is global post object. A post_id or post object
1939  * @param bool $translate Optional, default is false. Whether to translate the result
1940  * @return string Returns timestamp
1941  */
1942 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1943         $post = get_post($post);
1944
1945         if ( $gmt )
1946                 $time = $post->post_modified_gmt;
1947         else
1948                 $time = $post->post_modified;
1949         $time = mysql2date($d, $time, $translate);
1950
1951         /**
1952          * Filter the localized time a post was last modified.
1953          *
1954          * @since 2.8.0
1955          *
1956          * @param string $time The formatted time.
1957          * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
1958          * @param bool   $gmt  Whether to return the GMT time. Default false.
1959          */
1960         return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
1961 }
1962
1963 /**
1964  * Display the weekday on which the post was written.
1965  *
1966  * @since 0.71
1967  * @uses $wp_locale
1968  * @uses $post
1969  */
1970 function the_weekday() {
1971         global $wp_locale;
1972         $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
1973
1974         /**
1975          * Filter the weekday on which the post was written, for display.
1976          *
1977          * @since 0.71
1978          *
1979          * @param string $the_weekday 
1980          */
1981         $the_weekday = apply_filters( 'the_weekday', $the_weekday );
1982         echo $the_weekday;
1983 }
1984
1985 /**
1986  * Display the weekday on which the post was written.
1987  *
1988  * Will only output the weekday if the current post's weekday is different from
1989  * the previous one output.
1990  *
1991  * @since 0.71
1992  *
1993  * @param string $before Optional Output before the date.
1994  * @param string $after Optional Output after the date.
1995  */
1996 function the_weekday_date($before='',$after='') {
1997         global $wp_locale, $currentday, $previousweekday;
1998         $the_weekday_date = '';
1999         if ( $currentday != $previousweekday ) {
2000                 $the_weekday_date .= $before;
2001                 $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2002                 $the_weekday_date .= $after;
2003                 $previousweekday = $currentday;
2004         }
2005
2006         /**
2007          * Filter the localized date on which the post was written, for display.
2008          *
2009          * @since 0.71
2010          *
2011          * @param string $the_weekday_date 
2012          * @param string $before           The HTML to output before the date.
2013          * @param string $after            The HTML to output after the date.
2014          */
2015         $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
2016         echo $the_weekday_date;
2017 }
2018
2019 /**
2020  * Fire the wp_head action
2021  *
2022  * @since 1.2.0
2023  */
2024 function wp_head() {
2025         /**
2026          * Print scripts or data in the head tag on the front end.
2027          *
2028          * @since 1.5.0
2029          */
2030         do_action( 'wp_head' );
2031 }
2032
2033 /**
2034  * Fire the wp_footer action
2035  *
2036  * @since 1.5.1
2037  */
2038 function wp_footer() {
2039         /**
2040          * Print scripts or data before the closing body tag on the front end.
2041          *
2042          * @since 1.5.1
2043          */
2044         do_action( 'wp_footer' );
2045 }
2046
2047 /**
2048  * Display the links to the general feeds.
2049  *
2050  * @since 2.8.0
2051  *
2052  * @param array $args Optional arguments.
2053  */
2054 function feed_links( $args = array() ) {
2055         if ( !current_theme_supports('automatic-feed-links') )
2056                 return;
2057
2058         $defaults = array(
2059                 /* translators: Separator between blog name and feed type in feed links */
2060                 'separator'     => _x('&raquo;', 'feed link'),
2061                 /* translators: 1: blog title, 2: separator (raquo) */
2062                 'feedtitle'     => __('%1$s %2$s Feed'),
2063                 /* translators: 1: blog title, 2: separator (raquo) */
2064                 'comstitle'     => __('%1$s %2$s Comments Feed'),
2065         );
2066
2067         $args = wp_parse_args( $args, $defaults );
2068
2069         echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
2070         echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
2071 }
2072
2073 /**
2074  * Display the links to the extra feeds such as category feeds.
2075  *
2076  * @since 2.8.0
2077  *
2078  * @param array $args Optional arguments.
2079  */
2080 function feed_links_extra( $args = array() ) {
2081         $defaults = array(
2082                 /* translators: Separator between blog name and feed type in feed links */
2083                 'separator'   => _x('&raquo;', 'feed link'),
2084                 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
2085                 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
2086                 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
2087                 'cattitle'    => __('%1$s %2$s %3$s Category Feed'),
2088                 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
2089                 'tagtitle'    => __('%1$s %2$s %3$s Tag Feed'),
2090                 /* translators: 1: blog name, 2: separator(raquo), 3: author name  */
2091                 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
2092                 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
2093                 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
2094                 /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
2095                 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
2096         );
2097
2098         $args = wp_parse_args( $args, $defaults );
2099
2100         if ( is_singular() ) {
2101                 $id = 0;
2102                 $post = get_post( $id );
2103
2104                 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
2105                         $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
2106                         $href = get_post_comments_feed_link( $post->ID );
2107                 }
2108         } elseif ( is_post_type_archive() ) {
2109                 $post_type = get_query_var( 'post_type' );
2110                 if ( is_array( $post_type ) )
2111                         $post_type = reset( $post_type );
2112
2113                 $post_type_obj = get_post_type_object( $post_type );
2114                 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
2115                 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2116         } elseif ( is_category() ) {
2117                 $term = get_queried_object();
2118
2119                 if ( $term ) {
2120                         $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
2121                         $href = get_category_feed_link( $term->term_id );
2122                 }
2123         } elseif ( is_tag() ) {
2124                 $term = get_queried_object();
2125
2126                 if ( $term ) {
2127                         $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
2128                         $href = get_tag_feed_link( $term->term_id );
2129                 }
2130         } elseif ( is_author() ) {
2131                 $author_id = intval( get_query_var('author') );
2132
2133                 $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
2134                 $href = get_author_feed_link( $author_id );
2135         } elseif ( is_search() ) {
2136                 $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
2137                 $href = get_search_feed_link();
2138         } elseif ( is_post_type_archive() ) {
2139                 $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
2140                 $post_type_obj = get_queried_object();
2141                 if ( $post_type_obj )
2142                         $href = get_post_type_archive_feed_link( $post_type_obj->name );
2143         }
2144
2145         if ( isset($title) && isset($href) )
2146                 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
2147 }
2148
2149 /**
2150  * Display the link to the Really Simple Discovery service endpoint.
2151  *
2152  * @link http://archipelago.phrasewise.com/rsd
2153  * @since 2.0.0
2154  */
2155 function rsd_link() {
2156         echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
2157 }
2158
2159 /**
2160  * Display the link to the Windows Live Writer manifest file.
2161  *
2162  * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
2163  * @since 2.3.1
2164  */
2165 function wlwmanifest_link() {
2166         echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
2167                 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
2168 }
2169
2170 /**
2171  * Display a noindex meta tag if required by the blog configuration.
2172  *
2173  * If a blog is marked as not being public then the noindex meta tag will be
2174  * output to tell web robots not to index the page content. Add this to the wp_head action.
2175  * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
2176  *
2177  * @see wp_no_robots
2178  *
2179  * @since 2.1.0
2180  */
2181 function noindex() {
2182         // If the blog is not public, tell robots to go away.
2183         if ( '0' == get_option('blog_public') )
2184                 wp_no_robots();
2185 }
2186
2187 /**
2188  * Display a noindex meta tag.
2189  *
2190  * Outputs a noindex meta tag that tells web robots not to index the page content.
2191  * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
2192  *
2193  * @since 3.3.0
2194  */
2195 function wp_no_robots() {
2196         echo "<meta name='robots' content='noindex,follow' />\n";
2197 }
2198
2199 /**
2200  * Whether the user should have a WYSIWIG editor.
2201  *
2202  * Checks that the user requires a WYSIWIG editor and that the editor is
2203  * supported in the users browser.
2204  *
2205  * @since 2.0.0
2206  *
2207  * @return bool
2208  */
2209 function user_can_richedit() {
2210         global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
2211
2212         if ( !isset($wp_rich_edit) ) {
2213                 $wp_rich_edit = false;
2214
2215                 if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
2216                         if ( $is_safari ) {
2217                                 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
2218                         } elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
2219                                 $wp_rich_edit = true;
2220                         }
2221                 }
2222         }
2223
2224         /**
2225          * Filter whether the user can access the rich (Visual) editor.
2226          *
2227          * @since 2.1.0
2228          *
2229          * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
2230          */
2231         return apply_filters( 'user_can_richedit', $wp_rich_edit );
2232 }
2233
2234 /**
2235  * Find out which editor should be displayed by default.
2236  *
2237  * Works out which of the two editors to display as the current editor for a
2238  * user. The 'html' setting is for the "Text" editor tab.
2239  *
2240  * @since 2.5.0
2241  *
2242  * @return string Either 'tinymce', or 'html', or 'test'
2243  */
2244 function wp_default_editor() {
2245         $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
2246         if ( $user = wp_get_current_user() ) { // look for cookie
2247                 $ed = get_user_setting('editor', 'tinymce');
2248                 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
2249         }
2250
2251         /**
2252          * Filter which editor should be displayed by default.
2253          *
2254          * @since 2.5.0
2255          *
2256          * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
2257          */
2258         return apply_filters( 'wp_default_editor', $r );
2259 }
2260
2261 /**
2262  * Renders an editor.
2263  *
2264  * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2265  * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
2266  *
2267  * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2268  * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
2269  * On the post edit screen several actions can be used to include additional editors
2270  * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2271  * See http://core.trac.wordpress.org/ticket/19173 for more information.
2272  *
2273  * @see wp-includes/class-wp-editor.php
2274  * @since 3.3.0
2275  *
2276  * @param string $content Initial content for the editor.
2277  * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
2278  * @param array $settings See _WP_Editors::editor().
2279  */
2280 function wp_editor( $content, $editor_id, $settings = array() ) {
2281         if ( ! class_exists( '_WP_Editors' ) )
2282                 require( ABSPATH . WPINC . '/class-wp-editor.php' );
2283
2284         _WP_Editors::editor($content, $editor_id, $settings);
2285 }
2286
2287 /**
2288  * Retrieve the contents of the search WordPress query variable.
2289  *
2290  * The search query string is passed through {@link esc_attr()}
2291  * to ensure that it is safe for placing in an html attribute.
2292  *
2293  * @since 2.3.0
2294  * @uses esc_attr()
2295  *
2296  * @param bool $escaped Whether the result is escaped. Default true.
2297  *      Only use when you are later escaping it. Do not use unescaped.
2298  * @return string
2299  */
2300 function get_search_query( $escaped = true ) {
2301         /**
2302          * Filter the contents of the search query variable.
2303          *
2304          * @since 2.3.0
2305          *
2306          * @param mixed $search Contents of the search query variable.
2307          */
2308         $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
2309
2310         if ( $escaped )
2311                 $query = esc_attr( $query );
2312         return $query;
2313 }
2314
2315 /**
2316  * Display the contents of the search query variable.
2317  *
2318  * The search query string is passed through {@link esc_attr()}
2319  * to ensure that it is safe for placing in an html attribute.
2320  *
2321  * @uses esc_attr()
2322  * @since 2.1.0
2323  */
2324 function the_search_query() {
2325         /**
2326          * Filter the contents of the search query variable for display.
2327          *
2328          * @since 2.3.0
2329          *
2330          * @param mixed $search Contents of the search query variable.
2331          */
2332         echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
2333 }
2334
2335 /**
2336  * Display the language attributes for the html tag.
2337  *
2338  * Builds up a set of html attributes containing the text direction and language
2339  * information for the page.
2340  *
2341  * @since 2.1.0
2342  *
2343  * @param string $doctype The type of html document (xhtml|html).
2344  */
2345 function language_attributes($doctype = 'html') {
2346         $attributes = array();
2347         $output = '';
2348
2349         if ( function_exists( 'is_rtl' ) && is_rtl() )
2350                 $attributes[] = 'dir="rtl"';
2351
2352         if ( $lang = get_bloginfo('language') ) {
2353                 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
2354                         $attributes[] = "lang=\"$lang\"";
2355
2356                 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
2357                         $attributes[] = "xml:lang=\"$lang\"";
2358         }
2359
2360         $output = implode(' ', $attributes);
2361
2362         /**
2363          * Filter the language attributes for display in the html tag.
2364          *
2365          * @since 2.5.0
2366          *
2367          * @param string $output A space-separated list of language attributes.
2368          */
2369         echo apply_filters( 'language_attributes', $output );
2370 }
2371
2372 /**
2373  * Retrieve paginated link for archive post pages.
2374  *
2375  * Technically, the function can be used to create paginated link list for any
2376  * area. The 'base' argument is used to reference the url, which will be used to
2377  * create the paginated links. The 'format' argument is then used for replacing
2378  * the page number. It is however, most likely and by default, to be used on the
2379  * archive post pages.
2380  *
2381  * The 'type' argument controls format of the returned value. The default is
2382  * 'plain', which is just a string with the links separated by a newline
2383  * character. The other possible values are either 'array' or 'list'. The
2384  * 'array' value will return an array of the paginated link list to offer full
2385  * control of display. The 'list' value will place all of the paginated links in
2386  * an unordered HTML list.
2387  *
2388  * The 'total' argument is the total amount of pages and is an integer. The
2389  * 'current' argument is the current page number and is also an integer.
2390  *
2391  * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
2392  * and the '%_%' is required. The '%_%' will be replaced by the contents of in
2393  * the 'format' argument. An example for the 'format' argument is "?page=%#%"
2394  * and the '%#%' is also required. The '%#%' will be replaced with the page
2395  * number.
2396  *
2397  * You can include the previous and next links in the list by setting the
2398  * 'prev_next' argument to true, which it is by default. You can set the
2399  * previous text, by using the 'prev_text' argument. You can set the next text
2400  * by setting the 'next_text' argument.
2401  *
2402  * If the 'show_all' argument is set to true, then it will show all of the pages
2403  * instead of a short list of the pages near the current page. By default, the
2404  * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
2405  * arguments. The 'end_size' argument is how many numbers on either the start
2406  * and the end list edges, by default is 1. The 'mid_size' argument is how many
2407  * numbers to either side of current page, but not including current page.
2408  *
2409  * It is possible to add query vars to the link by using the 'add_args' argument
2410  * and see {@link add_query_arg()} for more information.
2411  *
2412  * The 'before_page_number' and 'after_page_number' arguments allow users to 
2413  * augment the links themselves. Typically this might be to add context to the
2414  * numbered links so that screen reader users understand what the links are for.
2415  * The text strings are added before and after the page number - within the 
2416  * anchor tag.
2417  *
2418  * @since 2.1.0
2419  *
2420  * @param string|array $args Optional. Override defaults.
2421  * @return array|string String of page links or array of page links.
2422  */
2423 function paginate_links( $args = '' ) {
2424         $defaults = array(
2425                 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
2426                 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
2427                 'total' => 1,
2428                 'current' => 0,
2429                 'show_all' => false,
2430                 'prev_next' => true,
2431                 'prev_text' => __('&laquo; Previous'),
2432                 'next_text' => __('Next &raquo;'),
2433                 'end_size' => 1,
2434                 'mid_size' => 2,
2435                 'type' => 'plain',
2436                 'add_args' => false, // array of query args to add
2437                 'add_fragment' => '',
2438                 'before_page_number' => '',
2439                 'after_page_number' => ''
2440         );
2441
2442         $args = wp_parse_args( $args, $defaults );
2443         extract($args, EXTR_SKIP);
2444
2445         // Who knows what else people pass in $args
2446         $total = (int) $total;
2447         if ( $total < 2 )
2448                 return;
2449         $current  = (int) $current;
2450         $end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.
2451         $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
2452         $add_args = is_array($add_args) ? $add_args : false;
2453         $r = '';
2454         $page_links = array();
2455         $n = 0;
2456         $dots = false;
2457
2458         if ( $prev_next && $current && 1 < $current ) :
2459                 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
2460                 $link = str_replace('%#%', $current - 1, $link);
2461                 if ( $add_args )
2462                         $link = add_query_arg( $add_args, $link );
2463                 $link .= $add_fragment;
2464
2465                 /**
2466                  * Filter the paginated links for the given archive pages.
2467                  *
2468                  * @since 3.0.0
2469                  *
2470                  * @param string $link The paginated link URL.
2471                  */
2472                 $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
2473         endif;
2474         for ( $n = 1; $n <= $total; $n++ ) :
2475                 if ( $n == $current ) :
2476                         $page_links[] = "<span class='page-numbers current'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</span>";
2477                         $dots = true;
2478                 else :
2479                         if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
2480                                 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
2481                                 $link = str_replace('%#%', $n, $link);
2482                                 if ( $add_args )
2483                                         $link = add_query_arg( $add_args, $link );
2484                                 $link .= $add_fragment;
2485
2486                                 /** This filter is documented in wp-includes/general-template.php */
2487                                 $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</a>";
2488                                 $dots = true;
2489                         elseif ( $dots && !$show_all ) :
2490                                 $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
2491                                 $dots = false;
2492                         endif;
2493                 endif;
2494         endfor;
2495         if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
2496                 $link = str_replace('%_%', $format, $base);
2497                 $link = str_replace('%#%', $current + 1, $link);
2498                 if ( $add_args )
2499                         $link = add_query_arg( $add_args, $link );
2500                 $link .= $add_fragment;
2501
2502                 /** This filter is documented in wp-includes/general-template.php */
2503                 $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
2504         endif;
2505         switch ( $type ) :
2506                 case 'array' :
2507                         return $page_links;
2508                         break;
2509                 case 'list' :
2510                         $r .= "<ul class='page-numbers'>\n\t<li>";
2511                         $r .= join("</li>\n\t<li>", $page_links);
2512                         $r .= "</li>\n</ul>\n";
2513                         break;
2514                 default :
2515                         $r = join("\n", $page_links);
2516                         break;
2517         endswitch;
2518         return $r;
2519 }
2520
2521 /**
2522  * Registers an admin colour scheme css file.
2523  *
2524  * Allows a plugin to register a new admin colour scheme. For example:
2525  * <code>
2526  * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
2527  * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
2528  * </code>
2529  *
2530  * @since 2.5.0
2531  *
2532  * @param string $key The unique key for this theme.
2533  * @param string $name The name of the theme.
2534  * @param string $url The url of the css file containing the colour scheme.
2535  * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
2536  * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
2537  */
2538 function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
2539         global $_wp_admin_css_colors;
2540
2541         if ( !isset($_wp_admin_css_colors) )
2542                 $_wp_admin_css_colors = array();
2543
2544         $_wp_admin_css_colors[$key] = (object) array(
2545                 'name' => $name,
2546                 'url' => $url,
2547                 'colors' => $colors,
2548                 'icon_colors' => $icons,
2549         );
2550 }
2551
2552 /**
2553  * Registers the default Admin color schemes
2554  *
2555  * @since 3.0.0
2556  */
2557 function register_admin_color_schemes() {
2558         $suffix = is_rtl() ? '-rtl' : '';
2559         $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
2560
2561         wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
2562                 false,
2563                 array( '#222', '#333', '#0074a2', '#2ea2cc' ),
2564                 array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )
2565         );
2566
2567         // Other color schemes are not available when running out of src
2568         if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
2569                 return;
2570
2571         wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
2572                 admin_url( "css/colors/light/colors$suffix.css" ),
2573                 array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
2574                 array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
2575         );
2576
2577         wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
2578                 admin_url( "css/colors/blue/colors$suffix.css" ),
2579                 array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
2580                 array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
2581         );
2582
2583         wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
2584                 admin_url( "css/colors/midnight/colors$suffix.css" ),
2585                 array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
2586                 array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
2587         );
2588
2589         wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
2590                 admin_url( "css/colors/sunrise/colors$suffix.css" ),
2591                 array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
2592                 array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
2593         );
2594
2595         wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
2596                 admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
2597                 array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
2598                 array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
2599         );
2600
2601         wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
2602                 admin_url( "css/colors/ocean/colors$suffix.css" ),
2603                 array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
2604                 array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
2605         );
2606
2607         wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
2608                 admin_url( "css/colors/coffee/colors$suffix.css" ),
2609                 array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
2610                 array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
2611         );
2612
2613 }
2614
2615 /**
2616  * Display the URL of a WordPress admin CSS file.
2617  *
2618  * @see WP_Styles::_css_href and its style_loader_src filter.
2619  *
2620  * @since 2.3.0
2621  *
2622  * @param string $file file relative to wp-admin/ without its ".css" extension.
2623  */
2624 function wp_admin_css_uri( $file = 'wp-admin' ) {
2625         if ( defined('WP_INSTALLING') ) {
2626                 $_file = "./$file.css";
2627         } else {
2628                 $_file = admin_url("$file.css");
2629         }
2630         $_file = add_query_arg( 'version', get_bloginfo( 'version' ),  $_file );
2631
2632         /**
2633          * Filter the URI of a WordPress admin CSS file.
2634          *
2635          * @since 2.3.0
2636          *
2637          * @param string $_file Relative path to the file with query arguments attached.
2638          * @param string $file  Relative path to the file, minus its ".css" extension.
2639          */
2640         return apply_filters( 'wp_admin_css_uri', $_file, $file );
2641 }
2642
2643 /**
2644  * Enqueues or directly prints a stylesheet link to the specified CSS file.
2645  *
2646  * "Intelligently" decides to enqueue or to print the CSS file. If the
2647  * 'wp_print_styles' action has *not* yet been called, the CSS file will be
2648  * enqueued. If the wp_print_styles action *has* been called, the CSS link will
2649  * be printed. Printing may be forced by passing true as the $force_echo
2650  * (second) parameter.
2651  *
2652  * For backward compatibility with WordPress 2.3 calling method: If the $file
2653  * (first) parameter does not correspond to a registered CSS file, we assume
2654  * $file is a file relative to wp-admin/ without its ".css" extension. A
2655  * stylesheet link to that generated URL is printed.
2656  *
2657  * @since 2.3.0
2658  * @uses $wp_styles WordPress Styles Object
2659  *
2660  * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
2661  *       to wp-admin/. Defaults to 'wp-admin'.
2662  * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
2663  */
2664 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
2665         global $wp_styles;
2666         if ( !is_a($wp_styles, 'WP_Styles') )
2667                 $wp_styles = new WP_Styles();
2668
2669         // For backward compatibility
2670         $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
2671
2672         if ( $wp_styles->query( $handle ) ) {
2673                 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
2674                         wp_print_styles( $handle );
2675                 else // Add to style queue
2676                         wp_enqueue_style( $handle );
2677                 return;
2678         }
2679
2680         /**
2681          * Filter the stylesheet link to the specified CSS file.
2682          *
2683          * If the site is set to display right-to-left, the RTL stylesheet link
2684          * will be used instead.
2685          *
2686          * @since 2.3.0
2687          *
2688          * @param string $file Style handle name or filename (without ".css" extension)
2689          *                     relative to wp-admin/. Defaults to 'wp-admin'.
2690          */
2691         echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
2692
2693         if ( function_exists( 'is_rtl' ) && is_rtl() ) {
2694                 /** This filter is documented in wp-includes/general-template.php */
2695                 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
2696         }
2697 }
2698
2699 /**
2700  * Enqueues the default ThickBox js and css.
2701  *
2702  * If any of the settings need to be changed, this can be done with another js
2703  * file similar to media-upload.js. That file should
2704  * require array('thickbox') to ensure it is loaded after.
2705  *
2706  * @since 2.5.0
2707  */
2708 function add_thickbox() {
2709         wp_enqueue_script( 'thickbox' );
2710         wp_enqueue_style( 'thickbox' );
2711
2712         if ( is_network_admin() )
2713                 add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
2714 }
2715
2716 /**
2717  * Display the XHTML generator that is generated on the wp_head hook.
2718  *
2719  * @since 2.5.0
2720  */
2721 function wp_generator() {
2722         /**
2723          * Filter the output of the XHTML generator tag.
2724          *
2725          * @since 2.5.0
2726          *
2727          * @param string $generator_type The XHTML generator.
2728          */
2729         the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
2730 }
2731
2732 /**
2733  * Display the generator XML or Comment for RSS, ATOM, etc.
2734  *
2735  * Returns the correct generator type for the requested output format. Allows
2736  * for a plugin to filter generators overall the the_generator filter.
2737  *
2738  * @since 2.5.0
2739  *
2740  * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2741  */
2742 function the_generator( $type ) {
2743         /**
2744          * Filter the output of the XHTML generator tag for display.
2745          *
2746          * @since 2.5.0
2747          *
2748          * @param string $generator_type The generator output.
2749          * @param string $type           The type of generator to output. Accepts 'html',
2750          *                               'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
2751          */
2752         echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
2753 }
2754
2755 /**
2756  * Creates the generator XML or Comment for RSS, ATOM, etc.
2757  *
2758  * Returns the correct generator type for the requested output format. Allows
2759  * for a plugin to filter generators on an individual basis using the
2760  * 'get_the_generator_{$type}' filter.
2761  *
2762  * @since 2.5.0
2763  *
2764  * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2765  * @return string The HTML content for the generator.
2766  */
2767 function get_the_generator( $type = '' ) {
2768         if ( empty( $type ) ) {
2769
2770                 $current_filter = current_filter();
2771                 if ( empty( $current_filter ) )
2772                         return;
2773
2774                 switch ( $current_filter ) {
2775                         case 'rss2_head' :
2776                         case 'commentsrss2_head' :
2777                                 $type = 'rss2';
2778                                 break;
2779                         case 'rss_head' :
2780                         case 'opml_head' :
2781                                 $type = 'comment';
2782                                 break;
2783                         case 'rdf_header' :
2784                                 $type = 'rdf';
2785                                 break;
2786                         case 'atom_head' :
2787                         case 'comments_atom_head' :
2788                         case 'app_head' :
2789                                 $type = 'atom';
2790                                 break;
2791                 }
2792         }
2793
2794         switch ( $type ) {
2795                 case 'html':
2796                         $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2797                         break;
2798                 case 'xhtml':
2799                         $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2800                         break;
2801                 case 'atom':
2802                         $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2803                         break;
2804                 case 'rss2':
2805                         $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2806                         break;
2807                 case 'rdf':
2808                         $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2809                         break;
2810                 case 'comment':
2811                         $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2812                         break;
2813                 case 'export':
2814                         $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
2815                         break;
2816         }
2817
2818         /**
2819          * Filter the HTML for the retrieved generator type.
2820          *
2821          * The dynamic portion of the hook name, $type, refers to the generator type.
2822          *
2823          * @since 2.5.0
2824          *
2825          * @param string $gen  The HTML markup output to 'wp_head()'.
2826          * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
2827          *                     'rss2', 'rdf', 'comment', 'export'.
2828          */
2829         return apply_filters( "get_the_generator_{$type}", $gen, $type );
2830 }
2831
2832 /**
2833  * Outputs the html checked attribute.
2834  *
2835  * Compares the first two arguments and if identical marks as checked
2836  *
2837  * @since 1.0.0
2838  *
2839  * @param mixed $checked One of the values to compare
2840  * @param mixed $current (true) The other value to compare if not just true
2841  * @param bool $echo Whether to echo or just return the string
2842  * @return string html attribute or empty string
2843  */
2844 function checked( $checked, $current = true, $echo = true ) {
2845         return __checked_selected_helper( $checked, $current, $echo, 'checked' );
2846 }
2847
2848 /**
2849  * Outputs the html selected attribute.
2850  *
2851  * Compares the first two arguments and if identical marks as selected
2852  *
2853  * @since 1.0.0
2854  *
2855  * @param mixed $selected One of the values to compare
2856  * @param mixed $current (true) The other value to compare if not just true
2857  * @param bool $echo Whether to echo or just return the string
2858  * @return string html attribute or empty string
2859  */
2860 function selected( $selected, $current = true, $echo = true ) {
2861         return __checked_selected_helper( $selected, $current, $echo, 'selected' );
2862 }
2863
2864 /**
2865  * Outputs the html disabled attribute.
2866  *
2867  * Compares the first two arguments and if identical marks as disabled
2868  *
2869  * @since 3.0.0
2870  *
2871  * @param mixed $disabled One of the values to compare
2872  * @param mixed $current (true) The other value to compare if not just true
2873  * @param bool $echo Whether to echo or just return the string
2874  * @return string html attribute or empty string
2875  */
2876 function disabled( $disabled, $current = true, $echo = true ) {
2877         return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
2878 }
2879
2880 /**
2881  * Private helper function for checked, selected, and disabled.
2882  *
2883  * Compares the first two arguments and if identical marks as $type
2884  *
2885  * @since 2.8.0
2886  * @access private
2887  *
2888  * @param mixed $helper One of the values to compare
2889  * @param mixed $current (true) The other value to compare if not just true
2890  * @param bool $echo Whether to echo or just return the string
2891  * @param string $type The type of checked|selected|disabled we are doing
2892  * @return string html attribute or empty string
2893  */
2894 function __checked_selected_helper( $helper, $current, $echo, $type ) {
2895         if ( (string) $helper === (string) $current )
2896                 $result = " $type='$type'";
2897         else
2898                 $result = '';
2899
2900         if ( $echo )
2901                 echo $result;
2902
2903         return $result;
2904 }
2905
2906 /**
2907  * Default settings for heartbeat
2908  *
2909  * Outputs the nonce used in the heartbeat XHR
2910  *
2911  * @since 3.6.0
2912  *
2913  * @param array $settings
2914  * @return array $settings
2915  */
2916 function wp_heartbeat_settings( $settings ) {
2917         if ( ! is_admin() )
2918                 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
2919
2920         if ( is_user_logged_in() )
2921                 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
2922
2923         return $settings;
2924 }