web/wp-includes/post-template.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 /**
       
     3  * WordPress Post Template Functions.
       
     4  *
       
     5  * Gets content for the current post in the loop.
       
     6  *
       
     7  * @package WordPress
       
     8  * @subpackage Template
       
     9  */
       
    10 
       
    11 /**
       
    12  * Display the ID of the current item in the WordPress Loop.
       
    13  *
       
    14  * @since 0.71
       
    15  * @uses $id
       
    16  */
       
    17 function the_ID() {
       
    18 	global $id;
       
    19 	echo $id;
       
    20 }
       
    21 
       
    22 /**
       
    23  * Retrieve the ID of the current item in the WordPress Loop.
       
    24  *
       
    25  * @since 2.1.0
       
    26  * @uses $id
       
    27  *
       
    28  * @return unknown
       
    29  */
       
    30 function get_the_ID() {
       
    31 	global $id;
       
    32 	return $id;
       
    33 }
       
    34 
       
    35 /**
       
    36  * Display or retrieve the current post title with optional content.
       
    37  *
       
    38  * @since 0.71
       
    39  *
       
    40  * @param string $before Optional. Content to prepend to the title.
       
    41  * @param string $after Optional. Content to append to the title.
       
    42  * @param bool $echo Optional, default to true.Whether to display or return.
       
    43  * @return null|string Null on no title. String if $echo parameter is false.
       
    44  */
       
    45 function the_title($before = '', $after = '', $echo = true) {
       
    46 	$title = get_the_title();
       
    47 
       
    48 	if ( strlen($title) == 0 )
       
    49 		return;
       
    50 
       
    51 	$title = $before . $title . $after;
       
    52 
       
    53 	if ( $echo )
       
    54 		echo $title;
       
    55 	else
       
    56 		return $title;
       
    57 }
       
    58 
       
    59 /**
       
    60  * Sanitize the current title when retrieving or displaying.
       
    61  *
       
    62  * Works like {@link the_title()}, except the parameters can be in a string or
       
    63  * an array. See the function for what can be override in the $args parameter.
       
    64  *
       
    65  * The title before it is displayed will have the tags stripped and {@link
       
    66  * esc_attr()} before it is passed to the user or displayed. The default
       
    67  * as with {@link the_title()}, is to display the title.
       
    68  *
       
    69  * @since 2.3.0
       
    70  *
       
    71  * @param string|array $args Optional. Override the defaults.
       
    72  * @return string|null Null on failure or display. String when echo is false.
       
    73  */
       
    74 function the_title_attribute( $args = '' ) {
       
    75 	$title = get_the_title();
       
    76 
       
    77 	if ( strlen($title) == 0 )
       
    78 		return;
       
    79 
       
    80 	$defaults = array('before' => '', 'after' =>  '', 'echo' => true);
       
    81 	$r = wp_parse_args($args, $defaults);
       
    82 	extract( $r, EXTR_SKIP );
       
    83 
       
    84 
       
    85 	$title = $before . $title . $after;
       
    86 	$title = esc_attr(strip_tags($title));
       
    87 
       
    88 	if ( $echo )
       
    89 		echo $title;
       
    90 	else
       
    91 		return $title;
       
    92 }
       
    93 
       
    94 /**
       
    95  * Retrieve post title.
       
    96  *
       
    97  * If the post is protected and the visitor is not an admin, then "Protected"
       
    98  * will be displayed before the post title. If the post is private, then
       
    99  * "Private" will be located before the post title.
       
   100  *
       
   101  * @since 0.71
       
   102  *
       
   103  * @param int $id Optional. Post ID.
       
   104  * @return string
       
   105  */
       
   106 function get_the_title( $id = 0 ) {
       
   107 	$post = &get_post($id);
       
   108 
       
   109 	$title = $post->post_title;
       
   110 
       
   111 	if ( !is_admin() ) {
       
   112 		if ( !empty($post->post_password) ) {
       
   113 			$protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
       
   114 			$title = sprintf($protected_title_format, $title);
       
   115 		} else if ( isset($post->post_status) && 'private' == $post->post_status ) {
       
   116 			$private_title_format = apply_filters('private_title_format', __('Private: %s'));
       
   117 			$title = sprintf($private_title_format, $title);
       
   118 		}
       
   119 	}
       
   120 	return apply_filters( 'the_title', $title, $post->ID );
       
   121 }
       
   122 
       
   123 /**
       
   124  * Display the Post Global Unique Identifier (guid).
       
   125  *
       
   126  * The guid will appear to be a link, but should not be used as an link to the
       
   127  * post. The reason you should not use it as a link, is because of moving the
       
   128  * blog across domains.
       
   129  *
       
   130  * @since 1.5.0
       
   131  *
       
   132  * @param int $id Optional. Post ID.
       
   133  */
       
   134 function the_guid( $id = 0 ) {
       
   135 	echo get_the_guid($id);
       
   136 }
       
   137 
       
   138 /**
       
   139  * Retrieve the Post Global Unique Identifier (guid).
       
   140  *
       
   141  * The guid will appear to be a link, but should not be used as an link to the
       
   142  * post. The reason you should not use it as a link, is because of moving the
       
   143  * blog across domains.
       
   144  *
       
   145  * @since 1.5.0
       
   146  *
       
   147  * @param int $id Optional. Post ID.
       
   148  * @return string
       
   149  */
       
   150 function get_the_guid( $id = 0 ) {
       
   151 	$post = &get_post($id);
       
   152 
       
   153 	return apply_filters('get_the_guid', $post->guid);
       
   154 }
       
   155 
       
   156 /**
       
   157  * Display the post content.
       
   158  *
       
   159  * @since 0.71
       
   160  *
       
   161  * @param string $more_link_text Optional. Content for when there is more text.
       
   162  * @param string $stripteaser Optional. Teaser content before the more text.
       
   163  */
       
   164 function the_content($more_link_text = null, $stripteaser = 0) {
       
   165 	$content = get_the_content($more_link_text, $stripteaser);
       
   166 	$content = apply_filters('the_content', $content);
       
   167 	$content = str_replace(']]>', ']]&gt;', $content);
       
   168 	if (is_single() && function_exists(amt_cc)) { $content = amt_cc($content); }
       
   169 	echo $content;
       
   170 }
       
   171 
       
   172 /**
       
   173  * Retrieve the post content.
       
   174  *
       
   175  * @since 0.71
       
   176  *
       
   177  * @param string $more_link_text Optional. Content for when there is more text.
       
   178  * @param string $stripteaser Optional. Teaser content before the more text.
       
   179  * @return string
       
   180  */
       
   181 function get_the_content($more_link_text = null, $stripteaser = 0) {
       
   182 	global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
       
   183 
       
   184 	if ( null === $more_link_text )
       
   185 		$more_link_text = __( '(more...)' );
       
   186 
       
   187 	$output = '';
       
   188 	$hasTeaser = false;
       
   189 
       
   190 	// If post password required and it doesn't match the cookie.
       
   191 	if ( post_password_required($post) ) {
       
   192 		$output = get_the_password_form();
       
   193 		return $output;
       
   194 	}
       
   195 
       
   196 	if ( $page > count($pages) ) // if the requested page doesn't exist
       
   197 		$page = count($pages); // give them the highest numbered page that DOES exist
       
   198 
       
   199 	$content = $pages[$page-1];
       
   200 	if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
       
   201 		$content = explode($matches[0], $content, 2);
       
   202 		if ( !empty($matches[1]) && !empty($more_link_text) )
       
   203 			$more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
       
   204 
       
   205 		$hasTeaser = true;
       
   206 	} else {
       
   207 		$content = array($content);
       
   208 	}
       
   209 	if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
       
   210 		$stripteaser = 1;
       
   211 	$teaser = $content[0];
       
   212 	if ( ($more) && ($stripteaser) && ($hasTeaser) )
       
   213 		$teaser = '';
       
   214 	$output .= $teaser;
       
   215 	if ( count($content) > 1 ) {
       
   216 		if ( $more ) {
       
   217 			$output .= '<span id="more-' . $id . '"></span>' . $content[1];
       
   218 		} else {
       
   219 			if ( ! empty($more_link_text) )
       
   220 				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
       
   221 			$output = force_balance_tags($output);
       
   222 		}
       
   223 
       
   224 	}
       
   225 	if ( $preview ) // preview fix for javascript bug with foreign languages
       
   226 		$output =	preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
       
   227 
       
   228 	return $output;
       
   229 }
       
   230 
       
   231 /**
       
   232  * Display the post excerpt.
       
   233  *
       
   234  * @since 0.71
       
   235  * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
       
   236  */
       
   237 function the_excerpt() {
       
   238 	echo apply_filters('the_excerpt', get_the_excerpt());
       
   239 }
       
   240 
       
   241 /**
       
   242  * Retrieve the post excerpt.
       
   243  *
       
   244  * @since 0.71
       
   245  *
       
   246  * @param mixed $deprecated Not used.
       
   247  * @return string
       
   248  */
       
   249 function get_the_excerpt($deprecated = '') {
       
   250 	global $post;
       
   251 	$output = $post->post_excerpt;
       
   252 	if ( post_password_required($post) ) {
       
   253 		$output = __('There is no excerpt because this is a protected post.');
       
   254 		return $output;
       
   255 	}
       
   256 
       
   257 	return apply_filters('get_the_excerpt', $output);
       
   258 }
       
   259 
       
   260 /**
       
   261  * Whether post has excerpt.
       
   262  *
       
   263  * @since 2.3.0
       
   264  *
       
   265  * @param int $id Optional. Post ID.
       
   266  * @return bool
       
   267  */
       
   268 function has_excerpt( $id = 0 ) {
       
   269 	$post = &get_post( $id );
       
   270 	return ( !empty( $post->post_excerpt ) );
       
   271 }
       
   272 
       
   273 /**
       
   274  * Display the classes for the post div.
       
   275  *
       
   276  * @since 2.7.0
       
   277  *
       
   278  * @param string|array $class One or more classes to add to the class list.
       
   279  * @param int $post_id An optional post ID.
       
   280  */
       
   281 function post_class( $class = '', $post_id = null ) {
       
   282 	// Separates classes with a single space, collates classes for post DIV
       
   283 	echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
       
   284 }
       
   285 
       
   286 /**
       
   287  * Retrieve the classes for the post div as an array.
       
   288  *
       
   289  * The class names are add are many. If the post is a sticky, then the 'sticky'
       
   290  * class name. The class 'hentry' is always added to each post. For each
       
   291  * category, the class will be added with 'category-' with category slug is
       
   292  * added. The tags are the same way as the categories with 'tag-' before the tag
       
   293  * slug. All classes are passed through the filter, 'post_class' with the list
       
   294  * of classes, followed by $class parameter value, with the post ID as the last
       
   295  * parameter.
       
   296  *
       
   297  * @since 2.7.0
       
   298  *
       
   299  * @param string|array $class One or more classes to add to the class list.
       
   300  * @param int $post_id An optional post ID.
       
   301  * @return array Array of classes.
       
   302  */
       
   303 function get_post_class( $class = '', $post_id = null ) {
       
   304 	$post = get_post($post_id);
       
   305 
       
   306 	$classes = array();
       
   307 
       
   308 	if ( empty($post) )
       
   309 		return $classes;
       
   310 
       
   311 	$classes[] = 'post-' . $post->ID;
       
   312 	$classes[] = $post->post_type;
       
   313 
       
   314 	// sticky for Sticky Posts
       
   315 	if ( is_sticky($post->ID) && is_home())
       
   316 		$classes[] = 'sticky';
       
   317 
       
   318 	// hentry for hAtom compliace
       
   319 	$classes[] = 'hentry';
       
   320 
       
   321 	// Categories
       
   322 	foreach ( (array) get_the_category($post->ID) as $cat ) {
       
   323 		if ( empty($cat->slug ) )
       
   324 			continue;
       
   325 		$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
       
   326 	}
       
   327 
       
   328 	// Tags
       
   329 	foreach ( (array) get_the_tags($post->ID) as $tag ) {
       
   330 		if ( empty($tag->slug ) )
       
   331 			continue;
       
   332 		$classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
       
   333 	}
       
   334 
       
   335 	if ( !empty($class) ) {
       
   336 		if ( !is_array( $class ) )
       
   337 			$class = preg_split('#\s+#', $class);
       
   338 		$classes = array_merge($classes, $class);
       
   339 	}
       
   340 
       
   341 	$classes = array_map('esc_attr', $classes);
       
   342 
       
   343 	return apply_filters('post_class', $classes, $class, $post_id);
       
   344 }
       
   345 
       
   346 /**
       
   347  * Display the classes for the body element.
       
   348  *
       
   349  * @since 2.8.0
       
   350  *
       
   351  * @param string|array $class One or more classes to add to the class list.
       
   352  */
       
   353 function body_class( $class = '' ) {
       
   354 	// Separates classes with a single space, collates classes for body element
       
   355 	echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
       
   356 }
       
   357 
       
   358 /**
       
   359  * Retrieve the classes for the body element as an array.
       
   360  *
       
   361  * @since 2.8.0
       
   362  *
       
   363  * @param string|array $class One or more classes to add to the class list.
       
   364  * @return array Array of classes.
       
   365  */
       
   366 function get_body_class( $class = '' ) {
       
   367 	global $wp_query, $wpdb, $current_user;
       
   368 
       
   369 	$classes = array();
       
   370 
       
   371 	if ( 'rtl' == get_bloginfo('text_direction') )
       
   372 		$classes[] = 'rtl';
       
   373 
       
   374 	if ( is_front_page() )
       
   375 		$classes[] = 'home';
       
   376 	if ( is_home() )
       
   377 		$classes[] = 'blog';
       
   378 	if ( is_archive() )
       
   379 		$classes[] = 'archive';
       
   380 	if ( is_date() )
       
   381 		$classes[] = 'date';
       
   382 	if ( is_search() )
       
   383 		$classes[] = 'search';
       
   384 	if ( is_paged() )
       
   385 		$classes[] = 'paged';
       
   386 	if ( is_attachment() )
       
   387 		$classes[] = 'attachment';
       
   388 	if ( is_404() )
       
   389 		$classes[] = 'error404';
       
   390 
       
   391 	if ( is_single() ) {
       
   392 		$wp_query->post = $wp_query->posts[0];
       
   393 		setup_postdata($wp_query->post);
       
   394 
       
   395 		$postID = $wp_query->post->ID;
       
   396 		$classes[] = 'single postid-' . $postID;
       
   397 
       
   398 		if ( is_attachment() ) {
       
   399 			$mime_type = get_post_mime_type();
       
   400 			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
       
   401 			$classes[] = 'attachmentid-' . $postID;
       
   402 			$classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
       
   403 		}
       
   404 	} elseif ( is_archive() ) {
       
   405 		if ( is_author() ) {
       
   406 			$author = $wp_query->get_queried_object();
       
   407 			$classes[] = 'author';
       
   408 			$classes[] = 'author-' . sanitize_html_class($author->user_nicename , $author->ID);
       
   409 		} elseif ( is_category() ) {
       
   410 			$cat = $wp_query->get_queried_object();
       
   411 			$classes[] = 'category';
       
   412 			$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
       
   413 		} elseif ( is_tag() ) {
       
   414 			$tags = $wp_query->get_queried_object();
       
   415 			$classes[] = 'tag';
       
   416 			$classes[] = 'tag-' . sanitize_html_class($tags->slug, $tags->term_id);
       
   417 		}
       
   418 	} elseif ( is_page() ) {
       
   419 		$classes[] = 'page';
       
   420 
       
   421 		$wp_query->post = $wp_query->posts[0];
       
   422 		setup_postdata($wp_query->post);
       
   423 
       
   424 		$pageID = $wp_query->post->ID;
       
   425 
       
   426 		$classes[] = 'page-id-' . $pageID;
       
   427 
       
   428 		if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' LIMIT 1", $pageID) ) )
       
   429 			$classes[] = 'page-parent';
       
   430 
       
   431 		if ( $wp_query->post->post_parent ) {
       
   432 			$classes[] = 'page-child';
       
   433 			$classes[] = 'parent-pageid-' . $wp_query->post->post_parent;
       
   434 		}
       
   435 		if ( is_page_template() ) {
       
   436 			$classes[] = 'page-template';
       
   437 			$classes[] = 'page-template-' . str_replace( '.php', '-php', get_post_meta( $pageID, '_wp_page_template', true ) );
       
   438 		}
       
   439 	} elseif ( is_search() ) {
       
   440 		if ( !empty($wp_query->posts) )
       
   441 			$classes[] = 'search-results';
       
   442 		else
       
   443 			$classes[] = 'search-no-results';
       
   444 	}
       
   445 
       
   446 	if ( is_user_logged_in() )
       
   447 		$classes[] = 'logged-in';
       
   448 
       
   449 	$page = $wp_query->get('page');
       
   450 
       
   451 	if ( !$page || $page < 2)
       
   452 		$page = $wp_query->get('paged');
       
   453 
       
   454 	if ( $page && $page > 1 ) {
       
   455 		$classes[] = 'paged-' . $page;
       
   456 
       
   457 		if ( is_single() )
       
   458 			$classes[] = 'single-paged-' . $page;
       
   459 		elseif ( is_page() )
       
   460 			$classes[] = 'page-paged-' . $page;
       
   461 		elseif ( is_category() )
       
   462 			$classes[] = 'category-paged-' . $page;
       
   463 		elseif ( is_tag() )
       
   464 			$classes[] = 'tag-paged-' . $page;
       
   465 		elseif ( is_date() )
       
   466 			$classes[] = 'date-paged-' . $page;
       
   467 		elseif ( is_author() )
       
   468 			$classes[] = 'author-paged-' . $page;
       
   469 		elseif ( is_search() )
       
   470 			$classes[] = 'search-paged-' . $page;
       
   471 	}
       
   472 
       
   473 	if ( !empty($class) ) {
       
   474 		if ( !is_array( $class ) )
       
   475 			$class = preg_split('#\s+#', $class);
       
   476 		$classes = array_merge($classes, $class);
       
   477 	}
       
   478 
       
   479 	$classes = array_map('esc_attr', $classes);
       
   480 
       
   481 	return apply_filters('body_class', $classes, $class);
       
   482 }
       
   483 
       
   484 /**
       
   485  * Whether post requires password and correct password has been provided.
       
   486  *
       
   487  * @since 2.7.0
       
   488  *
       
   489  * @param int|object $post An optional post.  Global $post used if not provided.
       
   490  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
       
   491  */
       
   492 function post_password_required( $post = null ) {
       
   493 	$post = get_post($post);
       
   494 
       
   495 	if ( empty($post->post_password) )
       
   496 		return false;
       
   497 
       
   498 	if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
       
   499 		return true;
       
   500 
       
   501 	if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
       
   502 		return true;
       
   503 
       
   504 	return false;
       
   505 }
       
   506 
       
   507 /**
       
   508  * Display "sticky" CSS class, if a post is sticky.
       
   509  *
       
   510  * @since 2.7.0
       
   511  *
       
   512  * @param int $post_id An optional post ID.
       
   513  */
       
   514 function sticky_class( $post_id = null ) {
       
   515 	if ( !is_sticky($post_id) )
       
   516 		return;
       
   517 
       
   518 	echo " sticky";
       
   519 }
       
   520 
       
   521 /**
       
   522  * Page Template Functions for usage in Themes
       
   523  *
       
   524  * @package WordPress
       
   525  * @subpackage Template
       
   526  */
       
   527 
       
   528 /**
       
   529  * The formatted output of a list of pages.
       
   530  *
       
   531  * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
       
   532  * Quicktag one or more times). This tag must be within The Loop.
       
   533  *
       
   534  * The defaults for overwriting are:
       
   535  * 'next_or_number' - Default is 'number' (string). Indicates whether page
       
   536  *      numbers should be used. Valid values are number and next.
       
   537  * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
       
   538  *      of the bookmark.
       
   539  * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
       
   540  *      previous page, if available.
       
   541  * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
       
   542  *      the parameter string will be replaced with the page number, so Page %
       
   543  *      generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
       
   544  * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
       
   545  *      each bookmarks.
       
   546  * 'after' - Default is '</p>' (string). The html or text to append to each
       
   547  *      bookmarks.
       
   548  * 'link_before' - Default is '' (string). The html or text to prepend to each
       
   549  *      Pages link inside the <a> tag.
       
   550  * 'link_after' - Default is '' (string). The html or text to append to each
       
   551  *      Pages link inside the <a> tag.
       
   552  *
       
   553  * @since 1.2.0
       
   554  * @access private
       
   555  *
       
   556  * @param string|array $args Optional. Overwrite the defaults.
       
   557  * @return string Formatted output in HTML.
       
   558  */
       
   559 function wp_link_pages($args = '') {
       
   560 	$defaults = array(
       
   561 		'before' => '<p>' . __('Pages:'), 'after' => '</p>',
       
   562 		'link_before' => '', 'link_after' => '',
       
   563 		'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
       
   564 		'previouspagelink' => __('Previous page'), 'pagelink' => '%',
       
   565 		'echo' => 1
       
   566 	);
       
   567 
       
   568 	$r = wp_parse_args( $args, $defaults );
       
   569 	extract( $r, EXTR_SKIP );
       
   570 
       
   571 	global $post, $page, $numpages, $multipage, $more, $pagenow;
       
   572 
       
   573 	$output = '';
       
   574 	if ( $multipage ) {
       
   575 		if ( 'number' == $next_or_number ) {
       
   576 			$output .= $before;
       
   577 			for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
       
   578 				$j = str_replace('%',"$i",$pagelink);
       
   579 				$output .= ' ';
       
   580 				if ( ($i != $page) || ((!$more) && ($page==1)) ) {
       
   581 					if ( 1 == $i ) {
       
   582 						$output .= '<a href="' . get_permalink() . '">';
       
   583 					} else {
       
   584 						if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
       
   585 							$output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">';
       
   586 						else
       
   587 							$output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
       
   588 					}
       
   589 
       
   590 				}
       
   591 				$output .= $link_before;
       
   592 				$output .= $j;
       
   593 				$output .= $link_after;
       
   594 				if ( ($i != $page) || ((!$more) && ($page==1)) )
       
   595 					$output .= '</a>';
       
   596 			}
       
   597 			$output .= $after;
       
   598 		} else {
       
   599 			if ( $more ) {
       
   600 				$output .= $before;
       
   601 				$i = $page - 1;
       
   602 				if ( $i && $more ) {
       
   603 					if ( 1 == $i ) {
       
   604 						$output .= '<a href="' . get_permalink() . '">' . $link_before. $previouspagelink . $link_after . '</a>';
       
   605 					} else {
       
   606 						if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
       
   607 							$output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">' . $link_before. $previouspagelink . $link_after . '</a>';
       
   608 						else
       
   609 							$output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $previouspagelink . $link_after . '</a>';
       
   610 					}
       
   611 				}
       
   612 				$i = $page + 1;
       
   613 				if ( $i <= $numpages && $more ) {
       
   614 					if ( 1 == $i ) {
       
   615 						$output .= '<a href="' . get_permalink() . '">' . $link_before. $nextpagelink . $link_after . '</a>';
       
   616 					} else {
       
   617 						if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
       
   618 							$output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">' . $link_before. $nextpagelink . $link_after . '</a>';
       
   619 						else
       
   620 							$output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $nextpagelink . $link_after . '</a>';
       
   621 					}
       
   622 				}
       
   623 				$output .= $after;
       
   624 			}
       
   625 		}
       
   626 	}
       
   627 
       
   628 	if ( $echo )
       
   629 		echo $output;
       
   630 
       
   631 	return $output;
       
   632 }
       
   633 
       
   634 
       
   635 //
       
   636 // Post-meta: Custom per-post fields.
       
   637 //
       
   638 
       
   639 /**
       
   640  * Retrieve post custom meta data field.
       
   641  *
       
   642  * @since 1.5.0
       
   643  *
       
   644  * @param string $key Meta data key name.
       
   645  * @return string|array Array of values or single value, if only one element exists.
       
   646  */
       
   647 function post_custom( $key = '' ) {
       
   648 	$custom = get_post_custom();
       
   649 
       
   650 	if ( 1 == count($custom[$key]) )
       
   651 		return $custom[$key][0];
       
   652 	else
       
   653 		return $custom[$key];
       
   654 }
       
   655 
       
   656 /**
       
   657  * Display list of post custom fields.
       
   658  *
       
   659  * @internal This will probably change at some point...
       
   660  * @since 1.2.0
       
   661  * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
       
   662  */
       
   663 function the_meta() {
       
   664 	if ( $keys = get_post_custom_keys() ) {
       
   665 		echo "<ul class='post-meta'>\n";
       
   666 		foreach ( (array) $keys as $key ) {
       
   667 			$keyt = trim($key);
       
   668 			if ( '_' == $keyt{0} )
       
   669 				continue;
       
   670 			$values = array_map('trim', get_post_custom_values($key));
       
   671 			$value = implode($values,', ');
       
   672 			echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
       
   673 		}
       
   674 		echo "</ul>\n";
       
   675 	}
       
   676 }
       
   677 
       
   678 //
       
   679 // Pages
       
   680 //
       
   681 
       
   682 /**
       
   683  * Retrieve or display list of pages as a dropdown (select list).
       
   684  *
       
   685  * @since 2.1.0
       
   686  *
       
   687  * @param array|string $args Optional. Override default arguments.
       
   688  * @return string HTML content, if not displaying.
       
   689  */
       
   690 function wp_dropdown_pages($args = '') {
       
   691 	$defaults = array(
       
   692 		'depth' => 0, 'child_of' => 0,
       
   693 		'selected' => 0, 'echo' => 1,
       
   694 		'name' => 'page_id', 'show_option_none' => '', 'show_option_no_change' => '',
       
   695 		'option_none_value' => ''
       
   696 	);
       
   697 
       
   698 	$r = wp_parse_args( $args, $defaults );
       
   699 	extract( $r, EXTR_SKIP );
       
   700 
       
   701 	$pages = get_pages($r);
       
   702 	$output = '';
       
   703 	$name = esc_attr($name);
       
   704 
       
   705 	if ( ! empty($pages) ) {
       
   706 		$output = "<select name=\"$name\" id=\"$name\">\n";
       
   707 		if ( $show_option_no_change )
       
   708 			$output .= "\t<option value=\"-1\">$show_option_no_change</option>";
       
   709 		if ( $show_option_none )
       
   710 			$output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
       
   711 		$output .= walk_page_dropdown_tree($pages, $depth, $r);
       
   712 		$output .= "</select>\n";
       
   713 	}
       
   714 
       
   715 	$output = apply_filters('wp_dropdown_pages', $output);
       
   716 
       
   717 	if ( $echo )
       
   718 		echo $output;
       
   719 
       
   720 	return $output;
       
   721 }
       
   722 
       
   723 /**
       
   724  * Retrieve or display list of pages in list (li) format.
       
   725  *
       
   726  * @since 1.5.0
       
   727  *
       
   728  * @param array|string $args Optional. Override default arguments.
       
   729  * @return string HTML content, if not displaying.
       
   730  */
       
   731 function wp_list_pages($args = '') {
       
   732 	$defaults = array(
       
   733 		'depth' => 0, 'show_date' => '',
       
   734 		'date_format' => get_option('date_format'),
       
   735 		'child_of' => 0, 'exclude' => '',
       
   736 		'title_li' => __('Pages'), 'echo' => 1,
       
   737 		'authors' => '', 'sort_column' => 'menu_order, post_title',
       
   738 		'link_before' => '', 'link_after' => '', 'walker' => '',
       
   739 	);
       
   740 
       
   741 	$r = wp_parse_args( $args, $defaults );
       
   742 	extract( $r, EXTR_SKIP );
       
   743 
       
   744 	$output = '';
       
   745 	$current_page = 0;
       
   746 
       
   747 	// sanitize, mostly to keep spaces out
       
   748 	$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
       
   749 
       
   750 	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
       
   751 	$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
       
   752 	$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
       
   753 
       
   754 	// Query pages.
       
   755 	$r['hierarchical'] = 0;
       
   756 	$pages = get_pages($r);
       
   757 
       
   758 	if ( !empty($pages) ) {
       
   759 		if ( $r['title_li'] )
       
   760 			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
       
   761 
       
   762 		global $wp_query;
       
   763 		if ( is_page() || is_attachment() || $wp_query->is_posts_page )
       
   764 			$current_page = $wp_query->get_queried_object_id();
       
   765 		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
       
   766 
       
   767 		if ( $r['title_li'] )
       
   768 			$output .= '</ul></li>';
       
   769 	}
       
   770 
       
   771 	$output = apply_filters('wp_list_pages', $output, $r);
       
   772 
       
   773 	if ( $r['echo'] )
       
   774 		echo $output;
       
   775 	else
       
   776 		return $output;
       
   777 }
       
   778 
       
   779 /**
       
   780  * Display or retrieve list of pages with optional home link.
       
   781  *
       
   782  * The arguments are listed below and part of the arguments are for {@link
       
   783  * wp_list_pages()} function. Check that function for more info on those
       
   784  * arguments.
       
   785  *
       
   786  * <ul>
       
   787  * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
       
   788  * to page title. Use column for posts table.</li>
       
   789  * <li><strong>menu_class</strong> - Class to use for the div ID which contains
       
   790  * the page list. Defaults to 'menu'.</li>
       
   791  * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
       
   792  * echo.</li>
       
   793  * <li><strong>link_before</strong> - Text before show_home argument text.</li>
       
   794  * <li><strong>link_after</strong> - Text after show_home argument text.</li>
       
   795  * <li><strong>show_home</strong> - If you set this argument, then it will
       
   796  * display the link to the home page. The show_home argument really just needs
       
   797  * to be set to the value of the text of the link.</li>
       
   798  * </ul>
       
   799  *
       
   800  * @since 2.7.0
       
   801  *
       
   802  * @param array|string $args
       
   803  */
       
   804 function wp_page_menu( $args = array() ) {
       
   805 	$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
       
   806 	$args = wp_parse_args( $args, $defaults );
       
   807 	$args = apply_filters( 'wp_page_menu_args', $args );
       
   808 
       
   809 	$menu = '';
       
   810 
       
   811 	$list_args = $args;
       
   812 
       
   813 	// Show Home in the menu
       
   814 	if ( isset($args['show_home']) && ! empty($args['show_home']) ) {
       
   815 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
       
   816 			$text = __('Home');
       
   817 		else
       
   818 			$text = $args['show_home'];
       
   819 		$class = '';
       
   820 		if ( is_front_page() && !is_paged() )
       
   821 			$class = 'class="current_page_item"';
       
   822 		$menu .= '<li ' . $class . '><a href="' . get_option('home') . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
       
   823 		// If the front page is a page, add it to the exclude list
       
   824 		if (get_option('show_on_front') == 'page') {
       
   825 			if ( !empty( $list_args['exclude'] ) ) {
       
   826 				$list_args['exclude'] .= ',';
       
   827 			} else {
       
   828 				$list_args['exclude'] = '';
       
   829 			}
       
   830 			$list_args['exclude'] .= get_option('page_on_front');
       
   831 		}
       
   832 	}
       
   833 
       
   834 	$list_args['echo'] = false;
       
   835 	$list_args['title_li'] = '';
       
   836 	$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
       
   837 
       
   838 	if ( $menu )
       
   839 		$menu = '<ul>' . $menu . '</ul>';
       
   840 
       
   841 	$menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
       
   842 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
       
   843 	if ( $args['echo'] )
       
   844 		echo $menu;
       
   845 	else
       
   846 		return $menu;
       
   847 }
       
   848 
       
   849 //
       
   850 // Page helpers
       
   851 //
       
   852 
       
   853 /**
       
   854  * Retrieve HTML list content for page list.
       
   855  *
       
   856  * @uses Walker_Page to create HTML list content.
       
   857  * @since 2.1.0
       
   858  * @see Walker_Page::walk() for parameters and return description.
       
   859  */
       
   860 function walk_page_tree($pages, $depth, $current_page, $r) {
       
   861 	if ( empty($r['walker']) )
       
   862 		$walker = new Walker_Page;
       
   863 	else
       
   864 		$walker = $r['walker'];
       
   865 
       
   866 	$args = array($pages, $depth, $r, $current_page);
       
   867 	return call_user_func_array(array(&$walker, 'walk'), $args);
       
   868 }
       
   869 
       
   870 /**
       
   871  * Retrieve HTML dropdown (select) content for page list.
       
   872  *
       
   873  * @uses Walker_PageDropdown to create HTML dropdown content.
       
   874  * @since 2.1.0
       
   875  * @see Walker_PageDropdown::walk() for parameters and return description.
       
   876  */
       
   877 function walk_page_dropdown_tree() {
       
   878 	$args = func_get_args();
       
   879 	if ( empty($args[2]['walker']) ) // the user's options are the third parameter
       
   880 		$walker = new Walker_PageDropdown;
       
   881 	else
       
   882 		$walker = $args[2]['walker'];
       
   883 
       
   884 	return call_user_func_array(array(&$walker, 'walk'), $args);
       
   885 }
       
   886 
       
   887 //
       
   888 // Attachments
       
   889 //
       
   890 
       
   891 /**
       
   892  * Display an attachment page link using an image or icon.
       
   893  *
       
   894  * @since 2.0.0
       
   895  *
       
   896  * @param int $id Optional. Post ID.
       
   897  * @param bool $fullsize Optional, default is false. Whether to use full size.
       
   898  * @param bool $deprecated Deprecated. Not used.
       
   899  * @param bool $permalink Optional, default is false. Whether to include permalink.
       
   900  */
       
   901 function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) {
       
   902 	if ( $fullsize )
       
   903 		echo wp_get_attachment_link($id, 'full', $permalink);
       
   904 	else
       
   905 		echo wp_get_attachment_link($id, 'thumbnail', $permalink);
       
   906 }
       
   907 
       
   908 /**
       
   909  * Retrieve an attachment page link using an image or icon, if possible.
       
   910  *
       
   911  * @since 2.5.0
       
   912  * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
       
   913  *
       
   914  * @param int $id Optional. Post ID.
       
   915  * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
       
   916  * @param bool $permalink Optional, default is false. Whether to add permalink to image.
       
   917  * @param bool $icon Optional, default is false. Whether to include icon.
       
   918  * @param string $text Optional, default is false. If string, then will be link text.
       
   919  * @return string HTML content.
       
   920  */
       
   921 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
       
   922 	$id = intval($id);
       
   923 	$_post = & get_post( $id );
       
   924 
       
   925 	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
       
   926 		return __('Missing Attachment');
       
   927 
       
   928 	if ( $permalink )
       
   929 		$url = get_attachment_link($_post->ID);
       
   930 
       
   931 	$post_title = esc_attr($_post->post_title);
       
   932 
       
   933 	if ( $text ) {
       
   934 		$link_text = esc_attr($text);
       
   935 	} elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
       
   936 		$link_text = wp_get_attachment_image($id, $size, $icon);
       
   937 	}
       
   938 
       
   939 	if( trim($link_text) == '' )
       
   940 		$link_text = $_post->post_title;
       
   941 
       
   942 	return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
       
   943 }
       
   944 
       
   945 /**
       
   946  * Retrieve HTML content of attachment image with link.
       
   947  *
       
   948  * @since 2.0.0
       
   949  * @deprecated Use {@link wp_get_attachment_link()}
       
   950  * @see wp_get_attachment_link() Use instead.
       
   951  *
       
   952  * @param int $id Optional. Post ID.
       
   953  * @param bool $fullsize Optional, default is false. Whether to use full size image.
       
   954  * @param array $max_dims Optional. Max image dimensions.
       
   955  * @param bool $permalink Optional, default is false. Whether to include permalink to image.
       
   956  * @return string
       
   957  */
       
   958 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
       
   959 	$id = (int) $id;
       
   960 	$_post = & get_post($id);
       
   961 
       
   962 	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
       
   963 		return __('Missing Attachment');
       
   964 
       
   965 	if ( $permalink )
       
   966 		$url = get_attachment_link($_post->ID);
       
   967 
       
   968 	$post_title = esc_attr($_post->post_title);
       
   969 
       
   970 	$innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
       
   971 	return "<a href='$url' title='$post_title'>$innerHTML</a>";
       
   972 }
       
   973 
       
   974 /**
       
   975  * Retrieve icon URL and Path.
       
   976  *
       
   977  * @since 2.1.0
       
   978  * @deprecated Use {@link wp_get_attachment_image_src()}
       
   979  * @see wp_get_attachment_image_src() Use instead.
       
   980  *
       
   981  * @param int $id Optional. Post ID.
       
   982  * @param bool $fullsize Optional, default to false. Whether to have full image.
       
   983  * @return array Icon URL and full path to file, respectively.
       
   984  */
       
   985 function get_attachment_icon_src( $id = 0, $fullsize = false ) {
       
   986 	$id = (int) $id;
       
   987 	if ( !$post = & get_post($id) )
       
   988 		return false;
       
   989 
       
   990 	$file = get_attached_file( $post->ID );
       
   991 
       
   992 	if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
       
   993 		// We have a thumbnail desired, specified and existing
       
   994 
       
   995 		$src_file = basename($src);
       
   996 		$class = 'attachmentthumb';
       
   997 	} elseif ( wp_attachment_is_image( $post->ID ) ) {
       
   998 		// We have an image without a thumbnail
       
   999 
       
  1000 		$src = wp_get_attachment_url( $post->ID );
       
  1001 		$src_file = & $file;
       
  1002 		$class = 'attachmentimage';
       
  1003 	} elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
       
  1004 		// No thumb, no image. We'll look for a mime-related icon instead.
       
  1005 
       
  1006 		$icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
       
  1007 		$src_file = $icon_dir . '/' . basename($src);
       
  1008 	}
       
  1009 
       
  1010 	if ( !isset($src) || !$src )
       
  1011 		return false;
       
  1012 
       
  1013 	return array($src, $src_file);
       
  1014 }
       
  1015 
       
  1016 /**
       
  1017  * Retrieve HTML content of icon attachment image element.
       
  1018  *
       
  1019  * @since 2.0.0
       
  1020  * @deprecated Use {@link wp_get_attachment_image()}
       
  1021  * @see wp_get_attachment_image() Use instead of.
       
  1022  *
       
  1023  * @param int $id Optional. Post ID.
       
  1024  * @param bool $fullsize Optional, default to false. Whether to have full size image.
       
  1025  * @param array $max_dims Optional. Dimensions of image.
       
  1026  * @return string HTML content.
       
  1027  */
       
  1028 function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
       
  1029 	$id = (int) $id;
       
  1030 	if ( !$post = & get_post($id) )
       
  1031 		return false;
       
  1032 
       
  1033 	if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )
       
  1034 		return false;
       
  1035 
       
  1036 	list($src, $src_file) = $src;
       
  1037 
       
  1038 	// Do we need to constrain the image?
       
  1039 	if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
       
  1040 
       
  1041 		$imagesize = getimagesize($src_file);
       
  1042 
       
  1043 		if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
       
  1044 			$actual_aspect = $imagesize[0] / $imagesize[1];
       
  1045 			$desired_aspect = $max_dims[0] / $max_dims[1];
       
  1046 
       
  1047 			if ( $actual_aspect >= $desired_aspect ) {
       
  1048 				$height = $actual_aspect * $max_dims[0];
       
  1049 				$constraint = "width='{$max_dims[0]}' ";
       
  1050 				$post->iconsize = array($max_dims[0], $height);
       
  1051 			} else {
       
  1052 				$width = $max_dims[1] / $actual_aspect;
       
  1053 				$constraint = "height='{$max_dims[1]}' ";
       
  1054 				$post->iconsize = array($width, $max_dims[1]);
       
  1055 			}
       
  1056 		} else {
       
  1057 			$post->iconsize = array($imagesize[0], $imagesize[1]);
       
  1058 			$constraint = '';
       
  1059 		}
       
  1060 	} else {
       
  1061 		$constraint = '';
       
  1062 	}
       
  1063 
       
  1064 	$post_title = esc_attr($post->post_title);
       
  1065 
       
  1066 	$icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";
       
  1067 
       
  1068 	return apply_filters( 'attachment_icon', $icon, $post->ID );
       
  1069 }
       
  1070 
       
  1071 /**
       
  1072  * Retrieve HTML content of image element.
       
  1073  *
       
  1074  * @since 2.0.0
       
  1075  * @deprecated Use {@link wp_get_attachment_image()}
       
  1076  * @see wp_get_attachment_image() Use instead.
       
  1077  *
       
  1078  * @param int $id Optional. Post ID.
       
  1079  * @param bool $fullsize Optional, default to false. Whether to have full size image.
       
  1080  * @param array $max_dims Optional. Dimensions of image.
       
  1081  * @return string
       
  1082  */
       
  1083 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
       
  1084 	$id = (int) $id;
       
  1085 	if ( !$post = & get_post($id) )
       
  1086 		return false;
       
  1087 
       
  1088 	if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))
       
  1089 		return $innerHTML;
       
  1090 
       
  1091 
       
  1092 	$innerHTML = esc_attr($post->post_title);
       
  1093 
       
  1094 	return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
       
  1095 }
       
  1096 
       
  1097 /**
       
  1098  * Wrap attachment in <<p>> element before content.
       
  1099  *
       
  1100  * @since 2.0.0
       
  1101  * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
       
  1102  *
       
  1103  * @param string $content
       
  1104  * @return string
       
  1105  */
       
  1106 function prepend_attachment($content) {
       
  1107 	global $post;
       
  1108 
       
  1109 	if ( empty($post->post_type) || $post->post_type != 'attachment' )
       
  1110 		return $content;
       
  1111 
       
  1112 	$p = '<p class="attachment">';
       
  1113 	// show the medium sized image representation of the attachment if available, and link to the raw file
       
  1114 	$p .= wp_get_attachment_link(0, 'medium', false);
       
  1115 	$p .= '</p>';
       
  1116 	$p = apply_filters('prepend_attachment', $p);
       
  1117 
       
  1118 	return "$p\n$content";
       
  1119 }
       
  1120 
       
  1121 //
       
  1122 // Misc
       
  1123 //
       
  1124 
       
  1125 /**
       
  1126  * Retrieve protected post password form content.
       
  1127  *
       
  1128  * @since 1.0.0
       
  1129  * @uses apply_filters() Calls 'the_password_form' filter on output.
       
  1130  *
       
  1131  * @return string HTML content for password form for password protected post.
       
  1132  */
       
  1133 function get_the_password_form() {
       
  1134 	global $post;
       
  1135 	$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
       
  1136 	$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
       
  1137 	<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
       
  1138 	<p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
       
  1139 	</form>
       
  1140 	';
       
  1141 	return apply_filters('the_password_form', $output);
       
  1142 }
       
  1143 
       
  1144 /**
       
  1145  * Whether currently in a page template.
       
  1146  *
       
  1147  * This template tag allows you to determine whether or not you are in a page
       
  1148  * template. You can optional provide a template name and then the check will be
       
  1149  * specific to that template.
       
  1150  *
       
  1151  * @since 2.5.0
       
  1152  * @uses $wp_query
       
  1153  *
       
  1154  * @param string $template The specific template name if specific matching is required.
       
  1155  * @return bool False on failure, true if success.
       
  1156  */
       
  1157 function is_page_template($template = '') {
       
  1158 	if (!is_page()) {
       
  1159 		return false;
       
  1160 	}
       
  1161 
       
  1162 	global $wp_query;
       
  1163 
       
  1164 	$page = $wp_query->get_queried_object();
       
  1165 	$custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
       
  1166 	$page_template = $custom_fields[0];
       
  1167 
       
  1168 	// We have no argument passed so just see if a page_template has been specified
       
  1169 	if ( empty( $template ) ) {
       
  1170 		if (!empty( $page_template ) ) {
       
  1171 			return true;
       
  1172 		}
       
  1173 	} elseif ( $template == $page_template) {
       
  1174 		return true;
       
  1175 	}
       
  1176 
       
  1177 	return false;
       
  1178 }
       
  1179 
       
  1180 /**
       
  1181  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
       
  1182  *
       
  1183  * @package WordPress
       
  1184  * @subpackage Post_Revisions
       
  1185  * @since 2.6.0
       
  1186  *
       
  1187  * @uses date_i18n()
       
  1188  *
       
  1189  * @param int|object $revision Revision ID or revision object.
       
  1190  * @param bool $link Optional, default is true. Link to revisions's page?
       
  1191  * @return string i18n formatted datetimestamp or localized 'Current Revision'.
       
  1192  */
       
  1193 function wp_post_revision_title( $revision, $link = true ) {
       
  1194 	if ( !$revision = get_post( $revision ) )
       
  1195 		return $revision;
       
  1196 
       
  1197 	if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
       
  1198 		return false;
       
  1199 
       
  1200 	/* translators: revision date format, see http://php.net/date */
       
  1201 	$datef = _x( 'j F, Y @ G:i', 'revision date format');
       
  1202 	/* translators: 1: date */
       
  1203 	$autosavef = __( '%1$s [Autosave]' );
       
  1204 	/* translators: 1: date */
       
  1205 	$currentf  = __( '%1$s [Current Revision]' );
       
  1206 
       
  1207 	$date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
       
  1208 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
       
  1209 		$date = "<a href='$link'>$date</a>";
       
  1210 
       
  1211 	if ( !wp_is_post_revision( $revision ) )
       
  1212 		$date = sprintf( $currentf, $date );
       
  1213 	elseif ( wp_is_post_autosave( $revision ) )
       
  1214 		$date = sprintf( $autosavef, $date );
       
  1215 
       
  1216 	return $date;
       
  1217 }
       
  1218 
       
  1219 /**
       
  1220  * Display list of a post's revisions.
       
  1221  *
       
  1222  * Can output either a UL with edit links or a TABLE with diff interface, and
       
  1223  * restore action links.
       
  1224  *
       
  1225  * Second argument controls parameters:
       
  1226  *   (bool)   parent : include the parent (the "Current Revision") in the list.
       
  1227  *   (string) format : 'list' or 'form-table'.  'list' outputs UL, 'form-table'
       
  1228  *                     outputs TABLE with UI.
       
  1229  *   (int)    right  : what revision is currently being viewed - used in
       
  1230  *                     form-table format.
       
  1231  *   (int)    left   : what revision is currently being diffed against right -
       
  1232  *                     used in form-table format.
       
  1233  *
       
  1234  * @package WordPress
       
  1235  * @subpackage Post_Revisions
       
  1236  * @since 2.6.0
       
  1237  *
       
  1238  * @uses wp_get_post_revisions()
       
  1239  * @uses wp_post_revision_title()
       
  1240  * @uses get_edit_post_link()
       
  1241  * @uses get_the_author_meta()
       
  1242  *
       
  1243  * @todo split into two functions (list, form-table) ?
       
  1244  *
       
  1245  * @param int|object $post_id Post ID or post object.
       
  1246  * @param string|array $args See description {@link wp_parse_args()}.
       
  1247  * @return null
       
  1248  */
       
  1249 function wp_list_post_revisions( $post_id = 0, $args = null ) {
       
  1250 	if ( !$post = get_post( $post_id ) )
       
  1251 		return;
       
  1252 
       
  1253 	$defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
       
  1254 	extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
       
  1255 
       
  1256 	switch ( $type ) {
       
  1257 	case 'autosave' :
       
  1258 		if ( !$autosave = wp_get_post_autosave( $post->ID ) )
       
  1259 			return;
       
  1260 		$revisions = array( $autosave );
       
  1261 		break;
       
  1262 	case 'revision' : // just revisions - remove autosave later
       
  1263 	case 'all' :
       
  1264 	default :
       
  1265 		if ( !$revisions = wp_get_post_revisions( $post->ID ) )
       
  1266 			return;
       
  1267 		break;
       
  1268 	}
       
  1269 
       
  1270 	/* translators: post revision: 1: when, 2: author name */
       
  1271 	$titlef = _x( '%1$s by %2$s', 'post revision' );
       
  1272 
       
  1273 	if ( $parent )
       
  1274 		array_unshift( $revisions, $post );
       
  1275 
       
  1276 	$rows = '';
       
  1277 	$class = false;
       
  1278 	$can_edit_post = current_user_can( 'edit_post', $post->ID );
       
  1279 	foreach ( $revisions as $revision ) {
       
  1280 		if ( !current_user_can( 'read_post', $revision->ID ) )
       
  1281 			continue;
       
  1282 		if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
       
  1283 			continue;
       
  1284 
       
  1285 		$date = wp_post_revision_title( $revision );
       
  1286 		$name = get_the_author_meta( 'display_name', $revision->post_author );
       
  1287 
       
  1288 		if ( 'form-table' == $format ) {
       
  1289 			if ( $left )
       
  1290 				$left_checked = $left == $revision->ID ? ' checked="checked"' : '';
       
  1291 			else
       
  1292 				$left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
       
  1293 			$right_checked = $right == $revision->ID ? ' checked="checked"' : '';
       
  1294 
       
  1295 			$class = $class ? '' : " class='alternate'";
       
  1296 
       
  1297 			if ( $post->ID != $revision->ID && $can_edit_post )
       
  1298 				$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
       
  1299 			else
       
  1300 				$actions = '';
       
  1301 
       
  1302 			$rows .= "<tr$class>\n";
       
  1303 			$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
       
  1304 			$rows .= "\t<td>$date</td>\n";
       
  1305 			$rows .= "\t<td>$name</td>\n";
       
  1306 			$rows .= "\t<td class='action-links'>$actions</td>\n";
       
  1307 			$rows .= "</tr>\n";
       
  1308 		} else {
       
  1309 			$title = sprintf( $titlef, $date, $name );
       
  1310 			$rows .= "\t<li>$title</li>\n";
       
  1311 		}
       
  1312 	}
       
  1313 
       
  1314 	if ( 'form-table' == $format ) : ?>
       
  1315 
       
  1316 <form action="revision.php" method="get">
       
  1317 
       
  1318 <div class="tablenav">
       
  1319 	<div class="alignleft">
       
  1320 		<input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
       
  1321 		<input type="hidden" name="action" value="diff" />
       
  1322 	</div>
       
  1323 </div>
       
  1324 
       
  1325 <br class="clear" />
       
  1326 
       
  1327 <table class="widefat post-revisions" cellspacing="0">
       
  1328 	<col />
       
  1329 	<col style="width: 33%" />
       
  1330 	<col style="width: 33%" />
       
  1331 	<col style="width: 33%" />
       
  1332 <thead>
       
  1333 <tr>
       
  1334 	<th scope="col"></th>
       
  1335 	<th scope="col"><?php _e( 'Date Created' ); ?></th>
       
  1336 	<th scope="col"><?php _e( 'Author' ); ?></th>
       
  1337 	<th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
       
  1338 </tr>
       
  1339 </thead>
       
  1340 <tbody>
       
  1341 
       
  1342 <?php echo $rows; ?>
       
  1343 
       
  1344 </tbody>
       
  1345 </table>
       
  1346 
       
  1347 </form>
       
  1348 
       
  1349 <?php
       
  1350 	else :
       
  1351 		echo "<ul class='post-revisions'>\n";
       
  1352 		echo $rows;
       
  1353 		echo "</ul>";
       
  1354 	endif;
       
  1355 
       
  1356 }