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