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