Advertisement
Guest User

Amer Kawar

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