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