PageRenderTime 66ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/Old 2014/wp-includes/general-template.php

https://github.com/armandoaffonso/silmo
PHP | 2926 lines | 1622 code | 207 blank | 1097 comment | 238 complexity | 153c5ee02349cae867f5e449f8eac2a9 MD5 | raw file

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

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