[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> class-wp-list-table.php (source)

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


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting