PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/general-template.php

https://bitbucket.org/jcsarda/wordpress-dotcloud-deployable
PHP | 2287 lines | 1379 code | 174 blank | 734 comment | 219 complexity | db8b0c15fc133e667f84ec9432dd76bd MD5 | raw file

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

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

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