PageRenderTime 70ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

https://bitbucket.org/aukhanev/xdn-wordpress31
PHP | 2320 lines | 1420 code | 178 blank | 722 comment | 225 complexity | a852aa92bd83092eeeafb3ecb9eb98b5 MD5 | raw file
  1. <?php
  2. /**
  3. * General template tags that can go anywhere in a template.
  4. *
  5. * @package WordPress
  6. * @subpackage Template
  7. */
  8. /**
  9. * Load header template.
  10. *
  11. * Includes the header template for a theme or if a name is specified then a
  12. * specialised header will be included.
  13. *
  14. * For the parameter, if the file is called "header-special.php" then specify
  15. * "special".
  16. *
  17. * @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('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.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' => 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', '', $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_attr( $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, 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. $arc_title = $arcresult->post_title;
  937. if ( $arc_title )
  938. $text = strip_tags(apply_filters('the_title', $arc_title));
  939. else
  940. $text = $arcresult->ID;
  941. $output .= get_archives_link($url, $text, $format, $before, $after);
  942. }
  943. }
  944. }
  945. }
  946. if ( $echo )
  947. echo $output;
  948. else
  949. return $output;
  950. }
  951. /**
  952. * Get number of days since the start of the week.
  953. *
  954. * @since 1.5.0
  955. * @usedby get_calendar()
  956. *
  957. * @param int $num Number of day.
  958. * @return int Days since the start of the week.
  959. */
  960. function calendar_week_mod($num) {
  961. $base = 7;
  962. return ($num - $base*floor($num/$base));
  963. }
  964. /**
  965. * Display calendar with days that have posts as links.
  966. *
  967. * The calendar is cached, which will be retrieved, if it exists. If there are
  968. * no posts for the month, then it will not be displayed.
  969. *
  970. * @since 1.0.0
  971. *
  972. * @param bool $initial Optional, default is true. Use initial calendar names.
  973. * @param bool $echo Optional, default is true. Set to false for return.
  974. */
  975. function get_calendar($initial = true, $echo = true) {
  976. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  977. $cache = array();
  978. $key = md5( $m . $monthnum . $year );
  979. if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
  980. if ( is_array($cache) && isset( $cache[ $key ] ) ) {
  981. if ( $echo ) {
  982. echo apply_filters( 'get_calendar', $cache[$key] );
  983. return;
  984. } else {
  985. return apply_filters( 'get_calendar', $cache[$key] );
  986. }
  987. }
  988. }
  989. if ( !is_array($cache) )
  990. $cache = array();
  991. // Quick check. If we have no posts at all, abort!
  992. if ( !$posts ) {
  993. $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  994. if ( !$gotsome ) {
  995. $cache[ $key ] = '';
  996. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  997. return;
  998. }
  999. }
  1000. if ( isset($_GET['w']) )
  1001. $w = ''.intval($_GET['w']);
  1002. // week_begins = 0 stands for Sunday
  1003. $week_begins = intval(get_option('start_of_week'));
  1004. // Let's figure out when we are
  1005. if ( !empty($monthnum) && !empty($year) ) {
  1006. $thismonth = ''.zeroise(intval($monthnum), 2);
  1007. $thisyear = ''.intval($year);
  1008. } elseif ( !empty($w) ) {
  1009. // We need to get the month from MySQL
  1010. $thisyear = ''.intval(substr($m, 0, 4));
  1011. $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
  1012. $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
  1013. } elseif ( !empty($m) ) {
  1014. $thisyear = ''.intval(substr($m, 0, 4));
  1015. if ( strlen($m) < 6 )
  1016. $thismonth = '01';
  1017. else
  1018. $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
  1019. } else {
  1020. $thisyear = gmdate('Y', current_time('timestamp'));
  1021. $thismonth = gmdate('m', current_time('timestamp'));
  1022. }
  1023. $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
  1024. $last_day = date('t', $unixmonth);
  1025. // Get the next and previous month and year with at least one post
  1026. $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1027. FROM $wpdb->posts
  1028. WHERE post_date < '$thisyear-$thismonth-01'
  1029. AND post_type = 'post' AND post_status = 'publish'
  1030. ORDER BY post_date DESC
  1031. LIMIT 1");
  1032. $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1033. FROM $wpdb->posts
  1034. WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
  1035. AND post_type = 'post' AND post_status = 'publish'
  1036. ORDER BY post_date ASC
  1037. LIMIT 1");
  1038. /* translators: Calendar caption: 1: month name, 2: 4-digit year */
  1039. $calendar_caption = _x('%1$s %2$s', 'calendar caption');
  1040. $calendar_output = '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
  1041. <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
  1042. <thead>
  1043. <tr>';
  1044. $myweek = array();
  1045. for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
  1046. $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
  1047. }
  1048. foreach ( $myweek as $wd ) {
  1049. $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
  1050. $wd = esc_attr($wd);
  1051. $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
  1052. }
  1053. $calendar_output .= '
  1054. </tr>
  1055. </thead>
  1056. <tfoot>
  1057. <tr>';
  1058. if ( $previous ) {
  1059. $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>';
  1060. } else {
  1061. $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
  1062. }
  1063. $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
  1064. if ( $next ) {
  1065. $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>';
  1066. } else {
  1067. $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
  1068. }
  1069. $calendar_output .= '
  1070. </tr>
  1071. </tfoot>
  1072. <tbody>
  1073. <tr>';
  1074. // Get days with posts
  1075. $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
  1076. FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
  1077. AND post_type = 'post' AND post_status = 'publish'
  1078. AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
  1079. if ( $dayswithposts ) {
  1080. foreach ( (array) $dayswithposts as $daywith ) {
  1081. $daywithpost[] = $daywith[0];
  1082. }
  1083. } else {
  1084. $daywithpost = array();
  1085. }
  1086. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
  1087. $ak_title_separator = "\n";
  1088. else
  1089. $ak_title_separator = ', ';
  1090. $ak_titles_for_day = array();
  1091. $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
  1092. ."FROM $wpdb->posts "
  1093. ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
  1094. ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
  1095. ."AND post_type = 'post' AND post_status = 'publish'"
  1096. );
  1097. if ( $ak_post_titles ) {
  1098. foreach ( (array) $ak_post_titles as $ak_post_title ) {
  1099. $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
  1100. if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
  1101. $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
  1102. if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
  1103. $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
  1104. else
  1105. $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
  1106. }
  1107. }
  1108. // See how much we should pad in the beginning
  1109. $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
  1110. if ( 0 != $pad )
  1111. $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
  1112. $daysinmonth = intval(date('t', $unixmonth));
  1113. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  1114. if ( isset($newrow) && $newrow )
  1115. $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
  1116. $newrow = false;
  1117. if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
  1118. $calendar_output .= '<td id="today">';
  1119. else
  1120. $calendar_output .= '<td>';
  1121. if ( in_array($day, $daywithpost) ) // any posts today?
  1122. $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
  1123. else
  1124. $calendar_output .= $day;
  1125. $calendar_output .= '</td>';
  1126. if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
  1127. $newrow = true;
  1128. }
  1129. $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
  1130. if ( $pad != 0 && $pad != 7 )
  1131. $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
  1132. $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
  1133. $cache[ $key ] = $calendar_output;
  1134. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1135. if ( $echo )
  1136. echo apply_filters( 'get_calendar', $calendar_output );
  1137. else
  1138. return apply_filters( 'get_calendar', $calendar_output );
  1139. }
  1140. /**
  1141. * Purge the cached results of get_calendar.
  1142. *
  1143. * @see get_calendar
  1144. * @since 2.1.0
  1145. */
  1146. function delete_get_calendar_cache() {
  1147. wp_cache_delete( 'get_calendar', 'calendar' );
  1148. }
  1149. add_action( 'save_post', 'delete_get_calendar_cache' );
  1150. add_action( 'delete_post', 'delete_get_calendar_cache' );
  1151. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1152. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  1153. /**
  1154. * Display all of the allowed tags in HTML format with attributes.
  1155. *
  1156. * This is useful for displaying in the comment area, which elements and
  1157. * attributes are supported. As well as any plugins which want to display it.
  1158. *
  1159. * @since 1.0.1
  1160. * @uses $allowedtags
  1161. *
  1162. * @return string HTML allowed tags entity encoded.
  1163. */
  1164. function allowed_tags() {
  1165. global $allowedtags;
  1166. $allowed = '';
  1167. foreach ( (array) $allowedtags as $tag => $attributes ) {
  1168. $allowed .= '<'.$tag;
  1169. if ( 0 < count($attributes) ) {
  1170. foreach ( $attributes as $attribute => $limits ) {
  1171. $allowed .= ' '.$attribute.'=""';
  1172. }
  1173. }
  1174. $allowed .= '> ';
  1175. }
  1176. return htmlentities($allowed);
  1177. }
  1178. /***** Date/Time tags *****/
  1179. /**
  1180. * Outputs the date in iso8601 format for xml files.
  1181. *
  1182. * @since 1.0.0
  1183. */
  1184. function the_date_xml() {
  1185. global $post;
  1186. echo mysql2date('Y-m-d', $post->post_date, false);
  1187. }
  1188. /**
  1189. * Display or Retrieve the date the current $post was written (once per date)
  1190. *
  1191. * Will only output the date if the current post's date is different from the
  1192. * previous one output.
  1193. *
  1194. * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  1195. * function is called several times for each post.
  1196. *
  1197. * HTML output can be filtered with 'the_date'.
  1198. * Date string output can be filtered with 'get_the_date'.
  1199. *
  1200. * @since 0.71
  1201. * @uses get_the_date()
  1202. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1203. * @param string $before Optional. Output before the date.
  1204. * @param string $after Optional. Output after the date.
  1205. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1206. * @return string|null Null if displaying, string if retrieving.
  1207. */
  1208. function the_date( $d = '', $before = '', $after = '', $echo = true ) {
  1209. global $currentday, $previousday;
  1210. $the_date = '';
  1211. if ( $currentday != $previousday ) {
  1212. $the_date .= $before;
  1213. $the_date .= get_the_date( $d );
  1214. $the_date .= $after;
  1215. $previousday = $currentday;
  1216. $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
  1217. if ( $echo )
  1218. echo $the_date;
  1219. else
  1220. return $the_date;
  1221. }
  1222. return null;
  1223. }
  1224. /**
  1225. * Retrieve the date the current $post was written.
  1226. *
  1227. * Unlike the_date() this function will always return the date.
  1228. * Modify output with 'get_the_date' filter.
  1229. *
  1230. * @since 3.0.0
  1231. *
  1232. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1233. * @return string|null Null if displaying, string if retrieving.
  1234. */
  1235. function get_the_date( $d = '' ) {
  1236. global $post;
  1237. $the_date = '';
  1238. if ( '' == $d )
  1239. $the_date .= mysql2date(get_option('date_format'), $post->post_date);
  1240. else
  1241. $the_date .= mysql2date($d, $post->post_date);
  1242. return apply_filters('get_the_date', $the_date, $d);
  1243. }
  1244. /**
  1245. * Display the date on which the post was last modified.
  1246. *
  1247. * @since 2.1.0
  1248. *
  1249. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1250. * @param string $before Optional. Output before the date.
  1251. * @param string $after Optional. Output after the date.
  1252. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1253. * @return string|null Null if displaying, string if retrieving.
  1254. */
  1255. function the_modified_date($d = '', $before='', $after='', $echo = true) {
  1256. $the_modified_date = $before . get_the_modified_date($d) . $after;
  1257. $the_modified_date = apply_filters('the_modified_date', $the_modified_date, $d, $before, $after);
  1258. if ( $echo )
  1259. echo $the_modified_date;
  1260. else
  1261. return $the_modified_date;
  1262. }
  1263. /**
  1264. * Retrieve the date on which the post was last modified.
  1265. *
  1266. * @since 2.1.0
  1267. *
  1268. * @param string $d Optional. PHP date format. Defaults to the "date_format" option
  1269. * @return string
  1270. */
  1271. function get_the_modified_date($d = '') {
  1272. if ( '' == $d )
  1273. $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
  1274. else
  1275. $the_time = get_post_modified_time($d, null, null, true);
  1276. return apply_filters('get_the_modified_date', $the_time, $d);
  1277. }
  1278. /**
  1279. * Display the time at which the post was written.
  1280. *
  1281. * @since 0.71
  1282. *
  1283. * @param string $d Either 'G', 'U', or php date format.
  1284. */
  1285. function the_time( $d = '' ) {
  1286. echo apply_filters('the_time', get_the_time( $d ), $d);
  1287. }
  1288. /**
  1289. * Retrieve the time at which the post was written.
  1290. *
  1291. * @since 1.5.0
  1292. *
  1293. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1294. * @param int|object $post Optional post ID or object. Default is global $post object.
  1295. * @return string
  1296. */
  1297. function get_the_time( $d = '', $post = null ) {
  1298. $post = get_post($post);
  1299. if ( '' == $d )
  1300. $the_time = get_post_time(get_option('time_format'), false, $post, true);
  1301. else
  1302. $the_time = get_post_time($d, false, $post, true);
  1303. return apply_filters('get_the_time', $the_time, $d, $post);
  1304. }
  1305. /**
  1306. * Retrieve the time at which the post was written.
  1307. *
  1308. * @since 2.0.0
  1309. *
  1310. * @param string $d Optional Either 'G', 'U', or php date format.
  1311. * @param bool $gmt Optional, default is false. Whether to return the gmt time.
  1312. * @param int|object $post Optional post ID or object. Default is global $post object.
  1313. * @param bool $translate Whether to translate the time string
  1314. * @return string
  1315. */
  1316. function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
  1317. $post = get_post($post);
  1318. if ( $gmt )
  1319. $time = $post->post_date_gmt;
  1320. else
  1321. $time = $post->post_date;
  1322. $time = mysql2date($d, $time, $translate);
  1323. return apply_filters('get_post_time', $time, $d, $gmt);
  1324. }
  1325. /**
  1326. * Display the time at which the post was last modified.
  1327. *
  1328. * @since 2.0.0
  1329. *
  1330. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1331. */
  1332. function the_modified_time($d = '') {
  1333. echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
  1334. }
  1335. /**
  1336. * Retrieve the time at which the post was last modified.
  1337. *
  1338. * @since 2.0.0
  1339. *
  1340. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1341. * @return string
  1342. */
  1343. function get_the_modified_time($d = '') {
  1344. if ( '' == $d )
  1345. $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
  1346. else
  1347. $the_time = get_post_modified_time($d, null, null, true);
  1348. return apply_filters('get_the_modified_time', $the_time, $d);
  1349. }
  1350. /**
  1351. * Retrieve the time at which the post was last modified.
  1352. *
  1353. * @since 2.0.0
  1354. *
  1355. * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
  1356. * @param bool $gmt Optional, default is false. Whether to return the gmt time.
  1357. * @param int|object $post Optional, default is global post object. A post_id or post object
  1358. * @param bool $translate Optional, default is false. Whether to translate the result
  1359. * @return string Returns timestamp
  1360. */
  1361. function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1362. $post = get_post($post);
  1363. if ( $gmt )
  1364. $time = $post->post_modified_gmt;
  1365. else
  1366. $time = $post->post_modified;
  1367. $time = mysql2date($d, $time, $translate);
  1368. return apply_filters('get_post_modified_time', $time, $d, $gmt);
  1369. }
  1370. /**
  1371. * Display the weekday on which the post was written.
  1372. *
  1373. * @since 0.71
  1374. * @uses $wp_locale
  1375. * @uses $post
  1376. */
  1377. function the_weekday() {
  1378. global $wp_locale, $post;
  1379. $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
  1380. $the_weekday = apply_filters('the_weekday', $the_weekday);
  1381. echo $the_weekday;
  1382. }
  1383. /**
  1384. * Display the weekday on which the post was written.
  1385. *
  1386. * Will only output the weekday if the current post's weekday is different from
  1387. * the previous one output.
  1388. *
  1389. * @since 0.71
  1390. *
  1391. * @param string $before Optional Output before the date.
  1392. * @param string $after Optional Output after the date.
  1393. */
  1394. function the_weekday_date($before='',$after='') {
  1395. global $wp_locale, $post, $day, $previousweekday;
  1396. $the_weekday_date = '';
  1397. if ( $currentday != $previousweekday ) {
  1398. $the_weekday_date .= $before;
  1399. $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
  1400. $the_weekday_date .= $after;
  1401. $previousweekday = $currentday;
  1402. }
  1403. $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
  1404. echo $the_weekday_date;
  1405. }
  1406. /**
  1407. * Fire the wp_head action
  1408. *
  1409. * @since 1.2.0
  1410. * @uses do_action() Calls 'wp_head' hook.
  1411. */
  1412. function wp_head() {
  1413. do_action('wp_head');
  1414. }
  1415. /**
  1416. * Fire the wp_footer action
  1417. *
  1418. * @since 1.5.1
  1419. * @uses do_action() Calls 'wp_footer' hook.
  1420. */
  1421. function wp_footer() {
  1422. do_action('wp_footer');
  1423. }
  1424. /**
  1425. * Display the links to the general feeds.
  1426. *
  1427. * @since 2.8.0
  1428. *
  1429. * @param array $args Optional arguments.
  1430. */
  1431. function feed_links( $args = array() ) {
  1432. if ( !current_theme_supports('automatic-feed-links') )
  1433. return;
  1434. $defaults = array(
  1435. /* translators: Separator between blog name and feed type in feed links */
  1436. 'separator' => _x('&raquo;', 'feed link'),
  1437. /* translators: 1: blog title, 2: separator (raquo) */
  1438. 'feedtitle' => __('%1$s %2$s Feed'),
  1439. /* translators: %s: blog title, 2: separator (raquo) */
  1440. 'comstitle' => __('%1$s %2$s Comments Feed'),
  1441. );
  1442. $args = wp_parse_args( $args, $defaults );
  1443. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
  1444. 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";
  1445. }
  1446. /**
  1447. * Display the links to the extra feeds such as category feeds.
  1448. *
  1449. * @since 2.8.0
  1450. *
  1451. * @param array $args Optional arguments.
  1452. */
  1453. function feed_links_extra( $args = array() ) {
  1454. $defaults = array(
  1455. /* translators: Separator between blog name and feed type in feed links */
  1456. 'separator' => _x('&raquo;', 'feed link'),
  1457. /* translators: 1: blog name, 2: separator(raquo), 3: post title */
  1458. 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
  1459. /* translators: 1: blog name, 2: separator(raquo), 3: category name */
  1460. 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
  1461. /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
  1462. 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
  1463. /* translators: 1: blog name, 2: separator(raquo), 3: author name */
  1464. 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
  1465. /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
  1466. 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
  1467. );
  1468. $args = wp_parse_args( $args, $defaults );
  1469. if ( is_single() || is_page() ) {
  1470. $post = &get_post( $id = 0 );
  1471. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  1472. $title = esc_attr(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 = esc_attr(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 = esc_attr(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 = esc_attr(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 = esc_attr(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="' . $title . '" href="' . $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.
  1518. *
  1519. * @since 2.1.0
  1520. */
  1521. function noindex() {
  1522. // If the blog is not public, tell robots to go away.
  1523. if ( '0' == get_option('blog_public') )
  1524. echo "<meta name='robots' content='noindex,nofollow' />\n";
  1525. }
  1526. /**
  1527. * Determine if TinyMCE is available.
  1528. *
  1529. * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
  1530. *
  1531. * @since 2.1.0
  1532. *
  1533. * @return bool Whether TinyMCE exists.
  1534. */
  1535. function rich_edit_exists() {
  1536. global $wp_rich_edit_exists;
  1537. if ( !isset($wp_rich_edit_exists) )
  1538. $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
  1539. return $wp_rich_edit_exists;
  1540. }
  1541. /**
  1542. * Whether the user should have a WYSIWIG editor.
  1543. *
  1544. * Checks that the user requires a WYSIWIG editor and that the editor is
  1545. * supported in the users browser.
  1546. *
  1547. * @since 2.0.0
  1548. *
  1549. * @return bool
  1550. */
  1551. function user_can_richedit() {
  1552. global $wp_rich_edit, $pagenow, $is_iphone;
  1553. if ( !isset( $wp_rich_edit) ) {
  1554. if ( get_user_option( 'rich_editing' ) == 'true' &&
  1555. !$is_iphone && // this includes all Safari mobile browsers
  1556. ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
  1557. !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
  1558. && 'comment.php' != $pagenow ) {
  1559. $wp_rich_edit = true;
  1560. } else {
  1561. $wp_rich_edit = false;
  1562. }
  1563. }
  1564. return apply_filters('user_can_richedit', $wp_rich_edit);
  1565. }
  1566. /**
  1567. * Find out which editor should be displayed by default.
  1568. *
  1569. * Works out which of the two editors to display as the current editor for a
  1570. * user.
  1571. *
  1572. * @since 2.5.0
  1573. *
  1574. * @return string Either 'tinymce', or 'html', or 'test'
  1575. */
  1576. function wp_default_editor() {
  1577. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  1578. if ( $user = wp_get_current_user() ) { // look for cookie
  1579. $ed = get_user_setting('editor', 'tinymce');
  1580. $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
  1581. }
  1582. return apply_filters( 'wp_default_editor', $r ); // filter
  1583. }
  1584. /**
  1585. * Display visual editor forms: TinyMCE, or HTML, or both.
  1586. *
  1587. * The amount of rows the text area will have for the content has to be between
  1588. * 3 and 100 or will default at 12. There is only one option used for all users,
  1589. * named 'default_post_edit_rows'.
  1590. *
  1591. * If the user can not use the rich editor (TinyMCE), then the switch button
  1592. * will not be displayed.
  1593. *
  1594. * @since 2.1.0
  1595. *
  1596. * @param string $content Textarea content.
  1597. * @param string $id Optional, default is 'content'. HTML ID attribute value.
  1598. * @param string $prev_id Optional, default is 'title'. HTML ID name for switching back and forth between visual editors.
  1599. * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
  1600. * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
  1601. */
  1602. function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
  1603. $rows = get_option('default_post_edit_rows');
  1604. if (($rows < 3) || ($rows > 100))
  1605. $rows = 12;
  1606. if ( !current_user_can( 'upload_files' ) )
  1607. $media_buttons = false;
  1608. $richedit = user_can_richedit();
  1609. $class = '';
  1610. if ( $richedit || $media_buttons ) { ?>
  1611. <div id="editor-toolbar">
  1612. <?php
  1613. if ( $richedit ) {
  1614. $wp_default_editor = wp_default_editor(); ?>
  1615. <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
  1616. <?php if ( 'html' == $wp_default_editor ) {
  1617. add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
  1618. <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
  1619. <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
  1620. <?php } else {
  1621. $class = " class='theEditor'";
  1622. add_filter('the_editor_content', 'wp_richedit_pre'); ?>
  1623. <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
  1624. <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
  1625. <?php }
  1626. }
  1627. if ( $media_buttons ) { ?>
  1628. <div id="media-buttons" class="hide-if-no-js">
  1629. <?php do_action( 'media_buttons' ); ?>
  1630. </div>
  1631. <?php
  1632. } ?>
  1633. </div>
  1634. <?php
  1635. }
  1636. ?>
  1637. <div id="quicktags"><?php
  1638. wp_print_scripts( 'quicktags' ); ?>
  1639. <script type="text/javascript">edToolbar()</script>
  1640. </div>
  1641. <?php
  1642. $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
  1643. $the_editor_content = apply_filters('the_editor_content', $content);
  1644. printf($the_editor, $the_editor_content);
  1645. ?>
  1646. <script type="text/javascript">
  1647. edCanvas = document.getElementById('<?php echo $id; ?>');
  1648. </script>
  1649. <?php
  1650. }
  1651. /**
  1652. * Retrieve the contents of the search WordPress query variable.
  1653. *
  1654. * The search query string is passed through {@link esc_attr()}
  1655. * to ensure that it is safe for placing in an html attribute.
  1656. *
  1657. * @since 2.3.0
  1658. * @uses esc_attr()
  1659. *
  1660. * @param bool $escaped Whether the result is escaped. Default true.
  1661. * Only use when you are later escaping it. Do not use unescaped.
  1662. * @return string
  1663. */
  1664. function get_search_query( $escaped = true ) {
  1665. $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
  1666. if ( $escaped )
  1667. $query = esc_attr( $query );
  1668. return $query;
  1669. }
  1670. /**
  1671. * Display the contents of the search query variable.
  1672. *
  1673. * The search query string is passed through {@link esc_attr()}
  1674. * to ensure that it is safe for placing in an html attribute.
  1675. *
  1676. * @uses esc_attr()
  1677. * @since 2.1.0
  1678. */
  1679. function the_search_query() {
  1680. echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
  1681. }
  1682. /**
  1683. * Display the language attributes for the html tag.
  1684. *
  1685. * Builds up a set of html attributes containing the text direction and language
  1686. * information for the page.
  1687. *
  1688. * @since 2.1.0
  1689. *
  1690. * @param string $doctype The type of html document (xhtml|html).
  1691. */
  1692. function language_attributes($doctype = 'html') {
  1693. $attributes = array();
  1694. $output = '';
  1695. if ( function_exists( 'is_rtl' ) )
  1696. $attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"';
  1697. if ( $lang = get_bloginfo('language') ) {
  1698. if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
  1699. $attributes[] = "lang=\"$lang\"";
  1700. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
  1701. $attributes[] = "xml:lang=\"$lang\"";
  1702. }
  1703. $output = implode(' ', $attributes);
  1704. $output = apply_filters('language_attributes', $output);
  1705. echo $output;
  1706. }
  1707. /**
  1708. * Retrieve paginated link for archive post pages.
  1709. *
  1710. * Technically, the function can be used to create paginated link list for any
  1711. * area. The 'base' argument is used to reference the url, which will be used to
  1712. * create the paginated links. The 'format' argument is then used for replacing
  1713. * the page number. It is however, most likely and by default, to be used on the
  1714. * archive post pages.
  1715. *
  1716. * The 'type' argument controls format of the returned value. The default is
  1717. * 'plain', which is just a string with the links separated by a newline
  1718. * character. The other possible values are either 'array' or 'list'. The
  1719. * 'array' value will return an array of the paginated link list to offer full
  1720. * control of display. The 'list' value will place all of the paginated links in
  1721. * an unordered HTML list.
  1722. *
  1723. * The 'total' argument is the total amount of pages and is an integer. The
  1724. * 'current' argument is the current page number and is also an integer.
  1725. *
  1726. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  1727. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  1728. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  1729. * and the '%#%' is also required. The '%#%' will be replaced with the page
  1730. * number.
  1731. *
  1732. * You can include the previous and next links in the list by setting the
  1733. * 'prev_next' argument to true, which it is by default. You can set the
  1734. * previous text, by using the 'prev_text' argument. You can set the next text
  1735. * by setting the 'next_text' argument.
  1736. *
  1737. * If the 'show_all' argument is set to true, then it will show all of the pages
  1738. * instead of a short list of the pages near the current page. By default, the
  1739. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  1740. * arguments. The 'end_size' argument is how many numbers on either the start
  1741. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  1742. * numbers to either side of current page, but not including current page.
  1743. *
  1744. * It is possible to add query vars to the link by using the 'add_args' argument
  1745. * and see {@link add_query_arg()} for more information.
  1746. *
  1747. * @since 2.1.0
  1748. *
  1749. * @param string|array $args Optional. Override defaults.
  1750. * @return array|string String of page links or array of page links.
  1751. */
  1752. function paginate_links( $args = '' ) {
  1753. $defaults = array(
  1754. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  1755. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  1756. 'total' => 1,
  1757. 'current' => 0,
  1758. 'show_all' => false,
  1759. 'prev_next' => true,
  1760. 'prev_text' => __('&laquo; Previous'),
  1761. 'next_text' => __('Next &raquo;'),
  1762. 'end_size' => 1,
  1763. 'mid_size' => 2,
  1764. 'type' => 'plain',
  1765. 'add_args' => false, // array of query args to add
  1766. 'add_fragment' => ''
  1767. );
  1768. $args = wp_parse_args( $args, $defaults );
  1769. extract($args, EXTR_SKIP);
  1770. // Who knows what else people pass in $args
  1771. $total = (int) $total;
  1772. if ( $total < 2 )
  1773. return;
  1774. $current = (int) $current;
  1775. $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
  1776. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
  1777. $add_args = is_array($add_args) ? $add_args : false;
  1778. $r = '';
  1779. $page_links = array();
  1780. $n = 0;
  1781. $dots = false;
  1782. if ( $prev_next && $current && 1 < $current ) :
  1783. $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
  1784. $link = str_replace('%#%', $current - 1, $link);
  1785. if ( $add_args )
  1786. $link = add_query_arg( $add_args, $link );
  1787. $link .= $add_fragment;
  1788. $page_links[] = "<a class='prev page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$prev_text</a>";
  1789. endif;
  1790. for ( $n = 1; $n <= $total; $n++ ) :
  1791. $n_display = number_format_i18n($n);
  1792. if ( $n == $current ) :
  1793. $page_links[] = "<span class='page-numbers current'>$n_display</span>";
  1794. $dots = true;
  1795. else :
  1796. if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  1797. $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
  1798. $link = str_replace('%#%', $n, $link);
  1799. if ( $add_args )
  1800. $link = add_query_arg( $add_args, $link );
  1801. $link .= $add_fragment;
  1802. $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
  1803. $dots = true;
  1804. elseif ( $dots && !$show_all ) :
  1805. $page_links[] = "<span class='page-numbers dots'>...</span>";
  1806. $dots = false;
  1807. endif;
  1808. endif;
  1809. endfor;
  1810. if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
  1811. $link = str_replace('%_%', $format, $base);
  1812. $link = str_replace('%#%', $current + 1, $link);
  1813. if ( $add_args )
  1814. $link = add_query_arg( $add_args, $link );
  1815. $link .= $add_fragment;
  1816. $page_links[] = "<a class='next page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$next_text</a>";
  1817. endif;
  1818. switch ( $type ) :
  1819. case 'array' :
  1820. return $page_links;
  1821. break;
  1822. case 'list' :
  1823. $r .= "<ul class='page-numbers'>\n\t<li>";
  1824. $r .= join("</li>\n\t<li>", $page_links);
  1825. $r .= "</li>\n</ul>\n";
  1826. break;
  1827. default :
  1828. $r = join("\n", $page_links);
  1829. break;
  1830. endswitch;
  1831. return $r;
  1832. }
  1833. /**
  1834. * Registers an admin colour scheme css file.
  1835. *
  1836. * Allows a plugin to register a new admin colour scheme. For example:
  1837. * <code>
  1838. * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
  1839. * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  1840. * </code>
  1841. *
  1842. * @since 2.5.0
  1843. *
  1844. * @param string $key The unique key for this theme.
  1845. * @param string $name The name of the theme.
  1846. * @param string $url The url of the css file containing the colour scheme.
  1847. * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
  1848. */
  1849. function wp_admin_css_color($key, $name, $url, $colors = array()) {
  1850. global $_wp_admin_css_colors;
  1851. if ( !isset($_wp_admin_css_colors) )
  1852. $_wp_admin_css_colors = array();
  1853. $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
  1854. }
  1855. /**
  1856. * Registers the default Admin color schemes
  1857. *
  1858. * @since 3.0.0
  1859. */
  1860. function register_admin_color_schemes() {
  1861. wp_admin_css_color( 'classic', __( 'Blue' ), admin_url( 'css/colors-classic.css' ),
  1862. array( '#5589aa', '#cfdfe9', '#d1e5ee', '#eff8ff' ) );
  1863. wp_admin_css_color( 'fresh', __( 'Gray' ), admin_url( 'css/colors-fresh.css' ),
  1864. array( '#7c7976', '#c6c6c6', '#e0e0e0', '#f1f1f1' ) );
  1865. }
  1866. /**
  1867. * Display the URL of a WordPress admin CSS file.
  1868. *
  1869. * @see WP_Styles::_css_href and its style_loader_src filter.
  1870. *
  1871. * @since 2.3.0
  1872. *
  1873. * @param string $file file relative to wp-admin/ without its ".css" extension.
  1874. */
  1875. function wp_admin_css_uri( $file = 'wp-admin' ) {
  1876. if ( defined('WP_INSTALLING') ) {
  1877. $_file = "./$file.css";
  1878. } else {
  1879. $_file = admin_url("$file.css");
  1880. }
  1881. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  1882. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  1883. }
  1884. /**
  1885. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  1886. *
  1887. * "Intelligently" decides to enqueue or to print the CSS file. If the
  1888. * 'wp_print_styles' action has *not* yet been called, the CSS file will be
  1889. * enqueued. If the wp_print_styles action *has* been called, the CSS link will
  1890. * be printed. Printing may be forced by passing TRUE as the $force_echo
  1891. * (second) parameter.
  1892. *
  1893. * For backward compatibility with WordPress 2.3 calling method: If the $file
  1894. * (first) parameter does not correspond to a registered CSS file, we assume
  1895. * $file is a file relative to wp-admin/ without its ".css" extension. A
  1896. * stylesheet link to that generated URL is printed.
  1897. *
  1898. * @package WordPress
  1899. * @since 2.3.0
  1900. * @uses $wp_styles WordPress Styles Object
  1901. *
  1902. * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
  1903. * to wp-admin/. Defaults to 'wp-admin'.
  1904. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  1905. */
  1906. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  1907. global $wp_styles;
  1908. if ( !is_a($wp_styles, 'WP_Styles') )
  1909. $wp_styles = new WP_Styles();
  1910. // For backward compatibility
  1911. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  1912. if ( $wp_styles->query( $handle ) ) {
  1913. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
  1914. wp_print_styles( $handle );
  1915. else // Add to style queue
  1916. wp_enqueue_style( $handle );
  1917. return;
  1918. }
  1919. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
  1920. if ( is_rtl() )
  1921. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
  1922. }
  1923. /**
  1924. * Enqueues the default ThickBox js and css.
  1925. *
  1926. * If any of the settings need to be changed, this can be done with another js
  1927. * file similar to media-upload.js and theme-preview.js. That file should
  1928. * require array('thickbox') to ensure it is loaded after.
  1929. *
  1930. * @since 2.5.0
  1931. */
  1932. function add_thickbox() {
  1933. wp_enqueue_script( 'thickbox' );
  1934. wp_enqueue_style( 'thickbox' );
  1935. if ( is_network_admin() )
  1936. add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
  1937. }
  1938. /**
  1939. * Display the XHTML generator that is generated on the wp_head hook.
  1940. *
  1941. * @since 2.5.0
  1942. */
  1943. function wp_generator() {
  1944. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  1945. }
  1946. /**
  1947. * Display the generator XML or Comment for RSS, ATOM, etc.
  1948. *
  1949. * Returns the correct generator type for the requested output format. Allows
  1950. * for a plugin to filter generators overall the the_generator filter.
  1951. *
  1952. * @since 2.5.0
  1953. * @uses apply_filters() Calls 'the_generator' hook.
  1954. *
  1955. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  1956. */
  1957. function the_generator( $type ) {
  1958. echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
  1959. }
  1960. /**
  1961. * Creates the generator XML or Comment for RSS, ATOM, etc.
  1962. *
  1963. * Returns the correct generator type for the requested output format. Allows
  1964. * for a plugin to filter generators on an individual basis using the
  1965. * 'get_the_generator_{$type}' filter.
  1966. *
  1967. * @since 2.5.0
  1968. * @uses apply_filters() Calls 'get_the_generator_$type' hook.
  1969. *
  1970. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  1971. * @return string The HTML content for the generator.
  1972. */
  1973. function get_the_generator( $type = '' ) {
  1974. if ( empty( $type ) ) {
  1975. $current_filter = current_filter();
  1976. if ( empty( $current_filter ) )
  1977. return;
  1978. switch ( $current_filter ) {
  1979. case 'rss2_head' :
  1980. case 'commentsrss2_head' :
  1981. $type = 'rss2';
  1982. break;
  1983. case 'rss_head' :
  1984. case 'opml_head' :
  1985. $type = 'comment';
  1986. break;
  1987. case 'rdf_header' :
  1988. $type = 'rdf';
  1989. break;
  1990. case 'atom_head' :
  1991. case 'comments_atom_head' :
  1992. case 'app_head' :
  1993. $type = 'atom';
  1994. break;
  1995. }
  1996. }
  1997. switch ( $type ) {
  1998. case 'html':
  1999. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
  2000. break;
  2001. case 'xhtml':
  2002. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
  2003. break;
  2004. case 'atom':
  2005. $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
  2006. break;
  2007. case 'rss2':
  2008. $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
  2009. break;
  2010. case 'rdf':
  2011. $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
  2012. break;
  2013. case 'comment':
  2014. $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
  2015. break;
  2016. case 'export':
  2017. $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
  2018. break;
  2019. }
  2020. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  2021. }
  2022. /**
  2023. * Outputs the html checked attribute.
  2024. *
  2025. * Compares the first two arguments and if identical marks as checked
  2026. *
  2027. * @since 1.0.0
  2028. *
  2029. * @param mixed $checked One of the values to compare
  2030. * @param mixed $current (true) The other value to compare if not just true
  2031. * @param bool $echo Whether to echo or just return the string
  2032. * @return string html attribute or empty string
  2033. */
  2034. function checked( $checked, $current = true, $echo = true ) {
  2035. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  2036. }
  2037. /**
  2038. * Outputs the html selected attribute.
  2039. *
  2040. * Compares the first two arguments and if identical marks as selected
  2041. *
  2042. * @since 1.0.0
  2043. *
  2044. * @param mixed $selected One of the values to compare
  2045. * @param mixed $current (true) The other value to compare if not just true
  2046. * @param bool $echo Whether to echo or just return the string
  2047. * @return string html attribute or empty string
  2048. */
  2049. function selected( $selected, $current = true, $echo = true ) {
  2050. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  2051. }
  2052. /**
  2053. * Outputs the html disabled attribute.
  2054. *
  2055. * Compares the first two arguments and if identical marks as disabled
  2056. *
  2057. * @since 3.0.0
  2058. *
  2059. * @param mixed $disabled One of the values to compare
  2060. * @param mixed $current (true) The other value to compare if not just true
  2061. * @param bool $echo Whether to echo or just return the string
  2062. * @return string html attribute or empty string
  2063. */
  2064. function disabled( $disabled, $current = true, $echo = true ) {
  2065. return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  2066. }
  2067. /**
  2068. * Private helper function for checked, selected, and disabled.
  2069. *
  2070. * Compares the first two arguments and if identical marks as $type
  2071. *
  2072. * @since 2.8.0
  2073. * @access private
  2074. *
  2075. * @param any $helper One of the values to compare
  2076. * @param any $current (true) The other value to compare if not just true
  2077. * @param bool $echo Whether to echo or just return the string
  2078. * @param string $type The type of checked|selected|disabled we are doing
  2079. * @return string html attribute or empty string
  2080. */
  2081. function __checked_selected_helper( $helper, $current, $echo, $type ) {
  2082. if ( (string) $helper === (string) $current )
  2083. $result = " $type='$type'";
  2084. else
  2085. $result = '';
  2086. if ( $echo )
  2087. echo $result;
  2088. return $result;
  2089. }
  2090. ?>