WordPress.org

Make WordPress Core

Changeset 10883


Ignore:
Timestamp:
04/07/2009 09:44:41 AM (9 years ago)
Author:
azaozz
Message:

Theme install: replace 'popular tags' section with feature filter, props josephscott, see #8652

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/colors-classic.css

    r10872 r10883  
    15831583}
    15841584
    1585 p.popular-tags {
     1585.popular-tags,
     1586.feature-filter {
    15861587    background-color: #FFFFFF;
    15871588    border-color: #DFDFDF;
  • trunk/wp-admin/css/colors-fresh.css

    r10872 r10883  
    15831583}
    15841584
    1585 p.popular-tags {
     1585.popular-tags,
     1586.feature-filter {
    15861587    background-color: #FFFFFF;
    15871588    border-color: #DFDFDF;
  • trunk/wp-admin/css/ie.css

    r10869 r10883  
    349349    border: 1px solid #DFDFDF;
    350350}
     351
     352* html .feature-filter .feature-group li {
     353    width: 145px;
     354}
  • trunk/wp-admin/css/theme-install.css

    r10823 r10883  
    112112}
    113113
     114.feature-filter {
     115    -moz-border-radius: 8px;
     116    -khtml-border-radius: 8px;
     117    -webkit-border-radius: 8px;
     118    border-radius: 8px;
     119    border-width: 1px;
     120    border-style: solid;
     121    padding: 8px 12px 0;
     122    margin-bottom: 10px;
     123}
    114124
     125.feature-filter .feature-group {
     126    float: left;
     127    margin-bottom: 20px;
     128    width: 725px;
     129}
     130
     131.feature-filter .feature-name {
     132    float: left;
     133    text-align: right;
     134    width: 65px;
     135}
     136
     137.feature-filter .feature-group li {
     138    display: inline;
     139    float: left;
     140    list-style-type: none;
     141    padding-right: 25px;
     142    min-width: 145px;
     143}
  • trunk/wp-admin/includes/theme-install.php

    r10823 r10883  
    6767
    6868/**
    69  * Retrieve popular WordPress theme tags.
    70  *
    71  * @since 2.8.0
    72  *
    73  * @param array $args
     69 * Retrive list of WordPress theme features (aka theme tags)
     70 *
     71 * @since 2.8.0
     72 *
    7473 * @return array
    7574 */
    76 function install_themes_popular_tags( $args = array() ) {
    77     global $theme_field_defaults;
    78     if ( !$cache = get_option('wporg_theme_popular_tags') )
    79         add_option('wporg_theme_popular_tags', array(), '', 'no'); ///No autoload.
    80 
    81     if ( $cache && $cache->timeout + 3 * 60 * 60 > time() )
     75function install_themes_feature_list( ) {
     76    if ( !$cache = get_option( 'wporg_theme_feature_list' ) )
     77        add_option( 'wporg_theme_feature_list', array( ), '', 'no' );
     78
     79    if ( $cache && $cache->timeout +3 * 60 * 60 > time( ) )
    8280        return $cache->cached;
    8381
    84     $args['fields'] = $theme_field_defaults;
    85 
    86     $tags = themes_api('hot_tags', $args);
    87 
    88     if ( is_wp_error($tags) )
    89         return $tags;
    90 
    91     $cache = (object) array('timeout' => time(), 'cached' => $tags);
    92 
    93     update_option('wporg_theme_popular_tags', $cache);
    94 
    95     return $tags;
     82    $feature_list = themes_api( 'feature_list', array( ) );
     83    if ( is_wp_error( $feature_list ) )
     84        return $features;
     85
     86    $cache = (object) array( 'timeout' => time( ), 'cached' => $feature_list );
     87    update_option( 'wporg_theme_feature_list', $cache );
     88
     89    return $feature_list;
    9690}
    9791
    9892add_action('install_themes_search', 'install_theme_search', 10, 1);
    9993/**
    100  * Display theme search results and display as tag cloud.
     94 * Display theme search results
    10195 *
    10296 * @since 2.8.0
     
    128122    $args['fields'] = $theme_field_defaults;
    129123
     124    if ( !empty( $_POST['features'] ) ) {
     125        $terms = $_POST['features'];
     126        $terms = array_map( 'trim', $terms );
     127        $terms = array_map( 'sanitize_title_with_dashes', $terms );
     128        $args['tag'] = $terms;
     129        $_REQUEST['s'] = implode( ',', $terms );
     130        $_REQUEST['type'] = 'tag';
     131    }
     132
    130133    $api = themes_api('query_themes', $args);
    131134
     
    138141}
    139142
    140 add_action('install_themes_dashboard', 'install_themes_dashboard');
    141 function install_themes_dashboard() {
     143/**
     144 * Display search form for searching themes.
     145 *
     146 * @since 2.8.0
     147 */
     148function install_theme_search_form() {
     149    $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
     150    $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    142151    ?>
    143152<p class="install-help"><?php _e('Search for themes by keyword, author, or tag.') ?></p>
    144153
    145     <?php install_theme_search_form(); ?>
    146 
    147 <h4><?php _e('Popular tags') ?></h4>
    148 <p class="install-help"><?php _e('You may also browse based on the most popular tags in the Theme Directory:') ?></p>
     154<form id="search-themes" method="post" action="<?php echo admin_url( 'theme-install.php?tab=search' ); ?>">
     155    <select name="type" id="typeselector">
     156    <option value="term" <?php selected('term', $type) ?>><?php _e('Term'); ?></option>
     157    <option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option>
     158    <option value="tag" <?php selected('tag', $type) ?>><?php _e('Tag'); ?></option>
     159    </select>
     160    <input type="text" name="s" class="search-input" size="30" value="<?php echo attribute_escape($term) ?>" />
     161    <input type="submit" name="search" value="<?php echo attribute_escape(__('Search')); ?>" class="button" />
     162</form>
     163<?php
     164}
     165
     166add_action('install_themes_dashboard', 'install_themes_dashboard');
     167/**
     168 * Display tags filter for themes.
     169 *
     170 * @since 2.8.0
     171 */
     172function install_themes_dashboard() {
     173    install_theme_search_form();
     174?>
     175<h4><?php _e('Feature Filter') ?></h4>
     176<form method="post" action="<?php echo admin_url( 'theme-install.php?tab=search' ); ?>">
     177<p class="install-help"><?php _e('Find a theme based on specific features') ?></p>
    149178    <?php
    150 
    151     $api_tags = install_themes_popular_tags();
    152 
    153     //Set up the tags in a way which can be interprated by wp_generate_tag_cloud()
    154     $tags = array();
    155     foreach ( (array)$api_tags as $tag ) {
    156         $tags[ $tag['name'] ] = (object) array(
    157                                 'link' => clean_url( admin_url('theme-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
    158                                 'name' => $tag['name'],
    159                                 'id' => sanitize_title_with_dashes($tag['name']),
    160                                 'count' => $tag['count'] );
    161     }
    162     echo '<p class="popular-tags">';
    163     echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d theme'), 'multiple_text' => __('%d themes') ) );
    164     echo '</p><br class="clear" />';
    165 }
    166 
    167 /**
    168  * Display search form for searching themes.
    169  *
    170  * @since 2.8.0
    171  */
    172 function install_theme_search_form(){
    173     $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
    174     $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
    175 
    176     ?>
    177 <form id="search-themes" method="post"
    178     action="<?php echo admin_url('theme-install.php?tab=search') ?>"><select
    179     name="type" id="typeselector">
    180     <option value="term" <?php selected('term', $type) ?>><?php _e('Term') ?></option>
    181     <option value="author" <?php selected('author', $type) ?>><?php _e('Author') ?></option>
    182     <option value="tag" <?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
    183 </select> <input type="text" name="s" class="search-input"
    184     value="<?php echo attribute_escape($term) ?>" /> <input type="submit"
    185     name="search" value="<?php echo attribute_escape(__('Search')) ?>"
    186     class="button" /></form>
    187     <?php
     179    $feature_list = install_themes_feature_list( );
     180    echo '<div class="feature-filter">';
     181
     182    foreach ( (array) $feature_list as $feature_name => $features ) {
     183        $html_safe['feature_name'] = wp_specialchars( $feature_name );
     184        echo '<div class="feature-name">' . $html_safe['feature_name'] . '</div>';
     185
     186        echo '<ol style="float: left; width: 725px;" class="feature-group">';
     187        foreach ( $features as $feature ) {
     188            $html_safe['feature'] = wp_specialchars( $feature );
     189?>
     190
     191<li>
     192    <input type="checkbox" name="features[<?php echo $html_safe['feature']; ?>]" id="feature-id-<?php echo $html_safe['feature']; ?>" value="<?php echo $html_safe['feature']; ?>">
     193    <label for="feature-id-<?php echo $html_safe['feature']; ?>"><?php echo $html_safe['feature']; ?></label>
     194</li>
     195
     196<?php   } ?>
     197</ol>
     198<br class="clear" />
     199<?php
     200    } ?>
     201
     202</div>
     203<br class="clear" />
     204<input type="submit" name="search" value="<?php echo attribute_escape(__('Find Themes')); ?>" class="button" />
     205</form>
     206<?php
    188207}
    189208
     
    202221    if ( is_wp_error($api) )
    203222        wp_die($api);
    204     display_themes($api->themes, $api->info['page'], $api->info['pages']);
    205 }
    206 
    207 add_action('install_thems_popular', 'install_themes_popular', 10, 1);
    208 /**
    209  * Display popular themes.
    210  *
    211  * @since 2.8.0
    212  *
    213  * @param string $page
    214  */
    215 function install_themes_popular($page = 1) {
    216     global $theme_field_defaults;
    217     $args = array('browse' => 'popular', 'page' => $page, 'fields' => $theme_field_defaults);
    218     $api = themes_api('query_themes', $args);
    219223    display_themes($api->themes, $api->info['page'], $api->info['pages']);
    220224}
     
    351355    ?>
    352356<div class="tablenav">
    353 <div class="alignleft actions"><?php do_action('install_themes_table_header'); ?>
    354 </div>
     357<div class="alignleft actions"><?php do_action('install_themes_table_header'); ?></div>
    355358    <?php
    356359    $url = clean_url($_SERVER['REQUEST_URI']);
Note: See TracChangeset for help on using the changeset viewer.