PageRenderTime 62ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 2982 lines | 1661 code | 216 blank | 1105 comment | 243 complexity | 9504d637c151893fdd5bd263ade7f493 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * General template tags that can go anywhere in a template.
  4. *
  5. * @package WordPress
  6. * @subpackage Template
  7. */
  8. /**
  9. * Load header template.
  10. *
  11. * Includes the header template for a theme or if a name is specified then a
  12. * specialised header will be included.
  13. *
  14. * For the parameter, if the file is called "header-special.php" then specify
  15. * "special".
  16. *
  17. * @since 1.5.0
  18. *
  19. * @uses locate_template()
  20. *
  21. * @param string $name The name of the specialised header.
  22. */
  23. function get_header( $name = null ) {
  24. /**
  25. * Fires before the header template file is loaded.
  26. *
  27. * The hook allows a specific header template file to be used in place of the
  28. * default header template file. If your file is called header-new.php,
  29. * you would specify the filename in the hook as get_header( 'new' ).
  30. *
  31. * @since 2.1.0
  32. * @since 2.8.0 $name parameter added.
  33. *
  34. * @param string $name Name of the specific header file to use.
  35. */
  36. do_action( 'get_header', $name );
  37. $templates = array();
  38. $name = (string) $name;
  39. if ( '' !== $name )
  40. $templates[] = "header-{$name}.php";
  41. $templates[] = 'header.php';
  42. // Backward compat code will be removed in a future release
  43. if ('' == locate_template($templates, true))
  44. load_template( ABSPATH . WPINC . '/theme-compat/header.php');
  45. }
  46. /**
  47. * Load footer template.
  48. *
  49. * Includes the footer template for a theme or if a name is specified then a
  50. * specialised footer will be included.
  51. *
  52. * For the parameter, if the file is called "footer-special.php" then specify
  53. * "special".
  54. *
  55. * @since 1.5.0
  56. *
  57. * @uses locate_template()
  58. *
  59. * @param string $name The name of the specialised footer.
  60. */
  61. function get_footer( $name = null ) {
  62. /**
  63. * Fires before the footer template file is loaded.
  64. *
  65. * The hook allows a specific footer template file to be used in place of the
  66. * default footer template file. If your file is called footer-new.php,
  67. * you would specify the filename in the hook as get_footer( 'new' ).
  68. *
  69. * @since 2.1.0
  70. * @since 2.8.0 $name parameter added.
  71. *
  72. * @param string $name Name of the specific footer file to use.
  73. */
  74. do_action( 'get_footer', $name );
  75. $templates = array();
  76. $name = (string) $name;
  77. if ( '' !== $name )
  78. $templates[] = "footer-{$name}.php";
  79. $templates[] = 'footer.php';
  80. // Backward compat code will be removed in a future release
  81. if ('' == locate_template($templates, true))
  82. load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
  83. }
  84. /**
  85. * Load sidebar template.
  86. *
  87. * Includes the sidebar template for a theme or if a name is specified then a
  88. * specialised sidebar will be included.
  89. *
  90. * For the parameter, if the file is called "sidebar-special.php" then specify
  91. * "special".
  92. *
  93. * @since 1.5.0
  94. *
  95. * @uses locate_template()
  96. *
  97. * @param string $name The name of the specialised sidebar.
  98. */
  99. function get_sidebar( $name = null ) {
  100. /**
  101. * Fires before the sidebar template file is loaded.
  102. *
  103. * The hook allows a specific sidebar template file to be used in place of the
  104. * default sidebar template file. If your file is called sidebar-new.php,
  105. * you would specify the filename in the hook as get_sidebar( 'new' ).
  106. *
  107. * @since 2.2.0
  108. * @since 2.8.0 $name parameter added.
  109. *
  110. * @param string $name Name of the specific sidebar file to use.
  111. */
  112. do_action( 'get_sidebar', $name );
  113. $templates = array();
  114. $name = (string) $name;
  115. if ( '' !== $name )
  116. $templates[] = "sidebar-{$name}.php";
  117. $templates[] = 'sidebar.php';
  118. // Backward compat code will be removed in a future release
  119. if ('' == locate_template($templates, true))
  120. load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
  121. }
  122. /**
  123. * Load a template part into a template
  124. *
  125. * Makes it easy for a theme to reuse sections of code in a easy to overload way
  126. * for child themes.
  127. *
  128. * Includes the named template part for a theme or if a name is specified then a
  129. * specialised part will be included. If the theme contains no {slug}.php file
  130. * then no template will be included.
  131. *
  132. * The template is included using require, not require_once, so you may include the
  133. * same template part multiple times.
  134. *
  135. * For the $name parameter, if the file is called "{slug}-special.php" then specify
  136. * "special".
  137. *
  138. * @since 3.0.0
  139. *
  140. * @uses locate_template()
  141. *
  142. * @param string $slug The slug name for the generic template.
  143. * @param string $name The name of the specialised template.
  144. */
  145. function get_template_part( $slug, $name = null ) {
  146. /**
  147. * Fires before the specified template part file is loaded.
  148. *
  149. * The dynamic portion of the hook name, $slug, refers to the slug name
  150. * for the generic template part.
  151. *
  152. * @since 3.0.0
  153. *
  154. * @param string $slug The slug name for the generic template.
  155. * @param string $name The name of the specialized template.
  156. */
  157. do_action( "get_template_part_{$slug}", $slug, $name );
  158. $templates = array();
  159. $name = (string) $name;
  160. if ( '' !== $name )
  161. $templates[] = "{$slug}-{$name}.php";
  162. $templates[] = "{$slug}.php";
  163. locate_template($templates, true, false);
  164. }
  165. /**
  166. * Display search form.
  167. *
  168. * Will first attempt to locate the searchform.php file in either the child or
  169. * the parent, then load it. If it doesn't exist, then the default search form
  170. * will be displayed. The default search form is HTML, which will be displayed.
  171. * There is a filter applied to the search form HTML in order to edit or replace
  172. * it. The filter is 'get_search_form'.
  173. *
  174. * This function is primarily used by themes which want to hardcode the search
  175. * form into the sidebar and also by the search widget in WordPress.
  176. *
  177. * There is also an action that is called whenever the function is run called,
  178. * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
  179. * search relies on or various formatting that applies to the beginning of the
  180. * search. To give a few examples of what it can be used for.
  181. *
  182. * @since 2.7.0
  183. *
  184. * @param boolean $echo Default to echo and not return the form.
  185. * @return string|null String when retrieving, null when displaying or if searchform.php exists.
  186. */
  187. function get_search_form( $echo = true ) {
  188. /**
  189. * Fires before the search form is retrieved, at the start of get_search_form().
  190. *
  191. * @since 2.7.0 as 'get_search_form' action.
  192. * @since 3.6.0
  193. *
  194. * @link https://core.trac.wordpress.org/ticket/19321
  195. */
  196. do_action( 'pre_get_search_form' );
  197. $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
  198. /**
  199. * Filter the HTML format of the search form.
  200. *
  201. * @since 3.6.0
  202. *
  203. * @param string $format The type of markup to use in the search form.
  204. * Accepts 'html5', 'xhtml'.
  205. */
  206. $format = apply_filters( 'search_form_format', $format );
  207. $search_form_template = locate_template( 'searchform.php' );
  208. if ( '' != $search_form_template ) {
  209. ob_start();
  210. require( $search_form_template );
  211. $form = ob_get_clean();
  212. } else {
  213. if ( 'html5' == $format ) {
  214. $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
  215. <label>
  216. <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
  217. <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' ) . '" />
  218. </label>
  219. <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  220. </form>';
  221. } else {
  222. $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
  223. <div>
  224. <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
  225. <input type="text" value="' . get_search_query() . '" name="s" id="s" />
  226. <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  227. </div>
  228. </form>';
  229. }
  230. }
  231. /**
  232. * Filter the HTML output of the search form.
  233. *
  234. * @since 2.7.0
  235. *
  236. * @param string $form The search form HTML output.
  237. */
  238. $result = apply_filters( 'get_search_form', $form );
  239. if ( null === $result )
  240. $result = $form;
  241. if ( $echo )
  242. echo $result;
  243. else
  244. return $result;
  245. }
  246. /**
  247. * Display the Log In/Out link.
  248. *
  249. * Displays a link, which allows users to navigate to the Log In page to log in
  250. * or log out depending on whether they are currently logged in.
  251. *
  252. * @since 1.5.0
  253. *
  254. * @param string $redirect Optional path to redirect to on login/logout.
  255. * @param boolean $echo Default to echo and not return the link.
  256. * @return string|null String when retrieving, null when displaying.
  257. */
  258. function wp_loginout($redirect = '', $echo = true) {
  259. if ( ! is_user_logged_in() )
  260. $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
  261. else
  262. $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
  263. if ( $echo ) {
  264. /**
  265. * Filter the HTML output for the Log In/Log Out link.
  266. *
  267. * @since 1.5.0
  268. *
  269. * @param string $link The HTML link content.
  270. */
  271. echo apply_filters( 'loginout', $link );
  272. } else {
  273. /** This filter is documented in wp-includes/general-template.php */
  274. return apply_filters( 'loginout', $link );
  275. }
  276. }
  277. /**
  278. * Returns the Log Out URL.
  279. *
  280. * Returns the URL that allows the user to log out of the site.
  281. *
  282. * @since 2.7.0
  283. *
  284. * @uses wp_nonce_url() To protect against CSRF.
  285. * @uses site_url() To generate the log out URL.
  286. *
  287. * @param string $redirect Path to redirect to on logout.
  288. * @return string A log out URL.
  289. */
  290. function wp_logout_url($redirect = '') {
  291. $args = array( 'action' => 'logout' );
  292. if ( !empty($redirect) ) {
  293. $args['redirect_to'] = urlencode( $redirect );
  294. }
  295. $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
  296. $logout_url = wp_nonce_url( $logout_url, 'log-out' );
  297. /**
  298. * Filter the logout URL.
  299. *
  300. * @since 2.8.0
  301. *
  302. * @param string $logout_url The Log Out URL.
  303. * @param string $redirect Path to redirect to on logout.
  304. */
  305. return apply_filters( 'logout_url', $logout_url, $redirect );
  306. }
  307. /**
  308. * Returns the Log In URL.
  309. *
  310. * Returns the URL that allows the user to log in to the site.
  311. *
  312. * @since 2.7.0
  313. *
  314. * @uses site_url() To generate the log in URL.
  315. *
  316. * @param string $redirect Path to redirect to on login.
  317. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
  318. * @return string A log in URL.
  319. */
  320. function wp_login_url($redirect = '', $force_reauth = false) {
  321. $login_url = site_url('wp-login.php', 'login');
  322. if ( !empty($redirect) )
  323. $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
  324. if ( $force_reauth )
  325. $login_url = add_query_arg('reauth', '1', $login_url);
  326. /**
  327. * Filter the login URL.
  328. *
  329. * @since 2.8.0
  330. *
  331. * @param string $login_url The login URL.
  332. * @param string $redirect The path to redirect to on login, if supplied.
  333. */
  334. return apply_filters( 'login_url', $login_url, $redirect );
  335. }
  336. /**
  337. * Returns the user registration URL.
  338. *
  339. * Returns the URL that allows the user to register on the site.
  340. *
  341. * @since 3.6.0
  342. *
  343. * @uses site_url() To generate the registration URL.
  344. *
  345. * @return string User registration URL.
  346. */
  347. function wp_registration_url() {
  348. /**
  349. * Filter the user registration URL.
  350. *
  351. * @since 3.6.0
  352. *
  353. * @param string $register The user registration URL.
  354. */
  355. return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
  356. }
  357. /**
  358. * Provides a simple login form for use anywhere within WordPress. By default, it echoes
  359. * the HTML immediately. Pass array('echo'=>false) to return the string instead.
  360. *
  361. * @since 3.0.0
  362. *
  363. * @param array $args Configuration options to modify the form output.
  364. * @return string|null String when retrieving, null when displaying.
  365. */
  366. function wp_login_form( $args = array() ) {
  367. $defaults = array(
  368. 'echo' => true,
  369. 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
  370. 'form_id' => 'loginform',
  371. 'label_username' => __( 'Username' ),
  372. 'label_password' => __( 'Password' ),
  373. 'label_remember' => __( 'Remember Me' ),
  374. 'label_log_in' => __( 'Log In' ),
  375. 'id_username' => 'user_login',
  376. 'id_password' => 'user_pass',
  377. 'id_remember' => 'rememberme',
  378. 'id_submit' => 'wp-submit',
  379. 'remember' => true,
  380. 'value_username' => '',
  381. 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
  382. );
  383. /**
  384. * Filter the default login form output arguments.
  385. *
  386. * @since 3.0.0
  387. *
  388. * @see wp_login_form()
  389. *
  390. * @param array $defaults An array of default login form arguments.
  391. */
  392. $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
  393. /**
  394. * Filter content to display at the top of the login form.
  395. *
  396. * The filter evaluates just following the opening form tag element.
  397. *
  398. * @since 3.0.0
  399. *
  400. * @param string $content Content to display. Default empty.
  401. * @param array $args Array of login form arguments.
  402. */
  403. $login_form_top = apply_filters( 'login_form_top', '', $args );
  404. /**
  405. * Filter content to display in the middle of the login form.
  406. *
  407. * The filter evaluates just following the location where the 'login-password'
  408. * field is displayed.
  409. *
  410. * @since 3.0.0
  411. *
  412. * @param string $content Content to display. Default empty.
  413. * @param array $args Array of login form arguments.
  414. */
  415. $login_form_middle = apply_filters( 'login_form_middle', '', $args );
  416. /**
  417. * Filter content to display at the bottom of the login form.
  418. *
  419. * The filter evaluates just preceding the closing form tag element.
  420. *
  421. * @since 3.0.0
  422. *
  423. * @param string $content Content to display. Default empty.
  424. * @param array $args Array of login form arguments.
  425. */
  426. $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
  427. $form = '
  428. <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
  429. ' . $login_form_top . '
  430. <p class="login-username">
  431. <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
  432. <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
  433. </p>
  434. <p class="login-password">
  435. <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
  436. <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
  437. </p>
  438. ' . $login_form_middle . '
  439. ' . ( $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>' : '' ) . '
  440. <p class="login-submit">
  441. <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
  442. <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
  443. </p>
  444. ' . $login_form_bottom . '
  445. </form>';
  446. if ( $args['echo'] )
  447. echo $form;
  448. else
  449. return $form;
  450. }
  451. /**
  452. * Returns the Lost Password URL.
  453. *
  454. * Returns the URL that allows the user to retrieve the lost password
  455. *
  456. * @since 2.8.0
  457. *
  458. * @uses site_url() To generate the lost password URL
  459. *
  460. * @param string $redirect Path to redirect to on login.
  461. * @return string Lost password URL.
  462. */
  463. function wp_lostpassword_url( $redirect = '' ) {
  464. $args = array( 'action' => 'lostpassword' );
  465. if ( !empty($redirect) ) {
  466. $args['redirect_to'] = $redirect;
  467. }
  468. $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
  469. /**
  470. * Filter the Lost Password URL.
  471. *
  472. * @since 2.8.0
  473. *
  474. * @param string $lostpassword_url The lost password page URL.
  475. * @param string $redirect The path to redirect to on login.
  476. */
  477. return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
  478. }
  479. /**
  480. * Display the Registration or Admin link.
  481. *
  482. * Display a link which allows the user to navigate to the registration page if
  483. * not logged in and registration is enabled or to the dashboard if logged in.
  484. *
  485. * @since 1.5.0
  486. *
  487. * @param string $before Text to output before the link (defaults to <li>).
  488. * @param string $after Text to output after the link (defaults to </li>).
  489. * @param boolean $echo Default to echo and not return the link.
  490. * @return string|null String when retrieving, null when displaying.
  491. */
  492. function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
  493. if ( ! is_user_logged_in() ) {
  494. if ( get_option('users_can_register') )
  495. $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
  496. else
  497. $link = '';
  498. } else {
  499. $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
  500. }
  501. /**
  502. * Filter the HTML link to the Registration or Admin page.
  503. *
  504. * Users are sent to the admin page if logged-in, or the registration page
  505. * if enabled and logged-out.
  506. *
  507. * @since 1.5.0
  508. *
  509. * @param string $link The HTML code for the link to the Registration or Admin page.
  510. */
  511. $link = apply_filters( 'register', $link );
  512. if ( $echo ) {
  513. echo $link;
  514. } else {
  515. return $link;
  516. }
  517. }
  518. /**
  519. * Theme container function for the 'wp_meta' action.
  520. *
  521. * The 'wp_meta' action can have several purposes, depending on how you use it,
  522. * but one purpose might have been to allow for theme switching.
  523. *
  524. * @since 1.5.0
  525. *
  526. * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
  527. */
  528. function wp_meta() {
  529. /**
  530. * Fires before displaying echoed content in the sidebar.
  531. *
  532. * @since 1.5.0
  533. */
  534. do_action( 'wp_meta' );
  535. }
  536. /**
  537. * Display information about the blog.
  538. *
  539. * @see get_bloginfo() For possible values for the parameter.
  540. * @since 0.71
  541. *
  542. * @param string $show What to display.
  543. */
  544. function bloginfo( $show='' ) {
  545. echo get_bloginfo( $show, 'display' );
  546. }
  547. /**
  548. * Retrieve information about the blog.
  549. *
  550. * Some show parameter values are deprecated and will be removed in future
  551. * versions. These options will trigger the _deprecated_argument() function.
  552. * The deprecated blog info options are listed in the function contents.
  553. *
  554. * The possible values for the 'show' parameter are listed below.
  555. * <ol>
  556. * <li><strong>url</strong> - Blog URI to homepage.</li>
  557. * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
  558. * <li><strong>description</strong> - Secondary title</li>
  559. * </ol>
  560. *
  561. * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
  562. * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
  563. * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
  564. * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
  565. *
  566. * @since 0.71
  567. *
  568. * @param string $show Blog info to retrieve.
  569. * @param string $filter How to filter what is retrieved.
  570. * @return string Mostly string values, might be empty.
  571. */
  572. function get_bloginfo( $show = '', $filter = 'raw' ) {
  573. switch( $show ) {
  574. case 'home' : // DEPRECATED
  575. case 'siteurl' : // DEPRECATED
  576. _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' ) );
  577. case 'url' :
  578. $output = home_url();
  579. break;
  580. case 'wpurl' :
  581. $output = site_url();
  582. break;
  583. case 'description':
  584. $output = get_option('blogdescription');
  585. break;
  586. case 'rdf_url':
  587. $output = get_feed_link('rdf');
  588. break;
  589. case 'rss_url':
  590. $output = get_feed_link('rss');
  591. break;
  592. case 'rss2_url':
  593. $output = get_feed_link('rss2');
  594. break;
  595. case 'atom_url':
  596. $output = get_feed_link('atom');
  597. break;
  598. case 'comments_atom_url':
  599. $output = get_feed_link('comments_atom');
  600. break;
  601. case 'comments_rss2_url':
  602. $output = get_feed_link('comments_rss2');
  603. break;
  604. case 'pingback_url':
  605. $output = site_url( 'xmlrpc.php' );
  606. break;
  607. case 'stylesheet_url':
  608. $output = get_stylesheet_uri();
  609. break;
  610. case 'stylesheet_directory':
  611. $output = get_stylesheet_directory_uri();
  612. break;
  613. case 'template_directory':
  614. case 'template_url':
  615. $output = get_template_directory_uri();
  616. break;
  617. case 'admin_email':
  618. $output = get_option('admin_email');
  619. break;
  620. case 'charset':
  621. $output = get_option('blog_charset');
  622. if ('' == $output) $output = 'UTF-8';
  623. break;
  624. case 'html_type' :
  625. $output = get_option('html_type');
  626. break;
  627. case 'version':
  628. global $wp_version;
  629. $output = $wp_version;
  630. break;
  631. case 'language':
  632. $output = get_locale();
  633. $output = str_replace('_', '-', $output);
  634. break;
  635. case 'text_direction':
  636. //_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()' ) );
  637. if ( function_exists( 'is_rtl' ) ) {
  638. $output = is_rtl() ? 'rtl' : 'ltr';
  639. } else {
  640. $output = 'ltr';
  641. }
  642. break;
  643. case 'name':
  644. default:
  645. $output = get_option('blogname');
  646. break;
  647. }
  648. $url = true;
  649. if (strpos($show, 'url') === false &&
  650. strpos($show, 'directory') === false &&
  651. strpos($show, 'home') === false)
  652. $url = false;
  653. if ( 'display' == $filter ) {
  654. if ( $url ) {
  655. /**
  656. * Filter the URL returned by get_bloginfo().
  657. *
  658. * @since 2.0.5
  659. *
  660. * @param mixed $output The URL returned by bloginfo().
  661. * @param mixed $show Type of information requested.
  662. */
  663. $output = apply_filters( 'bloginfo_url', $output, $show );
  664. } else {
  665. /**
  666. * Filter the site information returned by get_bloginfo().
  667. *
  668. * @since 0.71
  669. *
  670. * @param mixed $output The requested non-URL site information.
  671. * @param mixed $show Type of information requested.
  672. */
  673. $output = apply_filters( 'bloginfo', $output, $show );
  674. }
  675. }
  676. return $output;
  677. }
  678. /**
  679. * Display or retrieve page title for all areas of blog.
  680. *
  681. * By default, the page title will display the separator before the page title,
  682. * so that the blog title will be before the page title. This is not good for
  683. * title display, since the blog title shows up on most tabs and not what is
  684. * important, which is the page that the user is looking at.
  685. *
  686. * There are also SEO benefits to having the blog title after or to the 'right'
  687. * or the page title. However, it is mostly common sense to have the blog title
  688. * to the right with most browsers supporting tabs. You can achieve this by
  689. * using the seplocation parameter and setting the value to 'right'. This change
  690. * was introduced around 2.5.0, in case backwards compatibility of themes is
  691. * important.
  692. *
  693. * @since 1.0.0
  694. *
  695. * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
  696. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  697. * @param string $seplocation Optional. Direction to display title, 'right'.
  698. * @return string|null String on retrieve, null when displaying.
  699. */
  700. function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
  701. global $wp_locale;
  702. $m = get_query_var('m');
  703. $year = get_query_var('year');
  704. $monthnum = get_query_var('monthnum');
  705. $day = get_query_var('day');
  706. $search = get_query_var('s');
  707. $title = '';
  708. $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  709. // If there is a post
  710. if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  711. $title = single_post_title( '', false );
  712. }
  713. // If there's a post type archive
  714. if ( is_post_type_archive() ) {
  715. $post_type = get_query_var( 'post_type' );
  716. if ( is_array( $post_type ) )
  717. $post_type = reset( $post_type );
  718. $post_type_object = get_post_type_object( $post_type );
  719. if ( ! $post_type_object->has_archive )
  720. $title = post_type_archive_title( '', false );
  721. }
  722. // If there's a category or tag
  723. if ( is_category() || is_tag() ) {
  724. $title = single_term_title( '', false );
  725. }
  726. // If there's a taxonomy
  727. if ( is_tax() ) {
  728. $term = get_queried_object();
  729. if ( $term ) {
  730. $tax = get_taxonomy( $term->taxonomy );
  731. $title = single_term_title( $tax->labels->name . $t_sep, false );
  732. }
  733. }
  734. // If there's an author
  735. if ( is_author() && ! is_post_type_archive() ) {
  736. $author = get_queried_object();
  737. if ( $author )
  738. $title = $author->display_name;
  739. }
  740. // Post type archives with has_archive should override terms.
  741. if ( is_post_type_archive() && $post_type_object->has_archive )
  742. $title = post_type_archive_title( '', false );
  743. // If there's a month
  744. if ( is_archive() && !empty($m) ) {
  745. $my_year = substr($m, 0, 4);
  746. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  747. $my_day = intval(substr($m, 6, 2));
  748. $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
  749. }
  750. // If there's a year
  751. if ( is_archive() && !empty($year) ) {
  752. $title = $year;
  753. if ( !empty($monthnum) )
  754. $title .= $t_sep . $wp_locale->get_month($monthnum);
  755. if ( !empty($day) )
  756. $title .= $t_sep . zeroise($day, 2);
  757. }
  758. // If it's a search
  759. if ( is_search() ) {
  760. /* translators: 1: separator, 2: search phrase */
  761. $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
  762. }
  763. // If it's a 404 page
  764. if ( is_404() ) {
  765. $title = __('Page not found');
  766. }
  767. $prefix = '';
  768. if ( !empty($title) )
  769. $prefix = " $sep ";
  770. /**
  771. * Filter the parts of the page title.
  772. *
  773. * @since 4.0.0
  774. *
  775. * @param array $title_array Parts of the page title.
  776. */
  777. $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
  778. // Determines position of the separator and direction of the breadcrumb
  779. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  780. $title_array = array_reverse( $title_array );
  781. $title = implode( " $sep ", $title_array ) . $prefix;
  782. } else {
  783. $title = $prefix . implode( " $sep ", $title_array );
  784. }
  785. /**
  786. * Filter the text of the page title.
  787. *
  788. * @since 2.0.0
  789. *
  790. * @param string $title Page title.
  791. * @param string $sep Title separator.
  792. * @param string $seplocation Location of the separator (left or right).
  793. */
  794. $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  795. // Send it out
  796. if ( $display )
  797. echo $title;
  798. else
  799. return $title;
  800. }
  801. /**
  802. * Display or retrieve page title for post.
  803. *
  804. * This is optimized for single.php template file for displaying the post title.
  805. *
  806. * It does not support placing the separator after the title, but by leaving the
  807. * prefix parameter empty, you can set the title separator manually. The prefix
  808. * does not automatically place a space between the prefix, so if there should
  809. * be a space, the parameter value will need to have it at the end.
  810. *
  811. * @since 0.71
  812. *
  813. * @param string $prefix Optional. What to display before the title.
  814. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  815. * @return string|null Title when retrieving, null when displaying or failure.
  816. */
  817. function single_post_title($prefix = '', $display = true) {
  818. $_post = get_queried_object();
  819. if ( !isset($_post->post_title) )
  820. return;
  821. /**
  822. * Filter the page title for a single post.
  823. *
  824. * @since 0.71
  825. *
  826. * @param string $_post_title The single post page title.
  827. * @param object $_post The current queried object as returned by get_queried_object().
  828. */
  829. $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
  830. if ( $display )
  831. echo $prefix . $title;
  832. else
  833. return $prefix . $title;
  834. }
  835. /**
  836. * Display or retrieve title for a post type archive.
  837. *
  838. * This is optimized for archive.php and archive-{$post_type}.php template files
  839. * for displaying the title of the post type.
  840. *
  841. * @since 3.1.0
  842. *
  843. * @param string $prefix Optional. What to display before the title.
  844. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  845. * @return string|null Title when retrieving, null when displaying or failure.
  846. */
  847. function post_type_archive_title( $prefix = '', $display = true ) {
  848. if ( ! is_post_type_archive() )
  849. return;
  850. $post_type = get_query_var( 'post_type' );
  851. if ( is_array( $post_type ) )
  852. $post_type = reset( $post_type );
  853. $post_type_obj = get_post_type_object( $post_type );
  854. /**
  855. * Filter the post type archive title.
  856. *
  857. * @since 3.1.0
  858. *
  859. * @param string $post_type_name Post type 'name' label.
  860. * @param string $post_type Post type.
  861. */
  862. $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
  863. if ( $display )
  864. echo $prefix . $title;
  865. else
  866. return $prefix . $title;
  867. }
  868. /**
  869. * Display or retrieve page title for category archive.
  870. *
  871. * This is useful for category template file or files, because it is optimized
  872. * for category page title and with less overhead than {@link wp_title()}.
  873. *
  874. * It does not support placing the separator after the title, but by leaving the
  875. * prefix parameter empty, you can set the title separator manually. The prefix
  876. * does not automatically place a space between the prefix, so if there should
  877. * be a space, the parameter value will need to have it at the end.
  878. *
  879. * @since 0.71
  880. *
  881. * @param string $prefix Optional. What to display before the title.
  882. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  883. * @return string|null Title when retrieving, null when displaying or failure.
  884. */
  885. function single_cat_title( $prefix = '', $display = true ) {
  886. return single_term_title( $prefix, $display );
  887. }
  888. /**
  889. * Display or retrieve page title for tag post archive.
  890. *
  891. * Useful for tag template files for displaying the tag page title. It has less
  892. * overhead than {@link wp_title()}, because of its limited implementation.
  893. *
  894. * It does not support placing the separator after the title, but by leaving the
  895. * prefix parameter empty, you can set the title separator manually. The prefix
  896. * does not automatically place a space between the prefix, so if there should
  897. * be a space, the parameter value will need to have it at the end.
  898. *
  899. * @since 2.3.0
  900. *
  901. * @param string $prefix Optional. What to display before the title.
  902. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  903. * @return string|null Title when retrieving, null when displaying or failure.
  904. */
  905. function single_tag_title( $prefix = '', $display = true ) {
  906. return single_term_title( $prefix, $display );
  907. }
  908. /**
  909. * Display or retrieve page title for taxonomy term archive.
  910. *
  911. * Useful for taxonomy term template files for displaying the taxonomy term page title.
  912. * It has less overhead than {@link wp_title()}, because of its limited implementation.
  913. *
  914. * It does not support placing the separator after the title, but by leaving the
  915. * prefix parameter empty, you can set the title separator manually. The prefix
  916. * does not automatically place a space between the prefix, so if there should
  917. * be a space, the parameter value will need to have it at the end.
  918. *
  919. * @since 3.1.0
  920. *
  921. * @param string $prefix Optional. What to display before the title.
  922. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  923. * @return string|null Title when retrieving, null when displaying or failure.
  924. */
  925. function single_term_title( $prefix = '', $display = true ) {
  926. $term = get_queried_object();
  927. if ( !$term )
  928. return;
  929. if ( is_category() ) {
  930. /**
  931. * Filter the category archive page title.
  932. *
  933. * @since 2.0.10
  934. *
  935. * @param string $term_name Category name for archive being displayed.
  936. */
  937. $term_name = apply_filters( 'single_cat_title', $term->name );
  938. } elseif ( is_tag() ) {
  939. /**
  940. * Filter the tag archive page title.
  941. *
  942. * @since 2.3.0
  943. *
  944. * @param string $term_name Tag name for archive being displayed.
  945. */
  946. $term_name = apply_filters( 'single_tag_title', $term->name );
  947. } elseif ( is_tax() ) {
  948. /**
  949. * Filter the custom taxonomy archive page title.
  950. *
  951. * @since 3.1.0
  952. *
  953. * @param string $term_name Term name for archive being displayed.
  954. */
  955. $term_name = apply_filters( 'single_term_title', $term->name );
  956. } else {
  957. return;
  958. }
  959. if ( empty( $term_name ) )
  960. return;
  961. if ( $display )
  962. echo $prefix . $term_name;
  963. else
  964. return $prefix . $term_name;
  965. }
  966. /**
  967. * Display or retrieve page title for post archive based on date.
  968. *
  969. * Useful for when the template only needs to display the month and year, if
  970. * either are available. Optimized for just this purpose, so if it is all that
  971. * is needed, should be better than {@link wp_title()}.
  972. *
  973. * It does not support placing the separator after the title, but by leaving the
  974. * prefix parameter empty, you can set the title separator manually. The prefix
  975. * does not automatically place a space between the prefix, so if there should
  976. * be a space, the parameter value will need to have it at the end.
  977. *
  978. * @since 0.71
  979. *
  980. * @param string $prefix Optional. What to display before the title.
  981. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  982. * @return string|null Title when retrieving, null when displaying or failure.
  983. */
  984. function single_month_title($prefix = '', $display = true ) {
  985. global $wp_locale;
  986. $m = get_query_var('m');
  987. $year = get_query_var('year');
  988. $monthnum = get_query_var('monthnum');
  989. if ( !empty($monthnum) && !empty($year) ) {
  990. $my_year = $year;
  991. $my_month = $wp_locale->get_month($monthnum);
  992. } elseif ( !empty($m) ) {
  993. $my_year = substr($m, 0, 4);
  994. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  995. }
  996. if ( empty($my_month) )
  997. return false;
  998. $result = $prefix . $my_month . $prefix . $my_year;
  999. if ( !$display )
  1000. return $result;
  1001. echo $result;
  1002. }
  1003. /**
  1004. * Retrieve archive link content based on predefined or custom code.
  1005. *
  1006. * The format can be one of four styles. The 'link' for head element, 'option'
  1007. * for use in the select element, 'html' for use in list (either ol or ul HTML
  1008. * elements). Custom content is also supported using the before and after
  1009. * parameters.
  1010. *
  1011. * The 'link' format uses the link HTML element with the <em>archives</em>
  1012. * relationship. The before and after parameters are not used. The text
  1013. * parameter is used to describe the link.
  1014. *
  1015. * The 'option' format uses the option HTML element for use in select element.
  1016. * The value is the url parameter and the before and after parameters are used
  1017. * between the text description.
  1018. *
  1019. * The 'html' format, which is the default, uses the li HTML element for use in
  1020. * the list HTML elements. The before parameter is before the link and the after
  1021. * parameter is after the closing link.
  1022. *
  1023. * The custom format uses the before parameter before the link ('a' HTML
  1024. * element) and the after parameter after the closing link tag. If the above
  1025. * three values for the format are not used, then custom format is assumed.
  1026. *
  1027. * @since 1.0.0
  1028. *
  1029. * @param string $url URL to archive.
  1030. * @param string $text Archive text description.
  1031. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  1032. * @param string $before Optional.
  1033. * @param string $after Optional.
  1034. * @return string HTML link content for archive.
  1035. */
  1036. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
  1037. $text = wptexturize($text);
  1038. $url = esc_url($url);
  1039. if ('link' == $format)
  1040. $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
  1041. elseif ('option' == $format)
  1042. $link_html = "\t<option value='$url'>$before $text $after</option>\n";
  1043. elseif ('html' == $format)
  1044. $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
  1045. else // custom
  1046. $link_html = "\t$before<a href='$url'>$text</a>$after\n";
  1047. /**
  1048. * Filter the archive link content.
  1049. *
  1050. * @since 2.6.0
  1051. *
  1052. * @param string $link_html The archive HTML link content.
  1053. */
  1054. $link_html = apply_filters( 'get_archives_link', $link_html );
  1055. return $link_html;
  1056. }
  1057. /**
  1058. * Display archive links based on type and format.
  1059. *
  1060. * @since 1.2.0
  1061. *
  1062. * @see get_archives_link()
  1063. *
  1064. * @param string|array $args {
  1065. * Default archive links arguments. Optional.
  1066. *
  1067. * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
  1068. * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
  1069. * display the same archive link list as well as post titles instead
  1070. * of displaying dates. The difference between the two is that 'alpha'
  1071. * will order by post title and 'postbypost' will order by post date.
  1072. * Default 'monthly'.
  1073. * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
  1074. * @type string $format Format each link should take using the $before and $after args.
  1075. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
  1076. * (`<li>` tag), or a custom format, which generates a link anchor
  1077. * with $before preceding and $after succeeding. Default 'html'.
  1078. * @type string $before Markup to prepend to the beginning of each link. Default empty.
  1079. * @type string $after Markup to append to the end of each link. Default empty.
  1080. * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
  1081. * @type bool $echo Whether to echo or return the links list. Default 1|true to echo.
  1082. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
  1083. * Default 'DESC'.
  1084. * }
  1085. * @return string|null String when retrieving, null when displaying.
  1086. */
  1087. function wp_get_archives( $args = '' ) {
  1088. global $wpdb, $wp_locale;
  1089. $defaults = array(
  1090. 'type' => 'monthly', 'limit' => '',
  1091. 'format' => 'html', 'before' => '',
  1092. 'after' => '', 'show_post_count' => false,
  1093. 'echo' => 1, 'order' => 'DESC',
  1094. );
  1095. $r = wp_parse_args( $args, $defaults );
  1096. if ( '' == $r['type'] ) {
  1097. $r['type'] = 'monthly';
  1098. }
  1099. if ( ! empty( $r['limit'] ) ) {
  1100. $r['limit'] = absint( $r['limit'] );
  1101. $r['limit'] = ' LIMIT ' . $r['limit'];
  1102. }
  1103. $order = strtoupper( $r['order'] );
  1104. if ( $order !== 'ASC' ) {
  1105. $order = 'DESC';
  1106. }
  1107. // this is what will separate dates on weekly archive links
  1108. $archive_week_separator = '&#8211;';
  1109. // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
  1110. $archive_date_format_over_ride = 0;
  1111. // options for daily archive (only if you over-ride the general date format)
  1112. $archive_day_date_format = 'Y/m/d';
  1113. // options for weekly archive (only if you over-ride the general date format)
  1114. $archive_week_start_date_format = 'Y/m/d';
  1115. $archive_week_end_date_format = 'Y/m/d';
  1116. if ( ! $archive_date_format_over_ride ) {
  1117. $archive_day_date_format = get_option( 'date_format' );
  1118. $archive_week_start_date_format = get_option( 'date_format' );
  1119. $archive_week_end_date_format = get_option( 'date_format' );
  1120. }
  1121. /**
  1122. * Filter the SQL WHERE clause for retrieving archives.
  1123. *
  1124. * @since 2.2.0
  1125. *
  1126. * @param string $sql_where Portion of SQL query containing the WHERE clause.
  1127. * @param array $r An array of default arguments.
  1128. */
  1129. $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
  1130. /**
  1131. * Filter the SQL JOIN clause for retrieving archives.
  1132. *
  1133. * @since 2.2.0
  1134. *
  1135. * @param string $sql_join Portion of SQL query containing JOIN clause.
  1136. * @param array $r An array of default arguments.
  1137. */
  1138. $join = apply_filters( 'getarchives_join', '', $r );
  1139. $output = '';
  1140. $last_changed = wp_cache_get( 'last_changed', 'posts' );
  1141. if ( ! $last_changed ) {
  1142. $last_changed = microtime();
  1143. wp_cache_set( 'last_changed', $last_changed, 'posts' );
  1144. }
  1145. $limit = $r['limit'];
  1146. if ( 'monthly' == $r['type'] ) {
  1147. $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";
  1148. $key = md5( $query );
  1149. $key = "wp_get_archives:$key:$last_changed";
  1150. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1151. $results = $wpdb->get_results( $query );
  1152. wp_cache_set( $key, $results, 'posts' );
  1153. }
  1154. if ( $results ) {
  1155. $after = $r['after'];
  1156. foreach ( (array) $results as $result ) {
  1157. $url = get_month_link( $result->year, $result->month );
  1158. /* translators: 1: month name, 2: 4-digit year */
  1159. $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
  1160. if ( $r['show_post_count'] ) {
  1161. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1162. }
  1163. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1164. }
  1165. }
  1166. } elseif ( 'yearly' == $r['type'] ) {
  1167. $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";
  1168. $key = md5( $query );
  1169. $key = "wp_get_archives:$key:$last_changed";
  1170. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1171. $results = $wpdb->get_results( $query );
  1172. wp_cache_set( $key, $results, 'posts' );
  1173. }
  1174. if ( $results ) {
  1175. $after = $r['after'];
  1176. foreach ( (array) $results as $result) {
  1177. $url = get_year_link( $result->year );
  1178. $text = sprintf( '%d', $result->year );
  1179. if ( $r['show_post_count'] ) {
  1180. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1181. }
  1182. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1183. }
  1184. }
  1185. } elseif ( 'daily' == $r['type'] ) {
  1186. $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";
  1187. $key = md5( $query );
  1188. $key = "wp_get_archives:$key:$last_changed";
  1189. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1190. $results = $wpdb->get_results( $query );
  1191. $cache[ $key ] = $results;
  1192. wp_cache_set( $key, $results, 'posts' );
  1193. }
  1194. if ( $results ) {
  1195. $after = $r['after'];
  1196. foreach ( (array) $results as $result ) {
  1197. $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  1198. $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
  1199. $text = mysql2date( $archive_day_date_format, $date );
  1200. if ( $r['show_post_count'] ) {
  1201. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1202. }
  1203. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1204. }
  1205. }
  1206. } elseif ( 'weekly' == $r['type'] ) {
  1207. $week = _wp_mysql_week( '`post_date`' );
  1208. $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";
  1209. $key = md5( $query );
  1210. $key = "wp_get_archives:$key:$last_changed";
  1211. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1212. $results = $wpdb->get_results( $query );
  1213. wp_cache_set( $key, $results, 'posts' );
  1214. }
  1215. $arc_w_last = '';
  1216. if ( $results ) {
  1217. $after = $r['after'];
  1218. foreach ( (array) $results as $result ) {
  1219. if ( $result->week != $arc_w_last ) {
  1220. $arc_year = $result->yr;
  1221. $arc_w_last = $result->week;
  1222. $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
  1223. $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
  1224. $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
  1225. $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 );
  1226. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  1227. if ( $r['show_post_count'] ) {
  1228. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1229. }
  1230. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1231. }
  1232. }
  1233. }
  1234. } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
  1235. $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
  1236. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  1237. $key = md5( $query );
  1238. $key = "wp_get_archives:$key:$last_changed";
  1239. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1240. $results = $wpdb->get_results( $query );
  1241. wp_cache_set( $key, $results, 'posts' );
  1242. }
  1243. if ( $results ) {
  1244. foreach ( (array) $results as $result ) {
  1245. if ( $result->post_date != '0000-00-00 00:00:00' ) {
  1246. $url = get_permalink( $result );
  1247. if ( $result->post_title ) {
  1248. /** This filter is documented in wp-includes/post-template.php */
  1249. $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
  1250. } else {
  1251. $text = $result->ID;
  1252. }
  1253. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1254. }
  1255. }
  1256. }
  1257. }
  1258. if ( $r['echo'] ) {
  1259. echo $output;
  1260. } else {
  1261. return $output;
  1262. }
  1263. }
  1264. /**
  1265. * Get number of days since the start of the week.
  1266. *
  1267. * @since 1.5.0
  1268. *
  1269. * @param int $num Number of day.
  1270. * @return int Days since the start of the week.
  1271. */
  1272. function calendar_week_mod($num) {
  1273. $base = 7;
  1274. return ($num - $base*floor($num/$base));
  1275. }
  1276. /**
  1277. * Display calendar with days that have posts as links.
  1278. *
  1279. * The calendar is cached, which will be retrieved, if it exists. If there are
  1280. * no posts for the month, then it will not be displayed.
  1281. *
  1282. * @since 1.0.0
  1283. * @uses calendar_week_mod()
  1284. *
  1285. * @param bool $initial Optional, default is true. Use initial calendar names.
  1286. * @param bool $echo Optional, default is true. Set to false for return.
  1287. * @return string|null String when retrieving, null when displaying.
  1288. */
  1289. function get_calendar($initial = true, $echo = true) {
  1290. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  1291. $key = md5( $m . $monthnum . $year );
  1292. if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
  1293. if ( is_array($cache) && isset( $cache[ $key ] ) ) {
  1294. if ( $echo ) {
  1295. /** This filter is documented in wp-includes/general-template.php */
  1296. echo apply_filters( 'get_calendar', $cache[$key] );
  1297. return;
  1298. } else {
  1299. /** This filter is documented in wp-includes/general-template.php */
  1300. return apply_filters( 'get_calendar', $cache[$key] );
  1301. }
  1302. }
  1303. }
  1304. if ( !is_array($cache) )
  1305. $cache = array();
  1306. // Quick check. If we have no posts at all, abort!
  1307. if ( !$posts ) {
  1308. $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  1309. if ( !$gotsome ) {
  1310. $cache[ $key ] = '';
  1311. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1312. return;
  1313. }
  1314. }
  1315. if ( isset($_GET['w']) )
  1316. $w = ''.intval($_GET['w']);
  1317. // week_begins = 0 stands for Sunday
  1318. $week_begins = intval(get_option('start_of_week'));
  1319. // Let's figure out when we are
  1320. if ( !empty($monthnum) && !empty($year) ) {
  1321. $thismonth = ''.zeroise(intval($monthnum), 2);
  1322. $thisyear = ''.intval($year);
  1323. } elseif ( !empty($w) ) {
  1324. // We need to get the month from MySQL
  1325. $thisyear = ''.intval(substr($m, 0, 4));
  1326. $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
  1327. $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
  1328. } elseif ( !empty($m) ) {
  1329. $thisyear = ''.intval(substr($m, 0, 4));
  1330. if ( strlen($m) < 6 )
  1331. $thismonth = '01';
  1332. else
  1333. $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
  1334. } else {
  1335. $thisyear = gmdate('Y', current_time('timestamp'));
  1336. $thismonth = gmdate('m', current_time('timestamp'));
  1337. }
  1338. $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
  1339. $last_day = date('t', $unixmonth);
  1340. // Get the next and previous month and year with at least one post
  1341. $previous = $wpdb->get_row("SEL…

Large files files are truncated, but you can click here to view the full file