PageRenderTime 82ms CodeModel.GetById 35ms RepoModel.GetById 1ms 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
  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_status = 'publish'
  1379. AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
  1380. if ( $dayswithposts ) {
  1381. foreach ( (array) $dayswithposts as $daywith ) {
  1382. $daywithpost[] = $daywith[0];
  1383. }
  1384. } else {
  1385. $daywithpost = array();
  1386. }
  1387. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
  1388. $ak_title_separator = "\n";
  1389. else
  1390. $ak_title_separator = ', ';
  1391. $ak_titles_for_day = array();
  1392. $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
  1393. ."FROM $wpdb->posts "
  1394. ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
  1395. ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
  1396. ."AND post_type = 'post' AND post_status = 'publish'"
  1397. );
  1398. if ( $ak_post_titles ) {
  1399. foreach ( (array) $ak_post_titles as $ak_post_title ) {
  1400. /** This filter is documented in wp-includes/post-template.php */
  1401. $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
  1402. if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
  1403. $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
  1404. if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
  1405. $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
  1406. else
  1407. $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
  1408. }
  1409. }
  1410. // See how much we should pad in the beginning
  1411. $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
  1412. if ( 0 != $pad )
  1413. $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
  1414. $daysinmonth = intval(date('t', $unixmonth));
  1415. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  1416. if ( isset($newrow) && $newrow )
  1417. $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
  1418. $newrow = false;
  1419. if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
  1420. $calendar_output .= '<td id="today">';
  1421. else
  1422. $calendar_output .= '<td>';
  1423. if ( in_array($day, $daywithpost) ) // any posts today?
  1424. $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
  1425. else
  1426. $calendar_output .= $day;
  1427. $calendar_output .= '</td>';
  1428. if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
  1429. $newrow = true;
  1430. }
  1431. $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
  1432. if ( $pad != 0 && $pad != 7 )
  1433. $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
  1434. $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
  1435. $cache[ $key ] = $calendar_output;
  1436. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1437. if ( $echo ) {
  1438. /**
  1439. * Filter the HTML calendar output.
  1440. *
  1441. * @since 3.0.0
  1442. *
  1443. * @param string $calendar_output HTML output of the calendar.
  1444. */
  1445. echo apply_filters( 'get_calendar', $calendar_output );
  1446. } else {
  1447. /** This filter is documented in wp-includes/general-template.php */
  1448. return apply_filters( 'get_calendar', $calendar_output );
  1449. }
  1450. }
  1451. /**
  1452. * Purge the cached results of get_calendar.
  1453. *
  1454. * @see get_calendar
  1455. * @since 2.1.0
  1456. */
  1457. function delete_get_calendar_cache() {
  1458. wp_cache_delete( 'get_calendar', 'calendar' );
  1459. }
  1460. add_action( 'save_post', 'delete_get_calendar_cache' );
  1461. add_action( 'delete_post', 'delete_get_calendar_cache' );
  1462. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1463. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  1464. /**
  1465. * Display all of the allowed tags in HTML format with attributes.
  1466. *
  1467. * This is useful for displaying in the comment area, which elements and
  1468. * attributes are supported. As well as any plugins which want to display it.
  1469. *
  1470. * @since 1.0.1
  1471. * @uses $allowedtags
  1472. *
  1473. * @return string HTML allowed tags entity encoded.
  1474. */
  1475. function allowed_tags() {
  1476. global $allowedtags;
  1477. $allowed = '';
  1478. foreach ( (array) $allowedtags as $tag => $attributes ) {
  1479. $allowed .= '<'.$tag;
  1480. if ( 0 < count($attributes) ) {
  1481. foreach ( $attributes as $attribute => $limits ) {
  1482. $allowed .= ' '.$attribute.'=""';
  1483. }
  1484. }
  1485. $allowed .= '> ';
  1486. }
  1487. return htmlentities($allowed);
  1488. }
  1489. /***** Date/Time tags *****/
  1490. /**
  1491. * Outputs the date in iso8601 format for xml files.
  1492. *
  1493. * @since 1.0.0
  1494. */
  1495. function the_date_xml() {
  1496. echo mysql2date( 'Y-m-d', get_post()->post_date, false );
  1497. }
  1498. /**
  1499. * Display or Retrieve the date the current post was written (once per date)
  1500. *
  1501. * Will only output the date if the current post's date is different from the
  1502. * previous one output.
  1503. *
  1504. * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  1505. * function is called several times for each post.
  1506. *
  1507. * HTML output can be filtered with 'the_date'.
  1508. * Date string output can be filtered with 'get_the_date'.
  1509. *
  1510. * @since 0.71
  1511. *
  1512. * @uses get_the_date()
  1513. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1514. * @param string $before Optional. Output before the date.
  1515. * @param string $after Optional. Output after the date.
  1516. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1517. * @return string|null Null if displaying, string if retrieving.
  1518. */
  1519. function the_date( $d = '', $before = '', $after = '', $echo = true ) {
  1520. global $currentday, $previousday;
  1521. if ( $currentday != $previousday ) {
  1522. $the_date = $before . get_the_date( $d ) . $after;
  1523. $previousday = $currentday;
  1524. /**
  1525. * Filter the date a post was published for display.
  1526. *
  1527. * @since 0.71
  1528. *
  1529. * @param string $the_date The formatted date string.
  1530. * @param string $d PHP date format. Defaults to 'date_format' option
  1531. * if not specified.
  1532. * @param string $before HTML output before the date.
  1533. * @param string $after HTML output after the date.
  1534. */
  1535. $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
  1536. if ( $echo )
  1537. echo $the_date;
  1538. else
  1539. return $the_date;
  1540. }
  1541. return null;
  1542. }
  1543. /**
  1544. * Retrieve the date on which the post was written.
  1545. *
  1546. * Unlike the_date() this function will always return the date.
  1547. * Modify output with 'get_the_date' filter.
  1548. *
  1549. * @since 3.0.0
  1550. *
  1551. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1552. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  1553. * @return string Date the current post was written.
  1554. */
  1555. function get_the_date( $d = '', $post = null ) {
  1556. $post = get_post( $post );
  1557. if ( '' == $d ) {
  1558. $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
  1559. } else {
  1560. $the_date = mysql2date( $d, $post->post_date );
  1561. }
  1562. /**
  1563. * Filter the date a post was published.
  1564. *
  1565. * @since 3.0.0
  1566. *
  1567. * @param string $the_date The formatted date.
  1568. * @param string $d PHP date format. Defaults to 'date_format' option
  1569. * if not specified.
  1570. * @param int|WP_Post $post The post object or ID.
  1571. */
  1572. return apply_filters( 'get_the_date', $the_date, $d, $post );
  1573. }
  1574. /**
  1575. * Display the date on which the post was last modified.
  1576. *
  1577. * @since 2.1.0
  1578. *
  1579. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1580. * @param string $before Optional. Output before the date.
  1581. * @param string $after Optional. Output after the date.
  1582. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1583. * @return string|null Null if displaying, string if retrieving.
  1584. */
  1585. function the_modified_date($d = '', $before='', $after='', $echo = true) {
  1586. $the_modified_date = $before . get_the_modified_date($d) . $after;
  1587. /**
  1588. * Filter the date a post was last modified for display.
  1589. *
  1590. * @since 2.1.0
  1591. *
  1592. * @param string $the_modified_date The last modified date.
  1593. * @param string $d PHP date format. Defaults to 'date_format' option
  1594. * if not specified.
  1595. * @param string $before HTML output before the date.
  1596. * @param string $after HTML output after the date.
  1597. */
  1598. $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
  1599. if ( $echo )
  1600. echo $the_modified_date;
  1601. else
  1602. return $the_modified_date;
  1603. }
  1604. /**
  1605. * Retrieve the date on which the post was last modified.
  1606. *
  1607. * @since 2.1.0
  1608. *
  1609. * @param string $d Optional. PHP date format. Defaults to the "date_format" option
  1610. * @return string
  1611. */
  1612. function get_the_modified_date($d = '') {
  1613. if ( '' == $d )
  1614. $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
  1615. else
  1616. $the_time = get_post_modified_time($d, null, null, true);
  1617. /**
  1618. * Filter the date a post was last modified.
  1619. *
  1620. * @since 2.1.0
  1621. *
  1622. * @param string $the_time The formatted date.
  1623. * @param string $d PHP date format. Defaults to value specified in
  1624. * 'date_format' option.
  1625. */
  1626. return apply_filters( 'get_the_modified_date', $the_time, $d );
  1627. }
  1628. /**
  1629. * Display the time at which the post was written.
  1630. *
  1631. * @since 0.71
  1632. *
  1633. * @param string $d Either 'G', 'U', or php date format.
  1634. */
  1635. function the_time( $d = '' ) {
  1636. /**
  1637. * Filter the time a post was written for display.
  1638. *
  1639. * @since 0.71
  1640. *
  1641. * @param string $get_the_time The formatted time.
  1642. * @param string $d The time format. Accepts 'G', 'U',
  1643. * or php date format.
  1644. */
  1645. echo apply_filters( 'the_time', get_the_time( $d ), $d );
  1646. }
  1647. /**
  1648. * Retrieve the time at which the post was written.
  1649. *
  1650. * @since 1.5.0
  1651. *
  1652. * @param string $d Optional. Format to use for retrieving the time the post
  1653. * was written. Either 'G', 'U', or php date format defaults
  1654. * to the value specified in the time_format option. Default empty.
  1655. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
  1656. * @return string|int Formatted date string, or Unix timestamp.
  1657. */
  1658. function get_the_time( $d = '', $post = null ) {
  1659. $post = get_post($post);
  1660. if ( '' == $d )
  1661. $the_time = get_post_time(get_option('time_format'), false, $post, true);
  1662. else
  1663. $the_time = get_post_time($d, false, $post, true);
  1664. /**
  1665. * Filter the time a post was written.
  1666. *
  1667. * @since 1.5.0
  1668. *
  1669. * @param string $the_time The formatted time.
  1670. * @param string $d Format to use for retrieving the time the post was written.
  1671. * Accepts 'G', 'U', or php date format value specified
  1672. * in 'time_format' option. Default empty.
  1673. * @param int|WP_Post $post WP_Post object or ID.
  1674. */
  1675. return apply_filters( 'get_the_time', $the_time, $d, $post );
  1676. }
  1677. /**
  1678. * Retrieve the time at which the post was written.
  1679. *
  1680. * @since 2.0.0
  1681. *
  1682. * @param string $d Optional. Format to use for retrieving the time the post
  1683. * was written. Either 'G', 'U', or php date format. Default 'U'.
  1684. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
  1685. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
  1686. * @param bool $translate Whether to translate the time string. Default false.
  1687. * @return string|int Formatted date string, or Unix timestamp.
  1688. */
  1689. function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1690. $post = get_post($post);
  1691. if ( $gmt )
  1692. $time = $post->post_date_gmt;
  1693. else
  1694. $time = $post->post_date;
  1695. $time = mysql2date($d, $time, $translate);
  1696. /**
  1697. * Filter the localized time a post was written.
  1698. *
  1699. * @since 2.6.0
  1700. *
  1701. * @param string $time The formatted time.
  1702. * @param string $d Format to use for retrieving the time the post was written.
  1703. * Accepts 'G', 'U', or php date format. Default 'U'.
  1704. * @param bool $gmt Whether to retrieve the GMT time. Default false.
  1705. */
  1706. return apply_filters( 'get_post_time', $time, $d, $gmt );
  1707. }
  1708. /**
  1709. * Display the time at which the post was last modified.
  1710. *
  1711. * @since 2.0.0
  1712. *
  1713. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1714. */
  1715. function the_modified_time($d = '') {
  1716. /**
  1717. * Filter the localized time a post was last modified, for display.
  1718. *
  1719. * @since 2.0.0
  1720. *
  1721. * @param string $get_the_modified_time The formatted time.
  1722. * @param string $d The time format. Accepts 'G', 'U',
  1723. * or php date format. Defaults to value
  1724. * specified in 'time_format' option.
  1725. */
  1726. echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
  1727. }
  1728. /**
  1729. * Retrieve the time at which the post was last modified.
  1730. *
  1731. * @since 2.0.0
  1732. *
  1733. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1734. * @return string
  1735. */
  1736. function get_the_modified_time($d = '') {
  1737. if ( '' == $d )
  1738. $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
  1739. else
  1740. $the_time = get_post_modified_time($d, null, null, true);
  1741. /**
  1742. * Filter the localized time a post was last modified.
  1743. *
  1744. * @since 2.0.0
  1745. *
  1746. * @param string $the_time The formatted time.
  1747. * @param string $d Format to use for retrieving the time the post was
  1748. * written. Accepts 'G', 'U', or php date format. Defaults
  1749. * to value specified in 'time_format' option.
  1750. */
  1751. return apply_filters( 'get_the_modified_time', $the_time, $d );
  1752. }
  1753. /**
  1754. * Retrieve the time at which the post was last modified.
  1755. *
  1756. * @since 2.0.0
  1757. *
  1758. * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
  1759. * @param bool $gmt Optional, default is false. Whether to return the gmt time.
  1760. * @param int|object $post Optional, default is global post object. A post_id or post object
  1761. * @param bool $translate Optional, default is false. Whether to translate the result
  1762. * @return string Returns timestamp
  1763. */
  1764. function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1765. $post = get_post($post);
  1766. if ( $gmt )
  1767. $time = $post->post_modified_gmt;
  1768. else
  1769. $time = $post->post_modified;
  1770. $time = mysql2date($d, $time, $translate);
  1771. /**
  1772. * Filter the localized time a post was last modified.
  1773. *
  1774. * @since 2.8.0
  1775. *
  1776. * @param string $time The formatted time.
  1777. * @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
  1778. * @param bool $gmt Whether to return the GMT time. Default false.
  1779. */
  1780. return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
  1781. }
  1782. /**
  1783. * Display the weekday on which the post was written.
  1784. *
  1785. * @since 0.71
  1786. * @uses $wp_locale
  1787. * @uses $post
  1788. */
  1789. function the_weekday() {
  1790. global $wp_locale;
  1791. $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
  1792. /**
  1793. * Filter the weekday on which the post was written, for display.
  1794. *
  1795. * @since 0.71
  1796. *
  1797. * @param string $the_weekday
  1798. */
  1799. $the_weekday = apply_filters( 'the_weekday', $the_weekday );
  1800. echo $the_weekday;
  1801. }
  1802. /**
  1803. * Display the weekday on which the post was written.
  1804. *
  1805. * Will only output the weekday if the current post's weekday is different from
  1806. * the previous one output.
  1807. *
  1808. * @since 0.71
  1809. *
  1810. * @param string $before Optional Output before the date.
  1811. * @param string $after Optional Output after the date.
  1812. */
  1813. function the_weekday_date($before='',$after='') {
  1814. global $wp_locale, $currentday, $previousweekday;
  1815. $the_weekday_date = '';
  1816. if ( $currentday != $previousweekday ) {
  1817. $the_weekday_date .= $before;
  1818. $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
  1819. $the_weekday_date .= $after;
  1820. $previousweekday = $currentday;
  1821. }
  1822. /**
  1823. * Filter the localized date on which the post was written, for display.
  1824. *
  1825. * @since 0.71
  1826. *
  1827. * @param string $the_weekday_date
  1828. * @param string $before The HTML to output before the date.
  1829. * @param string $after The HTML to output after the date.
  1830. */
  1831. $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
  1832. echo $the_weekday_date;
  1833. }
  1834. /**
  1835. * Fire the wp_head action
  1836. *
  1837. * @since 1.2.0
  1838. */
  1839. function wp_head() {
  1840. /**
  1841. * Print scripts or data in the head tag on the front end.
  1842. *
  1843. * @since 1.5.0
  1844. */
  1845. do_action( 'wp_head' );
  1846. }
  1847. /**
  1848. * Fire the wp_footer action
  1849. *
  1850. * @since 1.5.1
  1851. */
  1852. function wp_footer() {
  1853. /**
  1854. * Print scripts or data before the closing body tag on the front end.
  1855. *
  1856. * @since 1.5.1
  1857. */
  1858. do_action( 'wp_footer' );
  1859. }
  1860. /**
  1861. * Display the links to the general feeds.
  1862. *
  1863. * @since 2.8.0
  1864. *
  1865. * @param array $args Optional arguments.
  1866. */
  1867. function feed_links( $args = array() ) {
  1868. if ( !current_theme_supports('automatic-feed-links') )
  1869. return;
  1870. $defaults = array(
  1871. /* translators: Separator between blog name and feed type in feed links */
  1872. 'separator' => _x('&raquo;', 'feed link'),
  1873. /* translators: 1: blog title, 2: separator (raquo) */
  1874. 'feedtitle' => __('%1$s %2$s Feed'),
  1875. /* translators: 1: blog title, 2: separator (raquo) */
  1876. 'comstitle' => __('%1$s %2$s Comments Feed'),
  1877. );
  1878. $args = wp_parse_args( $args, $defaults );
  1879. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
  1880. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
  1881. }
  1882. /**
  1883. * Display the links to the extra feeds such as category feeds.
  1884. *
  1885. * @since 2.8.0
  1886. *
  1887. * @param array $args Optional arguments.
  1888. */
  1889. function feed_links_extra( $args = array() ) {
  1890. $defaults = array(
  1891. /* translators: Separator between blog name and feed type in feed links */
  1892. 'separator' => _x('&raquo;', 'feed link'),
  1893. /* translators: 1: blog name, 2: separator(raquo), 3: post title */
  1894. 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
  1895. /* translators: 1: blog name, 2: separator(raquo), 3: category name */
  1896. 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
  1897. /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
  1898. 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
  1899. /* translators: 1: blog name, 2: separator(raquo), 3: author name */
  1900. 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
  1901. /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
  1902. 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
  1903. /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
  1904. 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
  1905. );
  1906. $args = wp_parse_args( $args, $defaults );
  1907. if ( is_singular() ) {
  1908. $id = 0;
  1909. $post = get_post( $id );
  1910. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  1911. $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
  1912. $href = get_post_comments_feed_link( $post->ID );
  1913. }
  1914. } elseif ( is_post_type_archive() ) {
  1915. $post_type = get_query_var( 'post_type' );
  1916. if ( is_array( $post_type ) )
  1917. $post_type = reset( $post_type );
  1918. $post_type_obj = get_post_type_object( $post_type );
  1919. $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
  1920. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  1921. } elseif ( is_category() ) {
  1922. $term = get_queried_object();
  1923. if ( $term ) {
  1924. $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1925. $href = get_category_feed_link( $term->term_id );
  1926. }
  1927. } elseif ( is_tag() ) {
  1928. $term = get_queried_object();
  1929. if ( $term ) {
  1930. $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1931. $href = get_tag_feed_link( $term->term_id );
  1932. }
  1933. } elseif ( is_author() ) {
  1934. $author_id = intval( get_query_var('author') );
  1935. $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
  1936. $href = get_author_feed_link( $author_id );
  1937. } elseif ( is_search() ) {
  1938. $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
  1939. $href = get_search_feed_link();
  1940. } elseif ( is_post_type_archive() ) {
  1941. $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
  1942. $post_type_obj = get_queried_object();
  1943. if ( $post_type_obj )
  1944. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  1945. }
  1946. if ( isset($title) && isset($href) )
  1947. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
  1948. }
  1949. /**
  1950. * Display the link to the Really Simple Discovery service endpoint.
  1951. *
  1952. * @link http://archipelago.phrasewise.com/rsd
  1953. * @since 2.0.0
  1954. */
  1955. function rsd_link() {
  1956. echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
  1957. }
  1958. /**
  1959. * Display the link to the Windows Live Writer manifest file.
  1960. *
  1961. * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
  1962. * @since 2.3.1
  1963. */
  1964. function wlwmanifest_link() {
  1965. echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
  1966. . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
  1967. }
  1968. /**
  1969. * Display a noindex meta tag if required by the blog configuration.
  1970. *
  1971. * If a blog is marked as not being public then the noindex meta tag will be
  1972. * output to tell web robots not to index the page content. Add this to the wp_head action.
  1973. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
  1974. *
  1975. * @see wp_no_robots
  1976. *
  1977. * @since 2.1.0
  1978. */
  1979. function noindex() {
  1980. // If the blog is not public, tell robots to go away.
  1981. if ( '0' == get_option('blog_public') )
  1982. wp_no_robots();
  1983. }
  1984. /**
  1985. * Display a noindex meta tag.
  1986. *
  1987. * Outputs a noindex meta tag that tells web robots not to index the page content.
  1988. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
  1989. *
  1990. * @since 3.3.0
  1991. */
  1992. function wp_no_robots() {
  1993. echo "<meta name='robots' content='noindex,follow' />\n";
  1994. }
  1995. /**
  1996. * Whether the user should have a WYSIWIG editor.
  1997. *
  1998. * Checks that the user requires a WYSIWIG editor and that the editor is
  1999. * supported in the users browser.
  2000. *
  2001. * @since 2.0.0
  2002. *
  2003. * @return bool
  2004. */
  2005. function user_can_richedit() {
  2006. global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
  2007. if ( !isset($wp_rich_edit) ) {
  2008. $wp_rich_edit = false;
  2009. if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
  2010. if ( $is_safari ) {
  2011. $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
  2012. } elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
  2013. $wp_rich_edit = true;
  2014. }
  2015. }
  2016. }
  2017. /**
  2018. * Filter whether the user can access the rich (Visual) editor.
  2019. *
  2020. * @since 2.1.0
  2021. *
  2022. * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
  2023. */
  2024. return apply_filters( 'user_can_richedit', $wp_rich_edit );
  2025. }
  2026. /**
  2027. * Find out which editor should be displayed by default.
  2028. *
  2029. * Works out which of the two editors to display as the current editor for a
  2030. * user. The 'html' setting is for the "Text" editor tab.
  2031. *
  2032. * @since 2.5.0
  2033. *
  2034. * @return string Either 'tinymce', or 'html', or 'test'
  2035. */
  2036. function wp_default_editor() {
  2037. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  2038. if ( $user = wp_get_current_user() ) { // look for cookie
  2039. $ed = get_user_setting('editor', 'tinymce');
  2040. $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
  2041. }
  2042. /**
  2043. * Filter which editor should be displayed by default.
  2044. *
  2045. * @since 2.5.0
  2046. *
  2047. * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
  2048. */
  2049. return apply_filters( 'wp_default_editor', $r );
  2050. }
  2051. /**
  2052. * Renders an editor.
  2053. *
  2054. * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
  2055. * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
  2056. *
  2057. * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
  2058. * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
  2059. * On the post edit screen several actions can be used to include additional editors
  2060. * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
  2061. * See http://core.trac.wordpress.org/ticket/19173 for more information.
  2062. *
  2063. * @see wp-includes/class-wp-editor.php
  2064. * @since 3.3.0
  2065. *
  2066. * @param string $content Initial content for the editor.
  2067. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
  2068. * @param array $settings See _WP_Editors::editor().
  2069. */
  2070. function wp_editor( $content, $editor_id, $settings = array() ) {
  2071. if ( ! class_exists( '_WP_Editors' ) )
  2072. require( ABSPATH . WPINC . '/class-wp-editor.php' );
  2073. _WP_Editors::editor($content, $editor_id, $settings);
  2074. }
  2075. /**
  2076. * Retrieve the contents of the search WordPress query variable.
  2077. *
  2078. * The search query string is passed through {@link esc_attr()}
  2079. * to ensure that it is safe for placing in an html attribute.
  2080. *
  2081. * @since 2.3.0
  2082. * @uses esc_attr()
  2083. *
  2084. * @param bool $escaped Whether the result is escaped. Default true.
  2085. * Only use when you are later escaping it. Do not use unescaped.
  2086. * @return string
  2087. */
  2088. function get_search_query( $escaped = true ) {
  2089. /**
  2090. * Filter the contents of the search query variable.
  2091. *
  2092. * @since 2.3.0
  2093. *
  2094. * @param mixed $search Contents of the search query variable.
  2095. */
  2096. $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
  2097. if ( $escaped )
  2098. $query = esc_attr( $query );
  2099. return $query;
  2100. }
  2101. /**
  2102. * Display the contents of the search query variable.
  2103. *
  2104. * The search query string is passed through {@link esc_attr()}
  2105. * to ensure that it is safe for placing in an html attribute.
  2106. *
  2107. * @uses esc_attr()
  2108. * @since 2.1.0
  2109. */
  2110. function the_search_query() {
  2111. /**
  2112. * Filter the contents of the search query variable for display.
  2113. *
  2114. * @since 2.3.0
  2115. *
  2116. * @param mixed $search Contents of the search query variable.
  2117. */
  2118. echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
  2119. }
  2120. /**
  2121. * Display the language attributes for the html tag.
  2122. *
  2123. * Builds up a set of html attributes containing the text direction and language
  2124. * information for the page.
  2125. *
  2126. * @since 2.1.0
  2127. *
  2128. * @param string $doctype The type of html document (xhtml|html).
  2129. */
  2130. function language_attributes($doctype = 'html') {
  2131. $attributes = array();
  2132. $output = '';
  2133. if ( function_exists( 'is_rtl' ) && is_rtl() )
  2134. $attributes[] = 'dir="rtl"';
  2135. if ( $lang = get_bloginfo('language') ) {
  2136. if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
  2137. $attributes[] = "lang=\"$lang\"";
  2138. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
  2139. $attributes[] = "xml:lang=\"$lang\"";
  2140. }
  2141. $output = implode(' ', $attributes);
  2142. /**
  2143. * Filter the language attributes for display in the html tag.
  2144. *
  2145. * @since 2.5.0
  2146. *
  2147. * @param string $output A space-separated list of language attributes.
  2148. */
  2149. echo apply_filters( 'language_attributes', $output );
  2150. }
  2151. /**
  2152. * Retrieve paginated link for archive post pages.
  2153. *
  2154. * Technically, the function can be used to create paginated link list for any
  2155. * area. The 'base' argument is used to reference the url, which will be used to
  2156. * create the paginated links. The 'format' argument is then used for replacing
  2157. * the page number. It is however, most likely and by default, to be used on the
  2158. * archive post pages.
  2159. *
  2160. * The 'type' argument controls format of the returned value. The default is
  2161. * 'plain', which is just a string with the links separated by a newline
  2162. * character. The other possible values are either 'array' or 'list'. The
  2163. * 'array' value will return an array of the paginated link list to offer full
  2164. * control of display. The 'list' value will place all of the paginated links in
  2165. * an unordered HTML list.
  2166. *
  2167. * The 'total' argument is the total amount of pages and is an integer. The
  2168. * 'current' argument is the current page number and is also an integer.
  2169. *
  2170. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  2171. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  2172. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  2173. * and the '%#%' is also required. The '%#%' will be replaced with the page
  2174. * number.
  2175. *
  2176. * You can include the previous and next links in the list by setting the
  2177. * 'prev_next' argument to true, which it is by default. You can set the
  2178. * previous text, by using the 'prev_text' argument. You can set the next text
  2179. * by setting the 'next_text' argument.
  2180. *
  2181. * If the 'show_all' argument is set to true, then it will show all of the pages
  2182. * instead of a short list of the pages near the current page. By default, the
  2183. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  2184. * arguments. The 'end_size' argument is how many numbers on either the start
  2185. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  2186. * numbers to either side of current page, but not including current page.
  2187. *
  2188. * It is possible to add query vars to the link by using the 'add_args' argument
  2189. * and see {@link add_query_arg()} for more information.
  2190. *
  2191. * The 'before_page_number' and 'after_page_number' arguments allow users to
  2192. * augment the links themselves. Typically this might be to add context to the
  2193. * numbered links so that screen reader users understand what the links are for.
  2194. * The text strings are added before and after the page number - within the
  2195. * anchor tag.
  2196. *
  2197. * @since 2.1.0
  2198. *
  2199. * @param string|array $args Optional. Override defaults.
  2200. * @return array|string String of page links or array of page links.
  2201. */
  2202. function paginate_links( $args = '' ) {
  2203. $defaults = array(
  2204. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  2205. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  2206. 'total' => 1,
  2207. 'current' => 0,
  2208. 'show_all' => false,
  2209. 'prev_next' => true,
  2210. 'prev_text' => __('&laquo; Previous'),
  2211. 'next_text' => __('Next &raquo;'),
  2212. 'end_size' => 1,
  2213. 'mid_size' => 2,
  2214. 'type' => 'plain',
  2215. 'add_args' => false, // array of query args to add
  2216. 'add_fragment' => '',
  2217. 'before_page_number' => '',
  2218. 'after_page_number' => ''
  2219. );
  2220. $args = wp_parse_args( $args, $defaults );
  2221. extract($args, EXTR_SKIP);
  2222. // Who knows what else people pass in $args
  2223. $total = (int) $total;
  2224. if ( $total < 2 )
  2225. return;
  2226. $current = (int) $current;
  2227. $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
  2228. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
  2229. $add_args = is_array($add_args) ? $add_args : false;
  2230. $r = '';
  2231. $page_links = array();
  2232. $n = 0;
  2233. $dots = false;
  2234. if ( $prev_next && $current && 1 < $current ) :
  2235. $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
  2236. $link = str_replace('%#%', $current - 1, $link);
  2237. if ( $add_args )
  2238. $link = add_query_arg( $add_args, $link );
  2239. $link .= $add_fragment;
  2240. /**
  2241. * Filter the paginated links for the given archive pages.
  2242. *
  2243. * @since 3.0.0
  2244. *
  2245. * @param string $link The paginated link URL.
  2246. */
  2247. $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
  2248. endif;
  2249. for ( $n = 1; $n <= $total; $n++ ) :
  2250. if ( $n == $current ) :
  2251. $page_links[] = "<span class='page-numbers current'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</span>";
  2252. $dots = true;
  2253. else :
  2254. if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  2255. $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
  2256. $link = str_replace('%#%', $n, $link);
  2257. if ( $add_args )
  2258. $link = add_query_arg( $add_args, $link );
  2259. $link .= $add_fragment;
  2260. /** This filter is documented in wp-includes/general-template.php */
  2261. $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</a>";
  2262. $dots = true;
  2263. elseif ( $dots && !$show_all ) :
  2264. $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
  2265. $dots = false;
  2266. endif;
  2267. endif;
  2268. endfor;
  2269. if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
  2270. $link = str_replace('%_%', $format, $base);
  2271. $link = str_replace('%#%', $current + 1, $link);
  2272. if ( $add_args )
  2273. $link = add_query_arg( $add_args, $link );
  2274. $link .= $add_fragment;
  2275. /** This filter is documented in wp-includes/general-template.php */
  2276. $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
  2277. endif;
  2278. switch ( $type ) :
  2279. case 'array' :
  2280. return $page_links;
  2281. break;
  2282. case 'list' :
  2283. $r .= "<ul class='page-numbers'>\n\t<li>";
  2284. $r .= join("</li>\n\t<li>", $page_links);
  2285. $r .= "</li>\n</ul>\n";
  2286. break;
  2287. default :
  2288. $r = join("\n", $page_links);
  2289. break;
  2290. endswitch;
  2291. return $r;
  2292. }
  2293. /**
  2294. * Registers an admin colour scheme css file.
  2295. *
  2296. * Allows a plugin to register a new admin colour scheme. For example:
  2297. * <code>
  2298. * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
  2299. * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  2300. * </code>
  2301. *
  2302. * @since 2.5.0
  2303. *
  2304. * @param string $key The unique key for this theme.
  2305. * @param string $name The name of the theme.
  2306. * @param string $url The url of the css file containing the colour scheme.
  2307. * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
  2308. * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
  2309. */
  2310. function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
  2311. global $_wp_admin_css_colors;
  2312. if ( !isset($_wp_admin_css_colors) )
  2313. $_wp_admin_css_colors = array();
  2314. $_wp_admin_css_colors[$key] = (object) array(
  2315. 'name' => $name,
  2316. 'url' => $url,
  2317. 'colors' => $colors,
  2318. 'icon_colors' => $icons,
  2319. );
  2320. }
  2321. /**
  2322. * Registers the default Admin color schemes
  2323. *
  2324. * @since 3.0.0
  2325. */
  2326. function register_admin_color_schemes() {
  2327. $suffix = is_rtl() ? '-rtl' : '';
  2328. $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
  2329. wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
  2330. false,
  2331. array( '#222', '#333', '#0074a2', '#2ea2cc' ),
  2332. array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )
  2333. );
  2334. // Other color schemes are not available when running out of src
  2335. if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
  2336. return;
  2337. wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
  2338. admin_url( "css/colors/light/colors$suffix.css" ),
  2339. array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
  2340. array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
  2341. );
  2342. wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
  2343. admin_url( "css/colors/blue/colors$suffix.css" ),
  2344. array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
  2345. array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
  2346. );
  2347. wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
  2348. admin_url( "css/colors/midnight/colors$suffix.css" ),
  2349. array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
  2350. array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
  2351. );
  2352. wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
  2353. admin_url( "css/colors/sunrise/colors$suffix.css" ),
  2354. array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
  2355. array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
  2356. );
  2357. wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
  2358. admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
  2359. array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
  2360. array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
  2361. );
  2362. wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
  2363. admin_url( "css/colors/ocean/colors$suffix.css" ),
  2364. array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
  2365. array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
  2366. );
  2367. wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
  2368. admin_url( "css/colors/coffee/colors$suffix.css" ),
  2369. array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
  2370. array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
  2371. );
  2372. }
  2373. /**
  2374. * Display the URL of a WordPress admin CSS file.
  2375. *
  2376. * @see WP_Styles::_css_href and its style_loader_src filter.
  2377. *
  2378. * @since 2.3.0
  2379. *
  2380. * @param string $file file relative to wp-admin/ without its ".css" extension.
  2381. */
  2382. function wp_admin_css_uri( $file = 'wp-admin' ) {
  2383. if ( defined('WP_INSTALLING') ) {
  2384. $_file = "./$file.css";
  2385. } else {
  2386. $_file = admin_url("$file.css");
  2387. }
  2388. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  2389. /**
  2390. * Filter the URI of a WordPress admin CSS file.
  2391. *
  2392. * @since 2.3.0
  2393. *
  2394. * @param string $_file Relative path to the file with query arguments attached.
  2395. * @param string $file Relative path to the file, minus its ".css" extension.
  2396. */
  2397. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  2398. }
  2399. /**
  2400. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  2401. *
  2402. * "Intelligently" decides to enqueue or to print the CSS file. If the
  2403. * 'wp_print_styles' action has *not* yet been called, the CSS file will be
  2404. * enqueued. If the wp_print_styles action *has* been called, the CSS link will
  2405. * be printed. Printing may be forced by passing true as the $force_echo
  2406. * (second) parameter.
  2407. *
  2408. * For backward compatibility with WordPress 2.3 calling method: If the $file
  2409. * (first) parameter does not correspond to a registered CSS file, we assume
  2410. * $file is a file relative to wp-admin/ without its ".css" extension. A
  2411. * stylesheet link to that generated URL is printed.
  2412. *
  2413. * @since 2.3.0
  2414. * @uses $wp_styles WordPress Styles Object
  2415. *
  2416. * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
  2417. * to wp-admin/. Defaults to 'wp-admin'.
  2418. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  2419. */
  2420. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  2421. global $wp_styles;
  2422. if ( !is_a($wp_styles, 'WP_Styles') )
  2423. $wp_styles = new WP_Styles();
  2424. // For backward compatibility
  2425. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  2426. if ( $wp_styles->query( $handle ) ) {
  2427. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
  2428. wp_print_styles( $handle );
  2429. else // Add to style queue
  2430. wp_enqueue_style( $handle );
  2431. return;
  2432. }
  2433. /**
  2434. * Filter the stylesheet link to the specified CSS file.
  2435. *
  2436. * If the site is set to display right-to-left, the RTL stylesheet link
  2437. * will be used instead.
  2438. *
  2439. * @since 2.3.0
  2440. *
  2441. * @param string $file Style handle name or filename (without ".css" extension)
  2442. * relative to wp-admin/. Defaults to 'wp-admin'.
  2443. */
  2444. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
  2445. if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  2446. /** This filter is documented in wp-includes/general-template.php */
  2447. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
  2448. }
  2449. }
  2450. /**
  2451. * Enqueues the default ThickBox js and css.
  2452. *
  2453. * If any of the settings need to be changed, this can be done with another js
  2454. * file similar to media-upload.js. That file should
  2455. * require array('thickbox') to ensure it is loaded after.
  2456. *
  2457. * @since 2.5.0
  2458. */
  2459. function add_thickbox() {
  2460. wp_enqueue_script( 'thickbox' );
  2461. wp_enqueue_style( 'thickbox' );
  2462. if ( is_network_admin() )
  2463. add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
  2464. }
  2465. /**
  2466. * Display the XHTML generator that is generated on the wp_head hook.
  2467. *
  2468. * @since 2.5.0
  2469. */
  2470. function wp_generator() {
  2471. /**
  2472. * Filter the output of the XHTML generator tag.
  2473. *
  2474. * @since 2.5.0
  2475. *
  2476. * @param string $generator_type The XHTML generator.
  2477. */
  2478. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  2479. }
  2480. /**
  2481. * Display the generator XML or Comment for RSS, ATOM, etc.
  2482. *
  2483. * Returns the correct generator type for the requested output format. Allows
  2484. * for a plugin to filter generators overall the the_generator filter.
  2485. *
  2486. * @since 2.5.0
  2487. *
  2488. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  2489. */
  2490. function the_generator( $type ) {
  2491. /**
  2492. * Filter the output of the XHTML generator tag for display.
  2493. *
  2494. * @since 2.5.0
  2495. *
  2496. * @param string $generator_type The generator output.
  2497. * @param string $type The type of generator to output. Accepts 'html',
  2498. * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
  2499. */
  2500. echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
  2501. }
  2502. /**
  2503. * Creates the generator XML or Comment for RSS, ATOM, etc.
  2504. *
  2505. * Returns the correct generator type for the requested output format. Allows
  2506. * for a plugin to filter generators on an individual basis using the
  2507. * 'get_the_generator_{$type}' filter.
  2508. *
  2509. * @since 2.5.0
  2510. *
  2511. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  2512. * @return string The HTML content for the generator.
  2513. */
  2514. function get_the_generator( $type = '' ) {
  2515. if ( empty( $type ) ) {
  2516. $current_filter = current_filter();
  2517. if ( empty( $current_filter ) )
  2518. return;
  2519. switch ( $current_filter ) {
  2520. case 'rss2_head' :
  2521. case 'commentsrss2_head' :
  2522. $type = 'rss2';
  2523. break;
  2524. case 'rss_head' :
  2525. case 'opml_head' :
  2526. $type = 'comment';
  2527. break;
  2528. case 'rdf_header' :
  2529. $type = 'rdf';
  2530. break;
  2531. case 'atom_head' :
  2532. case 'comments_atom_head' :
  2533. case 'app_head' :
  2534. $type = 'atom';
  2535. break;
  2536. }
  2537. }
  2538. switch ( $type ) {
  2539. case 'html':
  2540. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
  2541. break;
  2542. case 'xhtml':
  2543. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
  2544. break;
  2545. case 'atom':
  2546. $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
  2547. break;
  2548. case 'rss2':
  2549. $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
  2550. break;
  2551. case 'rdf':
  2552. $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
  2553. break;
  2554. case 'comment':
  2555. $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
  2556. break;
  2557. case 'export':
  2558. $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
  2559. break;
  2560. }
  2561. /**
  2562. * Filter the HTML for the retrieved generator type.
  2563. *
  2564. * The dynamic portion of the hook name, $type, refers to the generator type.
  2565. *
  2566. * @since 2.5.0
  2567. *
  2568. * @param string $gen The HTML markup output to 'wp_head()'.
  2569. * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
  2570. * 'rss2', 'rdf', 'comment', 'export'.
  2571. */
  2572. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  2573. }
  2574. /**
  2575. * Outputs the html checked attribute.
  2576. *
  2577. * Compares the first two arguments and if identical marks as checked
  2578. *
  2579. * @since 1.0.0
  2580. *
  2581. * @param mixed $checked One of the values to compare
  2582. * @param mixed $current (true) The other value to compare if not just true
  2583. * @param bool $echo Whether to echo or just return the string
  2584. * @return string html attribute or empty string
  2585. */
  2586. function checked( $checked, $current = true, $echo = true ) {
  2587. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  2588. }
  2589. /**
  2590. * Outputs the html selected attribute.
  2591. *
  2592. * Compares the first two arguments and if identical marks as selected
  2593. *
  2594. * @since 1.0.0
  2595. *
  2596. * @param mixed $selected One of the values to compare
  2597. * @param mixed $current (true) The other value to compare if not just true
  2598. * @param bool $echo Whether to echo or just return the string
  2599. * @return string html attribute or empty string
  2600. */
  2601. function selected( $selected, $current = true, $echo = true ) {
  2602. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  2603. }
  2604. /**
  2605. * Outputs the html disabled attribute.
  2606. *
  2607. * Compares the first two arguments and if identical marks as disabled
  2608. *
  2609. * @since 3.0.0
  2610. *
  2611. * @param mixed $disabled One of the values to compare
  2612. * @param mixed $current (true) The other value to compare if not just true
  2613. * @param bool $echo Whether to echo or just return the string
  2614. * @return string html attribute or empty string
  2615. */
  2616. function disabled( $disabled, $current = true, $echo = true ) {
  2617. return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  2618. }
  2619. /**
  2620. * Private helper function for checked, selected, and disabled.
  2621. *
  2622. * Compares the first two arguments and if identical marks as $type
  2623. *
  2624. * @since 2.8.0
  2625. * @access private
  2626. *
  2627. * @param mixed $helper One of the values to compare
  2628. * @param mixed $current (true) The other value to compare if not just true
  2629. * @param bool $echo Whether to echo or just return the string
  2630. * @param string $type The type of checked|selected|disabled we are doing
  2631. * @return string html attribute or empty string
  2632. */
  2633. function __checked_selected_helper( $helper, $current, $echo, $type ) {
  2634. if ( (string) $helper === (string) $current )
  2635. $result = " $type='$type'";
  2636. else
  2637. $result = '';
  2638. if ( $echo )
  2639. echo $result;
  2640. return $result;
  2641. }
  2642. /**
  2643. * Default settings for heartbeat
  2644. *
  2645. * Outputs the nonce used in the heartbeat XHR
  2646. *
  2647. * @since 3.6.0
  2648. *
  2649. * @param array $settings
  2650. * @return array $settings
  2651. */
  2652. function wp_heartbeat_settings( $settings ) {
  2653. if ( ! is_admin() )
  2654. $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
  2655. if ( is_user_logged_in() )
  2656. $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
  2657. return $settings;
  2658. }