]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-list-table.php
Wordpress 3.1
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-list-table.php
1 <?php
2 /**
3  * Base class for displaying a list of items in an ajaxified HTML table.
4  *
5  * @package WordPress
6  * @subpackage List_Table
7  * @since 3.1.0
8  */
9
10 /**
11  * Base class for displaying a list of items in an ajaxified HTML table.
12  *
13  * @package WordPress
14  * @subpackage List_Table
15  * @since 3.1.0
16  * @access private
17  */
18 class WP_List_Table {
19
20         /**
21          * The current list of items
22          *
23          * @since 3.1.0
24          * @var array
25          * @access protected
26          */
27         var $items;
28
29         /**
30          * Various information about the current table
31          *
32          * @since 3.1.0
33          * @var array
34          * @access private
35          */
36         var $_args;
37
38         /**
39          * Various information needed for displaying the pagination
40          *
41          * @since 3.1.0
42          * @var array
43          * @access private
44          */
45         var $_pagination_args = array();
46
47         /**
48          * The current screen
49          *
50          * @since 3.1.0
51          * @var object
52          * @access protected
53          */
54         var $screen;
55
56         /**
57          * Cached bulk actions
58          *
59          * @since 3.1.0
60          * @var array
61          * @access private
62          */
63         var $_actions;
64
65         /**
66          * Cached pagination output
67          *
68          * @since 3.1.0
69          * @var string
70          * @access private
71          */
72         var $_pagination;
73
74         /**
75          * Constructor. The child class should call this constructor from it's own constructor
76          *
77          * @param array $args An associative array with information about the current table
78          * @access protected
79          */
80         function WP_List_Table( $args = array() ) {
81                 $args = wp_parse_args( $args, array(
82                         'plural' => '',
83                         'singular' => '',
84                         'ajax' => false
85                 ) );
86
87                 $screen = get_current_screen();
88
89                 add_filter( "manage_{$screen->id}_columns", array( &$this, 'get_columns' ), 0 );
90
91                 if ( !$args['plural'] )
92                         $args['plural'] = $screen->base;
93
94                 $this->_args = $args;
95
96                 if ( $args['ajax'] ) {
97                         // wp_enqueue_script( 'list-table' );
98                         add_action( 'admin_footer', array( &$this, '_js_vars' ) );
99                 }
100         }
101
102         /**
103          * Checks the current user's permissions
104          * @uses wp_die()
105          *
106          * @since 3.1.0
107          * @access public
108          * @abstract
109          */
110         function ajax_user_can() {
111                 die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
112         }
113
114         /**
115          * Prepares the list of items for displaying.
116          * @uses WP_List_Table::set_pagination_args()
117          *
118          * @since 3.1.0
119          * @access public
120          * @abstract
121          */
122         function prepare_items() {
123                 die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
124         }
125
126         /**
127          * An internal method that sets all the necessary pagination arguments
128          *
129          * @param array $args An associative array with information about the pagination
130          * @access protected
131          */
132         function set_pagination_args( $args ) {
133                 $args = wp_parse_args( $args, array(
134                         'total_items' => 0,
135                         'total_pages' => 0,
136                         'per_page' => 0,
137                 ) );
138
139                 if ( !$args['total_pages'] && $args['per_page'] > 0 )
140                         $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
141
142                 $this->_pagination_args = $args;
143         }
144
145         /**
146          * Access the pagination args
147          *
148          * @since 3.1.0
149          * @access public
150          *
151          * @param string $key
152          * @return array
153          */
154         function get_pagination_arg( $key ) {
155                 if ( 'page' == $key )
156                         return $this->get_pagenum();
157
158                 if ( isset( $this->_pagination_args[$key] ) )
159                         return $this->_pagination_args[$key];
160         }
161
162         /**
163          * Whether the table has items to display or not
164          *
165          * @since 3.1.0
166          * @access public
167          *
168          * @return bool
169          */
170         function has_items() {
171                 return !empty( $this->items );
172         }
173
174         /**
175          * Message to be displayed when there are no items
176          *
177          * @since 3.1.0
178          * @access public
179          */
180         function no_items() {
181                 _e( 'No items found.' );
182         }
183
184         /**
185          * Display the search box.
186          *
187          * @since 3.1.0
188          * @access public
189          *
190          * @param string $text The search button text
191          * @param string $input_id The search input id
192          */
193         function search_box( $text, $input_id ) {
194                 if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
195                         return;
196
197                 $input_id = $input_id . '-search-input';
198
199                 if ( ! empty( $_REQUEST['orderby'] ) )
200                         echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
201                 if ( ! empty( $_REQUEST['order'] ) )
202                         echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
203 ?>
204 <p class="search-box">
205         <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
206         <input type="text" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
207         <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?>
208 </p>
209 <?php
210         }
211
212         /**
213          * Get an associative array ( id => link ) with the list
214          * of views available on this table.
215          *
216          * @since 3.1.0
217          * @access protected
218          *
219          * @return array
220          */
221         function get_views() {
222                 return array();
223         }
224
225         /**
226          * Display the bulk actions dropdown.
227          *
228          * @since 3.1.0
229          * @access public
230          */
231         function views() {
232                 $screen = get_current_screen();
233
234                 $views = $this->get_views();
235                 $views = apply_filters( 'views_' . $screen->id, $views );
236
237                 if ( empty( $views ) )
238                         return;
239
240                 echo "<ul class='subsubsub'>\n";
241                 foreach ( $views as $class => $view ) {
242                         $views[ $class ] = "\t<li class='$class'>$view";
243                 }
244                 echo implode( " |</li>\n", $views ) . "</li>\n";
245                 echo "</ul>";
246         }
247
248         /**
249          * Get an associative array ( option_name => option_title ) with the list
250          * of bulk actions available on this table.
251          *
252          * @since 3.1.0
253          * @access protected
254          *
255          * @return array
256          */
257         function get_bulk_actions() {
258                 return array();
259         }
260
261         /**
262          * Display the bulk actions dropdown.
263          *
264          * @since 3.1.0
265          * @access public
266          */
267         function bulk_actions() {
268                 $screen = get_current_screen();
269
270                 if ( is_null( $this->_actions ) ) {
271                         $no_new_actions = $this->_actions = $this->get_bulk_actions();
272                         // This filter can currently only be used to remove actions.
273                         $this->_actions = apply_filters( 'bulk_actions-' . $screen->id, $this->_actions );
274                         $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
275                         $two = '';
276                 } else {
277                         $two = '2';
278                 }
279
280                 if ( empty( $this->_actions ) )
281                         return;
282
283                 echo "<select name='action$two'>\n";
284                 echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
285                 foreach ( $this->_actions as $name => $title )
286                         echo "\t<option value='$name'>$title</option>\n";
287                 echo "</select>\n";
288
289                 submit_button( __( 'Apply' ), 'button-secondary action', false, false, array( 'id' => "doaction$two" ) );
290                 echo "\n";
291         }
292
293         /**
294          * Get the current action selected from the bulk actions dropdown.
295          *
296          * @since 3.1.0
297          * @access public
298          *
299          * @return string|bool The action name or False if no action was selected
300          */
301         function current_action() {
302                 if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
303                         return $_REQUEST['action'];
304
305                 if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
306                         return $_REQUEST['action2'];
307
308                 return false;
309         }
310
311         /**
312          * Generate row actions div
313          *
314          * @since 3.1.0
315          * @access protected
316          *
317          * @param array $actions The list of actions
318          * @param bool $always_visible Wether the actions should be always visible
319          * @return string
320          */
321         function row_actions( $actions, $always_visible = false ) {
322                 $action_count = count( $actions );
323                 $i = 0;
324
325                 if ( !$action_count )
326                         return '';
327
328                 $out = '<div class="' . ( $always_visible ? 'row-actions-visible' : 'row-actions' ) . '">';
329                 foreach ( $actions as $action => $link ) {
330                         ++$i;
331                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
332                         $out .= "<span class='$action'>$link$sep</span>";
333                 }
334                 $out .= '</div>';
335
336                 return $out;
337         }
338
339         /**
340          * Display a monthly dropdown for filtering items
341          *
342          * @since 3.1.0
343          * @access protected
344          */
345         function months_dropdown( $post_type ) {
346                 global $wpdb, $wp_locale;
347
348                 $months = $wpdb->get_results( $wpdb->prepare( "
349                         SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
350                         FROM $wpdb->posts
351                         WHERE post_type = %s
352                         ORDER BY post_date DESC
353                 ", $post_type ) );
354
355                 $month_count = count( $months );
356
357                 if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
358                         return;
359
360                 $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
361 ?>
362                 <select name='m'>
363                         <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'Show all dates' ); ?></option>
364 <?php
365                 foreach ( $months as $arc_row ) {
366                         if ( 0 == $arc_row->year )
367                                 continue;
368
369                         $month = zeroise( $arc_row->month, 2 );
370                         $year = $arc_row->year;
371
372                         printf( "<option %s value='%s'>%s</option>\n",
373                                 selected( $m, $year . $month, false ),
374                                 esc_attr( $arc_row->year . $month ),
375                                 $wp_locale->get_month( $month ) . " $year"
376                         );
377                 }
378 ?>
379                 </select>
380 <?php
381         }
382
383         /**
384          * Display a view switcher
385          *
386          * @since 3.1.0
387          * @access protected
388          */
389         function view_switcher( $current_mode ) {
390                 $modes = array(
391                         'list'    => __( 'List View' ),
392                         'excerpt' => __( 'Excerpt View' )
393                 );
394
395 ?>
396                 <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
397                 <div class="view-switch">
398 <?php
399                         foreach ( $modes as $mode => $title ) {
400                                 $class = ( $current_mode == $mode ) ? 'class="current"' : '';
401                                 echo "<a href='" . esc_url( add_query_arg( 'mode', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class><img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n";
402                         }
403                 ?>
404                 </div>
405 <?php
406         }
407
408         /**
409          * Display a comment count bubble
410          *
411          * @since 3.1.0
412          * @access protected
413          *
414          * @param int $post_id
415          * @param int $pending_comments
416          */
417         function comments_bubble( $post_id, $pending_comments ) {
418                 $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
419
420                 if ( $pending_comments )
421                         echo '<strong>';
422
423                 echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
424
425                 if ( $pending_comments )
426                         echo '</strong>';
427         }
428
429         /**
430          * Get the current page number
431          *
432          * @since 3.1.0
433          * @access protected
434          *
435          * @return int
436          */
437         function get_pagenum() {
438                 $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
439
440                 if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
441                         $pagenum = $this->_pagination_args['total_pages'];
442
443                 return max( 1, $pagenum );
444         }
445
446         /**
447          * Get number of items to display on a single page
448          *
449          * @since 3.1.0
450          * @access protected
451          *
452          * @return int
453          */
454         function get_items_per_page( $option, $default = 20 ) {
455                 $per_page = (int) get_user_option( $option );
456                 if ( empty( $per_page ) || $per_page < 1 )
457                         $per_page = $default;
458
459                 return (int) apply_filters( $option, $per_page );
460         }
461
462         /**
463          * Display the pagination.
464          *
465          * @since 3.1.0
466          * @access protected
467          */
468         function pagination( $which ) {
469                 if ( empty( $this->_pagination_args ) )
470                         return;
471
472                 extract( $this->_pagination_args );
473
474                 $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
475
476                 $current = $this->get_pagenum();
477
478                 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
479
480                 $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
481
482                 $page_links = array();
483
484                 $disable_first = $disable_last = '';
485                 if ( $current == 1 )
486                         $disable_first = ' disabled';
487                 if ( $current == $total_pages )
488                         $disable_last = ' disabled';
489
490                 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
491                         'first-page' . $disable_first,
492                         esc_attr__( 'Go to the first page' ),
493                         esc_url( remove_query_arg( 'paged', $current_url ) ),
494                         '&laquo;'
495                 );
496
497                 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
498                         'prev-page' . $disable_first,
499                         esc_attr__( 'Go to the previous page' ),
500                         esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
501                         '&lsaquo;'
502                 );
503
504                 if ( 'bottom' == $which )
505                         $html_current_page = $current;
506                 else
507                         $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='%s' value='%s' size='%d' />",
508                                 esc_attr__( 'Current page' ),
509                                 esc_attr( 'paged' ),
510                                 $current,
511                                 strlen( $total_pages )
512                         );
513
514                 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
515                 $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
516
517                 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
518                         'next-page' . $disable_last,
519                         esc_attr__( 'Go to the next page' ),
520                         esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
521                         '&rsaquo;'
522                 );
523
524                 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
525                         'last-page' . $disable_last,
526                         esc_attr__( 'Go to the last page' ),
527                         esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
528                         '&raquo;'
529                 );
530
531                 $output .= "\n" . join( "\n", $page_links );
532
533                 $page_class = $total_pages < 2 ? ' one-page' : '';
534
535                 $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
536
537                 echo $this->_pagination;
538         }
539
540         /**
541          * Get a list of columns. The format is:
542          * 'internal-name' => 'Title'
543          *
544          * @since 3.1.0
545          * @access protected
546          * @abstract
547          *
548          * @return array
549          */
550         function get_columns() {
551                 die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
552         }
553
554         /**
555          * Get a list of sortable columns. The format is:
556          * 'internal-name' => 'orderby'
557          * or
558          * 'internal-name' => array( 'orderby', true )
559          *
560          * The second format will make the initial sorting order be descending
561          *
562          * @since 3.1.0
563          * @access protected
564          *
565          * @return array
566          */
567         function get_sortable_columns() {
568                 return array();
569         }
570
571         /**
572          * Get a list of all, hidden and sortable columns, with filter applied
573          *
574          * @since 3.1.0
575          * @access protected
576          *
577          * @return array
578          */
579         function get_column_info() {
580                 if ( isset( $this->_column_headers ) )
581                         return $this->_column_headers;
582
583                 $screen = get_current_screen();
584
585                 $columns = get_column_headers( $screen );
586                 $hidden = get_hidden_columns( $screen );
587
588                 $_sortable = apply_filters( "manage_{$screen->id}_sortable_columns", $this->get_sortable_columns() );
589
590                 $sortable = array();
591                 foreach ( $_sortable as $id => $data ) {
592                         if ( empty( $data ) )
593                                 continue;
594
595                         $data = (array) $data;
596                         if ( !isset( $data[1] ) )
597                                 $data[1] = false;
598
599                         $sortable[$id] = $data;
600                 }
601
602                 $this->_column_headers = array( $columns, $hidden, $sortable );
603
604                 return $this->_column_headers;
605         }
606
607         /**
608          * Return number of visible columns
609          *
610          * @since 3.1.0
611          * @access public
612          *
613          * @return int
614          */
615         function get_column_count() {
616                 list ( $columns, $hidden ) = $this->get_column_info();
617                 $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
618                 return count( $columns ) - count( $hidden );
619         }
620
621         /**
622          * Print column headers, accounting for hidden and sortable columns.
623          *
624          * @since 3.1.0
625          * @access protected
626          *
627          * @param bool $with_id Whether to set the id attribute or not
628          */
629         function print_column_headers( $with_id = true ) {
630                 $screen = get_current_screen();
631
632                 list( $columns, $hidden, $sortable ) = $this->get_column_info();
633
634                 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
635                 $current_url = remove_query_arg( 'paged', $current_url );
636
637                 if ( isset( $_GET['orderby'] ) )
638                         $current_orderby = $_GET['orderby'];
639                 else
640                         $current_orderby = '';
641
642                 if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
643                         $current_order = 'desc';
644                 else
645                         $current_order = 'asc';
646
647                 foreach ( $columns as $column_key => $column_display_name ) {
648                         $class = array( 'manage-column', "column-$column_key" );
649
650                         $style = '';
651                         if ( in_array( $column_key, $hidden ) )
652                                 $style = 'display:none;';
653
654                         $style = ' style="' . $style . '"';
655
656                         if ( 'cb' == $column_key )
657                                 $class[] = 'check-column';
658                         elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
659                                 $class[] = 'num';
660
661                         if ( isset( $sortable[$column_key] ) ) {
662                                 list( $orderby, $desc_first ) = $sortable[$column_key];
663
664                                 if ( $current_orderby == $orderby ) {
665                                         $order = 'asc' == $current_order ? 'desc' : 'asc';
666                                         $class[] = 'sorted';
667                                         $class[] = $current_order;
668                                 } else {
669                                         $order = $desc_first ? 'desc' : 'asc';
670                                         $class[] = 'sortable';
671                                         $class[] = $desc_first ? 'asc' : 'desc';
672                                 }
673
674                                 $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
675                         }
676
677                         $id = $with_id ? "id='$column_key'" : '';
678
679                         if ( !empty( $class ) )
680                                 $class = "class='" . join( ' ', $class ) . "'";
681
682                         echo "<th scope='col' $id $class $style>$column_display_name</th>";
683                 }
684         }
685
686         /**
687          * Display the table
688          *
689          * @since 3.1.0
690          * @access public
691          */
692         function display() {
693                 extract( $this->_args );
694
695                 $this->display_tablenav( 'top' );
696
697 ?>
698 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
699         <thead>
700         <tr>
701                 <?php $this->print_column_headers(); ?>
702         </tr>
703         </thead>
704
705         <tfoot>
706         <tr>
707                 <?php $this->print_column_headers( false ); ?>
708         </tr>
709         </tfoot>
710
711         <tbody id="the-list"<?php if ( $singular ) echo " class='list:$singular'"; ?>>
712                 <?php $this->display_rows_or_placeholder(); ?>
713         </tbody>
714 </table>
715 <?php
716                 $this->display_tablenav( 'bottom' );
717         }
718
719         /**
720          * Get a list of CSS classes for the <table> tag
721          *
722          * @since 3.1.0
723          * @access protected
724          *
725          * @return array
726          */
727         function get_table_classes() {
728                 return array( 'widefat', 'fixed', $this->_args['plural'] );
729         }
730
731         /**
732          * Generate the table navigation above or below the table
733          *
734          * @since 3.1.0
735          * @access protected
736          */
737         function display_tablenav( $which ) {
738                 if ( 'top' == $which )
739                         wp_nonce_field( 'bulk-' . $this->_args['plural'] );
740 ?>
741         <div class="tablenav <?php echo esc_attr( $which ); ?>">
742
743                 <div class="alignleft actions">
744                         <?php $this->bulk_actions( $which ); ?>
745                 </div>
746 <?php
747                 $this->extra_tablenav( $which );
748                 $this->pagination( $which );
749 ?>
750
751                 <br class="clear" />
752         </div>
753 <?php
754         }
755
756         /**
757          * Extra controls to be displayed between bulk actions and pagination
758          *
759          * @since 3.1.0
760          * @access protected
761          */
762         function extra_tablenav( $which ) {}
763
764         /**
765          * Generate the <tbody> part of the table
766          *
767          * @since 3.1.0
768          * @access protected
769          */
770         function display_rows_or_placeholder() {
771                 if ( $this->has_items() ) {
772                         $this->display_rows();
773                 } else {
774                         list( $columns, $hidden ) = $this->get_column_info();
775                         echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
776                         $this->no_items();
777                         echo '</td></tr>';
778                 }
779         }
780
781         /**
782          * Generate the table rows
783          *
784          * @since 3.1.0
785          * @access protected
786          */
787         function display_rows() {
788                 foreach ( $this->items as $item )
789                         $this->single_row( $item );
790         }
791
792         /**
793          * Generates content for a single row of the table
794          *
795          * @since 3.1.0
796          * @access protected
797          *
798          * @param object $item The current item
799          */
800         function single_row( $item ) {
801                 static $row_class = '';
802                 $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
803
804                 echo '<tr' . $row_class . '>';
805                 echo $this->single_row_columns( $item );
806                 echo '</tr>';
807         }
808
809         /**
810          * Generates the columns for a single row of the table
811          *
812          * @since 3.1.0
813          * @access protected
814          *
815          * @param object $item The current item
816          */
817         function single_row_columns( $item ) {
818                 list( $columns, $hidden ) = $this->get_column_info();
819
820                 foreach ( $columns as $column_name => $column_display_name ) {
821                         $class = "class='$column_name column-$column_name'";
822
823                         $style = '';
824                         if ( in_array( $column_name, $hidden ) )
825                                 $style = ' style="display:none;"';
826
827                         $attributes = "$class$style";
828
829                         if ( 'cb' == $column_name ) {
830                                 echo '<th scope="row" class="check-column">';
831                                 echo $this->column_cb( $item );
832                                 echo '</th>';
833                         }
834                         elseif ( method_exists( $this, 'column_' . $column_name ) ) {
835                                 echo "<td $attributes>";
836                                 echo call_user_func( array( &$this, 'column_' . $column_name ), $item );
837                                 echo "</td>";
838                         }
839                         else {
840                                 echo "<td $attributes>";
841                                 echo $this->column_default( $item, $column_name );
842                                 echo "</td>";
843                         }
844                 }
845         }
846
847         /**
848          * Handle an incoming ajax request (called from admin-ajax.php)
849          *
850          * @since 3.1.0
851          * @access public
852          */
853         function ajax_response() {
854                 $this->prepare_items();
855
856                 extract( $this->_args );
857                 extract( $this->_pagination_args );
858
859                 ob_start();
860                 if ( ! empty( $_REQUEST['no_placeholder'] ) )
861                         $this->display_rows();
862                 else
863                         $this->display_rows_or_placeholder();
864
865                 $rows = ob_get_clean();
866
867                 $response = array( 'rows' => $rows );
868
869                 if ( isset( $total_items ) )
870                         $response['total_items_i18n'] = sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) );
871
872                 if ( isset( $total_pages ) ) {
873                         $response['total_pages'] = $total_pages;
874                         $response['total_pages_i18n'] = number_format_i18n( $total_pages );
875                 }
876
877                 die( json_encode( $response ) );
878         }
879
880         /**
881          * Send required variables to JavaScript land
882          *
883          * @access private
884          */
885         function _js_vars() {
886                 $args = array(
887                         'class' => get_class( $this ),
888                         'screen' => get_current_screen()
889                 );
890
891                 printf( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) );
892         }
893 }
894 ?>