Make WordPress Core


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

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

File:
1 copied

Legend:

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

    r15953 r15954  
    11<?php
    2 
    32/**
    43 * List table classes
     
    983982}
    984983
    985 class WP_Media_Table extends WP_List_Table {
    986 
    987         function WP_Media_Table() {
    988                 global $detached;
    989 
    990                 $detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
    991 
    992                 parent::WP_List_Table( array(
    993                         'screen' => $detached ? 'upload-detached' : 'upload',
    994                         'plural' => 'media'
    995                 ) );
    996         }
    997 
    998         function check_permissions() {
    999                 if ( !current_user_can('upload_files') )
    1000                         wp_die( __( 'You do not have permission to upload files.' ) );
    1001         }
    1002 
    1003         function prepare_items() {
    1004                 global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types;
    1005 
    1006                 $q = $_REQUEST;
    1007 
    1008                 if ( !empty( $lost ) )
    1009                         $q['post__in'] = implode( ',', $lost );
    1010 
    1011                 list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q );
    1012 
    1013                 $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
    1014 
    1015                 $this->set_pagination_args( array(
    1016                         'total_items' => $wp_query->found_posts,
    1017                         'total_pages' => $wp_query->max_num_pages,
    1018                         'per_page' => $wp_query->query_vars['posts_per_page'],
    1019                 ) );
    1020         }
    1021 
    1022         function get_views() {
    1023                 global $wpdb, $post_mime_types, $detached, $avail_post_mime_types;
    1024 
    1025                 $type_links = array();
    1026                 $_num_posts = (array) wp_count_attachments();
    1027                 $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
    1028                 if ( !isset( $total_orphans ) )
    1029                                 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
    1030                 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    1031                 foreach ( $matches as $type => $reals )
    1032                         foreach ( $reals as $real )
    1033                                 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
    1034 
    1035                 $class = ( empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ) ? ' class="current"' : '';
    1036                 $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>';
    1037                 foreach ( $post_mime_types as $mime_type => $label ) {
    1038                         $class = '';
    1039 
    1040                         if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
    1041                                 continue;
    1042 
    1043                         if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
    1044                                 $class = ' class="current"';
    1045                         if ( !empty( $num_posts[$mime_type] ) )
    1046                                 $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>';
    1047                 }
    1048                 $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>';
    1049 
    1050                 if ( !empty($_num_posts['trash']) )
    1051                         $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>';
    1052 
    1053                 return $type_links;
    1054         }
    1055 
    1056         function get_bulk_actions() {
    1057                 global $detached;
    1058 
    1059                 $actions = array();
    1060                 $actions['delete'] = __( 'Delete Permanently' );
    1061                 if ( $detached )
    1062                         $actions['attach'] = __( 'Attach to a post' );
    1063 
    1064                 return $actions;
    1065         }
    1066 
    1067         function extra_tablenav( $which ) {
    1068                 global $post_type, $detached;
    1069984?>
    1070                 <div class="alignleft actions">
    1071 <?php
    1072                 if ( 'top' == $which && !is_singular() && !$detached && !$this->is_trash ) {
    1073                         $this->months_dropdown( $post_type );
    1074 
    1075                         do_action( 'restrict_manage_posts' );
    1076 ?>
    1077                         <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" />
    1078 <?php
    1079                 }
    1080 
    1081                 if ( $detached ) { ?>
    1082                         <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e( 'Scan for lost attachments' ); ?>" class="button-secondary" />
    1083                 <?php } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { ?>
    1084                         <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e( 'Empty Trash' ); ?>" class="button-secondary apply" />
    1085                 <?php } ?>
    1086                 </div>
    1087 <?php
    1088         }
    1089 
    1090         function current_action() {
    1091                 if ( isset( $_REQUEST['find_detached'] ) )
    1092                         return 'find_detached';
    1093 
    1094                 if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
    1095                         return 'attach';
    1096 
    1097                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
    1098                         return 'delete_all';
    1099 
    1100                 return parent::current_action();
    1101         }
    1102 
    1103         function has_items() {
    1104                 return have_posts();
    1105         }
    1106 
    1107         function no_items() {
    1108                 _e( 'No media attachments found.' );
    1109         }
    1110 
    1111         function get_columns() {
    1112                 $posts_columns = array();
    1113                 $posts_columns['cb'] = '<input type="checkbox" />';
    1114                 $posts_columns['icon'] = '';
    1115                 /* translators: column name */
    1116                 $posts_columns['title'] = _x( 'File', 'column name' );
    1117                 $posts_columns['author'] = __( 'Author' );
    1118                 //$posts_columns['tags'] = _x( 'Tags', 'column name' );
    1119                 /* translators: column name */
    1120                 if ( 'upload' == $this->_screen->id ) {
    1121                         $posts_columns['parent'] = _x( 'Attached to', 'column name' );
    1122                         $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
    1123                 }
    1124                 /* translators: column name */
    1125                 $posts_columns['date'] = _x( 'Date', 'column name' );
    1126                 $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, 'upload' != $this->_screen->id );
    1127 
    1128                 return $posts_columns;
    1129         }
    1130 
    1131         function get_sortable_columns() {
    1132                 return array(
    1133                         'title'    => 'title',
    1134                         'author'   => 'author',
    1135                         'parent'   => 'parent',
    1136                         'comments' => 'comment_count',
    1137                         'date'     => 'date',
    1138                 );
    1139         }
    1140 
    1141         function display_rows() {
    1142                 global $detached, $post, $id;
    1143 
    1144                 if ( $detached ) {
    1145                         $this->display_orphans();
    1146                         return;
    1147                 }
    1148 
    1149                 add_filter( 'the_title','esc_html' );
    1150                 $alt = '';
    1151 
    1152                 while ( have_posts() ) : the_post();
    1153 
    1154                         if ( $this->is_trash && $post->post_status != 'trash'
    1155                         ||  !$this->is_trash && $post->post_status == 'trash' )
    1156                                 continue;
    1157 
    1158                         $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
    1159                         $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
    1160                         $att_title = _draft_or_post_title();
    1161 ?>
    1162         <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
    1163 <?php
    1164 
    1165 list( $columns, $hidden ) = $this->get_column_info();
    1166 foreach ( $columns as $column_name => $column_display_name ) {
    1167         $class = "class='$column_name column-$column_name'";
    1168 
    1169         $style = '';
    1170         if ( in_array( $column_name, $hidden ) )
    1171                 $style = ' style="display:none;"';
    1172 
    1173         $attributes = $class . $style;
    1174 
    1175         switch ( $column_name ) {
    1176 
    1177         case 'cb':
    1178 ?>
    1179                 <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>
    1180 <?php
    1181                 break;
    1182 
    1183         case 'icon':
    1184                 $attributes = 'class="column-icon media-icon"' . $style;
    1185 ?>
    1186                 <td <?php echo $attributes ?>><?php
    1187                         if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
    1188                                 if ( $this->is_trash ) {
    1189                                         echo $thumb;
    1190                                 } else {
    1191 ?>
    1192                                 <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
    1193                                         <?php echo $thumb; ?>
    1194                                 </a>
    1195 
    1196 <?php                   }
    1197                         }
    1198 ?>
    1199                 </td>
    1200 <?php
    1201                 break;
    1202 
    1203         case 'title':
    1204 ?>
    1205                 <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>
    1206                         <p>
    1207 <?php
    1208                         if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
    1209                                 echo esc_html( strtoupper( $matches[1] ) );
    1210                         else
    1211                                 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
    1212 ?>
    1213                         </p>
    1214 <?php
    1215                 $actions = array();
    1216                 if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
    1217                         $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
    1218                 if ( current_user_can( 'delete_post', $post->ID ) ) {
    1219                         if ( $this->is_trash )
    1220                                 $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-attachment_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
    1221                         elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH )
    1222                                 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
    1223                         if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) {
    1224                                 $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
    1225                                 $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>";
    1226                         }
    1227                 }
    1228                 if ( !$this->is_trash ) {
    1229                         $title =_draft_or_post_title( $post->post_parent );
    1230                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    1231                 }
    1232                 $actions = apply_filters( 'media_row_actions', $actions, $post );
    1233                 echo $this->row_actions( $actions );
    1234 ?>
    1235                 </td>
    1236 <?php
    1237                 break;
    1238 
    1239         case 'author':
    1240 ?>
    1241                 <td <?php echo $attributes ?>><?php the_author() ?></td>
    1242 <?php
    1243                 break;
    1244 
    1245         case 'tags':
    1246 ?>
    1247                 <td <?php echo $attributes ?>><?php
    1248                 $tags = get_the_tags();
    1249                 if ( !empty( $tags ) ) {
    1250                         $out = array();
    1251                         foreach ( $tags as $c )
    1252                                 $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
    1253                         echo join( ', ', $out );
    1254                 } else {
    1255                         _e( 'No Tags' );
    1256                 }
    1257 ?>
    1258                 </td>
    1259 <?php
    1260                 break;
    1261 
    1262         case 'desc':
    1263 ?>
    1264                 <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
    1265 <?php
    1266                 break;
    1267 
    1268         case 'date':
    1269                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    1270                         $t_time = $h_time = __( 'Unpublished' );
    1271                 } else {
    1272                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
    1273                         $m_time = $post->post_date;
    1274                         $time = get_post_time( 'G', true, $post, false );
    1275                         if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) {
    1276                                 if ( $t_diff < 0 )
    1277                                         $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
    1278                                 else
    1279                                         $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
    1280                         } else {
    1281                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    1282                         }
    1283                 }
    1284 ?>
    1285                 <td <?php echo $attributes ?>><?php echo $h_time ?></td>
    1286 <?php
    1287                 break;
    1288 
    1289         case 'parent':
    1290                 if ( $post->post_parent > 0 ) {
    1291                         if ( get_post( $post->post_parent ) ) {
    1292                                 $title =_draft_or_post_title( $post->post_parent );
    1293                         }
    1294 ?>
    1295                         <td <?php echo $attributes ?>>
    1296                                 <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>,
    1297                                 <?php echo get_the_time( __( 'Y/m/d' ) ); ?>
    1298                         </td>
    1299 <?php
    1300                 } else {
    1301 ?>
    1302                         <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br />
    1303                         <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' );return false;" href="#the-list"><?php _e( 'Attach' ); ?></a></td>
    1304 <?php
    1305                 }
    1306                 break;
    1307 
    1308         case 'comments':
    1309                 $attributes = 'class="comments column-comments num"' . $style;
    1310 ?>
    1311                 <td <?php echo $attributes ?>>
    1312                         <div class="post-com-count-wrapper">
    1313 <?php
    1314                 $pending_comments = get_pending_comments_num( $post->ID );
    1315 
    1316                 $this->comments_bubble( $post->ID, $pending_comments );
    1317 ?>
    1318                         </div>
    1319                 </td>
    1320 <?php
    1321                 break;
    1322 
    1323         case 'actions':
    1324 ?>
    1325                 <td <?php echo $attributes ?>>
    1326                         <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> |
    1327                         <a href="<?php the_permalink(); ?>"><?php _e( 'Get permalink' ); ?></a>
    1328                 </td>
    1329                 <?php
    1330                 break;
    1331 
    1332         default:
    1333 ?>
    1334                 <td <?php echo $attributes ?>>
    1335                         <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
    1336                 </td>
    1337 <?php
    1338                 break;
    1339         }
    1340 }
    1341 ?>
    1342         </tr>
    1343 <?php endwhile;
    1344         }
    1345 
    1346         function display_orphans() {
    1347                 global $post;
    1348 
    1349                 $class = '';
    1350 
    1351                 while ( have_posts() ) : the_post();
    1352 
    1353                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    1354                         $att_title = esc_html( _draft_or_post_title( $post->ID ) );
    1355 
    1356                         $edit_link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ) . '">%s</a>';
    1357 ?>
    1358         <tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top">
    1359                 <th scope="row" class="check-column">
    1360                 <?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?>
    1361                         <input type="checkbox" name="media[]" value="<?php echo esc_attr( $post->ID ); ?>" />
    1362                 <?php } ?>
    1363                 </th>
    1364 
    1365                 <td class="media-icon">
    1366                 <?php if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
    1367                         printf( $edit_link, $thumb );
    1368                 } ?>
    1369                 </td>
    1370 
    1371                 <td class="media column-media">
    1372                         <strong><?php printf( $edit_link, $att_title ); ?></strong><br />
    1373 <?php
    1374                         if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
    1375                                 echo esc_html( strtoupper( $matches[1] ) );
    1376                         else
    1377                                 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
    1378 ?>
    1379 <?php
    1380                         $actions = array();
    1381                         if ( current_user_can( 'edit_post', $post->ID ) )
    1382                                 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
    1383                         if ( current_user_can( 'delete_post', $post->ID ) )
    1384                                 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
    1385                                         $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
    1386                                 } else {
    1387                                         $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
    1388                                         $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>";
    1389                                 }
    1390                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    1391                         if ( current_user_can( 'edit_post', $post->ID ) )
    1392                                 $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>';
    1393                         $actions = apply_filters( 'media_row_actions', $actions, $post );
    1394 
    1395                         echo $this->row_actions( $actions );
    1396 ?>
    1397                 </td>
    1398                 <td class="author column-author">
    1399                         <?php $author = get_userdata( $post->post_author ); echo $author->display_name; ?>
    1400                 </td>
    1401 <?php
    1402                 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    1403                         $t_time = $h_time = __( 'Unpublished' );
    1404                 } else {
    1405                         $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
    1406                         $m_time = $post->post_date;
    1407                         $time = get_post_time( 'G', true );
    1408                         if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) {
    1409                                 if ( $t_diff < 0 )
    1410                                         $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
    1411                                 else
    1412                                         $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
    1413                         } else {
    1414                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    1415                         }
    1416                 }
    1417 ?>
    1418                 <td class="date column-date"><?php echo $h_time ?></td>
    1419         </tr>
    1420 <?php
    1421                 endwhile;
    1422         }
    1423 }
    1424 
    1425 class WP_Terms_Table extends WP_List_Table {
    1426 
    1427         var $callback_args;
    1428 
    1429         function WP_Terms_Table() {
    1430                 global $post_type, $taxonomy, $tax, $current_screen;
    1431 
    1432                 wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) );
    1433 
    1434                 if ( empty( $taxonomy ) )
    1435                         $taxonomy = 'post_tag';
    1436 
    1437                 if ( !taxonomy_exists( $taxonomy ) )
    1438                         wp_die( __( 'Invalid taxonomy' ) );
    1439 
    1440                 $tax = get_taxonomy( $taxonomy );
    1441 
    1442                 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) )
    1443                         $post_type = 'post';
    1444 
    1445                 if ( !isset( $current_screen ) )
    1446                         set_current_screen( 'edit-' . $taxonomy );
    1447 
    1448                 parent::WP_List_Table( array(
    1449                         'screen' => $current_screen,
    1450                         'plural' => 'tags',
    1451                         'singular' => 'tag',
    1452                 ) );
    1453         }
    1454 
    1455         function check_permissions( $type = 'manage' ) {
    1456                 global $tax;
    1457 
    1458                 $cap = 'manage' == $type ? $tax->cap->manage_terms : $tax->cap->edit_terms;
    1459 
    1460                 if ( !current_user_can( $tax->cap->manage_terms ) )
    1461                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    1462         }
    1463 
    1464         function prepare_items() {
    1465                 global $taxonomy;
    1466 
    1467                 $tags_per_page = $this->get_items_per_page( 'edit_' .  $taxonomy . '_per_page' );
    1468 
    1469                 if ( 'post_tag' == $taxonomy ) {
    1470                         $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
    1471                         $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
    1472                 } elseif ( 'category' == $taxonomy ) {
    1473                         $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
    1474                 }
    1475 
    1476                 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
    1477 
    1478                 $args = array(
    1479                         'search' => $search,
    1480                         'page' => $this->get_pagenum(),
    1481                         'number' => $tags_per_page,
    1482                 );
    1483 
    1484                 if ( !empty( $_REQUEST['orderby'] ) )
    1485                         $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
    1486 
    1487                 if ( !empty( $_REQUEST['order'] ) )
    1488                         $args['order'] = trim( stripslashes( $_REQUEST['order'] ) );
    1489 
    1490                 $this->callback_args = $args;
    1491 
    1492                 $this->set_pagination_args( array(
    1493                         'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ),
    1494                         'per_page' => $tags_per_page,
    1495                 ) );
    1496         }
    1497 
    1498         function get_bulk_actions() {
    1499                 $actions = array();
    1500                 $actions['delete'] = __( 'Delete' );
    1501 
    1502                 return $actions;
    1503         }
    1504 
    1505         function current_action() {
    1506                 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
    1507                         return 'bulk-delete';
    1508 
    1509                 return parent::current_action();
    1510         }
    1511 
    1512         function get_columns() {
    1513                 global $taxonomy;
    1514 
    1515                 $columns = array(
    1516                         'cb'          => '<input type="checkbox" />',
    1517                         'name'        => __( 'Name' ),
    1518                         'description' => __( 'Description' ),
    1519                         'slug'        => __( 'Slug' ),
    1520                 );
    1521 
    1522                 if ( 'link_category' == $taxonomy )
    1523                         $columns['links'] = __( 'Links' );
    1524                 else
    1525                         $columns['posts'] = __( 'Posts' );
    1526 
    1527                 return $columns;
    1528         }
    1529 
    1530         function get_sortable_columns() {
    1531                 return array(
    1532                         'name'        => 'name',
    1533                         'description' => 'description',
    1534                         'slug'        => 'slug',
    1535                         'posts'       => 'count',
    1536                         'links'       => 'count'
    1537                 );
    1538         }
    1539 
    1540         function display_rows() {
    1541                 global $taxonomy;
    1542 
    1543                 $args = wp_parse_args( $this->callback_args, array(
    1544                         'page' => 1,
    1545                         'number' => 20,
    1546                         'search' => '',
    1547                         'hide_empty' => 0
    1548                 ) );
    1549 
    1550                 extract( $args, EXTR_SKIP );
    1551 
    1552                 $args['offset'] = $offset = ( $page - 1 ) * $number;
    1553 
    1554                 // convert it to table rows
    1555                 $out = '';
    1556                 $count = 0;
    1557                 if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) {
    1558                         // We'll need the full set of terms then.
    1559                         $args['number'] = $args['offset'] = 0;
    1560 
    1561                         $terms = get_terms( $taxonomy, $args );
    1562                         if ( !empty( $search ) ) // Ignore children on searches.
    1563                                 $children = array();
    1564                         else
    1565                                 $children = _get_term_hierarchy( $taxonomy );
    1566 
    1567                         // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
    1568                         $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
    1569                 } else {
    1570                         $terms = get_terms( $taxonomy, $args );
    1571                         foreach ( $terms as $term )
    1572                                 $out .= $this->single_row( $term, 0, $taxonomy );
    1573                         $count = $number; // Only displaying a single page.
    1574                 }
    1575 
    1576                 echo $out;
    1577         }
    1578 
    1579         function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
    1580 
    1581                 $end = $start + $per_page;
    1582 
    1583                 $output = '';
    1584                 foreach ( $terms as $key => $term ) {
    1585 
    1586                         if ( $count >= $end )
    1587                                 break;
    1588 
    1589                         if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
    1590                                 continue;
    1591 
    1592                         // If the page starts in a subtree, print the parents.
    1593                         if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
    1594                                 $my_parents = $parent_ids = array();
    1595                                 $p = $term->parent;
    1596                                 while ( $p ) {
    1597                                         $my_parent = get_term( $p, $taxonomy );
    1598                                         $my_parents[] = $my_parent;
    1599                                         $p = $my_parent->parent;
    1600                                         if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
    1601                                                 break;
    1602                                         $parent_ids[] = $p;
    1603                                 }
    1604                                 unset( $parent_ids );
    1605 
    1606                                 $num_parents = count( $my_parents );
    1607                                 while ( $my_parent = array_pop( $my_parents ) ) {
    1608                                         $output .=  "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy );
    1609                                         $num_parents--;
    1610                                 }
    1611                         }
    1612 
    1613                         if ( $count >= $start )
    1614                                 $output .= "\t" . $this->single_row( $term, $level, $taxonomy );
    1615 
    1616                         ++$count;
    1617 
    1618                         unset( $terms[$key] );
    1619 
    1620                         if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
    1621                                 $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
    1622                 }
    1623 
    1624                 return $output;
    1625         }
    1626 
    1627         function single_row( $tag, $level = 0 ) {
    1628                 static $row_class = '';
    1629                 $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
    1630 
    1631                 $this->level = $level;
    1632 
    1633                 echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
    1634                 echo $this->single_row_columns( $tag );
    1635                 echo '</tr>';
    1636         }
    1637 
    1638         function column_cb( $tag ) {
    1639                 global $taxonomy, $tax;
    1640 
    1641                 $default_term = get_option( 'default_' . $taxonomy );
    1642 
    1643                 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
    1644                         return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />';
    1645                 else
    1646                         return '&nbsp;';
    1647         }
    1648 
    1649         function column_name( $tag ) {
    1650                 global $taxonomy, $tax, $post_type;
    1651 
    1652                 $default_term = get_option( 'default_' . $taxonomy );
    1653 
    1654                 $pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
    1655                 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
    1656                 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
    1657                 $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $post_type );
    1658 
    1659                 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
    1660 
    1661                 $actions = array();
    1662                 if ( current_user_can( $tax->cap->edit_terms ) ) {
    1663                         $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    1664                         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
    1665                 }
    1666                 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
    1667                         $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>";
    1668 
    1669                 $actions = apply_filters( 'tag_row_actions', $actions, $tag );
    1670                 $actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag );
    1671 
    1672                 $out .= $this->row_actions( $actions );
    1673                 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
    1674                 $out .= '<div class="name">' . $qe_data->name . '</div>';
    1675                 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
    1676                 $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
    1677 
    1678                 return $out;
    1679         }
    1680 
    1681         function column_description( $tag ) {
    1682                 return $tag->description;
    1683         }
    1684 
    1685         function column_slug( $tag ) {
    1686                 return apply_filters( 'editable_slug', $tag->slug );
    1687         }
    1688 
    1689         function column_posts( $tag ) {
    1690                 global $taxonomy, $post_type;
    1691 
    1692                 $count = number_format_i18n( $tag->count );
    1693 
    1694                 if ( 'post_tag' == $taxonomy ) {
    1695                         $tagsel = 'tag';
    1696                 } elseif ( 'category' == $taxonomy ) {
    1697                         $tagsel = 'category_name';
    1698                 } elseif ( ! empty( $tax->query_var ) ) {
    1699                         $tagsel = $tax->query_var;
    1700                 } else {
    1701                         $tagsel = $taxonomy;
    1702                 }
    1703 
    1704                 return "<a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a>";
    1705         }
    1706 
    1707         function column_links( $tag ) {
    1708                 $count = number_format_i18n( $tag->count );
    1709                 return $count;
    1710         }
    1711 
    1712         function column_default( $tag, $column_name ) {
    1713                 global $taxonomy;
    1714 
    1715                 return apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id );
    1716                 $out .= "</td>";
    1717         }
    1718 
    1719         /**
    1720          * Outputs the hidden row displayed when inline editing
    1721          *
    1722          * @since 3.1.0
    1723          */
    1724         function inline_edit() {
    1725                 global $tax;
    1726 
    1727                 if ( ! current_user_can( $tax->cap->edit_terms ) )
    1728                         return;
    1729 
    1730                 list( $columns, $hidden ) = $this->get_column_info();
    1731 
    1732                 $col_count = count( $columns ) - count( $hidden );
    1733                 ?>
    1734 
    1735         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
    1736                 <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>">
    1737 
    1738                         <fieldset><div class="inline-edit-col">
    1739                                 <h4><?php _e( 'Quick Edit' ); ?></h4>
    1740 
    1741                                 <label>
    1742                                         <span class="title"><?php _e( 'Name' ); ?></span>
    1743                                         <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
    1744                                 </label>
    1745         <?php if ( !global_terms_enabled() ) { ?>
    1746                                 <label>
    1747                                         <span class="title"><?php _e( 'Slug' ); ?></span>
    1748                                         <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
    1749                                 </label>
    1750         <?php } ?>
    1751 
    1752                         </div></fieldset>
    1753         <?php
    1754 
    1755                 $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
    1756 
    1757                 foreach ( $columns as $column_name => $column_display_name ) {
    1758                         if ( isset( $core_columns[$column_name] ) )
    1759                                 continue;
    1760                         do_action( 'quick_edit_custom_box', $column_name, $type, $tax->taxonomy );
    1761                 }
    1762 
    1763         ?>
    1764 
    1765                 <p class="inline-edit-save submit">
    1766                         <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
    1767                         <?php $update_text = $tax->labels->update_item; ?>
    1768                         <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
    1769                         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
    1770                         <span class="error" style="display:none;"></span>
    1771                         <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
    1772                         <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
    1773                         <br class="clear" />
    1774                 </p>
    1775                 </td></tr>
    1776                 </tbody></table></form>
    1777         <?php
    1778         }
    1779 }
    1780 
    1781 class WP_Users_Table extends WP_List_Table {
    1782 
    1783         function WP_Users_Table() {
    1784                 parent::WP_List_Table( array(
    1785                         'screen' => 'users',
    1786                         'plural' => 'users'
    1787                 ) );
    1788         }
    1789 
    1790         function check_permissions() {
    1791                 if ( !current_user_can('list_users') )
    1792                         wp_die(__('Cheatin&#8217; uh?'));
    1793         }
    1794 
    1795         function prepare_items() {
    1796                 global $role, $usersearch;
    1797 
    1798                 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    1799 
    1800                 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    1801 
    1802                 $users_per_page = $this->get_items_per_page( 'users_per_page' );
    1803 
    1804                 $paged = $this->get_pagenum();
    1805 
    1806                 $args = array(
    1807                         'number' => $users_per_page,
    1808                         'offset' => ( $paged-1 ) * $users_per_page,
    1809                         'role' => $role,
    1810                         'search' => $usersearch
    1811                 );
    1812 
    1813                 if ( isset( $_REQUEST['orderby'] ) )
    1814                         $args['orderby'] = $_REQUEST['orderby'];
    1815 
    1816                 if ( isset( $_REQUEST['order'] ) )
    1817                         $args['order'] = $_REQUEST['order'];
    1818 
    1819                 // Query the user IDs for this page
    1820                 $wp_user_search = new WP_User_Query( $args );
    1821 
    1822                 $this->items = $wp_user_search->get_results();
    1823 
    1824                 $this->set_pagination_args( array(
    1825                         'total_items' => $wp_user_search->get_total(),
    1826                         'per_page' => $users_per_page,
    1827                 ) );
    1828         }
    1829 
    1830         function no_items() {
    1831                 _e( 'No matching users were found.' );
    1832         }
    1833 
    1834         function get_views() {
    1835                 global $wp_roles, $role;
    1836 
    1837                 $users_of_blog = count_users();
    1838                 $total_users = $users_of_blog['total_users'];
    1839                 $avail_roles =& $users_of_blog['avail_roles'];
    1840                 unset($users_of_blog);
    1841 
    1842                 $current_role = false;
    1843                 $class = empty($role) ? ' class="current"' : '';
    1844                 $role_links = array();
    1845                 $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>';
    1846                 foreach ( $wp_roles->get_names() as $this_role => $name ) {
    1847                         if ( !isset($avail_roles[$this_role]) )
    1848                                 continue;
    1849 
    1850                         $class = '';
    1851 
    1852                         if ( $this_role == $role ) {
    1853                                 $current_role = $role;
    1854                                 $class = ' class="current"';
    1855                         }
    1856 
    1857                         $name = translate_user_role( $name );
    1858                         /* translators: User role name with count */
    1859                         $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] );
    1860                         $role_links[$this_role] = "<li><a href='users.php?role=$this_role'$class>$name</a>";
    1861                 }
    1862 
    1863                 return $role_links;
    1864         }
    1865 
    1866         function get_bulk_actions() {
    1867                 $actions = array();
    1868 
    1869                 if ( !is_multisite() && current_user_can( 'delete_users' ) )
    1870                         $actions['delete'] = __( 'Delete' );
    1871                 else
    1872                         $actions['remove'] = __( 'Remove' );
    1873 
    1874                 return $actions;
    1875         }
    1876 
    1877         function extra_tablenav( $which ) {
    1878                 if ( 'top' != $which )
    1879                         return;
    1880 ?>
    1881         <div class="alignleft actions">
    1882                 <label class="screen-reader-text" for="new_role"><?php _e( 'Change role to&hellip;' ) ?></label>
    1883                 <select name="new_role" id="new_role">
    1884                         <option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
    1885                         <?php wp_dropdown_roles(); ?>
    1886                 </select>
    1887                 <input type="submit" value="<?php esc_attr_e( 'Change' ); ?>" name="changeit" class="button-secondary" />
    1888         </div>
    1889 <?php
    1890         }
    1891 
    1892         function current_action() {
    1893                 if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
    1894                         return 'promote';
    1895 
    1896                 return parent::current_action();
    1897         }
    1898 
    1899         function get_columns() {
    1900                 return array(
    1901                         'cb'       => '<input type="checkbox" />',
    1902                         'username' => __( 'Login' ),
    1903                         'name'     => __( 'Name' ),
    1904                         'email'    => __( 'E-mail' ),
    1905                         'role'     => __( 'Role' ),
    1906                         'posts'    => __( 'Posts' )
    1907                 );
    1908         }
    1909 
    1910         function get_sortable_columns() {
    1911                 return array(
    1912                         'username' => 'login',
    1913                         'name'     => 'name',
    1914                         'email'    => 'email',
    1915                         'posts'    => 'post_count',
    1916                 );
    1917         }
    1918 
    1919         function display_rows() {
    1920                 // Query the post counts for this page
    1921                 $post_counts = count_many_users_posts( array_keys( $this->items ) );
    1922 
    1923                 $style = '';
    1924                 foreach ( $this->items as $userid => $user_object ) {
    1925                         $role = reset( $user_object->roles );
    1926 
    1927                         if ( is_multisite() && empty( $role ) )
    1928                                 continue;
    1929 
    1930                         $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
    1931                         echo "\n\t", $this->single_row( $user_object, $style, $role, $post_counts[ $userid ] );
    1932                 }
    1933         }
    1934 
    1935         /**
    1936          * Generate HTML for a single row on the users.php admin panel.
    1937          *
    1938          * @since 2.1.0
    1939          *
    1940          * @param object $user_object
    1941          * @param string $style Optional. Attributes added to the TR element.  Must be sanitized.
    1942          * @param string $role Key for the $wp_roles array.
    1943          * @param int $numposts Optional. Post count to display for this user.  Defaults to zero, as in, a new user has made zero posts.
    1944          * @return string
    1945          */
    1946         function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
    1947                 global $wp_roles;
    1948 
    1949                 if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
    1950                         $user_object = new WP_User( (int) $user_object );
    1951                 $user_object = sanitize_user_object( $user_object, 'display' );
    1952                 $email = $user_object->user_email;
    1953                 $url = $user_object->user_url;
    1954                 $short_url = str_replace( 'http://', '', $url );
    1955                 $short_url = str_replace( 'www.', '', $short_url );
    1956                 if ( '/' == substr( $short_url, -1 ) )
    1957                         $short_url = substr( $short_url, 0, -1 );
    1958                 if ( strlen( $short_url ) > 35 )
    1959                         $short_url = substr( $short_url, 0, 32 ).'...';
    1960                 $checkbox = '';
    1961                 // Check if the user for this row is editable
    1962                 if ( current_user_can( 'list_users' ) ) {
    1963                         // Set up the user editing link
    1964                         // TODO: make profile/user-edit determination a separate function
    1965                         if ( get_current_user_id() == $user_object->ID ) {
    1966                                 $edit_link = 'profile.php';
    1967                         } else {
    1968                                 $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" ) );
    1969                         }
    1970                         $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
    1971 
    1972                         // Set up the hover actions for this user
    1973                         $actions = array();
    1974 
    1975                         if ( current_user_can( 'edit_user',  $user_object->ID ) ) {
    1976                                 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
    1977                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    1978                         } else {
    1979                                 $edit = "<strong>$user_object->user_login</strong><br />";
    1980                         }
    1981 
    1982                         if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
    1983                                 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
    1984                         if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
    1985                                 $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
    1986                         $actions = apply_filters( 'user_row_actions', $actions, $user_object );
    1987                         $edit .= $this->row_actions( $actions );
    1988 
    1989                         // Set up the checkbox ( because the user is editable, otherwise its empty )
    1990                         $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
    1991 
    1992                 } else {
    1993                         $edit = '<strong>' . $user_object->user_login . '</strong>';
    1994                 }
    1995                 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' );
    1996                 $r = "<tr id='user-$user_object->ID'$style>";
    1997                 $avatar = get_avatar( $user_object->ID, 32 );
    1998 
    1999                 list( $columns, $hidden ) = $this->get_column_info();
    2000 
    2001                 foreach ( $columns as $column_name => $column_display_name ) {
    2002                         $class = "class=\"$column_name column-$column_name\"";
    2003 
    2004                         $style = '';
    2005                         if ( in_array( $column_name, $hidden ) )
    2006                                 $style = ' style="display:none;"';
    2007 
    2008                         $attributes = "$class$style";
    2009 
    2010                         switch ( $column_name ) {
    2011                                 case 'cb':
    2012                                         $r .= "<th scope='row' class='check-column'>$checkbox</th>";
    2013                                         break;
    2014                                 case 'username':
    2015                                         $r .= "<td $attributes>$avatar $edit</td>";
    2016                                         break;
    2017                                 case 'name':
    2018                                         $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
    2019                                         break;
    2020                                 case 'email':
    2021                                         $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __( 'E-mail: %s' ), $email ) . "'>$email</a></td>";
    2022                                         break;
    2023                                 case 'role':
    2024                                         $r .= "<td $attributes>$role_name</td>";
    2025                                         break;
    2026                                 case 'posts':
    2027                                         $attributes = 'class="posts column-posts num"' . $style;
    2028                                         $r .= "<td $attributes>";
    2029                                         if ( $numposts > 0 ) {
    2030                                                 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
    2031                                                 $r .= $numposts;
    2032                                                 $r .= '</a>';
    2033                                         } else {
    2034                                                 $r .= 0;
    2035                                         }
    2036                                         $r .= "</td>";
    2037                                         break;
    2038                                 default:
    2039                                         $r .= "<td $attributes>";
    2040                                         $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
    2041                                         $r .= "</td>";
    2042                         }
    2043                 }
    2044                 $r .= '</tr>';
    2045 
    2046                 return $r;
    2047         }
    2048 }
    2049 
    2050 class WP_Comments_Table extends WP_List_Table {
    2051 
    2052         var $checkbox = true;
    2053         var $from_ajax = false;
    2054 
    2055         var $pending_count = array();
    2056 
    2057         function WP_Comments_Table() {
    2058                 global $mode;
    2059 
    2060                 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'detail' : $_REQUEST['mode'];
    2061 
    2062                 if ( get_option('show_avatars') && 'single' != $mode )
    2063                         add_filter( 'comment_author', 'floated_admin_avatar' );
    2064 
    2065                 parent::WP_List_Table( array(
    2066                         'screen' => 'edit-comments',
    2067                         'plural' => 'comments'
    2068                 ) );
    2069         }
    2070 
    2071         function check_permissions() {
    2072                 if ( !current_user_can('edit_posts') )
    2073                         wp_die(__('Cheatin&#8217; uh?'));
    2074         }
    2075 
    2076         function prepare_items() {
    2077                 global $post_id, $comment_status, $search;
    2078 
    2079                 if ( isset( $_REQUEST['p'] ) )
    2080                         $post_id = absint( $_REQUEST['p'] );
    2081                 elseif ( isset( $_REQUEST['post'] ) )
    2082                         $post_id = absint( $_REQUEST['post'] );
    2083                 elseif ( isset( $_REQUEST['post_ID'] ) )
    2084                         $post_id = absint( $_REQUEST['post_ID'] );
    2085                 else
    2086                         $post_id = 0;
    2087 
    2088                 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
    2089                 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
    2090                         $comment_status = 'all';
    2091 
    2092                 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
    2093 
    2094                 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
    2095 
    2096                 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
    2097 
    2098                 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
    2099                 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
    2100 
    2101                 if ( isset( $_POST['number'] ) )
    2102                         $number = (int) $_POST['number'];
    2103                 else
    2104                         $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
    2105 
    2106                 $page = $this->get_pagenum();
    2107 
    2108                 $start = $offset = ( $page - 1 ) * $comments_per_page;
    2109 
    2110                 $status_map = array(
    2111                         'moderated' => 'hold',
    2112                         'approved' => 'approve'
    2113                 );
    2114 
    2115                 $args = array(
    2116                         'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
    2117                         'search' => $search,
    2118                         'user_id' => $user_id,
    2119                         'offset' => $start,
    2120                         'number' => $number,
    2121                         'post_id' => $post_id,
    2122                         'type' => $comment_type,
    2123                         'orderby' => @$_REQUEST['orderby'],
    2124                         'order' => @$_REQUEST['order'],
    2125                 );
    2126 
    2127                 $_comments = get_comments( $args );
    2128 
    2129                 update_comment_cache( $_comments );
    2130 
    2131                 $this->items = array_slice( $_comments, 0, $comments_per_page );
    2132                 $this->extra_items = array_slice( $_comments, $comments_per_page );
    2133 
    2134                 $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
    2135 
    2136                 $_comment_post_ids = array();
    2137                 foreach ( $_comments as $_c ) {
    2138                         $_comment_post_ids[] = $_c->comment_post_ID;
    2139                 }
    2140 
    2141                 $this->pending_count = get_pending_comments_num( $_comment_post_ids );
    2142 
    2143                 $this->set_pagination_args( array(
    2144                         'total_items' => $total_comments,
    2145                         'per_page' => $comments_per_page,
    2146                 ) );
    2147         }
    2148 
    2149         function get_views() {
    2150                 global $post_id, $comment_status;
    2151 
    2152                 $status_links = array();
    2153                 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
    2154                 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
    2155                 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
    2156                 $stati = array(
    2157                                 'all' => _nx_noop('All', 'All', 'comments'), // singular not used
    2158                                 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
    2159                                 'approved' => _n_noop('Approved', 'Approved'), // singular not used
    2160                                 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
    2161                                 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
    2162                         );
    2163 
    2164                 if ( !EMPTY_TRASH_DAYS )
    2165                         unset($stati['trash']);
    2166 
    2167                 $link = 'edit-comments.php';
    2168                 if ( !empty($comment_type) && 'all' != $comment_type )
    2169                         $link = add_query_arg( 'comment_type', $comment_type, $link );
    2170 
    2171                 foreach ( $stati as $status => $label ) {
    2172                         $class = ( $status == $comment_status ) ? ' class="current"' : '';
    2173 
    2174                         if ( !isset( $num_comments->$status ) )
    2175                                 $num_comments->$status = 10;
    2176                         $link = add_query_arg( 'comment_status', $status, $link );
    2177                         if ( $post_id )
    2178                                 $link = add_query_arg( 'p', absint( $post_id ), $link );
    2179                         /*
    2180                         // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
    2181                         if ( !empty( $_REQUEST['s'] ) )
    2182                                 $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
    2183                         */
    2184                         $status_links[$status] = "<li class='$status'><a href='$link'$class>" . sprintf(
    2185                                 _n( $label[0], $label[1], $num_comments->$status ),
    2186                                 number_format_i18n( $num_comments->$status )
    2187                         ) . '</a>';
    2188                 }
    2189 
    2190                 $status_links = apply_filters( 'comment_status_links', $status_links );
    2191                 return $status_links;
    2192         }
    2193 
    2194         function get_bulk_actions() {
    2195                 global $comment_status;
    2196 
    2197                 $actions = array();
    2198                 if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
    2199                         $actions['unapprove'] = __( 'Unapprove' );
    2200                 if ( in_array( $comment_status, array( 'all', 'moderated', 'spam' ) ) )
    2201                         $actions['approve'] = __( 'Approve' );
    2202                 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved' ) ) )
    2203                         $actions['spam'] = _x( 'Mark as Spam', 'comment' );
    2204 
    2205                 if ( 'trash' == $comment_status )
    2206                         $actions['untrash'] = __( 'Restore' );
    2207                 elseif ( 'spam' == $comment_status )
    2208                         $actions['unspam'] = _x( 'Not Spam', 'comment' );
    2209 
    2210                 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
    2211                         $actions['delete'] = __( 'Delete Permanently' );
    2212                 else
    2213                         $actions['trash'] = __( 'Move to Trash' );
    2214 
    2215                 return $actions;
    2216         }
    2217 
    2218         function extra_tablenav( $which ) {
    2219                 global $comment_status, $comment_type;
    2220 ?>
    2221                 <div class="alignleft actions">
    2222 <?php
    2223                 if ( 'top' == $which ) {
    2224 ?>
    2225                         <select name="comment_type">
    2226                                 <option value=""><?php _e( 'Show all comment types' ); ?></option>
    2227 <?php
    2228                                 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
    2229                                         'comment' => __( 'Comments' ),
    2230                                         'pings' => __( 'Pings' ),
    2231                                 ) );
    2232 
    2233                                 foreach ( $comment_types as $type => $label )
    2234                                         echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n";
    2235                         ?>
    2236                         </select>
    2237                         <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" />
    2238 <?php
    2239                 }
    2240 
    2241                 if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) {
    2242                         wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
    2243                         $title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
    2244 ?>
    2245                         <input type="submit" name="delete_all" id="delete_all" value="<?php echo $title ?>" class="button-secondary apply" />
    2246 <?php
    2247                 }
    2248 ?>
    2249 <?php
    2250                 do_action( 'manage_comments_nav', $comment_status );
    2251                 echo '</div>';
    2252         }
    2253 
    2254         function current_action() {
    2255                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
    2256                         return 'delete_all';
    2257 
    2258                 return parent::current_action();
    2259         }
    2260 
    2261         function get_columns() {
    2262                 global $mode;
    2263 
    2264                 $columns = array();
    2265 
    2266                 if ( $this->checkbox )
    2267                         $columns['cb'] = '<input type="checkbox" />';
    2268 
    2269                 $columns['author'] = __( 'Author' );
    2270                 $columns['comment'] = _x( 'Comment', 'column name' );
    2271 
    2272                 if ( 'single' !== $mode )
    2273                         $columns['response'] = _x( 'Comment', 'column name' );
    2274 
    2275                 return $columns;
    2276         }
    2277 
    2278         function get_sortable_columns() {
    2279                 return array(
    2280                         'author'   => 'comment_author',
    2281                         'comment'  => 'comment_content',
    2282                         'response' => 'comment_post_ID'
    2283                 );
    2284         }
    2285 
    2286         function display_table() {
    2287                 extract( $this->_args );
    2288 
    2289                 $this->display_tablenav( 'top' );
    2290 
    2291 ?>
    2292 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
    2293         <thead>
    2294         <tr>
    2295                 <?php $this->print_column_headers(); ?>
    2296         </tr>
    2297         </thead>
    2298 
    2299         <tfoot>
    2300         <tr>
    2301                 <?php $this->print_column_headers( false ); ?>
    2302         </tr>
    2303         </tfoot>
    2304 
    2305         <tbody id="the-comment-list" class="list:comment">
    2306                 <?php $this->display_rows(); ?>
    2307         </tbody>
    2308 
    2309         <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
    2310                 <?php $this->items = $this->extra_items; $this->display_rows(); ?>
    2311         </tbody>
    2312 </table>
    2313 <?php
    2314 
    2315                 $this->display_tablenav( 'bottom' );
    2316         }
    2317 
    2318         function single_row( $a_comment ) {
    2319                 global $post, $comment, $the_comment_status;
    2320 
    2321                 $comment = $a_comment;
    2322                 $the_comment_status = wp_get_comment_status( $comment->comment_ID );
    2323 
    2324                 $post = get_post( $comment->comment_post_ID );
    2325 
    2326                 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    2327 
    2328                 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
    2329                 echo $this->single_row_columns( $comment );
    2330                 echo "</tr>\n";
    2331         }
    2332 
    2333         function column_cb( $comment ) {
    2334                 if ( $this->user_can )
    2335                         echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
    2336         }
    2337 
    2338         function column_comment( $comment ) {
    2339                 global $post, $comment_status, $the_comment_status;
    2340 
    2341                 $user_can = $this->user_can;
    2342 
    2343                 $comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
    2344 
    2345                 $ptime = date( 'G', strtotime( $comment->comment_date ) );
    2346                 if ( ( abs( time() - $ptime ) ) < 86400 )
    2347                         $ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) );
    2348                 else
    2349                         $ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date );
    2350 
    2351                 if ( $user_can ) {
    2352                         $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
    2353                         $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
    2354 
    2355                         $url = "comment.php?c=$comment->comment_ID";
    2356 
    2357                         $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
    2358                         $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
    2359                         $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
    2360                         $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
    2361                         $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
    2362                         $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
    2363                         $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
    2364                 }
    2365 
    2366                 echo '<div id="submitted-on">';
    2367                 /* translators: 2: comment date, 3: comment time */
    2368                 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
    2369                         /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ),
    2370                         /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) );
    2371 
    2372                 if ( $comment->comment_parent ) {
    2373                         $parent = get_comment( $comment->comment_parent );
    2374                         $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
    2375                         $name = get_comment_author( $parent->comment_ID );
    2376                         printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
    2377                 }
    2378 
    2379                 echo '</div>';
    2380                 comment_text();
    2381                 if ( $user_can ) { ?>
    2382                 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
    2383                 <textarea class="comment" rows="1" cols="1"><?php echo esc_html( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); ?></textarea>
    2384                 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
    2385                 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
    2386                 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
    2387                 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
    2388                 </div>
    2389                 <?php
    2390                 }
    2391 
    2392                 if ( $user_can ) {
    2393                         // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
    2394                         $actions = array(
    2395                                 'approve' => '', 'unapprove' => '',
    2396                                 'reply' => '',
    2397                                 'quickedit' => '',
    2398                                 'edit' => '',
    2399                                 'spam' => '', 'unspam' => '',
    2400                                 'trash' => '', 'untrash' => '', 'delete' => ''
    2401                         );
    2402 
    2403                         if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
    2404                                 if ( 'approved' == $the_comment_status )
    2405                                         $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
    2406                                 else if ( 'unapproved' == $the_comment_status )
    2407                                         $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    2408                         } else {
    2409                                 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    2410                                 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
    2411                         }
    2412 
    2413                         if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
    2414                                 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
    2415                         } elseif ( 'spam' == $the_comment_status ) {
    2416                                 $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
    2417                         } elseif ( 'trash' == $the_comment_status ) {
    2418                                 $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
    2419                         }
    2420 
    2421                         if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
    2422                                 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
    2423                         } else {
    2424                                 $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
    2425                         }
    2426 
    2427                         if ( 'trash' != $the_comment_status ) {
    2428                                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
    2429                                 $actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
    2430                                 if ( 'spam' != $the_comment_status )
    2431                                         $actions['reply'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>';
    2432                         }
    2433 
    2434                         $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
    2435 
    2436                         $i = 0;
    2437                         echo '<div class="row-actions">';
    2438                         foreach ( $actions as $action => $link ) {
    2439                                 ++$i;
    2440                                 ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
    2441 
    2442                                 // Reply and quickedit need a hide-if-no-js span when not added with ajax
    2443                                 if ( ( 'reply' == $action || 'quickedit' == $action ) && ! $this->from_ajax )
    2444                                         $action .= ' hide-if-no-js';
    2445                                 elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
    2446                                         if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
    2447                                                 $action .= ' approve';
    2448                                         else
    2449                                                 $action .= ' unapprove';
    2450                                 }
    2451 
    2452                                 echo "<span class='$action'>$sep$link</span>";
    2453                         }
    2454                         echo '</div>';
    2455                 }
    2456         }
    2457 
    2458         function column_author( $comment ) {
    2459                 global $comment_status;
    2460 
    2461                 $author_url = get_comment_author_url();
    2462                 if ( 'http://' == $author_url )
    2463                         $author_url = '';
    2464                 $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url );
    2465                 if ( strlen( $author_url_display ) > 50 )
    2466                         $author_url_display = substr( $author_url_display, 0, 49 ) . '...';
    2467 
    2468                 echo "<strong>"; comment_author(); echo '</strong><br />';
    2469                 if ( !empty( $author_url ) )
    2470                         echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
    2471 
    2472                 if ( $this->user_can ) {
    2473                         if ( !empty( $comment->comment_author_email ) ) {
    2474                                 comment_author_email_link();
    2475                                 echo '<br />';
    2476                         }
    2477                         echo '<a href="edit-comments.php?s=';
    2478                         comment_author_IP();
    2479                         echo '&amp;mode=detail';
    2480                         if ( 'spam' == $comment_status )
    2481                                 echo '&amp;comment_status=spam';
    2482                         echo '">';
    2483                         comment_author_IP();
    2484                         echo '</a>';
    2485                 }
    2486         }
    2487 
    2488         function column_date( $comment ) {
    2489                 return get_comment_date( __( 'Y/m/d \a\t g:ia' ) );
    2490         }
    2491 
    2492         function column_response( $comment ) {
    2493                 global $post;
    2494 
    2495                 if ( isset( $this->pending_count[$post->ID] ) ) {
    2496                         $pending_comments = $this->pending_count[$post->ID];
    2497                 } else {
    2498                         $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
    2499                         $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
    2500                 }
    2501 
    2502                 if ( current_user_can( 'edit_post', $post->ID ) ) {
    2503                         $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>";
    2504                         $post_link .= get_the_title( $post->ID ) . '</a>';
    2505                 } else {
    2506                         $post_link = get_the_title( $post->ID );
    2507                 }
    2508 
    2509                 echo '<div class="response-links"><span class="post-com-count-wrapper">';
    2510                 echo $post_link . '<br />';
    2511                 $this->comments_bubble( $post->ID, $pending_comments );
    2512                 echo '</span> ';
    2513                 echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
    2514                 echo '</div>';
    2515                 if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) )
    2516                         echo $thumb;
    2517         }
    2518 
    2519         function column_default( $comment, $column_name ) {
    2520                 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
    2521         }
    2522 }
    2523 
    2524 class WP_Post_Comments_Table extends WP_Comments_Table {
    2525 
    2526         function get_columns() {
    2527                 return array(
    2528                         'author'   => __( 'Author' ),
    2529                         'comment'  => _x( 'Comment', 'column name' ),
    2530                 );
    2531         }
    2532 
    2533         function get_sortable_columns() {
    2534                 return array();
    2535         }
    2536 }
    2537 
    2538 class WP_Links_Table extends WP_List_Table {
    2539 
    2540         function WP_Links_Table() {
    2541                 parent::WP_List_Table( array(
    2542                         'screen' => 'link-manager',
    2543                         'plural' => 'bookmarks',
    2544                 ) );
    2545         }
    2546 
    2547         function check_permissions() {
    2548                 if ( ! current_user_can( 'manage_links' ) )
    2549                         wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) );
    2550         }
    2551 
    2552         function prepare_items() {
    2553                 global $cat_id, $s, $orderby, $order;
    2554 
    2555                 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' ) );
    2556 
    2557                 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
    2558 
    2559                 if ( 'all' != $cat_id )
    2560                         $args['category'] = $cat_id;
    2561                 if ( !empty( $s ) )
    2562                         $args['search'] = $s;
    2563                 if ( !empty( $orderby ) )
    2564                         $args['orderby'] = $orderby;
    2565                 if ( !empty( $order ) )
    2566                         $args['order'] = $order;
    2567 
    2568                 $this->items = get_bookmarks( $args );
    2569         }
    2570 
    2571         function no_items() {
    2572                 _e( 'No links found.' );
    2573         }
    2574 
    2575         function get_bulk_actions() {
    2576                 $actions = array();
    2577                 $actions['delete'] = __( 'Delete' );
    2578 
    2579                 return $actions;
    2580         }
    2581 
    2582         function extra_tablenav( $which ) {
    2583                 global $cat_id;
    2584 
    2585                 if ( 'top' != $which )
    2586                         return;
    2587 ?>
    2588                 <div class="alignleft actions">
    2589 <?php
    2590                         $dropdown_options = array(
    2591                                 'selected' => $cat_id,
    2592                                 'name' => 'cat_id',
    2593                                 'taxonomy' => 'link_category',
    2594                                 'show_option_all' => __( 'View all categories' ),
    2595                                 'hide_empty' => true,
    2596                                 'hierarchical' => 1,
    2597                                 'show_count' => 0,
    2598                                 'orderby' => 'name',
    2599                         );
    2600                         wp_dropdown_categories( $dropdown_options );
    2601 ?>
    2602                         <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" />
    2603                 </div>
    2604 <?php
    2605         }
    2606 
    2607         function get_columns() {
    2608                 return array(
    2609                         'cb'         => '<input type="checkbox" />',
    2610                         'name'       => __( 'Name' ),
    2611                         'url'        => __( 'URL' ),
    2612                         'categories' => __( 'Categories' ),
    2613                         'rel'        => __( 'Relationship' ),
    2614                         'visible'    => __( 'Visible' ),
    2615                         'rating'     => __( 'Rating' )
    2616                 );
    2617         }
    2618 
    2619         function get_sortable_columns() {
    2620                 return array(
    2621                         'name'    => 'name',
    2622                         'url'     => 'url',
    2623                         'visible' => 'visible',
    2624                         'rating'  => 'rating'
    2625                 );
    2626         }
    2627 
    2628         function display_rows() {
    2629                 global $cat_id;
    2630 
    2631                 $alt = 0;
    2632 
    2633                 foreach ( $this->items as $link ) {
    2634                         $link = sanitize_bookmark( $link );
    2635                         $link->link_name = esc_attr( $link->link_name );
    2636                         $link->link_category = wp_get_link_cats( $link->link_id );
    2637 
    2638                         $short_url = str_replace( 'http://', '', $link->link_url );
    2639                         $short_url = preg_replace( '/^www\./i', '', $short_url );
    2640                         if ( '/' == substr( $short_url, -1 ) )
    2641                                 $short_url = substr( $short_url, 0, -1 );
    2642                         if ( strlen( $short_url ) > 35 )
    2643                                 $short_url = substr( $short_url, 0, 32 ).'...';
    2644 
    2645                         $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' );
    2646                         $rating  = $link->link_rating;
    2647                         $style = ( $alt++ % 2 ) ? '' : ' class="alternate"';
    2648 
    2649                         $edit_link = get_edit_bookmark_link( $link );
    2650 ?>
    2651                 <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
    2652 <?php
    2653 
    2654                         list( $columns, $hidden ) = $this->get_column_info();
    2655 
    2656                         foreach ( $columns as $column_name => $column_display_name ) {
    2657                                 $class = "class='column-$column_name'";
    2658 
    2659                                 $style = '';
    2660                                 if ( in_array( $column_name, $hidden ) )
    2661                                         $style = ' style="display:none;"';
    2662 
    2663                                 $attributes = $class . $style;
    2664 
    2665                                 switch ( $column_name ) {
    2666                                         case 'cb':
    2667                                                 echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr( $link->link_id ) .'" /></th>';
    2668                                                 break;
    2669 
    2670                                         case 'name':
    2671                                                 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 />";
    2672 
    2673                                                 $actions = array();
    2674                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    2675                                                 $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>";
    2676                                                 echo $this->row_actions( $actions );
    2677 
    2678                                                 echo '</td>';
    2679                                                 break;
    2680                                         case 'url':
    2681                                                 echo "<td $attributes><a href='$link->link_url' title='".sprintf( __( 'Visit %s' ), $link->link_name )."'>$short_url</a></td>";
    2682                                                 break;
    2683                                         case 'categories':
    2684                                                 ?><td <?php echo $attributes ?>><?php
    2685                                                 $cat_names = array();
    2686                                                 foreach ( $link->link_category as $category ) {
    2687                                                         $cat = get_term( $category, 'link_category', OBJECT, 'display' );
    2688                                                         if ( is_wp_error( $cat ) )
    2689                                                                 echo $cat->get_error_message();
    2690                                                         $cat_name = $cat->name;
    2691                                                         if ( $cat_id != $category )
    2692                                                                 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
    2693                                                         $cat_names[] = $cat_name;
    2694                                                 }
    2695                                                 echo implode( ', ', $cat_names );
    2696                                                 ?></td><?php
    2697                                                 break;
    2698                                         case 'rel':
    2699                                                 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
    2700                                                 break;
    2701                                         case 'visible':
    2702                                                 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
    2703                                                 break;
    2704                                         case 'rating':
    2705                                                 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
    2706                                                 break;
    2707                                         default:
    2708                                                 ?>
    2709                                                 <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>
    2710                                                 <?php
    2711                                                 break;
    2712                                 }
    2713                         }
    2714 ?>
    2715                 </tr>
    2716 <?php
    2717                 }
    2718         }
    2719 }
    2720 
    2721 class WP_Sites_Table extends WP_List_Table {
    2722 
    2723         function WP_Sites_Table() {
    2724                 parent::WP_List_Table( array(
    2725                         'screen' => 'sites-network',
    2726                         'plural' => 'sites',
    2727                 ) );
    2728         }
    2729 
    2730         function check_permissions() {
    2731                 if ( ! current_user_can( 'manage_sites' ) )
    2732                         wp_die( __( 'You do not have permission to access this page.' ) );
    2733         }
    2734 
    2735         function prepare_items() {
    2736                 global $s, $mode, $wpdb;
    2737 
    2738                 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
    2739 
    2740                 $per_page = $this->get_items_per_page( 'sites_network_per_page' );
    2741 
    2742                 $pagenum = $this->get_pagenum();
    2743 
    2744                 $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
    2745                 $like_s = esc_sql( like_escape( $s ) );
    2746 
    2747                 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
    2748 
    2749                 if ( isset( $_REQUEST['searchaction'] ) ) {
    2750                         if ( 'name' == $_REQUEST['searchaction'] ) {
    2751                                 $query .= " AND ( {$wpdb->blogs}.domain LIKE '%{$like_s}%' OR {$wpdb->blogs}.path LIKE '%{$like_s}%' ) ";
    2752                         } elseif ( 'id' == $_REQUEST['searchaction'] ) {
    2753                                 $query .= " AND {$wpdb->blogs}.blog_id = '{$like_s}' ";
    2754                         } elseif ( 'ip' == $_REQUEST['searchaction'] ) {
    2755                                 $query = "SELECT *
    2756                                         FROM {$wpdb->blogs}, {$wpdb->registration_log}
    2757                                         WHERE site_id = '{$wpdb->siteid}'
    2758                                         AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
    2759                                         AND {$wpdb->registration_log}.IP LIKE ( '%{$like_s}%' )";
    2760                         }
    2761                 }
    2762 
    2763                 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'id';
    2764                 if ( $order_by == 'registered' ) {
    2765                         $query .= ' ORDER BY registered ';
    2766                 } elseif ( $order_by == 'lastupdated' ) {
    2767                         $query .= ' ORDER BY last_updated ';
    2768                 } elseif ( $order_by == 'blogname' ) {
    2769                         $query .= ' ORDER BY domain ';
    2770                 } else {
    2771                         $order_by = 'id';
    2772                         $query .= " ORDER BY {$wpdb->blogs}.blog_id ";
    2773                 }
    2774 
    2775                 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
    2776                 $query .= $order;
    2777 
    2778                 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
    2779 
    2780                 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
    2781                 $this->items = $wpdb->get_results( $query, ARRAY_A );
    2782 
    2783                 $this->set_pagination_args( array(
    2784                         'total_items' => $total,
    2785                         'per_page' => $per_page,
    2786                 ) );
    2787         }
    2788 
    2789         function no_items() {
    2790                 _e( 'No sites found.' );
    2791         }
    2792 
    2793         function get_bulk_actions() {
    2794                 $actions = array();
    2795                 $actions['delete'] = __( 'Delete' );
    2796                 $actions['spam'] = _x( 'Mark as Spam', 'site' );
    2797                 $actions['notspam'] = _x( 'Not Spam', 'site' );
    2798 
    2799                 return $actions;
    2800         }
    2801 
    2802         function pagination( $which ) {
    2803                 global $mode;
    2804 
    2805                 parent::pagination( $which );
    2806 
    2807                 if ( 'top' == $which )
    2808                         $this->view_switcher( $mode );
    2809         }
    2810 
    2811         function get_columns() {
    2812                 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
    2813                 $sites_columns = array(
    2814                         'cb'          => '<input type="checkbox" />',
    2815                         'blogname'    => $blogname_columns,
    2816                         'lastupdated' => __( 'Last Updated' ),
    2817                         'registered'  => _x( 'Registered', 'site' ),
    2818                         'users'       => __( 'Users' )
    2819                 );
    2820 
    2821                 if ( has_filter( 'wpmublogsaction' ) )
    2822                         $sites_columns['plugins'] = __( 'Actions' );
    2823 
    2824                 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
    2825 
    2826                 return $sites_columns;
    2827         }
    2828 
    2829         function get_sortable_columns() {
    2830                 return array(
    2831                         'id'          => 'id',
    2832                         'blogname'    => 'blogname',
    2833                         'lastupdated' => 'lastupdated',
    2834                         'registered'  => 'registered',
    2835                 );
    2836         }
    2837 
    2838         function display_rows() {
    2839                 global $current_site, $mode;
    2840 
    2841                 $status_list = array(
    2842                         'archived' => array( 'site-archived', __( 'Archived' ) ),
    2843                         'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
    2844                         'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
    2845                         'mature'   => array( 'site-mature', __( 'Mature' ) )
    2846                 );
    2847 
    2848                 $class = '';
    2849                 foreach ( $this->items as $blog ) {
    2850                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    2851                         reset( $status_list );
    2852 
    2853                         $blog_states = array();
    2854                         foreach ( $status_list as $status => $col ) {
    2855                                 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
    2856                                         $class = $col[0];
    2857                                         $blog_states[] = $col[1];
    2858                                 }
    2859                         }
    2860                         $blog_state = '';
    2861                         if ( ! empty( $blog_states ) ) {
    2862                                 $state_count = count( $blog_states );
    2863                                 $i = 0;
    2864                                 $blog_state .= ' - ';
    2865                                 foreach ( $blog_states as $state ) {
    2866                                         ++$i;
    2867                                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
    2868                                         $blog_state .= "<span class='post-state'>$state$sep</span>";
    2869                                 }
    2870                         }
    2871                         echo "<tr class='$class'>";
    2872 
    2873                         $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
    2874 
    2875                         list( $columns, $hidden ) = $this->get_column_info();
    2876 
    2877                         foreach ( $columns as $column_name => $column_display_name ) {
    2878                                 switch ( $column_name ) {
    2879                                         case 'cb': ?>
    2880                                                 <th scope="row" class="check-column">
    2881                                                         <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
    2882                                                 </th>
    2883                                         <?php
    2884                                         break;
    2885 
    2886                                         case 'id': ?>
    2887                                                 <th valign="top" scope="row">
    2888                                                         <?php echo $blog['blog_id'] ?>
    2889                                                 </th>
    2890                                         <?php
    2891                                         break;
    2892 
    2893                                         case 'blogname': ?>
    2894                                                 <td class="column-title">
    2895                                                         <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
    2896                                                         <?php
    2897                                                         if ( 'list' != $mode )
    2898                                                                 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>';
    2899 
    2900                                                         // Preordered.
    2901                                                         $actions = array(
    2902                                                                 'edit' => '', 'backend' => '',
    2903                                                                 'activate' => '', 'deactivate' => '',
    2904                                                                 'archive' => '', 'unarchive' => '',
    2905                                                                 'spam' => '', 'unspam' => '',
    2906                                                                 'delete' => '',
    2907                                                                 'visit' => '',
    2908                                                         );
    2909 
    2910                                                         $actions['edit']        = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
    2911                                                         $actions['backend']     = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
    2912                                                         if ( $current_site->blog_id != $blog['blog_id'] ) {
    2913                                                                 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
    2914                                                                         $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>';
    2915                                                                 else
    2916                                                                         $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>';
    2917 
    2918                                                                 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
    2919                                                                         $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>';
    2920                                                                 else
    2921                                                                         $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>';
    2922 
    2923                                                                 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
    2924                                                                         $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>';
    2925                                                                 else
    2926                                                                         $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>';
    2927 
    2928                                                                 $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>';
    2929                                                         }
    2930 
    2931                                                         $actions['visit']       = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
    2932                                                         $actions = array_filter( $actions );
    2933                                                         echo $this->row_actions( $actions );
    2934                                         ?>
    2935                                                 </td>
    2936                                         <?php
    2937                                         break;
    2938 
    2939                                         case 'lastupdated': ?>
    2940                                                 <td valign="top">
    2941                                                         <?php
    2942                                                         if ( 'list' == $mode )
    2943                                                                 $date = 'Y/m/d';
    2944                                                         else
    2945                                                                 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    2946                                                         echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
    2947                                                 </td>
    2948                                         <?php
    2949                                         break;
    2950                                 case 'registered': ?>
    2951                                                 <td valign="top">
    2952                                                 <?php
    2953                                                 if ( $blog['registered'] == '0000-00-00 00:00:00' )
    2954                                                         echo '&#x2014;';
    2955                                                 else
    2956                                                         echo mysql2date( $date, $blog['registered'] );
    2957                                                 ?>
    2958                                                 </td>
    2959                                 <?php
    2960                                 break;
    2961                                         case 'users': ?>
    2962                                                 <td valign="top">
    2963                                                         <?php
    2964                                                         $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
    2965                                                         if ( is_array( $blogusers ) ) {
    2966                                                                 $blogusers_warning = '';
    2967                                                                 if ( count( $blogusers ) > 5 ) {
    2968                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
    2969                                                                         $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '">' . __( 'More' ) . '</a>';
    2970                                                                 }
    2971                                                                 foreach ( $blogusers as $user_object ) {
    2972                                                                         echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
    2973                                                                         if ( 'list' != $mode )
    2974                                                                                 echo '( ' . $user_object->user_email . ' )';
    2975                                                                         echo '<br />';
    2976                                                                 }
    2977                                                                 if ( $blogusers_warning != '' )
    2978                                                                         echo '<strong>' . $blogusers_warning . '</strong><br />';
    2979                                                         }
    2980                                                         ?>
    2981                                                 </td>
    2982                                         <?php
    2983                                         break;
    2984 
    2985                                         case 'plugins': ?>
    2986                                                 <?php if ( has_filter( 'wpmublogsaction' ) ) { ?>
    2987                                                 <td valign="top">
    2988                                                         <?php do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
    2989                                                 </td>
    2990                                                 <?php } ?>
    2991                                         <?php break;
    2992 
    2993                                         default: ?>
    2994                                                 <?php if ( has_filter( 'manage_blogs_custom_column' ) ) { ?>
    2995                                                 <td valign="top">
    2996                                                         <?php do_action( 'manage_blogs_custom_column', $column_name, $blog['blog_id'] ); ?>
    2997                                                 </td>
    2998                                                 <?php } ?>
    2999                                         <?php break;
    3000                                 }
    3001                         }
    3002                         ?>
    3003                         </tr>
    3004                         <?php
    3005                 }
    3006         }
    3007 }
    3008 
    3009 class WP_MS_Users_Table extends WP_List_Table {
    3010 
    3011         function WP_MS_Users_Table() {
    3012                 parent::WP_List_Table( array(
    3013                         'screen' => 'users-network',
    3014                 ) );
    3015         }
    3016 
    3017         function check_permissions() {
    3018                 if ( !is_multisite() )
    3019                         wp_die( __( 'Multisite support is not enabled.' ) );
    3020 
    3021                 if ( ! current_user_can( 'manage_network_users' ) )
    3022                         wp_die( __( 'You do not have permission to access this page.' ) );
    3023         }
    3024 
    3025         function prepare_items() {
    3026                 global $usersearch;
    3027 
    3028                 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    3029 
    3030                 $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
    3031 
    3032                 $paged = $this->get_pagenum();
    3033 
    3034                 $args = array(
    3035                         'number' => $users_per_page,
    3036                         'offset' => ( $paged-1 ) * $users_per_page,
    3037                         'search' => $usersearch,
    3038                         'blog_id' => 0
    3039                 );
    3040 
    3041                 if ( isset( $_REQUEST['orderby'] ) )
    3042                         $args['orderby'] = $_REQUEST['orderby'];
    3043 
    3044                 if ( isset( $_REQUEST['order'] ) )
    3045                         $args['order'] = $_REQUEST['order'];
    3046 
    3047                 // Query the user IDs for this page
    3048                 $wp_user_search = new WP_User_Query( $args );
    3049 
    3050                 $this->items = $wp_user_search->get_results();
    3051 
    3052                 $this->set_pagination_args( array(
    3053                         'total_items' => $wp_user_search->get_total(),
    3054                         'per_page' => $users_per_page,
    3055                 ) );
    3056         }
    3057 
    3058         function get_bulk_actions() {
    3059                 $actions = array();
    3060                 $actions['delete'] = __( 'Delete' );
    3061                 $actions['spam'] = _x( 'Mark as Spam', 'user' );
    3062                 $actions['notspam'] = _x( 'Not Spam', 'user' );
    3063 
    3064                 return $actions;
    3065         }
    3066 
    3067         function no_items() {
    3068                 _e( 'No users found.' );
    3069         }
    3070 
    3071         function pagination( $which ) {
    3072                 global $mode;
    3073 
    3074                 parent::pagination ( $which );
    3075 
    3076                 if ( 'top' == $which )
    3077                         $this->view_switcher( $mode );
    3078         }
    3079 
    3080         function get_columns() {
    3081                 $users_columns = array(
    3082                         'cb'         => '<input type="checkbox" />',
    3083                         'login'      => __( 'Login' ),
    3084                         'name'       => __( 'Name' ),
    3085                         'email'      => __( 'E-mail' ),
    3086                         'registered' => _x( 'Registered', 'user' ),
    3087                         'blogs'      => __( 'Sites' )
    3088                 );
    3089                 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
    3090 
    3091                 return $users_columns;
    3092         }
    3093 
    3094         function get_sortable_columns() {
    3095                 return array(
    3096                         'id'         => 'id',
    3097                         'login'      => 'login',
    3098                         'name'       => 'name',
    3099                         'email'      => 'email',
    3100                         'registered' => 'registered',
    3101                 );
    3102         }
    3103 
    3104         function display_rows() {
    3105                 global $current_site, $mode;
    3106 
    3107                 $class = '';
    3108                 $super_admins = get_super_admins();
    3109                 foreach ( $this->items as $user ) {
    3110                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
    3111 
    3112                         $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
    3113 
    3114                         foreach ( $status_list as $status => $col ) {
    3115                                 if ( $user->$status )
    3116                                         $class = $col;
    3117                         }
    3118 
    3119                         ?>
    3120                         <tr class="<?php echo $class; ?>">
    3121                         <?php
    3122 
    3123                         list( $columns, $hidden ) = $this->get_column_info();
    3124 
    3125                         foreach ( $columns as $column_name => $column_display_name ) :
    3126                                 switch ( $column_name ) {
    3127                                         case 'cb': ?>
    3128                                                 <th scope="row" class="check-column">
    3129                                                         <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
    3130                                                 </th>
    3131                                         <?php
    3132                                         break;
    3133 
    3134                                         case 'id': ?>
    3135                                                 <th valign="top" scope="row">
    3136                                                         <?php echo $user->ID ?>
    3137                                                 </th>
    3138                                         <?php
    3139                                         break;
    3140 
    3141                                         case 'login':
    3142                                                 $avatar = get_avatar( $user->user_email, 32 );
    3143                                                 $edit_link = ( get_current_user_id() == $user->ID ) ? 'profile.php' : 'user-edit.php?user_id=' . $user->ID;
    3144                                                 ?>
    3145                                                 <td class="username column-username">
    3146                                                         <?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
    3147                                                         if ( in_array( $user->user_login, $super_admins ) )
    3148                                                                 echo ' - ' . __( 'Super admin' );
    3149                                                         ?></strong>
    3150                                                         <br/>
    3151                                                         <?php
    3152                                                                 $actions = array();
    3153                                                                 $actions['edit'] = '<a href="' . esc_url( self_admin_url( $edit_link ) ) . '">' . __( 'Edit' ) . '</a>';
    3154 
    3155                                                                 if ( ! in_array( $user->user_login, $super_admins ) ) {
    3156                                                                         $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>';
    3157                                                                 }
    3158 
    3159                                                                 echo $this->row_actions( $actions );
    3160                                                         ?>
    3161                                                         </div>
    3162                                                 </td>
    3163                                         <?php
    3164                                         break;
    3165 
    3166                                         case 'name': ?>
    3167                                                 <td class="name column-name"><?php echo $user->display_name ?></td>
    3168                                         <?php
    3169                                         break;
    3170 
    3171                                         case 'email': ?>
    3172                                                 <td class="email column-email"><a href="mailto:<?php echo $user->user_email ?>"><?php echo $user->user_email ?></a></td>
    3173                                         <?php
    3174                                         break;
    3175 
    3176                                         case 'registered':
    3177                                                 if ( 'list' == $mode )
    3178                                                         $date = 'Y/m/d';
    3179                                                 else
    3180                                                         $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    3181                                         ?>
    3182                                                 <td><?php echo mysql2date( $date, $user->user_registered ); ?></td>
    3183                                         <?php
    3184                                         break;
    3185 
    3186                                         case 'blogs':
    3187                                                 $blogs = get_blogs_of_user( $user->ID, true );
    3188                                                 ?>
    3189                                                 <td>
    3190                                                         <?php
    3191                                                         if ( is_array( $blogs ) ) {
    3192                                                                 foreach ( (array) $blogs as $key => $val ) {
    3193                                                                         $path   = ( $val->path == '/' ) ? '' : $val->path;
    3194                                                                         echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
    3195                                                                         echo ' <small class="row-actions">';
    3196 
    3197                                                                         // Edit
    3198                                                                         echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a> | ';
    3199 
    3200                                                                         // View
    3201                                                                         echo '<a ';
    3202                                                                         if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
    3203                                                                                 echo 'style="background-color: #faa" ';
    3204                                                                         echo 'href="' .  esc_url( get_home_url( $val->userblog_id ) )  . '">' . __( 'View' ) . '</a>';
    3205 
    3206                                                                         echo '</small><br />';
    3207                                                                 }
    3208                                                         }
    3209                                                         ?>
    3210                                                 </td>
    3211                                         <?php
    3212                                         break;
    3213 
    3214                                         default: ?>
    3215                                                 <td><?php do_action( 'manage_users_custom_column', $column_name, $user->ID ); ?></td>
    3216                                         <?php
    3217                                         break;
    3218                                 }
    3219                         endforeach
    3220                         ?>
    3221                         </tr>
    3222                         <?php
    3223                 }
    3224         }
    3225 }
    3226 
    3227 class WP_Plugins_Table extends WP_List_Table {
    3228 
    3229         function WP_Plugins_Table() {
    3230                 global $status, $page;
    3231 
    3232                 $default_status = get_user_option( 'plugins_last_view' );
    3233                 if ( empty( $default_status ) )
    3234                         $default_status = 'all';
    3235                 $status = isset( $_REQUEST['plugin_status'] ) ? $_REQUEST['plugin_status'] : $default_status;
    3236                 if ( !in_array( $status, array( 'all', 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
    3237                         $status = 'all';
    3238                 if ( $status != $default_status && 'search' != $status )
    3239                         update_user_meta( get_current_user_id(), 'plugins_last_view', $status );
    3240 
    3241                 $page = $this->get_pagenum();
    3242 
    3243                 parent::WP_List_Table( array(
    3244                         'screen' => 'plugins',
    3245                         'plural' => 'plugins',
    3246                 ) );
    3247         }
    3248 
    3249         function check_permissions() {
    3250                 if ( is_multisite() ) {
    3251                         $menu_perms = get_site_option( 'menu_items', array() );
    3252 
    3253                         if ( empty( $menu_perms['plugins'] ) ) {
    3254                                 if ( !is_super_admin() )
    3255                                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    3256                         }
    3257                 }
    3258 
    3259                 if ( !current_user_can('activate_plugins') )
    3260                         wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
    3261         }
    3262 
    3263         function prepare_items() {
    3264                 global $status, $plugins, $totals, $page, $orderby, $order, $s;
    3265 
    3266                 wp_reset_vars( array( 'orderby', 'order', 's' ) );
    3267 
    3268                 $plugins = array(
    3269                         'all' => apply_filters( 'all_plugins', get_plugins() ),
    3270                         'search' => array(),
    3271                         'active' => array(),
    3272                         'inactive' => array(),
    3273                         'recently_activated' => array(),
    3274                         'upgrade' => array(),
    3275                         'mustuse' => array(),
    3276                         'dropins' => array()
    3277                 );
    3278 
    3279                 if ( ! is_multisite() || ( is_network_admin() && current_user_can('manage_network_plugins') ) ) {
    3280                         if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
    3281                                 $plugins['mustuse'] = get_mu_plugins();
    3282                         if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
    3283                                 $plugins['dropins'] = get_dropins();
    3284                 }
    3285 
    3286                 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
    3287 
    3288                 $recently_activated = get_option( 'recently_activated', array() );
    3289 
    3290                 $one_week = 7*24*60*60;
    3291                 foreach ( $recently_activated as $key => $time )
    3292                         if ( $time + $one_week < time() )
    3293                                 unset( $recently_activated[$key] );
    3294                 update_option( 'recently_activated', $recently_activated );
    3295 
    3296                 $current = get_site_transient( 'update_plugins' );
    3297 
    3298                 foreach ( array( 'all', 'mustuse', 'dropins' ) as $type ) {
    3299                         foreach ( (array) $plugins[$type] as $plugin_file => $plugin_data ) {
    3300                                 // Translate, Apply Markup, Sanitize HTML
    3301                                 $plugins[$type][$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
    3302                         }
    3303                 }
    3304 
    3305                 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    3306                         // Filter into individual sections
    3307                         if ( is_plugin_active_for_network($plugin_file) && !is_network_admin() ) {
    3308                                 unset( $plugins['all'][ $plugin_file ] );
    3309                                 continue;
    3310                         } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
    3311                                 $plugins['network'][ $plugin_file ] = $plugin_data;
    3312                         } elseif ( ( !is_network_admin() && is_plugin_active( $plugin_file ) )
    3313                                 || ( is_network_admin() && is_plugin_active_for_network( $plugin_file ) ) ) {
    3314                                 $plugins['active'][ $plugin_file ] = $plugin_data;
    3315                         } else {
    3316                                 if ( !is_network_admin() && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
    3317                                         $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
    3318                                 $plugins['inactive'][ $plugin_file ] = $plugin_data;
    3319                         }
    3320 
    3321                         if ( isset( $current->response[ $plugin_file ] ) )
    3322                                 $plugins['upgrade'][ $plugin_file ] = $plugin_data;
    3323                 }
    3324 
    3325                 if ( !current_user_can( 'update_plugins' ) )
    3326                         $plugins['upgrade'] = array();
    3327 
    3328                 if ( $s ) {
    3329                         $status = 'search';
    3330                         $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
    3331                 }
    3332 
    3333                 $totals = array();
    3334                 foreach ( $plugins as $type => $list )
    3335                         $totals[ $type ] = count( $list );
    3336 
    3337                 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
    3338                         $status = 'all';
    3339 
    3340                 $this->items = $plugins[ $status ];
    3341                 $total_this_page = $totals[ $status ];
    3342 
    3343                 if ( $orderby ) {
    3344                         $orderby = ucfirst( $orderby );
    3345                         $order = strtoupper( $order );
    3346 
    3347                         uasort( $this->items, array( $this, '_order_callback' ) );
    3348                 }
    3349 
    3350                 $plugins_per_page = $this->get_items_per_page( 'plugins_per_page', 999 );
    3351 
    3352                 $start = ( $page - 1 ) * $plugins_per_page;
    3353 
    3354                 if ( $total_this_page > $plugins_per_page )
    3355                         $this->items = array_slice( $this->items, $start, $plugins_per_page );
    3356 
    3357                 $this->set_pagination_args( array(
    3358                         'total_items' => $total_this_page,
    3359                         'per_page' => $plugins_per_page,
    3360                 ) );
    3361         }
    3362 
    3363         function _search_callback( $plugin ) {
    3364                 static $term;
    3365                 if ( is_null( $term ) )
    3366                         $term = stripslashes( $_REQUEST['s'] );
    3367 
    3368                 foreach ( $plugin as $value )
    3369                         if ( stripos( $value, $term ) !== false )
    3370                                 return true;
    3371 
    3372                 return false;
    3373         }
    3374 
    3375         function _order_callback( $plugin_a, $plugin_b ) {
    3376                 global $orderby, $order;
    3377 
    3378                 $a = $plugin_a[$orderby];
    3379                 $b = $plugin_b[$orderby];
    3380 
    3381                 if ( $a == $b )
    3382                         return 0;
    3383 
    3384                 if ( 'DESC' == $order )
    3385                         return ( $a < $b ) ? 1 : -1;
    3386                 else
    3387                         return ( $a < $b ) ? -1 : 1;
    3388         }
    3389 
    3390         function no_items() {
    3391                 global $plugins;
    3392 
    3393                 if ( !empty( $plugins['all'] ) )
    3394                         _e( 'No plugins found.' );
    3395                 else
    3396                         _e( 'You do not appear to have any plugins available at this time.' );
    3397         }
    3398 
    3399         function get_columns() {
    3400                 global $status;
    3401 
    3402                 return array(
    3403                         'cb'          => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
    3404                         'name'        => __( 'Plugin' ),
    3405                         'description' => __( 'Description' ),
    3406                 );
    3407         }
    3408 
    3409         function get_sortable_columns() {
    3410                 return array(
    3411                         'name'         => 'name',
    3412                         'description'  => 'description',
    3413                 );
    3414         }
    3415 
    3416         function display_tablenav( $which ) {
    3417                 global $status;
    3418 
    3419                 if ( !in_array( $status, array( 'mustuse', 'dropins' ) ) )
    3420                         parent::display_tablenav( $which );
    3421         }
    3422 
    3423         function get_views() {
    3424                 global $totals, $status;
    3425 
    3426                 $status_links = array();
    3427                 foreach ( $totals as $type => $count ) {
    3428                         if ( !$count )
    3429                                 continue;
    3430 
    3431                         switch ( $type ) {
    3432                                 case 'all':
    3433                                         $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
    3434                                         break;
    3435                                 case 'active':
    3436                                         $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
    3437                                         break;
    3438                                 case 'recently_activated':
    3439                                         $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
    3440                                         break;
    3441                                 case 'inactive':
    3442                                         $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
    3443                                         break;
    3444                                 case 'network':
    3445                                         $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
    3446                                         break;
    3447                                 case 'mustuse':
    3448                                         $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
    3449                                         break;
    3450                                 case 'dropins':
    3451                                         $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
    3452                                         break;
    3453                                 case 'upgrade':
    3454                                         $text = _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $count );
    3455                                         break;
    3456                                 case 'search':
    3457                                         $text = _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $count );
    3458                                         break;
    3459                         }
    3460 
    3461                         $status_links[$type] = sprintf( "<li><a href='%s' %s>%s</a>",
    3462                                 add_query_arg('plugin_status', $type, 'plugins.php'),
    3463                                 ( $type == $status ) ? ' class="current"' : '',
    3464                                 sprintf( $text, number_format_i18n( $count ) )
    3465                         );
    3466                 }
    3467 
    3468                 return $status_links;
    3469         }
    3470 
    3471         function get_bulk_actions() {
    3472                 global $status;
    3473 
    3474                 $actions = array();
    3475                 if ( 'active' != $status )
    3476                         $actions['activate-selected'] = __( 'Activate' );
    3477                 if ( is_multisite() && 'network' != $status )
    3478                         $actions['network-activate-selected'] = __( 'Network Activate' );
    3479                 if ( 'inactive' != $status && 'recent' != $status )
    3480                         $actions['deactivate-selected'] = __( 'Deactivate' );
    3481                 if ( current_user_can( 'update_plugins' ) )
    3482                         $actions['update-selected'] = __( 'Update' );
    3483                 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
    3484                         $actions['delete-selected'] = __( 'Delete' );
    3485 
    3486                 return $actions;
    3487         }
    3488 
    3489         function bulk_actions( $which ) {
    3490                 global $status;
    3491 
    3492                 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
    3493                         return;
    3494 
    3495                 parent::bulk_actions( $which );
    3496         }
    3497 
    3498         function extra_tablenav( $which ) {
    3499                 global $status;
    3500 
    3501                 if ( 'recently_activated' == $status ) { ?>
    3502                         <div class="alignleft actions">
    3503                                 <input type="submit" name="clear-recent-list" value="<?php esc_attr_e( 'Clear List' ) ?>" class="button-secondary" />
    3504                         </div>
    3505                 <?php }
    3506         }
    3507 
    3508         function current_action() {
    3509                 if ( isset($_POST['clear-recent-list']) )
    3510                         return 'clear-recent-list';
    3511 
    3512                 return parent::current_action();
    3513         }
    3514 
    3515         function display_rows() {
    3516                 global $status, $page, $s;
    3517 
    3518                 $context = $status;
    3519 
    3520                 foreach ( $this->items as $plugin_file => $plugin_data ) {
    3521                         // preorder
    3522                         $actions = array(
    3523                                 'network_deactivate' => '', 'deactivate' => '',
    3524                                 'network_only' => '', 'activate' => '',
    3525                                 'network_activate' => '',
    3526                                 'edit' => '',
    3527                                 'delete' => '',
    3528                         );
    3529 
    3530                         if ( 'mustuse' == $context ) {
    3531                                 if ( is_multisite() && !is_network_admin() )
    3532                                         continue;
    3533                                 $is_active = true;
    3534                         } elseif ( 'dropins' == $context ) {
    3535                                 if ( is_multisite() && !is_network_admin() )
    3536                                         continue;
    3537                                 $dropins = _get_dropins();
    3538                                 $plugin_name = $plugin_file;
    3539                                 if ( $plugin_file != $plugin_data['Name'] )
    3540                                         $plugin_name .= '<br/>' . $plugin_data['Name'];
    3541                                 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
    3542                                         $is_active = true;
    3543                                         $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
    3544                                 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
    3545                                         $is_active = true;
    3546                                         $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
    3547                                 } else {
    3548                                         $is_active = false;
    3549                                         $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>';
    3550                                 }
    3551                                 if ( $plugin_data['Description'] )
    3552                                         $description .= '<p>' . $plugin_data['Description'] . '</p>';
    3553                         } else {
    3554                                 $is_active_for_network = is_plugin_active_for_network($plugin_file);
    3555                                 if ( is_network_admin() )
    3556                                         $is_active = $is_active_for_network;
    3557                                 else
    3558                                         $is_active = is_plugin_active( $plugin_file );
    3559 
    3560                                 if ( $is_active_for_network && !is_super_admin() && !is_network_admin() )
    3561                                         continue;
    3562 
    3563                                 if ( is_network_admin() ) {
    3564                                         if ( $is_active_for_network ) {
    3565                                                 if ( current_user_can( 'manage_network_plugins' ) )
    3566                                                         $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>';
    3567                                         } else {
    3568                                                 if ( current_user_can( 'manage_network_plugins' ) )
    3569                                                         $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>';
    3570                                                 if ( current_user_can('delete_plugins') )
    3571                                                         $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>';
    3572                                         }
    3573                                 } else {
    3574                                         if ( $is_active ) {
    3575                                                 $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>';
    3576                                         } else {
    3577                                                 if ( is_network_only_plugin( $plugin_file ) && !is_network_admin() )
    3578                                                         continue;
    3579 
    3580                                                 $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>';
    3581 
    3582                                                 if ( current_user_can('delete_plugins') )
    3583                                                         $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>';
    3584                                         } // end if $is_active
    3585                                  } // end if is_network_admin()
    3586 
    3587                                 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    3588                                         $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    3589                         } // end if $context
    3590 
    3591                         $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
    3592                         $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
    3593 
    3594                         $class = $is_active ? 'active' : 'inactive';
    3595                         $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' />";
    3596                         if ( 'dropins' != $status ) {
    3597                                 $description = '<p>' . $plugin_data['Description'] . '</p>';
    3598                                 $plugin_name = $plugin_data['Name'];
    3599                         }
    3600 
    3601                         $id = sanitize_title( $plugin_name );
    3602 
    3603                         echo "
    3604                 <tr id='$id' class='$class'>
    3605                         <th scope='row' class='check-column'>$checkbox</th>
    3606                         <td class='plugin-title'><strong>$plugin_name</strong></td>
    3607                         <td class='desc'>$description</td>
    3608                 </tr>
    3609                 <tr class='$class second'>
    3610                         <td></td>
    3611                         <td class='plugin-title'>";
    3612 
    3613                         echo $this->row_actions( $actions, true );
    3614 
    3615                         echo "</td>
    3616                         <td class='desc'>";
    3617                         $plugin_meta = array();
    3618                         if ( !empty( $plugin_data['Version'] ) )
    3619                                 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
    3620                         if ( !empty( $plugin_data['Author'] ) ) {
    3621                                 $author = $plugin_data['Author'];
    3622                                 if ( !empty( $plugin_data['AuthorURI'] ) )
    3623                                         $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    3624                                 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
    3625                         }
    3626                         if ( ! empty( $plugin_data['PluginURI'] ) )
    3627                                 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
    3628 
    3629                         $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
    3630                         echo implode( ' | ', $plugin_meta );
    3631                         echo "</td>
    3632                 </tr>\n";
    3633 
    3634                         do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
    3635                         do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
    3636                 }
    3637         }
    3638 }
    3639 
    3640 class WP_Plugin_Install_Table extends WP_List_Table {
    3641 
    3642         function WP_Plugin_Install_Table() {
    3643                 parent::WP_List_Table( array(
    3644                         'screen' => 'plugin-install',
    3645                 ) );
    3646         }
    3647 
    3648         function check_permissions() {
    3649                 if ( ! current_user_can('install_plugins') )
    3650                         wp_die(__('You do not have sufficient permissions to install plugins on this site.'));
    3651         }
    3652 
    3653         function prepare_items() {
    3654                 include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    3655 
    3656                 global $tabs, $tab, $paged, $type, $term;
    3657 
    3658                 wp_reset_vars( array( 'tab' ) );
    3659 
    3660                 $paged = $this->get_pagenum();
    3661 
    3662                 $per_page = 30;
    3663 
    3664                 // These are the tabs which are shown on the page
    3665                 $tabs = array();
    3666                 $tabs['dashboard'] = __( 'Search' );
    3667                 if ( 'search' == $tab )
    3668                         $tabs['search'] = __( 'Search Results' );
    3669                 $tabs['upload'] = __( 'Upload' );
    3670                 $tabs['featured'] = _x( 'Featured','Plugin Installer' );
    3671                 $tabs['popular']  = _x( 'Popular','Plugin Installer' );
    3672                 $tabs['new']      = _x( 'Newest','Plugin Installer' );
    3673                 $tabs['updated']  = _x( 'Recently Updated','Plugin Installer' );
    3674 
    3675                 $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
    3676 
    3677                 $tabs = apply_filters( 'install_plugins_tabs', $tabs );
    3678                 $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
    3679 
    3680                 // If a non-valid menu tab has been selected, And its not a non-menu action.
    3681                 if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    3682                         $tab = key( $tabs );
    3683 
    3684                 $args = array( 'page' => $paged, 'per_page' => $per_page );
    3685 
    3686                 switch ( $tab ) {
    3687                         case 'search':
    3688                                 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
    3689                                 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    3690 
    3691                                 switch ( $type ) {
    3692                                         case 'tag':
    3693                                                 $args['tag'] = sanitize_title_with_dashes( $term );
    3694                                                 break;
    3695                                         case 'term':
    3696                                                 $args['search'] = $term;
    3697                                                 break;
    3698                                         case 'author':
    3699                                                 $args['author'] = $term;
    3700                                                 break;
    3701                                 }
    3702 
    3703                                 add_action( 'install_plugins_table_header', 'install_search_form' );
    3704                                 break;
    3705 
    3706                         case 'featured':
    3707                         case 'popular':
    3708                         case 'new':
    3709                         case 'updated':
    3710                                 $args['browse'] = $tab;
    3711                                 break;
    3712 
    3713                         default:
    3714                                 $args = false;
    3715                 }
    3716 
    3717                 if ( !$args )
    3718                         return;
    3719 
    3720                 $api = plugins_api( 'query_plugins', $args );
    3721 
    3722                 if ( is_wp_error( $api ) )
    3723                         wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
    3724 
    3725                 $this->items = $api->plugins;
    3726 
    3727                 $this->set_pagination_args( array(
    3728                         'total_items' => $api->info['results'],
    3729                         'per_page' => $per_page,
    3730                 ) );
    3731         }
    3732 
    3733         function no_items() {
    3734                 _e( 'No plugins match your request.' );
    3735         }
    3736 
    3737         function get_views() {
    3738                 global $tabs, $tab;
    3739 
    3740                 $display_tabs = array();
    3741                 foreach ( (array) $tabs as $action => $text ) {
    3742                         $class = ( $action == $tab ) ? ' class="current"' : '';
    3743                         $href = admin_url('plugin-install.php?tab=' . $action);
    3744                         $display_tabs[$action] = "<a href='$href'$class>$text</a>";
    3745                 }
    3746 
    3747                 return $display_tabs;
    3748         }
    3749 
    3750         function display_tablenav( $which ) {
    3751                 if ( 'top' ==  $which ) { ?>
    3752                         <div class="tablenav">
    3753                                 <div class="alignleft actions">
    3754                                         <?php do_action( 'install_plugins_table_header' ); ?>
    3755                                 </div>
    3756                                 <?php $this->pagination( $which ); ?>
    3757                                 <br class="clear" />
    3758                         </div>
    3759                 <?php } else { ?>
    3760                         <div class="tablenav">
    3761                                 <?php $this->pagination( $which ); ?>
    3762                                 <br class="clear" />
    3763                         </div>
    3764                 <?php
    3765                 }
    3766         }
    3767 
    3768         function get_table_classes() {
    3769                 extract( $this->_args );
    3770 
    3771                 return array( 'widefat', $plural );
    3772         }
    3773 
    3774         function get_columns() {
    3775                 return array(
    3776                         'name'        => __( 'Name' ),
    3777                         'version'     => __( 'Version' ),
    3778                         'rating'      => __( 'Rating' ),
    3779                         'description' => __( 'Description' ),
    3780                 );
    3781         }
    3782 
    3783         function display_rows() {
    3784                 $plugins_allowedtags = array(
    3785                         'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
    3786                         'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
    3787                         'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
    3788                         'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
    3789                 );
    3790 
    3791                 foreach ( (array) $this->items as $plugin ) {
    3792                         if ( is_object( $plugin ) )
    3793                                 $plugin = (array) $plugin;
    3794 
    3795                         $title = wp_kses( $plugin['name'], $plugins_allowedtags );
    3796                         //Limit description to 400char, and remove any HTML.
    3797                         $description = strip_tags( $plugin['description'] );
    3798                         if ( strlen( $description ) > 400 )
    3799                                 $description = mb_substr( $description, 0, 400 ) . '&#8230;';
    3800                         //remove any trailing entities
    3801                         $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
    3802                         //strip leading/trailing & multiple consecutive lines
    3803                         $description = trim( $description );
    3804                         $description = preg_replace( "|(\r?\n)+|", "\n", $description );
    3805                         //\n => <br>
    3806                         $description = nl2br( $description );
    3807                         $version = wp_kses( $plugin['version'], $plugins_allowedtags );
    3808 
    3809                         $name = strip_tags( $title . ' ' . $version );
    3810 
    3811                         $author = $plugin['author'];
    3812                         if ( ! empty( $plugin['author'] ) )
    3813                                 $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
    3814 
    3815                         $author = wp_kses( $author, $plugins_allowedtags );
    3816 
    3817                         $action_links = array();
    3818                         $action_links[] = '<a href="' . admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
    3819                                                                 '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
    3820                                                                 esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
    3821 
    3822                         if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
    3823                                 $status = install_plugin_install_status( $plugin );
    3824 
    3825                                 switch ( $status['status'] ) {
    3826                                         case 'install':
    3827                                                 if ( $status['url'] )
    3828                                                         $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
    3829                                                 break;
    3830                                         case 'update_available':
    3831                                                 if ( $status['url'] )
    3832                                                         $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
    3833                                                 break;
    3834                                         case 'latest_installed':
    3835                                         case 'newer_installed':
    3836                                                 $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . __( 'Installed' ) . '</span>';
    3837                                                 break;
    3838                                 }
    3839                         }
    3840 
    3841                         $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
    3842                 ?>
    3843                 <tr>
    3844                         <td class="name"><strong><?php echo $title; ?></strong>
    3845                                 <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
    3846                         </td>
    3847                         <td class="vers"><?php echo $version; ?></td>
    3848                         <td class="vers">
    3849                                 <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'] ) ) ?>">
    3850                                         <div class="star star-rating" style="width: <?php echo esc_attr( $plugin['rating'] ) ?>px"></div>
    3851                                         <div class="star star5"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '5 stars' ) ?>" /></div>
    3852                                         <div class="star star4"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '4 stars' ) ?>" /></div>
    3853                                         <div class="star star3"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '3 stars' ) ?>" /></div>
    3854                                         <div class="star star2"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '2 stars' ) ?>" /></div>
    3855                                         <div class="star star1"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '1 star' ) ?>" /></div>
    3856                                 </div>
    3857                         </td>
    3858                         <td class="desc"><?php echo $description, $author; ?></td>
    3859                 </tr>
    3860                 <?php
    3861                 }
    3862         }
    3863 }
    3864 
    3865 class WP_Themes_Table extends WP_List_Table {
    3866 
    3867         var $search = array();
    3868         var $features = array();
    3869 
    3870         function WP_Themes_Table() {
    3871                 parent::__construct( array(
    3872                         'screen' => 'themes',
    3873                 ) );
    3874         }
    3875 
    3876         function check_permissions() {
    3877                 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
    3878                         wp_die( __( 'Cheatin&#8217; uh?' ) );
    3879         }
    3880 
    3881         function prepare_items() {
    3882                 global $ct;
    3883 
    3884                 $ct = current_theme_info();
    3885 
    3886                 $themes = get_allowed_themes();
    3887 
    3888                 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
    3889 
    3890                 if ( '' !== $search ) {
    3891                         $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
    3892                         $this->search = array_unique( $this->search );
    3893                 }
    3894 
    3895                 if ( !empty( $_REQUEST['features'] ) ) {
    3896                         $this->features = $_REQUEST['features'];
    3897                         $this->features = array_map( 'trim', $this->features );
    3898                         $this->features = array_map( 'sanitize_title_with_dashes', $this->features );
    3899                         $this->features = array_unique( $this->features );
    3900                 }
    3901 
    3902                 if ( $this->search || $this->features ) {
    3903                         foreach ( $themes as $key => $theme ) {
    3904                                 if ( !$this->search_theme( $theme ) )
    3905                                         unset( $themes[ $key ] );
    3906                         }
    3907                 }
    3908 
    3909                 unset( $themes[$ct->name] );
    3910                 uksort( $themes, "strnatcasecmp" );
    3911 
    3912                 $per_page = 15;
    3913                 $page = $this->get_pagenum();
    3914 
    3915                 $start = ( $page - 1 ) * $per_page;
    3916 
    3917                 $this->items = array_slice( $themes, $start, $per_page );
    3918 
    3919                 $this->set_pagination_args( array(
    3920                         'query_var' => 'pagenum',
    3921                         'total_items' => count( $themes ),
    3922                         'per_page' => $per_page,
    3923                 ) );
    3924         }
    3925 
    3926         function no_items() {
    3927                 if ( current_user_can( 'install_themes' ) )
    3928                         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' );
    3929                 else
    3930                         printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
    3931         }
    3932 
    3933         function display_table() {
    3934 ?>
    3935                 <div class="tablenav">
    3936                         <?php $this->pagination( 'top' ); ?>
    3937                         <br class="clear" />
    3938                 </div>
    3939 
    3940                 <table id="availablethemes" cellspacing="0" cellpadding="0">
    3941                         <tbody id="the-list" class="list:themes">
    3942                                 <?php $this->display_rows(); ?>
    3943                         </tbody>
    3944                 </table>
    3945 
    3946                 <div class="tablenav">
    3947                         <?php $this->pagination( 'bottom' ); ?>
    3948                         <br class="clear" />
    3949                 </div>
    3950 <?php
    3951         }
    3952 
    3953         function get_columns() {
    3954                 return array();
    3955         }
    3956 
    3957         function display_rows() {
    3958                 $themes = $this->items;
    3959                 $theme_names = array_keys( $themes );
    3960                 natcasesort( $theme_names );
    3961 
    3962                 $table = array();
    3963                 $rows = ceil( count( $theme_names ) / 3 );
    3964                 for ( $row = 1; $row <= $rows; $row++ )
    3965                         for ( $col = 1; $col <= 3; $col++ )
    3966                                 $table[$row][$col] = array_shift( $theme_names );
    3967 
    3968                 foreach ( $table as $row => $cols ) {
    3969 ?>
    3970 <tr>
    3971 <?php
    3972 foreach ( $cols as $col => $theme_name ) {
    3973         $class = array( 'available-theme' );
    3974         if ( $row == 1 ) $class[] = 'top';
    3975         if ( $col == 1 ) $class[] = 'left';
    3976         if ( $row == $rows ) $class[] = 'bottom';
    3977         if ( $col == 3 ) $class[] = 'right';
    3978 ?>
    3979         <td class="<?php echo join( ' ', $class ); ?>">
    3980 <?php if ( !empty( $theme_name ) ) :
    3981         $template = $themes[$theme_name]['Template'];
    3982         $stylesheet = $themes[$theme_name]['Stylesheet'];
    3983         $title = $themes[$theme_name]['Title'];
    3984         $version = $themes[$theme_name]['Version'];
    3985         $description = $themes[$theme_name]['Description'];
    3986         $author = $themes[$theme_name]['Author'];
    3987         $screenshot = $themes[$theme_name]['Screenshot'];
    3988         $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
    3989         $template_dir = $themes[$theme_name]['Template Dir'];
    3990         $parent_theme = $themes[$theme_name]['Parent Theme'];
    3991         $theme_root = $themes[$theme_name]['Theme Root'];
    3992         $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
    3993         $preview_link = esc_url( get_option( 'home' ) . '/' );
    3994         if ( is_ssl() )
    3995                 $preview_link = str_replace( 'http://', 'https://', $preview_link );
    3996         $preview_link = htmlspecialchars( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
    3997         $preview_text = esc_attr( sprintf( __( 'Preview of &#8220;%s&#8221;' ), $title ) );
    3998         $tags = $themes[$theme_name]['Tags'];
    3999         $thickbox_class = 'thickbox thickbox-preview';
    4000         $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=".urlencode( $template )."&amp;stylesheet=".urlencode( $stylesheet ), 'switch-theme_' . $template );
    4001         $activate_text = esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) );
    4002         $actions = array();
    4003         $actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>';
    4004         $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>';
    4005         if ( current_user_can( 'delete_themes' ) )
    4006                 $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>';
    4007         $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] );
    4008 
    4009         $actions = implode ( ' | ', $actions );
    4010 ?>
    4011                 <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
    4012 <?php if ( $screenshot ) : ?>
    4013                         <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
    4014 <?php endif; ?>
    4015                 </a>
    4016 <h3><?php
    4017         /* translators: 1: theme title, 2: theme version, 3: theme author */
    4018         printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
    4019 <p class="description"><?php echo $description; ?></p>
    4020 <span class='action-links'><?php echo $actions ?></span>
    4021         <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) {
    4022         /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
    4023         <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>
    4024 <?php } else { ?>
    4025         <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>
    4026 <?php } ?>
    4027 <?php if ( $tags ) : ?>
    4028 <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p>
    4029 <?php endif; ?>
    4030                 <?php theme_update_available( $themes[$theme_name] ); ?>
    4031 <?php endif; // end if not empty theme_name ?>
    4032         </td>
    4033 <?php } // end foreach $cols ?>
    4034 </tr>
    4035 <?php } // end foreach $table
    4036         }
    4037 
    4038         function search_theme( $theme ) {
    4039                 $matched = 0;
    4040 
    4041                 // Match all phrases
    4042                 if ( count( $this->search ) > 0 ) {
    4043                         foreach ( $this->search as $word ) {
    4044                                 $matched = 0;
    4045 
    4046                                 // In a tag?
    4047                                 if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
    4048                                         $matched = 1;
    4049 
    4050                                 // In one of the fields?
    4051                                 foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
    4052                                         if ( stripos( $theme[$field], $word ) !== false )
    4053                                                 $matched++;
    4054                                 }
    4055 
    4056                                 if ( $matched == 0 )
    4057                                         return false;
    4058                         }
    4059                 }
    4060 
    4061                 // Now search the features
    4062                 if ( count( $this->features ) > 0 ) {
    4063                         foreach ( $this->features as $word ) {
    4064                                 // In a tag?
    4065                                 if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
    4066                                         return false;
    4067                         }
    4068                 }
    4069 
    4070                 // Only get here if each word exists in the tags or one of the fields
    4071                 return true;
    4072         }
    4073 }
    4074 
    4075 class WP_Theme_Install_Table extends WP_List_Table {
    4076 
    4077         function WP_Theme_Install_Table() {
    4078                 parent::WP_List_Table( array(
    4079                         'screen' => 'theme-install',
    4080                 ) );
    4081         }
    4082 
    4083         function check_permissions() {
    4084                 if ( ! current_user_can('install_themes') )
    4085                         wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
    4086         }
    4087 
    4088         function prepare_items() {
    4089                 include( ABSPATH . 'wp-admin/includes/theme-install.php' );
    4090 
    4091                 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults;
    4092 
    4093                 wp_reset_vars( array( 'tab' ) );
    4094 
    4095                 $paged = $this->get_pagenum();
    4096 
    4097                 $per_page = 30;
    4098 
    4099                 // These are the tabs which are shown on the page,
    4100                 $tabs = array();
    4101                 $tabs['dashboard'] = __( 'Search' );
    4102                 if ( 'search' == $tab )
    4103                         $tabs['search'] = __( 'Search Results' );
    4104                 $tabs['upload'] = __( 'Upload' );
    4105                 $tabs['featured'] = _x( 'Featured','Theme Installer' );
    4106                 //$tabs['popular']  = _x( 'Popular','Theme Installer' );
    4107                 $tabs['new']      = _x( 'Newest','Theme Installer' );
    4108                 $tabs['updated']  = _x( 'Recently Updated','Theme Installer' );
    4109 
    4110                 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
    4111 
    4112                 $tabs = apply_filters( 'install_themes_tabs', $tabs );
    4113                 $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
    4114 
    4115                 // If a non-valid menu tab has been selected, And its not a non-menu action.
    4116                 if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
    4117                         $tab = key( $tabs );
    4118 
    4119                 $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
    4120 
    4121                 switch ( $tab ) {
    4122                         case 'search':
    4123                                 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
    4124                                 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    4125 
    4126                                 switch ( $type ) {
    4127                                         case 'tag':
    4128                                                 $terms = explode( ',', $term );
    4129                                                 $terms = array_map( 'trim', $terms );
    4130                                                 $terms = array_map( 'sanitize_title_with_dashes', $terms );
    4131                                                 $args['tag'] = $terms;
    4132                                                 break;
    4133                                         case 'term':
    4134                                                 $args['search'] = $term;
    4135                                                 break;
    4136                                         case 'author':
    4137                                                 $args['author'] = $term;
    4138                                                 break;
    4139                                 }
    4140 
    4141                                 if ( !empty( $_POST['features'] ) ) {
    4142                                         $terms = $_POST['features'];
    4143                                         $terms = array_map( 'trim', $terms );
    4144                                         $terms = array_map( 'sanitize_title_with_dashes', $terms );
    4145                                         $args['tag'] = $terms;
    4146                                         $_REQUEST['s'] = implode( ',', $terms );
    4147                                         $_REQUEST['type'] = 'tag';
    4148                                 }
    4149 
    4150                                 add_action( 'install_themes_table_header', 'install_theme_search_form' );
    4151                                 break;
    4152 
    4153                         case 'featured':
    4154                         //case 'popular':
    4155                         case 'new':
    4156                         case 'updated':
    4157                                 $args['browse'] = $tab;
    4158                                 break;
    4159 
    4160                         default:
    4161                                 $args = false;
    4162                 }
    4163 
    4164                 if ( !$args )
    4165                         return;
    4166 
    4167                 $api = themes_api( 'query_themes', $args );
    4168 
    4169                 if ( is_wp_error( $api ) )
    4170                         wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
    4171 
    4172                 $this->items = $api->themes;
    4173 
    4174                 $this->set_pagination_args( array(
    4175                         'total_items' => $api->info['results'],
    4176                         'per_page' => $per_page,
    4177                 ) );
    4178         }
    4179 
    4180         function no_items() {
    4181                 _e( 'No themes match your request.' );
    4182         }
    4183 
    4184         function get_views() {
    4185                 global $tabs, $tab;
    4186 
    4187                 $display_tabs = array();
    4188                 foreach ( (array) $tabs as $action => $text ) {
    4189                         $class = ( $action == $tab ) ? ' class="current"' : '';
    4190                         $href = self_admin_url('theme-install.php?tab=' . $action);
    4191                         $display_tabs[$action] = "<a href='$href'$class>$text</a>";
    4192                 }
    4193 
    4194                 return $display_tabs;
    4195         }
    4196 
    4197         function get_columns() {
    4198                 return array();
    4199         }
    4200 
    4201         function display_table() {
    4202 ?>
    4203                 <div class="tablenav">
    4204                         <div class="alignleft actions">
    4205                                 <?php do_action( 'install_themes_table_header' ); ?>
    4206                         </div>
    4207                         <?php $this->pagination( 'top' ); ?>
    4208                         <br class="clear" />
    4209                 </div>
    4210 
    4211                 <table id="availablethemes" cellspacing="0" cellpadding="0">
    4212                         <tbody id="the-list" class="list:themes">
    4213                                 <?php $this->display_rows(); ?>
    4214                         </tbody>
    4215                 </table>
    4216 
    4217                 <div class="tablenav">
    4218                         <?php $this->pagination( 'bottom' ); ?>
    4219                         <br class="clear" />
    4220                 </div>
    4221 <?php
    4222         }
    4223 
    4224         function display_rows() {
    4225                 $themes = $this->items;
    4226 
    4227                 $rows = ceil( count( $themes ) / 3 );
    4228                 $table = array();
    4229                 $theme_keys = array_keys( $themes );
    4230                 for ( $row = 1; $row <= $rows; $row++ )
    4231                         for ( $col = 1; $col <= 3; $col++ )
    4232                                 $table[$row][$col] = array_shift( $theme_keys );
    4233 
    4234                 foreach ( $table as $row => $cols ) {
    4235                         echo "\t<tr>\n";
    4236                         foreach ( $cols as $col => $theme_index ) {
    4237                                 $class = array( 'available-theme' );
    4238                                 if ( $row == 1 ) $class[] = 'top';
    4239                                 if ( $col == 1 ) $class[] = 'left';
    4240                                 if ( $row == $rows ) $class[] = 'bottom';
    4241                                 if ( $col == 3 ) $class[] = 'right';
    4242                                 ?>
    4243                                 <td class="<?php echo join( ' ', $class ); ?>"><?php
    4244                                         if ( isset( $themes[$theme_index] ) )
    4245                                                 display_theme( $themes[$theme_index] );
    4246                                 ?></td>
    4247                         <?php } // end foreach $cols
    4248                         echo "\t</tr>\n";
    4249                 } // end foreach $table
    4250         }
    4251 }
    4252 
Note: See TracChangeset for help on using the changeset viewer.