[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> general-template.php (source)

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