PageRenderTime 32ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

https://github.com/schr/wordpress
PHP | 1995 lines | 1388 code | 129 blank | 478 comment | 157 complexity | adbf6872651dd25d8bdfab6dd7de577f 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. If the theme contains no header.php file
  13. * then the header from the default theme will be included.
  14. *
  15. * For the parameter, if the file is called "header-special.php" then specify
  16. * "special".
  17. *
  18. * @uses locate_template()
  19. * @since 1.5.0
  20. * @uses do_action() Calls 'get_header' action.
  21. *
  22. * @param string $name The name of the specialised header.
  23. */
  24. function get_header( $name = null ) {
  25. do_action( 'get_header' );
  26. $templates = array();
  27. if ( isset($name) )
  28. $templates[] = "header-{$name}.php";
  29. $templates[] = "header.php";
  30. if ('' == locate_template($templates, true))
  31. load_template( get_theme_root() . '/default/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. If the theme contains no footer.php file
  38. * then the footer from the default theme will be included.
  39. *
  40. * For the parameter, if the file is called "footer-special.php" then specify
  41. * "special".
  42. *
  43. * @uses locate_template()
  44. * @since 1.5.0
  45. * @uses do_action() Calls 'get_footer' action.
  46. *
  47. * @param string $name The name of the specialised footer.
  48. */
  49. function get_footer( $name = null ) {
  50. do_action( 'get_footer' );
  51. $templates = array();
  52. if ( isset($name) )
  53. $templates[] = "footer-{$name}.php";
  54. $templates[] = "footer.php";
  55. if ('' == locate_template($templates, true))
  56. load_template( get_theme_root() . '/default/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. If the theme contains no sidebar.php
  63. * file then the sidebar from the default theme will be included.
  64. *
  65. * For the parameter, if the file is called "sidebar-special.php" then specify
  66. * "special".
  67. *
  68. * @uses locate_template()
  69. * @since 1.5.0
  70. * @uses do_action() Calls 'get_sidebar' action.
  71. *
  72. * @param string $name The name of the specialised sidebar.
  73. */
  74. function get_sidebar( $name = null ) {
  75. do_action( 'get_sidebar' );
  76. $templates = array();
  77. if ( isset($name) )
  78. $templates[] = "sidebar-{$name}.php";
  79. $templates[] = "sidebar.php";
  80. if ('' == locate_template($templates, true))
  81. load_template( get_theme_root() . '/default/sidebar.php');
  82. }
  83. /**
  84. * Display search form.
  85. *
  86. * Will first attempt to locate the searchform.php file in either the child or
  87. * the parent, then load it. If it doesn't exist, then the default search form
  88. * will be displayed. The default search form is HTML, which will be displayed.
  89. * There is a filter applied to the search form HTML in order to edit or replace
  90. * it. The filter is 'get_search_form'.
  91. *
  92. * This function is primarily used by themes which want to hardcode the search
  93. * form into the sidebar and also by the search widget in WordPress.
  94. *
  95. * There is also an action that is called whenever the function is run called,
  96. * 'get_search_form'. This can be useful for outputting JavaScript that the
  97. * search relies on or various formatting that applies to the beginning of the
  98. * search. To give a few examples of what it can be used for.
  99. *
  100. * @since 2.7.0
  101. */
  102. function get_search_form() {
  103. do_action( 'get_search_form' );
  104. if ( '' != locate_template(array('searchform.php'), true) )
  105. return;
  106. $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
  107. <div><label class="hidden" for="s">' . __('Search for:') . '</label>
  108. <input type="text" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
  109. <input type="submit" id="searchsubmit" value="'.attribute_escape(__('Search')).'" />
  110. </div>
  111. </form>';
  112. echo apply_filters('get_search_form', $form);
  113. }
  114. /**
  115. * Display the Log In/Out link.
  116. *
  117. * Displays a link, which allows the user to navigate to the Log In page to log in
  118. * or log out depending on whether or not they are currently logged in.
  119. *
  120. * @since 1.5.0
  121. * @uses apply_filters() Calls 'loginout' hook on HTML link content.
  122. */
  123. function wp_loginout() {
  124. if ( ! is_user_logged_in() )
  125. $link = '<a href="' . wp_login_url() . '">' . __('Log in') . '</a>';
  126. else
  127. $link = '<a href="' . wp_logout_url() . '">' . __('Log out') . '</a>';
  128. echo apply_filters('loginout', $link);
  129. }
  130. /**
  131. * Returns the Log Out URL.
  132. *
  133. * Returns the URL that allows the user to log out of the site
  134. *
  135. * @since 2.7
  136. * @uses wp_nonce_url() To protect against CSRF
  137. * @uses site_url() To generate the log in URL
  138. *
  139. * @param string $redirect Path to redirect to on logout.
  140. */
  141. function wp_logout_url($redirect = '') {
  142. if ( strlen($redirect) )
  143. $redirect = "&redirect_to=$redirect";
  144. return wp_nonce_url( site_url("wp-login.php?action=logout$redirect", 'login'), 'log-out' );
  145. }
  146. /**
  147. * Returns the Log In URL.
  148. *
  149. * Returns the URL that allows the user to log in to the site
  150. *
  151. * @since 2.7
  152. * @uses site_url() To generate the log in URL
  153. *
  154. * @param string $redirect Path to redirect to on login.
  155. */
  156. function wp_login_url($redirect = '') {
  157. if ( strlen($redirect) )
  158. $redirect = "?redirect_to=$redirect";
  159. return site_url("wp-login.php$redirect", 'login');
  160. }
  161. /**
  162. * Display the Registration or Admin link.
  163. *
  164. * Display a link which allows the user to navigate to the registration page if
  165. * not logged in and registration is enabled or to the dashboard if logged in.
  166. *
  167. * @since 1.5.0
  168. * @uses apply_filters() Calls 'register' hook on register / admin link content.
  169. *
  170. * @param string $before Text to output before the link (defaults to <li>).
  171. * @param string $after Text to output after the link (defaults to </li>).
  172. */
  173. function wp_register( $before = '<li>', $after = '</li>' ) {
  174. if ( ! is_user_logged_in() ) {
  175. if ( get_option('users_can_register') )
  176. $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
  177. else
  178. $link = '';
  179. } else {
  180. $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
  181. }
  182. echo apply_filters('register', $link);
  183. }
  184. /**
  185. * Theme container function for the 'wp_meta' action.
  186. *
  187. * The 'wp_meta' action can have several purposes, depending on how you use it,
  188. * but one purpose might have been to allow for theme switching.
  189. *
  190. * @since 1.5.0
  191. * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
  192. * @uses do_action() Calls 'wp_meta' hook.
  193. */
  194. function wp_meta() {
  195. do_action('wp_meta');
  196. }
  197. /**
  198. * Display information about the blog.
  199. *
  200. * @see get_bloginfo() For possible values for the parameter.
  201. * @since 0.71
  202. *
  203. * @param string $show What to display.
  204. */
  205. function bloginfo($show='') {
  206. echo get_bloginfo($show, 'display');
  207. }
  208. /**
  209. * Retrieve information about the blog.
  210. *
  211. * Some show parameter values are deprecated and will be removed in future
  212. * versions. Care should be taken to check the function contents and know what
  213. * the deprecated blog info options are. Options without "// DEPRECATED" are
  214. * the preferred and recommended ways to get the information.
  215. *
  216. * The possible values for the 'show' parameter are listed below.
  217. * <ol>
  218. * <li><strong>url<strong> - Blog URI to homepage.</li>
  219. * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
  220. * <li><strong>description</strong> - Secondary title</li>
  221. * </ol>
  222. *
  223. * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
  224. * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
  225. * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
  226. * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
  227. *
  228. * There are many other options and you should check the function contents:
  229. * {@source 32 37}
  230. *
  231. * @since 0.71
  232. *
  233. * @param string $show Blog info to retrieve.
  234. * @param string $filter How to filter what is retrieved.
  235. * @return string Mostly string values, might be empty.
  236. */
  237. function get_bloginfo($show = '', $filter = 'raw') {
  238. switch($show) {
  239. case 'url' :
  240. case 'home' : // DEPRECATED
  241. case 'siteurl' : // DEPRECATED
  242. $output = get_option('home');
  243. break;
  244. case 'wpurl' :
  245. $output = get_option('siteurl');
  246. break;
  247. case 'description':
  248. $output = get_option('blogdescription');
  249. break;
  250. case 'rdf_url':
  251. $output = get_feed_link('rdf');
  252. break;
  253. case 'rss_url':
  254. $output = get_feed_link('rss');
  255. break;
  256. case 'rss2_url':
  257. $output = get_feed_link('rss2');
  258. break;
  259. case 'atom_url':
  260. $output = get_feed_link('atom');
  261. break;
  262. case 'comments_atom_url':
  263. $output = get_feed_link('comments_atom');
  264. break;
  265. case 'comments_rss2_url':
  266. $output = get_feed_link('comments_rss2');
  267. break;
  268. case 'pingback_url':
  269. $output = get_option('siteurl') .'/xmlrpc.php';
  270. break;
  271. case 'stylesheet_url':
  272. $output = get_stylesheet_uri();
  273. break;
  274. case 'stylesheet_directory':
  275. $output = get_stylesheet_directory_uri();
  276. break;
  277. case 'template_directory':
  278. case 'template_url':
  279. $output = get_template_directory_uri();
  280. break;
  281. case 'admin_email':
  282. $output = get_option('admin_email');
  283. break;
  284. case 'charset':
  285. $output = get_option('blog_charset');
  286. if ('' == $output) $output = 'UTF-8';
  287. break;
  288. case 'html_type' :
  289. $output = get_option('html_type');
  290. break;
  291. case 'version':
  292. global $wp_version;
  293. $output = $wp_version;
  294. break;
  295. case 'language':
  296. $output = get_locale();
  297. $output = str_replace('_', '-', $output);
  298. break;
  299. case 'text_direction':
  300. global $wp_locale;
  301. $output = $wp_locale->text_direction;
  302. break;
  303. case 'name':
  304. default:
  305. $output = get_option('blogname');
  306. break;
  307. }
  308. $url = true;
  309. if (strpos($show, 'url') === false &&
  310. strpos($show, 'directory') === false &&
  311. strpos($show, 'home') === false)
  312. $url = false;
  313. if ( 'display' == $filter ) {
  314. if ( $url )
  315. $output = apply_filters('bloginfo_url', $output, $show);
  316. else
  317. $output = apply_filters('bloginfo', $output, $show);
  318. }
  319. return $output;
  320. }
  321. /**
  322. * Display or retrieve page title for all areas of blog.
  323. *
  324. * By default, the page title will display the separator before the page title,
  325. * so that the blog title will be before the page title. This is not good for
  326. * title display, since the blog title shows up on most tabs and not what is
  327. * important, which is the page that the user is looking at.
  328. *
  329. * There are also SEO benefits to having the blog title after or to the 'right'
  330. * or the page title. However, it is mostly common sense to have the blog title
  331. * to the right with most browsers supporting tabs. You can achieve this by
  332. * using the seplocation parameter and setting the value to 'right'. This change
  333. * was introduced around 2.5.0, in case backwards compatibility of themes is
  334. * important.
  335. *
  336. * @since 1.0.0
  337. *
  338. * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
  339. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  340. * @param string $seplocation Optional. Direction to display title, 'right'.
  341. * @return string|null String on retrieve, null when displaying.
  342. */
  343. function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
  344. global $wpdb, $wp_locale, $wp_query;
  345. $cat = get_query_var('cat');
  346. $tag = get_query_var('tag_id');
  347. $category_name = get_query_var('category_name');
  348. $author = get_query_var('author');
  349. $author_name = get_query_var('author_name');
  350. $m = get_query_var('m');
  351. $year = get_query_var('year');
  352. $monthnum = get_query_var('monthnum');
  353. $day = get_query_var('day');
  354. $search = get_query_var('s');
  355. $title = '';
  356. $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  357. // If there's a category
  358. if ( !empty($cat) ) {
  359. // category exclusion
  360. if ( !stristr($cat,'-') )
  361. $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
  362. } elseif ( !empty($category_name) ) {
  363. if ( stristr($category_name,'/') ) {
  364. $category_name = explode('/',$category_name);
  365. if ( $category_name[count($category_name)-1] )
  366. $category_name = $category_name[count($category_name)-1]; // no trailing slash
  367. else
  368. $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
  369. }
  370. $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
  371. if ( $cat )
  372. $title = apply_filters('single_cat_title', $cat->name);
  373. }
  374. if ( !empty($tag) ) {
  375. $tag = get_term($tag, 'post_tag', OBJECT, 'display');
  376. if ( is_wp_error( $tag ) )
  377. return $tag;
  378. if ( ! empty($tag->name) )
  379. $title = apply_filters('single_tag_title', $tag->name);
  380. }
  381. // If there's an author
  382. if ( !empty($author) ) {
  383. $title = get_userdata($author);
  384. $title = $title->display_name;
  385. }
  386. if ( !empty($author_name) ) {
  387. // We do a direct query here because we don't cache by nicename.
  388. $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
  389. }
  390. // If there's a month
  391. if ( !empty($m) ) {
  392. $my_year = substr($m, 0, 4);
  393. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  394. $my_day = intval(substr($m, 6, 2));
  395. $title = "$my_year" . ($my_month ? "$t_sep$my_month" : "") . ($my_day ? "$t_sep$my_day" : "");
  396. }
  397. if ( !empty($year) ) {
  398. $title = $year;
  399. if ( !empty($monthnum) )
  400. $title .= "$t_sep" . $wp_locale->get_month($monthnum);
  401. if ( !empty($day) )
  402. $title .= "$t_sep" . zeroise($day, 2);
  403. }
  404. // If there is a post
  405. if ( is_single() || ( is_page() && !is_front_page() ) ) {
  406. $post = $wp_query->get_queried_object();
  407. $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
  408. }
  409. // If there's a taxonomy
  410. if ( is_tax() ) {
  411. $taxonomy = get_query_var( 'taxonomy' );
  412. $tax = get_taxonomy( $taxonomy );
  413. $tax = $tax->label;
  414. $term = $wp_query->get_queried_object();
  415. $term = $term->name;
  416. $title = "$tax$t_sep$term";
  417. }
  418. //If it's a search
  419. if ( is_search() ) {
  420. $title = sprintf(__('Search Results %s %s'), $t_sep, strip_tags($search));
  421. }
  422. if ( is_404() ) {
  423. $title = __('Page not found');
  424. }
  425. $prefix = '';
  426. if ( !empty($title) )
  427. $prefix = " $sep ";
  428. // Determines position of the separator and direction of the breadcrumb
  429. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  430. $title_array = explode( $t_sep, $title );
  431. $title_array = array_reverse( $title_array );
  432. $title = implode( " $sep ", $title_array ) . $prefix;
  433. } else {
  434. $title_array = explode( $t_sep, $title );
  435. $title = $prefix . implode( " $sep ", $title_array );
  436. }
  437. $title = apply_filters('wp_title', $title, $sep, $seplocation);
  438. // Send it out
  439. if ( $display )
  440. echo $title;
  441. else
  442. return $title;
  443. }
  444. /**
  445. * Display or retrieve page title for post.
  446. *
  447. * This is optimized for single.php template file for displaying the post title.
  448. * Only useful for posts, does not support pages for example.
  449. *
  450. * It does not support placing the separator after the title, but by leaving the
  451. * prefix parameter empty, you can set the title separator manually. The prefix
  452. * does not automatically place a space between the prefix, so if there should
  453. * be a space, the parameter value will need to have it at the end.
  454. *
  455. * @since 0.71
  456. * @uses $wpdb
  457. *
  458. * @param string $prefix Optional. What to display before the title.
  459. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  460. * @return string|null Title when retrieving, null when displaying or failure.
  461. */
  462. function single_post_title($prefix = '', $display = true) {
  463. global $wpdb;
  464. $p = get_query_var('p');
  465. $name = get_query_var('name');
  466. if ( intval($p) || '' != $name ) {
  467. if ( !$p )
  468. $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
  469. $post = & get_post($p);
  470. $title = $post->post_title;
  471. $title = apply_filters('single_post_title', $title);
  472. if ( $display )
  473. echo $prefix.strip_tags($title);
  474. else
  475. return strip_tags($title);
  476. }
  477. }
  478. /**
  479. * Display or retrieve page title for category archive.
  480. *
  481. * This is useful for category template file or files, because it is optimized
  482. * for category page title and with less overhead than {@link wp_title()}.
  483. *
  484. * It does not support placing the separator after the title, but by leaving the
  485. * prefix parameter empty, you can set the title separator manually. The prefix
  486. * does not automatically place a space between the prefix, so if there should
  487. * be a space, the parameter value will need to have it at the end.
  488. *
  489. * @since 0.71
  490. *
  491. * @param string $prefix Optional. What to display before the title.
  492. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  493. * @return string|null Title when retrieving, null when displaying or failure.
  494. */
  495. function single_cat_title($prefix = '', $display = true ) {
  496. $cat = intval( get_query_var('cat') );
  497. if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
  498. $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
  499. if ( !empty($my_cat_name) ) {
  500. if ( $display )
  501. echo $prefix.strip_tags($my_cat_name);
  502. else
  503. return strip_tags($my_cat_name);
  504. }
  505. } else if ( is_tag() ) {
  506. return single_tag_title($prefix, $display);
  507. }
  508. }
  509. /**
  510. * Display or retrieve page title for tag post archive.
  511. *
  512. * Useful for tag template files for displaying the tag page title. It has less
  513. * overhead than {@link wp_title()}, because of its limited implementation.
  514. *
  515. * It does not support placing the separator after the title, but by leaving the
  516. * prefix parameter empty, you can set the title separator manually. The prefix
  517. * does not automatically place a space between the prefix, so if there should
  518. * be a space, the parameter value will need to have it at the end.
  519. *
  520. * @since 2.3.0
  521. *
  522. * @param string $prefix Optional. What to display before the title.
  523. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  524. * @return string|null Title when retrieving, null when displaying or failure.
  525. */
  526. function single_tag_title($prefix = '', $display = true ) {
  527. if ( !is_tag() )
  528. return;
  529. $tag_id = intval( get_query_var('tag_id') );
  530. if ( !empty($tag_id) ) {
  531. $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display');
  532. if ( is_wp_error( $my_tag ) )
  533. return false;
  534. $my_tag_name = apply_filters('single_tag_title', $my_tag->name);
  535. if ( !empty($my_tag_name) ) {
  536. if ( $display )
  537. echo $prefix . $my_tag_name;
  538. else
  539. return $my_tag_name;
  540. }
  541. }
  542. }
  543. /**
  544. * Display or retrieve page title for post archive based on date.
  545. *
  546. * Useful for when the template only needs to display the month and year, if
  547. * either are available. Optimized for just this purpose, so if it is all that
  548. * is needed, should be better than {@link wp_title()}.
  549. *
  550. * It does not support placing the separator after the title, but by leaving the
  551. * prefix parameter empty, you can set the title separator manually. The prefix
  552. * does not automatically place a space between the prefix, so if there should
  553. * be a space, the parameter value will need to have it at the end.
  554. *
  555. * @since 0.71
  556. *
  557. * @param string $prefix Optional. What to display before the title.
  558. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  559. * @return string|null Title when retrieving, null when displaying or failure.
  560. */
  561. function single_month_title($prefix = '', $display = true ) {
  562. global $wp_locale;
  563. $m = get_query_var('m');
  564. $year = get_query_var('year');
  565. $monthnum = get_query_var('monthnum');
  566. if ( !empty($monthnum) && !empty($year) ) {
  567. $my_year = $year;
  568. $my_month = $wp_locale->get_month($monthnum);
  569. } elseif ( !empty($m) ) {
  570. $my_year = substr($m, 0, 4);
  571. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  572. }
  573. if ( empty($my_month) )
  574. return false;
  575. $result = $prefix . $my_month . $prefix . $my_year;
  576. if ( !$display )
  577. return $result;
  578. echo $result;
  579. }
  580. /**
  581. * Retrieve archive link content based on predefined or custom code.
  582. *
  583. * The format can be one of four styles. The 'link' for head element, 'option'
  584. * for use in the select element, 'html' for use in list (either ol or ul HTML
  585. * elements). Custom content is also supported using the before and after
  586. * parameters.
  587. *
  588. * The 'link' format uses the link HTML element with the <em>archives</em>
  589. * relationship. The before and after parameters are not used. The text
  590. * parameter is used to describe the link.
  591. *
  592. * The 'option' format uses the option HTML element for use in select element.
  593. * The value is the url parameter and the before and after parameters are used
  594. * between the text description.
  595. *
  596. * The 'html' format, which is the default, uses the li HTML element for use in
  597. * the list HTML elements. The before parameter is before the link and the after
  598. * parameter is after the closing link.
  599. *
  600. * The custom format uses the before parameter before the link ('a' HTML
  601. * element) and the after parameter after the closing link tag. If the above
  602. * three values for the format are not used, then custom format is assumed.
  603. *
  604. * @since 1.0.0
  605. * @author Orien
  606. * @link http://icecode.com/ link navigation hack by Orien
  607. *
  608. * @param string $url URL to archive.
  609. * @param string $text Archive text description.
  610. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  611. * @param string $before Optional.
  612. * @param string $after Optional.
  613. * @return string HTML link content for archive.
  614. */
  615. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
  616. $text = wptexturize($text);
  617. $title_text = attribute_escape($text);
  618. $url = clean_url($url);
  619. if ('link' == $format)
  620. $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
  621. elseif ('option' == $format)
  622. $link_html = "\t<option value='$url'>$before $text $after</option>\n";
  623. elseif ('html' == $format)
  624. $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
  625. else // custom
  626. $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
  627. $link_html = apply_filters( "get_archives_link", $link_html );
  628. return $link_html;
  629. }
  630. /**
  631. * Display archive links based on type and format.
  632. *
  633. * The 'type' argument offers a few choices and by default will display monthly
  634. * archive links. The other options for values are 'daily', 'weekly', 'monthly',
  635. * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
  636. * same archive link list, the difference between the two is that 'alpha'
  637. * will order by post title and 'postbypost' will order by post date.
  638. *
  639. * The date archives will logically display dates with links to the archive post
  640. * page. The 'postbypost' and 'alpha' values for 'type' argument will display
  641. * the post titles.
  642. *
  643. * The 'limit' argument will only display a limited amount of links, specified
  644. * by the 'limit' integer value. By default, there is no limit. The
  645. * 'show_post_count' argument will show how many posts are within the archive.
  646. * By default, the 'show_post_count' argument is set to false.
  647. *
  648. * For the 'format', 'before', and 'after' arguments, see {@link
  649. * get_archives_link()}. The values of these arguments have to do with that
  650. * function.
  651. *
  652. * @since 1.2.0
  653. *
  654. * @param string|array $args Optional. Override defaults.
  655. */
  656. function wp_get_archives($args = '') {
  657. global $wpdb, $wp_locale;
  658. $defaults = array(
  659. 'type' => 'monthly', 'limit' => '',
  660. 'format' => 'html', 'before' => '',
  661. 'after' => '', 'show_post_count' => false,
  662. 'echo' => 1
  663. );
  664. $r = wp_parse_args( $args, $defaults );
  665. extract( $r, EXTR_SKIP );
  666. if ( '' == $type )
  667. $type = 'monthly';
  668. if ( '' != $limit ) {
  669. $limit = absint($limit);
  670. $limit = ' LIMIT '.$limit;
  671. }
  672. // this is what will separate dates on weekly archive links
  673. $archive_week_separator = '&#8211;';
  674. // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
  675. $archive_date_format_over_ride = 0;
  676. // options for daily archive (only if you over-ride the general date format)
  677. $archive_day_date_format = 'Y/m/d';
  678. // options for weekly archive (only if you over-ride the general date format)
  679. $archive_week_start_date_format = 'Y/m/d';
  680. $archive_week_end_date_format = 'Y/m/d';
  681. if ( !$archive_date_format_over_ride ) {
  682. $archive_day_date_format = get_option('date_format');
  683. $archive_week_start_date_format = get_option('date_format');
  684. $archive_week_end_date_format = get_option('date_format');
  685. }
  686. //filters
  687. $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
  688. $join = apply_filters('getarchives_join', "", $r);
  689. $output = '';
  690. if ( 'monthly' == $type ) {
  691. $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";
  692. $key = md5($query);
  693. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  694. if ( !isset( $cache[ $key ] ) ) {
  695. $arcresults = $wpdb->get_results($query);
  696. $cache[ $key ] = $arcresults;
  697. wp_cache_add( 'wp_get_archives', $cache, 'general' );
  698. } else {
  699. $arcresults = $cache[ $key ];
  700. }
  701. if ( $arcresults ) {
  702. $afterafter = $after;
  703. foreach ( (array) $arcresults as $arcresult ) {
  704. $url = get_month_link( $arcresult->year, $arcresult->month );
  705. $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
  706. if ( $show_post_count )
  707. $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
  708. $output .= get_archives_link($url, $text, $format, $before, $after);
  709. }
  710. }
  711. } elseif ('yearly' == $type) {
  712. $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";
  713. $key = md5($query);
  714. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  715. if ( !isset( $cache[ $key ] ) ) {
  716. $arcresults = $wpdb->get_results($query);
  717. $cache[ $key ] = $arcresults;
  718. wp_cache_add( 'wp_get_archives', $cache, 'general' );
  719. } else {
  720. $arcresults = $cache[ $key ];
  721. }
  722. if ($arcresults) {
  723. $afterafter = $after;
  724. foreach ( (array) $arcresults as $arcresult) {
  725. $url = get_year_link($arcresult->year);
  726. $text = sprintf('%d', $arcresult->year);
  727. if ($show_post_count)
  728. $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
  729. $output .= get_archives_link($url, $text, $format, $before, $after);
  730. }
  731. }
  732. } elseif ( 'daily' == $type ) {
  733. $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";
  734. $key = md5($query);
  735. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  736. if ( !isset( $cache[ $key ] ) ) {
  737. $arcresults = $wpdb->get_results($query);
  738. $cache[ $key ] = $arcresults;
  739. wp_cache_add( 'wp_get_archives', $cache, 'general' );
  740. } else {
  741. $arcresults = $cache[ $key ];
  742. }
  743. if ( $arcresults ) {
  744. $afterafter = $after;
  745. foreach ( (array) $arcresults as $arcresult ) {
  746. $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
  747. $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
  748. $text = mysql2date($archive_day_date_format, $date);
  749. if ($show_post_count)
  750. $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
  751. $output .= get_archives_link($url, $text, $format, $before, $after);
  752. }
  753. }
  754. } elseif ( 'weekly' == $type ) {
  755. $start_of_week = get_option('start_of_week');
  756. $query = "SELECT DISTINCT WEEK(post_date, $start_of_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(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit";
  757. $key = md5($query);
  758. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  759. if ( !isset( $cache[ $key ] ) ) {
  760. $arcresults = $wpdb->get_results($query);
  761. $cache[ $key ] = $arcresults;
  762. wp_cache_add( 'wp_get_archives', $cache, 'general' );
  763. } else {
  764. $arcresults = $cache[ $key ];
  765. }
  766. $arc_w_last = '';
  767. $afterafter = $after;
  768. if ( $arcresults ) {
  769. foreach ( (array) $arcresults as $arcresult ) {
  770. if ( $arcresult->week != $arc_w_last ) {
  771. $arc_year = $arcresult->yr;
  772. $arc_w_last = $arcresult->week;
  773. $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
  774. $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
  775. $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
  776. $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
  777. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  778. if ($show_post_count)
  779. $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
  780. $output .= get_archives_link($url, $text, $format, $before, $after);
  781. }
  782. }
  783. }
  784. } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
  785. $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
  786. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  787. $key = md5($query);
  788. $cache = wp_cache_get( 'wp_get_archives' , 'general');
  789. if ( !isset( $cache[ $key ] ) ) {
  790. $arcresults = $wpdb->get_results($query);
  791. $cache[ $key ] = $arcresults;
  792. wp_cache_add( 'wp_get_archives', $cache, 'general' );
  793. } else {
  794. $arcresults = $cache[ $key ];
  795. }
  796. if ( $arcresults ) {
  797. foreach ( (array) $arcresults as $arcresult ) {
  798. if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
  799. $url = get_permalink($arcresult);
  800. $arc_title = $arcresult->post_title;
  801. if ( $arc_title )
  802. $text = strip_tags(apply_filters('the_title', $arc_title));
  803. else
  804. $text = $arcresult->ID;
  805. $output .= get_archives_link($url, $text, $format, $before, $after);
  806. }
  807. }
  808. }
  809. }
  810. if ( $echo )
  811. echo $output;
  812. else
  813. return $output;
  814. }
  815. /**
  816. * Get number of days since the start of the week.
  817. *
  818. * @since 1.5.0
  819. * @usedby get_calendar()
  820. *
  821. * @param int $num Number of day.
  822. * @return int Days since the start of the week.
  823. */
  824. function calendar_week_mod($num) {
  825. $base = 7;
  826. return ($num - $base*floor($num/$base));
  827. }
  828. /**
  829. * Display calendar with days that have posts as links.
  830. *
  831. * The calendar is cached, which will be retrieved, if it exists. If there are
  832. * no posts for the month, then it will not be displayed.
  833. *
  834. * @since 1.0.0
  835. *
  836. * @param bool $initial Optional, default is true. Use initial calendar names.
  837. */
  838. function get_calendar($initial = true) {
  839. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  840. $cache = array();
  841. $key = md5( $m . $monthnum . $year );
  842. if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
  843. if ( is_array($cache) && isset( $cache[ $key ] ) ) {
  844. echo $cache[ $key ];
  845. return;
  846. }
  847. }
  848. if ( !is_array($cache) )
  849. $cache = array();
  850. // Quick check. If we have no posts at all, abort!
  851. if ( !$posts ) {
  852. $gotsome = $wpdb->get_var("SELECT 1 FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  853. if ( !$gotsome ) {
  854. $cache[ $key ] = '';
  855. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  856. return;
  857. }
  858. }
  859. ob_start();
  860. if ( isset($_GET['w']) )
  861. $w = ''.intval($_GET['w']);
  862. // week_begins = 0 stands for Sunday
  863. $week_begins = intval(get_option('start_of_week'));
  864. // Let's figure out when we are
  865. if ( !empty($monthnum) && !empty($year) ) {
  866. $thismonth = ''.zeroise(intval($monthnum), 2);
  867. $thisyear = ''.intval($year);
  868. } elseif ( !empty($w) ) {
  869. // We need to get the month from MySQL
  870. $thisyear = ''.intval(substr($m, 0, 4));
  871. $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
  872. $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
  873. } elseif ( !empty($m) ) {
  874. $thisyear = ''.intval(substr($m, 0, 4));
  875. if ( strlen($m) < 6 )
  876. $thismonth = '01';
  877. else
  878. $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
  879. } else {
  880. $thisyear = gmdate('Y', current_time('timestamp'));
  881. $thismonth = gmdate('m', current_time('timestamp'));
  882. }
  883. $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
  884. // Get the next and previous month and year with at least one post
  885. $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
  886. FROM $wpdb->posts
  887. WHERE post_date < '$thisyear-$thismonth-01'
  888. AND post_type = 'post' AND post_status = 'publish'
  889. ORDER BY post_date DESC
  890. LIMIT 1");
  891. $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
  892. FROM $wpdb->posts
  893. WHERE post_date > '$thisyear-$thismonth-01'
  894. AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
  895. AND post_type = 'post' AND post_status = 'publish'
  896. ORDER BY post_date ASC
  897. LIMIT 1");
  898. echo '<table id="wp-calendar" summary="' . __('Calendar') . '">
  899. <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
  900. <thead>
  901. <tr>';
  902. $myweek = array();
  903. for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
  904. $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
  905. }
  906. foreach ( $myweek as $wd ) {
  907. $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
  908. echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
  909. }
  910. echo '
  911. </tr>
  912. </thead>
  913. <tfoot>
  914. <tr>';
  915. if ( $previous ) {
  916. echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
  917. get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
  918. 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>';
  919. } else {
  920. echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
  921. }
  922. echo "\n\t\t".'<td class="pad">&nbsp;</td>';
  923. if ( $next ) {
  924. echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
  925. get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
  926. 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>';
  927. } else {
  928. echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
  929. }
  930. echo '
  931. </tr>
  932. </tfoot>
  933. <tbody>
  934. <tr>';
  935. // Get days with posts
  936. $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
  937. FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
  938. AND YEAR(post_date) = '$thisyear'
  939. AND post_type = 'post' AND post_status = 'publish'
  940. AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
  941. if ( $dayswithposts ) {
  942. foreach ( (array) $dayswithposts as $daywith ) {
  943. $daywithpost[] = $daywith[0];
  944. }
  945. } else {
  946. $daywithpost = array();
  947. }
  948. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false)
  949. $ak_title_separator = "\n";
  950. else
  951. $ak_title_separator = ', ';
  952. $ak_titles_for_day = array();
  953. $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
  954. ."FROM $wpdb->posts "
  955. ."WHERE YEAR(post_date) = '$thisyear' "
  956. ."AND MONTH(post_date) = '$thismonth' "
  957. ."AND post_date < '".current_time('mysql')."' "
  958. ."AND post_type = 'post' AND post_status = 'publish'"
  959. );
  960. if ( $ak_post_titles ) {
  961. foreach ( (array) $ak_post_titles as $ak_post_title ) {
  962. $post_title = apply_filters( "the_title", $ak_post_title->post_title );
  963. $post_title = str_replace('"', '&quot;', wptexturize( $post_title ));
  964. if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
  965. $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
  966. if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
  967. $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
  968. else
  969. $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
  970. }
  971. }
  972. // See how much we should pad in the beginning
  973. $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
  974. if ( 0 != $pad )
  975. echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
  976. $daysinmonth = intval(date('t', $unixmonth));
  977. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  978. if ( isset($newrow) && $newrow )
  979. echo "\n\t</tr>\n\t<tr>\n\t\t";
  980. $newrow = false;
  981. if ( $day == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)) )
  982. echo '<td id="today">';
  983. else
  984. echo '<td>';
  985. if ( in_array($day, $daywithpost) ) // any posts today?
  986. echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
  987. else
  988. echo $day;
  989. echo '</td>';
  990. if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
  991. $newrow = true;
  992. }
  993. $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
  994. if ( $pad != 0 && $pad != 7 )
  995. echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
  996. echo "\n\t</tr>\n\t</tbody>\n\t</table>";
  997. $output = ob_get_contents();
  998. ob_end_clean();
  999. echo $output;
  1000. $cache[ $key ] = $output;
  1001. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1002. }
  1003. /**
  1004. * Purge the cached results of get_calendar.
  1005. *
  1006. * @see get_calendar
  1007. * @since 2.1.0
  1008. */
  1009. function delete_get_calendar_cache() {
  1010. wp_cache_delete( 'get_calendar', 'calendar' );
  1011. }
  1012. add_action( 'save_post', 'delete_get_calendar_cache' );
  1013. add_action( 'delete_post', 'delete_get_calendar_cache' );
  1014. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1015. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  1016. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1017. /**
  1018. * Display all of the allowed tags in HTML format with attributes.
  1019. *
  1020. * This is useful for displaying in the comment area, which elements and
  1021. * attributes are supported. As well as any plugins which want to display it.
  1022. *
  1023. * @since 1.0.1
  1024. * @uses $allowedtags
  1025. *
  1026. * @return string HTML allowed tags entity encoded.
  1027. */
  1028. function allowed_tags() {
  1029. global $allowedtags;
  1030. $allowed = '';
  1031. foreach ( (array) $allowedtags as $tag => $attributes ) {
  1032. $allowed .= '<'.$tag;
  1033. if ( 0 < count($attributes) ) {
  1034. foreach ( $attributes as $attribute => $limits ) {
  1035. $allowed .= ' '.$attribute.'=""';
  1036. }
  1037. }
  1038. $allowed .= '> ';
  1039. }
  1040. return htmlentities($allowed);
  1041. }
  1042. /***** Date/Time tags *****/
  1043. /**
  1044. * Outputs the date in iso8601 format for xml files.
  1045. *
  1046. * @since 1.0.0
  1047. */
  1048. function the_date_xml() {
  1049. global $post;
  1050. echo mysql2date('Y-m-d', $post->post_date);
  1051. }
  1052. /**
  1053. * Display or Retrieve the date the post was written.
  1054. *
  1055. * Will only output the date if the current post's date is different from the
  1056. * previous one output.
  1057. *
  1058. * @since 0.71
  1059. *
  1060. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1061. * @param string $before Optional. Output before the date.
  1062. * @param string $after Optional. Output after the date.
  1063. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1064. * @return string|null Null if displaying, string if retrieving.
  1065. */
  1066. function the_date($d='', $before='', $after='', $echo = true) {
  1067. global $post, $day, $previousday;
  1068. $the_date = '';
  1069. if ( $day != $previousday ) {
  1070. $the_date .= $before;
  1071. if ( $d=='' )
  1072. $the_date .= mysql2date(get_option('date_format'), $post->post_date);
  1073. else
  1074. $the_date .= mysql2date($d, $post->post_date);
  1075. $the_date .= $after;
  1076. $previousday = $day;
  1077. $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
  1078. if ( $echo )
  1079. echo $the_date;
  1080. else
  1081. return $the_date;
  1082. }
  1083. }
  1084. /**
  1085. * Display the date on which the post was last modified.
  1086. *
  1087. * @since 2.1.0
  1088. *
  1089. * @param string $d Optional. PHP date format.
  1090. * @return string
  1091. */
  1092. function the_modified_date($d = '') {
  1093. echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
  1094. }
  1095. /**
  1096. * Retrieve the date on which the post was last modified.
  1097. *
  1098. * @since 2.1.0
  1099. *
  1100. * @param string $d Optional. PHP date format. Defaults to the "date_format" option
  1101. * @return string
  1102. */
  1103. function get_the_modified_date($d = '') {
  1104. if ( '' == $d )
  1105. $the_time = get_post_modified_time(get_option('date_format'));
  1106. else
  1107. $the_time = get_post_modified_time($d);
  1108. return apply_filters('get_the_modified_date', $the_time, $d);
  1109. }
  1110. /**
  1111. * Display the time at which the post was written.
  1112. *
  1113. * @since 0.71
  1114. *
  1115. * @param string $d Either 'G', 'U', or php date format.
  1116. */
  1117. function the_time( $d = '' ) {
  1118. echo apply_filters('the_time', get_the_time( $d ), $d);
  1119. }
  1120. /**
  1121. * Retrieve the time at which the post was written.
  1122. *
  1123. * @since 1.5.0
  1124. *
  1125. * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1126. * @param int|object $post Optional post ID or object. Default is global $post object.
  1127. * @return string
  1128. */
  1129. function get_the_time( $d = '', $post = null ) {
  1130. $post = get_post($post);
  1131. if ( '' == $d )
  1132. $the_time = get_post_time(get_option('time_format'), false, $post);
  1133. else
  1134. $the_time = get_post_time($d, false, $post);
  1135. return apply_filters('get_the_time', $the_time, $d, $post);
  1136. }
  1137. /**
  1138. * Retrieve the time at which the post was written.
  1139. *
  1140. * @since 2.0.0
  1141. *
  1142. * @param string $d Either 'G', 'U', or php date format.
  1143. * @param bool $gmt Whether of not to return the gmt time.
  1144. * @param int|object $post Optional post ID or object. Default is global $post object.
  1145. * @return string
  1146. */
  1147. function get_post_time( $d = 'U', $gmt = false, $post = null ) { // returns timestamp
  1148. $post = get_post($post);
  1149. if ( $gmt )
  1150. $time = $post->post_date_gmt;
  1151. else
  1152. $time = $post->post_date;
  1153. $time = mysql2date($d, $time);
  1154. return apply_filters('get_post_time', $time, $d, $gmt);
  1155. }
  1156. /**
  1157. * Display the time at which the post was last modified.
  1158. *
  1159. * @since 2.0.0
  1160. *
  1161. * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1162. */
  1163. function the_modified_time($d = '') {
  1164. echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
  1165. }
  1166. /**
  1167. * Retrieve the time at which the post was last modified.
  1168. *
  1169. * @since 2.0.0
  1170. *
  1171. * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1172. * @return string
  1173. */
  1174. function get_the_modified_time($d = '') {
  1175. if ( '' == $d )
  1176. $the_time = get_post_modified_time(get_option('time_format'));
  1177. else
  1178. $the_time = get_post_modified_time($d);
  1179. return apply_filters('get_the_modified_time', $the_time, $d);
  1180. }
  1181. /**
  1182. * Retrieve the time at which the post was last modified.
  1183. *
  1184. * @since 2.0.0
  1185. *
  1186. * @param string $d Either 'G', 'U', or php date format.
  1187. * @param bool $gmt Whether of not to return the gmt time.
  1188. * @return string Returns timestamp
  1189. */
  1190. function get_post_modified_time( $d = 'U', $gmt = false ) {
  1191. global $post;
  1192. if ( $gmt )
  1193. $time = $post->post_modified_gmt;
  1194. else
  1195. $time = $post->post_modified;
  1196. $time = mysql2date($d, $time);
  1197. return apply_filters('get_the_modified_time', $time, $d, $gmt);
  1198. }
  1199. /**
  1200. * Display the weekday on which the post was written.
  1201. *
  1202. * @since 0.71
  1203. * @uses $wp_locale
  1204. * @uses $post
  1205. */
  1206. function the_weekday() {
  1207. global $wp_locale, $post;
  1208. $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date));
  1209. $the_weekday = apply_filters('the_weekday', $the_weekday);
  1210. echo $the_weekday;
  1211. }
  1212. /**
  1213. * Display the weekday on which the post was written.
  1214. *
  1215. * Will only output the weekday if the current post's weekday is different from
  1216. * the previous one output.
  1217. *
  1218. * @since 0.71
  1219. *
  1220. * @param string $before output before the date.
  1221. * @param string $after output after the date.
  1222. */
  1223. function the_weekday_date($before='',$after='') {
  1224. global $wp_locale, $post, $day, $previousweekday;
  1225. $the_weekday_date = '';
  1226. if ( $day != $previousweekday ) {
  1227. $the_weekday_date .= $before;
  1228. $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date));
  1229. $the_weekday_date .= $after;
  1230. $previousweekday = $day;
  1231. }
  1232. $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
  1233. echo $the_weekday_date;
  1234. }
  1235. /**
  1236. * Fire the wp_head action
  1237. *
  1238. * @since 1.2.0
  1239. * @uses do_action() Calls 'wp_head' hook.
  1240. */
  1241. function wp_head() {
  1242. do_action('wp_head');
  1243. }
  1244. /**
  1245. * Fire the wp_footer action
  1246. *
  1247. * @since 1.5.1
  1248. * @uses do_action() Calls 'wp_footer' hook.
  1249. */
  1250. function wp_footer() {
  1251. do_action('wp_footer');
  1252. }
  1253. /**
  1254. * Enable/disable automatic general feed link outputting.
  1255. *
  1256. * @since 2.8.0
  1257. *
  1258. * @param boolean $add Add or remove links. Defaults to true.
  1259. */
  1260. function automatic_feed_links( $add = true ) {
  1261. if ( $add )
  1262. add_action( 'wp_head', 'feed_links', 2 );
  1263. else {
  1264. remove_action( 'wp_head', 'feed_links', 2 );
  1265. remove_action( 'wp_head', 'feed_links_extra', 3 );
  1266. }
  1267. }
  1268. /**
  1269. * Display the links to the general feeds.
  1270. *
  1271. * @since 2.8.0
  1272. *
  1273. * @param array $args Optional arguments.
  1274. */
  1275. function feed_links( $args ) {
  1276. $defaults = array(
  1277. 'seperator' => _c('&raquo;|Seperator character for feed titles in theme head'),
  1278. 'feedtitle' => __('%s Feed'),
  1279. 'comstitle' => __('%s Comments Feed'),
  1280. );
  1281. $args = wp_parse_args( $args, $defaults );
  1282. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['feedtitle'], get_bloginfo('name') )) . '" href="' . get_feed_link() . "\" />\n";
  1283. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['comstitle'], get_bloginfo('name') )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
  1284. }
  1285. /**
  1286. * Display the links to the extra feeds such as category feeds.
  1287. *
  1288. * @since 2.8.0
  1289. *
  1290. * @param array $args Optional arguments.
  1291. */
  1292. function feed_links_extra( $args ) {
  1293. $defaults = array(
  1294. 'seperator' => _c('&raquo;|Seperator character for feed titles in theme head'),
  1295. 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
  1296. 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
  1297. 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
  1298. 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
  1299. 'searchtitle' => __('%1$s %2$s Search Results for &quot;%3$s&quot; Feed'),
  1300. );
  1301. $args = wp_parse_args( $args, $defaults );
  1302. if ( is_single() || is_page() ) {
  1303. $post = &get_post( $id = 0 );
  1304. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  1305. $title = attribute_escape(sprintf( $args['singletitle'], get_bloginfo('name'), $args['seperator'], wp_specialchars( get_the_title() ) ));
  1306. $href = get_post_comments_feed_link( $post->ID );
  1307. }
  1308. } elseif ( is_category() ) {
  1309. $cat_id = intval( get_query_var('cat') );
  1310. $title = attribute_escape(sprintf( $args['cattitle'], get_bloginfo('name'), $args['seperator'], get_cat_name( $cat_id ) ));
  1311. $href = get_category_feed_link( $cat_id );
  1312. } elseif ( is_tag() ) {
  1313. $tag_id = intval( get_query_var('tag_id') );
  1314. $tag = get_tag( $tag_id );
  1315. $title = attribute_escape(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['seperator'], $tag->name ));
  1316. $href = get_tag_feed_link( $tag_id );
  1317. } elseif ( is_author() ) {
  1318. $author_id = intval( get_query_var('author') );
  1319. $title = attribute_escape(sprintf( $args['authortitle'], get_bloginfo('name'), $args['seperator'], get_author_name( $author_id ) ));
  1320. $href = get_author_feed_link( $author_id );
  1321. } elseif ( is_search() ) {
  1322. $title = attribute_escape(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['seperator'], get_search_query() ));
  1323. $href = get_search_feed_link();
  1324. }
  1325. if ( isset($title) && isset($href) )
  1326. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . '" />' . "\n";
  1327. }
  1328. /**
  1329. * Display the link to the Really Simple Discovery service endpoint.
  1330. *
  1331. * @link http://archipelago.phrasewise.com/rsd
  1332. * @since 2.0.0
  1333. */
  1334. function rsd_link() {
  1335. echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
  1336. }
  1337. /**
  1338. * Display the link to the Windows Live Writer manifest file.
  1339. *
  1340. * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
  1341. * @since 2.3.1
  1342. */
  1343. function wlwmanifest_link() {
  1344. echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
  1345. . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
  1346. }
  1347. /**
  1348. * Display a noindex meta tag if required by the blog configuration.
  1349. *
  1350. * If a blog is marked as not being public then the noindex meta tag will be
  1351. * output to tell web robots not to index the page content.
  1352. *
  1353. * @since 2.1.0
  1354. */
  1355. function noindex() {
  1356. // If the blog is not public, tell robots to go away.
  1357. if ( '0' == get_option('blog_public') )
  1358. echo "<meta name='robots' content='noindex,nofollow' />\n";
  1359. }
  1360. /**
  1361. * Determine if TinyMCE is available.
  1362. *
  1363. * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
  1364. *
  1365. * @since 2.1.0
  1366. *
  1367. * @return bool Whether of not TinyMCE exists.
  1368. */
  1369. function rich_edit_exists() {
  1370. global $wp_rich_edit_exists;
  1371. if ( !isset($wp_rich_edit_exists) )
  1372. $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
  1373. return $wp_rich_edit_exists;
  1374. }
  1375. /**
  1376. * Whether or not the user should have a WYSIWIG editor.
  1377. *
  1378. * Checks that the user requires a WYSIWIG editor and that the editor is
  1379. * supported in the users browser.
  1380. *
  1381. * @since 2.0.0
  1382. *
  1383. * @return bool
  1384. */
  1385. function user_can_richedit() {
  1386. global $wp_rich_edit, $pagenow;
  1387. if ( !isset( $wp_rich_edit) ) {
  1388. if ( get_user_option( 'rich_editing' ) == 'true' &&
  1389. ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
  1390. !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
  1391. && 'comment.php' != $pagenow ) {
  1392. $wp_rich_edit = true;
  1393. } else {
  1394. $wp_rich_edit = false;
  1395. }
  1396. }
  1397. return apply_filters('user_can_richedit', $wp_rich_edit);
  1398. }
  1399. /**
  1400. * Find out which editor should be displayed by default.
  1401. *
  1402. * Works out which of the two editors to display as the current editor for a
  1403. * user.
  1404. *
  1405. * @since 2.5.0
  1406. *
  1407. * @return string Either 'tinymce', or 'html', or 'test'
  1408. */
  1409. function wp_default_editor() {
  1410. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  1411. if ( $user = wp_get_current_user() ) { // look for cookie
  1412. $ed = get_user_setting('editor', 'tinymce');
  1413. $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
  1414. }
  1415. return apply_filters( 'wp_default_editor', $r ); // filter
  1416. }
  1417. /**
  1418. * Display visual editor forms: TinyMCE, or HTML, or both.
  1419. *
  1420. * The amount of rows the text area will have for the content has to be between
  1421. * 3 and 100 or will default at 12. There is only one option used for all users,
  1422. * named 'default_post_edit_rows'.
  1423. *
  1424. * If the user can not use the rich editor (TinyMCE), then the switch button
  1425. * will not be displayed.
  1426. *
  1427. * @since 2.1.0
  1428. *
  1429. * @param string $content Textarea content.
  1430. * @param string $id HTML ID attribute value.
  1431. * @param string $prev_id HTML ID name for switching back and forth between visual editors.
  1432. * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
  1433. * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
  1434. */
  1435. function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
  1436. $rows = get_option('default_post_edit_rows');
  1437. if (($rows < 3) || ($rows > 100))
  1438. $rows = 12;
  1439. if ( !current_user_can( 'upload_files' ) )
  1440. $media_buttons = false;
  1441. $richedit = user_can_richedit();
  1442. $rows = "rows='$rows'";
  1443. if ( $richedit || $media_buttons ) { ?>
  1444. <div id="editor-toolbar">
  1445. <?php if ( $richedit ) {
  1446. $wp_default_editor = wp_default_editor(); ?>
  1447. <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
  1448. <?php if ( 'html' == $wp_default_editor ) {
  1449. add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
  1450. <a id="edButtonHTML" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
  1451. <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
  1452. <?php } else {
  1453. add_filter('the_editor_content', 'wp_richedit_pre'); ?>
  1454. <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
  1455. <a id="edButtonPreview" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
  1456. <?php }
  1457. }
  1458. if ( $media_buttons ) { ?>
  1459. <div id="media-buttons" class="hide-if-no-js">
  1460. <?php do_action( 'media_buttons' ); ?>
  1461. </div>
  1462. <?php } ?>
  1463. </div>
  1464. <?php } ?>
  1465. <div id="quicktags">
  1466. <?php wp_print_scripts( 'quicktags' ); ?>
  1467. <script type="text/javascript">edToolbar()</script>
  1468. </div>
  1469. <?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
  1470. $the_editor_content = apply_filters('the_editor_content', $content);
  1471. printf($the_editor, $the_editor_content);
  1472. ?>
  1473. <script type="text/javascript">
  1474. /* <![CDATA[ */
  1475. edCanvas = document.getElementById('<?php echo $id; ?>');
  1476. /* ]]> */
  1477. </script>
  1478. <?php
  1479. }
  1480. /**
  1481. * Retrieve the contents of the search WordPress query variable.
  1482. *
  1483. * @since 2.3.0
  1484. *
  1485. * @return string
  1486. */
  1487. function get_search_query() {
  1488. return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) );
  1489. }
  1490. /**
  1491. * Display the contents of the search query variable.
  1492. *
  1493. * The search query string is passed through {@link attribute_escape()}
  1494. * to ensure that it is safe for placing in an html attribute.
  1495. *
  1496. * @uses attribute_escape
  1497. * @since 2.1.0
  1498. */
  1499. function the_search_query() {
  1500. echo attribute_escape( apply_filters( 'the_search_query', get_search_query() ) );
  1501. }
  1502. /**
  1503. * Display the language attributes for the html tag.
  1504. *
  1505. * Builds up a set of html attributes containing the text direction and language
  1506. * information for the page.
  1507. *
  1508. * @since 2.1.0
  1509. *
  1510. * @param string $doctype The type of html document (xhtml|html).
  1511. */
  1512. function language_attributes($doctype = 'html') {
  1513. $attributes = array();
  1514. $output = '';
  1515. if ( $dir = get_bloginfo('text_direction') )
  1516. $attributes[] = "dir=\"$dir\"";
  1517. if ( $lang = get_bloginfo('language') ) {
  1518. if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
  1519. $attributes[] = "lang=\"$lang\"";
  1520. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
  1521. $attributes[] = "xml:lang=\"$lang\"";
  1522. }
  1523. $output = implode(' ', $attributes);
  1524. $output = apply_filters('language_attributes', $output);
  1525. echo $output;
  1526. }
  1527. /**
  1528. * Retrieve paginated link for archive post pages.
  1529. *
  1530. * Technically, the function can be used to create paginated link list for any
  1531. * area. The 'base' argument is used to reference the url, which will be used to
  1532. * create the paginated links. The 'format' argument is then used for replacing
  1533. * the page number. It is however, most likely and by default, to be used on the
  1534. * archive post pages.
  1535. *
  1536. * The 'type' argument controls format of the returned value. The default is
  1537. * 'plain', which is just a string with the links separated by a newline
  1538. * character. The other possible values are either 'array' or 'list'. The
  1539. * 'array' value will return an array of the paginated link list to offer full
  1540. * control of display. The 'list' value will place all of the paginated links in
  1541. * an unordered HTML list.
  1542. *
  1543. * The 'total' argument is the total amount of pages and is an integer. The
  1544. * 'current' argument is the current page number and is also an integer.
  1545. *
  1546. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  1547. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  1548. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  1549. * and the '%#%' is also required. The '%#%' will be replaced with the page
  1550. * number.
  1551. *
  1552. * You can include the previous and next links in the list by setting the
  1553. * 'prev_next' argument to true, which it is by default. You can set the
  1554. * previous text, by using the 'prev_text' argument. You can set the next text
  1555. * by setting the 'next_text' argument.
  1556. *
  1557. * If the 'show_all' argument is set to true, then it will show all of the pages
  1558. * instead of a short list of the pages near the current page. By default, the
  1559. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  1560. * arguments. The 'end_size' argument is how many numbers on either the start
  1561. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  1562. * numbers to either side of current page, but not including current page.
  1563. *
  1564. * It is possible to add query vars to the link by using the 'add_args' argument
  1565. * and see {@link add_query_arg()} for more information.
  1566. *
  1567. * @since 2.1.0
  1568. *
  1569. * @param string|array $args Optional. Override defaults.
  1570. * @return array|string String of page links or array of page links.
  1571. */
  1572. function paginate_links( $args = '' ) {
  1573. $defaults = array(
  1574. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  1575. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  1576. 'total' => 1,
  1577. 'current' => 0,
  1578. 'show_all' => false,
  1579. 'prev_next' => true,
  1580. 'prev_text' => __('&laquo; Previous'),
  1581. 'next_text' => __('Next &raquo;'),
  1582. 'end_size' => 1,
  1583. 'mid_size' => 2,
  1584. 'type' => 'plain',
  1585. 'add_args' => false, // array of query args to add
  1586. 'add_fragment' => ''
  1587. );
  1588. $args = wp_parse_args( $args, $defaults );
  1589. extract($args, EXTR_SKIP);
  1590. // Who knows what else people pass in $args
  1591. $total = (int) $total;
  1592. if ( $total < 2 )
  1593. return;
  1594. $current = (int) $current;
  1595. $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
  1596. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
  1597. $add_args = is_array($add_args) ? $add_args : false;
  1598. $r = '';
  1599. $page_links = array();
  1600. $n = 0;
  1601. $dots = false;
  1602. if ( $prev_next && $current && 1 < $current ) :
  1603. $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
  1604. $link = str_replace('%#%', $current - 1, $link);
  1605. if ( $add_args )
  1606. $link = add_query_arg( $add_args, $link );
  1607. $link .= $add_fragment;
  1608. $page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>";
  1609. endif;
  1610. for ( $n = 1; $n <= $total; $n++ ) :
  1611. $n_display = number_format_i18n($n);
  1612. if ( $n == $current ) :
  1613. $page_links[] = "<span class='page-numbers current'>$n_display</span>";
  1614. $dots = true;
  1615. else :
  1616. if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  1617. $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
  1618. $link = str_replace('%#%', $n, $link);
  1619. if ( $add_args )
  1620. $link = add_query_arg( $add_args, $link );
  1621. $link .= $add_fragment;
  1622. $page_links[] = "<a class='page-numbers' href='" . clean_url($link) . "'>$n_display</a>";
  1623. $dots = true;
  1624. elseif ( $dots && !$show_all ) :
  1625. $page_links[] = "<span class='page-numbers dots'>...</span>";
  1626. $dots = false;
  1627. endif;
  1628. endif;
  1629. endfor;
  1630. if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
  1631. $link = str_replace('%_%', $format, $base);
  1632. $link = str_replace('%#%', $current + 1, $link);
  1633. if ( $add_args )
  1634. $link = add_query_arg( $add_args, $link );
  1635. $link .= $add_fragment;
  1636. $page_links[] = "<a class='next page-numbers' href='" . clean_url($link) . "'>$next_text</a>";
  1637. endif;
  1638. switch ( $type ) :
  1639. case 'array' :
  1640. return $page_links;
  1641. break;
  1642. case 'list' :
  1643. $r .= "<ul class='page-numbers'>\n\t<li>";
  1644. $r .= join("</li>\n\t<li>", $page_links);
  1645. $r .= "</li>\n</ul>\n";
  1646. break;
  1647. default :
  1648. $r = join("\n", $page_links);
  1649. break;
  1650. endswitch;
  1651. return $r;
  1652. }
  1653. /**
  1654. * Registers an admin colour scheme css file.
  1655. *
  1656. * Allows a plugin to register a new admin colour scheme. For example:
  1657. * <code>
  1658. * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
  1659. * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  1660. * </code>
  1661. *
  1662. * @since 2.5.0
  1663. *
  1664. * @param string $key The unique key for this theme.
  1665. * @param string $name The name of the theme.
  1666. * @param string $url The url of the css file containing the colour scheme.
  1667. * @param array @colors An array of CSS color definitions which are used to give the user a feel for the theme.
  1668. */
  1669. function wp_admin_css_color($key, $name, $url, $colors = array()) {
  1670. global $_wp_admin_css_colors;
  1671. if ( !isset($_wp_admin_css_colors) )
  1672. $_wp_admin_css_colors = array();
  1673. $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
  1674. }
  1675. /**
  1676. * Display the URL of a WordPress admin CSS file.
  1677. *
  1678. * @see WP_Styles::_css_href and its style_loader_src filter.
  1679. *
  1680. * @since 2.3.0
  1681. *
  1682. * @param string $file file relative to wp-admin/ without its ".css" extension.
  1683. */
  1684. function wp_admin_css_uri( $file = 'wp-admin' ) {
  1685. if ( defined('WP_INSTALLING') ) {
  1686. $_file = "./$file.css";
  1687. } else {
  1688. $_file = admin_url("$file.css");
  1689. }
  1690. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  1691. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  1692. }
  1693. /**
  1694. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  1695. *
  1696. * "Intelligently" decides to enqueue or to print the CSS file. If the
  1697. * 'wp_print_styles' action has *not* yet been called, the CSS file will be
  1698. * enqueued. If the wp_print_styles action *has* been called, the CSS link will
  1699. * be printed. Printing may be forced by passing TRUE as the $force_echo
  1700. * (second) parameter.
  1701. *
  1702. * For backward compatibility with WordPress 2.3 calling method: If the $file
  1703. * (first) parameter does not correspond to a registered CSS file, we assume
  1704. * $file is a file relative to wp-admin/ without its ".css" extension. A
  1705. * stylesheet link to that generated URL is printed.
  1706. *
  1707. * @package WordPress
  1708. * @since 2.3.0
  1709. * @uses $wp_styles WordPress Styles Object
  1710. *
  1711. * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
  1712. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  1713. */
  1714. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  1715. global $wp_styles;
  1716. if ( !is_a($wp_styles, 'WP_Styles') )
  1717. $wp_styles = new WP_Styles();
  1718. // For backward compatibility
  1719. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  1720. if ( $wp_styles->query( $handle ) ) {
  1721. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
  1722. wp_print_styles( $handle );
  1723. else // Add to style queue
  1724. wp_enqueue_style( $handle );
  1725. return;
  1726. }
  1727. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
  1728. if ( 'rtl' == get_bloginfo( 'text_direction' ) )
  1729. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
  1730. }
  1731. /**
  1732. * Enqueues the default ThickBox js and css.
  1733. *
  1734. * If any of the settings need to be changed, this can be done with another js
  1735. * file similar to media-upload.js and theme-preview.js. That file should
  1736. * require array('thickbox') to ensure it is loaded after.
  1737. *
  1738. * @since 2.5.0
  1739. */
  1740. function add_thickbox() {
  1741. wp_enqueue_script( 'thickbox' );
  1742. wp_enqueue_style( 'thickbox' );
  1743. }
  1744. /**
  1745. * Display the XHTML generator that is generated on the wp_head hook.
  1746. *
  1747. * @since 2.5.0
  1748. */
  1749. function wp_generator() {
  1750. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  1751. }
  1752. /**
  1753. * Display the generator XML or Comment for RSS, ATOM, etc.
  1754. *
  1755. * Returns the correct generator type for the requested output format. Allows
  1756. * for a plugin to filter generators overall the the_generator filter.
  1757. *
  1758. * @since 2.5.0
  1759. * @uses apply_filters() Calls 'the_generator' hook.
  1760. *
  1761. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  1762. */
  1763. function the_generator( $type ) {
  1764. echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
  1765. }
  1766. /**
  1767. * Creates the generator XML or Comment for RSS, ATOM, etc.
  1768. *
  1769. * Returns the correct generator type for the requested output format. Allows
  1770. * for a plugin to filter generators on an individual basis using the
  1771. * 'get_the_generator_{$type}' filter.
  1772. *
  1773. * @since 2.5.0
  1774. * @uses apply_filters() Calls 'get_the_generator_$type' hook.
  1775. *
  1776. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  1777. * @return string The HTML content for the generator.
  1778. */
  1779. function get_the_generator( $type ) {
  1780. switch ($type) {
  1781. case 'html':
  1782. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
  1783. break;
  1784. case 'xhtml':
  1785. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
  1786. break;
  1787. case 'atom':
  1788. $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
  1789. break;
  1790. case 'rss2':
  1791. $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
  1792. break;
  1793. case 'rdf':
  1794. $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
  1795. break;
  1796. case 'comment':
  1797. $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
  1798. break;
  1799. case 'export':
  1800. $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
  1801. break;
  1802. }
  1803. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  1804. }
  1805. ?>