From e9fd5a004affd95430f49f63946fb788f0e9fdc0 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 26 Feb 2009 23:35:38 +0000 Subject: [PATCH] More theme install tweaks. See #8652 git-svn-id: https://develop.svn.wordpress.org/trunk@10656 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/theme-install.php | 488 ++++++++++++---------------- 1 file changed, 210 insertions(+), 278 deletions(-) diff --git a/wp-admin/includes/theme-install.php b/wp-admin/includes/theme-install.php index 316e829de5..0de605af9b 100644 --- a/wp-admin/includes/theme-install.php +++ b/wp-admin/includes/theme-install.php @@ -35,7 +35,7 @@ $themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), */ function themes_api($action, $args = null) { - if( is_array($args) ) + if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) @@ -51,7 +51,7 @@ function themes_api($action, $args = null) { } else { $res = unserialize($request['body']); if ( ! $res ) - $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']); + $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']); } } //var_dump(array($args, $res)); @@ -129,33 +129,34 @@ function install_theme_search($page) { add_action('install_themes_dashboard', 'install_themes_dashboard'); function install_themes_dashboard() { ?> -

+

' . __('[need help?]') . '') ?> -
-


- Term: Searches theme names and descriptions for the specified term') ?>
- Tag: Searches for themes tagged as such') ?>
- Author: Searches for themes created by the Author, or which the Author contributed to.') ?>

-
+
+


+ Term: Searches theme names and descriptions for the specified term') ?>
+ Tag: Searches for themes tagged as such') ?>
+ Author: Searches for themes created by the Author, or which the Author contributed to.') ?>

+
-

-

+

+

-

-

+

+

clean_url( admin_url('theme-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ), 'name' => $tag['name'], 'id' => sanitize_title_with_dashes($tag['name']), 'count' => $tag['count'] ); + } echo '

'; echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d theme'), 'multiple_text' => __('%d themes') ) ); echo '


'; @@ -170,15 +171,18 @@ function install_theme_search_form(){ $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : ''; $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : ''; - ?>
- - - -
+
+ -

-

-
- - - -
- +

+

+
+
+ name, $themes_allowedtags); + $desc = wp_kses($theme->description, $themes_allowedtags); + //if ( strlen($desc) > 30 ) + // $desc = substr($desc, 0, 30) . '...' . substr($desc, 30) . ''; + + $preview_link = $theme->preview_url . '?TB_iframe=true&width=600&height=400'; + if ( empty($actions) ) { + $actions = array(); + $actions[] = '' . __('Install') . ''; + $actions[] = '' . __('Preview') . ''; + $actions = apply_filters('theme_install_action_links', $actions, $theme); + } + + $actions = implode ( ' | ', $actions ); + ?> +'> + + +

+ +

+ + +
+

version, $themes_allowedtags) ?>

+

author, $themes_allowedtags) ?>

+
+ string 'Magazine Basic' (length=14) + public 'slug' => string 'magazine-basic' (length=14) + public 'version' => string '1.1' (length=3) + public 'author' => string 'tinkerpriest' (length=12) + public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36) + public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68) + public 'rating' => float 80 + public 'num_ratings' => int 1 + public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49) + 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.' (length=214) + public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66) + */ } /** @@ -268,112 +323,66 @@ function display_themes($themes, $page = 1, $totalpages = 1) { $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : ''; $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : ''; -?> -
-
- -
- +
+
+
+ add_query_arg('paged', '%#%', $url), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $totalpages, 'current' => $page - )); + )); - if ( $page_links ) - echo "\t\t
$page_links
"; -?> -
-
- - $page_links"; + ?>
+ +
+ $cols ) { -?> - - $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'; - $theme = $themes[$theme_index]; -?> - - - - + foreach ( $table as $row => $cols ) { + ?> + + $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'; + $theme = $themes[$theme_index]; + ?> + + + +
-name, $themes_allowedtags); - $desc = wp_kses($theme->description, $themes_allowedtags); - //if ( strlen($desc) > 30 ) - // $desc = substr($desc, 0, 30) . '...' . substr($desc, 30) . ''; - - $preview_link = $theme->preview_url . '?TB_iframe=true&width=600&height=400'; - $action_links = array(); - $action_links[] = '' . __('Install') . ''; - $action_links[] = '' . __('Preview') . ''; - - $action_links = apply_filters('theme_install_action_links', $action_links, $theme); - $actions = implode ( ' | ', $action_links ); -?> - '> - - -

- -

- -
-

version, $themes_allowedtags) ?>

-

author, $themes_allowedtags) ?>

-
- string 'Magazine Basic' (length=14) - public 'slug' => string 'magazine-basic' (length=14) - public 'version' => string '1.1' (length=3) - public 'author' => string 'tinkerpriest' (length=12) - public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36) - public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68) - public 'rating' => float 80 - public 'num_ratings' => int 1 - public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49) - 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.' (length=214) - public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66) - */ -?> -
-
- $page_links
"; ?> -
-
+
$page_links
"; ?>
+ sections as $section_name => $content ) $api->sections[$section_name] = wp_kses($content, $themes_allowedtags); foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key ) $api->$key = wp_kses($api->$key, $themes_allowedtags); $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English. - if( empty($section) || ! isset($api->sections[ $section ]) ) + if ( empty($section) || ! isset($api->sections[ $section ]) ) $section = array_shift( $section_titles = array_keys((array)$api->sections) ); iframe_header( __('Theme Install') ); - echo "
\n"; - echo "\n"; - echo "
\n"; ?> -
- download_link) ) : ?> -

- response as $file => $theme ) { - if ( $theme->slug === $api->slug ) { - $type = 'update_available'; - $update_file = $file; - break; - } - } - /*if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { - $installed_theme = get_themes('/' . $api->slug); - if ( ! empty($installed_theme) ) { - $key = array_shift( $key = array_keys($installed_theme) ); //Use the first theme regardless of the name, Could have issues for multiple-themes in one directory if they share different version numbers - if ( version_compare($api->version, $installed_theme[ $key ]['Version'], '>') ){ - $type = 'latest_installed'; - } elseif ( version_compare($api->version, $installed_theme[ $key ]['Version'], '<') ) { - $type = 'newer_installed'; - $newer_version = $installed_theme[ $key ]['Version']; - } else { - //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh - delete_option('update_themes'); - $update_file = $api->slug . '/' . $key; //This code branch only deals with a theme which is in a folder the same name as its slug, Doesnt support themes which have 'non-standard' names - $type = 'update_available'; - } - } - }*/ - switch ( $type ) : - default: - case 'install': - if ( current_user_can('install_themes') ) : - ?> -

- -

- -

-
-
-
<?php _e('5 stars') ?>
-
<?php _e('4 stars') ?>
-
<?php _e('3 stars') ?>
-
<?php _e('2 stars') ?>
-
<?php _e('1 star') ?>
-
- num_ratings), number_format_i18n($api->num_ratings)); ?> -
-
+

response as $file => $theme ) { + if ( $theme->slug === $api->slug ) { + $type = 'update_available'; + $update_file = $file; + break; + } +} + +$action = ''; +switch ( $type ) { + default: + case 'install': + if ( current_user_can('install_themes') ) : + $action = '' . __('Install Now') . ''; + endif; + break; +case 'update_available': + if ( current_user_can('update_themes') ) : + ?>

+
+ +
tested, '>') ) - echo '

' . __('Warning: This theme has not been tested with your current version of WordPress.') . '

'; - else if ( version_compare($GLOBALS['wp_version'], $api->requires, '<') ) - echo '

' . __('Warning: This theme has not been marked as compatible with your version of WordPress.') . '

'; - foreach ( (array)$api->sections as $section_name => $content ) { - $title = $section_name; - $title[0] = strtoupper($title[0]); - $title = str_replace('_', ' ', $title); - - $content = links_add_base_url($content, 'http://wordpress.org/extend/themes/' . $api->slug . '/'); - $content = links_add_target($content, '_blank'); - - $san_title = attribute_escape(sanitize_title_with_dashes($title)); - - $display = ( $section_name == $section ) ? 'block' : 'none'; - - echo "\t
\n"; - echo "\t\t

$title

"; - echo $content; - echo "\t
\n"; - } - echo "
\n"; - iframe_footer(); exit; } - add_action('install_themes_do_upload', 'upload_theme'); function upload_theme() { @@ -630,7 +563,7 @@ function do_theme_install($download_url, $theme_information = null) { if ( $wp_filesystem->errors->get_error_code() ) { foreach ( $wp_filesystem->errors->get_error_messages() as $message ) - show_message($message); + show_message($message); return; } @@ -644,10 +577,10 @@ function do_theme_install($download_url, $theme_information = null) { $theme_file = $result; $install_actions = apply_filters('install_theme_complete_actions', array( - //'activate_theme' => '' . __('Activate Theme') . '', + //'activate_theme' => '' . __('Activate Theme') . '', 'themes_page' => '' . __('Return to Themes page') . '' - ), $theme_information, $theme_file); - if ( ! empty($install_actions) ) + ), $theme_information, $theme_file); + if ( ! empty($install_actions) ) show_message('' . __('Actions:') . ' ' . implode(' | ', (array)$install_actions)); } } @@ -686,7 +619,7 @@ function do_theme_install_local_package($package, $filename = '') { if ( $wp_filesystem->errors->get_error_code() ) { foreach ( $wp_filesystem->errors->get_error_messages() as $message ) - show_message($message); + show_message($message); return; } @@ -700,11 +633,11 @@ function do_theme_install_local_package($package, $filename = '') { $theme_file = $result; $install_actions = apply_filters('install_theme_complete_actions', array( - //'activate_theme' => '' . __('Activate Theme') . '', + //'activate_theme' => '' . __('Activate Theme') . '', 'themes_page' => '' . __('Return to Themes page') . '' ), array(), $theme_file); - if ( ! empty($install_actions) ) - show_message('' . __('Actions:') . ' ' . implode(' | ', (array)$install_actions)); + if ( ! empty($install_actions) ) + show_message('' . __('Actions:') . ' ' . implode(' | ', (array)$install_actions)); } } @@ -733,14 +666,14 @@ function wp_install_theme($package, $feedback = '') { if ( $wp_filesystem->errors->get_error_code() ) return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); - //Get the base theme folder + // Get the base theme folder $themes_dir = $wp_filesystem->wp_themes_dir(); if ( empty($themes_dir) ) return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress Theme directory.')); - //And the same for the Content directory. + // And the same for the Content directory. $content_dir = $wp_filesystem->wp_content_dir(); - if( empty($content_dir) ) + if ( empty($content_dir) ) return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); $themes_dir = trailingslashit( $themes_dir ); @@ -777,7 +710,7 @@ function wp_install_theme($package, $feedback = '') { //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); - if( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) { + if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) { $wp_filesystem->delete($working_dir, true); return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] ); } @@ -796,14 +729,13 @@ function wp_install_theme($package, $feedback = '') { // Remove working directory $wp_filesystem->delete($working_dir, true); - if( empty($filelist) ) + if ( empty($filelist) ) return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup. - -//TODO: TODO: TODO + //TODO: TODO: TODO $stylesheet = $filelist[0]; -// $theme = get_themes('/' . $folder); //Ensure to pass with leading slash //TODO: TODO: TODO -// $themefiles = array_keys($theme); //Assume the requested theme is the first in the list + // $theme = get_themes('/' . $folder); //Ensure to pass with leading slash //TODO: TODO: TODO + // $themefiles = array_keys($theme); //Assume the requested theme is the first in the list //Return the theme files name. return $stylesheet; //$folder . '/' . $themefiles[0]; @@ -841,7 +773,7 @@ function wp_install_theme_local_package($package, $feedback = '') { //And the same for the Content directory. $content_dir = $wp_filesystem->wp_content_dir(); - if( empty($content_dir) ) + if ( empty($content_dir) ) return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); $themes_dir = trailingslashit( $themes_dir ); @@ -872,11 +804,11 @@ function wp_install_theme_local_package($package, $feedback = '') { //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); - if( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) { + if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) { $wp_filesystem->delete($working_dir, true); return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] ); } - + apply_filters('install_feedback', __('Installing the theme')); // Copy new version of theme into place. $result = copy_dir($working_dir, $themes_dir); @@ -891,13 +823,13 @@ function wp_install_theme_local_package($package, $feedback = '') { // Remove working directory $wp_filesystem->delete($working_dir, true); - if( empty($filelist) ) + if ( empty($filelist) ) return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup. -//TODO TODO TODO + //TODO TODO TODO $stylesheet = $filelist[0]; -// $theme = get_themes('/' . $folder); //Ensure to pass with leading slash -// $themefiles = array_keys($theme); //Assume the requested theme is the first in the list + // $theme = get_themes('/' . $folder); //Ensure to pass with leading slash + // $themefiles = array_keys($theme); //Assume the requested theme is the first in the list //Return the theme files name. return $stylsheet; //$folder . '/' . $themefiles[0];