[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

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


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7