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