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