[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Theme Installer List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Theme_Install_List_Table extends WP_List_Table {
  11  
  12  	function ajax_user_can() {
  13          return current_user_can('install_themes');
  14      }
  15  
  16  	function prepare_items() {
  17          include ( ABSPATH . 'wp-admin/includes/theme-install.php' );
  18  
  19          global $tabs, $tab, $paged, $type, $term, $theme_field_defaults;
  20  
  21          wp_reset_vars( array( 'tab' ) );
  22  
  23          $paged = $this->get_pagenum();
  24  
  25          $per_page = 30;
  26  
  27          // These are the tabs which are shown on the page,
  28          $tabs = array();
  29          $tabs['dashboard'] = __( 'Search' );
  30          if ( 'search' == $tab )
  31              $tabs['search']    = __( 'Search Results' );
  32          $tabs['upload'] = __( 'Upload' );
  33          $tabs['featured'] = _x( 'Featured','Theme Installer' );
  34          //$tabs['popular']  = _x( 'Popular','Theme Installer' );
  35          $tabs['new']      = _x( 'Newest','Theme Installer' );
  36          $tabs['updated']  = _x( 'Recently Updated','Theme Installer' );
  37  
  38          $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
  39  
  40          $tabs = apply_filters( 'install_themes_tabs', $tabs );
  41          $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
  42  
  43          // If a non-valid menu tab has been selected, And its not a non-menu action.
  44          if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
  45              $tab = key( $tabs );
  46  
  47          $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
  48  
  49          switch ( $tab ) {
  50              case 'search':
  51                  $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
  52                  $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  53  
  54                  switch ( $type ) {
  55                      case 'tag':
  56                          $terms = explode( ',', $term );
  57                          $terms = array_map( 'trim', $terms );
  58                          $terms = array_map( 'sanitize_title_with_dashes', $terms );
  59                          $args['tag'] = $terms;
  60                          break;
  61                      case 'term':
  62                          $args['search'] = $term;
  63                          break;
  64                      case 'author':
  65                          $args['author'] = $term;
  66                          break;
  67                  }
  68  
  69                  if ( !empty( $_POST['features'] ) ) {
  70                      $terms = $_POST['features'];
  71                      $terms = array_map( 'trim', $terms );
  72                      $terms = array_map( 'sanitize_title_with_dashes', $terms );
  73                      $args['tag'] = $terms;
  74                      $_REQUEST['s'] = implode( ',', $terms );
  75                      $_REQUEST['type'] = 'tag';
  76                  }
  77  
  78                  add_action( 'install_themes_table_header', 'install_theme_search_form' );
  79                  break;
  80  
  81              case 'featured':
  82              //case 'popular':
  83              case 'new':
  84              case 'updated':
  85                  $args['browse'] = $tab;
  86                  break;
  87  
  88              default:
  89                  $args = false;
  90          }
  91  
  92          if ( !$args )
  93              return;
  94  
  95          $api = themes_api( 'query_themes', $args );
  96  
  97          if ( is_wp_error( $api ) )
  98              wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
  99  
 100          $this->items = $api->themes;
 101  
 102          $this->set_pagination_args( array(
 103              'total_items' => $api->info['results'],
 104              'per_page' => $per_page,
 105          ) );
 106      }
 107  
 108  	function no_items() {
 109          _e( 'No themes match your request.' );
 110      }
 111  
 112  	function get_views() {
 113          global $tabs, $tab;
 114  
 115          $display_tabs = array();
 116          foreach ( (array) $tabs as $action => $text ) {
 117              $class = ( $action == $tab ) ? ' class="current"' : '';
 118              $href = self_admin_url('theme-install.php?tab=' . $action);
 119              $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>";
 120          }
 121  
 122          return $display_tabs;
 123      }
 124  
 125  	function get_columns() {
 126          return array();
 127      }
 128  
 129  	function display() {
 130  
 131          // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
 132  ?>
 133          <div class="tablenav top">
 134              <div class="alignleft actions">
 135                  <?php do_action( 'install_themes_table_header' ); ?>
 136              </div>
 137              <?php $this->pagination( 'top' ); ?>
 138              <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
 139              <br class="clear" />
 140          </div>
 141  
 142          <table id="availablethemes" cellspacing="0" cellpadding="0">
 143              <tbody id="the-list" class="list:themes">
 144                  <?php $this->display_rows_or_placeholder(); ?>
 145              </tbody>
 146          </table>
 147  
 148          <div class="tablenav bottom">
 149              <?php $this->pagination( 'bottom' ); ?>
 150              <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
 151              <br class="clear" />
 152          </div>
 153  <?php
 154      }
 155  
 156  	function display_rows() {
 157          $themes = $this->items;
 158  
 159          $rows = ceil( count( $themes ) / 3 );
 160          $table = array();
 161          $theme_keys = array_keys( $themes );
 162          for ( $row = 1; $row <= $rows; $row++ )
 163              for ( $col = 1; $col <= 3; $col++ )
 164                  $table[$row][$col] = array_shift( $theme_keys );
 165  
 166          foreach ( $table as $row => $cols ) {
 167              echo "\t<tr>\n";
 168              foreach ( $cols as $col => $theme_index ) {
 169                  $class = array( 'available-theme' );
 170                  if ( $row == 1 ) $class[] = 'top';
 171                  if ( $col == 1 ) $class[] = 'left';
 172                  if ( $row == $rows ) $class[] = 'bottom';
 173                  if ( $col == 3 ) $class[] = 'right';
 174                  ?>
 175                  <td class="<?php echo join( ' ', $class ); ?>"><?php
 176                      if ( isset( $themes[$theme_index] ) )
 177                          display_theme( $themes[$theme_index] );
 178                  ?></td>
 179              <?php } // end foreach $cols
 180              echo "\t</tr>\n";
 181          } // end foreach $table
 182      }
 183  }
 184  
 185  ?>


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