| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * List table classes 5 * 6 * Each list-type admin screen has a class that handles the rendering of the list table. 7 * 8 * @package WordPress 9 * @subpackage Administration 10 */ 11 12 class WP_Media_Table extends WP_List_Table { 13 14 function WP_Media_Table() { 15 global $detached; 16 17 $detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] ); 18 19 parent::WP_List_Table( array( 20 'screen' => $detached ? 'upload-detached' : 'upload', 21 'plural' => 'media' 22 ) ); 23 } 24 25 function check_permissions() { 26 if ( !current_user_can('upload_files') ) 27 wp_die( __( 'You do not have permission to upload files.' ) ); 28 } 29 30 function prepare_items() { 31 global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types; 32 33 $q = $_REQUEST; 34 35 if ( !empty( $lost ) ) 36 $q['post__in'] = implode( ',', $lost ); 37 38 list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q ); 39 40 $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status']; 41 42 $this->set_pagination_args( array( 43 'total_items' => $wp_query->found_posts, 44 'total_pages' => $wp_query->max_num_pages, 45 'per_page' => $wp_query->query_vars['posts_per_page'], 46 ) ); 47 } 48 49 function get_views() { 50 global $wpdb, $post_mime_types, $detached, $avail_post_mime_types; 51 52 $type_links = array(); 53 $_num_posts = (array) wp_count_attachments(); 54 $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; 55 if ( !isset( $total_orphans ) ) 56 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); 57 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 58 foreach ( $matches as $type => $reals ) 59 foreach ( $reals as $real ) 60 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; 61 62 $class = ( empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ) ? ' class="current"' : ''; 63 $type_links['all'] = "<li><a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>'; 64 foreach ( $post_mime_types as $mime_type => $label ) { 65 $class = ''; 66 67 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) 68 continue; 69 70 if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) 71 $class = ' class="current"'; 72 if ( !empty( $num_posts[$mime_type] ) ) 73 $type_links[$mime_type] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; 74 } 75 $type_links['detached'] = '<li><a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>'; 76 77 if ( !empty($_num_posts['trash']) ) 78 $type_links['trash'] = '<li><a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>'; 79 80 return $type_links; 81 } 82 83 function get_bulk_actions() { 84 global $detached; 85 86 $actions = array(); 87 $actions['delete'] = __( 'Delete Permanently' ); 88 if ( $detached ) 89 $actions['attach'] = __( 'Attach to a post' ); 90 91 return $actions; 92 } 93 94 function extra_tablenav( $which ) { 95 global $post_type, $detached; 96 ?> 97 <div class="alignleft actions"> 98 <?php 99 if ( 'top' == $which && !is_singular() && !$detached && !$this->is_trash ) { 100 $this->months_dropdown( $post_type ); 101 102 do_action( 'restrict_manage_posts' ); 103 ?> 104 <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" /> 105 <?php 106 } 107 108 if ( $detached ) { ?> 109 <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e( 'Scan for lost attachments' ); ?>" class="button-secondary" /> 110 <?php } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { ?> 111 <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e( 'Empty Trash' ); ?>" class="button-secondary apply" /> 112 <?php } ?> 113 </div> 114 <?php 115 } 116 117 function current_action() { 118 if ( isset( $_REQUEST['find_detached'] ) ) 119 return 'find_detached'; 120 121 if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) 122 return 'attach'; 123 124 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) 125 return 'delete_all'; 126 127 return parent::current_action(); 128 } 129 130 function has_items() { 131 return have_posts(); 132 } 133 134 function no_items() { 135 _e( 'No media attachments found.' ); 136 } 137 138 function get_columns() { 139 $posts_columns = array(); 140 $posts_columns['cb'] = '<input type="checkbox" />'; 141 $posts_columns['icon'] = ''; 142 /* translators: column name */ 143 $posts_columns['title'] = _x( 'File', 'column name' ); 144 $posts_columns['author'] = __( 'Author' ); 145 //$posts_columns['tags'] = _x( 'Tags', 'column name' ); 146 /* translators: column name */ 147 if ( 'upload' == $this->_screen->id ) { 148 $posts_columns['parent'] = _x( 'Attached to', 'column name' ); 149 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>'; 150 } 151 /* translators: column name */ 152 $posts_columns['date'] = _x( 'Date', 'column name' ); 153 $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, 'upload' != $this->_screen->id ); 154 155 return $posts_columns; 156 } 157 158 function get_sortable_columns() { 159 return array( 160 'title' => 'title', 161 'author' => 'author', 162 'parent' => 'parent', 163 'comments' => 'comment_count', 164 'date' => 'date', 165 ); 166 } 167 168 function display_rows() { 169 global $detached, $post, $id; 170 171 if ( $detached ) { 172 $this->display_orphans(); 173 return; 174 } 175 176 add_filter( 'the_title','esc_html' ); 177 $alt = ''; 178 179 while ( have_posts() ) : the_post(); 180 181 if ( $this->is_trash && $post->post_status != 'trash' 182 || !$this->is_trash && $post->post_status == 'trash' ) 183 continue; 184 185 $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; 186 $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; 187 $att_title = _draft_or_post_title(); 188 ?> 189 <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top"> 190 <?php 191 192 list( $columns, $hidden ) = $this->get_column_info(); 193 foreach ( $columns as $column_name => $column_display_name ) { 194 $class = "class='$column_name column-$column_name'"; 195 196 $style = ''; 197 if ( in_array( $column_name, $hidden ) ) 198 $style = ' style="display:none;"'; 199 200 $attributes = $class . $style; 201 202 switch ( $column_name ) { 203 204 case 'cb': 205 ?> 206 <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /><?php } ?></th> 207 <?php 208 break; 209 210 case 'icon': 211 $attributes = 'class="column-icon media-icon"' . $style; 212 ?> 213 <td <?php echo $attributes ?>><?php 214 if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { 215 if ( $this->is_trash ) { 216 echo $thumb; 217 } else { 218 ?> 219 <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"> 220 <?php echo $thumb; ?> 221 </a> 222 223 <?php } 224 } 225 ?> 226 </td> 227 <?php 228 break; 229 230 case 'title': 231 ?> 232 <td <?php echo $attributes ?>><strong><?php if ( $this->is_trash ) echo $att_title; else { ?><a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"><?php echo $att_title; ?></a><?php } ?></strong> 233 <p> 234 <?php 235 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) 236 echo esc_html( strtoupper( $matches[1] ) ); 237 else 238 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) ); 239 ?> 240 </p> 241 <?php 242 $actions = array(); 243 if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) 244 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; 245 if ( current_user_can( 'delete_post', $post->ID ) ) { 246 if ( $this->is_trash ) 247 $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-attachment_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>"; 248 elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) 249 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; 250 if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) { 251 $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; 252 $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; 253 } 254 } 255 if ( !$this->is_trash ) { 256 $title =_draft_or_post_title( $post->post_parent ); 257 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; 258 } 259 $actions = apply_filters( 'media_row_actions', $actions, $post ); 260 echo $this->row_actions( $actions ); 261 ?> 262 </td> 263 <?php 264 break; 265 266 case 'author': 267 ?> 268 <td <?php echo $attributes ?>><?php the_author() ?></td> 269 <?php 270 break; 271 272 case 'tags': 273 ?> 274 <td <?php echo $attributes ?>><?php 275 $tags = get_the_tags(); 276 if ( !empty( $tags ) ) { 277 $out = array(); 278 foreach ( $tags as $c ) 279 $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>"; 280 echo join( ', ', $out ); 281 } else { 282 _e( 'No Tags' ); 283 } 284 ?> 285 </td> 286 <?php 287 break; 288 289 case 'desc': 290 ?> 291 <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td> 292 <?php 293 break; 294 295 case 'date': 296 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) { 297 $t_time = $h_time = __( 'Unpublished' ); 298 } else { 299 $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); 300 $m_time = $post->post_date; 301 $time = get_post_time( 'G', true, $post, false ); 302 if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) { 303 if ( $t_diff < 0 ) 304 $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); 305 else 306 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 307 } else { 308 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); 309 } 310 } 311 ?> 312 <td <?php echo $attributes ?>><?php echo $h_time ?></td> 313 <?php 314 break; 315 316 case 'parent': 317 if ( $post->post_parent > 0 ) { 318 if ( get_post( $post->post_parent ) ) { 319 $title =_draft_or_post_title( $post->post_parent ); 320 } 321 ?> 322 <td <?php echo $attributes ?>> 323 <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, 324 <?php echo get_the_time( __( 'Y/m/d' ) ); ?> 325 </td> 326 <?php 327 } else { 328 ?> 329 <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br /> 330 <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' );return false;" href="#the-list"><?php _e( 'Attach' ); ?></a></td> 331 <?php 332 } 333 break; 334 335 case 'comments': 336 $attributes = 'class="comments column-comments num"' . $style; 337 ?> 338 <td <?php echo $attributes ?>> 339 <div class="post-com-count-wrapper"> 340 <?php 341 $pending_comments = get_pending_comments_num( $post->ID ); 342 343 $this->comments_bubble( $post->ID, $pending_comments ); 344 ?> 345 </div> 346 </td> 347 <?php 348 break; 349 350 case 'actions': 351 ?> 352 <td <?php echo $attributes ?>> 353 <a href="media.php?action=edit&attachment_id=<?php the_ID(); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"><?php _e( 'Edit' ); ?></a> | 354 <a href="<?php the_permalink(); ?>"><?php _e( 'Get permalink' ); ?></a> 355 </td> 356 <?php 357 break; 358 359 default: 360 ?> 361 <td <?php echo $attributes ?>> 362 <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?> 363 </td> 364 <?php 365 break; 366 } 367 } 368 ?> 369 </tr> 370 <?php endwhile; 371 } 372 373 function display_orphans() { 374 global $post; 375 376 $class = ''; 377 378 while ( have_posts() ) : the_post(); 379 380 $class = ( 'alternate' == $class ) ? '' : 'alternate'; 381 $att_title = esc_html( _draft_or_post_title( $post->ID ) ); 382 383 $edit_link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ) . '">%s</a>'; 384 ?> 385 <tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top"> 386 <th scope="row" class="check-column"> 387 <?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?> 388 <input type="checkbox" name="media[]" value="<?php echo esc_attr( $post->ID ); ?>" /> 389 <?php } ?> 390 </th> 391 392 <td class="media-icon"> 393 <?php if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { 394 printf( $edit_link, $thumb ); 395 } ?> 396 </td> 397 398 <td class="media column-media"> 399 <strong><?php printf( $edit_link, $att_title ); ?></strong><br /> 400 <?php 401 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) 402 echo esc_html( strtoupper( $matches[1] ) ); 403 else 404 echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) ); 405 ?> 406 <?php 407 $actions = array(); 408 if ( current_user_can( 'edit_post', $post->ID ) ) 409 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; 410 if ( current_user_can( 'delete_post', $post->ID ) ) 411 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { 412 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; 413 } else { 414 $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; 415 $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; 416 } 417 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; 418 if ( current_user_can( 'edit_post', $post->ID ) ) 419 $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>'; 420 $actions = apply_filters( 'media_row_actions', $actions, $post ); 421 422 echo $this->row_actions( $actions ); 423 ?> 424 </td> 425 <td class="author column-author"> 426 <?php $author = get_userdata( $post->post_author ); echo $author->display_name; ?> 427 </td> 428 <?php 429 if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) { 430 $t_time = $h_time = __( 'Unpublished' ); 431 } else { 432 $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); 433 $m_time = $post->post_date; 434 $time = get_post_time( 'G', true ); 435 if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) { 436 if ( $t_diff < 0 ) 437 $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); 438 else 439 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 440 } else { 441 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); 442 } 443 } 444 ?> 445 <td class="date column-date"><?php echo $h_time ?></td> 446 </tr> 447 <?php 448 endwhile; 449 } 450 } 451 452 class WP_Terms_Table extends WP_List_Table { 453 454 var $callback_args; 455 456 function WP_Terms_Table() { 457 global $post_type, $taxonomy, $tax, $current_screen; 458 459 wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) ); 460 461 if ( empty( $taxonomy ) ) 462 $taxonomy = 'post_tag'; 463 464 if ( !taxonomy_exists( $taxonomy ) ) 465 wp_die( __( 'Invalid taxonomy' ) ); 466 467 $tax = get_taxonomy( $taxonomy ); 468 469 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) ) 470 $post_type = 'post'; 471 472 if ( !isset( $current_screen ) ) 473 set_current_screen( 'edit-' . $taxonomy ); 474 475 parent::WP_List_Table( array( 476 'screen' => $current_screen, 477 'plural' => 'tags', 478 'singular' => 'tag', 479 ) ); 480 } 481 482 function check_permissions( $type = 'manage' ) { 483 global $tax; 484 485 $cap = 'manage' == $type ? $tax->cap->manage_terms : $tax->cap->edit_terms; 486 487 if ( !current_user_can( $tax->cap->manage_terms ) ) 488 wp_die( __( 'Cheatin’ uh?' ) ); 489 } 490 491 function prepare_items() { 492 global $taxonomy; 493 494 $tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' ); 495 496 if ( 'post_tag' == $taxonomy ) { 497 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); 498 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter 499 } elseif ( 'category' == $taxonomy ) { 500 $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter 501 } 502 503 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; 504 505 $args = array( 506 'search' => $search, 507 'page' => $this->get_pagenum(), 508 'number' => $tags_per_page, 509 ); 510 511 if ( !empty( $_REQUEST['orderby'] ) ) 512 $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) ); 513 514 if ( !empty( $_REQUEST['order'] ) ) 515 $args['order'] = trim( stripslashes( $_REQUEST['order'] ) ); 516 517 $this->callback_args = $args; 518 519 $this->set_pagination_args( array( 520 'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ), 521 'per_page' => $tags_per_page, 522 ) ); 523 } 524 525 function get_bulk_actions() { 526 $actions = array(); 527 $actions['delete'] = __( 'Delete' ); 528 529 return $actions; 530 } 531 532 function current_action() { 533 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) 534 return 'bulk-delete'; 535 536 return parent::current_action(); 537 } 538 539 function get_columns() { 540 global $taxonomy; 541 542 $columns = array( 543 'cb' => '<input type="checkbox" />', 544 'name' => __( 'Name' ), 545 'description' => __( 'Description' ), 546 'slug' => __( 'Slug' ), 547 ); 548 549 if ( 'link_category' == $taxonomy ) 550 $columns['links'] = __( 'Links' ); 551 else 552 $columns['posts'] = __( 'Posts' ); 553 554 return $columns; 555 } 556 557 function get_sortable_columns() { 558 return array( 559 'name' => 'name', 560 'description' => 'description', 561 'slug' => 'slug', 562 'posts' => 'count', 563 'links' => 'count' 564 ); 565 } 566 567 function display_rows() { 568 global $taxonomy; 569 570 $args = wp_parse_args( $this->callback_args, array( 571 'page' => 1, 572 'number' => 20, 573 'search' => '', 574 'hide_empty' => 0 575 ) ); 576 577 extract( $args, EXTR_SKIP ); 578 579 $args['offset'] = $offset = ( $page - 1 ) * $number; 580 581 // convert it to table rows 582 $out = ''; 583 $count = 0; 584 if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) { 585 // We'll need the full set of terms then. 586 $args['number'] = $args['offset'] = 0; 587 588 $terms = get_terms( $taxonomy, $args ); 589 if ( !empty( $search ) ) // Ignore children on searches. 590 $children = array(); 591 else 592 $children = _get_term_hierarchy( $taxonomy ); 593 594 // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake 595 $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count ); 596 } else { 597 $terms = get_terms( $taxonomy, $args ); 598 foreach ( $terms as $term ) 599 $out .= $this->single_row( $term, 0, $taxonomy ); 600 $count = $number; // Only displaying a single page. 601 } 602 603 echo $out; 604 } 605 606 function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) { 607 608 $end = $start + $per_page; 609 610 $output = ''; 611 foreach ( $terms as $key => $term ) { 612 613 if ( $count >= $end ) 614 break; 615 616 if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) 617 continue; 618 619 // If the page starts in a subtree, print the parents. 620 if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) { 621 $my_parents = $parent_ids = array(); 622 $p = $term->parent; 623 while ( $p ) { 624 $my_parent = get_term( $p, $taxonomy ); 625 $my_parents[] = $my_parent; 626 $p = $my_parent->parent; 627 if ( in_array( $p, $parent_ids ) ) // Prevent parent loops. 628 break; 629 $parent_ids[] = $p; 630 } 631 unset( $parent_ids ); 632 633 $num_parents = count( $my_parents ); 634 while ( $my_parent = array_pop( $my_parents ) ) { 635 $output .= "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy ); 636 $num_parents--; 637 } 638 } 639 640 if ( $count >= $start ) 641 $output .= "\t" . $this->single_row( $term, $level, $taxonomy ); 642 643 ++$count; 644 645 unset( $terms[$key] ); 646 647 if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) ) 648 $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 ); 649 } 650 651 return $output; 652 } 653 654 function single_row( $tag, $level = 0 ) { 655 static $row_class = ''; 656 $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); 657 658 $this->level = $level; 659 660 echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>'; 661 echo $this->single_row_columns( $tag ); 662 echo '</tr>'; 663 } 664 665 function column_cb( $tag ) { 666 global $taxonomy, $tax; 667 668 $default_term = get_option( 'default_' . $taxonomy ); 669 670 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) 671 return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />'; 672 else 673 return ' '; 674 } 675 676 function column_name( $tag ) { 677 global $taxonomy, $tax, $post_type; 678 679 $default_term = get_option( 'default_' . $taxonomy ); 680 681 $pad = str_repeat( '— ', max( 0, $this->level ) ); 682 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); 683 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); 684 $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $post_type ); 685 686 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; 687 688 $actions = array(); 689 if ( current_user_can( $tax->cap->edit_terms ) ) { 690 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 691 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick Edit' ) . '</a>'; 692 } 693 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) 694 $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>"; 695 696 $actions = apply_filters( 'tag_row_actions', $actions, $tag ); 697 $actions = apply_filters( "$taxonomy}_row_actions", $actions, $tag ); 698 699 $out .= $this->row_actions( $actions ); 700 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; 701 $out .= '<div class="name">' . $qe_data->name . '</div>'; 702 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>'; 703 $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>'; 704 705 return $out; 706 } 707 708 function column_description( $tag ) { 709 return $tag->description; 710 } 711 712 function column_slug( $tag ) { 713 return apply_filters( 'editable_slug', $tag->slug ); 714 } 715 716 function column_posts( $tag ) { 717 global $taxonomy, $post_type; 718 719 $count = number_format_i18n( $tag->count ); 720 721 if ( 'post_tag' == $taxonomy ) { 722 $tagsel = 'tag'; 723 } elseif ( 'category' == $taxonomy ) { 724 $tagsel = 'category_name'; 725 } elseif ( ! empty( $tax->query_var ) ) { 726 $tagsel = $tax->query_var; 727 } else { 728 $tagsel = $taxonomy; 729 } 730 731 return "<a href='edit.php?$tagsel=$tag->slug&post_type=$post_type'>$count</a>"; 732 } 733 734 function column_links( $tag ) { 735 $count = number_format_i18n( $tag->count ); 736 return $count; 737 } 738 739 function column_default( $tag, $column_name ) { 740 global $taxonomy; 741 742 return apply_filters( "manage_$taxonomy}_custom_column", '', $column_name, $tag->term_id ); 743 $out .= "</td>"; 744 } 745 746 /** 747 * Outputs the hidden row displayed when inline editing 748 * 749 * @since 3.1.0 750 */ 751 function inline_edit() { 752 global $tax; 753 754 if ( ! current_user_can( $tax->cap->edit_terms ) ) 755 return; 756 757 list( $columns, $hidden ) = $this->get_column_info(); 758 759 $col_count = count( $columns ) - count( $hidden ); 760 ?> 761 762 <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> 763 <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>"> 764 765 <fieldset><div class="inline-edit-col"> 766 <h4><?php _e( 'Quick Edit' ); ?></h4> 767 768 <label> 769 <span class="title"><?php _e( 'Name' ); ?></span> 770 <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span> 771 </label> 772 <?php if ( !global_terms_enabled() ) { ?> 773 <label> 774 <span class="title"><?php _e( 'Slug' ); ?></span> 775 <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span> 776 </label> 777 <?php } ?> 778 779 </div></fieldset> 780 <?php 781 782 $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true ); 783 784 foreach ( $columns as $column_name => $column_display_name ) { 785 if ( isset( $core_columns[$column_name] ) ) 786 continue; 787 do_action( 'quick_edit_custom_box', $column_name, $type, $tax->taxonomy ); 788 } 789 790 ?> 791 792 <p class="inline-edit-save submit"> 793 <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a> 794 <?php $update_text = $tax->labels->update_item; ?> 795 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> 796 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 797 <span class="error" style="display:none;"></span> 798 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> 799 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" /> 800 <br class="clear" /> 801 </p> 802 </td></tr> 803 </tbody></table></form> 804 <?php 805 } 806 } 807 808 class WP_Users_Table extends WP_List_Table { 809 810 function WP_Users_Table() { 811 parent::WP_List_Table( array( 812 'screen' => 'users', 813 'plural' => 'users' 814 ) ); 815 } 816 817 function check_permissions() { 818 if ( !current_user_can('list_users') ) 819 wp_die(__('Cheatin’ uh?')); 820 } 821 822 function prepare_items() { 823 global $role, $usersearch; 824 825 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 826 827 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; 828 829 $users_per_page = $this->get_items_per_page( 'users_per_page' ); 830 831 $paged = $this->get_pagenum(); 832 833 $args = array( 834 'number' => $users_per_page, 835 'offset' => ( $paged-1 ) * $users_per_page, 836 'role' => $role, 837 'search' => $usersearch 838 ); 839 840 if ( isset( $_REQUEST['orderby'] ) ) 841 $args['orderby'] = $_REQUEST['orderby']; 842 843 if ( isset( $_REQUEST['order'] ) ) 844 $args['order'] = $_REQUEST['order']; 845 846 // Query the user IDs for this page 847 $wp_user_search = new WP_User_Query( $args ); 848 849 $this->items = $wp_user_search->get_results(); 850 851 $this->set_pagination_args( array( 852 'total_items' => $wp_user_search->get_total(), 853 'per_page' => $users_per_page, 854 ) ); 855 } 856 857 function no_items() { 858 _e( 'No matching users were found.' ); 859 } 860 861 function get_views() { 862 global $wp_roles, $role; 863 864 $users_of_blog = count_users(); 865 $total_users = $users_of_blog['total_users']; 866 $avail_roles =& $users_of_blog['avail_roles']; 867 unset($users_of_blog); 868 869 $current_role = false; 870 $class = empty($role) ? ' class="current"' : ''; 871 $role_links = array(); 872 $role_links['all'] = "<li><a href='users.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; 873 foreach ( $wp_roles->get_names() as $this_role => $name ) { 874 if ( !isset($avail_roles[$this_role]) ) 875 continue; 876 877 $class = ''; 878 879 if ( $this_role == $role ) { 880 $current_role = $role; 881 $class = ' class="current"'; 882 } 883 884 $name = translate_user_role( $name ); 885 /* translators: User role name with count */ 886 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] ); 887 $role_links[$this_role] = "<li><a href='users.php?role=$this_role'$class>$name</a>"; 888 } 889 890 return $role_links; 891 } 892 893 function get_bulk_actions() { 894 $actions = array(); 895 896 if ( !is_multisite() && current_user_can( 'delete_users' ) ) 897 $actions['delete'] = __( 'Delete' ); 898 else 899 $actions['remove'] = __( 'Remove' ); 900 901 return $actions; 902 } 903 904 function extra_tablenav( $which ) { 905 if ( 'top' != $which ) 906 return; 907 ?> 908 <div class="alignleft actions"> 909 <label class="screen-reader-text" for="new_role"><?php _e( 'Change role to…' ) ?></label> 910 <select name="new_role" id="new_role"> 911 <option value=''><?php _e( 'Change role to…' ) ?></option> 912 <?php wp_dropdown_roles(); ?> 913 </select> 914 <input type="submit" value="<?php esc_attr_e( 'Change' ); ?>" name="changeit" class="button-secondary" /> 915 </div> 916 <?php 917 } 918 919 function current_action() { 920 if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) ) 921 return 'promote'; 922 923 return parent::current_action(); 924 } 925 926 function get_columns() { 927 return array( 928 'cb' => '<input type="checkbox" />', 929 'username' => __( 'Login' ), 930 'name' => __( 'Name' ), 931 'email' => __( 'E-mail' ), 932 'role' => __( 'Role' ), 933 'posts' => __( 'Posts' ) 934 ); 935 } 936 937 function get_sortable_columns() { 938 return array( 939 'username' => 'login', 940 'name' => 'name', 941 'email' => 'email', 942 'posts' => 'post_count', 943 ); 944 } 945 946 function display_rows() { 947 // Query the post counts for this page 948 $post_counts = count_many_users_posts( array_keys( $this->items ) ); 949 950 $style = ''; 951 foreach ( $this->items as $userid => $user_object ) { 952 $role = reset( $user_object->roles ); 953 954 if ( is_multisite() && empty( $role ) ) 955 continue; 956 957 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 958 echo "\n\t", $this->single_row( $user_object, $style, $role, $post_counts[ $userid ] ); 959 } 960 } 961 962 /** 963 * Generate HTML for a single row on the users.php admin panel. 964 * 965 * @since 2.1.0 966 * 967 * @param object $user_object 968 * @param string $style Optional. Attributes added to the TR element. Must be sanitized. 969 * @param string $role Key for the $wp_roles array. 970 * @param int $numposts Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts. 971 * @return string 972 */ 973 function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) { 974 global $wp_roles; 975 976 if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) ) 977 $user_object = new WP_User( (int) $user_object ); 978 $user_object = sanitize_user_object( $user_object, 'display' ); 979 $email = $user_object->user_email; 980 $url = $user_object->user_url; 981 $short_url = str_replace( 'http://', '', $url ); 982 $short_url = str_replace( 'www.', '', $short_url ); 983 if ( '/' == substr( $short_url, -1 ) ) 984 $short_url = substr( $short_url, 0, -1 ); 985 if ( strlen( $short_url ) > 35 ) 986 $short_url = substr( $short_url, 0, 32 ).'...'; 987 $checkbox = ''; 988 // Check if the user for this row is editable 989 if ( current_user_can( 'list_users' ) ) { 990 // Set up the user editing link 991 // TODO: make profile/user-edit determination a separate function 992 if ( get_current_user_id() == $user_object->ID ) { 993 $edit_link = 'profile.php'; 994 } else { 995 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) ); 996 } 997 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />"; 998 999 // Set up the hover actions for this user 1000 $actions = array(); 1001 1002 if ( current_user_can( 'edit_user', $user_object->ID ) ) { 1003 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />"; 1004 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 1005 } else { 1006 $edit = "<strong>$user_object->user_login</strong><br />"; 1007 } 1008 1009 if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) 1010 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>"; 1011 if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) ) 1012 $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=remove&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>"; 1013 $actions = apply_filters( 'user_row_actions', $actions, $user_object ); 1014 $edit .= $this->row_actions( $actions ); 1015 1016 // Set up the checkbox ( because the user is editable, otherwise its empty ) 1017 $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />"; 1018 1019 } else { 1020 $edit = '<strong>' . $user_object->user_login . '</strong>'; 1021 } 1022 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' ); 1023 $r = "<tr id='user-$user_object->ID'$style>"; 1024 $avatar = get_avatar( $user_object->ID, 32 ); 1025 1026 list( $columns, $hidden ) = $this->get_column_info(); 1027 1028 foreach ( $columns as $column_name => $column_display_name ) { 1029 $class = "class=\"$column_name column-$column_name\""; 1030 1031 $style = ''; 1032 if ( in_array( $column_name, $hidden ) ) 1033 $style = ' style="display:none;"'; 1034 1035 $attributes = "$class$style"; 1036 1037 switch ( $column_name ) { 1038 case 'cb': 1039 $r .= "<th scope='row' class='check-column'>$checkbox</th>"; 1040 break; 1041 case 'username': 1042 $r .= "<td $attributes>$avatar $edit</td>"; 1043 break; 1044 case 'name': 1045 $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>"; 1046 break; 1047 case 'email': 1048 $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __( 'E-mail: %s' ), $email ) . "'>$email</a></td>"; 1049 break; 1050 case 'role': 1051 $r .= "<td $attributes>$role_name</td>"; 1052 break; 1053 case 'posts': 1054 $attributes = 'class="posts column-posts num"' . $style; 1055 $r .= "<td $attributes>"; 1056 if ( $numposts > 0 ) { 1057 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>"; 1058 $r .= $numposts; 1059 $r .= '</a>'; 1060 } else { 1061 $r .= 0; 1062 } 1063 $r .= "</td>"; 1064 break; 1065 default: 1066 $r .= "<td $attributes>"; 1067 $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID ); 1068 $r .= "</td>"; 1069 } 1070 } 1071 $r .= '</tr>'; 1072 1073 return $r; 1074 } 1075 } 1076 1077 class WP_Comments_Table extends WP_List_Table { 1078 1079 var $checkbox = true; 1080 var $from_ajax = false; 1081 1082 var $pending_count = array(); 1083 1084 function WP_Comments_Table() { 1085 global $mode; 1086 1087 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'detail' : $_REQUEST['mode']; 1088 1089 if ( get_option('show_avatars') && 'single' != $mode ) 1090 add_filter( 'comment_author', 'floated_admin_avatar' ); 1091 1092 parent::WP_List_Table( array( 1093 'screen' => 'edit-comments', 1094 'plural' => 'comments' 1095 ) ); 1096 } 1097 1098 function check_permissions() { 1099 if ( !current_user_can('edit_posts') ) 1100 wp_die(__('Cheatin’ uh?')); 1101 } 1102 1103 function prepare_items() { 1104 global $post_id, $comment_status, $search; 1105 1106 if ( isset( $_REQUEST['p'] ) ) 1107 $post_id = absint( $_REQUEST['p'] ); 1108 elseif ( isset( $_REQUEST['post'] ) ) 1109 $post_id = absint( $_REQUEST['post'] ); 1110 elseif ( isset( $_REQUEST['post_ID'] ) ) 1111 $post_id = absint( $_REQUEST['post_ID'] ); 1112 else 1113 $post_id = 0; 1114 1115 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; 1116 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) 1117 $comment_status = 'all'; 1118 1119 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; 1120 1121 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; 1122 1123 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; 1124 1125 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' ); 1126 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); 1127 1128 if ( isset( $_POST['number'] ) ) 1129 $number = (int) $_POST['number']; 1130 else 1131 $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra 1132 1133 $page = $this->get_pagenum(); 1134 1135 $start = $offset = ( $page - 1 ) * $comments_per_page; 1136 1137 $status_map = array( 1138 'moderated' => 'hold', 1139 'approved' => 'approve' 1140 ); 1141 1142 $args = array( 1143 'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status, 1144 'search' => $search, 1145 'user_id' => $user_id, 1146 'offset' => $start, 1147 'number' => $number, 1148 'post_id' => $post_id, 1149 'type' => $comment_type, 1150 'orderby' => @$_REQUEST['orderby'], 1151 'order' => @$_REQUEST['order'], 1152 ); 1153 1154 $_comments = get_comments( $args ); 1155 1156 update_comment_cache( $_comments ); 1157 1158 $this->items = array_slice( $_comments, 0, $comments_per_page ); 1159 $this->extra_items = array_slice( $_comments, $comments_per_page ); 1160 1161 $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); 1162 1163 $_comment_post_ids = array(); 1164 foreach ( $_comments as $_c ) { 1165 $_comment_post_ids[] = $_c->comment_post_ID; 1166 } 1167 1168 $this->pending_count = get_pending_comments_num( $_comment_post_ids ); 1169 1170 $this->set_pagination_args( array( 1171 'total_items' => $total_comments, 1172 'per_page' => $comments_per_page, 1173 ) ); 1174 } 1175 1176 function get_views() { 1177 global $post_id, $comment_status; 1178 1179 $status_links = array(); 1180 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); 1181 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 1182 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>") 1183 $stati = array( 1184 'all' => _nx_noop('All', 'All', 'comments'), // singular not used 1185 '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>'), 1186 'approved' => _n_noop('Approved', 'Approved'), // singular not used 1187 '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>'), 1188 '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>') 1189 ); 1190 1191 if ( !EMPTY_TRASH_DAYS ) 1192 unset($stati['trash']); 1193 1194 $link = 'edit-comments.php'; 1195 if ( !empty($comment_type) && 'all' != $comment_type ) 1196 $link = add_query_arg( 'comment_type', $comment_type, $link ); 1197 1198 foreach ( $stati as $status => $label ) { 1199 $class = ( $status == $comment_status ) ? ' class="current"' : ''; 1200 1201 if ( !isset( $num_comments->$status ) ) 1202 $num_comments->$status = 10; 1203 $link = add_query_arg( 'comment_status', $status, $link ); 1204 if ( $post_id ) 1205 $link = add_query_arg( 'p', absint( $post_id ), $link ); 1206 /* 1207 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark 1208 if ( !empty( $_REQUEST['s'] ) ) 1209 $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link ); 1210 */ 1211 $status_links[$status] = "<li class='$status'><a href='$link'$class>" . sprintf( 1212 _n( $label[0], $label[1], $num_comments->$status ), 1213 number_format_i18n( $num_comments->$status ) 1214 ) . '</a>'; 1215 } 1216 1217 $status_links = apply_filters( 'comment_status_links', $status_links ); 1218 return $status_links; 1219 } 1220 1221 function get_bulk_actions() { 1222 global $comment_status; 1223 1224 $actions = array(); 1225 if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) 1226 $actions['unapprove'] = __( 'Unapprove' ); 1227 if ( in_array( $comment_status, array( 'all', 'moderated', 'spam' ) ) ) 1228 $actions['approve'] = __( 'Approve' ); 1229 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved' ) ) ) 1230 $actions['spam'] = _x( 'Mark as Spam', 'comment' ); 1231 1232 if ( 'trash' == $comment_status ) 1233 $actions['untrash'] = __( 'Restore' ); 1234 elseif ( 'spam' == $comment_status ) 1235 $actions['unspam'] = _x( 'Not Spam', 'comment' ); 1236 1237 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS ) 1238 $actions['delete'] = __( 'Delete Permanently' ); 1239 else 1240 $actions['trash'] = __( 'Move to Trash' ); 1241 1242 return $actions; 1243 } 1244 1245 function extra_tablenav( $which ) { 1246 global $comment_status, $comment_type; 1247 ?> 1248 <div class="alignleft actions"> 1249 <?php 1250 if ( 'top' == $which ) { 1251 ?> 1252 <select name="comment_type"> 1253 <option value=""><?php _e( 'Show all comment types' ); ?></option> 1254 <?php 1255 $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 1256 'comment' => __( 'Comments' ), 1257 'pings' => __( 'Pings' ), 1258 ) ); 1259 1260 foreach ( $comment_types as $type => $label ) 1261 echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n"; 1262 ?> 1263 </select> 1264 <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" /> 1265 <?php 1266 } 1267 1268 if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) { 1269 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); 1270 $title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); 1271 ?> 1272 <input type="submit" name="delete_all" id="delete_all" value="<?php echo $title ?>" class="button-secondary apply" /> 1273 <?php 1274 } 1275 ?> 1276 <?php 1277 do_action( 'manage_comments_nav', $comment_status ); 1278 echo '</div>'; 1279 } 1280 1281 function current_action() { 1282 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) 1283 return 'delete_all'; 1284 1285 return parent::current_action(); 1286 } 1287 1288 function get_columns() { 1289 global $mode; 1290 1291 $columns = array(); 1292 1293 if ( $this->checkbox ) 1294 $columns['cb'] = '<input type="checkbox" />'; 1295 1296 $columns['author'] = __( 'Author' ); 1297 $columns['comment'] = _x( 'Comment', 'column name' ); 1298 1299 if ( 'single' !== $mode ) 1300 $columns['response'] = _x( 'Comment', 'column name' ); 1301 1302 return $columns; 1303 } 1304 1305 function get_sortable_columns() { 1306 return array( 1307 'author' => 'comment_author', 1308 'comment' => 'comment_content', 1309 'response' => 'comment_post_ID' 1310 ); 1311 } 1312 1313 function display_table() { 1314 extract( $this->_args ); 1315 1316 $this->display_tablenav( 'top' ); 1317 1318 ?> 1319 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0"> 1320 <thead> 1321 <tr> 1322 <?php $this->print_column_headers(); ?> 1323 </tr> 1324 </thead> 1325 1326 <tfoot> 1327 <tr> 1328 <?php $this->print_column_headers( false ); ?> 1329 </tr> 1330 </tfoot> 1331 1332 <tbody id="the-comment-list" class="list:comment"> 1333 <?php $this->display_rows(); ?> 1334 </tbody> 1335 1336 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;"> 1337 <?php $this->items = $this->extra_items; $this->display_rows(); ?> 1338 </tbody> 1339 </table> 1340 <?php 1341 1342 $this->display_tablenav( 'bottom' ); 1343 } 1344 1345 function single_row( $a_comment ) { 1346 global $post, $comment, $the_comment_status; 1347 1348 $comment = $a_comment; 1349 $the_comment_status = wp_get_comment_status( $comment->comment_ID ); 1350 1351 $post = get_post( $comment->comment_post_ID ); 1352 1353 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); 1354 1355 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>"; 1356 echo $this->single_row_columns( $comment ); 1357 echo "</tr>\n"; 1358 } 1359 1360 function column_cb( $comment ) { 1361 if ( $this->user_can ) 1362 echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />"; 1363 } 1364 1365 function column_comment( $comment ) { 1366 global $post, $comment_status, $the_comment_status; 1367 1368 $user_can = $this->user_can; 1369 1370 $comment_url = esc_url( get_comment_link( $comment->comment_ID ) ); 1371 1372 $ptime = date( 'G', strtotime( $comment->comment_date ) ); 1373 if ( ( abs( time() - $ptime ) ) < 86400 ) 1374 $ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) ); 1375 else 1376 $ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date ); 1377 1378 if ( $user_can ) { 1379 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); 1380 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); 1381 1382 $url = "comment.php?c=$comment->comment_ID"; 1383 1384 $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" ); 1385 $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" ); 1386 $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" ); 1387 $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" ); 1388 $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" ); 1389 $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" ); 1390 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); 1391 } 1392 1393 echo '<div id="submitted-on">'; 1394 /* translators: 2: comment date, 3: comment time */ 1395 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ), $comment_url, 1396 /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ), 1397 /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) ); 1398 1399 if ( $comment->comment_parent ) { 1400 $parent = get_comment( $comment->comment_parent ); 1401 $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); 1402 $name = get_comment_author( $parent->comment_ID ); 1403 printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name ); 1404 } 1405 1406 echo '</div>'; 1407 comment_text(); 1408 if ( $user_can ) { ?> 1409 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> 1410 <textarea class="comment" rows="1" cols="1"><?php echo esc_html( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); ?></textarea> 1411 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div> 1412 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div> 1413 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div> 1414 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> 1415 </div> 1416 <?php 1417 } 1418 1419 if ( $user_can ) { 1420 // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash 1421 $actions = array( 1422 'approve' => '', 'unapprove' => '', 1423 'reply' => '', 1424 'quickedit' => '', 1425 'edit' => '', 1426 'spam' => '', 'unspam' => '', 1427 'trash' => '', 'untrash' => '', 'delete' => '' 1428 ); 1429 1430 if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments 1431 if ( 'approved' == $the_comment_status ) 1432 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; 1433 else if ( 'unapproved' == $the_comment_status ) 1434 $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; 1435 } else { 1436 $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>'; 1437 $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>'; 1438 } 1439 1440 if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { 1441 $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>'; 1442 } elseif ( 'spam' == $the_comment_status ) { 1443 $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>'; 1444 } elseif ( 'trash' == $the_comment_status ) { 1445 $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>'; 1446 } 1447 1448 if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) { 1449 $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>'; 1450 } else { 1451 $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>'; 1452 } 1453 1454 if ( 'trash' != $the_comment_status ) { 1455 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>'; 1456 $actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick Edit' ) . '</a>'; 1457 if ( 'spam' != $the_comment_status ) 1458 $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>'; 1459 } 1460 1461 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); 1462 1463 $i = 0; 1464 echo '<div class="row-actions">'; 1465 foreach ( $actions as $action => $link ) { 1466 ++$i; 1467 ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; 1468 1469 // Reply and quickedit need a hide-if-no-js span when not added with ajax 1470 if ( ( 'reply' == $action || 'quickedit' == $action ) && ! $this->from_ajax ) 1471 $action .= ' hide-if-no-js'; 1472 elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) { 1473 if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) 1474 $action .= ' approve'; 1475 else 1476 $action .= ' unapprove'; 1477 } 1478 1479 echo "<span class='$action'>$sep$link</span>"; 1480 } 1481 echo '</div>'; 1482 } 1483 } 1484 1485 function column_author( $comment ) { 1486 global $comment_status; 1487 1488 $author_url = get_comment_author_url(); 1489 if ( 'http://' == $author_url ) 1490 $author_url = ''; 1491 $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url ); 1492 if ( strlen( $author_url_display ) > 50 ) 1493 $author_url_display = substr( $author_url_display, 0, 49 ) . '...'; 1494 1495 echo "<strong>"; comment_author(); echo '</strong><br />'; 1496 if ( !empty( $author_url ) ) 1497 echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />"; 1498 1499 if ( $this->user_can ) { 1500 if ( !empty( $comment->comment_author_email ) ) { 1501 comment_author_email_link(); 1502 echo '<br />'; 1503 } 1504 echo '<a href="edit-comments.php?s='; 1505 comment_author_IP(); 1506 echo '&mode=detail'; 1507 if ( 'spam' == $comment_status ) 1508 echo '&comment_status=spam'; 1509 echo '">'; 1510 comment_author_IP(); 1511 echo '</a>'; 1512 } 1513 } 1514 1515 function column_date( $comment ) { 1516 return get_comment_date( __( 'Y/m/d \a\t g:ia' ) ); 1517 } 1518 1519 function column_response( $comment ) { 1520 global $post; 1521 1522 if ( isset( $this->pending_count[$post->ID] ) ) { 1523 $pending_comments = $this->pending_count[$post->ID]; 1524 } else { 1525 $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); 1526 $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; 1527 } 1528 1529 if ( current_user_can( 'edit_post', $post->ID ) ) { 1530 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>"; 1531 $post_link .= get_the_title( $post->ID ) . '</a>'; 1532 } else { 1533 $post_link = get_the_title( $post->ID ); 1534 } 1535 1536 echo '<div class="response-links"><span class="post-com-count-wrapper">'; 1537 echo $post_link . '<br />'; 1538 $this->comments_bubble( $post->ID, $pending_comments ); 1539 echo '</span> '; 1540 echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>"; 1541 echo '</div>'; 1542 if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) 1543 echo $thumb; 1544 } 1545 1546 function column_default( $comment, $column_name ) { 1547 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); 1548 } 1549 } 1550 1551 class WP_Post_Comments_Table extends WP_Comments_Table { 1552 1553 function get_columns() { 1554 return array( 1555 'author' => __( 'Author' ), 1556 'comment' => _x( 'Comment', 'column name' ), 1557 ); 1558 } 1559 1560 function get_sortable_columns() { 1561 return array(); 1562 } 1563 } 1564 1565 class WP_Links_Table extends WP_List_Table { 1566 1567 function WP_Links_Table() { 1568 parent::WP_List_Table( array( 1569 'screen' => 'link-manager', 1570 'plural' => 'bookmarks', 1571 ) ); 1572 } 1573 1574 function check_permissions() { 1575 if ( ! current_user_can( 'manage_links' ) ) 1576 wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) ); 1577 } 1578 1579 function prepare_items() { 1580 global $cat_id, $s, $orderby, $order; 1581 1582 wp_reset_vars( array( 'action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'orderby', 'order', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]', 's' ) ); 1583 1584 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 ); 1585 1586 if ( 'all' != $cat_id ) 1587 $args['category'] = $cat_id; 1588 if ( !empty( $s ) ) 1589 $args['search'] = $s; 1590 if ( !empty( $orderby ) ) 1591 $args['orderby'] = $orderby; 1592 if ( !empty( $order ) ) 1593 $args['order'] = $order; 1594 1595 $this->items = get_bookmarks( $args ); 1596 } 1597 1598 function no_items() { 1599 _e( 'No links found.' ); 1600 } 1601 1602 function get_bulk_actions() { 1603 $actions = array(); 1604 $actions['delete'] = __( 'Delete' ); 1605 1606 return $actions; 1607 } 1608 1609 function extra_tablenav( $which ) { 1610 global $cat_id; 1611 1612 if ( 'top' != $which ) 1613 return; 1614 ?> 1615 <div class="alignleft actions"> 1616 <?php 1617 $dropdown_options = array( 1618 'selected' => $cat_id, 1619 'name' => 'cat_id', 1620 'taxonomy' => 'link_category', 1621 'show_option_all' => __( 'View all categories' ), 1622 'hide_empty' => true, 1623 'hierarchical' => 1, 1624 'show_count' => 0, 1625 'orderby' => 'name', 1626 ); 1627 wp_dropdown_categories( $dropdown_options ); 1628 ?> 1629 <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Filter' ); ?>" class="button-secondary" /> 1630 </div> 1631 <?php 1632 } 1633 1634 function get_columns() { 1635 return array( 1636 'cb' => '<input type="checkbox" />', 1637 'name' => __( 'Name' ), 1638 'url' => __( 'URL' ), 1639 'categories' => __( 'Categories' ), 1640 'rel' => __( 'Relationship' ), 1641 'visible' => __( 'Visible' ), 1642 'rating' => __( 'Rating' ) 1643 ); 1644 } 1645 1646 function get_sortable_columns() { 1647 return array( 1648 'name' => 'name', 1649 'url' => 'url', 1650 'visible' => 'visible', 1651 'rating' => 'rating' 1652 ); 1653 } 1654 1655 function display_rows() { 1656 global $cat_id; 1657 1658 $alt = 0; 1659 1660 foreach ( $this->items as $link ) { 1661 $link = sanitize_bookmark( $link ); 1662 $link->link_name = esc_attr( $link->link_name ); 1663 $link->link_category = wp_get_link_cats( $link->link_id ); 1664 1665 $short_url = str_replace( 'http://', '', $link->link_url ); 1666 $short_url = preg_replace( '/^www\./i', '', $short_url ); 1667 if ( '/' == substr( $short_url, -1 ) ) 1668 $short_url = substr( $short_url, 0, -1 ); 1669 if ( strlen( $short_url ) > 35 ) 1670 $short_url = substr( $short_url, 0, 32 ).'...'; 1671 1672 $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' ); 1673 $rating = $link->link_rating; 1674 $style = ( $alt++ % 2 ) ? '' : ' class="alternate"'; 1675 1676 $edit_link = get_edit_bookmark_link( $link ); 1677 ?> 1678 <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>> 1679 <?php 1680 1681 list( $columns, $hidden ) = $this->get_column_info(); 1682 1683 foreach ( $columns as $column_name => $column_display_name ) { 1684 $class = "class='column-$column_name'"; 1685 1686 $style = ''; 1687 if ( in_array( $column_name, $hidden ) ) 1688 $style = ' style="display:none;"'; 1689 1690 $attributes = $class . $style; 1691 1692 switch ( $column_name ) { 1693 case 'cb': 1694 echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr( $link->link_id ) .'" /></th>'; 1695 break; 1696 1697 case 'name': 1698 echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />"; 1699 1700 $actions = array(); 1701 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 1702 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>"; 1703 echo $this->row_actions( $actions ); 1704 1705 echo '</td>'; 1706 break; 1707 case 'url': 1708 echo "<td $attributes><a href='$link->link_url' title='".sprintf( __( 'Visit %s' ), $link->link_name )."'>$short_url</a></td>"; 1709 break; 1710 case 'categories': 1711 ?><td <?php echo $attributes ?>><?php 1712 $cat_names = array(); 1713 foreach ( $link->link_category as $category ) { 1714 $cat = get_term( $category, 'link_category', OBJECT, 'display' ); 1715 if ( is_wp_error( $cat ) ) 1716 echo $cat->get_error_message(); 1717 $cat_name = $cat->name; 1718 if ( $cat_id != $category ) 1719 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; 1720 $cat_names[] = $cat_name; 1721 } 1722 echo implode( ', ', $cat_names ); 1723 ?></td><?php 1724 break; 1725 case 'rel': 1726 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php 1727 break; 1728 case 'visible': 1729 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php 1730 break; 1731 case 'rating': 1732 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php 1733 break; 1734 default: 1735 ?> 1736 <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td> 1737 <?php 1738 break; 1739 } 1740 } 1741 ?> 1742 </tr> 1743 <?php 1744 } 1745 } 1746 } 1747 1748 class WP_Sites_Table extends WP_List_Table { 1749 1750 function WP_Sites_Table() { 1751 parent::WP_List_Table( array( 1752 'screen' => 'sites-network', 1753 'plural' => 'sites', 1754 ) ); 1755 } 1756 1757 function check_permissions() { 1758 if ( ! current_user_can( 'manage_sites' ) ) 1759 wp_die( __( 'You do not have permission to access this page.' ) ); 1760 } 1761 1762 function prepare_items() { 1763 global $s, $mode, $wpdb; 1764 1765 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; 1766 1767 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); 1768 1769 $pagenum = $this->get_pagenum(); 1770 1771 $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : ''; 1772 $like_s = esc_sql( like_escape( $s ) ); 1773 1774 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 1775 1776 if ( isset( $_REQUEST['searchaction'] ) ) { 1777 if ( 'name' == $_REQUEST['searchaction'] ) { 1778 $query .= " AND ( {$wpdb->blogs}.domain LIKE '%{$like_s}%' OR {$wpdb->blogs}.path LIKE '%{$like_s}%' ) "; 1779 } elseif ( 'id' == $_REQUEST['searchaction'] ) { 1780 $query .= " AND {$wpdb->blogs}.blog_id = '{$like_s}' "; 1781 } elseif ( 'ip' == $_REQUEST['searchaction'] ) { 1782 $query = "SELECT * 1783 FROM {$wpdb->blogs}, {$wpdb->registration_log} 1784 WHERE site_id = '{$wpdb->siteid}' 1785 AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id 1786 AND {$wpdb->registration_log}.IP LIKE ( '%{$like_s}%' )"; 1787 } 1788 } 1789 1790 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'id'; 1791 if ( $order_by == 'registered' ) { 1792 $query .= ' ORDER BY registered '; 1793 } elseif ( $order_by == 'lastupdated' ) { 1794