[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Themes List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Themes_List_Table extends WP_List_Table {
  11  
  12      protected $search_terms = array();
  13      var $features = array();
  14  
  15  	function __construct() {
  16          parent::__construct( array(
  17              'ajax' => true,
  18          ) );
  19      }
  20  
  21  	function ajax_user_can() {
  22          // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes.
  23          return current_user_can( 'switch_themes' );
  24      }
  25  
  26  	function prepare_items() {
  27          $themes = wp_get_themes( array( 'allowed' => true ) );
  28  
  29          if ( ! empty( $_REQUEST['s'] ) )
  30              $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( stripslashes( $_REQUEST['s'] ) ) ) ) ) );
  31  
  32          if ( ! empty( $_REQUEST['features'] ) )
  33              $this->features = $_REQUEST['features'];
  34  
  35          if ( $this->search_terms || $this->features ) {
  36              foreach ( $themes as $key => $theme ) {
  37                  if ( ! $this->search_theme( $theme ) )
  38                      unset( $themes[ $key ] );
  39              }
  40          }
  41  
  42          unset( $themes[ get_option( 'stylesheet' ) ] );
  43          WP_Theme::sort_by_name( $themes );
  44  
  45          $per_page = 999;
  46          $page = $this->get_pagenum();
  47  
  48          $start = ( $page - 1 ) * $per_page;
  49  
  50          $this->items = array_slice( $themes, $start, $per_page, true );
  51  
  52          $this->set_pagination_args( array(
  53              'total_items' => count( $themes ),
  54              'per_page' => $per_page,
  55              'infinite_scroll' => true,
  56          ) );
  57      }
  58  
  59  	function no_items() {
  60          if ( $this->search_terms || $this->features ) {
  61              _e( 'No items found.' );
  62              return;
  63          }
  64  
  65          if ( is_multisite() ) {
  66              if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
  67                  printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) );
  68  
  69                  return;
  70              } elseif ( current_user_can( 'manage_network_themes' ) ) {
  71                  printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) );
  72  
  73                  return;
  74              }
  75              // else, fallthrough. install_themes doesn't help if you can't enable it.
  76          } else {
  77              if ( current_user_can( 'install_themes' ) ) {
  78                  printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) );
  79  
  80                  return;
  81              }
  82          }
  83          // Fallthrough.
  84          printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
  85      }
  86  
  87  	function tablenav( $which = 'top' ) {
  88          if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
  89              return;
  90          ?>
  91          <div class="tablenav themes <?php echo $which; ?>">
  92              <?php $this->pagination( $which ); ?>
  93             <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
  94            <br class="clear" />
  95          </div>
  96          <?php
  97      }
  98  
  99  	function display() {
 100          wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
 101  ?>
 102          <?php $this->tablenav( 'top' ); ?>
 103  
 104          <div id="availablethemes">
 105              <?php $this->display_rows_or_placeholder(); ?>
 106          </div>
 107  
 108          <?php $this->tablenav( 'bottom' ); ?>
 109  <?php
 110      }
 111  
 112  	function get_columns() {
 113          return array();
 114      }
 115  
 116  	function display_rows() {
 117          $themes = $this->items;
 118  
 119          foreach ( $themes as $theme ):
 120              ?><div class="available-theme"><?php
 121  
 122              $template   = $theme->get_template();
 123              $stylesheet = $theme->get_stylesheet();
 124              $title      = $theme->display('Name');
 125              $version    = $theme->display('Version');
 126              $author     = $theme->display('Author');
 127  
 128              $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $template );
 129  
 130              $preview_link = esc_url( add_query_arg(
 131                  array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ),
 132                  home_url( '/' ) ) );
 133  
 134              $actions = array();
 135              $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="'
 136                  . esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
 137              $actions[] = '<a href="' . $preview_link . '" class="hide-if-customize" title="'
 138                  . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Preview' ) . '</a>'
 139                  . '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">'
 140                  . __( 'Live Preview' ) . '</a>';
 141              if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
 142                  $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet )
 143                      . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $title ) )
 144                      . "' );" . '">' . __( 'Delete' ) . '</a>';
 145  
 146              $actions       = apply_filters( 'theme_action_links', $actions, $theme );
 147              $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : '';
 148              unset( $actions['delete'] );
 149  
 150              ?>
 151  
 152              <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize">
 153                  <?php if ( $screenshot = $theme->get_screenshot() ) : ?>
 154                      <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
 155                  <?php endif; ?>
 156              </a>
 157              <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize">
 158                  <?php if ( $screenshot = $theme->get_screenshot() ) : ?>
 159                      <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
 160                  <?php endif; ?>
 161              </a>
 162  
 163              <h3><?php echo $title; ?></h3>
 164              <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
 165              <div class="action-links">
 166                  <ul>
 167                      <?php foreach ( $actions as $action ): ?>
 168                          <li><?php echo $action; ?></li>
 169                      <?php endforeach; ?>
 170                      <li class="hide-if-no-js"><a href="#" class="theme-detail" tabindex='4'><?php _e('Details') ?></a></li>
 171                  </ul>
 172                  <?php echo $delete_action; ?>
 173  
 174                  <?php theme_update_available( $theme ); ?>
 175              </div>
 176  
 177              <div class="themedetaildiv hide-if-js">
 178                  <p><strong><?php _e('Version: '); ?></strong><?php echo $version; ?></p>
 179                  <p><?php echo $theme->display('Description'); ?></p>
 180                  <?php if ( current_user_can( 'edit_themes' ) && $theme->parent() ) :
 181                      /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
 182                      <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ),
 183                          $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ), $title, $theme->parent()->display('Name') ); ?></p>
 184                  <?php else :
 185                          /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir */ ?>
 186                      <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ),
 187                          $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ) ); ?></p>
 188                  <?php endif; ?>
 189              </div>
 190  
 191              </div>
 192          <?php
 193          endforeach;
 194      }
 195  
 196  	function search_theme( $theme ) {
 197          // Search the features
 198          foreach ( $this->features as $word ) {
 199              if ( ! in_array( $word, $theme->get('Tags') ) )
 200                  return false;
 201          }
 202  
 203          // Match all phrases
 204          foreach ( $this->search_terms as $word ) {
 205              if ( in_array( $word, $theme->get('Tags') ) )
 206                  continue;
 207  
 208              foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
 209                  // Don't mark up; Do translate.
 210                  if ( false !== stripos( $theme->display( $header, false, true ), $word ) )
 211                      continue 2;
 212              }
 213  
 214              if ( false !== stripos( $theme->get_stylesheet(), $word ) )
 215                  continue;
 216  
 217              if ( false !== stripos( $theme->get_template(), $word ) )
 218                  continue;
 219  
 220              return false;
 221          }
 222  
 223          return true;
 224      }
 225  
 226      /**
 227       * Send required variables to JavaScript land
 228       *
 229       * @since 3.4
 230       * @access private
 231       *
 232       * @uses $this->features Array of all feature search terms.
 233       * @uses get_pagenum()
 234       * @uses _pagination_args['total_pages']
 235       */
 236  	 function _js_vars( $extra_args = array() ) {
 237          $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
 238  
 239          $args = array(
 240              'search' => $search_string,
 241              'features' => $this->features,
 242              'paged' => $this->get_pagenum(),
 243              'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
 244          );
 245  
 246          if ( is_array( $extra_args ) )
 247              $args = array_merge( $args, $extra_args );
 248  
 249          printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) );
 250          parent::_js_vars();
 251      }
 252  }


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.