PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/www/blog/wp-includes/general-template.php

http://timoseven.googlecode.com/
PHP | 1885 lines | 1182 code | 156 blank | 547 comment | 167 complexity | 2cfc70b4666858527edc8ececd5b4fd2 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-3.0, AGPL-1.0

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

  1. <?php
  2. /**
  3. * General template tags that can go anywhere in a template.
  4. *
  5. * @package WordPress
  6. * @subpackage Template
  7. */
  8. /**
  9. * Load header template.
  10. *
  11. * Includes the header template for a theme or if a name is specified then a
  12. * specialised header will be included.
  13. *
  14. * For the parameter, if the file is called "header-special.php" then specify
  15. * "special".
  16. *
  17. * @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 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(array('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="' . 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
  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
  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' => site_url( $_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="' . site_url( 'wp-login.php', 'login' ) . '" method="post">
  243. ' . apply_filters( 'login_form_top', '' ) . '
  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', '' ) . '
  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_attr( $args['redirect'] ) . '" />
  257. </p>
  258. ' . apply_filters( 'login_form_bottom', '' ) . '
  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, 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. * Display or retrieve page title for all areas of blog.
  451. *
  452. * By default, the page title will display the separator before the page title,
  453. * so that the blog title will be before the page title. This is not good for
  454. * title display, since the blog title shows up on most tabs and not what is
  455. * important, which is the page that the user is looking at.
  456. *
  457. * There are also SEO benefits to having the blog title after or to the 'right'
  458. * or the page title. However, it is mostly common sense to have the blog title
  459. * to the right with most browsers supporting tabs. You can achieve this by
  460. * using the seplocation parameter and setting the value to 'right'. This change
  461. * was introduced around 2.5.0, in case backwards compatibility of themes is
  462. * important.
  463. *
  464. * @since 1.0.0
  465. *
  466. * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
  467. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  468. * @param string $seplocation Optional. Direction to display title, 'right'.
  469. * @return string|null String on retrieve, null when displaying.
  470. */
  471. function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
  472. global $wpdb, $wp_locale, $wp_query;
  473. $cat = get_query_var('cat');
  474. $tag = get_query_var('tag_id');
  475. $category_name = get_query_var('category_name');
  476. $author = get_query_var('author');
  477. $author_name = get_query_var('author_name');
  478. $m = get_query_var('m');
  479. $year = get_query_var('year');
  480. $monthnum = get_query_var('monthnum');
  481. $day = get_query_var('day');
  482. $search = get_query_var('s');
  483. $title = '';
  484. $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  485. // If there's a category
  486. if ( !empty($cat) ) {
  487. // category exclusion
  488. if ( !stristr($cat,'-') )
  489. $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
  490. } elseif ( !empty($category_name) ) {
  491. if ( stristr($category_name,'/') ) {
  492. $category_name = explode('/',$category_name);
  493. if ( $category_name[count($category_name)-1] )
  494. $category_name = $category_name[count($category_name)-1]; // no trailing slash
  495. else
  496. $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
  497. }
  498. $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
  499. if ( $cat )
  500. $title = apply_filters('single_cat_title', $cat->name);
  501. }
  502. if ( !empty($tag) ) {
  503. $tag = get_term($tag, 'post_tag', OBJECT, 'display');
  504. if ( is_wp_error( $tag ) )
  505. return $tag;
  506. if ( ! empty($tag->name) )
  507. $title = apply_filters('single_tag_title', $tag->name);
  508. }
  509. // If there's an author
  510. if ( !empty($author) ) {
  511. $title = get_userdata($author);
  512. $title = $title->display_name;
  513. }
  514. if ( !empty($author_name) ) {
  515. // We do a direct query here because we don't cache by nicename.
  516. $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
  517. }
  518. // If there's a month
  519. if ( !empty($m) ) {
  520. $my_year = substr($m, 0, 4);
  521. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  522. $my_day = intval(substr($m, 6, 2));
  523. $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : "");
  524. }
  525. if ( !empty($year) ) {
  526. $title = $year;
  527. if ( !empty($monthnum) )
  528. $title .= $t_sep . $wp_locale->get_month($monthnum);
  529. if ( !empty($day) )
  530. $title .= $t_sep . zeroise($day, 2);
  531. }
  532. // If there is a post
  533. if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  534. $post = $wp_query->get_queried_object();
  535. $title = apply_filters( 'single_post_title', $post->post_title );
  536. }
  537. // If there's a taxonomy
  538. if ( is_tax() ) {
  539. $taxonomy = get_query_var( 'taxonomy' );
  540. $tax = get_taxonomy( $taxonomy );
  541. $term = $wp_query->get_queried_object();
  542. $term = $term->name;
  543. $title = $tax->labels->name . $t_sep . $term;
  544. }
  545. //If it's a search
  546. if ( is_search() ) {
  547. /* translators: 1: separator, 2: search phrase */
  548. $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
  549. }
  550. if ( is_404() ) {
  551. $title = __('Page not found');
  552. }
  553. $prefix = '';
  554. if ( !empty($title) )
  555. $prefix = " $sep ";
  556. // Determines position of the separator and direction of the breadcrumb
  557. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  558. $title_array = explode( $t_sep, $title );
  559. $title_array = array_reverse( $title_array );
  560. $title = implode( " $sep ", $title_array ) . $prefix;
  561. } else {
  562. $title_array = explode( $t_sep, $title );
  563. $title = $prefix . implode( " $sep ", $title_array );
  564. }
  565. $title = apply_filters('wp_title', $title, $sep, $seplocation);
  566. // Send it out
  567. if ( $display )
  568. echo $title;
  569. else
  570. return $title;
  571. }
  572. /**
  573. * Display or retrieve page title for post.
  574. *
  575. * This is optimized for single.php template file for displaying the post title.
  576. * Only useful for posts, does not support pages for example.
  577. *
  578. * It does not support placing the separator after the title, but by leaving the
  579. * prefix parameter empty, you can set the title separator manually. The prefix
  580. * does not automatically place a space between the prefix, so if there should
  581. * be a space, the parameter value will need to have it at the end.
  582. *
  583. * @since 0.71
  584. * @uses $wpdb
  585. *
  586. * @param string $prefix Optional. What to display before the title.
  587. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  588. * @return string|null Title when retrieving, null when displaying or failure.
  589. */
  590. function single_post_title($prefix = '', $display = true) {
  591. global $wp_query, $post;
  592. if ( ! $post )
  593. $_post = $wp_query->get_queried_object();
  594. else
  595. $_post = $post;
  596. if ( !isset($_post->post_title) )
  597. return;
  598. $title = apply_filters('single_post_title', $_post->post_title, $_post);
  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. global $wp_query;
  623. if ( is_tag() )
  624. return single_tag_title($prefix, $display);
  625. if ( !is_category() )
  626. return;
  627. $cat = $wp_query->get_queried_object();
  628. $my_cat_name = apply_filters('single_cat_title', $cat->name);
  629. if ( !empty($my_cat_name) ) {
  630. if ( $display )
  631. echo $prefix . $my_cat_name;
  632. else
  633. return $my_cat_name;
  634. }
  635. }
  636. /**
  637. * Display or retrieve page title for tag post archive.
  638. *
  639. * Useful for tag template files for displaying the tag page title. It has less
  640. * overhead than {@link wp_title()}, because of its limited implementation.
  641. *
  642. * It does not support placing the separator after the title, but by leaving the
  643. * prefix parameter empty, you can set the title separator manually. The prefix
  644. * does not automatically place a space between the prefix, so if there should
  645. * be a space, the parameter value will need to have it at the end.
  646. *
  647. * @since 2.3.0
  648. *
  649. * @param string $prefix Optional. What to display before the title.
  650. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  651. * @return string|null Title when retrieving, null when displaying or failure.
  652. */
  653. function single_tag_title($prefix = '', $display = true ) {
  654. global $wp_query;
  655. if ( !is_tag() )
  656. return;
  657. $tag = $wp_query->get_queried_object();
  658. if ( ! $tag )
  659. return;
  660. $my_tag_name = apply_filters('single_tag_title', $tag->name);
  661. if ( !empty($my_tag_name) ) {
  662. if ( $display )
  663. echo $prefix . $my_tag_name;
  664. else
  665. return $my_tag_name;
  666. }
  667. }
  668. /**
  669. * Display or retrieve page title for post archive based on date.
  670. *
  671. * Useful for when the template only needs to display the month and year, if
  672. * either are available. Optimized for just this purpose, so if it is all that
  673. * is needed, should be better than {@link wp_title()}.
  674. *
  675. * It does not support placing the separator after the title, but by leaving the
  676. * prefix parameter empty, you can set the title separator manually. The prefix
  677. * does not automatically place a space between the prefix, so if there should
  678. * be a space, the parameter value will need to have it at the end.
  679. *
  680. * @since 0.71
  681. *
  682. * @param string $prefix Optional. What to display before the title.
  683. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  684. * @return string|null Title when retrieving, null when displaying or failure.
  685. */
  686. function single_month_title($prefix = '', $display = true ) {
  687. global $wp_locale;
  688. $m = get_query_var('m');
  689. $year = get_query_var('year');
  690. $monthnum = get_query_var('monthnum');
  691. if ( !empty($monthnum) && !empty($year) ) {
  692. $my_year = $year;
  693. $my_month = $wp_locale->get_month($monthnum);
  694. } elseif ( !empty($m) ) {
  695. $my_year = substr($m, 0, 4);
  696. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  697. }
  698. if ( empty($my_month) )
  699. return false;
  700. $result = $prefix . $my_month . $prefix . $my_year;
  701. if ( !$display )
  702. return $result;
  703. echo $result;
  704. }
  705. /**
  706. * Retrieve archive link content based on predefined or custom code.
  707. *
  708. * The format can be one of four styles. The 'link' for head element, 'option'
  709. * for use in the select element, 'html' for use in list (either ol or ul HTML
  710. * elements). Custom content is also supported using the before and after
  711. * parameters.
  712. *
  713. * The 'link' format uses the link HTML element with the <em>archives</em>
  714. * relationship. The before and after parameters are not used. The text
  715. * parameter is used to describe the link.
  716. *
  717. * The 'option' format uses the option HTML element for use in select element.
  718. * The value is the url parameter and the before and after parameters are used
  719. * between the text description.
  720. *
  721. * The 'html' format, which is the default, uses the li HTML element for use in
  722. * the list HTML elements. The before parameter is before the link and the after
  723. * parameter is after the closing link.
  724. *
  725. * The custom format uses the before parameter before the link ('a' HTML
  726. * element) and the after parameter after the closing link tag. If the above
  727. * three values for the format are not used, then custom format is assumed.
  728. *
  729. * @since 1.0.0
  730. *
  731. * @param string $url URL to archive.
  732. * @param string $text Archive text description.
  733. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  734. * @param string $before Optional.
  735. * @param string $after Optional.
  736. * @return string HTML link content for archive.
  737. */
  738. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
  739. $text = wptexturize($text);
  740. $title_text = esc_attr($text);
  741. $url = esc_url($url);
  742. if ('link' == $format)
  743. $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
  744. elseif ('option' == $format)
  745. $link_html = "\t<option value='$url'>$before $text $after</option>\n";
  746. elseif ('html' == $format)
  747. $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
  748. else // custom
  749. $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
  750. $link_html = apply_filters( "get_archives_link", $link_html );
  751. return $link_html;
  752. }
  753. /**
  754. * Display archive links based on type and format.
  755. *
  756. * The 'type' argument offers a few choices and by default will display monthly
  757. * archive links. The other options for values are 'daily', 'weekly', 'monthly',
  758. * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
  759. * same archive link list, the difference between the two is that 'alpha'
  760. * will order by post title and 'postbypost' will order by post date.
  761. *
  762. * The date archives will logically display dates with links to the archive post
  763. * page. The 'postbypost' and 'alpha' values for 'type' argument will display
  764. * the post titles.
  765. *
  766. * The 'limit' argument will only display a limited amount of links, specified
  767. * by the 'limit' integer value. By default, there is no limit. The
  768. * 'show_post_count' argument will show how many posts are within the archive.
  769. * By default, the 'show_post_count' argument is set to false.
  770. *
  771. * For the 'format', 'before', and 'after' arguments, see {@link
  772. * get_archives_link()}. The values of these arguments have to do with that
  773. * function.
  774. *
  775. * @since 1.2.0
  776. *
  777. * @param string|array $args Optional. Override defaults.
  778. */
  779. function wp_get_archives($args = '') {
  780. global $wpdb, $wp_locale;
  781. $defaults = array(
  782. 'type' => 'monthly', 'limit' => '',
  783. 'format' => 'html', 'before' => '',
  784. 'after' => '', 'show_post_count' => false,
  785. 'echo' => 1
  786. );
  787. $r = wp_parse_args( $args, $defaults );
  788. extract( $r, EXTR_SKIP );
  789. if ( '' == $type )
  790. $type = 'monthly';
  791. if ( '' != $limit ) {
  792. $limit = absint($limit);
  793. $limit = ' LIMIT '.$limit;
  794. }
  795. // this is what will separate dates on weekly archive links
  796. $archive_week_separator = '&#8211;';
  797. // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
  798. $archive_date_format_over_ride = 0;
  799. // options for daily archive (only if you over-ride the general date format)
  800. $archive_day_date_format = 'Y/m/d';
  801. // options for weekly archive (only if you over-ride the general date format)
  802. $archive_week_start_date_format = 'Y/m/d';
  803. $archive_week_end_date_format = 'Y/m/d';
  804. if ( !$archive_date_format_over_ride ) {
  805. $archive_day_date_format = get_option('date_format');
  806. $archive_week_start_date_format = get_option('date_format');
  807. $archive_week_end_date_format = get_option('date_format');
  808. }
  809. //filters
  810. $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
  811. $join = apply_filters('getarchives_join', "", $r);
  812. $output = '';
  813. if ( 'monthly' == $type ) {
  814. $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";
  815. $key = md5($query);
  816. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  817. if ( !isset( $cache[ $key ] ) ) {
  818. $arcresults = $wpdb->get_results($query);
  819. $cache[ $key ] = $arcresults;
  820. wp_cache_set( 'wp_get_archives', $cache, 'general' );
  821. } else {
  822. $arcresults = $cache[ $key ];
  823. }
  824. if ( $arcresults ) {
  825. $afterafter = $after;
  826. foreach ( (array) $arcresults as $arcresult ) {
  827. $url = get_month_link( $arcresult->year, $arcresult->month );
  828. /* translators: 1: month name, 2: 4-digit year */
  829. $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
  830. if ( $show_post_count )
  831. $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
  832. $output .= get_archives_link($url, $text, $format, $before, $after);
  833. }
  834. }
  835. } elseif ('yearly' == $type) {
  836. $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";
  837. $key = md5($query);
  838. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  839. if ( !isset( $cache[ $key ] ) ) {
  840. $arcresults = $wpdb->get_results($query);
  841. $cache[ $key ] = $arcresults;
  842. wp_cache_set( 'wp_get_archives', $cache, 'general' );
  843. } else {
  844. $arcresults = $cache[ $key ];
  845. }
  846. if ($arcresults) {
  847. $afterafter = $after;
  848. foreach ( (array) $arcresults as $arcresult) {
  849. $url = get_year_link($arcresult->year);
  850. $text = sprintf('%d', $arcresult->year);
  851. if ($show_post_count)
  852. $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
  853. $output .= get_archives_link($url, $text, $format, $before, $after);
  854. }
  855. }
  856. } elseif ( 'daily' == $type ) {
  857. $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";
  858. $key = md5($query);
  859. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  860. if ( !isset( $cache[ $key ] ) ) {
  861. $arcresults = $wpdb->get_results($query);
  862. $cache[ $key ] = $arcresults;
  863. wp_cache_set( 'wp_get_archives', $cache, 'general' );
  864. } else {
  865. $arcresults = $cache[ $key ];
  866. }
  867. if ( $arcresults ) {
  868. $afterafter = $after;
  869. foreach ( (array) $arcresults as $arcresult ) {
  870. $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
  871. $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
  872. $text = mysql2date($archive_day_date_format, $date);
  873. if ($show_post_count)
  874. $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
  875. $output .= get_archives_link($url, $text, $format, $before, $after);
  876. }
  877. }
  878. } elseif ( 'weekly' == $type ) {
  879. $week = _wp_mysql_week( '`post_date`' );
  880. $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";
  881. $key = md5($query);
  882. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  883. if ( !isset( $cache[ $key ] ) ) {
  884. $arcresults = $wpdb->get_results($query);
  885. $cache[ $key ] = $arcresults;
  886. wp_cache_set( 'wp_get_archives', $cache, 'general' );
  887. } else {
  888. $arcresults = $cache[ $key ];
  889. }
  890. $arc_w_last = '';
  891. $afterafter = $after;
  892. if ( $arcresults ) {
  893. foreach ( (array) $arcresults as $arcresult ) {
  894. if ( $arcresult->week != $arc_w_last ) {
  895. $arc_year = $arcresult->yr;
  896. $arc_w_last = $arcresult->week;
  897. $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
  898. $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
  899. $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
  900. $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);
  901. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  902. if ($show_post_count)
  903. $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
  904. $output .= get_archives_link($url, $text, $format, $before, $after);
  905. }
  906. }
  907. }
  908. } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
  909. $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
  910. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  911. $key = md5($query);
  912. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  913. if ( !isset( $cache[ $key ] ) ) {
  914. $arcresults = $wpdb->get_results($query);
  915. $cache[ $key ] = $arcresults;
  916. wp_cache_set( 'wp_get_archives', $cache, 'general' );
  917. } else {
  918. $arcresults = $cache[ $key ];
  919. }
  920. if ( $arcresults ) {
  921. foreach ( (array) $arcresults as $arcresult ) {
  922. if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
  923. $url = get_permalink($arcresult);
  924. $arc_title = $arcresult->post_title;
  925. if ( $arc_title )
  926. $text = strip_tags(apply_filters('the_title', $arc_title));
  927. else
  928. $text = $arcresult->ID;
  929. $output .= get_archives_link($url, $text, $format, $before, $after);
  930. }
  931. }
  932. }
  933. }
  934. if ( $echo )
  935. echo $output;
  936. else
  937. return $output;
  938. }
  939. /**
  940. * Get number of days since the start of the week.
  941. *
  942. * @since 1.5.0
  943. * @usedby get_calendar()
  944. *
  945. * @param int $num Number of day.
  946. * @return int Days since the start of the week.
  947. */
  948. function calendar_week_mod($num) {
  949. $base = 7;
  950. return ($num - $base*floor($num/$base));
  951. }
  952. /**
  953. * Display calendar with days that have posts as links.
  954. *
  955. * The calendar is cached, which will be retrieved, if it exists. If there are
  956. * no posts for the month, then it will not be displayed.
  957. *
  958. * @since 1.0.0
  959. *
  960. * @param bool $initial Optional, default is true. Use initial calendar names.
  961. * @param bool $echo Optional, default is true. Set to false for return.
  962. */
  963. function get_calendar($initial = true, $echo = true) {
  964. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  965. $cache = array();
  966. $key = md5( $m . $monthnum . $year );
  967. if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
  968. if ( is_array($cache) && isset( $cache[ $key ] ) ) {
  969. if ( $echo ) {
  970. echo apply_filters( 'get_calendar', $cache[$key] );
  971. return;
  972. } else {
  973. return apply_filters( 'get_calendar', $cache[$key] );
  974. }
  975. }
  976. }
  977. if ( !is_array($cache) )
  978. $cache = array();
  979. // Quick check. If we have no posts at all, abort!
  980. if ( !$posts ) {
  981. $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  982. if ( !$gotsome ) {
  983. $cache[ $key ] = '';
  984. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  985. return;
  986. }
  987. }
  988. if ( isset($_GET['w']) )
  989. $w = ''.intval($_GET['w']);
  990. // week_begins = 0 stands for Sunday
  991. $week_begins = intval(get_option('start_of_week'));
  992. // Let's figure out when we are
  993. if ( !empty($monthnum) && !empty($year) ) {
  994. $thismonth = ''.zeroise(intval($monthnum), 2);
  995. $thisyear = ''.intval($year);
  996. } elseif ( !empty($w) ) {
  997. // We need to get the month from MySQL
  998. $thisyear = ''.intval(substr($m, 0, 4));
  999. $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
  1000. $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
  1001. } elseif ( !empty($m) ) {
  1002. $thisyear = ''.intval(substr($m, 0, 4));
  1003. if ( strlen($m) < 6 )
  1004. $thismonth = '01';
  1005. else
  1006. $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
  1007. } else {
  1008. $thisyear = gmdate('Y', current_time('timestamp'));
  1009. $thismonth = gmdate('m', current_time('timestamp'));
  1010. }
  1011. $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
  1012. // Get the next and previous month and year with at least one post
  1013. $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
  1014. FROM $wpdb->posts
  1015. WHERE post_date < '$thisyear-$thismonth-01'
  1016. AND post_type = 'post' AND post_status = 'publish'
  1017. ORDER BY post_date DESC
  1018. LIMIT 1");
  1019. $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
  1020. FROM $wpdb->posts
  1021. WHERE post_date > '$thisyear-$thismonth-01'
  1022. AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
  1023. AND post_type = 'post' AND post_status = 'publish'
  1024. ORDER BY post_date ASC
  1025. LIMIT 1");
  1026. /* translators: Calendar caption: 1: month name, 2: 4-digit year */
  1027. $calendar_caption = _x('%1$s %2$s', 'calendar caption');
  1028. $calendar_output = '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
  1029. <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
  1030. <thead>
  1031. <tr>';
  1032. $myweek = array();
  1033. for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
  1034. $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
  1035. }
  1036. foreach ( $myweek as $wd ) {
  1037. $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
  1038. $wd = esc_attr($wd);
  1039. $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
  1040. }
  1041. $calendar_output .= '
  1042. </tr>
  1043. </thead>
  1044. <tfoot>
  1045. <tr>';
  1046. if ( $previous ) {
  1047. $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . 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>';
  1048. } else {
  1049. $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
  1050. }
  1051. $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
  1052. if ( $next ) {
  1053. $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>';
  1054. } else {
  1055. $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
  1056. }
  1057. $calendar_output .= '
  1058. </tr>
  1059. </tfoot>
  1060. <tbody>
  1061. <tr>';
  1062. // Get days with posts
  1063. $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
  1064. FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
  1065. AND YEAR(post_date) = '$thisyear'
  1066. AND post_type = 'post' AND post_status = 'publish'
  1067. AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
  1068. if ( $dayswithposts ) {
  1069. foreach ( (array) $dayswithposts as $daywith ) {
  1070. $daywithpost[] = $daywith[0];
  1071. }
  1072. } else {
  1073. $daywithpost = array();
  1074. }
  1075. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
  1076. $ak_title_separator = "\n";
  1077. else
  1078. $ak_title_separator = ', ';
  1079. $ak_titles_for_day = array();
  1080. $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
  1081. ."FROM $wpdb->posts "
  1082. ."WHERE YEAR(post_date) = '$thisyear' "
  1083. ."AND MONTH(post_date) = '$thismonth' "
  1084. ."AND post_date < '".current_time('mysql')."' "
  1085. ."AND post_type = 'post' AND post_status = 'publish'"
  1086. );
  1087. if ( $ak_post_titles ) {
  1088. foreach ( (array) $ak_post_titles as $ak_post_title ) {
  1089. $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
  1090. if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
  1091. $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
  1092. if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
  1093. $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
  1094. else
  1095. $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
  1096. }
  1097. }
  1098. // See how much we should pad in the beginning
  1099. $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
  1100. if ( 0 != $pad )
  1101. $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
  1102. $daysinmonth = intval(date('t', $unixmonth));
  1103. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  1104. if ( isset($newrow) && $newrow )
  1105. $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
  1106. $newrow = false;
  1107. if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
  1108. $calendar_output .= '<td id="today">';
  1109. else
  1110. $calendar_output .= '<td>';
  1111. if ( in_array($day, $daywithpost) ) // any posts today?
  1112. $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
  1113. else
  1114. $calendar_output .= $day;
  1115. $calendar_output .= '</td>';
  1116. if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
  1117. $newrow = true;
  1118. }
  1119. $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
  1120. if ( $pad != 0 && $pad != 7 )
  1121. $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
  1122. $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
  1123. $cache[ $key ] = $calendar_output;
  1124. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1125. if ( $echo )
  1126. echo apply_filters( 'get_calendar', $calendar_output );
  1127. else
  1128. return apply_filters( 'get_calendar', $calendar_output );
  1129. }
  1130. /**
  1131. * Purge the cached results of get_calendar.
  1132. *
  1133. * @see get_calendar
  1134. * @since 2.1.0
  1135. */
  1136. function delete_get_calendar_cache() {
  1137. wp_cache_delete( 'get_calendar', 'calendar' );
  1138. }
  1139. add_action( 'save_post', 'delete_get_calendar_cache' );
  1140. add_action( 'delete_post', 'delete_get_calendar_cache' );
  1141. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1142. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  1143. /**
  1144. * Display all of the allowed tags in HTML format with attributes.
  1145. *
  1146. * This is useful for displaying in the comment area, which elements and
  1147. * attributes are supported. As well as any plugins which want to display it.
  1148. *
  1149. * @since 1.0.1
  1150. * @uses $allowedtags
  1151. *
  1152. * @return string HTML allowed tags entity encoded.
  1153. */
  1154. function allowed_tags() {
  1155. global $allowedtags;
  1156. $allowed = '';
  1157. foreach ( (array) $allowedtags as $tag => $attributes ) {
  1158. $allowed .= '<'.$tag;
  1159. if ( 0 < count($attributes) ) {
  1160. foreach ( $attributes as $attribute => $limits ) {
  1161. $allowed .= ' '.$attribute.'=""';
  1162. }
  1163. }
  1164. $allowed .= '> ';
  1165. }
  1166. return htmlentities($allowed);
  1167. }
  1168. /***** Date/Time tags *****/
  1169. /**
  1170. * Outputs the date in iso8601 format for xml files.
  1171. *
  1172. * @since 1.0.0
  1173. */
  1174. function the_date_xml() {
  1175. global $post;
  1176. echo mysql2date('Y-m-d', $post->post_date, false);
  1177. }
  1178. /**
  1179. * Display or Retrieve the date the current $post was written (once per date)
  1180. *
  1181. * Will only output the date if the current post's date is different from the
  1182. * previous one output.
  1183. * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  1184. * function is called several times for each post.
  1185. *
  1186. * HTML output can be filtered with 'the_date'.
  1187. * Date string output can be filtered with 'get_the_date'.
  1188. *
  1189. * @since 0.71
  1190. * @uses get_the_date()
  1191. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1192. * @param string $before Optional. Output before the date.
  1193. * @param string $after Optional. Output after the date.
  1194. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1195. * @return string|null Null if displaying, string if retrieving.
  1196. */
  1197. function the_date( $d = '', $before = '', $after = '', $echo = true ) {
  1198. global $day, $previousday;
  1199. $the_date = '';
  1200. if ( $day != $previousday ) {
  1201. $the_date .= $before;
  1202. $the_date .= get_the_date( $d );
  1203. $the_date .= $after;
  1204. $previousday = $day;
  1205. $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
  1206. if ( $echo )
  1207. echo $the_date;
  1208. else
  1209. return $the_date;
  1210. }
  1211. return null;
  1212. }
  1213. /**
  1214. * Retrieve the date the current $post was written.
  1215. *
  1216. * Unlike the_date() this function will always return the date.
  1217. * Modify output with 'get_the_date' filter.
  1218. *
  1219. * @since 3.0.0
  1220. *
  1221. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1222. * @return string|null Null if displaying, string if retrieving.
  1223. */
  1224. function get_the_date( $d = '' ) {
  1225. global $post;
  1226. $the_date = '';
  1227. if ( '' == $d )
  1228. $the_date .= mysql2date(get_option('date_format'), $post->post_date);
  1229. else
  1230. $the_date .= mysql2date($d, $post->post_date);
  1231. return apply_filters('get_the_date', $the_date, $d);
  1232. }
  1233. /**
  1234. * Display the date on which the post was last modified.
  1235. *
  1236. * @since 2.1.0
  1237. *
  1238. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1239. * @param string $before Optional. Output before the date.
  1240. * @param string $after Optional. Output after the date.
  1241. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1242. * @return string|null Null if displaying, string if retrieving.
  1243. */
  1244. function the_modified_date($d = '', $before='', $after='', $echo = true) {
  1245. $the_modified_date = $before . get_the_modified_date($d) . $after;
  1246. $the_modified_date = apply_filters('the_modified_date', $the_modified_date, $d, $before, $after);
  1247. if ( $echo )
  1248. echo $the_modified_date;
  1249. else
  1250. return $the_modified_date;
  1251. }
  1252. /**
  1253. * Retrieve the date on which the post was last modified.
  1254. *
  1255. * @since 2.1.0
  1256. *
  1257. * @param string $d Optional. PHP date format. Defaults to the "date_format" option
  1258. * @return string
  1259. */
  1260. function get_the_modified_date($d = '') {
  1261. if ( '' == $d )
  1262. $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
  1263. else
  1264. $the_time = get_post_modified_time($d, null, null, true);
  1265. return apply_filters('get_the_modified_date', $the_time, $d);
  1266. }
  1267. /**
  1268. * Display the time at which the post was written.
  1269. *
  1270. * @since 0.71
  1271. *

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