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