WordPress 3.4
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-posts-list-table.php
1 <?php
2 /**
3  * Posts List Table class.
4  *
5  * @package WordPress
6  * @subpackage List_Table
7  * @since 3.1.0
8  * @access private
9  */
10 class WP_Posts_List_Table extends WP_List_Table {
11
12         /**
13          * Whether the items should be displayed hierarchically or linearly
14          *
15          * @since 3.1.0
16          * @var bool
17          * @access protected
18          */
19         var $hierarchical_display;
20
21         /**
22          * Holds the number of pending comments for each post
23          *
24          * @since 3.1.0
25          * @var int
26          * @access protected
27          */
28         var $comment_pending_count;
29
30         /**
31          * Holds the number of posts for this user
32          *
33          * @since 3.1.0
34          * @var int
35          * @access private
36          */
37         var $user_posts_count;
38
39         /**
40          * Holds the number of posts which are sticky.
41          *
42          * @since 3.1.0
43          * @var int
44          * @access private
45          */
46         var $sticky_posts_count = 0;
47
48         function __construct() {
49                 global $post_type_object, $wpdb;
50
51                 $post_type = get_current_screen()->post_type;
52                 $post_type_object = get_post_type_object( $post_type );
53
54                 if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
55                         $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
56                                 SELECT COUNT( 1 ) FROM $wpdb->posts
57                                 WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
58                                 AND post_author = %d
59                         ", $post_type, get_current_user_id() ) );
60
61                         if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
62                                 $_GET['author'] = get_current_user_id();
63                 }
64
65                 if ( 'post' == $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
66                         $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
67                         $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status != 'trash' AND ID IN ($sticky_posts)", $post_type ) );
68                 }
69
70                 parent::__construct( array(
71                         'plural' => 'posts',
72                 ) );
73         }
74
75         function ajax_user_can() {
76                 global $post_type_object;
77
78                 return current_user_can( $post_type_object->cap->edit_posts );
79         }
80
81         function prepare_items() {
82                 global $post_type_object, $avail_post_stati, $wp_query, $per_page, $mode;
83
84                 $avail_post_stati = wp_edit_posts_query();
85
86                 $this->hierarchical_display = ( $post_type_object->hierarchical && 'menu_order title' == $wp_query->query['orderby'] );
87
88                 $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
89
90                 $post_type = $post_type_object->name;
91                 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
92                 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
93
94                 if ( $this->hierarchical_display )
95                         $total_pages = ceil( $total_items / $per_page );
96                 else
97                         $total_pages = $wp_query->max_num_pages;
98
99                 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
100
101                 $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
102
103                 $this->set_pagination_args( array(
104                         'total_items' => $total_items,
105                         'total_pages' => $total_pages,
106                         'per_page' => $per_page
107                 ) );
108         }
109
110         function has_items() {
111                 return have_posts();
112         }
113
114         function no_items() {
115                 global $post_type_object;
116
117                 if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
118                         echo $post_type_object->labels->not_found_in_trash;
119                 else
120                         echo $post_type_object->labels->not_found;
121         }
122
123         function get_views() {
124                 global $post_type_object, $locked_post_status, $avail_post_stati;
125
126                 $post_type = $post_type_object->name;
127
128                 if ( !empty($locked_post_status) )
129                         return array();
130
131                 $status_links = array();
132                 $num_posts = wp_count_posts( $post_type, 'readable' );
133                 $class = '';
134                 $allposts = '';
135
136                 $current_user_id = get_current_user_id();
137
138                 if ( $this->user_posts_count ) {
139                         if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
140                                 $class = ' class="current"';
141                         $status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
142                         $allposts = '&all_posts=1';
143                 }
144
145                 $total_posts = array_sum( (array) $num_posts );
146
147                 // Subtract post types that are not included in the admin all list.
148                 foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
149                         $total_posts -= $num_posts->$state;
150
151                 $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
152                 $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
153
154                 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
155                         $class = '';
156
157                         $status_name = $status->name;
158
159                         if ( !in_array( $status_name, $avail_post_stati ) )
160                                 continue;
161
162                         if ( empty( $num_posts->$status_name ) )
163                                 continue;
164
165                         if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
166                                 $class = ' class="current"';
167
168                         $status_links[$status_name] = "<a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
169                 }
170
171                 if ( ! empty( $this->sticky_posts_count ) ) {
172                         $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
173
174                         $sticky_link = array( 'sticky' => "<a href='edit.php?post_type=$post_type&amp;show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' );
175
176                         // Sticky comes after Publish, or if not listed, after All.
177                         $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
178                         $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
179                 }
180
181                 return $status_links;
182         }
183
184         function get_bulk_actions() {
185                 $actions = array();
186
187                 if ( $this->is_trash )
188                         $actions['untrash'] = __( 'Restore' );
189                 else
190                         $actions['edit'] = __( 'Edit' );
191
192                 if ( $this->is_trash || !EMPTY_TRASH_DAYS )
193                         $actions['delete'] = __( 'Delete Permanently' );
194                 else
195                         $actions['trash'] = __( 'Move to Trash' );
196
197                 return $actions;
198         }
199
200         function extra_tablenav( $which ) {
201                 global $post_type_object, $cat;
202 ?>
203                 <div class="alignleft actions">
204 <?php
205                 if ( 'top' == $which && !is_singular() ) {
206
207                         $this->months_dropdown( $post_type_object->name );
208
209                         if ( is_object_in_taxonomy( $post_type_object->name, 'category' ) ) {
210                                 $dropdown_options = array(
211                                         'show_option_all' => __( 'View all categories' ),
212                                         'hide_empty' => 0,
213                                         'hierarchical' => 1,
214                                         'show_count' => 0,
215                                         'orderby' => 'name',
216                                         'selected' => $cat
217                                 );
218                                 wp_dropdown_categories( $dropdown_options );
219                         }
220                         do_action( 'restrict_manage_posts' );
221                         submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
222                 }
223
224                 if ( $this->is_trash && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
225                         submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all', false );
226                 }
227 ?>
228                 </div>
229 <?php
230         }
231
232         function current_action() {
233                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
234                         return 'delete_all';
235
236                 return parent::current_action();
237         }
238
239         function pagination( $which ) {
240                 global $post_type_object, $mode;
241
242                 parent::pagination( $which );
243
244                 if ( 'top' == $which && !$post_type_object->hierarchical )
245                         $this->view_switcher( $mode );
246         }
247
248         function get_table_classes() {
249                 global $post_type_object;
250
251                 return array( 'widefat', 'fixed', $post_type_object->hierarchical ? 'pages' : 'posts' );
252         }
253
254         function get_columns() {
255                 $screen = get_current_screen();
256
257                 if ( empty( $screen ) )
258                         $post_type = 'post';
259                 else
260                         $post_type = $screen->post_type;
261
262                 $posts_columns = array();
263
264                 $posts_columns['cb'] = '<input type="checkbox" />';
265
266                 /* translators: manage posts column name */
267                 $posts_columns['title'] = _x( 'Title', 'column name' );
268
269                 if ( post_type_supports( $post_type, 'author' ) )
270                         $posts_columns['author'] = __( 'Author' );
271
272                 if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'category' ) )
273                         $posts_columns['categories'] = __( 'Categories' );
274
275                 if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) )
276                         $posts_columns['tags'] = __( 'Tags' );
277
278                 $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
279                 if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
280                         $posts_columns['comments'] = '<span class="vers"><img alt="' . esc_attr__( 'Comments' ) . '" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></span>';
281
282                 $posts_columns['date'] = __( 'Date' );
283
284                 if ( 'page' == $post_type )
285                         $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
286                 else
287                         $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
288                 $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
289
290                 return $posts_columns;
291         }
292
293         function get_sortable_columns() {
294                 return array(
295                         'title'    => 'title',
296                         'author'   => 'author',
297                         'parent'   => 'parent',
298                         'comments' => 'comment_count',
299                         'date'     => array( 'date', true )
300                 );
301         }
302
303         function display_rows( $posts = array() ) {
304                 global $wp_query, $post_type_object, $per_page;
305
306                 if ( empty( $posts ) )
307                         $posts = $wp_query->posts;
308
309                 add_filter( 'the_title', 'esc_html' );
310
311                 if ( $this->hierarchical_display ) {
312                         $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
313                 } else {
314                         $this->_display_rows( $posts );
315                 }
316         }
317
318         function _display_rows( $posts ) {
319                 global $post, $mode;
320
321                 // Create array of post IDs.
322                 $post_ids = array();
323
324                 foreach ( $posts as $a_post )
325                         $post_ids[] = $a_post->ID;
326
327                 $this->comment_pending_count = get_pending_comments_num( $post_ids );
328
329                 foreach ( $posts as $post )
330                         $this->single_row( $post );
331         }
332
333         function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
334                 global $wpdb;
335
336                 $level = 0;
337
338                 if ( ! $pages ) {
339                         $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
340
341                         if ( ! $pages )
342                                 return false;
343                 }
344
345                 /*
346                  * arrange pages into two parts: top level pages and children_pages
347                  * children_pages is two dimensional array, eg.
348                  * children_pages[10][] contains all sub-pages whose parent is 10.
349                  * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
350                  * If searching, ignore hierarchy and treat everything as top level
351                  */
352                 if ( empty( $_REQUEST['s'] ) ) {
353
354                         $top_level_pages = array();
355                         $children_pages = array();
356
357                         foreach ( $pages as $page ) {
358
359                                 // catch and repair bad pages
360                                 if ( $page->post_parent == $page->ID ) {
361                                         $page->post_parent = 0;
362                                         $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
363                                         clean_post_cache( $page );
364                                 }
365
366                                 if ( 0 == $page->post_parent )
367                                         $top_level_pages[] = $page;
368                                 else
369                                         $children_pages[ $page->post_parent ][] = $page;
370                         }
371
372                         $pages = &$top_level_pages;
373                 }
374
375                 $count = 0;
376                 $start = ( $pagenum - 1 ) * $per_page;
377                 $end = $start + $per_page;
378
379                 foreach ( $pages as $page ) {
380                         if ( $count >= $end )
381                                 break;
382
383                         if ( $count >= $start )
384                                 echo "\t" . $this->single_row( $page, $level );
385
386                         $count++;
387
388                         if ( isset( $children_pages ) )
389                                 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
390                 }
391
392                 // if it is the last pagenum and there are orphaned pages, display them with paging as well
393                 if ( isset( $children_pages ) && $count < $end ){
394                         foreach ( $children_pages as $orphans ){
395                                 foreach ( $orphans as $op ) {
396                                         if ( $count >= $end )
397                                                 break;
398                                         if ( $count >= $start )
399                                                 echo "\t" . $this->single_row( $op, 0 );
400                                         $count++;
401                                 }
402                         }
403                 }
404         }
405
406         /**
407          * Given a top level page ID, display the nested hierarchy of sub-pages
408          * together with paging support
409          *
410          * @since 3.1.0 (Standalone function exists since 2.6.0)
411          *
412          * @param unknown_type $children_pages
413          * @param unknown_type $count
414          * @param unknown_type $parent
415          * @param unknown_type $level
416          * @param unknown_type $pagenum
417          * @param unknown_type $per_page
418          */
419         function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
420
421                 if ( ! isset( $children_pages[$parent] ) )
422                         return;
423
424                 $start = ( $pagenum - 1 ) * $per_page;
425                 $end = $start + $per_page;
426
427                 foreach ( $children_pages[$parent] as $page ) {
428
429                         if ( $count >= $end )
430                                 break;
431
432                         // If the page starts in a subtree, print the parents.
433                         if ( $count == $start && $page->post_parent > 0 ) {
434                                 $my_parents = array();
435                                 $my_parent = $page->post_parent;
436                                 while ( $my_parent ) {
437                                         $my_parent = get_post( $my_parent );
438                                         $my_parents[] = $my_parent;
439                                         if ( !$my_parent->post_parent )
440                                                 break;
441                                         $my_parent = $my_parent->post_parent;
442                                 }
443                                 $num_parents = count( $my_parents );
444                                 while ( $my_parent = array_pop( $my_parents ) ) {
445                                         echo "\t" . $this->single_row( $my_parent, $level - $num_parents );
446                                         $num_parents--;
447                                 }
448                         }
449
450                         if ( $count >= $start )
451                                 echo "\t" . $this->single_row( $page, $level );
452
453                         $count++;
454
455                         $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
456                 }
457
458                 unset( $children_pages[$parent] ); //required in order to keep track of orphans
459         }
460
461         function single_row( $a_post, $level = 0 ) {
462                 global $post, $mode;
463                 static $alternate;
464
465                 $global_post = $post;
466                 $post = $a_post;
467                 setup_postdata( $post );
468
469                 $edit_link = get_edit_post_link( $post->ID );
470                 $title = _draft_or_post_title();
471                 $post_type_object = get_post_type_object( $post->post_type );
472                 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
473
474                 $alternate = 'alternate' == $alternate ? '' : 'alternate';
475                 $classes = $alternate . ' iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
476         ?>
477                 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>" valign="top">
478         <?php
479
480                 list( $columns, $hidden ) = $this->get_column_info();
481
482                 foreach ( $columns as $column_name => $column_display_name ) {
483                         $class = "class=\"$column_name column-$column_name\"";
484
485                         $style = '';
486                         if ( in_array( $column_name, $hidden ) )
487                                 $style = ' style="display:none;"';
488
489                         $attributes = "$class$style";
490
491                         switch ( $column_name ) {
492
493                         case 'cb':
494                         ?>
495                         <th scope="row" class="check-column"><?php if ( $can_edit_post ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
496                         <?php
497                         break;
498
499                         case 'title':
500                                 if ( $this->hierarchical_display ) {
501                                         $attributes = 'class="post-title page-title column-title"' . $style;
502
503                                         if ( 0 == $level && (int) $post->post_parent > 0 ) {
504                                                 //sent level 0 by accident, by default, or because we don't know the actual level
505                                                 $find_main_page = (int) $post->post_parent;
506                                                 while ( $find_main_page > 0 ) {
507                                                         $parent = get_page( $find_main_page );
508
509                                                         if ( is_null( $parent ) )
510                                                                 break;
511
512                                                         $level++;
513                                                         $find_main_page = (int) $parent->post_parent;
514
515                                                         if ( !isset( $parent_name ) )
516                                                                 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
517                                                 }
518                                         }
519
520                                         $pad = str_repeat( '&#8212; ', $level );
521 ?>
522                         <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states( $post ); echo isset( $parent_name ) ? ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ) : ''; ?></strong>
523 <?php
524                                 }
525                                 else {
526                                         $attributes = 'class="post-title page-title column-title"' . $style;
527 ?>
528                         <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states( $post ); ?></strong>
529 <?php
530                                         if ( 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
531                                                 the_excerpt();
532                                 }
533
534                                 $actions = array();
535                                 if ( $can_edit_post && 'trash' != $post->post_status ) {
536                                         $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
537                                         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
538                                 }
539                                 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
540                                         if ( 'trash' == $post->post_status )
541                                                 $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
542                                         elseif ( EMPTY_TRASH_DAYS )
543                                                 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
544                                         if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
545                                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
546                                 }
547                                 if ( $post_type_object->public ) {
548                                         if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
549                                                 if ( $can_edit_post )
550                                                         $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
551                                         } elseif ( 'trash' != $post->post_status ) {
552                                                 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
553                                         }
554                                 }
555
556                                 $actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post );
557                                 echo $this->row_actions( $actions );
558
559                                 get_inline_data( $post );
560                                 echo '</td>';
561                         break;
562
563                         case 'date':
564                                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
565                                         $t_time = $h_time = __( 'Unpublished' );
566                                         $time_diff = 0;
567                                 } else {
568                                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
569                                         $m_time = $post->post_date;
570                                         $time = get_post_time( 'G', true, $post );
571
572                                         $time_diff = time() - $time;
573
574                                         if ( $time_diff > 0 && $time_diff < 24*60*60 )
575                                                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
576                                         else
577                                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
578                                 }
579
580                                 echo '<td ' . $attributes . '>';
581                                 if ( 'excerpt' == $mode )
582                                         echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
583                                 else
584                                         echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
585                                 echo '<br />';
586                                 if ( 'publish' == $post->post_status ) {
587                                         _e( 'Published' );
588                                 } elseif ( 'future' == $post->post_status ) {
589                                         if ( $time_diff > 0 )
590                                                 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
591                                         else
592                                                 _e( 'Scheduled' );
593                                 } else {
594                                         _e( 'Last Modified' );
595                                 }
596                                 echo '</td>';
597                         break;
598
599                         case 'categories':
600                         ?>
601                         <td <?php echo $attributes ?>><?php
602                                 $categories = get_the_category();
603                                 if ( !empty( $categories ) ) {
604                                         $out = array();
605                                         foreach ( $categories as $c ) {
606                                                 $out[] = sprintf( '<a href="%s">%s</a>',
607                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'category_name' => $c->slug ), 'edit.php' ) ),
608                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) )
609                                                 );
610                                         }
611                                         /* translators: used between list items, there is a space after the comma */
612                                         echo join( __( ', ' ), $out );
613                                 } else {
614                                         _e( 'Uncategorized' );
615                                 }
616                         ?></td>
617                         <?php
618                         break;
619
620                         case 'tags':
621                         ?>
622                         <td <?php echo $attributes ?>><?php
623                                 $tags = get_the_tags( $post->ID );
624                                 if ( !empty( $tags ) ) {
625                                         $out = array();
626                                         foreach ( $tags as $c ) {
627                                                 $out[] = sprintf( '<a href="%s">%s</a>',
628                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'tag' => $c->slug ), 'edit.php' ) ),
629                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) )
630                                                 );
631                                         }
632                                         /* translators: used between list items, there is a space after the comma */
633                                         echo join( __( ', ' ), $out );
634                                 } else {
635                                         _e( 'No Tags' );
636                                 }
637                         ?></td>
638                         <?php
639                         break;
640
641                         case 'comments':
642                         ?>
643                         <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
644                         <?php
645                                 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
646
647                                 $this->comments_bubble( $post->ID, $pending_comments );
648                         ?>
649                         </div></td>
650                         <?php
651                         break;
652
653                         case 'author':
654                         ?>
655                         <td <?php echo $attributes ?>><?php
656                                 printf( '<a href="%s">%s</a>',
657                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
658                                         get_the_author()
659                                 );
660                         ?></td>
661                         <?php
662                         break;
663
664                         default:
665                         ?>
666                         <td <?php echo $attributes ?>><?php
667                                 if ( is_post_type_hierarchical( $post->post_type ) )
668                                         do_action( 'manage_pages_custom_column', $column_name, $post->ID );
669                                 else
670                                         do_action( 'manage_posts_custom_column', $column_name, $post->ID );
671                                 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
672                         ?></td>
673                         <?php
674                         break;
675                 }
676         }
677         ?>
678                 </tr>
679         <?php
680                 $post = $global_post;
681         }
682
683         /**
684          * Outputs the hidden row displayed when inline editing
685          *
686          * @since 3.1.0
687          */
688         function inline_edit() {
689                 global $mode;
690
691                 $screen = get_current_screen();
692
693                 $post = get_default_post_to_edit( $screen->post_type );
694                 $post_type_object = get_post_type_object( $screen->post_type );
695
696                 $taxonomy_names = get_object_taxonomies( $screen->post_type );
697                 $hierarchical_taxonomies = array();
698                 $flat_taxonomies = array();
699                 foreach ( $taxonomy_names as $taxonomy_name ) {
700                         $taxonomy = get_taxonomy( $taxonomy_name );
701
702                         if ( !$taxonomy->show_ui )
703                                 continue;
704
705                         if ( $taxonomy->hierarchical )
706                                 $hierarchical_taxonomies[] = $taxonomy;
707                         else
708                                 $flat_taxonomies[] = $taxonomy;
709                 }
710
711                 $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
712                 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
713                 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
714
715         ?>
716
717         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
718                 <?php
719                 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
720                 $bulk = 0;
721                 while ( $bulk < 2 ) { ?>
722
723                 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
724                         echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type";
725                 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
726
727                 <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
728                         <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
729         <?php
730
731         if ( post_type_supports( $screen->post_type, 'title' ) ) :
732                 if ( $bulk ) : ?>
733                         <div id="bulk-title-div">
734                                 <div id="bulk-titles"></div>
735                         </div>
736
737         <?php else : // $bulk ?>
738
739                         <label>
740                                 <span class="title"><?php _e( 'Title' ); ?></span>
741                                 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
742                         </label>
743
744                         <label>
745                                 <span class="title"><?php _e( 'Slug' ); ?></span>
746                                 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
747                         </label>
748
749         <?php endif; // $bulk
750         endif; // post_type_supports title ?>
751
752         <?php if ( !$bulk ) : ?>
753                         <label><span class="title"><?php _e( 'Date' ); ?></span></label>
754                         <div class="inline-edit-date">
755                                 <?php touch_time( 1, 1, 4, 1 ); ?>
756                         </div>
757                         <br class="clear" />
758         <?php endif; // $bulk
759
760                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
761                         $authors_dropdown = '';
762
763                         if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
764                                 $users_opt = array(
765                                         'hide_if_only_one_author' => false,
766                                         'who' => 'authors',
767                                         'name' => 'post_author',
768                                         'class'=> 'authors',
769                                         'multi' => 1,
770                                         'echo' => 0
771                                 );
772                                 if ( $bulk )
773                                         $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
774
775                                 if ( $authors = wp_dropdown_users( $users_opt ) ) :
776                                         $authors_dropdown  = '<label class="inline-edit-author">';
777                                         $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
778                                         $authors_dropdown .= $authors;
779                                         $authors_dropdown .= '</label>';
780                                 endif;
781                         endif; // authors
782         ?>
783
784         <?php if ( !$bulk ) echo $authors_dropdown;
785         endif; // post_type_supports author
786
787         if ( !$bulk ) :
788         ?>
789
790                         <div class="inline-edit-group">
791                                 <label class="alignleft">
792                                         <span class="title"><?php _e( 'Password' ); ?></span>
793                                         <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
794                                 </label>
795
796                                 <em style="margin:5px 10px 0 0" class="alignleft">
797                                         <?php
798                                         /* translators: Between password field and private checkbox on post quick edit interface */
799                                         echo __( '&ndash;OR&ndash;' );
800                                         ?>
801                                 </em>
802                                 <label class="alignleft inline-edit-private">
803                                         <input type="checkbox" name="keep_private" value="private" />
804                                         <span class="checkbox-title"><?php echo __( 'Private' ); ?></span>
805                                 </label>
806                         </div>
807
808         <?php endif; ?>
809
810                 </div></fieldset>
811
812         <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
813
814                 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
815
816         <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
817
818                         <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?>
819                                 <span class="catshow"><?php _e( '[more]' ); ?></span>
820                                 <span class="cathide" style="display:none;"><?php _e( '[less]' ); ?></span>
821                         </span>
822                         <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
823                         <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
824                                 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
825                         </ul>
826
827         <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
828
829                 </div></fieldset>
830
831         <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
832
833                 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
834
835         <?php
836                 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
837                         echo $authors_dropdown;
838
839                 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
840
841                         if ( $post_type_object->hierarchical ) :
842                 ?>
843                         <label>
844                                 <span class="title"><?php _e( 'Parent' ); ?></span>
845         <?php
846                 $dropdown_args = array(
847                         'post_type'         => $post_type_object->name,
848                         'selected'          => $post->post_parent,
849                         'name'              => 'post_parent',
850                         'show_option_none'  => __( 'Main Page (no parent)' ),
851                         'option_none_value' => 0,
852                         'sort_column'       => 'menu_order, post_title',
853                 );
854
855                 if ( $bulk )
856                         $dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
857                 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
858                 wp_dropdown_pages( $dropdown_args );
859         ?>
860                         </label>
861
862         <?php
863                         endif; // hierarchical
864
865                         if ( !$bulk ) : ?>
866
867                         <label>
868                                 <span class="title"><?php _e( 'Order' ); ?></span>
869                                 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
870                         </label>
871
872         <?php   endif; // !$bulk
873
874                         if ( 'page' == $screen->post_type ) :
875         ?>
876
877                         <label>
878                                 <span class="title"><?php _e( 'Template' ); ?></span>
879                                 <select name="page_template">
880         <?php   if ( $bulk ) : ?>
881                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
882         <?php   endif; // $bulk ?>
883                                         <option value="default"><?php _e( 'Default Template' ); ?></option>
884                                         <?php page_template_dropdown() ?>
885                                 </select>
886                         </label>
887
888         <?php
889                         endif; // page post_type
890                 endif; // page-attributes
891         ?>
892
893         <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
894
895         <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
896                 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
897                         <label class="inline-edit-tags">
898                                 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
899                                 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
900                         </label>
901                 <?php endif; ?>
902
903         <?php endforeach; //$flat_taxonomies as $taxonomy ?>
904
905         <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
906
907         <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
908                 if ( $bulk ) : ?>
909
910                         <div class="inline-edit-group">
911                 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
912                         <label class="alignleft">
913                                 <span class="title"><?php _e( 'Comments' ); ?></span>
914                                 <select name="comment_status">
915                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
916                                         <option value="open"><?php _e( 'Allow' ); ?></option>
917                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
918                                 </select>
919                         </label>
920                 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
921                         <label class="alignright">
922                                 <span class="title"><?php _e( 'Pings' ); ?></span>
923                                 <select name="ping_status">
924                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
925                                         <option value="open"><?php _e( 'Allow' ); ?></option>
926                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
927                                 </select>
928                         </label>
929                 <?php endif; ?>
930                         </div>
931
932         <?php else : // $bulk ?>
933
934                         <div class="inline-edit-group">
935                         <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
936                                 <label class="alignleft">
937                                         <input type="checkbox" name="comment_status" value="open" />
938                                         <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
939                                 </label>
940                         <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
941                                 <label class="alignleft">
942                                         <input type="checkbox" name="ping_status" value="open" />
943                                         <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
944                                 </label>
945                         <?php endif; ?>
946                         </div>
947
948         <?php endif; // $bulk
949         endif; // post_type_supports comments or pings ?>
950
951                         <div class="inline-edit-group">
952                                 <label class="inline-edit-status alignleft">
953                                         <span class="title"><?php _e( 'Status' ); ?></span>
954                                         <select name="_status">
955         <?php if ( $bulk ) : ?>
956                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
957         <?php endif; // $bulk ?>
958                                         <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
959                                                 <option value="publish"><?php _e( 'Published' ); ?></option>
960                                                 <option value="future"><?php _e( 'Scheduled' ); ?></option>
961         <?php if ( $bulk ) : ?>
962                                                 <option value="private"><?php _e( 'Private' ) ?></option>
963         <?php endif; // $bulk ?>
964                                         <?php endif; ?>
965                                                 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
966                                                 <option value="draft"><?php _e( 'Draft' ); ?></option>
967                                         </select>
968                                 </label>
969
970         <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
971
972         <?php   if ( $bulk ) : ?>
973
974                                 <label class="alignright">
975                                         <span class="title"><?php _e( 'Sticky' ); ?></span>
976                                         <select name="sticky">
977                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
978                                                 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
979                                                 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
980                                         </select>
981                                 </label>
982
983         <?php   else : // $bulk ?>
984
985                                 <label class="alignleft">
986                                         <input type="checkbox" name="sticky" value="sticky" />
987                                         <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
988                                 </label>
989
990         <?php   endif; // $bulk ?>
991
992         <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
993
994                         </div>
995
996         <?php if ( post_type_supports( $screen->post_type, 'post-formats' ) && current_theme_supports( 'post-formats' ) ) :
997                 $post_formats = get_theme_support( 'post-formats' );
998                 if ( isset( $post_formats[0] ) && is_array( $post_formats[0] ) ) :
999                         $all_post_formats = get_post_format_strings();
1000                         unset( $all_post_formats['standard'] ); ?>
1001                         <div class="inline-edit-group">
1002                                 <label class="alignleft" for="post_format">
1003                                 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1004                                 <select name="post_format">
1005                                 <?php if ( $bulk ) : ?>
1006                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1007                                 <?php endif; ?>
1008                                         <option value="0"><?php _ex( 'Standard', 'Post format' ); ?></option>
1009                                 <?php foreach ( $all_post_formats as $slug => $format ) :
1010                                         $unsupported = ! in_array( $slug, $post_formats[0] );
1011                                         if ( $bulk && $unsupported )
1012                                                 continue;
1013                                         ?>
1014                                         <option value="<?php echo esc_attr( $slug ); ?>"<?php if ( $unsupported ) echo ' class="unsupported"'; ?>><?php echo esc_html( $format ); ?></option>
1015                                 <?php endforeach; ?>
1016                                 </select></label>
1017                         </div>
1018                 <?php endif; ?>
1019         <?php endif; // post-formats ?>
1020
1021                 </div></fieldset>
1022
1023         <?php
1024                 list( $columns ) = $this->get_column_info();
1025
1026                 foreach ( $columns as $column_name => $column_display_name ) {
1027                         if ( isset( $core_columns[$column_name] ) )
1028                                 continue;
1029                         do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
1030                 }
1031         ?>
1032                 <p class="submit inline-edit-save">
1033                         <a accesskey="c" href="#inline-edit" title="<?php esc_attr_e( 'Cancel' ); ?>" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
1034                         <?php if ( ! $bulk ) {
1035                                 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1036                                 $update_text = __( 'Update' );
1037                                 ?>
1038                                 <a accesskey="s" href="#inline-edit" title="<?php esc_attr_e( 'Update' ); ?>" class="button-primary save alignright"><?php echo esc_attr( $update_text ); ?></a>
1039                                 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1040                         <?php } else {
1041                                 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
1042                         } ?>
1043                         <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1044                         <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1045                         <span class="error" style="display:none"></span>
1046                         <br class="clear" />
1047                 </p>
1048                 </td></tr>
1049         <?php
1050                 $bulk++;
1051                 }
1052 ?>
1053                 </tbody></table></form>
1054 <?php
1055         }
1056 }