Making WordPress.org

Changeset 1375


Ignore:
Timestamp:
03/04/2015 12:02:15 PM (9 years ago)
Author:
obenland
Message:

WP.org Themes: User server-side query results during bootstrapping.

This should avoid an extra API request on the initial load of a page.

H/t matveb.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php

    r1374 r1375  
    4949        wp_localize_script( 'theme', '_wpThemeSettings', array(
    5050            'themes'   => false,
     51            'query'    => wporg_themes_prepare_themes_for_js(),
    5152            'settings' => array(
    5253                'title'      => __( 'WordPress › %s « Free WordPress Themes', 'wporg-themes' ),
     
    110111}
    111112add_filter( 'wp_title', 'wporg_themes_wp_title', 10, 2 );
     113
     114/**
     115 * Bootstraps found themes for the frontend JS handler.
     116 *
     117 * @return array
     118 */
     119function wporg_themes_prepare_themes_for_js() {
     120    global $wp_query;
     121
     122    include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';
     123    $api = new Themes_API( 'get_result' );
     124    $api->fields = array_merge( $api->fields, array(
     125        'description'  => true,
     126        'sections'     => false,
     127        'tested'       => true,
     128        'requires'     => true,
     129        'rating'       => true,
     130        'ratings'      => true,
     131        'downloaded'   => true,
     132        'downloadlink' => true,
     133        'last_updated' => true,
     134        'homepage'     => true,
     135        'tags'         => true,
     136        'num_ratings'  => true,
     137        'parent'       => true,
     138    ) );
     139
     140    $themes = array_map( array( $api, 'fill_theme' ), $wp_query->posts );
     141    $themes = array_map( 'wporg_themes_ajax_prepare_theme', $themes );
     142
     143    $request = array();
     144    if ( get_query_var( 'browse' ) ) {
     145        $request['browse'] = get_query_var( 'browse' );
     146    } else if ( $wp_query->is_tag() ) {
     147        $request['tag'] = (array) explode( '+', get_query_var( 'tag' ) );
     148    }
     149    else if ( $wp_query->is_search() ) {
     150        $request['search'] = get_query_var( 's' );
     151    }
     152    else if ( $wp_query->is_author() ) {
     153        $request['author'] = get_user_by( 'id', get_query_var( 'author' ) )->user_nicename;
     154    }
     155    else if ( $wp_query->is_singular( 'repopackage' ) ) {
     156        $request['theme'] = get_query_var( 'name' );
     157    }
     158
     159    return array(
     160        'themes'  => $themes,
     161        'request' => $request,
     162        'total'   => $wp_query->found_posts,
     163    );
     164 }
    112165
    113166/**
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/index.php

    r1274 r1375  
    6363
    6464        <div class="theme-browser content-filterable">
    65             <div class="themes" style="display:none;">
     65            <div class="themes">
    6666                <?php
    6767                    while ( have_posts() ) :
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/js/theme.js

    r1373 r1375  
    644644        routes: {
    645645            'browse/:sort/'  : 'sort',
    646             'tags/:tag/'      : 'tag',
     646            'tags/:tag/'     : 'tag',
    647647            'search/:query/' : 'search',
    648648            'author/:author/': 'author',
     
    665665
    666666    _.extend( wp.themes.RunInstaller, {
    667         extraRoutes: function() {
     667        routes: function() {
    668668            var self = this,
    669             request = {};
    670 
    671             // Open the modal when matching the route for a single themes.
     669                request = {};
     670
     671            // Bind to our global `wp.themes` object
     672            // so that the router is available to sub-views
     673            wp.themes.router = new wp.themes.InstallerRouter();
     674
     675            // Handles `theme` route event
     676            // Queries the API for the passed theme slug
    672677            wp.themes.router.on( 'route:preview', function( slug ) {
     678                self.view.collection.queries.push( wp.themes.data.query );
     679
     680                request.theme = slug;
     681                self.view.collection.query( request );
     682
    673683                $( '.close-full-overlay' ).trigger( 'click' );
    674                 this.listenToOnce( self.view.collection, 'query:success', function() {
    675                     self.view.view.expand( slug );
    676                 });
     684                self.view.view.expand( slug );
     685            });
     686
     687            // Handles sorting / browsing routes
     688            // Also handles the root URL triggering a sort request
     689            // for `featured`, the default view
     690            wp.themes.router.on( 'route:sort', function( sort ) {
     691                self.view.collection.queries.push( wp.themes.data.query );
     692
     693                if ( ! sort ) {
     694                    sort = 'featured';
     695                }
     696                self.view.sort( sort );
     697                self.view.trigger( 'theme:close' );
     698            });
     699
     700            // The `search` route event. The router populates the input field.
     701            wp.themes.router.on( 'route:search', function() {
     702                self.view.collection.queries.push( wp.themes.data.query );
     703
     704                $( '.wp-filter-search' ).focus().trigger( 'keyup' );
    677705            });
    678706
    679707            wp.themes.router.on( 'route:tag', function( tag ) {
     708                self.view.collection.queries.push( wp.themes.data.query );
     709
    680710                _.each( tag.split( '+' ), function( tag ) {
    681711                    $( '#filter-id-' + tag ).prop( 'checked', true );
     
    686716
    687717            wp.themes.router.on( 'route:author', function( author ) {
     718                self.view.collection.queries.push( wp.themes.data.query );
     719
    688720                request.author = author;
    689721                self.view.collection.query( request );
    690722                wp.themes.utils.title( author );
    691723            });
     724
     725            this.extraRoutes();
    692726        }
    693727    });
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/style.css

    r1331 r1375  
    271271 * Theme heading information
    272272 */
     273.single.single-repopackage .themes .theme-wrap {
     274    visibility: hidden;
     275}
    273276.single .theme-wrap .current-label {
    274277    background: #333;
Note: See TracChangeset for help on using the changeset viewer.