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