Make WordPress Core

Ticket #27581: 27581.patch

File 27581.patch, 5.2 KB (added by johnbillion, 12 years ago)
  • src/wp-admin/admin-ajax.php

     
    5858        'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    5959        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    6060        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    61         'save-user-color-scheme', 'update-widget',
     61        'save-user-color-scheme', 'update-widget', 'query-themes'
    6262);
    6363
    6464// Register core Ajax calls.
  • src/wp-admin/includes/ajax-actions.php

     
    22072207        update_user_meta( get_current_user_id(), 'admin_color', $color_scheme );
    22082208        wp_send_json_success();
    22092209}
     2210
     2211/**
     2212 * Perform a query_themes lookup on api.wordpress.org.
     2213 *
     2214 * @since x.x.x
     2215 */
     2216function wp_ajax_query_themes() {
     2217        $url = 'http://api.wordpress.org/themes/info/1.1/?action=query_themes';
     2218
     2219        check_ajax_referer( 'query-themes', 'nonce' );
     2220
     2221        $request = wp_remote_post( $url, array(
     2222                'body' => wp_unslash( $_POST['api'] ),
     2223        ) );
     2224
     2225        if ( is_wp_error( $request ) ) {
     2226                wp_send_json_error();
     2227        }
     2228        if ( 200 != wp_remote_retrieve_response_code( $request ) ) {
     2229                wp_send_json_error();
     2230        }
     2231
     2232        $json = json_decode( wp_remote_retrieve_body( $request ) );
     2233
     2234        if ( !$json ) {
     2235                wp_send_json_error();
     2236        }
     2237
     2238        if ( isset( $json->themes ) ) {
     2239                foreach ( $json->themes as & $theme ) {
     2240                        $theme->num_ratings_text = sprintf( _n( 'Based on %s rating.', 'Based on %s ratings.', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) );
     2241                }
     2242        }
     2243
     2244        wp_send_json_success( $json );
     2245
     2246}
     2247 No newline at end of file
  • src/wp-admin/js/theme.js

     
    245245
    246246                // Otherwise, send a new API call and add it to the cache.
    247247                if ( ! query ) {
    248                         query = this.apiCall( request ).done( function( data ) {
     248                        query = this.apiCall( request ).done( function( response ) {
     249                                if ( !response.success ) {
     250                                        self.trigger( 'query:fail' );
     251                                        return;
     252                                }
     253                                data = response.data;
     254
    249255                                // Update the collection with the queried data.
    250256                                self.reset( data.themes );
    251257                                count = data.info.results;
     
    267273                } else {
    268274                        // If it's a paginated request we need to fetch more themes...
    269275                        if ( isPaginated ) {
    270                                 return this.apiCall( request, isPaginated ).done( function( data ) {
     276                                return this.apiCall( request, isPaginated ).done( function( response ) {
     277                                        if ( !response.success ) {
     278                                                self.trigger( 'query:fail' );
     279                                                return;
     280                                        }
     281                                        data = response.data;
     282
    271283                                        // Add the new themes to the current collection
    272284                                        // @todo update counter
    273285                                        self.add( data.themes );
     
    311323
    312324                // Ajax request to .org API
    313325                return $.ajax({
    314                         url: 'https://api.wordpress.org/themes/info/1.1/?action=query_themes',
     326                        url: ajaxurl,
    315327
    316328                        // We want JSON data
    317329                        dataType: 'json',
    318330                        type: 'POST',
    319                         crossDomain: true,
    320331
    321332                        // Request data
    322333                        data: {
    323                                 action: 'query_themes',
    324                                 request: _.extend({
    325                                         per_page: 72,
    326                                         fields: {
    327                                                 description: true,
    328                                                 tested: true,
    329                                                 requires: true,
    330                                                 rating: true,
    331                                                 downloaded: true,
    332                                                 downloadLink: true,
    333                                                 last_updated: true,
    334                                                 homepage: true,
    335                                                 num_ratings: true
    336                                         }
    337                                 }, request)
     334                                action: 'query-themes',
     335                                nonce: themes.data.settings._nonceQuery,
     336                                api: {
     337                                        action: 'query_themes',
     338                                        request: _.extend({
     339                                                per_page: 72,
     340                                                fields: {
     341                                                        description: true,
     342                                                        tested: true,
     343                                                        requires: true,
     344                                                        rating: true,
     345                                                        downloaded: true,
     346                                                        downloadLink: true,
     347                                                        last_updated: true,
     348                                                        homepage: true,
     349                                                        num_ratings: true
     350                                                }
     351                                        }, request)
     352                                }
    338353                        },
    339354
    340355                        beforeSend: function() {
  • src/wp-admin/theme-install.php

     
    4141                'installURI'    => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
    4242                'adminUrl'      => parse_url( self_admin_url(), PHP_URL_PATH ),
    4343                'updateURI'     => self_admin_url( 'update.php' ),
    44                 '_nonceInstall' => wp_create_nonce( 'install-theme' )
     44                '_nonceInstall' => wp_create_nonce( 'install-theme' ),
     45                '_nonceQuery'   => wp_create_nonce( 'query-themes' ),
    4546        ),
    4647        'l10n' => array(
    4748                'addNew' => __( 'Add New Theme' ),
     
    205206                                                <span class="three"></span>
    206207                                                <span class="four"></span>
    207208                                                <span class="five"></span>
    208                                                 <p class="votes"><?php printf( __( 'Based on %s ratings.' ), '{{ data.num_ratings }}' ); ?></p>
     209                                                <p class="votes">{{ data.num_ratings_text }}</p>
    209210                                        </div>
    210211                                        <div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
    211212                                        <div class="theme-description">{{ data.description }}</div>