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