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