Make WordPress Core


Ignore:
Timestamp:
10/25/2010 02:57:43 AM (16 years ago)
Author:
nacin
Message:

Introduce require_list_table(), rework get_list_table() calls, split default-list-tables into individual files. see #14579.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/list-table-comments.php

    r15954 r15955  
    1010 */
    1111
    12 class WP_Media_Table extends WP_List_Table {
    13 
    14         function WP_Media_Table() {
    15                 global $detached;
    16 
    17                 $detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
    18 
    19                 parent::WP_List_Table( array(
    20                         'screen' => $detached ? 'upload-detached' : 'upload',
    21                         'plural' => 'media'
    22                 ) );
    23         }
    24 
    25         function check_permissions() {
    26                 if ( !current_user_can('upload_files') )
    27                         wp_die( __( 'You do not have permission to upload files.' ) );
    28         }
    29 
    30         function prepare_items() {
    31                 global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types;
    32 
    33                 $q = $_REQUEST;
    34 
    35                 if ( !empty( $lost ) )
    36                         $q['post__in'] = implode( ',', $lost );
    37 
    38                 list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q );
    39 
    40                 $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
    41 
    42                 $this->set_pagination_args( array(
    43                         'total_items' => $wp_query->found_posts,
    44                         'total_pages' => $wp_query->max_num_pages,
    45                         'per_page' => $wp_query->query_vars['posts_per_page'],
    46                 ) );
    47         }
    48 
    49         function get_views() {
    50                 global $wpdb, $post_mime_types, $detached, $avail_post_mime_types;
    51 
    52                 $type_links = array();
    53                 $_num_posts = (array) wp_count_attachments();
    54                 $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
    55                 if ( !isset( $total_orphans ) )
    56                                 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
    57                 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    58                 foreach ( $matches as $type => $reals )
    59                         foreach ( $reals as $real )
    60                                 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
    61 
    62                 $class = ( empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ) ? ' class="current"' : '';
    63                 $type_links['all'] = "<li><a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>';
    64                 foreach ( $post_mime_types as $mime_type => $label ) {
    65                         $class = '';
    66 
    67                         if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
    68                                 continue;
    69 
    70                         if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
    71                                 $class = ' class="current"';
    72                         if ( !empty( $num_posts[$mime_type] ) )
    73                                 $type_links[$mime_type] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
    74                 }
    75                 $type_links['detached'] = '<li><a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
    76 
    77                 if ( !empty($_num_posts['trash']) )
    78                         $type_links['trash'] = '<li><a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
    79 
    80                 return $type_links;
    81         }
    82 
    83         function get_bulk_actions() {
    84                 global $detached;
    85 
    86                 $actions = array();
    87                 $actions['delete'] = __( 'Delete Permanently' );
    88                 if ( $detached )
    89                         $actions['attach'] = __( 'Attach to a post' );
    90 
    91                 return $actions;
    92         }
    93 
    94         function extra_tablenav( $which ) {
    95                 global $post_type, $detached;
    96 ?>
    97                 <div class="alignleft actions">
    98 <?php
    99                 if ( 'top' == $which && !is_singular() && !$detached && !$this->is_trash ) {
    100                         $this->months_dropdown( $post_type );
    101 
    102                         do_action( 'restrict_manage_posts' );
    103 ?>
    104                         <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" />
    105 <?php
    106                 }
    107 
    108                 if ( $detached ) { ?>
    109                         <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e( 'Scan for lost attachments' ); ?>" class="button-secondary" />
    110                 <?php } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { ?>
    111                         <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e( 'Empty Trash' ); ?>" class="button-secondary apply" />
    112                 <?php } ?>
    113                 </div>
    114 <?php
    115         }
    116 
    117         function current_action() {
    118                 if ( isset( $_REQUEST['find_detached'] ) )
    119                         return 'find_detached';
    120 
    121                 if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
    122                         return 'attach';
    123 
    124                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
    125                         return 'delete_all';
    126 
    127                 return parent::current_action();
    128         }
    129 
    130         function has_items() {
    131                 return have_posts();
    132         }
    133 
    134         function no_items() {
    135                 _e( 'No media attachments found.' );
    136         }
    137 
    138         function get_columns() {
    139                 $posts_columns = array();
    140                 $posts_columns['cb'] = '<input type="checkbox" />';
    141                 $posts_columns['icon'] = '';
    142                 /* translators: column name */
    143                 $posts_columns['title'] = _x( 'File', 'column name' );
    144                 $posts_columns['author'] = __( 'Author' );
    145                 //$posts_columns['tags'] = _x( 'Tags', 'column name' );
    146                 /* translators: column name */
    147                 if ( 'upload' == $this->_screen->id ) {
    148                         $posts_columns['parent'] = _x( 'Attached to', 'column name' );
    149                         $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
    150                 }
    151                 /* translators: column name */
    152                 $posts_columns['date'] = _x( 'Date', 'column name' );
    153                 $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, 'upload' != $this->_screen->id );
    154 
    155                 return $posts_columns;
    156         }
    157 
    158         function get_sortable_columns() {
    159                 return array(
    160                         'title'    => 'title',
    161                         'author'   => 'author',
    162                         'parent'   => 'parent',
    163                         'comments' => 'comment_count',
    164                         'date'     => 'date',
    165                 );
    166         }
    167 
    168         function display_rows() {
    169                 global $detached, $post, $id;
    170 
    171                 if ( $detached ) {
    172                         $this->display_orphans();
    173                         return;
    174                 }
    175 
    176                 add_filter( 'the_title','esc_html' );
    177                 $alt = '';
    178 
    179                 while ( have_posts() ) : the_post();
    180 
    181                         if ( $this->is_trash && $post->post_status != 'trash'
    182                         ||  !$this->is_trash && $post->post_status == 'trash' )
    183                                 continue;
    184 
    185                         $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
    186                         $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
    187                         $att_title = _draft_or_post_title();
    188 ?>
    189         <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
    190 <?php
    191 
    192 list( $columns, $hidden ) = $this->get_column_info();
    193 foreach ( $columns as $column_name => $column_display_name ) {
    194         $class = "class='$column_name column-$column_name'";
    195 
    196         $style = '';
    197         if ( in_array( $column_name, $hidden ) )
    198                 $style = ' style="display:none;"';
    199 
    200         $attributes = $class . $style;
    201 
    202         switch ( $column_name ) {
    203 
    204         case 'cb':
    205 ?>
    206                 <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /><?php } ?></th>
    207 <?php
    208                 break;
    209 
    210         case 'icon':
    211                 $attributes = 'class="column-icon media-icon"' . $style;
    212 ?>
    213                 <td <?php echo $attributes ?>><?php
    214                         if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
    215                                 if ( $this->is_trash ) {
    216                                         echo $thumb;
    217                                 } else {
    218 ?>
    219                                 <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
    220                                         <?php echo $thumb; ?>
    221                                 </a>
    222 
    223 <?php                   }
    224                         }
    225 ?>
    226                 </td>
    227 <?php
    228                 break;
    229 
    230         case 'title':
    231 ?>
    232                 <td <?php echo $attributes ?>><strong><?php if ( $this->is_trash ) echo $att_title; else { ?><a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"><?php echo $att_title; ?></a><?php } ?></strong>
    233                         <p>
    234 <?php
    235                         if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
    236                                 echo esc_html( strtoupper( $matches[1] ) );
    237                         else
    238                                 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
    239 ?>
    240                         </p>
    241 <?php
    242                 $actions = array();
    243                 if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
    244                         $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
    245                 if ( current_user_can( 'delete_post', $post->ID ) ) {
    246                         if ( $this->is_trash )
    247                                 $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-attachment_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
    248                         elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH )
    249                                 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
    250                         if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) {
    251                                 $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
    252                                 $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>";
    253                         }
    254                 }
    255                 if ( !$this->is_trash ) {
    256                         $title =_draft_or_post_title( $post->post_parent );
    257                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    258                 }
    259                 $actions = apply_filters( 'media_row_actions', $actions, $post );
    260                 echo $this->row_actions( $actions );
    261 ?>
    262                 </td>
    263 <?php
    264                 break;
    265 
    266         case 'author':
    267 ?>
    268                 <td <?php echo $attributes ?>><?php the_author() ?></td>
    269 <?php
    270                 break;
    271 
    272         case 'tags':
    273 ?>
    274                 <td <?php echo $attributes ?>><?php
    275                 $tags = get_the_tags();
    276                 if ( !empty( $tags ) ) {
    277                         $out = array();
    278                         foreach ( $tags as $c )
    279                                 $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
    280                         echo join( ', ', $out );
    281                 } else {
    282                         _e( 'No Tags' );
    283                 }
    284 ?>
    285                 </td>
    286 <?php
    287                 break;
    288 
    289         case 'desc':
    290 ?>
    291                 <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
    292 <?php
    293                 break;
    294 
    295         case 'date':
    296                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    297                         $t_time = $h_time = __( 'Unpublished' );
    298                 } else {
    299                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
    300                         $m_time = $post->post_date;
    301                         $time = get_post_time( 'G', true, $post, false );
    302                         if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) {
    303                                 if ( $t_diff < 0 )
    304                                         $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
    305                                 else
    306                                         $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
    307                         } else {
    308                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    309                         }
    310                 }
    311 ?>
    312                 <td <?php echo $attributes ?>><?php echo $h_time ?></td>
    313 <?php
    314                 break;
    315 
    316         case 'parent':
    317                 if ( $post->post_parent > 0 ) {
    318                         if ( get_post( $post->post_parent ) ) {
    319                                 $title =_draft_or_post_title( $post->post_parent );
    320                         }
    321 ?>
    322                         <td <?php echo $attributes ?>>
    323                                 <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>,
    324                                 <?php echo get_the_time( __( 'Y/m/d' ) ); ?>
    325                         </td>
    326 <?php
    327                 } else {
    328 ?>
    329                         <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br />
    330                         <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' );return false;" href="#the-list"><?php _e( 'Attach' ); ?></a></td>
    331 <?php
    332                 }
    333                 break;
    334 
    335         case 'comments':
    336                 $attributes = 'class="comments column-comments num"' . $style;
    337 ?>
    338                 <td <?php echo $attributes ?>>
    339                         <div class="post-com-count-wrapper">
    340 <?php
    341                 $pending_comments = get_pending_comments_num( $post->ID );
    342 
    343                 $this->comments_bubble( $post->ID, $pending_comments );
    344 ?>
    345                         </div>
    346                 </td>
    347 <?php
    348                 break;
    349 
    350         case 'actions':
    351 ?>
    352                 <td <?php echo $attributes ?>>
    353                         <a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"><?php _e( 'Edit' ); ?></a> |
    354                         <a href="<?php the_permalink(); ?>"><?php _e( 'Get permalink' ); ?></a>
    355                 </td>
    356                 <?php
    357                 break;
    358 
    359         default:
    360 ?>
    361                 <td <?php echo $attributes ?>>
    362                         <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
    363                 </td>
    364 <?php
    365                 break;
    366         }
    367 }
    368 ?>
    369         </tr>
    370 <?php endwhile;
    371         }
    372 
    373         function display_orphans() {
    374                 global $post;
    375 
    376                 $class = '';
    377 
    378                 while ( have_posts() ) : the_post();
    379 
    380                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    381                         $att_title = esc_html( _draft_or_post_title( $post->ID ) );
    382 
    383                         $edit_link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ) . '">%s</a>';
    384 ?>
    385         <tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top">
    386                 <th scope="row" class="check-column">
    387                 <?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?>
    388                         <input type="checkbox" name="media[]" value="<?php echo esc_attr( $post->ID ); ?>" />
    389                 <?php } ?>
    390                 </th>
    391 
    392                 <td class="media-icon">
    393                 <?php if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
    394                         printf( $edit_link, $thumb );
    395                 } ?>
    396                 </td>
    397 
    398                 <td class="media column-media">
    399                         <strong><?php printf( $edit_link, $att_title ); ?></strong><br />
    400 <?php
    401                         if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
    402                                 echo esc_html( strtoupper( $matches[1] ) );
    403                         else
    404                                 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
    405 ?>
    406 <?php
    407                         $actions = array();
    408                         if ( current_user_can( 'edit_post', $post->ID ) )
    409                                 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
    410                         if ( current_user_can( 'delete_post', $post->ID ) )
    411                                 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
    412                                         $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
    413                                 } else {
    414                                         $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
    415                                         $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>";
    416                                 }
    417                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    418                         if ( current_user_can( 'edit_post', $post->ID ) )
    419                                 $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>';
    420                         $actions = apply_filters( 'media_row_actions', $actions, $post );
    421 
    422                         echo $this->row_actions( $actions );
    423 ?>
    424                 </td>
    425                 <td class="author column-author">
    426                         <?php $author = get_userdata( $post->post_author ); echo $author->display_name; ?>
    427                 </td>
    428 <?php
    429                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    430                         $t_time = $h_time = __( 'Unpublished' );
    431                 } else {
    432                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
    433                         $m_time = $post->post_date;
    434                         $time = get_post_time( 'G', true );
    435                         if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) {
    436                                 if ( $t_diff < 0 )
    437                                         $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
    438                                 else
    439                                         $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
    440                         } else {
    441                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    442                         }
    443                 }
    444 ?>
    445                 <td class="date column-date"><?php echo $h_time ?></td>
    446         </tr>
    447 <?php
    448                 endwhile;
    449         }
    450 }
    451 
    452 class WP_Terms_Table extends WP_List_Table {
    453 
    454         var $callback_args;
    455 
    456         function WP_Terms_Table() {
    457                 global $post_type, $taxonomy, $tax, $current_screen;
    458 
    459                 wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) );
    460 
    461                 if ( empty( $taxonomy ) )
    462                         $taxonomy = 'post_tag';
    463 
    464                 if ( !taxonomy_exists( $taxonomy ) )
    465                         wp_die( __( 'Invalid taxonomy' ) );
    466 
    467                 $tax = get_taxonomy( $taxonomy );
    468 
    469                 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) )
    470                         $post_type = 'post';
    471 
    472                 if ( !isset( $current_screen ) )
    473                         set_current_screen( 'edit-' . $taxonomy );
    474 
    475                 parent::WP_List_Table( array(
    476                         'screen' => $current_screen,
    477                         'plural' => 'tags',
    478                         'singular' => 'tag',
    479                 ) );
    480         }
    481 
    482         function check_permissions( $type = 'manage' ) {
    483                 global $tax;
    484 
    485                 $cap = 'manage' == $type ? $tax->cap->manage_terms : $tax->cap->edit_terms;
    486 
    487                 if ( !current_user_can( $tax->cap->manage_terms ) )
    488                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    489         }
    490 
    491         function prepare_items() {
    492                 global $taxonomy;
    493 
    494                 $tags_per_page = $this->get_items_per_page( 'edit_' .  $taxonomy . '_per_page' );
    495 
    496                 if ( 'post_tag' == $taxonomy ) {
    497                         $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
    498                         $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
    499                 } elseif ( 'category' == $taxonomy ) {
    500                         $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
    501                 }
    502 
    503                 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
    504 
    505                 $args = array(
    506                         'search' => $search,
    507                         'page' => $this->get_pagenum(),
    508                         'number' => $tags_per_page,
    509                 );
    510 
    511                 if ( !empty( $_REQUEST['orderby'] ) )
    512                         $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
    513 
    514                 if ( !empty( $_REQUEST['order'] ) )
    515                         $args['order'] = trim( stripslashes( $_REQUEST['order'] ) );
    516 
    517                 $this->callback_args = $args;
    518 
    519                 $this->set_pagination_args( array(
    520                         'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ),
    521                         'per_page' => $tags_per_page,
    522                 ) );
    523         }
    524 
    525         function get_bulk_actions() {
    526                 $actions = array();
    527                 $actions['delete'] = __( 'Delete' );
    528 
    529                 return $actions;
    530         }
    531 
    532         function current_action() {
    533                 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
    534                         return 'bulk-delete';
    535 
    536                 return parent::current_action();
    537         }
    538 
    539         function get_columns() {
    540                 global $taxonomy;
    541 
    542                 $columns = array(
    543                         'cb'          => '<input type="checkbox" />',
    544                         'name'        => __( 'Name' ),
    545                         'description' => __( 'Description' ),
    546                         'slug'        => __( 'Slug' ),
    547                 );
    548 
    549                 if ( 'link_category' == $taxonomy )
    550                         $columns['links'] = __( 'Links' );
    551                 else
    552                         $columns['posts'] = __( 'Posts' );
    553 
    554                 return $columns;
    555         }
    556 
    557         function get_sortable_columns() {
    558                 return array(
    559                         'name'        => 'name',
    560                         'description' => 'description',
    561                         'slug'        => 'slug',
    562                         'posts'       => 'count',
    563                         'links'       => 'count'
    564                 );
    565         }
    566 
    567         function display_rows() {
    568                 global $taxonomy;
    569 
    570                 $args = wp_parse_args( $this->callback_args, array(
    571                         'page' => 1,
    572                         'number' => 20,
    573                         'search' => '',
    574                         'hide_empty' => 0
    575                 ) );
    576 
    577                 extract( $args, EXTR_SKIP );
    578 
    579                 $args['offset'] = $offset = ( $page - 1 ) * $number;
    580 
    581                 // convert it to table rows
    582                 $out = '';
    583                 $count = 0;
    584                 if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) {
    585                         // We'll need the full set of terms then.
    586                         $args['number'] = $args['offset'] = 0;
    587 
    588                         $terms = get_terms( $taxonomy, $args );
    589                         if ( !empty( $search ) ) // Ignore children on searches.
    590                                 $children = array();
    591                         else
    592                                 $children = _get_term_hierarchy( $taxonomy );
    593 
    594                         // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
    595                         $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
    596                 } else {
    597                         $terms = get_terms( $taxonomy, $args );
    598                         foreach ( $terms as $term )
    599                                 $out .= $this->single_row( $term, 0, $taxonomy );
    600                         $count = $number; // Only displaying a single page.
    601                 }
    602 
    603                 echo $out;
    604         }
    605 
    606         function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
    607 
    608                 $end = $start + $per_page;
    609 
    610                 $output = '';
    611                 foreach ( $terms as $key => $term ) {
    612 
    613                         if ( $count >= $end )
    614                                 break;
    615 
    616                         if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
    617                                 continue;
    618 
    619                         // If the page starts in a subtree, print the parents.
    620                         if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
    621                                 $my_parents = $parent_ids = array();
    622                                 $p = $term->parent;
    623                                 while ( $p ) {
    624                                         $my_parent = get_term( $p, $taxonomy );
    625                                         $my_parents[] = $my_parent;
    626                                         $p = $my_parent->parent;
    627                                         if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
    628                                                 break;
    629                                         $parent_ids[] = $p;
    630                                 }
    631                                 unset( $parent_ids );
    632 
    633                                 $num_parents = count( $my_parents );
    634                                 while ( $my_parent = array_pop( $my_parents ) ) {
    635                                         $output .=  "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy );
    636                                         $num_parents--;
    637                                 }
    638                         }
    639 
    640                         if ( $count >= $start )
    641                                 $output .= "\t" . $this->single_row( $term, $level, $taxonomy );
    642 
    643                         ++$count;
    644 
    645                         unset( $terms[$key] );
    646 
    647                         if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
    648                                 $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
    649                 }
    650 
    651                 return $output;
    652         }
    653 
    654         function single_row( $tag, $level = 0 ) {
    655                 static $row_class = '';
    656                 $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
    657 
    658                 $this->level = $level;
    659 
    660                 echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
    661                 echo $this->single_row_columns( $tag );
    662                 echo '</tr>';
    663         }
    664 
    665         function column_cb( $tag ) {
    666                 global $taxonomy, $tax;
    667 
    668                 $default_term = get_option( 'default_' . $taxonomy );
    669 
    670                 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
    671                         return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />';
    672                 else
    673                         return '&nbsp;';
    674         }
    675 
    676         function column_name( $tag ) {
    677                 global $taxonomy, $tax, $post_type;
    678 
    679                 $default_term = get_option( 'default_' . $taxonomy );
    680 
    681                 $pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
    682                 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
    683                 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
    684                 $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $post_type );
    685 
    686                 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
    687 
    688                 $actions = array();
    689                 if ( current_user_can( $tax->cap->edit_terms ) ) {
    690                         $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    691                         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
    692                 }
    693                 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
    694                         $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
    695 
    696                 $actions = apply_filters( 'tag_row_actions', $actions, $tag );
    697                 $actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag );
    698 
    699                 $out .= $this->row_actions( $actions );
    700                 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
    701                 $out .= '<div class="name">' . $qe_data->name . '</div>';
    702                 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
    703                 $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
    704 
    705                 return $out;
    706         }
    707 
    708         function column_description( $tag ) {
    709                 return $tag->description;
    710         }
    711 
    712         function column_slug( $tag ) {
    713                 return apply_filters( 'editable_slug', $tag->slug );
    714         }
    715 
    716         function column_posts( $tag ) {
    717                 global $taxonomy, $post_type;
    718 
    719                 $count = number_format_i18n( $tag->count );
    720 
    721                 if ( 'post_tag' == $taxonomy ) {
    722                         $tagsel = 'tag';
    723                 } elseif ( 'category' == $taxonomy ) {
    724                         $tagsel = 'category_name';
    725                 } elseif ( ! empty( $tax->query_var ) ) {
    726                         $tagsel = $tax->query_var;
    727                 } else {
    728                         $tagsel = $taxonomy;
    729                 }
    730 
    731                 return "<a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a>";
    732         }
    733 
    734         function column_links( $tag ) {
    735                 $count = number_format_i18n( $tag->count );
    736                 return $count;
    737         }
    738 
    739         function column_default( $tag, $column_name ) {
    740                 global $taxonomy;
    741 
    742                 return apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id );
    743                 $out .= "</td>";
    744         }
    745 
    746         /**
    747          * Outputs the hidden row displayed when inline editing
    748          *
    749          * @since 3.1.0
    750          */
    751         function inline_edit() {
    752                 global $tax;
    753 
    754                 if ( ! current_user_can( $tax->cap->edit_terms ) )
    755                         return;
    756 
    757                 list( $columns, $hidden ) = $this->get_column_info();
    758 
    759                 $col_count = count( $columns ) - count( $hidden );
    760                 ?>
    761 
    762         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
    763                 <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>">
    764 
    765                         <fieldset><div class="inline-edit-col">
    766                                 <h4><?php _e( 'Quick Edit' ); ?></h4>
    767 
    768                                 <label>
    769                                         <span class="title"><?php _e( 'Name' ); ?></span>
    770                                         <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
    771                                 </label>
    772         <?php if ( !global_terms_enabled() ) { ?>
    773                                 <label>
    774                                         <span class="title"><?php _e( 'Slug' ); ?></span>
    775                                         <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
    776                                 </label>
    777         <?php } ?>
    778 
    779                         </div></fieldset>
    780         <?php
    781 
    782                 $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
    783 
    784                 foreach ( $columns as $column_name => $column_display_name ) {
    785                         if ( isset( $core_columns[$column_name] ) )
    786                                 continue;
    787                         do_action( 'quick_edit_custom_box', $column_name, $type, $tax->taxonomy );
    788                 }
    789 
    790         ?>
    791 
    792                 <p class="inline-edit-save submit">
    793                         <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
    794                         <?php $update_text = $tax->labels->update_item; ?>
    795                         <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
    796                         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
    797                         <span class="error" style="display:none;"></span>
    798                         <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
    799                         <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
    800                         <br class="clear" />
    801                 </p>
    802                 </td></tr>
    803                 </tbody></table></form>
    804         <?php
    805         }
    806 }
    807 
    808 class WP_Users_Table extends WP_List_Table {
    809 
    810         function WP_Users_Table() {
    811                 parent::WP_List_Table( array(
    812                         'screen' => 'users',
    813                         'plural' => 'users'
    814                 ) );
    815         }
    816 
    817         function check_permissions() {
    818                 if ( !current_user_can('list_users') )
    819                         wp_die(__('Cheatin&#8217; uh?'));
    820         }
    821 
    822         function prepare_items() {
    823                 global $role, $usersearch;
    824 
    825                 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    826 
    827                 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    828 
    829                 $users_per_page = $this->get_items_per_page( 'users_per_page' );
    830 
    831                 $paged = $this->get_pagenum();
    832 
    833                 $args = array(
    834                         'number' => $users_per_page,
    835                         'offset' => ( $paged-1 ) * $users_per_page,
    836                         'role' => $role,
    837                         'search' => $usersearch
    838                 );
    839 
    840                 if ( isset( $_REQUEST['orderby'] ) )
    841                         $args['orderby'] = $_REQUEST['orderby'];
    842 
    843                 if ( isset( $_REQUEST['order'] ) )
    844                         $args['order'] = $_REQUEST['order'];
    845 
    846                 // Query the user IDs for this page
    847                 $wp_user_search = new WP_User_Query( $args );
    848 
    849                 $this->items = $wp_user_search->get_results();
    850 
    851                 $this->set_pagination_args( array(
    852                         'total_items' => $wp_user_search->get_total(),
    853                         'per_page' => $users_per_page,
    854                 ) );
    855         }
    856 
    857         function no_items() {
    858                 _e( 'No matching users were found.' );
    859         }
    860 
    861         function get_views() {
    862                 global $wp_roles, $role;
    863 
    864                 $users_of_blog = count_users();
    865                 $total_users = $users_of_blog['total_users'];
    866                 $avail_roles =& $users_of_blog['avail_roles'];
    867                 unset($users_of_blog);
    868 
    869                 $current_role = false;
    870                 $class = empty($role) ? ' class="current"' : '';
    871                 $role_links = array();
    872                 $role_links['all'] = "<li><a href='users.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
    873                 foreach ( $wp_roles->get_names() as $this_role => $name ) {
    874                         if ( !isset($avail_roles[$this_role]) )
    875                                 continue;
    876 
    877                         $class = '';
    878 
    879                         if ( $this_role == $role ) {
    880                                 $current_role = $role;
    881                                 $class = ' class="current"';
    882                         }
    883 
    884                         $name = translate_user_role( $name );
    885                         /* translators: User role name with count */
    886                         $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] );
    887                         $role_links[$this_role] = "<li><a href='users.php?role=$this_role'$class>$name</a>";
    888                 }
    889 
    890                 return $role_links;
    891         }
    892 
    893         function get_bulk_actions() {
    894                 $actions = array();
    895 
    896                 if ( !is_multisite() && current_user_can( 'delete_users' ) )
    897                         $actions['delete'] = __( 'Delete' );
    898                 else
    899                         $actions['remove'] = __( 'Remove' );
    900 
    901                 return $actions;
    902         }
    903 
    904         function extra_tablenav( $which ) {
    905                 if ( 'top' != $which )
    906                         return;
    907 ?>
    908         <div class="alignleft actions">
    909                 <label class="screen-reader-text" for="new_role"><?php _e( 'Change role to&hellip;' ) ?></label>
    910                 <select name="new_role" id="new_role">
    911                         <option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
    912                         <?php wp_dropdown_roles(); ?>
    913                 </select>
    914                 <input type="submit" value="<?php esc_attr_e( 'Change' ); ?>" name="changeit" class="button-secondary" />
    915         </div>
    916 <?php
    917         }
    918 
    919         function current_action() {
    920                 if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
    921                         return 'promote';
    922 
    923                 return parent::current_action();
    924         }
     12class WP_Post_Comments_Table extends WP_Comments_Table {
    92513
    92614        function get_columns() {
    92715                return array(
    928                         'cb'       => '<input type="checkbox" />',
    929                         'username' => __( 'Login' ),
    930                         'name'     => __( 'Name' ),
    931                         'email'    => __( 'E-mail' ),
    932                         'role'     => __( 'Role' ),
    933                         'posts'    => __( 'Posts' )
     16                        'author'   => __( 'Author' ),
     17                        'comment'  => _x( 'Comment', 'column name' ),
    93418                );
    93519        }
    93620
    93721        function get_sortable_columns() {
    938                 return array(
    939                         'username' => 'login',
    940                         'name'     => 'name',
    941                         'email'    => 'email',
    942                         'posts'    => 'post_count',
    943                 );
    944         }
    945 
    946         function display_rows() {
    947                 // Query the post counts for this page
    948                 $post_counts = count_many_users_posts( array_keys( $this->items ) );
    949 
    950                 $style = '';
    951                 foreach ( $this->items as $userid => $user_object ) {
    952                         $role = reset( $user_object->roles );
    953 
    954                         if ( is_multisite() && empty( $role ) )
    955                                 continue;
    956 
    957                         $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
    958                         echo "\n\t", $this->single_row( $user_object, $style, $role, $post_counts[ $userid ] );
    959                 }
    960         }
    961 
    962         /**
    963          * Generate HTML for a single row on the users.php admin panel.
    964          *
    965          * @since 2.1.0
    966          *
    967          * @param object $user_object
    968          * @param string $style Optional. Attributes added to the TR element.  Must be sanitized.
    969          * @param string $role Key for the $wp_roles array.
    970          * @param int $numposts Optional. Post count to display for this user.  Defaults to zero, as in, a new user has made zero posts.
    971          * @return string
    972          */
    973         function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
    974                 global $wp_roles;
    975 
    976                 if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
    977                         $user_object = new WP_User( (int) $user_object );
    978                 $user_object = sanitize_user_object( $user_object, 'display' );
    979                 $email = $user_object->user_email;
    980                 $url = $user_object->user_url;
    981                 $short_url = str_replace( 'http://', '', $url );
    982                 $short_url = str_replace( 'www.', '', $short_url );
    983                 if ( '/' == substr( $short_url, -1 ) )
    984                         $short_url = substr( $short_url, 0, -1 );
    985                 if ( strlen( $short_url ) > 35 )
    986                         $short_url = substr( $short_url, 0, 32 ).'...';
    987                 $checkbox = '';
    988                 // Check if the user for this row is editable
    989                 if ( current_user_can( 'list_users' ) ) {
    990                         // Set up the user editing link
    991                         // TODO: make profile/user-edit determination a separate function
    992                         if ( get_current_user_id() == $user_object->ID ) {
    993                                 $edit_link = 'profile.php';
    994                         } else {
    995                                 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
    996                         }
    997                         $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
    998 
    999                         // Set up the hover actions for this user
    1000                         $actions = array();
    1001 
    1002                         if ( current_user_can( 'edit_user',  $user_object->ID ) ) {
    1003                                 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
    1004                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    1005                         } else {
    1006                                 $edit = "<strong>$user_object->user_login</strong><br />";
    1007                         }
    1008 
    1009                         if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
    1010                                 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
    1011                         if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
    1012                                 $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
    1013                         $actions = apply_filters( 'user_row_actions', $actions, $user_object );
    1014                         $edit .= $this->row_actions( $actions );
    1015 
    1016                         // Set up the checkbox ( because the user is editable, otherwise its empty )
    1017                         $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
    1018 
    1019                 } else {
    1020                         $edit = '<strong>' . $user_object->user_login . '</strong>';
    1021                 }
    1022                 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' );
    1023                 $r = "<tr id='user-$user_object->ID'$style>";
    1024                 $avatar = get_avatar( $user_object->ID, 32 );
    1025 
    1026                 list( $columns, $hidden ) = $this->get_column_info();
    1027 
    1028                 foreach ( $columns as $column_name => $column_display_name ) {
    1029                         $class = "class=\"$column_name column-$column_name\"";
    1030 
    1031                         $style = '';
    1032                         if ( in_array( $column_name, $hidden ) )
    1033                                 $style = ' style="display:none;"';
    1034 
    1035                         $attributes = "$class$style";
    1036 
    1037                         switch ( $column_name ) {
    1038                                 case 'cb':
    1039                                         $r .= "<th scope='row' class='check-column'>$checkbox</th>";
    1040                                         break;
    1041                                 case 'username':
    1042                                         $r .= "<td $attributes>$avatar $edit</td>";
    1043                                         break;
    1044                                 case 'name':
    1045                                         $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
    1046                                         break;
    1047                                 case 'email':
    1048                                         $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __( 'E-mail: %s' ), $email ) . "'>$email</a></td>";
    1049                                         break;
    1050                                 case 'role':
    1051                                         $r .= "<td $attributes>$role_name</td>";
    1052                                         break;
    1053                                 case 'posts':
    1054                                         $attributes = 'class="posts column-posts num"' . $style;
    1055                                         $r .= "<td $attributes>";
    1056                                         if ( $numposts > 0 ) {
    1057                                                 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
    1058                                                 $r .= $numposts;
    1059                                                 $r .= '</a>';
    1060                                         } else {
    1061                                                 $r .= 0;
    1062                                         }
    1063                                         $r .= "</td>";
    1064                                         break;
    1065                                 default:
    1066                                         $r .= "<td $attributes>";
    1067                                         $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
    1068                                         $r .= "</td>";
    1069                         }
    1070                 }
    1071                 $r .= '</tr>';
    1072 
    1073                 return $r;
     22                return array();
    107423        }
    107524}
     
    1548497        }
    1549498}
    1550 
    1551 class WP_Post_Comments_Table extends WP_Comments_Table {
    1552 
    1553         function get_columns() {
    1554                 return array(
    1555                         'author'   => __( 'Author' ),
    1556                         'comment'  => _x( 'Comment', 'column name' ),
    1557                 );
    1558         }
    1559 
    1560         function get_sortable_columns() {
    1561                 return array();
    1562         }
    1563 }
    1564 
    1565 class WP_Links_Table extends WP_List_Table {
    1566 
    1567         function WP_Links_Table() {
    1568                 parent::WP_List_Table( array(
    1569                         'screen' => 'link-manager',
    1570                         'plural' => 'bookmarks',
    1571                 ) );
    1572         }
    1573 
    1574         function check_permissions() {
    1575                 if ( ! current_user_can( 'manage_links' ) )
    1576                         wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) );
    1577         }
    1578 
    1579         function prepare_items() {
    1580                 global $cat_id, $s, $orderby, $order;
    1581 
    1582                 wp_reset_vars( array( 'action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'orderby', 'order', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]', 's' ) );
    1583 
    1584                 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
    1585 
    1586                 if ( 'all' != $cat_id )
    1587                         $args['category'] = $cat_id;
    1588                 if ( !empty( $s ) )
    1589                         $args['search'] = $s;
    1590                 if ( !empty( $orderby ) )
    1591                         $args['orderby'] = $orderby;
    1592                 if ( !empty( $order ) )
    1593                         $args['order'] = $order;
    1594 
    1595                 $this->items = get_bookmarks( $args );
    1596         }
    1597 
    1598         function no_items() {
    1599                 _e( 'No links found.' );
    1600         }
    1601 
    1602         function get_bulk_actions() {
    1603                 $actions = array();
    1604                 $actions['delete'] = __( 'Delete' );
    1605 
    1606                 return $actions;
    1607         }
    1608 
    1609         function extra_tablenav( $which ) {
    1610                 global $cat_id;
    1611 
    1612                 if ( 'top' != $which )
    1613                         return;
    1614 ?>
    1615                 <div class="alignleft actions">
    1616 <?php
    1617                         $dropdown_options = array(
    1618                                 'selected' => $cat_id,
    1619                                 'name' => 'cat_id',
    1620                                 'taxonomy' => 'link_category',
    1621                                 'show_option_all' => __( 'View all categories' ),
    1622                                 'hide_empty' => true,
    1623                                 'hierarchical' => 1,
    1624                                 'show_count' => 0,
    1625                                 'orderby' => 'name',
    1626                         );
    1627                         wp_dropdown_categories( $dropdown_options );
    1628 ?>
    1629                         <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" />
    1630                 </div>
    1631 <?php
    1632         }
    1633 
    1634         function get_columns() {
    1635                 return array(
    1636                         'cb'         => '<input type="checkbox" />',
    1637                         'name'       => __( 'Name' ),
    1638                         'url'        => __( 'URL' ),
    1639                         'categories' => __( 'Categories' ),
    1640                         'rel'        => __( 'Relationship' ),
    1641                         'visible'    => __( 'Visible' ),
    1642                         'rating'     => __( 'Rating' )
    1643                 );
    1644         }
    1645 
    1646         function get_sortable_columns() {
    1647                 return array(
    1648                         'name'    => 'name',
    1649                         'url'     => 'url',
    1650                         'visible' => 'visible',
    1651                         'rating'  => 'rating'
    1652                 );
    1653         }
    1654 
    1655         function display_rows() {
    1656                 global $cat_id;
    1657 
    1658                 $alt = 0;
    1659 
    1660                 foreach ( $this->items as $link ) {
    1661                         $link = sanitize_bookmark( $link );
    1662                         $link->link_name = esc_attr( $link->link_name );
    1663                         $link->link_category = wp_get_link_cats( $link->link_id );
    1664 
    1665                         $short_url = str_replace( 'http://', '', $link->link_url );
    1666                         $short_url = preg_replace( '/^www\./i', '', $short_url );
    1667                         if ( '/' == substr( $short_url, -1 ) )
    1668                                 $short_url = substr( $short_url, 0, -1 );
    1669                         if ( strlen( $short_url ) > 35 )
    1670                                 $short_url = substr( $short_url, 0, 32 ).'...';
    1671 
    1672                         $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' );
    1673                         $rating  = $link->link_rating;
    1674                         $style = ( $alt++ % 2 ) ? '' : ' class="alternate"';
    1675 
    1676                         $edit_link = get_edit_bookmark_link( $link );
    1677 ?>
    1678                 <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
    1679 <?php
    1680 
    1681                         list( $columns, $hidden ) = $this->get_column_info();
    1682 
    1683                         foreach ( $columns as $column_name => $column_display_name ) {
    1684                                 $class = "class='column-$column_name'";
    1685 
    1686                                 $style = '';
    1687                                 if ( in_array( $column_name, $hidden ) )
    1688                                         $style = ' style="display:none;"';
    1689 
    1690                                 $attributes = $class . $style;
    1691 
    1692                                 switch ( $column_name ) {
    1693                                         case 'cb':
    1694                                                 echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr( $link->link_id ) .'" /></th>';
    1695                                                 break;
    1696 
    1697                                         case 'name':
    1698                                                 echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />";
    1699 
    1700                                                 $actions = array();
    1701                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    1702                                                 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>";
    1703                                                 echo $this->row_actions( $actions );
    1704 
    1705                                                 echo '</td>';
    1706                                                 break;
    1707                                         case 'url':
    1708                                                 echo "<td $attributes><a href='$link->link_url' title='".sprintf( __( 'Visit %s' ), $link->link_name )."'>$short_url</a></td>";
    1709                                                 break;
    1710                                         case 'categories':
    1711                                                 ?><td <?php echo $attributes ?>><?php
    1712                                                 $cat_names = array();
    1713                                                 foreach ( $link->link_category as $category ) {
    1714                                                         $cat = get_term( $category, 'link_category', OBJECT, 'display' );
    1715                                                         if ( is_wp_error( $cat ) )
    1716                                                                 echo $cat->get_error_message();
    1717                                                         $cat_name = $cat->name;
    1718                                                         if ( $cat_id != $category )
    1719                                                                 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
    1720                                                         $cat_names[] = $cat_name;
    1721                                                 }
    1722                                                 echo implode( ', ', $cat_names );
    1723                                                 ?></td><?php
    1724                                                 break;
    1725                                         case 'rel':
    1726                                                 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
    1727                                                 break;
    1728                                         case 'visible':
    1729                                                 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
    1730                                                 break;
    1731                                         case 'rating':
    1732                                                 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
    1733                                                 break;
    1734                                         default:
    1735                                                 ?>
    1736                                                 <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>
    1737                                                 <?php
    1738                                                 break;
    1739                                 }
    1740                         }
    1741 ?>
    1742                 </tr>
    1743 <?php
    1744                 }
    1745         }
    1746 }
    1747 
    1748 class WP_Sites_Table extends WP_List_Table {
    1749 
    1750         function WP_Sites_Table() {
    1751                 parent::WP_List_Table( array(
    1752                         'screen' => 'sites-network',
    1753                         'plural' => 'sites',
    1754                 ) );
    1755         }
    1756 
    1757         function check_permissions() {
    1758                 if ( ! current_user_can( 'manage_sites' ) )
    1759                         wp_die( __( 'You do not have permission to access this page.' ) );
    1760         }
    1761 
    1762         function prepare_items() {
    1763                 global $s, $mode, $wpdb;
    1764 
    1765                 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
    1766 
    1767                 $per_page = $this->get_items_per_page( 'sites_network_per_page' );
    1768 
    1769                 $pagenum = $this->get_pagenum();
    1770 
    1771                 $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
    1772                 $like_s = esc_sql( like_escape( $s ) );
    1773 
    1774                 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
    1775 
    1776                 if ( isset( $_REQUEST['searchaction'] ) ) {
    1777                         if ( 'name' == $_REQUEST['searchaction'] ) {
    1778                                 $query .= " AND ( {$wpdb->blogs}.domain LIKE '%{$like_s}%' OR {$wpdb->blogs}.path LIKE '%{$like_s}%' ) ";
    1779                         } elseif ( 'id' == $_REQUEST['searchaction'] ) {
    1780                                 $query .= " AND {$wpdb->blogs}.blog_id = '{$like_s}' ";
    1781                         } elseif ( 'ip' == $_REQUEST['searchaction'] ) {
    1782                                 $query = "SELECT *
    1783                                         FROM {$wpdb->blogs}, {$wpdb->registration_log}
    1784                                         WHERE site_id = '{$wpdb->siteid}'
    1785                                         AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
    1786                                         AND {$wpdb->registration_log}.IP LIKE ( '%{$like_s}%' )";
    1787                         }
    1788                 }
    1789 
    1790                 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'id';
    1791                 if ( $order_by == 'registered' ) {
    1792                         $query .= ' ORDER BY registered ';
    1793                 } elseif ( $order_by == 'lastupdated' ) {
    1794                         $query .= ' ORDER BY last_updated ';
    1795                 } elseif ( $order_by == 'blogname' ) {
    1796                         $query .= ' ORDER BY domain ';
    1797                 } else {
    1798                         $order_by = 'id';
    1799                         $query .= " ORDER BY {$wpdb->blogs}.blog_id ";
    1800                 }
    1801 
    1802                 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
    1803                 $query .= $order;
    1804 
    1805                 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
    1806 
    1807                 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
    1808                 $this->items = $wpdb->get_results( $query, ARRAY_A );
    1809 
    1810                 $this->set_pagination_args( array(
    1811                         'total_items' => $total,
    1812                         'per_page' => $per_page,
    1813                 ) );
    1814         }
    1815 
    1816         function no_items() {
    1817                 _e( 'No sites found.' );
    1818         }
    1819 
    1820         function get_bulk_actions() {
    1821                 $actions = array();
    1822                 $actions['delete'] = __( 'Delete' );
    1823                 $actions['spam'] = _x( 'Mark as Spam', 'site' );
    1824                 $actions['notspam'] = _x( 'Not Spam', 'site' );
    1825 
    1826                 return $actions;
    1827         }
    1828 
    1829         function pagination( $which ) {
    1830                 global $mode;
    1831 
    1832                 parent::pagination( $which );
    1833 
    1834                 if ( 'top' == $which )
    1835                         $this->view_switcher( $mode );
    1836         }
    1837 
    1838         function get_columns() {
    1839                 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
    1840                 $sites_columns = array(
    1841                         'cb'          => '<input type="checkbox" />',
    1842                         'blogname'    => $blogname_columns,
    1843                         'lastupdated' => __( 'Last Updated' ),
    1844                         'registered'  => _x( 'Registered', 'site' ),
    1845                         'users'       => __( 'Users' )
    1846                 );
    1847 
    1848                 if ( has_filter( 'wpmublogsaction' ) )
    1849                         $sites_columns['plugins'] = __( 'Actions' );
    1850 
    1851                 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
    1852 
    1853                 return $sites_columns;
    1854         }
    1855 
    1856         function get_sortable_columns() {
    1857                 return array(
    1858                         'id'          => 'id',
    1859                         'blogname'    => 'blogname',
    1860                         'lastupdated' => 'lastupdated',
    1861                         'registered'  => 'registered',
    1862                 );
    1863         }
    1864 
    1865         function display_rows() {
    1866                 global $current_site, $mode;
    1867 
    1868                 $status_list = array(
    1869                         'archived' => array( 'site-archived', __( 'Archived' ) ),
    1870                         'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
    1871                         'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
    1872                         'mature'   => array( 'site-mature', __( 'Mature' ) )
    1873                 );
    1874 
    1875                 $class = '';
    1876                 foreach ( $this->items as $blog ) {
    1877                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    1878                         reset( $status_list );
    1879 
    1880                         $blog_states = array();
    1881                         foreach ( $status_list as $status => $col ) {
    1882                                 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
    1883                                         $class = $col[0];
    1884                                         $blog_states[] = $col[1];
    1885                                 }
    1886                         }
    1887                         $blog_state = '';
    1888                         if ( ! empty( $blog_states ) ) {
    1889                                 $state_count = count( $blog_states );
    1890                                 $i = 0;
    1891                                 $blog_state .= ' - ';
    1892                                 foreach ( $blog_states as $state ) {
    1893                                         ++$i;
    1894                                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
    1895                                         $blog_state .= "<span class='post-state'>$state$sep</span>";
    1896                                 }
    1897                         }
    1898                         echo "<tr class='$class'>";
    1899 
    1900                         $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
    1901 
    1902                         list( $columns, $hidden ) = $this->get_column_info();
    1903 
    1904                         foreach ( $columns as $column_name => $column_display_name ) {
    1905                                 switch ( $column_name ) {
    1906                                         case 'cb': ?>
    1907                                                 <th scope="row" class="check-column">
    1908                                                         <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
    1909                                                 </th>
    1910                                         <?php
    1911                                         break;
    1912 
    1913                                         case 'id': ?>
    1914                                                 <th valign="top" scope="row">
    1915                                                         <?php echo $blog['blog_id'] ?>
    1916                                                 </th>
    1917                                         <?php
    1918                                         break;
    1919 
    1920                                         case 'blogname': ?>
    1921                                                 <td class="column-title">
    1922                                                         <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
    1923                                                         <?php
    1924                                                         if ( 'list' != $mode )
    1925                                                                 echo '<p>' . sprintf( _x( '%1$s &#8211; <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_blog_option( $blog['blog_id'], 'blogname' ), get_blog_option( $blog['blog_id'], 'blogdescription ' ) ) . '</p>';
    1926 
    1927                                                         // Preordered.
    1928                                                         $actions = array(
    1929                                                                 'edit' => '', 'backend' => '',
    1930                                                                 'activate' => '', 'deactivate' => '',
    1931                                                                 'archive' => '', 'unarchive' => '',
    1932                                                                 'spam' => '', 'unspam' => '',
    1933                                                                 'delete' => '',
    1934                                                                 'visit' => '',
    1935                                                         );
    1936 
    1937                                                         $actions['edit']        = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
    1938                                                         $actions['backend']     = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
    1939                                                         if ( $current_site->blog_id != $blog['blog_id'] ) {
    1940                                                                 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
    1941                                                                         $actions['activate']    = '<span class="activate"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ) ) . '">' . __( 'Activate' ) . '</a></span>';
    1942                                                                 else
    1943                                                                         $actions['deactivate']  = '<span class="activate"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ) ) . '">' . __( 'Deactivate' ) . '</a></span>';
    1944 
    1945                                                                 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
    1946                                                                         $actions['unarchive']   = '<span class="archive"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=unarchiveblog&amp;id=' .  $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Unarchive' ) . '</a></span>';
    1947                                                                 else
    1948                                                                         $actions['archive']     = '<span class="archive"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
    1949 
    1950                                                                 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
    1951                                                                         $actions['unspam']      = '<span class="spam"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
    1952                                                                 else
    1953                                                                         $actions['spam']        = '<span class="spam"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ) ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
    1954 
    1955                                                                 $actions['delete']      = '<span class="delete"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Delete' ) . '</a></span>';
    1956                                                         }
    1957 
    1958                                                         $actions['visit']       = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
    1959                                                         $actions = array_filter( $actions );
    1960                                                         echo $this->row_actions( $actions );
    1961                                         ?>
    1962                                                 </td>
    1963                                         <?php
    1964                                         break;
    1965 
    1966                                         case 'lastupdated': ?>
    1967                                                 <td valign="top">
    1968                                                         <?php
    1969                                                         if ( 'list' == $mode )
    1970                                                                 $date = 'Y/m/d';
    1971                                                         else
    1972                                                                 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    1973                                                         echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
    1974                                                 </td>
    1975                                         <?php
    1976                                         break;
    1977                                 case 'registered': ?>
    1978                                                 <td valign="top">
    1979                                                 <?php
    1980                                                 if ( $blog['registered'] == '0000-00-00 00:00:00' )
    1981                                                         echo '&#x2014;';
    1982                                                 else
    1983                                                         echo mysql2date( $date, $blog['registered'] );
    1984                                                 ?>
    1985                                                 </td>
    1986                                 <?php
    1987                                 break;
    1988                                         case 'users': ?>
    1989                                                 <td valign="top">
    1990                                                         <?php
    1991                                                         $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
    1992                                                         if ( is_array( $blogusers ) ) {
    1993                                                                 $blogusers_warning = '';
    1994                                                                 if ( count( $blogusers ) > 5 ) {
    1995                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
    1996                                                                         $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '">' . __( 'More' ) . '</a>';
    1997                                                                 }
    1998                                                                 foreach ( $blogusers as $user_object ) {
    1999                                                                         echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
    2000                                                                         if ( 'list' != $mode )
    2001                                                                                 echo '( ' . $user_object->user_email . ' )';
    2002                                                                         echo '<br />';
    2003                                                                 }
    2004                                                                 if ( $blogusers_warning != '' )
    2005                                                                         echo '<strong>' . $blogusers_warning . '</strong><br />';
    2006                                                         }
    2007                                                         ?>
    2008                                                 </td>
    2009                                         <?php
    2010                                         break;
    2011 
    2012                                         case 'plugins': ?>
    2013                                                 <?php if ( has_filter( 'wpmublogsaction' ) ) { ?>
    2014                                                 <td valign="top">
    2015                                                         <?php do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
    2016                                                 </td>
    2017                                                 <?php } ?>
    2018                                         <?php break;
    2019 
    2020                                         default: ?>
    2021                                                 <?php if ( has_filter( 'manage_blogs_custom_column' ) ) { ?>
    2022                                                 <td valign="top">
    2023                                                         <?php do_action( 'manage_blogs_custom_column', $column_name, $blog['blog_id'] ); ?>
    2024                                                 </td>
    2025                                                 <?php } ?>
    2026                                         <?php break;
    2027                                 }
    2028                         }
    2029                         ?>
    2030                         </tr>
    2031                         <?php
    2032                 }
    2033         }
    2034 }
    2035 
    2036 class WP_MS_Users_Table extends WP_List_Table {
    2037 
    2038         function WP_MS_Users_Table() {
    2039                 parent::WP_List_Table( array(
    2040                         'screen' => 'users-network',
    2041                 ) );
    2042         }
    2043 
    2044         function check_permissions() {
    2045                 if ( !is_multisite() )
    2046                         wp_die( __( 'Multisite support is not enabled.' ) );
    2047 
    2048                 if ( ! current_user_can( 'manage_network_users' ) )
    2049                         wp_die( __( 'You do not have permission to access this page.' ) );
    2050         }
    2051 
    2052         function prepare_items() {
    2053                 global $usersearch;
    2054 
    2055                 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    2056 
    2057                 $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
    2058 
    2059                 $paged = $this->get_pagenum();
    2060 
    2061                 $args = array(
    2062                         'number' => $users_per_page,
    2063                         'offset' => ( $paged-1 ) * $users_per_page,
    2064                         'search' => $usersearch,
    2065                         'blog_id' => 0
    2066                 );
    2067 
    2068                 if ( isset( $_REQUEST['orderby'] ) )
    2069                         $args['orderby'] = $_REQUEST['orderby'];
    2070 
    2071                 if ( isset( $_REQUEST['order'] ) )
    2072                         $args['order'] = $_REQUEST['order'];
    2073 
    2074                 // Query the user IDs for this page
    2075                 $wp_user_search = new WP_User_Query( $args );
    2076 
    2077                 $this->items = $wp_user_search->get_results();
    2078 
    2079                 $this->set_pagination_args( array(
    2080                         'total_items' => $wp_user_search->get_total(),
    2081                         'per_page' => $users_per_page,
    2082                 ) );
    2083         }
    2084 
    2085         function get_bulk_actions() {
    2086                 $actions = array();
    2087                 $actions['delete'] = __( 'Delete' );
    2088                 $actions['spam'] = _x( 'Mark as Spam', 'user' );
    2089                 $actions['notspam'] = _x( 'Not Spam', 'user' );
    2090 
    2091                 return $actions;
    2092         }
    2093 
    2094         function no_items() {
    2095                 _e( 'No users found.' );
    2096         }
    2097 
    2098         function pagination( $which ) {
    2099                 global $mode;
    2100 
    2101                 parent::pagination ( $which );
    2102 
    2103                 if ( 'top' == $which )
    2104                         $this->view_switcher( $mode );
    2105         }
    2106 
    2107         function get_columns() {
    2108                 $users_columns = array(
    2109                         'cb'         => '<input type="checkbox" />',
    2110                         'login'      => __( 'Login' ),
    2111                         'name'       => __( 'Name' ),
    2112                         'email'      => __( 'E-mail' ),
    2113                         'registered' => _x( 'Registered', 'user' ),
    2114                         'blogs'      => __( 'Sites' )
    2115                 );
    2116                 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
    2117 
    2118                 return $users_columns;
    2119         }
    2120 
    2121         function get_sortable_columns() {
    2122                 return array(
    2123                         'id'         => 'id',
    2124                         'login'      => 'login',
    2125                         'name'       => 'name',
    2126                         'email'      => 'email',
    2127                         'registered' => 'registered',
    2128                 );
    2129         }
    2130 
    2131         function display_rows() {
    2132                 global $current_site, $mode;
    2133 
    2134                 $class = '';
    2135                 $super_admins = get_super_admins();
    2136                 foreach ( $this->items as $user ) {
    2137                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    2138 
    2139                         $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
    2140 
    2141                         foreach ( $status_list as $status => $col ) {
    2142                                 if ( $user->$status )
    2143                                         $class = $col;
    2144                         }
    2145 
    2146                         ?>
    2147                         <tr class="<?php echo $class; ?>">
    2148                         <?php
    2149 
    2150                         list( $columns, $hidden ) = $this->get_column_info();
    2151 
    2152                         foreach ( $columns as $column_name => $column_display_name ) :
    2153                                 switch ( $column_name ) {
    2154                                         case 'cb': ?>
    2155                                                 <th scope="row" class="check-column">
    2156                                                         <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
    2157                                                 </th>
    2158                                         <?php
    2159                                         break;
    2160 
    2161                                         case 'id': ?>
    2162                                                 <th valign="top" scope="row">
    2163                                                         <?php echo $user->ID ?>
    2164                                                 </th>
    2165                                         <?php
    2166                                         break;
    2167 
    2168                                         case 'login':
    2169                                                 $avatar = get_avatar( $user->user_email, 32 );
    2170                                                 $edit_link = ( get_current_user_id() == $user->ID ) ? 'profile.php' : 'user-edit.php?user_id=' . $user->ID;
    2171                                                 ?>
    2172                                                 <td class="username column-username">
    2173                                                         <?php echo $avatar; ?><strong><a href="<?php echo esc_url( self_admin_url( $edit_link ) ); ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php
    2174                                                         if ( in_array( $user->user_login, $super_admins ) )
    2175                                                                 echo ' - ' . __( 'Super admin' );
    2176                                                         ?></strong>
    2177                                                         <br/>
    2178                                                         <?php
    2179                                                                 $actions = array();
    2180                                                                 $actions['edit'] = '<a href="' . esc_url( self_admin_url( $edit_link ) ) . '">' . __( 'Edit' ) . '</a>';
    2181 
    2182                                                                 if ( ! in_array( $user->user_login, $super_admins ) ) {
    2183                                                                         $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
    2184                                                                 }
    2185 
    2186                                                                 echo $this->row_actions( $actions );
    2187                                                         ?>
    2188                                                         </div>
    2189                                                 </td>
    2190                                         <?php
    2191                                         break;
    2192 
    2193                                         case 'name': ?>
    2194                                                 <td class="name column-name"><?php echo $user->display_name ?></td>
    2195                                         <?php
    2196                                         break;
    2197 
    2198                                         case 'email': ?>
    2199                                                 <td class="email column-email"><a href="mailto:<?php echo $user->user_email ?>"><?php echo $user->user_email ?></a></td>
    2200                                         <?php
    2201                                         break;
    2202 
    2203                                         case 'registered':
    2204                                                 if ( 'list' == $mode )
    2205                                                         $date = 'Y/m/d';
    2206                                                 else
    2207                                                         $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    2208                                         ?>
    2209                                                 <td><?php echo mysql2date( $date, $user->user_registered ); ?></td>
    2210                                         <?php
    2211                                         break;
    2212 
    2213                                         case 'blogs':
    2214                                                 $blogs = get_blogs_of_user( $user->ID, true );
    2215                                                 ?>
    2216                                                 <td>
    2217                                                         <?php
    2218                                                         if ( is_array( $blogs ) ) {
    2219                                                                 foreach ( (array) $blogs as $key => $val ) {
    2220                                                                         $path   = ( $val->path == '/' ) ? '' : $val->path;
    2221                                                                         echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
    2222                                                                         echo ' <small class="row-actions">';
    2223 
    2224                                                                         // Edit
    2225                                                                         echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a> | ';
    2226 
    2227                                                                         // View
    2228                                                                         echo '<a ';
    2229                                                                         if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
    2230                                                                                 echo 'style="background-color: #faa" ';
    2231                                                                         echo 'href="' .  esc_url( get_home_url( $val->userblog_id ) )  . '">' . __( 'View' ) . '</a>';
    2232 
    2233                                                                         echo '</small><br />';
    2234                                                                 }
    2235                                                         }
    2236                                                         ?>
    2237                                                 </td>
    2238                                         <?php
    2239                                         break;
    2240 
    2241                                         default: ?>
    2242                                                 <td><?php do_action( 'manage_users_custom_column', $column_name, $user->ID ); ?></td>
    2243                                         <?php
    2244                                         break;
    2245                                 }
    2246                         endforeach
    2247                         ?>
    2248                         </tr>
    2249                         <?php
    2250                 }
    2251         }
    2252 }
    2253 
    2254 class WP_Plugins_Table extends WP_List_Table {
    2255 
    2256         function WP_Plugins_Table() {
    2257                 global $status, $page;
    2258 
    2259                 $default_status = get_user_option( 'plugins_last_view' );
    2260                 if ( empty( $default_status ) )
    2261                         $default_status = 'all';
    2262                 $status = isset( $_REQUEST['plugin_status'] ) ? $_REQUEST['plugin_status'] : $default_status;
    2263                 if ( !in_array( $status, array( 'all', 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
    2264                         $status = 'all';
    2265                 if ( $status != $default_status && 'search' != $status )
    2266                         update_user_meta( get_current_user_id(), 'plugins_last_view', $status );
    2267 
    2268                 $page = $this->get_pagenum();
    2269 
    2270                 parent::WP_List_Table( array(
    2271                         'screen' => 'plugins',
    2272                         'plural' => 'plugins',
    2273                 ) );
    2274         }
    2275 
    2276         function check_permissions() {
    2277                 if ( is_multisite() ) {
    2278                         $menu_perms = get_site_option( 'menu_items', array() );
    2279 
    2280                         if ( empty( $menu_perms['plugins'] ) ) {
    2281                                 if ( !is_super_admin() )
    2282                                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    2283                         }
    2284                 }
    2285 
    2286                 if ( !current_user_can('activate_plugins') )
    2287                         wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
    2288         }
    2289 
    2290         function prepare_items() {
    2291                 global $status, $plugins, $totals, $page, $orderby, $order, $s;
    2292 
    2293                 wp_reset_vars( array( 'orderby', 'order', 's' ) );
    2294 
    2295                 $plugins = array(
    2296                         'all' => apply_filters( 'all_plugins', get_plugins() ),
    2297                         'search' => array(),
    2298                         'active' => array(),
    2299                         'inactive' => array(),
    2300                         'recently_activated' => array(),
    2301                         'upgrade' => array(),
    2302                         'mustuse' => array(),
    2303                         'dropins' => array()
    2304                 );
    2305 
    2306                 if ( ! is_multisite() || ( is_network_admin() && current_user_can('manage_network_plugins') ) ) {
    2307                         if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
    2308                                 $plugins['mustuse'] = get_mu_plugins();
    2309                         if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
    2310                                 $plugins['dropins'] = get_dropins();
    2311                 }
    2312 
    2313                 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
    2314 
    2315                 $recently_activated = get_option( 'recently_activated', array() );
    2316 
    2317                 $one_week = 7*24*60*60;
    2318                 foreach ( $recently_activated as $key => $time )
    2319                         if ( $time + $one_week < time() )
    2320                                 unset( $recently_activated[$key] );
    2321                 update_option( 'recently_activated', $recently_activated );
    2322 
    2323                 $current = get_site_transient( 'update_plugins' );
    2324 
    2325                 foreach ( array( 'all', 'mustuse', 'dropins' ) as $type ) {
    2326                         foreach ( (array) $plugins[$type] as $plugin_file => $plugin_data ) {
    2327                                 // Translate, Apply Markup, Sanitize HTML
    2328                                 $plugins[$type][$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
    2329                         }
    2330                 }
    2331 
    2332                 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    2333                         // Filter into individual sections
    2334                         if ( is_plugin_active_for_network($plugin_file) && !is_network_admin() ) {
    2335                                 unset( $plugins['all'][ $plugin_file ] );
    2336                                 continue;
    2337                         } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
    2338                                 $plugins['network'][ $plugin_file ] = $plugin_data;
    2339                         } elseif ( ( !is_network_admin() && is_plugin_active( $plugin_file ) )
    2340                                 || ( is_network_admin() && is_plugin_active_for_network( $plugin_file ) ) ) {
    2341                                 $plugins['active'][ $plugin_file ] = $plugin_data;
    2342                         } else {
    2343                                 if ( !is_network_admin() && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
    2344                                         $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
    2345                                 $plugins['inactive'][ $plugin_file ] = $plugin_data;
    2346                         }
    2347 
    2348                         if ( isset( $current->response[ $plugin_file ] ) )
    2349                                 $plugins['upgrade'][ $plugin_file ] = $plugin_data;
    2350                 }
    2351 
    2352                 if ( !current_user_can( 'update_plugins' ) )
    2353                         $plugins['upgrade'] = array();
    2354 
    2355                 if ( $s ) {
    2356                         $status = 'search';
    2357                         $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
    2358                 }
    2359 
    2360                 $totals = array();
    2361                 foreach ( $plugins as $type => $list )
    2362                         $totals[ $type ] = count( $list );
    2363 
    2364                 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
    2365                         $status = 'all';
    2366 
    2367                 $this->items = $plugins[ $status ];
    2368                 $total_this_page = $totals[ $status ];
    2369 
    2370                 if ( $orderby ) {
    2371                         $orderby = ucfirst( $orderby );
    2372                         $order = strtoupper( $order );
    2373 
    2374                         uasort( $this->items, array( $this, '_order_callback' ) );
    2375                 }
    2376 
    2377                 $plugins_per_page = $this->get_items_per_page( 'plugins_per_page', 999 );
    2378 
    2379                 $start = ( $page - 1 ) * $plugins_per_page;
    2380 
    2381                 if ( $total_this_page > $plugins_per_page )
    2382                         $this->items = array_slice( $this->items, $start, $plugins_per_page );
    2383 
    2384                 $this->set_pagination_args( array(
    2385                         'total_items' => $total_this_page,
    2386                         'per_page' => $plugins_per_page,
    2387                 ) );
    2388         }
    2389 
    2390         function _search_callback( $plugin ) {
    2391                 static $term;
    2392                 if ( is_null( $term ) )
    2393                         $term = stripslashes( $_REQUEST['s'] );
    2394 
    2395                 foreach ( $plugin as $value )
    2396                         if ( stripos( $value, $term ) !== false )
    2397                                 return true;
    2398 
    2399                 return false;
    2400         }
    2401 
    2402         function _order_callback( $plugin_a, $plugin_b ) {
    2403                 global $orderby, $order;
    2404 
    2405                 $a = $plugin_a[$orderby];
    2406                 $b = $plugin_b[$orderby];
    2407 
    2408                 if ( $a == $b )
    2409                         return 0;
    2410 
    2411                 if ( 'DESC' == $order )
    2412                         return ( $a < $b ) ? 1 : -1;
    2413                 else
    2414                         return ( $a < $b ) ? -1 : 1;
    2415         }
    2416 
    2417         function no_items() {
    2418                 global $plugins;
    2419 
    2420                 if ( !empty( $plugins['all'] ) )
    2421                         _e( 'No plugins found.' );
    2422                 else
    2423                         _e( 'You do not appear to have any plugins available at this time.' );
    2424         }
    2425 
    2426         function get_columns() {
    2427                 global $status;
    2428 
    2429                 return array(
    2430                         'cb'          => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
    2431                         'name'        => __( 'Plugin' ),
    2432                         'description' => __( 'Description' ),
    2433                 );
    2434         }
    2435 
    2436         function get_sortable_columns() {
    2437                 return array(
    2438                         'name'         => 'name',
    2439                         'description'  => 'description',
    2440                 );
    2441         }
    2442 
    2443         function display_tablenav( $which ) {
    2444                 global $status;
    2445 
    2446                 if ( !in_array( $status, array( 'mustuse', 'dropins' ) ) )
    2447                         parent::display_tablenav( $which );
    2448         }
    2449 
    2450         function get_views() {
    2451                 global $totals, $status;
    2452 
    2453                 $status_links = array();
    2454                 foreach ( $totals as $type => $count ) {
    2455                         if ( !$count )
    2456                                 continue;
    2457 
    2458                         switch ( $type ) {
    2459                                 case 'all':
    2460                                         $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
    2461                                         break;
    2462                                 case 'active':
    2463                                         $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
    2464                                         break;
    2465                                 case 'recently_activated':
    2466                                         $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
    2467                                         break;
    2468                                 case 'inactive':
    2469                                         $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
    2470                                         break;
    2471                                 case 'network':
    2472                                         $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
    2473                                         break;
    2474                                 case 'mustuse':
    2475                                         $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
    2476                                         break;
    2477                                 case 'dropins':
    2478                                         $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
    2479                                         break;
    2480                                 case 'upgrade':
    2481                                         $text = _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $count );
    2482                                         break;
    2483                                 case 'search':
    2484                                         $text = _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $count );
    2485                                         break;
    2486                         }
    2487 
    2488                         $status_links[$type] = sprintf( "<li><a href='%s' %s>%s</a>",
    2489                                 add_query_arg('plugin_status', $type, 'plugins.php'),
    2490                                 ( $type == $status ) ? ' class="current"' : '',
    2491                                 sprintf( $text, number_format_i18n( $count ) )
    2492                         );
    2493                 }
    2494 
    2495                 return $status_links;
    2496         }
    2497 
    2498         function get_bulk_actions() {
    2499                 global $status;
    2500 
    2501                 $actions = array();
    2502                 if ( 'active' != $status )
    2503                         $actions['activate-selected'] = __( 'Activate' );
    2504                 if ( is_multisite() && 'network' != $status )
    2505                         $actions['network-activate-selected'] = __( 'Network Activate' );
    2506                 if ( 'inactive' != $status && 'recent' != $status )
    2507                         $actions['deactivate-selected'] = __( 'Deactivate' );
    2508                 if ( current_user_can( 'update_plugins' ) )
    2509                         $actions['update-selected'] = __( 'Update' );
    2510                 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
    2511                         $actions['delete-selected'] = __( 'Delete' );
    2512 
    2513                 return $actions;
    2514         }
    2515 
    2516         function bulk_actions( $which ) {
    2517                 global $status;
    2518 
    2519                 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
    2520                         return;
    2521 
    2522                 parent::bulk_actions( $which );
    2523         }
    2524 
    2525         function extra_tablenav( $which ) {
    2526                 global $status;
    2527 
    2528                 if ( 'recently_activated' == $status ) { ?>
    2529                         <div class="alignleft actions">
    2530                                 <input type="submit" name="clear-recent-list" value="<?php esc_attr_e( 'Clear List' ) ?>" class="button-secondary" />
    2531                         </div>
    2532                 <?php }
    2533         }
    2534 
    2535         function current_action() {
    2536                 if ( isset($_POST['clear-recent-list']) )
    2537                         return 'clear-recent-list';
    2538 
    2539                 return parent::current_action();
    2540         }
    2541 
    2542         function display_rows() {
    2543                 global $status, $page, $s;
    2544 
    2545                 $context = $status;
    2546 
    2547                 foreach ( $this->items as $plugin_file => $plugin_data ) {
    2548                         // preorder
    2549                         $actions = array(
    2550                                 'network_deactivate' => '', 'deactivate' => '',
    2551                                 'network_only' => '', 'activate' => '',
    2552                                 'network_activate' => '',
    2553                                 'edit' => '',
    2554                                 'delete' => '',
    2555                         );
    2556 
    2557                         if ( 'mustuse' == $context ) {
    2558                                 if ( is_multisite() && !is_network_admin() )
    2559                                         continue;
    2560                                 $is_active = true;
    2561                         } elseif ( 'dropins' == $context ) {
    2562                                 if ( is_multisite() && !is_network_admin() )
    2563                                         continue;
    2564                                 $dropins = _get_dropins();
    2565                                 $plugin_name = $plugin_file;
    2566                                 if ( $plugin_file != $plugin_data['Name'] )
    2567                                         $plugin_name .= '<br/>' . $plugin_data['Name'];
    2568                                 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
    2569                                         $is_active = true;
    2570                                         $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
    2571                                 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
    2572                                         $is_active = true;
    2573                                         $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
    2574                                 } else {
    2575                                         $is_active = false;
    2576                                         $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
    2577                                 }
    2578                                 if ( $plugin_data['Description'] )
    2579                                         $description .= '<p>' . $plugin_data['Description'] . '</p>';
    2580                         } else {
    2581                                 $is_active_for_network = is_plugin_active_for_network($plugin_file);
    2582                                 if ( is_network_admin() )
    2583                                         $is_active = $is_active_for_network;
    2584                                 else
    2585                                         $is_active = is_plugin_active( $plugin_file );
    2586 
    2587                                 if ( $is_active_for_network && !is_super_admin() && !is_network_admin() )
    2588                                         continue;
    2589 
    2590                                 if ( is_network_admin() ) {
    2591                                         if ( $is_active_for_network ) {
    2592                                                 if ( current_user_can( 'manage_network_plugins' ) )
    2593                                                         $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
    2594                                         } else {
    2595                                                 if ( current_user_can( 'manage_network_plugins' ) )
    2596                                                         $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
    2597                                                 if ( current_user_can('delete_plugins') )
    2598                                                         $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    2599                                         }
    2600                                 } else {
    2601                                         if ( $is_active ) {
    2602                                                 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
    2603                                         } else {
    2604                                                 if ( is_network_only_plugin( $plugin_file ) && !is_network_admin() )
    2605                                                         continue;
    2606 
    2607                                                 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
    2608 
    2609                                                 if ( current_user_can('delete_plugins') )
    2610                                                         $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    2611                                         } // end if $is_active
    2612                                  } // end if is_network_admin()
    2613 
    2614                                 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    2615                                         $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    2616                         } // end if $context
    2617 
    2618                         $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
    2619                         $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
    2620 
    2621                         $class = $is_active ? 'active' : 'inactive';
    2622                         $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' />";
    2623                         if ( 'dropins' != $status ) {
    2624                                 $description = '<p>' . $plugin_data['Description'] . '</p>';
    2625                                 $plugin_name = $plugin_data['Name'];
    2626                         }
    2627 
    2628                         $id = sanitize_title( $plugin_name );
    2629 
    2630                         echo "
    2631                 <tr id='$id' class='$class'>
    2632                         <th scope='row' class='check-column'>$checkbox</th>
    2633                         <td class='plugin-title'><strong>$plugin_name</strong></td>
    2634                         <td class='desc'>$description</td>
    2635                 </tr>
    2636                 <tr class='$class second'>
    2637                         <td></td>
    2638                         <td class='plugin-title'>";
    2639 
    2640                         echo $this->row_actions( $actions, true );
    2641 
    2642                         echo "</td>
    2643                         <td class='desc'>";
    2644                         $plugin_meta = array();
    2645                         if ( !empty( $plugin_data['Version'] ) )
    2646                                 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
    2647                         if ( !empty( $plugin_data['Author'] ) ) {
    2648                                 $author = $plugin_data['Author'];
    2649                                 if ( !empty( $plugin_data['AuthorURI'] ) )
    2650                                         $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    2651                                 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
    2652                         }
    2653                         if ( ! empty( $plugin_data['PluginURI'] ) )
    2654                                 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
    2655 
    2656                         $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
    2657                         echo implode( ' | ', $plugin_meta );
    2658                         echo "</td>
    2659                 </tr>\n";
    2660 
    2661                         do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
    2662                         do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
    2663                 }
    2664         }
    2665 }
    2666 
    2667 class WP_Plugin_Install_Table extends WP_List_Table {
    2668 
    2669         function WP_Plugin_Install_Table() {
    2670                 parent::WP_List_Table( array(
    2671                         'screen' => 'plugin-install',
    2672                 ) );
    2673         }
    2674 
    2675         function check_permissions() {
    2676                 if ( ! current_user_can('install_plugins') )
    2677                         wp_die(__('You do not have sufficient permissions to install plugins on this site.'));
    2678         }
    2679 
    2680         function prepare_items() {
    2681                 include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    2682 
    2683                 global $tabs, $tab, $paged, $type, $term;
    2684 
    2685                 wp_reset_vars( array( 'tab' ) );
    2686 
    2687                 $paged = $this->get_pagenum();
    2688 
    2689                 $per_page = 30;
    2690 
    2691                 // These are the tabs which are shown on the page
    2692                 $tabs = array();
    2693                 $tabs['dashboard'] = __( 'Search' );
    2694                 if ( 'search' == $tab )
    2695                         $tabs['search'] = __( 'Search Results' );
    2696                 $tabs['upload'] = __( 'Upload' );
    2697                 $tabs['featured'] = _x( 'Featured','Plugin Installer' );
    2698                 $tabs['popular']  = _x( 'Popular','Plugin Installer' );
    2699                 $tabs['new']      = _x( 'Newest','Plugin Installer' );
    2700                 $tabs['updated']  = _x( 'Recently Updated','Plugin Installer' );
    2701 
    2702                 $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
    2703 
    2704                 $tabs = apply_filters( 'install_plugins_tabs', $tabs );
    2705                 $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
    2706 
    2707                 // If a non-valid menu tab has been selected, And its not a non-menu action.
    2708                 if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    2709                         $tab = key( $tabs );
    2710 
    2711                 $args = array( 'page' => $paged, 'per_page' => $per_page );
    2712 
    2713                 switch ( $tab ) {
    2714                         case 'search':
    2715                                 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
    2716                                 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    2717 
    2718                                 switch ( $type ) {
    2719                                         case 'tag':
    2720                                                 $args['tag'] = sanitize_title_with_dashes( $term );
    2721                                                 break;
    2722                                         case 'term':
    2723                                                 $args['search'] = $term;
    2724                                                 break;
    2725                                         case 'author':
    2726                                                 $args['author'] = $term;
    2727                                                 break;
    2728                                 }
    2729 
    2730                                 add_action( 'install_plugins_table_header', 'install_search_form' );
    2731                                 break;
    2732 
    2733                         case 'featured':
    2734                         case 'popular':
    2735                         case 'new':
    2736                         case 'updated':
    2737                                 $args['browse'] = $tab;
    2738                                 break;
    2739 
    2740                         default:
    2741                                 $args = false;
    2742                 }
    2743 
    2744                 if ( !$args )
    2745                         return;
    2746 
    2747                 $api = plugins_api( 'query_plugins', $args );
    2748 
    2749                 if ( is_wp_error( $api ) )
    2750                         wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
    2751 
    2752                 $this->items = $api->plugins;
    2753 
    2754                 $this->set_pagination_args( array(
    2755                         'total_items' => $api->info['results'],
    2756                         'per_page' => $per_page,
    2757                 ) );
    2758         }
    2759 
    2760         function no_items() {
    2761                 _e( 'No plugins match your request.' );
    2762         }
    2763 
    2764         function get_views() {
    2765                 global $tabs, $tab;
    2766 
    2767                 $display_tabs = array();
    2768                 foreach ( (array) $tabs as $action => $text ) {
    2769                         $class = ( $action == $tab ) ? ' class="current"' : '';
    2770                         $href = admin_url('plugin-install.php?tab=' . $action);
    2771                         $display_tabs[$action] = "<a href='$href'$class>$text</a>";
    2772                 }
    2773 
    2774                 return $display_tabs;
    2775         }
    2776 
    2777         function display_tablenav( $which ) {
    2778                 if ( 'top' ==  $which ) { ?>
    2779                         <div class="tablenav">
    2780                                 <div class="alignleft actions">
    2781                                         <?php do_action( 'install_plugins_table_header' ); ?>
    2782                                 </div>
    2783                                 <?php $this->pagination( $which ); ?>
    2784                                 <br class="clear" />
    2785                         </div>
    2786                 <?php } else { ?>
    2787                         <div class="tablenav">
    2788                                 <?php $this->pagination( $which ); ?>
    2789                                 <br class="clear" />
    2790                         </div>
    2791                 <?php
    2792                 }
    2793         }
    2794 
    2795         function get_table_classes() {
    2796                 extract( $this->_args );
    2797 
    2798                 return array( 'widefat', $plural );
    2799         }
    2800 
    2801         function get_columns() {
    2802                 return array(
    2803                         'name'        => __( 'Name' ),
    2804                         'version'     => __( 'Version' ),
    2805                         'rating'      => __( 'Rating' ),
    2806                         'description' => __( 'Description' ),
    2807                 );
    2808         }
    2809 
    2810         function display_rows() {
    2811                 $plugins_allowedtags = array(
    2812                         'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
    2813                         'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
    2814                         'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
    2815                         'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
    2816                 );
    2817 
    2818                 foreach ( (array) $this->items as $plugin ) {
    2819                         if ( is_object( $plugin ) )
    2820                                 $plugin = (array) $plugin;
    2821 
    2822                         $title = wp_kses( $plugin['name'], $plugins_allowedtags );
    2823                         //Limit description to 400char, and remove any HTML.
    2824                         $description = strip_tags( $plugin['description'] );
    2825                         if ( strlen( $description ) > 400 )
    2826                                 $description = mb_substr( $description, 0, 400 ) . '&#8230;';
    2827                         //remove any trailing entities
    2828                         $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
    2829                         //strip leading/trailing & multiple consecutive lines
    2830                         $description = trim( $description );
    2831                         $description = preg_replace( "|(\r?\n)+|", "\n", $description );
    2832                         //\n => <br>
    2833                         $description = nl2br( $description );
    2834                         $version = wp_kses( $plugin['version'], $plugins_allowedtags );
    2835 
    2836                         $name = strip_tags( $title . ' ' . $version );
    2837 
    2838                         $author = $plugin['author'];
    2839                         if ( ! empty( $plugin['author'] ) )
    2840                                 $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
    2841 
    2842                         $author = wp_kses( $author, $plugins_allowedtags );
    2843 
    2844                         $action_links = array();
    2845                         $action_links[] = '<a href="' . admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
    2846                                                                 '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
    2847                                                                 esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
    2848 
    2849                         if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
    2850                                 $status = install_plugin_install_status( $plugin );
    2851 
    2852                                 switch ( $status['status'] ) {
    2853                                         case 'install':
    2854                                                 if ( $status['url'] )
    2855                                                         $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
    2856                                                 break;
    2857                                         case 'update_available':
    2858                                                 if ( $status['url'] )
    2859                                                         $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
    2860                                                 break;
    2861                                         case 'latest_installed':
    2862                                         case 'newer_installed':
    2863                                                 $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . __( 'Installed' ) . '</span>';
    2864                                                 break;
    2865                                 }
    2866                         }
    2867 
    2868                         $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
    2869                 ?>
    2870                 <tr>
    2871                         <td class="name"><strong><?php echo $title; ?></strong>
    2872                                 <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
    2873                         </td>
    2874                         <td class="vers"><?php echo $version; ?></td>
    2875                         <td class="vers">
    2876                                 <div class="star-holder" title="<?php printf( _n( '( based on %s rating )', '( based on %s ratings )', $plugin['num_ratings'] ), number_format_i18n( $plugin['num_ratings'] ) ) ?>">
    2877                                         <div class="star star-rating" style="width: <?php echo esc_attr( $plugin['rating'] ) ?>px"></div>
    2878                                         <div class="star star5"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '5 stars' ) ?>" /></div>
    2879                                         <div class="star star4"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '4 stars' ) ?>" /></div>
    2880                                         <div class="star star3"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '3 stars' ) ?>" /></div>
    2881                                         <div class="star star2"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '2 stars' ) ?>" /></div>
    2882                                         <div class="star star1"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '1 star' ) ?>" /></div>
    2883                                 </div>
    2884                         </td>
    2885                         <td class="desc"><?php echo $description, $author; ?></td>
    2886                 </tr>
    2887                 <?php
    2888                 }
    2889         }
    2890 }
    2891 
    2892 class WP_Themes_Table extends WP_List_Table {
    2893 
    2894         var $search = array();
    2895         var $features = array();
    2896 
    2897         function WP_Themes_Table() {
    2898                 parent::__construct( array(
    2899                         'screen' => 'themes',
    2900                 ) );
    2901         }
    2902 
    2903         function check_permissions() {
    2904                 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
    2905                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    2906         }
    2907 
    2908         function prepare_items() {
    2909                 global $ct;
    2910 
    2911                 $ct = current_theme_info();
    2912 
    2913                 $themes = get_allowed_themes();
    2914 
    2915                 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
    2916 
    2917                 if ( '' !== $search ) {
    2918                         $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
    2919                         $this->search = array_unique( $this->search );
    2920                 }
    2921 
    2922                 if ( !empty( $_REQUEST['features'] ) ) {
    2923                         $this->features = $_REQUEST['features'];
    2924                         $this->features = array_map( 'trim', $this->features );
    2925                         $this->features = array_map( 'sanitize_title_with_dashes', $this->features );
    2926                         $this->features = array_unique( $this->features );
    2927                 }
    2928 
    2929                 if ( $this->search || $this->features ) {
    2930                         foreach ( $themes as $key => $theme ) {
    2931                                 if ( !$this->search_theme( $theme ) )
    2932                                         unset( $themes[ $key ] );
    2933                         }
    2934                 }
    2935 
    2936                 unset( $themes[$ct->name] );
    2937                 uksort( $themes, "strnatcasecmp" );
    2938 
    2939                 $per_page = 15;
    2940                 $page = $this->get_pagenum();
    2941 
    2942                 $start = ( $page - 1 ) * $per_page;
    2943 
    2944                 $this->items = array_slice( $themes, $start, $per_page );
    2945 
    2946                 $this->set_pagination_args( array(
    2947                         'query_var' => 'pagenum',
    2948                         'total_items' => count( $themes ),
    2949                         'per_page' => $per_page,
    2950                 ) );
    2951         }
    2952 
    2953         function no_items() {
    2954                 if ( current_user_can( 'install_themes' ) )
    2955                         printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <em><a href="%s">Install Themes</a></em> tab above.' ), 'theme-install.php' );
    2956                 else
    2957                         printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
    2958         }
    2959 
    2960         function display_table() {
    2961 ?>
    2962                 <div class="tablenav">
    2963                         <?php $this->pagination( 'top' ); ?>
    2964                         <br class="clear" />
    2965                 </div>
    2966 
    2967                 <table id="availablethemes" cellspacing="0" cellpadding="0">
    2968                         <tbody id="the-list" class="list:themes">
    2969                                 <?php $this->display_rows(); ?>
    2970                         </tbody>
    2971                 </table>
    2972 
    2973                 <div class="tablenav">
    2974                         <?php $this->pagination( 'bottom' ); ?>
    2975                         <br class="clear" />
    2976                 </div>
    2977 <?php
    2978         }
    2979 
    2980         function get_columns() {
    2981                 return array();
    2982         }
    2983 
    2984         function display_rows() {
    2985                 $themes = $this->items;
    2986                 $theme_names = array_keys( $themes );
    2987                 natcasesort( $theme_names );
    2988 
    2989                 $table = array();
    2990                 $rows = ceil( count( $theme_names ) / 3 );
    2991                 for ( $row = 1; $row <= $rows; $row++ )
    2992                         for ( $col = 1; $col <= 3; $col++ )
    2993                                 $table[$row][$col] = array_shift( $theme_names );
    2994 
    2995                 foreach ( $table as $row => $cols ) {
    2996 ?>
    2997 <tr>
    2998 <?php
    2999 foreach ( $cols as $col => $theme_name ) {
    3000         $class = array( 'available-theme' );
    3001         if ( $row == 1 ) $class[] = 'top';
    3002         if ( $col == 1 ) $class[] = 'left';
    3003         if ( $row == $rows ) $class[] = 'bottom';
    3004         if ( $col == 3 ) $class[] = 'right';
    3005 ?>
    3006         <td class="<?php echo join( ' ', $class ); ?>">
    3007 <?php if ( !empty( $theme_name ) ) :
    3008         $template = $themes[$theme_name]['Template'];
    3009         $stylesheet = $themes[$theme_name]['Stylesheet'];
    3010         $title = $themes[$theme_name]['Title'];
    3011         $version = $themes[$theme_name]['Version'];
    3012         $description = $themes[$theme_name]['Description'];
    3013         $author = $themes[$theme_name]['Author'];
    3014         $screenshot = $themes[$theme_name]['Screenshot'];
    3015         $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
    3016         $template_dir = $themes[$theme_name]['Template Dir'];
    3017         $parent_theme = $themes[$theme_name]['Parent Theme'];
    3018         $theme_root = $themes[$theme_name]['Theme Root'];
    3019         $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
    3020         $preview_link = esc_url( get_option( 'home' ) . '/' );
    3021         if ( is_ssl() )
    3022                 $preview_link = str_replace( 'http://', 'https://', $preview_link );
    3023         $preview_link = htmlspecialchars( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
    3024         $preview_text = esc_attr( sprintf( __( 'Preview of &#8220;%s&#8221;' ), $title ) );
    3025         $tags = $themes[$theme_name]['Tags'];
    3026         $thickbox_class = 'thickbox thickbox-preview';
    3027         $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=".urlencode( $template )."&amp;stylesheet=".urlencode( $stylesheet ), 'switch-theme_' . $template );
    3028         $activate_text = esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) );
    3029         $actions = array();
    3030         $actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>';
    3031         $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>';
    3032         if ( current_user_can( 'delete_themes' ) )
    3033                 $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $theme_name ) ) . "' );" . '">' . __( 'Delete' ) . '</a>';
    3034         $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] );
    3035 
    3036         $actions = implode ( ' | ', $actions );
    3037 ?>
    3038                 <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
    3039 <?php if ( $screenshot ) : ?>
    3040                         <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
    3041 <?php endif; ?>
    3042                 </a>
    3043 <h3><?php
    3044         /* translators: 1: theme title, 2: theme version, 3: theme author */
    3045         printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
    3046 <p class="description"><?php echo $description; ?></p>
    3047 <span class='action-links'><?php echo $actions ?></span>
    3048         <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) {
    3049         /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
    3050         <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ); ?></p>
    3051 <?php } else { ?>
    3052         <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
    3053 <?php } ?>
    3054 <?php if ( $tags ) : ?>
    3055 <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p>
    3056 <?php endif; ?>
    3057                 <?php theme_update_available( $themes[$theme_name] ); ?>
    3058 <?php endif; // end if not empty theme_name ?>
    3059         </td>
    3060 <?php } // end foreach $cols ?>
    3061 </tr>
    3062 <?php } // end foreach $table
    3063         }
    3064 
    3065         function search_theme( $theme ) {
    3066                 $matched = 0;
    3067 
    3068                 // Match all phrases
    3069                 if ( count( $this->search ) > 0 ) {
    3070                         foreach ( $this->search as $word ) {
    3071                                 $matched = 0;
    3072 
    3073                                 // In a tag?
    3074                                 if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
    3075                                         $matched = 1;
    3076 
    3077                                 // In one of the fields?
    3078                                 foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
    3079                                         if ( stripos( $theme[$field], $word ) !== false )
    3080                                                 $matched++;
    3081                                 }
    3082 
    3083                                 if ( $matched == 0 )
    3084                                         return false;
    3085                         }
    3086                 }
    3087 
    3088                 // Now search the features
    3089                 if ( count( $this->features ) > 0 ) {
    3090                         foreach ( $this->features as $word ) {
    3091                                 // In a tag?
    3092                                 if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
    3093                                         return false;
    3094                         }
    3095                 }
    3096 
    3097                 // Only get here if each word exists in the tags or one of the fields
    3098                 return true;
    3099         }
    3100 }
    3101 
    3102 class WP_Theme_Install_Table extends WP_List_Table {
    3103 
    3104         function WP_Theme_Install_Table() {
    3105                 parent::WP_List_Table( array(
    3106                         'screen' => 'theme-install',
    3107                 ) );
    3108         }
    3109 
    3110         function check_permissions() {
    3111                 if ( ! current_user_can('install_themes') )
    3112                         wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
    3113         }
    3114 
    3115         function prepare_items() {
    3116                 include( ABSPATH . 'wp-admin/includes/theme-install.php' );
    3117 
    3118                 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults;
    3119 
    3120                 wp_reset_vars( array( 'tab' ) );
    3121 
    3122                 $paged = $this->get_pagenum();
    3123 
    3124                 $per_page = 30;
    3125 
    3126                 // These are the tabs which are shown on the page,
    3127                 $tabs = array();
    3128                 $tabs['dashboard'] = __( 'Search' );
    3129                 if ( 'search' == $tab )
    3130                         $tabs['search'] = __( 'Search Results' );
    3131                 $tabs['upload'] = __( 'Upload' );
    3132                 $tabs['featured'] = _x( 'Featured','Theme Installer' );
    3133                 //$tabs['popular']  = _x( 'Popular','Theme Installer' );
    3134                 $tabs['new']      = _x( 'Newest','Theme Installer' );
    3135                 $tabs['updated']  = _x( 'Recently Updated','Theme Installer' );
    3136 
    3137                 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
    3138 
    3139                 $tabs = apply_filters( 'install_themes_tabs', $tabs );
    3140                 $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
    3141 
    3142                 // If a non-valid menu tab has been selected, And its not a non-menu action.
    3143                 if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
    3144                         $tab = key( $tabs );
    3145 
    3146                 $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
    3147 
    3148                 switch ( $tab ) {
    3149                         case 'search':
    3150                                 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
    3151                                 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    3152 
    3153                                 switch ( $type ) {
    3154                                         case 'tag':
    3155                                                 $terms = explode( ',', $term );
    3156                                                 $terms = array_map( 'trim', $terms );
    3157                                                 $terms = array_map( 'sanitize_title_with_dashes', $terms );
    3158                                                 $args['tag'] = $terms;
    3159                                                 break;
    3160                                         case 'term':
    3161                                                 $args['search'] = $term;
    3162                                                 break;
    3163                                         case 'author':
    3164                                                 $args['author'] = $term;
    3165                                                 break;
    3166                                 }
    3167 
    3168                                 if ( !empty( $_POST['features'] ) ) {
    3169                                         $terms = $_POST['features'];
    3170                                         $terms = array_map( 'trim', $terms );
    3171                                         $terms = array_map( 'sanitize_title_with_dashes', $terms );
    3172                                         $args['tag'] = $terms;
    3173                                         $_REQUEST['s'] = implode( ',', $terms );
    3174                                         $_REQUEST['type'] = 'tag';
    3175                                 }
    3176 
    3177                                 add_action( 'install_themes_table_header', 'install_theme_search_form' );
    3178                                 break;
    3179 
    3180                         case 'featured':
    3181                         //case 'popular':
    3182                         case 'new':
    3183                         case 'updated':
    3184                                 $args['browse'] = $tab;
    3185                                 break;
    3186 
    3187                         default:
    3188                                 $args = false;
    3189                 }
    3190 
    3191                 if ( !$args )
    3192                         return;
    3193 
    3194                 $api = themes_api( 'query_themes', $args );
    3195 
    3196                 if ( is_wp_error( $api ) )
    3197                         wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
    3198 
    3199                 $this->items = $api->themes;
    3200 
    3201                 $this->set_pagination_args( array(
    3202                         'total_items' => $api->info['results'],
    3203                         'per_page' => $per_page,
    3204                 ) );
    3205         }
    3206 
    3207         function no_items() {
    3208                 _e( 'No themes match your request.' );
    3209         }
    3210 
    3211         function get_views() {
    3212                 global $tabs, $tab;
    3213 
    3214                 $display_tabs = array();
    3215                 foreach ( (array) $tabs as $action => $text ) {
    3216                         $class = ( $action == $tab ) ? ' class="current"' : '';
    3217                         $href = self_admin_url('theme-install.php?tab=' . $action);
    3218                         $display_tabs[$action] = "<a href='$href'$class>$text</a>";
    3219                 }
    3220 
    3221                 return $display_tabs;
    3222         }
    3223 
    3224         function get_columns() {
    3225                 return array();
    3226         }
    3227 
    3228         function display_table() {
    3229 ?>
    3230                 <div class="tablenav">
    3231                         <div class="alignleft actions">
    3232                                 <?php do_action( 'install_themes_table_header' ); ?>
    3233                         </div>
    3234                         <?php $this->pagination( 'top' ); ?>
    3235                         <br class="clear" />
    3236                 </div>
    3237 
    3238                 <table id="availablethemes" cellspacing="0" cellpadding="0">
    3239                         <tbody id="the-list" class="list:themes">
    3240                                 <?php $this->display_rows(); ?>
    3241                         </tbody>
    3242                 </table>
    3243 
    3244                 <div class="tablenav">
    3245                         <?php $this->pagination( 'bottom' ); ?>
    3246                         <br class="clear" />
    3247                 </div>
    3248 <?php
    3249         }
    3250 
    3251         function display_rows() {
    3252                 $themes = $this->items;
    3253 
    3254                 $rows = ceil( count( $themes ) / 3 );
    3255                 $table = array();
    3256                 $theme_keys = array_keys( $themes );
    3257                 for ( $row = 1; $row <= $rows; $row++ )
    3258                         for ( $col = 1; $col <= 3; $col++ )
    3259                                 $table[$row][$col] = array_shift( $theme_keys );
    3260 
    3261                 foreach ( $table as $row => $cols ) {
    3262                         echo "\t<tr>\n";
    3263                         foreach ( $cols as $col => $theme_index ) {
    3264                                 $class = array( 'available-theme' );
    3265                                 if ( $row == 1 ) $class[] = 'top';
    3266                                 if ( $col == 1 ) $class[] = 'left';
    3267                                 if ( $row == $rows ) $class[] = 'bottom';
    3268                                 if ( $col == 3 ) $class[] = 'right';
    3269                                 ?>
    3270                                 <td class="<?php echo join( ' ', $class ); ?>"><?php
    3271                                         if ( isset( $themes[$theme_index] ) )
    3272                                                 display_theme( $themes[$theme_index] );
    3273                                 ?></td>
    3274                         <?php } // end foreach $cols
    3275                         echo "\t</tr>\n";
    3276                 } // end foreach $table
    3277         }
    3278 }
    3279 
Note: See TracChangeset for help on using the changeset viewer.