<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20140] trunk/wp-admin: Theme Customizer: Make theme installer no-js compatible.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20140">20140</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-03-07 18:24:34 +0000 (Wed, 07 Mar 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Theme Customizer: Make theme installer no-js compatible. Fix JS click handler that caught clicks on the 'Activate' link. Relocate display_theme() to WP_Theme_Install_List_Table->single_row(). see <a href="http://core.trac.wordpress.org/ticket/19910">#19910</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadmindevcss">trunk/wp-admin/css/wp-admin.dev.css</a></li>
<li><a href="#trunkwpadminincludesclasswpthemeinstalllisttablephp">trunk/wp-admin/includes/class-wp-theme-install-list-table.php</a></li>
<li><a href="#trunkwpadminincludesthemeinstallphp">trunk/wp-admin/includes/theme-install.php</a></li>
<li><a href="#trunkwpadminjsthemedevjs">trunk/wp-admin/js/theme.dev.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincsswpadmindevcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.dev.css (20139 => 20140)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.dev.css        2012-03-07 17:45:21 UTC (rev 20139)
+++ trunk/wp-admin/css/wp-admin.dev.css        2012-03-07 18:24:34 UTC (rev 20140)
</span><span class="lines">@@ -5366,10 +5366,17 @@
</span><span class="cx">         display: none;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#theme-installer.single-theme {
+        display: block;
+}
+
</ins><span class="cx"> .install-theme-info {
</span><span class="cx">         display: none;
</span><span class="cx">         padding: 45px 20px 15px;
</span><span class="cx"> }
</span><ins>+.single-theme .install-theme-info {
+        padding-top: 15px;
+}
</ins><span class="cx">
</span><span class="cx"> #theme-installer .install-theme-info {
</span><span class="cx">         display: block;
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpthemeinstalllisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-theme-install-list-table.php (20139 => 20140)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-theme-install-list-table.php        2012-03-07 17:45:21 UTC (rev 20139)
+++ trunk/wp-admin/includes/class-wp-theme-install-list-table.php        2012-03-07 18:24:34 UTC (rev 20140)
</span><span class="lines">@@ -151,15 +151,71 @@
</span><span class="cx">                 $theme_names = array_keys( $themes );
</span><span class="cx">
</span><span class="cx">                 foreach ( $theme_names as $theme_name ) {
</span><del>-                                $class = array( 'available-theme' );
</del><span class="cx">                                 ?>
</span><del>-                                <div class="<?php echo join( ' ', $class ); ?>"><?php
</del><ins>+                                <div class="available-theme installable-theme"><?php
</ins><span class="cx">                                         if ( isset( $themes[$theme_name] ) )
</span><span class="cx">                                                 display_theme( $themes[$theme_name] );
</span><span class="cx">                                 ?></div>
</span><span class="cx">                 <?php } // end foreach $theme_names
</span><span class="cx">
</span><ins>+                $this->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' (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 <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' (length=214)
+         * public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
+         */
+        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 &#8220;%s&#8221;'), $name );
+                $preview_url = add_query_arg( array(
+                        'tab' => 'theme-information',
+                        'theme' => $theme->slug,
+                ) );
+
</ins><span class="cx">                 ?>
</span><ins>+                <a class="screenshot" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
+                        <img src='<?php echo esc_url( $theme->screenshot_url ); ?>' width='150' />
+                </a>
+
+                <h3><?php
+                        /* translators: 1: theme name, 2: author name */
+                        printf( __( '%1$s <span>by %2$s</span>' ), $name, $author );
+                ?></h3>
+
+                <?php
+                $this->install_theme_info( $theme );
+        }
+
+        /*
+         * Prints the wrapper for the theme installer.
+         */
+        function theme_installer() {
+                ?>
</ins><span class="cx">                 <div id="theme-installer" class="wp-full-overlay">
</span><span class="cx">                         <a href="#" class="close-full-overlay"><?php printf( __( '&larr; Return to %s' ), get_admin_page_title() ); ?></a>
</span><span class="cx">                         <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>"><span></span></a>
</span><span class="lines">@@ -172,6 +228,73 @@
</span><span class="cx">                 <?php
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        /*
+         * Prints the wrapper for the theme installer with a provided theme's data.
+         * Used to make the theme installer work for no-js.
+         *
+         * @param object $theme - A WordPress.org Theme API object.
+         */
+        function theme_installer_single( $theme ) {
+                $class = 'wp-full-overlay';
+                if ( $theme )
+                        $class .= ' single-theme';
+
+                ?>
+                <div id="theme-installer" class="wp-full-overlay single-theme">
+                        <div class="wp-full-overlay-sidebar">
+                                <?php $this->install_theme_info( $theme ); ?>
+                        </div>
+                        <div class="wp-full-overlay-main">
+                                <iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe>
+                        </div>
+                </div>
+                <?php
+        }
+
+        /*
+         * Prints the info for a theme (to be used in the theme installer modal).
+         *
+         * @param object $theme - A WordPress.org Theme API object.
+         */
+        function install_theme_info( $theme ) {
+                global $themes_allowedtags;
+
+                if ( empty( $theme ) )
+                        return;
+
+                $name = wp_kses( $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' ) );
+
+                ?>
+                <div class="install-theme-info">
+                        <a class="theme-install button-primary" href="<?php echo wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ); ?>"><?php _e( 'Install' ); ?></a>
+                        <h3 class="theme-name"><?php echo $name; ?></h3>
+                        <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
+                        <?php if ( isset( $theme->screenshot_url ) ): ?>
+                                <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" />
+                        <?php endif; ?>
+                        <div class="theme-rating" title="<?php echo esc_attr( $num_ratings ); ?>">
+                                <div style="width:<?php echo esc_attr( intval( $theme->rating ) . 'px' ); ?>;"></div>
+                        </div>
+                        <div class="theme-version">
+                                <strong><?php _e('Version:') ?> </strong>
+                                <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
+                        </div>
+                        <div class="theme-description">
+                                <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
+                        </div>
+                        <input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" />
+                </div>
+                <?php
+        }
+
</ins><span class="cx">         /**
</span><span class="cx">          * Send required variables to JavaScript land
</span><span class="cx">          *
</span></span></pre></div>
<a id="trunkwpadminincludesthemeinstallphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/theme-install.php (20139 => 20140)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/theme-install.php        2012-03-07 17:45:21 UTC (rev 20139)
+++ trunk/wp-admin/includes/theme-install.php        2012-03-07 18:24:34 UTC (rev 20140)
</span><span class="lines">@@ -131,68 +131,11 @@
</span><span class="cx"> * Prints a theme on the Install Themes pages.
</span><span class="cx"> *
</span><span class="cx"> * @param object $theme An object that contains theme data returned by the WordPress.org API.
</span><del>- *
- * Example theme data:
- * object(stdClass)[59]
- * public 'name' => 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 <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' (length=214)
- * public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
</del><span class="cx"> */
</span><span class="cx"> function display_theme( $theme ) {
</span><del>-        global $themes_allowedtags;
</del><ins>+        global $wp_list_table;
</ins><span class="cx">
</span><del>-        if ( empty( $theme ) )
-                return;
-
-        $name = wp_kses( $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 ) );
-
-        $preview_url = add_query_arg( 'theme_preview', '1' );
-        $preview_title = sprintf( __('Preview &#8220;%s&#8221;'), $name );
-
-        $install_url = add_query_arg( array(
-                'action' => 'install-theme',
-                'theme' => $theme->slug,
-        ), self_admin_url( 'update.php' ) );
-
-        ?>
-        <a class="screenshot" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
-                <img src='<?php echo esc_url( $theme->screenshot_url ); ?>' width='150' />
-        </a>
-
-        <h3><?php
-                /* translators: 1: theme name, 2: author name */
-                printf( __( '%1$s <span>by %2$s</span>' ), $name, $author );
-        ?></h3>
-
-        <div class="install-theme-info">
-                <a class="theme-install button-primary" href="<?php echo wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ); ?>"><?php _e( 'Install' ); ?></a>
-                <h3 class="theme-name"><?php echo $name; ?></h3>
-                <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
-                <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" />
-                <div class="theme-rating" title="<?php echo esc_attr( $num_ratings ); ?>">
-                        <div style="width:<?php echo esc_attr( intval( $theme->rating ) . 'px' ); ?>;"></div>
-                </div>
-                <div class="theme-version">
-                        <strong><?php _e('Version:') ?> </strong>
-                        <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
-                </div>
-                <div class="theme-description">
-                        <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
-                </div>
-                <input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" />
-        </div>
-        <?php
</del><ins>+        return $wp_list_table->single_row( $theme );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -216,104 +159,13 @@
</span><span class="cx"> * @since 2.8.0
</span><span class="cx"> */
</span><span class="cx"> function install_theme_information() {
</span><del>-        //TODO: This function needs a LOT of UI work :)
-        global $tab, $themes_allowedtags;
</del><ins>+        global $tab, $themes_allowedtags, $wp_list_table;
</ins><span class="cx">
</span><del>-        $api = themes_api('theme_information', array('slug' => stripslashes( $_REQUEST['theme'] ) ));
</del><ins>+        $theme = themes_api( 'theme_information', array( 'slug' => stripslashes( $_REQUEST['theme'] ) ) );
</ins><span class="cx">
</span><del>-        if ( is_wp_error($api) )
-                wp_die($api);
</del><ins>+        if ( is_wp_error( $theme ) )
+                wp_die( $theme );
</ins><span class="cx">
</span><del>-        // Sanitize HTML
-        foreach ( (array)$api->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 ) {
-                if ( isset($api->$key) )
-                        $api->$key = wp_kses($api->$key, $themes_allowedtags);
-        }
-
-        iframe_header( __('Theme Install') );
-
-        if ( empty($api->download_link) ) {
-                echo '<div id="message" class="error"><p>' . __('<strong>ERROR:</strong> This theme is currently not available. Please try again later.') . '</p></div>';
-                iframe_footer();
-                exit;
-        }
-
-        if ( !empty($api->tested) && version_compare($GLOBALS['wp_version'], $api->tested, '>') )
-                echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
-        else if ( !empty($api->requires) && version_compare($GLOBALS['wp_version'], $api->requires, '<') )
-                echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has not been marked as <strong>compatible</strong> with your version of WordPress.') . '</p></div>';
-
-        // Default to a "new" theme
-        $type = 'install';
-        // Check to see if this theme is known to be installed, and has an update awaiting it.
-        $update_themes = get_site_transient('update_themes');
-        if ( is_object($update_themes) && isset($update_themes->response) ) {
-                foreach ( (array)$update_themes->response as $theme_slug => $theme_info ) {
-                        if ( $theme_slug === $api->slug ) {
-                                $type = 'update_available';
-                                $update_file = $theme_slug;
-                                break;
-                        }
-                }
-        }
-
-        $theme = wp_get_theme( $api->slug );
-        if ( is_a( $theme, 'WP_Theme' ) ) {
-                switch ( version_compare( $theme->get('Version'), $api->version ) ) {
-                        case 0; // equal
-                                $type = 'latest_installed';
-                        case 1: // installed theme > api version
-                                $type = 'newer_installed';
-                                $newer_version = $theme->get('Version');
-                }
-        }
-?>
-
-<div class='available-theme'>
-<img src='<?php echo esc_url($api->screenshot_url) ?>' width='300' class="theme-preview-img" />
-<h3><?php echo $api->name; ?></h3>
-<p><?php printf(__('by %s'), $api->author); ?></p>
-<p><?php printf(__('Version: %s'), $api->version); ?></p>
-
-<?php
-$buttons = '<a class="button" id="cancel" href="#" onclick="tb_close();return false;">' . __('Cancel') . '</a> ';
-
-switch ( $type ) {
-default:
-case 'install':
-        if ( current_user_can('install_themes') ) :
-        $buttons .= '<a class="button-primary" id="install" href="' . wp_nonce_url(self_admin_url('update.php?action=install-theme&theme=' . $api->slug), 'install-theme_' . $api->slug) . '" target="_parent">' . __('Install Now') . '</a>';
-        endif;
-        break;
-case 'update_available':
-        if ( current_user_can('update_themes') ) :
-        $buttons .= '<a class="button-primary" id="install"        href="' . wp_nonce_url(self_admin_url('update.php?action=upgrade-theme&theme=' . $update_file), 'upgrade-theme_' . $update_file) . '" target="_parent">' . __('Install Update Now') . '</a>';
-        endif;
-        break;
-case 'newer_installed':
-        if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
-        ?><p><?php printf(__('Newer version (%s) is installed.'), $newer_version); ?></p><?php
-        endif;
-        break;
-case 'latest_installed':
-        if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
-        ?><p><?php _e('This version is already installed.'); ?></p><?php
-        endif;
-        break;
-} ?>
-<br class="clear" />
-</div>
-
-<p class="action-button">
-<?php echo $buttons; ?>
-<br class="clear" />
-</p>
-
-<?php
-        iframe_footer();
-        exit;
</del><ins>+        $wp_list_table->theme_installer_single( $theme );
</ins><span class="cx"> }
</span><span class="cx"> add_action('install_themes_pre_theme-information', 'install_theme_information');
</span></span></pre></div>
<a id="trunkwpadminjsthemedevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/theme.dev.js (20139 => 20140)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/theme.dev.js        2012-03-07 17:45:21 UTC (rev 20139)
+++ trunk/wp-admin/js/theme.dev.js        2012-03-07 18:24:34 UTC (rev 20140)
</span><span class="lines">@@ -22,7 +22,7 @@
</span><span class="cx">                 event.preventDefault();
</span><span class="cx">         });
</span><span class="cx">
</span><del>-        $('#availablethemes').on( 'click', '.available-theme', function( event ) {
</del><ins>+        $('#availablethemes').on( 'click', '.installable-theme', function( event ) {
</ins><span class="cx">                 var src;
</span><span class="cx">
</span><span class="cx">                 info.html( $(this).find('.install-theme-info').html() );
</span></span></pre>
</div>
</div>
</body>
</html>