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