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