Make WordPress Core

Ticket #8652: theme-install-feature-filter.diff

File theme-install-feature-filter.diff, 7.8 KB (added by josephscott, 16 years ago)

Replace 'popular tags' section with feature filter

  • wp-admin/includes/theme-install.php

     
    6666}
    6767
    6868/**
    69  * Retrieve popular WordPress theme tags.
     69 * Retrive list of WordPress theme features (aka theme tags)
    7070 *
    7171 * @since 2.8.0
    7272 *
    73  * @param array $args
    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.
     75function install_themes_feature_list( ) {
     76        if ( !$cache = get_option( 'wporg_theme_feature_list' ) )
     77                add_option( 'wporg_theme_feature_list', array( ), '', 'no' );
    8078
    81         if ( $cache && $cache->timeout + 3 * 60 * 60 > time() )
     79        if ( $cache && $cache->timeout +3 * 60 * 60 > time( ) )
    8280                return $cache->cached;
    8381
    84         $args['fields'] = $theme_field_defaults;
     82        $feature_list = themes_api( 'feature_list', array( ) );
     83        if ( is_wp_error( $feature_list ) )
     84                return $features;
    8585
    86         $tags = themes_api('hot_tags', $args);
     86        $cache = (object) array( 'timeout' => time( ), 'cached' => $feature_list );
     87        update_option( 'wporg_theme_feature_list', $cache );
    8788
    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;
     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
    10397 *
     
    127121        $args['page'] = $page;
    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
    132135        if ( is_wp_error($api) )
     
    139142
    140143add_action('install_themes_dashboard', 'install_themes_dashboard');
    141144function install_themes_dashboard() {
     145        $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
     146        $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    142147        ?>
    143148<p class="install-help"><?php _e('Search for themes by keyword, author, or tag.') ?></p>
    144149
    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>
    149         <?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         ?>
    177150<form id="search-themes" method="post"
    178         action="<?php echo admin_url('theme-install.php?tab=search') ?>"><select
     151        action="<?php echo admin_url( 'theme-install.php?tab=search' ); ?>"><select
    179152        name="type" id="typeselector">
    180153        <option value="term" <?php selected('term', $type) ?>><?php _e('Term') ?></option>
    181154        <option value="author" <?php selected('author', $type) ?>><?php _e('Author') ?></option>
    182155        <option value="tag" <?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
    183 </select> <input type="text" name="s" class="search-input"
     156</select> <input type="text" name="s" class="search-input" size="30"
    184157        value="<?php echo attribute_escape($term) ?>" /> <input type="submit"
    185158        name="search" value="<?php echo attribute_escape(__('Search')) ?>"
    186         class="button" /></form>
     159        class="button" />
     160
     161<h4><?php _e('Feature Filter') ?></h4>
     162<p class="install-help"><?php _e('Find a theme based on specific features') ?></p>
    187163        <?php
     164        $feature_list = install_themes_feature_list( );
     165        echo '<div class="feature-filter">';
     166
     167        foreach ( (array) $feature_list as $feature_name => $features ) {
     168                $html_safe['feature_name'] = wp_specialchars( $feature_name );
     169                echo '<div class="feature-name">' . $html_safe['feature_name'] . '</div>';
     170
     171                echo '<ol style="float: left; width: 725px;" class="feature-group">';
     172                foreach ( $features as $feature ) {
     173                        $html_safe['feature'] = wp_specialchars( $feature );
     174?>
     175
     176<li>
     177        <input type="checkbox" name="features[<?php echo $html_safe['feature']; ?>]" id="feature-id-<?php echo $html_safe['feature']; ?>" value="<?php echo $html_safe['feature']; ?>">
     178        <label for="feature-id-<?php echo $html_safe['feature']; ?>"><?php echo $html_safe['feature']; ?></label>
     179</li>
     180
     181<?php
     182                }
     183                echo '</ol>';
     184
     185                echo '<br class="clear" />';
     186                echo '<hr />';
     187        }
     188
     189        echo '</div>';
     190        echo '<br class="clear" />';
     191        echo '</form>';
    188192}
    189193
    190194add_action('install_themes_featured', 'install_themes_featured', 10, 1);
     
    204208        display_themes($api->themes, $api->info['page'], $api->info['pages']);
    205209}
    206210
    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);
    219         display_themes($api->themes, $api->info['page'], $api->info['pages']);
    220 }
    221 
    222211add_action('install_themes_new', 'install_themes_new', 10, 1);
    223212/**
    224213 * Display new themes/
  • wp-admin/css/colors-fresh.css

     
    15821582        background-color: #eee;
    15831583}
    15841584
    1585 p.popular-tags {
     1585.feature-filter {
     1586        -moz-border-radius-bottomleft:8px;
     1587        -moz-border-radius-bottomright:8px;
     1588        -moz-border-radius-topleft:8px;
     1589        -moz-border-radius-topright:8px;
    15861590        background-color: #FFFFFF;
    1587         border-color: #DFDFDF;
     1591        border: 1px solid #DFDFDF;
     1592        padding: 8px 12px 12px;
    15881593}
    15891594
     1595.feature-filter .feature-name {
     1596        float: left;
     1597        text-align: right;
     1598        width: 65px;
     1599}
     1600
     1601.feature-filter .feature-group li {
     1602        display: inline;
     1603        float: left;
     1604        list-style-type: none;
     1605        padding-right: 25px;
     1606        width: 145px;
     1607}
     1608
    15901609#theme-information .action-button {
    15911610        border-top-color: #DFDFDF;
    15921611}
  • wp-admin/css/colors-classic.css

     
    15821582        background-color: #eee;
    15831583}
    15841584
    1585 p.popular-tags {
     1585.feature-filter {
     1586        -moz-border-radius-bottomleft:8px;
     1587        -moz-border-radius-bottomright:8px;
     1588        -moz-border-radius-topleft:8px;
     1589        -moz-border-radius-topright:8px;
    15861590        background-color: #FFFFFF;
    1587         border-color: #DFDFDF;
     1591        border: 1px solid #DFDFDF;
     1592        padding: 8px 12px 12px;
    15881593}
    15891594
     1595.feature-filter .feature-name {
     1596        float: left;
     1597        text-align: right;
     1598        width: 65px;
     1599}
     1600
     1601.feature-filter .feature-group li {
     1602        display: inline;
     1603        float: left;
     1604        list-style-type: none;
     1605        padding-right: 25px;
     1606        width: 145px;
     1607}
     1608
    15901609#theme-information .action-button {
    15911610        border-top-color: #DFDFDF;
    15921611}