X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..61343b82c4f0da4c68e4c6373daafff4a81efdd1:/wp-admin/includes/class-wp-theme-install-list-table.php diff --git a/wp-admin/includes/class-wp-theme-install-list-table.php b/wp-admin/includes/class-wp-theme-install-list-table.php index 7e44267c..8a46199f 100644 --- a/wp-admin/includes/class-wp-theme-install-list-table.php +++ b/wp-admin/includes/class-wp-theme-install-list-table.php @@ -7,22 +7,33 @@ * @since 3.1.0 * @access private */ -class WP_Theme_Install_List_Table extends WP_List_Table { +class WP_Theme_Install_List_Table extends WP_Themes_List_Table { + + var $features = array(); function ajax_user_can() { - return current_user_can('install_themes'); + return current_user_can( 'install_themes' ); } function prepare_items() { include( ABSPATH . 'wp-admin/includes/theme-install.php' ); - global $tabs, $tab, $paged, $type, $term, $theme_field_defaults; - + global $tabs, $tab, $paged, $type, $theme_field_defaults; wp_reset_vars( array( 'tab' ) ); + $search_terms = array(); + $search_string = ''; + if ( ! empty( $_REQUEST['s'] ) ){ + $search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); + $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); + } + + if ( ! empty( $_REQUEST['features'] ) ) + $this->features = $_REQUEST['features']; + $paged = $this->get_pagenum(); - $per_page = 30; + $per_page = 36; // These are the tabs which are shown on the page, $tabs = array(); @@ -40,7 +51,7 @@ class WP_Theme_Install_List_Table extends WP_List_Table { $tabs = apply_filters( 'install_themes_tabs', $tabs ); $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs ); - // If a non-valid menu tab has been selected, And its not a non-menu action. + // If a non-valid menu tab has been selected, And it's not a non-menu action. if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) $tab = key( $tabs ); @@ -48,34 +59,26 @@ class WP_Theme_Install_List_Table extends WP_List_Table { switch ( $tab ) { case 'search': - $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : ''; - $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; - + $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; switch ( $type ) { case 'tag': - $terms = explode( ',', $term ); - $terms = array_map( 'trim', $terms ); - $terms = array_map( 'sanitize_title_with_dashes', $terms ); - $args['tag'] = $terms; + $args['tag'] = array_map( 'sanitize_key', $search_terms ); break; case 'term': - $args['search'] = $term; + $args['search'] = $search_string; break; case 'author': - $args['author'] = $term; + $args['author'] = $search_string; break; } - if ( !empty( $_POST['features'] ) ) { - $terms = $_POST['features']; - $terms = array_map( 'trim', $terms ); - $terms = array_map( 'sanitize_title_with_dashes', $terms ); - $args['tag'] = $terms; - $_REQUEST['s'] = implode( ',', $terms ); + if ( ! empty( $this->features ) ) { + $args['tag'] = $this->features; + $_REQUEST['s'] = implode( ',', $this->features ); $_REQUEST['type'] = 'tag'; } - add_action( 'install_themes_table_header', 'install_theme_search_form' ); + add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 ); break; case 'featured': @@ -89,7 +92,7 @@ class WP_Theme_Install_List_Table extends WP_List_Table { $args = false; } - if ( !$args ) + if ( ! $args ) return; $api = themes_api( 'query_themes', $args ); @@ -102,6 +105,7 @@ class WP_Theme_Install_List_Table extends WP_List_Table { $this->set_pagination_args( array( 'total_items' => $api->info['results'], 'per_page' => $per_page, + 'infinite_scroll' => true, ) ); } @@ -122,64 +126,269 @@ class WP_Theme_Install_List_Table extends WP_List_Table { return $display_tabs; } - function get_columns() { - return array(); - } - function display() { - - // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); + wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> -
+
pagination( 'top' ); ?> -
- - - display_rows_or_placeholder(); ?> - -
- -
- pagination( 'bottom' ); ?> - -
+
+ display_rows_or_placeholder(); ?>
-items; - - $rows = ceil( count( $themes ) / 3 ); - $table = array(); - $theme_keys = array_keys( $themes ); - for ( $row = 1; $row <= $rows; $row++ ) - for ( $col = 1; $col <= 3; $col++ ) - $table[$row][$col] = array_shift( $theme_keys ); - - foreach ( $table as $row => $cols ) { - echo "\t\n"; - foreach ( $cols as $col => $theme_index ) { - $class = array( 'available-theme' ); - if ( $row == 1 ) $class[] = 'top'; - if ( $col == 1 ) $class[] = 'left'; - if ( $row == $rows ) $class[] = 'bottom'; - if ( $col == 3 ) $class[] = 'right'; + foreach ( $themes as $theme ) { ?> - - \n"; - } // end foreach $table +
single_row( $theme ); + ?>
+ theme_installer(); } -} -?> + /* + * Prints a theme from the WordPress.org API. + * + * @param object $theme An object that contains theme data returned by the WordPress.org API. + * + * Example theme data: + * object(stdClass)[59] + * public 'name' => string 'Magazine Basic' + * public 'slug' => string 'magazine-basic' + * public 'version' => string '1.1' + * public 'author' => string 'tinkerpriest' + * public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' + * public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' + * public 'rating' => float 80 + * public 'num_ratings' => int 1 + * public 'homepage' => string 'http://wordpress.org/themes/magazine-basic' + * public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by c.bavota of Tinker Priest Media.' + * public 'download_link' => string 'http://wordpress.org/themes/download/magazine-basic.1.1.zip' + */ + function single_row( $theme ) { + global $themes_allowedtags; + + if ( empty( $theme ) ) + return; + + $name = wp_kses( $theme->name, $themes_allowedtags ); + $author = wp_kses( $theme->author, $themes_allowedtags ); + + $preview_title = sprintf( __('Preview “%s”'), $name ); + $preview_url = add_query_arg( array( + 'tab' => 'theme-information', + 'theme' => $theme->slug, + ) ); + + $actions = array(); + + $install_url = add_query_arg( array( + 'action' => 'install-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $update_url = add_query_arg( array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $status = $this->_get_theme_status( $theme ); + + switch ( $status ) { + default: + case 'install': + $actions[] = '' . __( 'Install Now' ) . ''; + break; + case 'update_available': + $actions[] = '' . __( 'Update' ) . ''; + break; + case 'newer_installed': + case 'latest_installed': + $actions[] = '' . _x( 'Installed', 'theme' ) . ''; + break; + } + + $actions[] = '' . __( 'Preview' ) . ''; + + $actions = apply_filters( 'theme_install_actions', $actions, $theme ); + + ?> + + + + +

+
+ + + + install_theme_info( $theme ); + } + + /* + * Prints the wrapper for the theme installer. + */ + function theme_installer() { + ?> +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+ install_theme_info( $theme ); ?> +
+
+ +
+
+ name, $themes_allowedtags ); + $author = wp_kses( $theme->author, $themes_allowedtags ); + + $num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) ); + + $install_url = add_query_arg( array( + 'action' => 'install-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $update_url = add_query_arg( array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $status = $this->_get_theme_status( $theme ); + + ?> +
slug ) ) . '">' . __( 'Install' ) . ''; + break; + case 'update_available': + echo '' . __( 'Update' ) . ''; + break; + case 'newer_installed': + case 'latest_installed': + echo '' . _x( 'Installed', 'theme' ) . ''; + break; + } ?> +

+ + screenshot_url ) ): ?> + + +
+
+
+
+
+ + version, $themes_allowedtags ); ?> +
+
+ description, $themes_allowedtags ); ?> +
+
+ +
+ Install screen + * @uses $type Global; type of search. + */ + function _js_vars( $extra_args = array() ) { + global $tab, $type; + parent::_js_vars( compact( 'tab', 'type' ) ); + } + + /** + * Check to see if the theme is already installed. + * + * @since 3.4 + * @access private + * + * @param object $theme - A WordPress.org Theme API object. + * @return string Theme status. + */ + private function _get_theme_status( $theme ) { + $status = 'install'; + + $installed_theme = wp_get_theme( $theme->slug ); + if ( $installed_theme->exists() ) { + if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) ) + $status = 'latest_installed'; + elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) ) + $status = 'newer_installed'; + else + $status = 'update_available'; + } + + return $status; + } +}