Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-theme-install-list-table.php

    r18673 r21014  
    88 * @access private
    99 */
    10 class WP_Theme_Install_List_Table extends WP_List_Table {
     10class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
     11
     12        var $features = array();
    1113
    1214        function ajax_user_can() {
    13                 return current_user_can('install_themes');
     15                return current_user_can( 'install_themes' );
    1416        }
    1517
    … …  
    1719                include( ABSPATH . 'wp-admin/includes/theme-install.php' );
    1820
    19                 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults;
    20 
     21                global $tabs, $tab, $paged, $type, $theme_field_defaults;
    2122                wp_reset_vars( array( 'tab' ) );
     23
     24                $search_terms = array();
     25                $search_string = '';
     26                if ( ! empty( $_REQUEST['s'] ) ){
     27                        $search_string = strtolower( stripslashes( $_REQUEST['s'] ) );
     28                        $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
     29                }
     30
     31                if ( ! empty( $_REQUEST['features'] ) )
     32                        $this->features = $_REQUEST['features'];
    2233
    2334                $paged = $this->get_pagenum();
    … …  
    4960                switch ( $tab ) {
    5061                        case 'search':
    51                                 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
    52                                 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    53 
     62                                $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
    5463                                switch ( $type ) {
    5564                                        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;
     65                                                $args['tag'] = array_map( 'sanitize_key', $search_terms );
    6066                                                break;
    6167                                        case 'term':
    62                                                 $args['search'] = $term;
     68                                                $args['search'] = $search_string;
    6369                                                break;
    6470                                        case 'author':
    65                                                 $args['author'] = $term;
     71                                                $args['author'] = $search_string;
    6672                                                break;
    6773                                }
    6874
    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                                if ( ! empty( $this->features ) ) {
     76                                        $args['tag'] = $this->features;
     77                                        $_REQUEST['s'] = implode( ',', $this->features );
    7578                                        $_REQUEST['type'] = 'tag';
    7679                                }
    7780
    78                                 add_action( 'install_themes_table_header', 'install_theme_search_form' );
     81                                add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
    7982                                break;
    8083
    … …  
    9093                }
    9194
    92                 if ( !$args )
     95                if ( ! $args )
    9396                        return;
    9497
    … …  
    103106                        'total_items' => $api->info['results'],
    104107                        'per_page' => $per_page,
     108                        'infinite_scroll' => true,
    105109                ) );
    106110        }
    … …  
    123127        }
    124128
    125         function get_columns() {
    126                 return array();
    127         }
    128 
    129129        function display() {
    130 
    131                 // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
     130                wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
    132131?>
    133132                <div class="tablenav top themes">
    … …  
    144143                </div>
    145144
    146                 <div class="tablenav bottom themes">
    147                         <?php $this->pagination( 'bottom' ); ?>
    148                         <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
    149                         <br class="clear" />
    150                 </div>
    151 <?php
     145                <?php
     146                parent::tablenav( 'bottom' );
    152147        }
    153148
    154149        function display_rows() {
    155150                $themes = $this->items;
    156                 $theme_names = array_keys( $themes );
    157 
    158                 foreach ( $theme_names as $theme_name ) {
    159                                 $class = array( 'available-theme' );
     151                foreach ( $themes as $theme ) {
    160152                                ?>
    161                                 <div class="<?php echo join( ' ', $class ); ?>"><?php
    162                                         if ( isset( $themes[$theme_name] ) )
    163                                                 display_theme( $themes[$theme_name] );
     153                                <div class="available-theme installable-theme"><?php
     154                                        $this->single_row( $theme );
    164155                                ?></div>
    165156                <?php } // end foreach $theme_names
     157
     158                $this->theme_installer();
     159        }
     160
     161        /*
     162         * Prints a theme from the WordPress.org API.
     163         *
     164         * @param object $theme An object that contains theme data returned by the WordPress.org API.
     165         *
     166         * Example theme data:
     167         *   object(stdClass)[59]
     168         *     public 'name' => string 'Magazine Basic' (length=14)
     169         *     public 'slug' => string 'magazine-basic' (length=14)
     170         *     public 'version' => string '1.1' (length=3)
     171         *     public 'author' => string 'tinkerpriest' (length=12)
     172         *     public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36)
     173         *     public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68)
     174         *     public 'rating' => float 80
     175         *     public 'num_ratings' => int 1
     176         *     public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49)
     177         *     public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' (length=214)
     178         *     public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
     179         */
     180        function single_row( $theme ) {
     181                global $themes_allowedtags;
     182
     183                if ( empty( $theme ) )
     184                        return;
     185
     186                $name   = wp_kses( $theme->name,   $themes_allowedtags );
     187                $author = wp_kses( $theme->author, $themes_allowedtags );
     188
     189                $preview_title = sprintf( __('Preview &#8220;%s&#8221;'), $name );
     190                $preview_url   = add_query_arg( array(
     191                        'tab'   => 'theme-information',
     192                        'theme' => $theme->slug,
     193                ) );
     194
     195                $actions = array();
     196
     197                $install_url = add_query_arg( array(
     198                        'action' => 'install-theme',
     199                        'theme'  => $theme->slug,
     200                ), self_admin_url( 'update.php' ) );
     201
     202                $update_url = add_query_arg( array(
     203                        'action' => 'upgrade-theme',
     204                        'theme'  => $theme->slug,
     205                ), self_admin_url( 'update.php' ) );
     206
     207                $status = $this->_get_theme_status( $theme );
     208
     209                switch ( $status ) {
     210                        default:
     211                        case 'install':
     212                                $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
     213                                break;
     214                        case 'update_available':
     215                                $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
     216                                break;
     217                        case 'newer_installed':
     218                        case 'latest_installed':
     219                                $actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
     220                                break;
     221                }
     222
     223                $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>';
     224
     225                $actions = apply_filters( 'theme_install_actions', $actions, $theme );
     226
     227                ?>
     228                <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
     229                        <img src='<?php echo esc_url( $theme->screenshot_url ); ?>' width='150' />
     230                </a>
     231
     232                <h3><?php echo $name; ?></h3>
     233                <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
     234
     235                <div class="action-links">
     236                        <ul>
     237                                <?php foreach ( $actions as $action ): ?>
     238                                        <li><?php echo $action; ?></li>
     239                                <?php endforeach; ?>
     240                                <li class="hide-if-no-js"><a href="#" class="theme-detail" tabindex='4'><?php _e('Details') ?></a></li>
     241                        </ul>
     242                </div>
     243
     244                <?php
     245                $this->install_theme_info( $theme );
     246        }
     247
     248        /*
     249         * Prints the wrapper for the theme installer.
     250         */
     251        function theme_installer() {
     252                ?>
     253                <div id="theme-installer" class="wp-full-overlay expanded">
     254                        <div class="wp-full-overlay-sidebar">
     255                                <div class="wp-full-overlay-header">
     256                                        <a href="#" class="close-full-overlay"><?php _e( '&larr; Close' ); ?></a>
     257                                </div>
     258                                <div class="wp-full-overlay-sidebar-content">
     259                                        <div class="install-theme-info"></div>
     260                                </div>
     261                                <div class="wp-full-overlay-footer">
     262                                        <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
     263                                                <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
     264                                                <span class="collapse-sidebar-arrow"></span>
     265                                        </a>
     266                                </div>
     267                        </div>
     268                        <div class="wp-full-overlay-main"></div>
     269                </div>
     270                <?php
     271        }
     272
     273        /*
     274         * Prints the wrapper for the theme installer with a provided theme's data.
     275         * Used to make the theme installer work for no-js.
     276         *
     277         * @param object $theme - A WordPress.org Theme API object.
     278         */
     279        function theme_installer_single( $theme ) {
     280                ?>
     281                <div id="theme-installer" class="wp-full-overlay single-theme">
     282                        <div class="wp-full-overlay-sidebar">
     283                                <?php $this->install_theme_info( $theme ); ?>
     284                        </div>
     285                        <div class="wp-full-overlay-main">
     286                                <iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe>
     287                        </div>
     288                </div>
     289                <?php
     290        }
     291
     292        /*
     293         * Prints the info for a theme (to be used in the theme installer modal).
     294         *
     295         * @param object $theme - A WordPress.org Theme API object.
     296         */
     297        function install_theme_info( $theme ) {
     298                global $themes_allowedtags;
     299
     300                if ( empty( $theme ) )
     301                        return;
     302
     303                $name   = wp_kses( $theme->name,   $themes_allowedtags );
     304                $author = wp_kses( $theme->author, $themes_allowedtags );
     305
     306                $num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) );
     307
     308                $install_url = add_query_arg( array(
     309                        'action' => 'install-theme',
     310                        'theme'  => $theme->slug,
     311                ), self_admin_url( 'update.php' ) );
     312
     313                $update_url = add_query_arg( array(
     314                        'action' => 'upgrade-theme',
     315                        'theme'  => $theme->slug,
     316                ), self_admin_url( 'update.php' ) );
     317
     318                $status = $this->_get_theme_status( $theme );
     319
     320                ?>
     321                <div class="install-theme-info"><?php
     322                        switch ( $status ) {
     323                                default:
     324                                case 'install':
     325                                        echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>';
     326                                        break;
     327                                case 'update_available':
     328                                        echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
     329                                        break;
     330                                case 'newer_installed':
     331                                case 'latest_installed':
     332                                        echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
     333                                        break;
     334                        } ?>
     335                        <h3 class="theme-name"><?php echo $name; ?></h3>
     336                        <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
     337                        <?php if ( isset( $theme->screenshot_url ) ): ?>
     338                                <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" />
     339                        <?php endif; ?>
     340                        <div class="theme-details">
     341                                <div class="star-holder" title="<?php echo esc_attr( $num_ratings ); ?>">
     342                                        <div class="star-rating" style="width:<?php echo esc_attr( intval( $theme->rating ) . 'px' ); ?>;"></div>
     343                                </div>
     344                                <div class="theme-version">
     345                                        <strong><?php _e('Version:') ?> </strong>
     346                                        <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
     347                                </div>
     348                                <div class="theme-description">
     349                                        <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
     350                                </div>
     351                        </div>
     352                        <input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" />
     353                </div>
     354                <?php
     355        }
     356
     357        /**
     358         * Send required variables to JavaScript land
     359         *
     360         * @since 3.4
     361         * @access private
     362         *
     363         * @uses $tab Global; current tab within Themes->Install screen
     364         * @uses $type Global; type of search.
     365         */
     366        function _js_vars() {
     367                global $tab, $type;
     368                parent::_js_vars( compact( 'tab', 'type' ) );
     369        }
     370
     371        /**
     372         * Check to see if the theme is already installed.
     373         *
     374         * @since 3.4
     375         * @access private
     376         *
     377         * @param object $theme - A WordPress.org Theme API object.
     378         * @return string Theme status.
     379         */
     380        private function _get_theme_status( $theme ) {
     381                $status = 'install';
     382
     383                $installed_theme = wp_get_theme( $theme->slug );
     384                if ( $installed_theme->exists() ) {
     385                        if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) )
     386                                $status = 'latest_installed';
     387                        elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) )
     388                                $status = 'newer_installed';
     389                        else
     390                                $status = 'update_available';
     391                }
     392
     393                return $status;
    166394        }
    167395}
    168 
    169 ?>
Note: See TracChangeset for help on using the changeset viewer.