]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-posts-list-table.php
Wordpress 3.1-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                 if ( $this->hierarchical_display ) {
314                         $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
315                 } else {
316                         $this->_display_rows( $posts );
317                 }
318         }
319
320         function _display_rows( $posts ) {
321                 global $post, $mode;
322
323                 add_filter( 'the_title', 'esc_html' );
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                                         $post->post_title = esc_html( $post->post_title );
526                                         $pad = str_repeat( '&#8212; ', $level );
527 ?>
528                         <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>
529 <?php
530                                 }
531                                 else {
532                                         $attributes = 'class="post-title page-title column-title"' . $style;
533 ?>
534                         <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>
535 <?php
536                                         if ( 'excerpt' == $mode ) {
537                                                 the_excerpt();
538                                         }
539                                 }
540
541                                 $actions = array();
542                                 if ( $can_edit_post && 'trash' != $post->post_status ) {
543                                         $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
544                                         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
545                                 }
546                                 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
547                                         if ( 'trash' == $post->post_status )
548                                                 $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>";
549                                         elseif ( EMPTY_TRASH_DAYS )
550                                                 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
551                                         if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
552                                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
553                                 }
554                                 if ( in_array( $post->post_status, array( 'pending', 'draft' ) ) ) {
555                                         if ( $can_edit_post )
556                                                 $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>';
557                                 } elseif ( 'trash' != $post->post_status ) {
558                                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
559                                 }
560
561                                 $actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post );
562                                 echo $this->row_actions( $actions );
563
564                                 get_inline_data( $post );
565                                 echo '</td>';
566                         break;
567
568                         case 'date':
569                                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
570                                         $t_time = $h_time = __( 'Unpublished' );
571                                         $time_diff = 0;
572                                 } else {
573                                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
574                                         $m_time = $post->post_date;
575                                         $time = get_post_time( 'G', true, $post );
576
577                                         $time_diff = time() - $time;
578
579                                         if ( $time_diff > 0 && $time_diff < 24*60*60 )
580                                                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
581                                         else
582                                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
583                                 }
584
585                                 echo '<td ' . $attributes . '>';
586                                 if ( 'excerpt' == $mode )
587                                         echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
588                                 else
589                                         echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
590                                 echo '<br />';
591                                 if ( 'publish' == $post->post_status ) {
592                                         _e( 'Published' );
593                                 } elseif ( 'future' == $post->post_status ) {
594                                         if ( $time_diff > 0 )
595                                                 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
596                                         else
597                                                 _e( 'Scheduled' );
598                                 } else {
599                                         _e( 'Last Modified' );
600                                 }
601                                 echo '</td>';
602                         break;
603
604                         case 'categories':
605                         ?>
606                         <td <?php echo $attributes ?>><?php
607                                 $categories = get_the_category();
608                                 if ( !empty( $categories ) ) {
609                                         $out = array();
610                                         foreach ( $categories as $c ) {
611                                                 $out[] = sprintf( '<a href="%s">%s</a>',
612                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'category_name' => $c->slug ), 'edit.php' ) ),
613                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) )
614                                                 );
615                                         }
616                                         echo join( ', ', $out );
617                                 } else {
618                                         _e( 'Uncategorized' );
619                                 }
620                         ?></td>
621                         <?php
622                         break;
623
624                         case 'tags':
625                         ?>
626                         <td <?php echo $attributes ?>><?php
627                                 $tags = get_the_tags( $post->ID );
628                                 if ( !empty( $tags ) ) {
629                                         $out = array();
630                                         foreach ( $tags as $c ) {
631                                                 $out[] = sprintf( '<a href="%s">%s</a>',
632                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'tag' => $c->slug ), 'edit.php' ) ),
633                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) )
634                                                 );
635                                         }
636                                         echo join( ', ', $out );
637                                 } else {
638                                         _e( 'No Tags' );
639                                 }
640                         ?></td>
641                         <?php
642                         break;
643
644                         case 'comments':
645                         ?>
646                         <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
647                         <?php
648                                 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
649
650                                 $this->comments_bubble( $post->ID, $pending_comments );
651                         ?>
652                         </div></td>
653                         <?php
654                         break;
655
656                         case 'author':
657                         ?>
658                         <td <?php echo $attributes ?>><?php
659                                 printf( '<a href="%s">%s</a>',
660                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
661                                         get_the_author()
662                                 );
663                         ?></td>
664                         <?php
665                         break;
666
667                         default:
668                         ?>
669                         <td <?php echo $attributes ?>><?php
670                                 if ( is_post_type_hierarchical( $post->post_type ) )
671                                         do_action( 'manage_pages_custom_column', $column_name, $post->ID );
672                                 else
673                                         do_action( 'manage_posts_custom_column', $column_name, $post->ID );
674                                 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
675                         ?></td>
676                         <?php
677                         break;
678                 }
679         }
680         ?>
681                 </tr>
682         <?php
683                 $post = $global_post;
684         }
685
686         /**
687          * Outputs the hidden row displayed when inline editing
688          *
689          * @since 3.1.0
690          */
691         function inline_edit() {
692                 global $mode;
693
694                 $screen = get_current_screen();
695
696                 $post = get_default_post_to_edit( $screen->post_type );
697                 $post_type_object = get_post_type_object( $screen->post_type );
698
699                 $taxonomy_names = get_object_taxonomies( $screen->post_type );
700                 $hierarchical_taxonomies = array();
701                 $flat_taxonomies = array();
702                 foreach ( $taxonomy_names as $taxonomy_name ) {
703                         $taxonomy = get_taxonomy( $taxonomy_name );
704
705                         if ( !$taxonomy->show_ui )
706                                 continue;
707
708                         if ( $taxonomy->hierarchical )
709                                 $hierarchical_taxonomies[] = $taxonomy;
710                         else
711                                 $flat_taxonomies[] = $taxonomy;
712                 }
713
714                 $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
715                 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
716                 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
717
718         ?>
719
720         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
721                 <?php
722                 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
723                 $bulk = 0;
724                 while ( $bulk < 2 ) { ?>
725
726                 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
727                         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";
728                 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
729
730                 <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
731                         <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
732         <?php
733
734         if ( post_type_supports( $screen->post_type, 'title' ) ) :
735                 if ( $bulk ) : ?>
736                         <div id="bulk-title-div">
737                                 <div id="bulk-titles"></div>
738                         </div>
739
740         <?php else : // $bulk ?>
741
742                         <label>
743                                 <span class="title"><?php _e( 'Title' ); ?></span>
744                                 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
745                         </label>
746
747                         <label>
748                                 <span class="title"><?php _e( 'Slug' ); ?></span>
749                                 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
750                         </label>
751
752         <?php endif; // $bulk
753         endif; // post_type_supports title ?>
754
755         <?php if ( !$bulk ) : ?>
756                         <label><span class="title"><?php _e( 'Date' ); ?></span></label>
757                         <div class="inline-edit-date">
758                                 <?php touch_time( 1, 1, 4, 1 ); ?>
759                         </div>
760                         <br class="clear" />
761         <?php endif; // $bulk
762
763                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
764                         $authors_dropdown = '';
765
766                         if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
767                                 $users_opt = array(
768                                         'hide_if_only_one_author' => false,
769                                         'who' => 'authors',
770                                         'name' => 'post_author',
771                                         'class'=> 'authors',
772                                         'multi' => 1,
773                                         'echo' => 0
774                                 );
775                                 if ( $bulk )
776                                         $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
777
778                                 if ( $authors = wp_dropdown_users( $users_opt ) ) :
779                                         $authors_dropdown  = '<label class="inline-edit-author">';
780                                         $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
781                                         $authors_dropdown .= $authors;
782                                         $authors_dropdown .= '</label>';
783                                 endif;
784                         endif; // authors
785         ?>
786
787         <?php if ( !$bulk ) echo $authors_dropdown;
788         endif; // post_type_supports author
789
790         if ( !$bulk ) :
791         ?>
792
793                         <div class="inline-edit-group">
794                                 <label class="alignleft">
795                                         <span class="title"><?php _e( 'Password' ); ?></span>
796                                         <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
797                                 </label>
798
799                                 <em style="margin:5px 10px 0 0" class="alignleft">
800                                         <?php
801                                         /* translators: Between password field and private checkbox on post quick edit interface */
802                                         echo __( '&ndash;OR&ndash;' );
803                                         ?>
804                                 </em>
805                                 <label class="alignleft inline-edit-private">
806                                         <input type="checkbox" name="keep_private" value="private" />
807                                         <span class="checkbox-title"><?php echo __( 'Private' ); ?></span>
808                                 </label>
809                         </div>
810
811         <?php endif; ?>
812
813                 </div></fieldset>
814
815         <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
816
817                 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
818
819         <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
820
821                         <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?>
822                                 <span class="catshow"><?php _e( '[more]' ); ?></span>
823                                 <span class="cathide" style="display:none;"><?php _e( '[less]' ); ?></span>
824                         </span>
825                         <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
826                         <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
827                                 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
828                         </ul>
829
830         <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
831
832                 </div></fieldset>
833
834         <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
835
836                 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
837
838         <?php
839                 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
840                         echo $authors_dropdown;
841         ?>
842
843         <?php if ( $post_type_object->hierarchical ) : ?>
844
845                         <label>
846                                 <span class="title"><?php _e( 'Parent' ); ?></span>
847         <?php
848                 $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' );
849                 if ( $bulk )
850                         $dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
851                 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
852                 wp_dropdown_pages( $dropdown_args );
853         ?>
854                         </label>
855
856         <?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
857                         if ( !$bulk ) : ?>
858
859                         <label>
860                                 <span class="title"><?php _e( 'Order' ); ?></span>
861                                 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
862                         </label>
863
864         <?php   endif; // !$bulk ?>
865
866                         <label>
867                                 <span class="title"><?php _e( 'Template' ); ?></span>
868                                 <select name="page_template">
869         <?php   if ( $bulk ) : ?>
870                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
871         <?php   endif; // $bulk ?>
872                                         <option value="default"><?php _e( 'Default Template' ); ?></option>
873                                         <?php page_template_dropdown() ?>
874                                 </select>
875                         </label>
876
877         <?php
878                 endif; // post_type_supports page-attributes
879         endif; // $post_type_object->hierarchical ?>
880
881         <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
882
883         <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
884
885                         <label class="inline-edit-tags">
886                                 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
887                                 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
888                         </label>
889
890         <?php endforeach; //$flat_taxonomies as $taxonomy ?>
891
892         <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
893
894         <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
895                 if ( $bulk ) : ?>
896
897                         <div class="inline-edit-group">
898                 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
899                         <label class="alignleft">
900                                 <span class="title"><?php _e( 'Comments' ); ?></span>
901                                 <select name="comment_status">
902                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
903                                         <option value="open"><?php _e( 'Allow' ); ?></option>
904                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
905                                 </select>
906                         </label>
907                 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
908                         <label class="alignright">
909                                 <span class="title"><?php _e( 'Pings' ); ?></span>
910                                 <select name="ping_status">
911                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
912                                         <option value="open"><?php _e( 'Allow' ); ?></option>
913                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
914                                 </select>
915                         </label>
916                 <?php endif; ?>
917                         </div>
918
919         <?php else : // $bulk ?>
920
921                         <div class="inline-edit-group">
922                         <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
923                                 <label class="alignleft">
924                                         <input type="checkbox" name="comment_status" value="open" />
925                                         <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
926                                 </label>
927                         <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
928                                 <label class="alignleft">
929                                         <input type="checkbox" name="ping_status" value="open" />
930                                         <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
931                                 </label>
932                         <?php endif; ?>
933                         </div>
934
935         <?php endif; // $bulk
936         endif; // post_type_supports comments or pings ?>
937
938                         <div class="inline-edit-group">
939                                 <label class="inline-edit-status alignleft">
940                                         <span class="title"><?php _e( 'Status' ); ?></span>
941                                         <select name="_status">
942         <?php if ( $bulk ) : ?>
943                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
944         <?php endif; // $bulk ?>
945                                         <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
946                                                 <option value="publish"><?php _e( 'Published' ); ?></option>
947                                                 <option value="future"><?php _e( 'Scheduled' ); ?></option>
948         <?php if ( $bulk ) : ?>
949                                                 <option value="private"><?php _e( 'Private' ) ?></option>
950         <?php endif; // $bulk ?>
951                                         <?php endif; ?>
952                                                 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
953                                                 <option value="draft"><?php _e( 'Draft' ); ?></option>
954                                         </select>
955                                 </label>
956
957         <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
958
959         <?php   if ( $bulk ) : ?>
960
961                                 <label class="alignright">
962                                         <span class="title"><?php _e( 'Sticky' ); ?></span>
963                                         <select name="sticky">
964                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
965                                                 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
966                                                 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
967                                         </select>
968                                 </label>
969
970         <?php   else : // $bulk ?>
971
972                                 <label class="alignleft">
973                                         <input type="checkbox" name="sticky" value="sticky" />
974                                         <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
975                                 </label>
976
977         <?php   endif; // $bulk ?>
978
979         <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
980
981                         </div>
982
983                 </div></fieldset>
984
985         <?php
986                 list( $columns ) = $this->get_column_info();
987
988                 foreach ( $columns as $column_name => $column_display_name ) {
989                         if ( isset( $core_columns[$column_name] ) )
990                                 continue;
991                         do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
992                 }
993         ?>
994                 <p class="submit inline-edit-save">
995                         <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
996                         <?php if ( ! $bulk ) {
997                                 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
998                                 $update_text = __( 'Update' );
999                                 ?>
1000                                 <a accesskey="s" href="#inline-edit" title="<?php _e( 'Update' ); ?>" class="button-primary save alignright"><?php echo esc_attr( $update_text ); ?></a>
1001                                 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1002                         <?php } else {
1003                                 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
1004                         } ?>
1005                         <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1006                         <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1007                         <br class="clear" />
1008                 </p>
1009                 </td></tr>
1010         <?php
1011                 $bulk++;
1012                 }
1013 ?>
1014                 </tbody></table></form>
1015 <?php
1016         }
1017 }
1018
1019 ?>