]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-posts-list-table.php
WordPress 3.8-scripts
[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                 if ( $post->post_parent ) {
496                     $count = count( get_post_ancestors( $post->ID ) );
497                     $classes .= ' level-'. $count;
498                 } else {
499                     $classes .= ' level-0';
500                 }
501         ?>
502                 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>" valign="top">
503         <?php
504
505                 list( $columns, $hidden ) = $this->get_column_info();
506
507                 foreach ( $columns as $column_name => $column_display_name ) {
508                         $class = "class=\"$column_name column-$column_name\"";
509
510                         $style = '';
511                         if ( in_array( $column_name, $hidden ) )
512                                 $style = ' style="display:none;"';
513
514                         $attributes = "$class$style";
515
516                         switch ( $column_name ) {
517
518                         case 'cb':
519                         ?>
520                         <th scope="row" class="check-column">
521                                 <?php
522                                 if ( $can_edit_post ) {
523
524                                 ?>
525                                 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label>
526                                 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
527                                 <div class="locked-indicator"></div>
528                                 <?php
529                                 }
530                                 ?>
531                         </th>
532                         <?php
533                         break;
534
535                         case 'title':
536                                 $attributes = 'class="post-title page-title column-title"' . $style;
537                                 if ( $this->hierarchical_display ) {
538                                         if ( 0 == $level && (int) $post->post_parent > 0 ) {
539                                                 //sent level 0 by accident, by default, or because we don't know the actual level
540                                                 $find_main_page = (int) $post->post_parent;
541                                                 while ( $find_main_page > 0 ) {
542                                                         $parent = get_post( $find_main_page );
543
544                                                         if ( is_null( $parent ) )
545                                                                 break;
546
547                                                         $level++;
548                                                         $find_main_page = (int) $parent->post_parent;
549
550                                                         if ( !isset( $parent_name ) ) {
551                                                                 /** This filter is documented in wp-includes/post-template.php */
552                                                                 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
553                                                         }
554                                                 }
555                                         }
556                                 }
557
558                                 $pad = str_repeat( '&#8212; ', $level );
559                                 echo "<td $attributes><strong>";
560
561                                 if ( $format = get_post_format( $post->ID ) ) {
562                                         $label = get_post_format_string( $format );
563
564                                         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> ";
565                                 }
566
567                                 if ( $can_edit_post && $post->post_status != 'trash' ) {
568                                         echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title . '</a>';
569                                 } else {
570                                         echo $pad . $title;
571                                 }
572                                 _post_states( $post );
573
574                                 if ( isset( $parent_name ) )
575                                         echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
576
577                                 echo "</strong>\n";
578
579                                 if ( $can_edit_post && $post->post_status != 'trash' ) {
580                                         if ( $lock_holder ) {
581                                                 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
582                                                 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
583                                         } else {
584                                                 $locked_avatar = $locked_text = '';
585                                         }
586
587                                         echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
588                                 }
589
590                                 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
591                                                 the_excerpt();
592
593                                 $actions = array();
594                                 if ( $can_edit_post && 'trash' != $post->post_status ) {
595                                         $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
596                                         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
597                                 }
598                                 if ( current_user_can( 'delete_post', $post->ID ) ) {
599                                         if ( 'trash' == $post->post_status )
600                                                 $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>";
601                                         elseif ( EMPTY_TRASH_DAYS )
602                                                 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
603                                         if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
604                                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
605                                 }
606                                 if ( $post_type_object->public ) {
607                                         if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
608                                                 if ( $can_edit_post )
609                                                         $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>';
610                                         } elseif ( 'trash' != $post->post_status ) {
611                                                 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
612                                         }
613                                 }
614
615                                 $actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post );
616                                 echo $this->row_actions( $actions );
617
618                                 get_inline_data( $post );
619                                 echo '</td>';
620                         break;
621
622                         case 'date':
623                                 if ( '0000-00-00 00:00:00' == $post->post_date ) {
624                                         $t_time = $h_time = __( 'Unpublished' );
625                                         $time_diff = 0;
626                                 } else {
627                                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
628                                         $m_time = $post->post_date;
629                                         $time = get_post_time( 'G', true, $post );
630
631                                         $time_diff = time() - $time;
632
633                                         if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS )
634                                                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
635                                         else
636                                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
637                                 }
638
639                                 echo '<td ' . $attributes . '>';
640                                 if ( 'excerpt' == $mode )
641                                         echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
642                                 else
643                                         echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
644                                 echo '<br />';
645                                 if ( 'publish' == $post->post_status ) {
646                                         _e( 'Published' );
647                                 } elseif ( 'future' == $post->post_status ) {
648                                         if ( $time_diff > 0 )
649                                                 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
650                                         else
651                                                 _e( 'Scheduled' );
652                                 } else {
653                                         _e( 'Last Modified' );
654                                 }
655                                 echo '</td>';
656                         break;
657
658                         case 'comments':
659                         ?>
660                         <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
661                         <?php
662                                 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
663
664                                 $this->comments_bubble( $post->ID, $pending_comments );
665                         ?>
666                         </div></td>
667                         <?php
668                         break;
669
670                         case 'author':
671                         ?>
672                         <td <?php echo $attributes ?>><?php
673                                 printf( '<a href="%s">%s</a>',
674                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
675                                         get_the_author()
676                                 );
677                         ?></td>
678                         <?php
679                         break;
680
681                         default:
682                                 if ( 'categories' == $column_name )
683                                         $taxonomy = 'category';
684                                 elseif ( 'tags' == $column_name )
685                                         $taxonomy = 'post_tag';
686                                 elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
687                                         $taxonomy = substr( $column_name, 9 );
688                                 else
689                                         $taxonomy = false;
690
691                                 if ( $taxonomy ) {
692                                         $taxonomy_object = get_taxonomy( $taxonomy );
693                                         echo '<td ' . $attributes . '>';
694                                         if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
695                                                 $out = array();
696                                                 foreach ( $terms as $t ) {
697                                                         $posts_in_term_qv = array();
698                                                         if ( 'post' != $post->post_type )
699                                                                 $posts_in_term_qv['post_type'] = $post->post_type;
700                                                         if ( $taxonomy_object->query_var ) {
701                                                                 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
702                                                         } else {
703                                                                 $posts_in_term_qv['taxonomy'] = $taxonomy;
704                                                                 $posts_in_term_qv['term'] = $t->slug;
705                                                         }
706
707                                                         $out[] = sprintf( '<a href="%s">%s</a>',
708                                                                 esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
709                                                                 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
710                                                         );
711                                                 }
712                                                 /* translators: used between list items, there is a space after the comma */
713                                                 echo join( __( ', ' ), $out );
714                                         } else {
715                                                 echo '&#8212;';
716                                         }
717                                         echo '</td>';
718                                         break;
719                                 }
720                         ?>
721                         <td <?php echo $attributes ?>><?php
722                                 if ( is_post_type_hierarchical( $post->post_type ) )
723                                         do_action( 'manage_pages_custom_column', $column_name, $post->ID );
724                                 else
725                                         do_action( 'manage_posts_custom_column', $column_name, $post->ID );
726                                 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
727                         ?></td>
728                         <?php
729                         break;
730                         }
731                 }
732         ?>
733                 </tr>
734         <?php
735                 $GLOBALS['post'] = $global_post;
736         }
737
738         /**
739          * Outputs the hidden row displayed when inline editing
740          *
741          * @since 3.1.0
742          */
743         function inline_edit() {
744                 global $mode;
745
746                 $screen = $this->screen;
747
748                 $post = get_default_post_to_edit( $screen->post_type );
749                 $post_type_object = get_post_type_object( $screen->post_type );
750
751                 $taxonomy_names = get_object_taxonomies( $screen->post_type );
752                 $hierarchical_taxonomies = array();
753                 $flat_taxonomies = array();
754                 foreach ( $taxonomy_names as $taxonomy_name ) {
755                         $taxonomy = get_taxonomy( $taxonomy_name );
756
757                         if ( !$taxonomy->show_ui )
758                                 continue;
759
760                         if ( $taxonomy->hierarchical )
761                                 $hierarchical_taxonomies[] = $taxonomy;
762                         else
763                                 $flat_taxonomies[] = $taxonomy;
764                 }
765
766                 $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
767                 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
768                 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
769
770         ?>
771
772         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
773                 <?php
774                 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
775                 $bulk = 0;
776                 while ( $bulk < 2 ) { ?>
777
778                 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
779                         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}";
780                 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
781
782                 <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
783                         <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
784         <?php
785
786         if ( post_type_supports( $screen->post_type, 'title' ) ) :
787                 if ( $bulk ) : ?>
788                         <div id="bulk-title-div">
789                                 <div id="bulk-titles"></div>
790                         </div>
791
792         <?php else : // $bulk ?>
793
794                         <label>
795                                 <span class="title"><?php _e( 'Title' ); ?></span>
796                                 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
797                         </label>
798
799                         <label>
800                                 <span class="title"><?php _e( 'Slug' ); ?></span>
801                                 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
802                         </label>
803
804         <?php endif; // $bulk
805         endif; // post_type_supports title ?>
806
807         <?php if ( !$bulk ) : ?>
808                         <label><span class="title"><?php _e( 'Date' ); ?></span></label>
809                         <div class="inline-edit-date">
810                                 <?php touch_time( 1, 1, 0, 1 ); ?>
811                         </div>
812                         <br class="clear" />
813         <?php endif; // $bulk
814
815                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
816                         $authors_dropdown = '';
817
818                         if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
819                                 $users_opt = array(
820                                         'hide_if_only_one_author' => false,
821                                         'who' => 'authors',
822                                         'name' => 'post_author',
823                                         'class'=> 'authors',
824                                         'multi' => 1,
825                                         'echo' => 0
826                                 );
827                                 if ( $bulk )
828                                         $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
829
830                                 if ( $authors = wp_dropdown_users( $users_opt ) ) :
831                                         $authors_dropdown  = '<label class="inline-edit-author">';
832                                         $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
833                                         $authors_dropdown .= $authors;
834                                         $authors_dropdown .= '</label>';
835                                 endif;
836                         endif; // authors
837         ?>
838
839         <?php if ( !$bulk ) echo $authors_dropdown;
840         endif; // post_type_supports author
841
842         if ( !$bulk ) :
843         ?>
844
845                         <div class="inline-edit-group">
846                                 <label class="alignleft">
847                                         <span class="title"><?php _e( 'Password' ); ?></span>
848                                         <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
849                                 </label>
850
851                                 <em style="margin:5px 10px 0 0" class="alignleft">
852                                         <?php
853                                         /* translators: Between password field and private checkbox on post quick edit interface */
854                                         echo __( '&ndash;OR&ndash;' );
855                                         ?>
856                                 </em>
857                                 <label class="alignleft inline-edit-private">
858                                         <input type="checkbox" name="keep_private" value="private" />
859                                         <span class="checkbox-title"><?php echo __( 'Private' ); ?></span>
860                                 </label>
861                         </div>
862
863         <?php endif; ?>
864
865                 </div></fieldset>
866
867         <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
868
869                 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
870
871         <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
872
873                         <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
874                         <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
875                         <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
876                                 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
877                         </ul>
878
879         <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
880
881                 </div></fieldset>
882
883         <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
884
885                 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
886
887         <?php
888                 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
889                         echo $authors_dropdown;
890
891                 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
892
893                         if ( $post_type_object->hierarchical ) :
894                 ?>
895                         <label>
896                                 <span class="title"><?php _e( 'Parent' ); ?></span>
897         <?php
898                 $dropdown_args = array(
899                         'post_type'         => $post_type_object->name,
900                         'selected'          => $post->post_parent,
901                         'name'              => 'post_parent',
902                         'show_option_none'  => __( 'Main Page (no parent)' ),
903                         'option_none_value' => 0,
904                         'sort_column'       => 'menu_order, post_title',
905                 );
906
907                 if ( $bulk )
908                         $dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
909                 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
910                 wp_dropdown_pages( $dropdown_args );
911         ?>
912                         </label>
913
914         <?php
915                         endif; // hierarchical
916
917                         if ( !$bulk ) : ?>
918
919                         <label>
920                                 <span class="title"><?php _e( 'Order' ); ?></span>
921                                 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
922                         </label>
923
924         <?php   endif; // !$bulk
925
926                         if ( 'page' == $screen->post_type ) :
927         ?>
928
929                         <label>
930                                 <span class="title"><?php _e( 'Template' ); ?></span>
931                                 <select name="page_template">
932         <?php   if ( $bulk ) : ?>
933                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
934         <?php   endif; // $bulk ?>
935                                         <option value="default"><?php _e( 'Default Template' ); ?></option>
936                                         <?php page_template_dropdown() ?>
937                                 </select>
938                         </label>
939
940         <?php
941                         endif; // page post_type
942                 endif; // page-attributes
943         ?>
944
945         <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
946
947         <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
948                 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
949                         <label class="inline-edit-tags">
950                                 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
951                                 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
952                         </label>
953                 <?php endif; ?>
954
955         <?php endforeach; //$flat_taxonomies as $taxonomy ?>
956
957         <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
958
959         <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
960                 if ( $bulk ) : ?>
961
962                         <div class="inline-edit-group">
963                 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
964                         <label class="alignleft">
965                                 <span class="title"><?php _e( 'Comments' ); ?></span>
966                                 <select name="comment_status">
967                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
968                                         <option value="open"><?php _e( 'Allow' ); ?></option>
969                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
970                                 </select>
971                         </label>
972                 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
973                         <label class="alignright">
974                                 <span class="title"><?php _e( 'Pings' ); ?></span>
975                                 <select name="ping_status">
976                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
977                                         <option value="open"><?php _e( 'Allow' ); ?></option>
978                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
979                                 </select>
980                         </label>
981                 <?php endif; ?>
982                         </div>
983
984         <?php else : // $bulk ?>
985
986                         <div class="inline-edit-group">
987                         <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
988                                 <label class="alignleft">
989                                         <input type="checkbox" name="comment_status" value="open" />
990                                         <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
991                                 </label>
992                         <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
993                                 <label class="alignleft">
994                                         <input type="checkbox" name="ping_status" value="open" />
995                                         <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
996                                 </label>
997                         <?php endif; ?>
998                         </div>
999
1000         <?php endif; // $bulk
1001         endif; // post_type_supports comments or pings ?>
1002
1003                         <div class="inline-edit-group">
1004                                 <label class="inline-edit-status alignleft">
1005                                         <span class="title"><?php _e( 'Status' ); ?></span>
1006                                         <select name="_status">
1007         <?php if ( $bulk ) : ?>
1008                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1009         <?php endif; // $bulk ?>
1010                                         <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1011                                                 <option value="publish"><?php _e( 'Published' ); ?></option>
1012                                                 <option value="future"><?php _e( 'Scheduled' ); ?></option>
1013         <?php if ( $bulk ) : ?>
1014                                                 <option value="private"><?php _e( 'Private' ) ?></option>
1015         <?php endif; // $bulk ?>
1016                                         <?php endif; ?>
1017                                                 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1018                                                 <option value="draft"><?php _e( 'Draft' ); ?></option>
1019                                         </select>
1020                                 </label>
1021
1022         <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1023
1024         <?php   if ( $bulk ) : ?>
1025
1026                                 <label class="alignright">
1027                                         <span class="title"><?php _e( 'Sticky' ); ?></span>
1028                                         <select name="sticky">
1029                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1030                                                 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1031                                                 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1032                                         </select>
1033                                 </label>
1034
1035         <?php   else : // $bulk ?>
1036
1037                                 <label class="alignleft">
1038                                         <input type="checkbox" name="sticky" value="sticky" />
1039                                         <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1040                                 </label>
1041
1042         <?php   endif; // $bulk ?>
1043
1044         <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1045
1046                         </div>
1047
1048         <?php
1049
1050         if ( $bulk && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1051                 $all_post_formats = get_post_format_strings();
1052
1053                 ?>
1054                 <label class="alignleft" for="post_format">
1055                 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1056                 <select name="post_format">
1057                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1058                         <?php
1059
1060                         foreach ( $all_post_formats as $slug => $format ) {
1061                                 ?>
1062                                 <option value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $format ); ?></option>
1063                                 <?php
1064                         }
1065
1066                         ?>
1067                 </select></label>
1068         <?php
1069
1070         }
1071
1072         ?>
1073
1074                 </div></fieldset>
1075
1076         <?php
1077                 list( $columns ) = $this->get_column_info();
1078
1079                 foreach ( $columns as $column_name => $column_display_name ) {
1080                         if ( isset( $core_columns[$column_name] ) )
1081                                 continue;
1082                         do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
1083                 }
1084         ?>
1085                 <p class="submit inline-edit-save">
1086                         <a accesskey="c" href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
1087                         <?php if ( ! $bulk ) {
1088                                 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1089                                 ?>
1090                                 <a accesskey="s" href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
1091                                 <span class="spinner"></span>
1092                         <?php } else {
1093                                 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
1094                         } ?>
1095                         <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1096                         <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1097                         <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1098                                 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1099                         <?php } ?>
1100                         <span class="error" style="display:none"></span>
1101                         <br class="clear" />
1102                 </p>
1103                 </td></tr>
1104         <?php
1105                 $bulk++;
1106                 }
1107 ?>
1108                 </tbody></table></form>
1109 <?php
1110         }
1111 }