Make WordPress Core

Changeset 10656


Ignore:
Timestamp:
02/26/2009 11:35:38 PM (18 years ago)
Author:
ryan
Message:

More theme install tweaks. See #8652

File:
1 edited

Legend:

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

    r10655 r10656  
    3636function themes_api($action, $args = null) {
    3737
    38         if( is_array($args) )
     38        if ( is_array($args) )
    3939                $args = (object)$args;
    4040
     
    5252                        $res = unserialize($request['body']);
    5353                        if ( ! $res )
    54                                 $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
     54                        $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
    5555                }
    5656        }
     
    130130function install_themes_dashboard() {
    131131        ?>
    132         <p><?php _e('Search for themes by keyword, author, or tag.') ?></p>
     132<p><?php _e('Search for themes by keyword, author, or tag.') ?></p>
    133133
    134134        <?php install_theme_search_form('<a href="' . add_query_arg('show-help', !isset($_REQUEST['show-help'])) .'" onclick="jQuery(\'#search-help\').toggle(); return false;">' . __('[need help?]') . '</a>') ?>
    135         <div id="search-help" style="display: <?php echo isset($_REQUEST['show-help']) ? 'block' : 'none'; ?>;">
    136         <p>     <?php _e('You may search based on 3 criteria:') ?><br />
    137                 <?php _e('<strong>Term:</strong> Searches theme names and descriptions for the specified term') ?><br />
    138                 <?php _e('<strong>Tag:</strong> Searches for themes tagged as such') ?><br />
    139                 <?php _e('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') ?></p>
    140         </div>
    141 
    142         <h4><?php _e('Advanced Search') ?></h4>
    143         <p><?php _e('Tag filter goes here') ?></p>
    144 
    145         <h4><?php _e('Popular tags') ?></h4>
    146         <p><?php _e('You may also browse based on the most popular tags in the Theme Directory:') ?></p>
     135<div id="search-help" style="display: <?php echo isset($_REQUEST['show-help']) ? 'block' : 'none'; ?>;">
     136<p><?php _e('You may search based on 3 criteria:') ?><br />
     137        <?php _e('<strong>Term:</strong> Searches theme names and descriptions for the specified term') ?><br />
     138        <?php _e('<strong>Tag:</strong> Searches for themes tagged as such') ?><br />
     139        <?php _e('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') ?></p>
     140</div>
     141
     142<h4><?php _e('Advanced Search') ?></h4>
     143<p><?php _e('Tag filter goes here') ?></p>
     144
     145<h4><?php _e('Popular tags') ?></h4>
     146<p><?php _e('You may also browse based on the most popular tags in the Theme Directory:') ?></p>
    147147        <?php
    148148
     
    151151        //Set up the tags in a way which can be interprated by wp_generate_tag_cloud()
    152152        $tags = array();
    153         foreach ( (array)$api_tags as $tag )
     153        foreach ( (array)$api_tags as $tag ) {
    154154                $tags[ $tag['name'] ] = (object) array(
    155155                                                                'link' => clean_url( admin_url('theme-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
     
    157157                                                                'id' => sanitize_title_with_dashes($tag['name']),
    158158                                                                'count' => $tag['count'] );
     159        }
    159160        echo '<p>';
    160161        echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d theme'), 'multiple_text' => __('%d themes') ) );
     
    171172        $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
    172173
    173         ?><form id="search-themes" method="post" action="<?php echo admin_url('theme-install.php?tab=search') ?>">
    174                 <select name="type" id="typeselector">
    175                         <option value="term"<?php selected('term', $type) ?>><?php _e('Term') ?></option>
    176                         <option value="author"<?php selected('author', $type) ?>><?php _e('Author') ?></option>
    177                         <option value="tag"<?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
    178                 </select>
    179                 <input type="text" name="s" id="search-field" value="<?php echo attribute_escape($term) ?>" />
    180                 <input type="submit" name="search" value="<?php echo attribute_escape(__('Search')) ?>" class="button" />
    181         </form><?php
     174        ?>
     175<form id="search-themes" method="post"
     176        action="<?php echo admin_url('theme-install.php?tab=search') ?>"><select
     177        name="type" id="typeselector">
     178        <option value="term" <?php selected('term', $type) ?>><?php _e('Term') ?></option>
     179        <option value="author" <?php selected('author', $type) ?>><?php _e('Author') ?></option>
     180        <option value="tag" <?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
     181</select> <input type="text" name="s" id="search-field"
     182        value="<?php echo attribute_escape($term) ?>" /> <input type="submit"
     183        name="search" value="<?php echo attribute_escape(__('Search')) ?>"
     184        class="button" /></form>
     185        <?php
    182186}
    183187
     
    244248add_action('install_themes_upload', 'install_themes_upload', 10, 1);
    245249function install_themes_upload($page = 1) {
    246 ?>
    247         <h4><?php _e('Install a theme in .zip format') ?></h4>
    248         <p><?php _e('If you have a theme in a .zip format, You may install it by uploading it here.') ?></p>
    249         <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('theme-install.php?tab=do_upload') ?>">
    250                 <?php wp_nonce_field( 'theme-upload') ?>
    251                 <input type="file" name="themezip" />
    252                 <input type="submit" class="button" value="<?php _e('Install Now') ?>" />
    253         </form>
    254 <?php
     250        ?>
     251<h4><?php _e('Install a theme in .zip format') ?></h4>
     252<p><?php _e('If you have a theme in a .zip format, You may install it by uploading it here.') ?></p>
     253<form method="post" enctype="multipart/form-data"
     254        action="<?php echo admin_url('theme-install.php?tab=do_upload') ?>"><?php wp_nonce_field( 'theme-upload') ?>
     255<input type="file" name="themezip" /> <input type="submit"
     256        class="button" value="<?php _e('Install Now') ?>" /></form>
     257        <?php
     258}
     259
     260function display_theme($theme, $actions = null, $show_details = true) {
     261        global $themes_allowedtags;
     262
     263        //var_dump($theme);
     264
     265        $name = wp_kses($theme->name, $themes_allowedtags);
     266        $desc = wp_kses($theme->description, $themes_allowedtags);
     267        //if ( strlen($desc) > 30 )
     268        //      $desc =  substr($desc, 0, 30) . '<span class="dots">...</span><span>' . substr($desc, 30) . '</span>';
     269
     270        $preview_link = $theme->preview_url . '?TB_iframe=true&amp;width=600&amp;height=400';
     271        if ( empty($actions) ) {
     272                $actions = array();
     273                $actions[] = '<a href="' . admin_url('theme-install.php?tab=theme-information&amp;theme=' . $theme->slug .
     274                                                                                '&amp;TB_iframe=true&amp;width=600&amp;height=800') . '" class="thickbox onclick" title="' . attribute_escape(sprintf(__('Install "%s"'), $name)) . '">' . __('Install') . '</a>';
     275                $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview onclick previewlink" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>';
     276                $actions = apply_filters('theme_install_action_links', $actions, $theme);
     277        }
     278
     279        $actions = implode ( ' | ', $actions );
     280        ?>
     281<a class='thickbox thickbox-preview screenshot'
     282        href='<? echo clean_url($preview_link) ?>'
     283        title='<?php attribute_escape(sprintf(__('Preview "%s"'), $name)) ?>'>
     284<img src='<?php echo clean_url($theme->screenshot_url) ?>' width='150' />
     285</a>
     286<h3><?php echo $name ?></h3>
     287<span class='action-links'><?php echo $actions ?></span>
     288<p><?php echo $desc ?></p>
     289<?php if ( $show_details ) { ?>
     290<a href="#theme_detail" class="theme-detail hide-if-no-js" tabindex='4'><?php _e('Details') ?></a>
     291<div id="themedetaildiv" class="hide-if-js">
     292<p><strong><?php _e('Version:') ?></strong> <?php echo wp_kses($theme->version, $themes_allowedtags) ?></p>
     293<p><strong><?php _e('Author:') ?></strong> <?php echo wp_kses($theme->author, $themes_allowedtags) ?></p>
     294</div>
     295<?php }
     296        /*
     297         object(stdClass)[59]
     298         public 'name' => string 'Magazine Basic' (length=14)
     299         public 'slug' => string 'magazine-basic' (length=14)
     300         public 'version' => string '1.1' (length=3)
     301         public 'author' => string 'tinkerpriest' (length=12)
     302         public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36)
     303         public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68)
     304         public 'rating' => float 80
     305         public 'num_ratings' => int 1
     306         public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49)
     307         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)
     308         public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
     309         */
    255310}
    256311
     
    269324        $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
    270325        $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
    271 ?>
    272         <div class="tablenav">
    273                 <div class="alignleft actions">
    274 <?php do_action('install_themes_table_header'); ?>
    275                 </div>
    276 <?php
    277                 $url = clean_url($_SERVER['REQUEST_URI']);
    278                 if ( ! empty($term) )
    279                         $url = add_query_arg('s', $term, $url);
    280                 if ( ! empty($type) )
    281                         $url = add_query_arg('type', $type, $url);
    282 
    283                 $page_links = paginate_links( array(
     326        ?>
     327<div class="tablenav">
     328<div class="alignleft actions"><?php do_action('install_themes_table_header'); ?>
     329</div>
     330        <?php
     331        $url = clean_url($_SERVER['REQUEST_URI']);
     332        if ( ! empty($term) )
     333                $url = add_query_arg('s', $term, $url);
     334        if ( ! empty($type) )
     335                $url = add_query_arg('type', $type, $url);
     336
     337        $page_links = paginate_links( array(
    284338                        'base' => add_query_arg('paged', '%#%', $url),
    285339                        'format' => '',
     
    288342                        'total' => $totalpages,
    289343                        'current' => $page
    290                 ));
    291 
    292                 if ( $page_links )
    293                         echo "\t\t<div class='tablenav-pages'>$page_links</div>";
    294 ?>
    295                 <br class="clear" />
    296         </div>
    297         <table id="availablethemes" cellspacing="0" cellpadding="0">
    298                 <?php
    299                 $in_column = 0;
    300                 $rows = ceil(count($themes) / 3);
    301                 $i = 0;
    302                 for ( $row = 1; $row <= $rows; $row++ ) {
    303                         for ( $col = 1; $col <= 3; $col++ ) {
    304                                 $table[$row][$col] = $i;
    305                                 $i++;
    306                         }
     344        ));
     345
     346        if ( $page_links )
     347                echo "\t\t<div class='tablenav-pages'>$page_links</div>";
     348        ?> <br class="clear" />
     349</div>
     350<table id="availablethemes" cellspacing="0" cellpadding="0">
     351<?php
     352        $in_column = 0;
     353        $rows = ceil(count($themes) / 3);
     354        $i = 0;
     355        for ( $row = 1; $row <= $rows; $row++ ) {
     356                for ( $col = 1; $col <= 3; $col++ ) {
     357                        $table[$row][$col] = $i;
     358                        $i++;
    307359                }
    308 
    309                 foreach ( $table as $row => $cols ) {
    310 ?>
    311 <tr>
    312 <?php
    313                         foreach ( $cols as $col => $theme_index ) {
    314                                 $class = array('available-theme');
    315                                 if ( $row == 1 ) $class[] = 'top';
    316                                 if ( $col == 1 ) $class[] = 'left';
    317                                 if ( $row == $rows ) $class[] = 'bottom';
    318                                 if ( $col == 3 ) $class[] = 'right';
    319                                 $theme = $themes[$theme_index];
    320 ?>
    321         <td class="<?php echo join(' ', $class); ?>">
    322 <?php
    323                                         //var_dump($theme);
    324                        
    325                                 $name = wp_kses($theme->name, $themes_allowedtags);
    326                                 $desc = wp_kses($theme->description, $themes_allowedtags);
    327                                 //if ( strlen($desc) > 30 )
    328                                 //      $desc =  substr($desc, 0, 30) . '<span class="dots">...</span><span>' . substr($desc, 30) . '</span>';
    329 
    330                                 $preview_link = $theme->preview_url . '?TB_iframe=true&amp;width=600&amp;height=400';
    331                                 $action_links = array();
    332                                 $action_links[] = '<a href="' . admin_url('theme-install.php?tab=theme-information&amp;theme=' . $theme->slug .
    333                                                                         '&amp;TB_iframe=true&amp;width=600&amp;height=800') . '" class="thickbox onclick" title="' . attribute_escape(sprintf(__('Install "%s"'), $name)) . '">' . __('Install') . '</a>';
    334                                 $action_links[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview onclick previewlink" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>';
    335        
    336                                 $action_links = apply_filters('theme_install_action_links', $action_links, $theme);
    337                                 $actions = implode ( ' | ', $action_links );
    338 ?>
    339                                 <a class='thickbox thickbox-preview screenshot' href='<? echo clean_url($preview_link) ?>' title='<?php attribute_escape(sprintf(__('Preview "%s"'), $name)) ?>'>
    340                                 <img src='<?php echo clean_url($theme->screenshot_url) ?>' width='150' />
    341                                 </a>
    342                                 <h3><?php echo $name ?></h3>
    343                                 <span class='action-links'><?php echo $actions ?></span>
    344                                 <p><?php echo $desc ?></p>
    345                                 <a href="#theme_detail" class="theme-detail hide-if-no-js" tabindex='4'><?php _e('Details') ?></a>
    346                                 <div id="themedetaildiv" class="hide-if-js">
    347                                 <p><strong><?php _e('Version:') ?></strong> <?php echo wp_kses($theme->version, $themes_allowedtags) ?></p>
    348                                 <p><strong><?php _e('Author:') ?></strong> <?php echo wp_kses($theme->author, $themes_allowedtags) ?></p>
    349                                 </div>
    350 <?php
    351                         /*
    352                         object(stdClass)[59]
    353                           public 'name' => string 'Magazine Basic' (length=14)
    354                           public 'slug' => string 'magazine-basic' (length=14)
    355                           public 'version' => string '1.1' (length=3)
    356                           public 'author' => string 'tinkerpriest' (length=12)
    357                           public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36)
    358                           public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68)
    359                           public 'rating' => float 80
    360                           public 'num_ratings' => int 1
    361                           public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49)
    362                           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)
    363                           public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
    364                           */
    365 ?>
    366         </td>
    367 <?php } // end foreach $cols ?>
    368 </tr>
    369 <?php } // end foreach $table ?>
     360        }
     361
     362        foreach ( $table as $row => $cols ) {
     363        ?>
     364        <tr>
     365        <?php
     366        foreach ( $cols as $col => $theme_index ) {
     367                $class = array('available-theme');
     368                if ( $row == 1 ) $class[] = 'top';
     369                if ( $col == 1 ) $class[] = 'left';
     370                if ( $row == $rows ) $class[] = 'bottom';
     371                if ( $col == 3 ) $class[] = 'right';
     372                $theme = $themes[$theme_index];
     373                ?>
     374                <td class="<?php echo join(' ', $class); ?>"><?php
     375                        display_theme($theme);
     376                ?></td>
     377                <?php } // end foreach $cols ?>
     378        </tr>
     379        <?php } // end foreach $table ?>
    370380</table>
    371381
    372         <div class="tablenav">
    373                 <?php if ( $page_links )
    374                                 echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?>
    375                 <br class="clear" />
    376         </div>
     382<div class="tablenav"><?php if ( $page_links )
     383echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?> <br
     384        class="clear" />
     385</div>
    377386
    378387<?php
     
    395404                wp_die($api);
    396405
    397         //Sanitize HTML
     406        // Sanitize HTML
    398407        foreach ( (array)$api->sections as $section_name => $content )
    399408                $api->sections[$section_name] = wp_kses($content, $themes_allowedtags);
     
    402411
    403412        $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
    404         if( empty($section) || ! isset($api->sections[ $section ]) )
     413        if ( empty($section) || ! isset($api->sections[ $section ]) )
    405414                $section = array_shift( $section_titles = array_keys((array)$api->sections) );
    406415
    407416        iframe_header( __('Theme Install') );
    408         echo "<div id='$tab-header'>\n";
    409         echo "<ul id='sidemenu'>\n";
    410         foreach ( (array)$api->sections as $section_name => $content ) {
    411 
    412                 $title = $section_name;
    413                 $title = ucwords(str_replace('_', ' ', $title));
    414 
    415                 $class = ( $section_name == $section ) ? ' class="current"' : '';
    416                 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
    417                 $href = clean_url($href);
    418                 $san_title = attribute_escape(sanitize_title_with_dashes($title));
    419                 echo "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
    420         }
    421         echo "</ul>\n";
    422         echo "</div>\n";
     417
     418        if ( version_compare($GLOBALS['wp_version'], $api->tested, '>') )
     419                echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
     420        else if ( version_compare($GLOBALS['wp_version'], $api->requires, '<') )
     421                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>';
     422
     423        if ( empty($api->download_link) ) {
     424                // No go
     425        }
    423426        ?>
    424         <div class="alignright fyi">
    425                 <?php if ( ! empty($api->download_link) ) : ?>
    426                 <p class="action-button">
    427                 <?php
    428                         //Default to a "new" theme
    429                         $type = 'install';
    430                         //Check to see if this theme is known to be installed, and has an update awaiting it.
    431                         $update_themes = get_option('update_themes');
    432                         foreach ( (array)$update_themes->response as $file => $theme ) {
    433                                 if ( $theme->slug === $api->slug ) {
    434                                         $type = 'update_available';
    435                                         $update_file = $file;
    436                                         break;
    437                                 }
    438                         }
    439                         /*if ( 'install' == $type && is_dir( WP_PLUGIN_DIR  . '/' . $api->slug ) ) {
    440                                 $installed_theme = get_themes('/' . $api->slug);
    441                                 if ( ! empty($installed_theme) ) {
    442                                         $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
    443                                         if ( version_compare($api->version, $installed_theme[ $key ]['Version'], '>') ){
    444                                                 $type = 'latest_installed';
    445                                         } elseif ( version_compare($api->version, $installed_theme[ $key ]['Version'], '<') ) {
    446                                                 $type = 'newer_installed';
    447                                                 $newer_version = $installed_theme[ $key ]['Version'];
    448                                         } else {
    449                                                 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
    450                                                 delete_option('update_themes');
    451                                                 $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
    452                                                 $type = 'update_available';
    453                                         }
    454                                 }
    455                         }*/
    456 
    457                         switch ( $type ) :
    458                                 default:
    459                                 case 'install':
    460                                         if ( current_user_can('install_themes') ) :
    461                                 ?><a href="<?php echo wp_nonce_url(admin_url('theme-install.php?tab=install&theme=' . $api->slug), 'install-theme_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php
    462                                         endif;
    463                                 break;
    464                                 case 'update_available':
    465                                         if ( current_user_can('update_themes') ) :
    466                                                 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-theme&theme=' . $update_file), 'upgrade-theme_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php
    467                                         endif;
    468                                 break;
    469                                 case 'newer_installed':
    470                                         if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
    471                                         ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
    472                                         endif;
    473                                 break;
    474                                 case 'latest_installed':
    475                                         if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
    476                                         ?><a><?php _e('Latest Version Installed') ?></a><?php
    477                                         endif;
    478                                 break;
    479                         endswitch; ?>
    480                 </p>
    481                 <?php endif; ?>
    482                 <h2 class="mainheader"><?php _e('FYI') ?></h2>
    483                 <ul>
    484 <?php if ( ! empty($api->version) ) : ?>
    485                         <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
    486 <?php endif; if ( ! empty($api->author) ) : ?>
    487                         <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
    488 <?php endif; if ( ! empty($api->last_updated) ) : ?>
    489                         <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
    490                                                         printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
    491 <?php endif; if ( ! empty($api->requires) ) : ?>
    492                         <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
    493 <?php endif; if ( ! empty($api->tested) ) : ?>
    494                         <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
    495 <?php endif; if ( ! empty($api->downloaded) ) : ?>
    496                         <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
    497 <?php endif; if ( ! empty($api->slug) ) : ?>
    498                         <li><a target="_blank" href="http://wordpress.org/extend/themes/<?php echo $api->slug ?>/"><?php _e('WordPress.org Theme Page &#187;') ?></a></li>
    499 <?php endif; if ( ! empty($api->homepage) ) : ?>
    500                         <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Theme Homepage  &#187;') ?></a></li>
    501 <?php endif; ?>
    502                 </ul>
    503                 <h2><?php _e('Average Rating') ?></h2>
    504                 <div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?>">
    505                         <div class="star star-rating" style="width: <?php echo attribute_escape($api->rating) ?>px"></div>
    506                         <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
    507                         <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
    508                         <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
    509                         <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
    510                         <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
    511                 </div>
    512                 <small><?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?></small>
    513         </div>
    514         <div id="section-holder" class="wrap">
     427
     428<p class="action-button"><?php
     429        // Default to a "new" theme
     430        $type = 'install';
     431        // Check to see if this theme is known to be installed, and has an update awaiting it.
     432        $update_themes = get_option('update_themes');
     433        foreach ( (array)$update_themes->response as $file => $theme ) {
     434                if ( $theme->slug === $api->slug ) {
     435                        $type = 'update_available';
     436                $update_file = $file;
     437                break;
     438        }
     439}
     440
     441$action = '';
     442switch ( $type ) {
     443        default:
     444        case 'install':
     445                if ( current_user_can('install_themes') ) :
     446                        $action = '<a class="button" href="' . wp_nonce_url(admin_url('theme-install.php?tab=install&theme=' . $api->slug), 'install-theme_' . $api->slug) . '" target="_parent">' . __('Install Now') . '</a>';
     447        endif;
     448        break;
     449case 'update_available':
     450        if ( current_user_can('update_themes') ) :
     451        ?><a class="button"
     452        href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-theme&theme=' . $update_file), 'upgrade-theme_' . $update_file) ?>"
     453        target="_parent"><?php _e('Install Update Now') ?></a><?php
     454        endif;
     455        break;
     456case 'newer_installed':
     457        if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
     458        ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
     459        endif;
     460        break;
     461case 'latest_installed':
     462        if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
     463        ?><a><?php _e('Latest Version Installed') ?></a><?php
     464        endif;
     465        break;
     466} ?></p>
     467<div class='available-theme'>
     468<?php
     469display_theme($api, array($action), false);
     470?>
     471</div>
    515472        <?php
    516                 if ( version_compare($GLOBALS['wp_version'], $api->tested, '>') )
    517                         echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
    518                 else if ( version_compare($GLOBALS['wp_version'], $api->requires, '<') )
    519                         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>';
    520                 foreach ( (array)$api->sections as $section_name => $content ) {
    521                         $title = $section_name;
    522                         $title[0] = strtoupper($title[0]);
    523                         $title = str_replace('_', ' ', $title);
    524 
    525                         $content = links_add_base_url($content, 'http://wordpress.org/extend/themes/' . $api->slug . '/');
    526                         $content = links_add_target($content, '_blank');
    527 
    528                         $san_title = attribute_escape(sanitize_title_with_dashes($title));
    529 
    530                         $display = ( $section_name == $section ) ? 'block' : 'none';
    531 
    532                         echo "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
    533                         echo "\t\t<h2 class='long-header'>$title</h2>";
    534                         echo $content;
    535                         echo "\t</div>\n";
    536                 }
    537         echo "</div>\n";
    538 
    539473        iframe_footer();
    540474        exit;
    541475}
    542 
    543476
    544477add_action('install_themes_do_upload', 'upload_theme');
     
    631564        if ( $wp_filesystem->errors->get_error_code() ) {
    632565                foreach ( $wp_filesystem->errors->get_error_messages() as $message )
    633                         show_message($message);
     566                show_message($message);
    634567                return;
    635568        }
     
    645578
    646579                $install_actions = apply_filters('install_theme_complete_actions', array(
    647                         //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&amp;theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . attribute_escape(__('Activate this theme')) . '" target="_parent">' . __('Activate Theme') . '</a>',
     580                //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&amp;theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . attribute_escape(__('Activate this theme')) . '" target="_parent">' . __('Activate Theme') . '</a>',
    648581                        'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . attribute_escape(__('Goto themes page')) . '" target="_parent">' . __('Return to Themes page') . '</a>'
    649                                                         ), $theme_information, $theme_file);
    650                 if ( ! empty($install_actions) )
     582                        ), $theme_information, $theme_file);
     583                        if ( ! empty($install_actions) )
    651584                        show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
    652585        }
     
    687620        if ( $wp_filesystem->errors->get_error_code() ) {
    688621                foreach ( $wp_filesystem->errors->get_error_messages() as $message )
    689                         show_message($message);
     622                show_message($message);
    690623                return;
    691624        }
     
    701634
    702635                $install_actions = apply_filters('install_theme_complete_actions', array(
    703                                                         //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&amp;theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . __('Activate this theme') . '" target="_parent">' . __('Activate Theme') . '</a>',
     636                //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&amp;theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . __('Activate this theme') . '" target="_parent">' . __('Activate Theme') . '</a>',
    704637                                                        'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . __('Goto themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'
    705638                                                        ), array(), $theme_file);
    706                 if ( ! empty($install_actions) )
    707                         show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
     639                                                        if ( ! empty($install_actions) )
     640                                                        show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
    708641        }
    709642}
     
    734667                return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
    735668
    736         //Get the base theme folder
     669        // Get the base theme folder
    737670        $themes_dir = $wp_filesystem->wp_themes_dir();
    738671        if ( empty($themes_dir) )
    739672                return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress Theme directory.'));
    740673
    741         //And the same for the Content directory.
     674        // And the same for the Content directory.
    742675        $content_dir = $wp_filesystem->wp_content_dir();
    743         if( empty($content_dir) )
     676        if ( empty($content_dir) )
    744677                return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
    745678
     
    778711        $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
    779712
    780         if( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {
     713        if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {
    781714                $wp_filesystem->delete($working_dir, true);
    782715                return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
     
    797730        $wp_filesystem->delete($working_dir, true);
    798731
    799         if( empty($filelist) )
     732        if ( empty($filelist) )
    800733                return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup.
    801734
    802 
    803 //TODO: TODO: TODO
     735        //TODO: TODO: TODO
    804736        $stylesheet = $filelist[0];
    805 //      $theme = get_themes('/' . $folder); //Ensure to pass with leading slash //TODO: TODO: TODO
    806 //      $themefiles = array_keys($theme); //Assume the requested theme is the first in the list
     737        //      $theme = get_themes('/' . $folder); //Ensure to pass with leading slash //TODO: TODO: TODO
     738        //      $themefiles = array_keys($theme); //Assume the requested theme is the first in the list
    807739
    808740        //Return the theme files name.
     
    842774        //And the same for the Content directory.
    843775        $content_dir = $wp_filesystem->wp_content_dir();
    844         if( empty($content_dir) )
     776        if ( empty($content_dir) )
    845777                return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
    846778
     
    873805        $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
    874806
    875         if( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {
     807        if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {
    876808                $wp_filesystem->delete($working_dir, true);
    877809                return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
    878810        }
    879 
     811       
    880812        apply_filters('install_feedback', __('Installing the theme'));
    881813        // Copy new version of theme into place.
     
    892824        $wp_filesystem->delete($working_dir, true);
    893825
    894         if( empty($filelist) )
     826        if ( empty($filelist) )
    895827                return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup.
    896828
    897 //TODO TODO TODO
     829        //TODO TODO TODO
    898830        $stylesheet = $filelist[0];
    899 //      $theme = get_themes('/' . $folder); //Ensure to pass with leading slash
    900 //      $themefiles = array_keys($theme); //Assume the requested theme is the first in the list
     831        //      $theme = get_themes('/' . $folder); //Ensure to pass with leading slash
     832        //      $themefiles = array_keys($theme); //Assume the requested theme is the first in the list
    901833
    902834        //Return the theme files name.
Note: See TracChangeset for help on using the changeset viewer.