[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * MS Themes List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_MS_Themes_List_Table extends WP_List_Table {
  11  
  12      var $site_id;
  13      var $is_site_themes;
  14  
  15  	function __construct() {
  16          global $status, $page;
  17  
  18          $default_status = get_user_option( 'themes_last_view' );
  19          if ( empty( $default_status ) )
  20              $default_status = 'all';
  21          $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : $default_status;
  22          if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search' ) ) )
  23              $status = 'all';
  24          if ( $status != $default_status && 'search' != $status )
  25              update_user_meta( get_current_user_id(), 'themes_last_view', $status );
  26  
  27          $page = $this->get_pagenum();
  28  
  29          $screen = get_current_screen();
  30          $this->is_site_themes = ( 'site-themes-network' == $screen->id ) ? true : false;
  31  
  32          if ( $this->is_site_themes )
  33              $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  34  
  35          parent::__construct( array(
  36              'plural' => 'themes'
  37          ) );
  38      }
  39  
  40  	function get_table_classes() {
  41          return array( 'widefat', 'plugins' );    // todo: remove and add CSS for .themes
  42      }
  43  
  44  	function ajax_user_can() {
  45          $menu_perms = get_site_option( 'menu_items', array() );
  46  
  47          if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
  48              return false;
  49  
  50          if ( $this->is_site_themes && !current_user_can('manage_sites') )
  51              return false;
  52          elseif ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
  53              return false;
  54          return true;
  55      }
  56  
  57  	function prepare_items() {
  58          global $status, $themes, $totals, $page, $orderby, $order, $s;
  59  
  60          wp_reset_vars( array( 'orderby', 'order', 's' ) );
  61  
  62          $themes = array(
  63              'all' => apply_filters( 'all_themes', get_themes() ),
  64              'search' => array(),
  65              'enabled' => array(),
  66              'disabled' => array(),
  67              'upgrade' => array()
  68          );
  69  
  70          $site_allowed_themes = get_site_allowed_themes();
  71          if ( !$this->is_site_themes ) {
  72              $allowed_themes = $site_allowed_themes;
  73              $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
  74          } else {
  75              $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
  76              $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
  77          }
  78  
  79          $current = get_site_transient( 'update_themes' );
  80  
  81          foreach ( (array) $themes['all'] as $key => $theme ) {
  82              $theme_key = $theme['Stylesheet'];
  83  
  84              if ( isset( $allowed_themes [ $theme_key ] ) )  {
  85                  $themes['all'][$key]['enabled'] = true;
  86                  $themes['enabled'][$key] = $themes['all'][$key];
  87              }
  88              else {
  89                  $themes['all'][$key]['enabled'] = false;
  90                  $themes['disabled'][$key] = $themes['all'][$key];
  91              }
  92              if ( isset( $current->response[ $theme['Template'] ] ) )
  93                  $themes['upgrade'][$key] = $themes['all'][$key];
  94  
  95              if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
  96                  unset( $themes['all'][$key] );
  97                  unset( $themes['enabled'][$key] );
  98                  unset( $themes['disabled'][$key] );
  99              }
 100          }
 101  
 102          if ( !current_user_can( 'update_themes' ) || $this->is_site_themes )
 103              $themes['upgrade'] = array();
 104  
 105          if ( $s ) {
 106              $status = 'search';
 107              $themes['search'] = array_filter( $themes['all'], array( &$this, '_search_callback' ) );
 108          }
 109  
 110          $totals = array();
 111          foreach ( $themes as $type => $list )
 112              $totals[ $type ] = count( $list );
 113  
 114          if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
 115              $status = 'all';
 116  
 117          $this->items = $themes[ $status ];
 118          $total_this_page = $totals[ $status ];
 119  
 120          if ( $orderby ) {
 121              $orderby = ucfirst( $orderby );
 122              $order = strtoupper( $order );
 123  
 124              uasort( $this->items, array( &$this, '_order_callback' ) );
 125          }
 126  
 127          $start = ( $page - 1 ) * $themes_per_page;
 128  
 129          if ( $total_this_page > $themes_per_page )
 130              $this->items = array_slice( $this->items, $start, $themes_per_page );
 131  
 132          $this->set_pagination_args( array(
 133              'total_items' => $total_this_page,
 134              'per_page' => $themes_per_page,
 135          ) );
 136      }
 137  
 138  	function _search_callback( $theme ) {
 139          static $term;
 140          if ( is_null( $term ) )
 141              $term = stripslashes( $_REQUEST['s'] );
 142  
 143          $search_fields = array( 'Name', 'Title', 'Description', 'Author', 'Author Name', 'Author URI', 'Template', 'Stylesheet' );
 144          foreach ( $search_fields as $field )
 145              if ( stripos( $theme[ $field ], $term ) !== false )
 146                  return true;
 147  
 148          return false;
 149      }
 150  
 151  	function _order_callback( $theme_a, $theme_b ) {
 152          global $orderby, $order;
 153  
 154          $a = $theme_a[$orderby];
 155          $b = $theme_b[$orderby];
 156  
 157          if ( $a == $b )
 158              return 0;
 159  
 160          if ( 'DESC' == $order )
 161              return ( $a < $b ) ? 1 : -1;
 162          else
 163              return ( $a < $b ) ? -1 : 1;
 164      }
 165  
 166  	function no_items() {
 167          global $themes;
 168  
 169          if ( !empty( $themes['all'] ) )
 170              _e( 'No themes found.' );
 171          else
 172              _e( 'You do not appear to have any themes available at this time.' );
 173      }
 174  
 175  	function get_columns() {
 176          global $status;
 177  
 178          return array(
 179              'cb'          => '<input type="checkbox" />',
 180              'name'        => __( 'Theme' ),
 181              'description' => __( 'Description' ),
 182          );
 183      }
 184  
 185  	function get_sortable_columns() {
 186          return array(
 187              'name'         => 'name',
 188          );
 189      }
 190  
 191  	function get_views() {
 192          global $totals, $status;
 193  
 194          $status_links = array();
 195          foreach ( $totals as $type => $count ) {
 196              if ( !$count )
 197                  continue;
 198  
 199              switch ( $type ) {
 200                  case 'all':
 201                      $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
 202                      break;
 203                  case 'enabled':
 204                      $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
 205                      break;
 206                  case 'disabled':
 207                      $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
 208                      break;
 209                  case 'upgrade':
 210                      $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
 211                      break;
 212              }
 213  
 214              if ( $this->is_site_themes )
 215                  $url = 'site-themes.php?id=' . $this->site_id;
 216              else
 217                  $url = 'themes.php';
 218  
 219              if ( 'search' != $type ) {
 220                  $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
 221                      esc_url( add_query_arg('theme_status', $type, $url) ),
 222                      ( $type == $status ) ? ' class="current"' : '',
 223                      sprintf( $text, number_format_i18n( $count ) )
 224                  );
 225              }
 226          }
 227  
 228          return $status_links;
 229      }
 230  
 231  	function get_bulk_actions() {
 232          global $status;
 233  
 234          $actions = array();
 235          if ( 'enabled' != $status )
 236              $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
 237          if ( 'disabled' != $status )
 238              $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
 239          if ( ! $this->is_site_themes ) {
 240              if ( current_user_can( 'delete_themes' ) )
 241                  $actions['delete-selected'] = __( 'Delete' );
 242              if ( current_user_can( 'update_themes' ) )
 243                  $actions['update-selected'] = __( 'Update' );
 244          }
 245          return $actions;
 246      }
 247  
 248  	function bulk_actions( $which ) {
 249          global $status;
 250          parent::bulk_actions( $which );
 251      }
 252  
 253  	function current_action() {
 254          return parent::current_action();
 255      }
 256  
 257  	function display_rows() {
 258          foreach ( $this->items as $key => $theme )
 259              $this->single_row( $key, $theme );
 260      }
 261  
 262  	function single_row( $key, $theme ) {
 263          global $status, $page, $s;
 264  
 265          $context = $status;
 266  
 267          if ( $this->is_site_themes )
 268              $url = "site-themes.php?id={$this->site_id}&amp;";
 269          else
 270              $url = 'themes.php?';
 271  
 272          // preorder
 273          $actions = array(
 274              'enable' => '',
 275              'disable' => '',
 276              'edit' => '',
 277              'delete' => ''
 278          );
 279  
 280          $theme_key = $theme['Stylesheet'];
 281  
 282          if ( empty( $theme['enabled'] ) )
 283              $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
 284          else
 285              $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
 286  
 287          if ( current_user_can('edit_themes') )
 288              $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . urlencode( $theme['Name'] )) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
 289  
 290          if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
 291              $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
 292  
 293          $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );
 294          $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context );
 295  
 296          $class = empty( $theme['enabled'] ) ? 'inactive' : 'active';
 297          $checkbox_id = "checkbox_" . md5($theme['Name']);
 298          $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme['Name'] . "</label>";
 299  
 300          $description = '<p>' . $theme['Description'] . '</p>';
 301          $theme_name = $theme['Name'];
 302  
 303          $id = sanitize_title( $theme_name );
 304  
 305          echo "<tr id='$id' class='$class'>";
 306  
 307          list( $columns, $hidden ) = $this->get_column_info();
 308  
 309          foreach ( $columns as $column_name => $column_display_name ) {
 310              $style = '';
 311              if ( in_array( $column_name, $hidden ) )
 312                  $style = ' style="display:none;"';
 313  
 314              switch ( $column_name ) {
 315                  case 'cb':
 316                      echo "<th scope='row' class='check-column'>$checkbox</th>";
 317                      break;
 318                  case 'name':
 319                      echo "<td class='theme-title'$style><strong>$theme_name</strong>";
 320                      echo $this->row_actions( $actions, true );
 321                      echo "</td>";
 322                      break;
 323                  case 'description':
 324                      echo "<td class='column-description desc'$style>
 325                          <div class='theme-description'>$description</div>
 326                          <div class='$class second theme-version-author-uri'>";
 327  
 328                      $theme_meta = array();
 329  
 330                      if ( !empty( $theme['Version'] ) )
 331                          $theme_meta[] = sprintf( __( 'Version %s' ), $theme['Version'] );
 332  
 333                      if ( !empty( $theme['Author'] ) )
 334                          $theme_meta[] = sprintf( __( 'By %s' ), $theme['Author'] );
 335  
 336                      if ( !empty( $theme['Theme URI'] ) )
 337                          $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
 338  
 339                      $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
 340                      echo implode( ' | ', $theme_meta );
 341  
 342                      echo "</div></td>";
 343                      break;
 344  
 345                  default:
 346                      echo "<td class='$column_name column-$column_name'$style>";
 347                      do_action( 'manage_themes_custom_column', $column_name, $theme_key, $theme );
 348                      echo "</td>";
 349              }
 350          }
 351  
 352          echo "</tr>";
 353  
 354          if ( $this->is_site_themes )
 355              remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' );
 356          do_action( 'after_theme_row', $theme_key, $theme, $status );
 357          do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status );
 358      }
 359  }
 360  
 361  ?>


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