PageRenderTime 33ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/MashedUpMedia/mashedupmedia
PHP | 2287 lines | 1379 code | 174 blank | 734 comment | 219 complexity | db8b0c15fc133e667f84ec9432dd76bd MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0
  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 Optional, default is false. Whether to return the gmt time.
  1311. * @param int|object $post Optional post ID or object. Default is global $post object.
  1312. * @param bool $translate Whether to translate the time string
  1313. * @return string
  1314. */
  1315. function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
  1316. $post = get_post($post);
  1317. if ( $gmt )
  1318. $time = $post->post_date_gmt;
  1319. else
  1320. $time = $post->post_date;
  1321. $time = mysql2date($d, $time, $translate);
  1322. return apply_filters('get_post_time', $time, $d, $gmt);
  1323. }
  1324. /**
  1325. * Display the time at which the post was last modified.
  1326. *
  1327. * @since 2.0.0
  1328. *
  1329. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1330. */
  1331. function the_modified_time($d = '') {
  1332. echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
  1333. }
  1334. /**
  1335. * Retrieve the time at which the post was last modified.
  1336. *
  1337. * @since 2.0.0
  1338. *
  1339. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1340. * @return string
  1341. */
  1342. function get_the_modified_time($d = '') {
  1343. if ( '' == $d )
  1344. $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
  1345. else
  1346. $the_time = get_post_modified_time($d, null, null, true);
  1347. return apply_filters('get_the_modified_time', $the_time, $d);
  1348. }
  1349. /**
  1350. * Retrieve the time at which the post was last modified.
  1351. *
  1352. * @since 2.0.0
  1353. *
  1354. * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
  1355. * @param bool $gmt Optional, default is false. Whether to return the gmt time.
  1356. * @param int|object $post Optional, default is global post object. A post_id or post object
  1357. * @param bool $translate Optional, default is false. Whether to translate the result
  1358. * @return string Returns timestamp
  1359. */
  1360. function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1361. $post = get_post($post);
  1362. if ( $gmt )
  1363. $time = $post->post_modified_gmt;
  1364. else
  1365. $time = $post->post_modified;
  1366. $time = mysql2date($d, $time, $translate);
  1367. return apply_filters('get_post_modified_time', $time, $d, $gmt);
  1368. }
  1369. /**
  1370. * Display the weekday on which the post was written.
  1371. *
  1372. * @since 0.71
  1373. * @uses $wp_locale
  1374. * @uses $post
  1375. */
  1376. function the_weekday() {
  1377. global $wp_locale, $post;
  1378. $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
  1379. $the_weekday = apply_filters('the_weekday', $the_weekday);
  1380. echo $the_weekday;
  1381. }
  1382. /**
  1383. * Display the weekday on which the post was written.
  1384. *
  1385. * Will only output the weekday if the current post's weekday is different from
  1386. * the previous one output.
  1387. *
  1388. * @since 0.71
  1389. *
  1390. * @param string $before Optional Output before the date.
  1391. * @param string $after Optional Output after the date.
  1392. */
  1393. function the_weekday_date($before='',$after='') {
  1394. global $wp_locale, $post, $day, $previousweekday;
  1395. $the_weekday_date = '';
  1396. if ( $currentday != $previousweekday ) {
  1397. $the_weekday_date .= $before;
  1398. $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
  1399. $the_weekday_date .= $after;
  1400. $previousweekday = $currentday;
  1401. }
  1402. $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
  1403. echo $the_weekday_date;
  1404. }
  1405. /**
  1406. * Fire the wp_head action
  1407. *
  1408. * @since 1.2.0
  1409. * @uses do_action() Calls 'wp_head' hook.
  1410. */
  1411. function wp_head() {
  1412. do_action('wp_head');
  1413. }
  1414. /**
  1415. * Fire the wp_footer action
  1416. *
  1417. * @since 1.5.1
  1418. * @uses do_action() Calls 'wp_footer' hook.
  1419. */
  1420. function wp_footer() {
  1421. do_action('wp_footer');
  1422. }
  1423. /**
  1424. * Display the links to the general feeds.
  1425. *
  1426. * @since 2.8.0
  1427. *
  1428. * @param array $args Optional arguments.
  1429. */
  1430. function feed_links( $args = array() ) {
  1431. if ( !current_theme_supports('automatic-feed-links') )
  1432. return;
  1433. $defaults = array(
  1434. /* translators: Separator between blog name and feed type in feed links */
  1435. 'separator' => _x('&raquo;', 'feed link'),
  1436. /* translators: 1: blog title, 2: separator (raquo) */
  1437. 'feedtitle' => __('%1$s %2$s Feed'),
  1438. /* translators: %s: blog title, 2: separator (raquo) */
  1439. 'comstitle' => __('%1$s %2$s Comments Feed'),
  1440. );
  1441. $args = wp_parse_args( $args, $defaults );
  1442. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
  1443. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
  1444. }
  1445. /**
  1446. * Display the links to the extra feeds such as category feeds.
  1447. *
  1448. * @since 2.8.0
  1449. *
  1450. * @param array $args Optional arguments.
  1451. */
  1452. function feed_links_extra( $args = array() ) {
  1453. $defaults = array(
  1454. /* translators: Separator between blog name and feed type in feed links */
  1455. 'separator' => _x('&raquo;', 'feed link'),
  1456. /* translators: 1: blog name, 2: separator(raquo), 3: post title */
  1457. 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
  1458. /* translators: 1: blog name, 2: separator(raquo), 3: category name */
  1459. 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
  1460. /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
  1461. 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
  1462. /* translators: 1: blog name, 2: separator(raquo), 3: author name */
  1463. 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
  1464. /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
  1465. 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
  1466. );
  1467. $args = wp_parse_args( $args, $defaults );
  1468. if ( is_single() || is_page() ) {
  1469. $id = 0;
  1470. $post = &get_post( $id );
  1471. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  1472. $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) );
  1473. $href = get_post_comments_feed_link( $post->ID );
  1474. }
  1475. } elseif ( is_category() ) {
  1476. $term = get_queried_object();
  1477. $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1478. $href = get_category_feed_link( $term->term_id );
  1479. } elseif ( is_tag() ) {
  1480. $term = get_queried_object();
  1481. $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1482. $href = get_tag_feed_link( $term->term_id );
  1483. } elseif ( is_author() ) {
  1484. $author_id = intval( get_query_var('author') );
  1485. $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
  1486. $href = get_author_feed_link( $author_id );
  1487. } elseif ( is_search() ) {
  1488. $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
  1489. $href = get_search_feed_link();
  1490. }
  1491. if ( isset($title) && isset($href) )
  1492. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
  1493. }
  1494. /**
  1495. * Display the link to the Really Simple Discovery service endpoint.
  1496. *
  1497. * @link http://archipelago.phrasewise.com/rsd
  1498. * @since 2.0.0
  1499. */
  1500. function rsd_link() {
  1501. echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
  1502. }
  1503. /**
  1504. * Display the link to the Windows Live Writer manifest file.
  1505. *
  1506. * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
  1507. * @since 2.3.1
  1508. */
  1509. function wlwmanifest_link() {
  1510. echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
  1511. . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
  1512. }
  1513. /**
  1514. * Display a noindex meta tag if required by the blog configuration.
  1515. *
  1516. * If a blog is marked as not being public then the noindex meta tag will be
  1517. * output to tell web robots not to index the page content. Add this to the wp_head action.
  1518. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
  1519. *
  1520. * @see wp_no_robots
  1521. *
  1522. * @since 2.1.0
  1523. */
  1524. function noindex() {
  1525. // If the blog is not public, tell robots to go away.
  1526. if ( '0' == get_option('blog_public') )
  1527. wp_no_robots();
  1528. }
  1529. /**
  1530. * Display a noindex meta tag.
  1531. *
  1532. * Outputs a noindex meta tag that tells web robots not to index the page content.
  1533. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
  1534. *
  1535. * @since 3.3.0
  1536. */
  1537. function wp_no_robots() {
  1538. echo "<meta name='robots' content='noindex,nofollow' />\n";
  1539. }
  1540. /**
  1541. * Determine if TinyMCE is available.
  1542. *
  1543. * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
  1544. *
  1545. * @since 2.1.0
  1546. *
  1547. * @return bool Whether TinyMCE exists.
  1548. */
  1549. function rich_edit_exists() {
  1550. global $wp_rich_edit_exists;
  1551. if ( !isset($wp_rich_edit_exists) )
  1552. $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
  1553. return $wp_rich_edit_exists;
  1554. }
  1555. /**
  1556. * Whether the user should have a WYSIWIG editor.
  1557. *
  1558. * Checks that the user requires a WYSIWIG editor and that the editor is
  1559. * supported in the users browser.
  1560. *
  1561. * @since 2.0.0
  1562. *
  1563. * @return bool
  1564. */
  1565. function user_can_richedit() {
  1566. global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_iphone, $is_IE;
  1567. if ( !isset($wp_rich_edit) ) {
  1568. $wp_rich_edit = false;
  1569. if ( get_user_option( 'rich_editing' ) == 'true' || !is_user_logged_in() ) { // default to 'true' for logged out users
  1570. if ( $is_safari ) {
  1571. if ( !$is_iphone || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 534 ) )
  1572. $wp_rich_edit = true;
  1573. } elseif ( $is_gecko || $is_opera || $is_chrome || $is_IE ) {
  1574. $wp_rich_edit = true;
  1575. }
  1576. }
  1577. }
  1578. return apply_filters('user_can_richedit', $wp_rich_edit);
  1579. }
  1580. /**
  1581. * Find out which editor should be displayed by default.
  1582. *
  1583. * Works out which of the two editors to display as the current editor for a
  1584. * user.
  1585. *
  1586. * @since 2.5.0
  1587. *
  1588. * @return string Either 'tinymce', or 'html', or 'test'
  1589. */
  1590. function wp_default_editor() {
  1591. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  1592. if ( $user = wp_get_current_user() ) { // look for cookie
  1593. $ed = get_user_setting('editor', 'tinymce');
  1594. $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
  1595. }
  1596. return apply_filters( 'wp_default_editor', $r ); // filter
  1597. }
  1598. /**
  1599. * Renders an editor.
  1600. *
  1601. * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
  1602. * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
  1603. *
  1604. * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
  1605. * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
  1606. * On the post edit screen several actions can be used to include additional editors
  1607. * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
  1608. * See http://core.trac.wordpress.org/ticket/19173 for more information.
  1609. *
  1610. * @see wp-includes/class-wp-editor.php
  1611. * @since 3.3
  1612. *
  1613. * @param string $content Initial content for the editor.
  1614. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
  1615. * @param array $settings See _WP_Editors::editor().
  1616. */
  1617. function wp_editor( $content, $editor_id, $settings = array() ) {
  1618. if ( ! class_exists( '_WP_Editors' ) )
  1619. require( ABSPATH . WPINC . '/class-wp-editor.php' );
  1620. _WP_Editors::editor($content, $editor_id, $settings);
  1621. }
  1622. /**
  1623. * Retrieve the contents of the search WordPress query variable.
  1624. *
  1625. * The search query string is passed through {@link esc_attr()}
  1626. * to ensure that it is safe for placing in an html attribute.
  1627. *
  1628. * @since 2.3.0
  1629. * @uses esc_attr()
  1630. *
  1631. * @param bool $escaped Whether the result is escaped. Default true.
  1632. * Only use when you are later escaping it. Do not use unescaped.
  1633. * @return string
  1634. */
  1635. function get_search_query( $escaped = true ) {
  1636. $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
  1637. if ( $escaped )
  1638. $query = esc_attr( $query );
  1639. return $query;
  1640. }
  1641. /**
  1642. * Display the contents of the search query variable.
  1643. *
  1644. * The search query string is passed through {@link esc_attr()}
  1645. * to ensure that it is safe for placing in an html attribute.
  1646. *
  1647. * @uses esc_attr()
  1648. * @since 2.1.0
  1649. */
  1650. function the_search_query() {
  1651. echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
  1652. }
  1653. /**
  1654. * Display the language attributes for the html tag.
  1655. *
  1656. * Builds up a set of html attributes containing the text direction and language
  1657. * information for the page.
  1658. *
  1659. * @since 2.1.0
  1660. *
  1661. * @param string $doctype The type of html document (xhtml|html).
  1662. */
  1663. function language_attributes($doctype = 'html') {
  1664. $attributes = array();
  1665. $output = '';
  1666. if ( function_exists( 'is_rtl' ) )
  1667. $attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"';
  1668. if ( $lang = get_bloginfo('language') ) {
  1669. if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
  1670. $attributes[] = "lang=\"$lang\"";
  1671. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
  1672. $attributes[] = "xml:lang=\"$lang\"";
  1673. }
  1674. $output = implode(' ', $attributes);
  1675. $output = apply_filters('language_attributes', $output);
  1676. echo $output;
  1677. }
  1678. /**
  1679. * Retrieve paginated link for archive post pages.
  1680. *
  1681. * Technically, the function can be used to create paginated link list for any
  1682. * area. The 'base' argument is used to reference the url, which will be used to
  1683. * create the paginated links. The 'format' argument is then used for replacing
  1684. * the page number. It is however, most likely and by default, to be used on the
  1685. * archive post pages.
  1686. *
  1687. * The 'type' argument controls format of the returned value. The default is
  1688. * 'plain', which is just a string with the links separated by a newline
  1689. * character. The other possible values are either 'array' or 'list'. The
  1690. * 'array' value will return an array of the paginated link list to offer full
  1691. * control of display. The 'list' value will place all of the paginated links in
  1692. * an unordered HTML list.
  1693. *
  1694. * The 'total' argument is the total amount of pages and is an integer. The
  1695. * 'current' argument is the current page number and is also an integer.
  1696. *
  1697. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  1698. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  1699. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  1700. * and the '%#%' is also required. The '%#%' will be replaced with the page
  1701. * number.
  1702. *
  1703. * You can include the previous and next links in the list by setting the
  1704. * 'prev_next' argument to true, which it is by default. You can set the
  1705. * previous text, by using the 'prev_text' argument. You can set the next text
  1706. * by setting the 'next_text' argument.
  1707. *
  1708. * If the 'show_all' argument is set to true, then it will show all of the pages
  1709. * instead of a short list of the pages near the current page. By default, the
  1710. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  1711. * arguments. The 'end_size' argument is how many numbers on either the start
  1712. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  1713. * numbers to either side of current page, but not including current page.
  1714. *
  1715. * It is possible to add query vars to the link by using the 'add_args' argument
  1716. * and see {@link add_query_arg()} for more information.
  1717. *
  1718. * @since 2.1.0
  1719. *
  1720. * @param string|array $args Optional. Override defaults.
  1721. * @return array|string String of page links or array of page links.
  1722. */
  1723. function paginate_links( $args = '' ) {
  1724. $defaults = array(
  1725. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  1726. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  1727. 'total' => 1,
  1728. 'current' => 0,
  1729. 'show_all' => false,
  1730. 'prev_next' => true,
  1731. 'prev_text' => __('&laquo; Previous'),
  1732. 'next_text' => __('Next &raquo;'),
  1733. 'end_size' => 1,
  1734. 'mid_size' => 2,
  1735. 'type' => 'plain',
  1736. 'add_args' => false, // array of query args to add
  1737. 'add_fragment' => ''
  1738. );
  1739. $args = wp_parse_args( $args, $defaults );
  1740. extract($args, EXTR_SKIP);
  1741. // Who knows what else people pass in $args
  1742. $total = (int) $total;
  1743. if ( $total < 2 )
  1744. return;
  1745. $current = (int) $current;
  1746. $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
  1747. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
  1748. $add_args = is_array($add_args) ? $add_args : false;
  1749. $r = '';
  1750. $page_links = array();
  1751. $n = 0;
  1752. $dots = false;
  1753. if ( $prev_next && $current && 1 < $current ) :
  1754. $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
  1755. $link = str_replace('%#%', $current - 1, $link);
  1756. if ( $add_args )
  1757. $link = add_query_arg( $add_args, $link );
  1758. $link .= $add_fragment;
  1759. $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
  1760. endif;
  1761. for ( $n = 1; $n <= $total; $n++ ) :
  1762. $n_display = number_format_i18n($n);
  1763. if ( $n == $current ) :
  1764. $page_links[] = "<span class='page-numbers current'>$n_display</span>";
  1765. $dots = true;
  1766. else :
  1767. if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  1768. $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
  1769. $link = str_replace('%#%', $n, $link);
  1770. if ( $add_args )
  1771. $link = add_query_arg( $add_args, $link );
  1772. $link .= $add_fragment;
  1773. $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
  1774. $dots = true;
  1775. elseif ( $dots && !$show_all ) :
  1776. $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
  1777. $dots = false;
  1778. endif;
  1779. endif;
  1780. endfor;
  1781. if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
  1782. $link = str_replace('%_%', $format, $base);
  1783. $link = str_replace('%#%', $current + 1, $link);
  1784. if ( $add_args )
  1785. $link = add_query_arg( $add_args, $link );
  1786. $link .= $add_fragment;
  1787. $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
  1788. endif;
  1789. switch ( $type ) :
  1790. case 'array' :
  1791. return $page_links;
  1792. break;
  1793. case 'list' :
  1794. $r .= "<ul class='page-numbers'>\n\t<li>";
  1795. $r .= join("</li>\n\t<li>", $page_links);
  1796. $r .= "</li>\n</ul>\n";
  1797. break;
  1798. default :
  1799. $r = join("\n", $page_links);
  1800. break;
  1801. endswitch;
  1802. return $r;
  1803. }
  1804. /**
  1805. * Registers an admin colour scheme css file.
  1806. *
  1807. * Allows a plugin to register a new admin colour scheme. For example:
  1808. * <code>
  1809. * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
  1810. * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  1811. * </code>
  1812. *
  1813. * @since 2.5.0
  1814. *
  1815. * @param string $key The unique key for this theme.
  1816. * @param string $name The name of the theme.
  1817. * @param string $url The url of the css file containing the colour scheme.
  1818. * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
  1819. */
  1820. function wp_admin_css_color($key, $name, $url, $colors = array()) {
  1821. global $_wp_admin_css_colors;
  1822. if ( !isset($_wp_admin_css_colors) )
  1823. $_wp_admin_css_colors = array();
  1824. $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
  1825. }
  1826. /**
  1827. * Registers the default Admin color schemes
  1828. *
  1829. * @since 3.0.0
  1830. */
  1831. function register_admin_color_schemes() {
  1832. wp_admin_css_color( 'classic', _x( 'Blue', 'admin color scheme' ), admin_url( 'css/colors-classic.css' ),
  1833. array( '#5589aa', '#cfdfe9', '#d1e5ee', '#eff8ff' ) );
  1834. wp_admin_css_color( 'fresh', _x( 'Gray', 'admin color scheme' ), admin_url( 'css/colors-fresh.css' ),
  1835. array( '#7c7976', '#c6c6c6', '#e0e0e0', '#f1f1f1' ) );
  1836. }
  1837. /**
  1838. * Display the URL of a WordPress admin CSS file.
  1839. *
  1840. * @see WP_Styles::_css_href and its style_loader_src filter.
  1841. *
  1842. * @since 2.3.0
  1843. *
  1844. * @param string $file file relative to wp-admin/ without its ".css" extension.
  1845. */
  1846. function wp_admin_css_uri( $file = 'wp-admin' ) {
  1847. if ( defined('WP_INSTALLING') ) {
  1848. $_file = "./$file.css";
  1849. } else {
  1850. $_file = admin_url("$file.css");
  1851. }
  1852. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  1853. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  1854. }
  1855. /**
  1856. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  1857. *
  1858. * "Intelligently" decides to enqueue or to print the CSS file. If the
  1859. * 'wp_print_styles' action has *not* yet been called, the CSS file will be
  1860. * enqueued. If the wp_print_styles action *has* been called, the CSS link will
  1861. * be printed. Printing may be forced by passing TRUE as the $force_echo
  1862. * (second) parameter.
  1863. *
  1864. * For backward compatibility with WordPress 2.3 calling method: If the $file
  1865. * (first) parameter does not correspond to a registered CSS file, we assume
  1866. * $file is a file relative to wp-admin/ without its ".css" extension. A
  1867. * stylesheet link to that generated URL is printed.
  1868. *
  1869. * @package WordPress
  1870. * @since 2.3.0
  1871. * @uses $wp_styles WordPress Styles Object
  1872. *
  1873. * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
  1874. * to wp-admin/. Defaults to 'wp-admin'.
  1875. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  1876. */
  1877. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  1878. global $wp_styles;
  1879. if ( !is_a($wp_styles, 'WP_Styles') )
  1880. $wp_styles = new WP_Styles();
  1881. // For backward compatibility
  1882. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  1883. if ( $wp_styles->query( $handle ) ) {
  1884. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
  1885. wp_print_styles( $handle );
  1886. else // Add to style queue
  1887. wp_enqueue_style( $handle );
  1888. return;
  1889. }
  1890. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
  1891. if ( is_rtl() )
  1892. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
  1893. }
  1894. /**
  1895. * Enqueues the default ThickBox js and css.
  1896. *
  1897. * If any of the settings need to be changed, this can be done with another js
  1898. * file similar to media-upload.js and theme-preview.js. That file should
  1899. * require array('thickbox') to ensure it is loaded after.
  1900. *
  1901. * @since 2.5.0
  1902. */
  1903. function add_thickbox() {
  1904. wp_enqueue_script( 'thickbox' );
  1905. wp_enqueue_style( 'thickbox' );
  1906. if ( is_network_admin() )
  1907. add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
  1908. }
  1909. /**
  1910. * Display the XHTML generator that is generated on the wp_head hook.
  1911. *
  1912. * @since 2.5.0
  1913. */
  1914. function wp_generator() {
  1915. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  1916. }
  1917. /**
  1918. * Display the generator XML or Comment for RSS, ATOM, etc.
  1919. *
  1920. * Returns the correct generator type for the requested output format. Allows
  1921. * for a plugin to filter generators overall the the_generator filter.
  1922. *
  1923. * @since 2.5.0
  1924. * @uses apply_filters() Calls 'the_generator' hook.
  1925. *
  1926. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  1927. */
  1928. function the_generator( $type ) {
  1929. echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
  1930. }
  1931. /**
  1932. * Creates the generator XML or Comment for RSS, ATOM, etc.
  1933. *
  1934. * Returns the correct generator type for the requested output format. Allows
  1935. * for a plugin to filter generators on an individual basis using the
  1936. * 'get_the_generator_{$type}' filter.
  1937. *
  1938. * @since 2.5.0
  1939. * @uses apply_filters() Calls 'get_the_generator_$type' hook.
  1940. *
  1941. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  1942. * @return string The HTML content for the generator.
  1943. */
  1944. function get_the_generator( $type = '' ) {
  1945. if ( empty( $type ) ) {
  1946. $current_filter = current_filter();
  1947. if ( empty( $current_filter ) )
  1948. return;
  1949. switch ( $current_filter ) {
  1950. case 'rss2_head' :
  1951. case 'commentsrss2_head' :
  1952. $type = 'rss2';
  1953. break;
  1954. case 'rss_head' :
  1955. case 'opml_head' :
  1956. $type = 'comment';
  1957. break;
  1958. case 'rdf_header' :
  1959. $type = 'rdf';
  1960. break;
  1961. case 'atom_head' :
  1962. case 'comments_atom_head' :
  1963. case 'app_head' :
  1964. $type = 'atom';
  1965. break;
  1966. }
  1967. }
  1968. switch ( $type ) {
  1969. case 'html':
  1970. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
  1971. break;
  1972. case 'xhtml':
  1973. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
  1974. break;
  1975. case 'atom':
  1976. $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
  1977. break;
  1978. case 'rss2':
  1979. $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
  1980. break;
  1981. case 'rdf':
  1982. $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
  1983. break;
  1984. case 'comment':
  1985. $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
  1986. break;
  1987. case 'export':
  1988. $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
  1989. break;
  1990. }
  1991. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  1992. }
  1993. /**
  1994. * Outputs the html checked attribute.
  1995. *
  1996. * Compares the first two arguments and if identical marks as checked
  1997. *
  1998. * @since 1.0.0
  1999. *
  2000. * @param mixed $checked One of the values to compare
  2001. * @param mixed $current (true) The other value to compare if not just true
  2002. * @param bool $echo Whether to echo or just return the string
  2003. * @return string html attribute or empty string
  2004. */
  2005. function checked( $checked, $current = true, $echo = true ) {
  2006. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  2007. }
  2008. /**
  2009. * Outputs the html selected attribute.
  2010. *
  2011. * Compares the first two arguments and if identical marks as selected
  2012. *
  2013. * @since 1.0.0
  2014. *
  2015. * @param mixed $selected One of the values to compare
  2016. * @param mixed $current (true) The other value to compare if not just true
  2017. * @param bool $echo Whether to echo or just return the string
  2018. * @return string html attribute or empty string
  2019. */
  2020. function selected( $selected, $current = true, $echo = true ) {
  2021. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  2022. }
  2023. /**
  2024. * Outputs the html disabled attribute.
  2025. *
  2026. * Compares the first two arguments and if identical marks as disabled
  2027. *
  2028. * @since 3.0.0
  2029. *
  2030. * @param mixed $disabled One of the values to compare
  2031. * @param mixed $current (true) The other value to compare if not just true
  2032. * @param bool $echo Whether to echo or just return the string
  2033. * @return string html attribute or empty string
  2034. */
  2035. function disabled( $disabled, $current = true, $echo = true ) {
  2036. return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  2037. }
  2038. /**
  2039. * Private helper function for checked, selected, and disabled.
  2040. *
  2041. * Compares the first two arguments and if identical marks as $type
  2042. *
  2043. * @since 2.8.0
  2044. * @access private
  2045. *
  2046. * @param any $helper One of the values to compare
  2047. * @param any $current (true) The other value to compare if not just true
  2048. * @param bool $echo Whether to echo or just return the string
  2049. * @param string $type The type of checked|selected|disabled we are doing
  2050. * @return string html attribute or empty string
  2051. */
  2052. function __checked_selected_helper( $helper, $current, $echo, $type ) {
  2053. if ( (string) $helper === (string) $current )
  2054. $result = " $type='$type'";
  2055. else
  2056. $result = '';
  2057. if ( $echo )
  2058. echo $result;
  2059. return $result;
  2060. }
  2061. ?>