[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

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      var $search = array();
  13      var $features = array();
  14  
  15  	function ajax_user_can() {
  16          // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes.
  17          return current_user_can('switch_themes');
  18      }
  19  
  20  	function prepare_items() {
  21          global $ct;
  22  
  23          $ct = current_theme_info();
  24  
  25          $themes = get_allowed_themes();
  26  
  27          if ( ! empty( $_REQUEST['s'] ) ) {
  28              $search = strtolower( stripslashes( $_REQUEST['s'] ) );
  29              $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
  30              $this->search = array_unique( $this->search );
  31          }
  32  
  33          if ( !empty( $_REQUEST['features'] ) ) {
  34              $this->features = $_REQUEST['features'];
  35              $this->features = array_map( 'trim', $this->features );
  36              $this->features = array_map( 'sanitize_title_with_dashes', $this->features );
  37              $this->features = array_unique( $this->features );
  38          }
  39  
  40          if ( $this->search || $this->features ) {
  41              foreach ( $themes as $key => $theme ) {
  42                  if ( !$this->search_theme( $theme ) )
  43                      unset( $themes[ $key ] );
  44              }
  45          }
  46  
  47          unset( $themes[$ct->name] );
  48          uksort( $themes, "strnatcasecmp" );
  49  
  50          $per_page = 15;
  51          $page = $this->get_pagenum();
  52  
  53          $start = ( $page - 1 ) * $per_page;
  54  
  55          $this->items = array_slice( $themes, $start, $per_page );
  56  
  57          $this->set_pagination_args( array(
  58              'total_items' => count( $themes ),
  59              'per_page' => $per_page,
  60          ) );
  61      }
  62  
  63  	function no_items() {
  64          if ( $this->search || $this->features ) {
  65              _e( 'No items found.' );
  66              return;
  67          }
  68  
  69          if ( is_multisite() ) {
  70              if ( current_user_can( 'install_themes' ) && 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> 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' ) );
  72  
  73                  return;
  74              } elseif ( current_user_can( 'manage_network_themes' ) ) {
  75                  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'] ) );
  76  
  77                  return;
  78              }
  79              // else, fallthrough. install_themes doesn't help if you can't enable it.
  80          } else {
  81              if ( current_user_can( 'install_themes' ) ) {
  82                  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' ) );
  83  
  84                  return;
  85              }
  86          }
  87          // Fallthrough.
  88          printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
  89      }
  90  
  91  	function tablenav( $which = 'top' ) {
  92          if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
  93              return;
  94          ?>
  95          <div class="tablenav <?php echo $which; ?>">
  96              <?php $this->pagination( $which ); ?>
  97             <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
  98            <br class="clear" />
  99          </div>
 100          <?php
 101      }
 102  
 103  	function display() {
 104          // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
 105  ?>
 106          <?php $this->tablenav( 'top' ); ?>
 107  
 108          <table id="availablethemes" cellspacing="0" cellpadding="0">
 109              <tbody id="the-list" class="list:themes">
 110                  <?php $this->display_rows_or_placeholder(); ?>
 111              </tbody>
 112          </table>
 113  
 114          <?php $this->tablenav( 'bottom' ); ?>
 115  <?php
 116      }
 117  
 118  	function get_columns() {
 119          return array();
 120      }
 121  
 122  	function display_rows() {
 123          $themes = $this->items;
 124          $theme_names = array_keys( $themes );
 125          natcasesort( $theme_names );
 126  
 127          $table = array();
 128          $rows = ceil( count( $theme_names ) / 3 );
 129          for ( $row = 1; $row <= $rows; $row++ )
 130              for ( $col = 1; $col <= 3; $col++ )
 131                  $table[$row][$col] = array_shift( $theme_names );
 132  
 133          foreach ( $table as $row => $cols ) {
 134  ?>
 135  <tr>
 136  <?php
 137  foreach ( $cols as $col => $theme_name ) {
 138      $class = array( 'available-theme' );
 139      if ( $row == 1 ) $class[] = 'top';
 140      if ( $col == 1 ) $class[] = 'left';
 141      if ( $row == $rows ) $class[] = 'bottom';
 142      if ( $col == 3 ) $class[] = 'right';
 143  ?>
 144      <td class="<?php echo join( ' ', $class ); ?>">
 145  <?php if ( !empty( $theme_name ) ) :
 146      $template = $themes[$theme_name]['Template'];
 147      $stylesheet = $themes[$theme_name]['Stylesheet'];
 148      $title = $themes[$theme_name]['Title'];
 149      $version = $themes[$theme_name]['Version'];
 150      $description = $themes[$theme_name]['Description'];
 151      $author = $themes[$theme_name]['Author'];
 152      $screenshot = $themes[$theme_name]['Screenshot'];
 153      $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
 154      $template_dir = $themes[$theme_name]['Template Dir'];
 155      $parent_theme = $themes[$theme_name]['Parent Theme'];
 156      $theme_root = $themes[$theme_name]['Theme Root'];
 157      $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
 158      $preview_link = esc_url( get_option( 'home' ) . '/' );
 159      if ( is_ssl() )
 160          $preview_link = str_replace( 'http://', 'https://', $preview_link );
 161      $preview_link = htmlspecialchars( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ), $preview_link ) );
 162      $preview_text = esc_attr( sprintf( __( 'Preview of &#8220;%s&#8221;' ), $title ) );
 163      $tags = $themes[$theme_name]['Tags'];
 164      $thickbox_class = 'thickbox thickbox-preview';
 165      $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=".urlencode( $template )."&amp;stylesheet=".urlencode( $stylesheet ), 'switch-theme_' . $template );
 166      $activate_text = esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) );
 167      $actions = array();
 168      $actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>';
 169      $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>';
 170      if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
 171          $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $theme_name ) ) . "' );" . '">' . __( 'Delete' ) . '</a>';
 172      $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] );
 173  
 174      $actions = implode ( ' | ', $actions );
 175  ?>
 176          <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
 177  <?php if ( $screenshot ) : ?>
 178              <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
 179  <?php endif; ?>
 180          </a>
 181  <h3><?php
 182      /* translators: 1: theme title, 2: theme version, 3: theme author */
 183      printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
 184  <p class="description"><?php echo $description; ?></p>
 185  <span class='action-links'><?php echo $actions ?></span>
 186      <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) {
 187      /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
 188      <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.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ); ?></p>
 189  <?php } else { ?>
 190      <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
 191  <?php } ?>
 192  <?php if ( $tags ) : ?>
 193  <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p>
 194  <?php endif; ?>
 195          <?php theme_update_available( $themes[$theme_name] ); ?>
 196  <?php endif; // end if not empty theme_name ?>
 197      </td>
 198  <?php } // end foreach $cols ?>
 199  </tr>
 200  <?php } // end foreach $table
 201      }
 202  
 203  	function search_theme( $theme ) {
 204          $matched = 0;
 205  
 206          // Match all phrases
 207          if ( count( $this->search ) > 0 ) {
 208              foreach ( $this->search as $word ) {
 209                  $matched = 0;
 210  
 211                  // In a tag?
 212                  if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
 213                      $matched = 1;
 214  
 215                  // In one of the fields?
 216                  foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
 217                      if ( stripos( $theme[$field], $word ) !== false )
 218                          $matched++;
 219                  }
 220  
 221                  if ( $matched == 0 )
 222                      return false;
 223              }
 224          }
 225  
 226          // Now search the features
 227          if ( count( $this->features ) > 0 ) {
 228              foreach ( $this->features as $word ) {
 229                  // In a tag?
 230                  if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
 231                      return false;
 232              }
 233          }
 234  
 235          // Only get here if each word exists in the tags or one of the fields
 236          return true;
 237      }
 238  }
 239  
 240  ?>


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