Make WordPress Core


Ignore:
Timestamp:
10/25/2010 12:12:41 AM (16 years ago)
Author:
nacin
Message:

Shuffle list-table files. First pass. see #14579.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/default-list-tables.php

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