WordPress.org

Making WordPress.org

Changeset 1322


Ignore:
Timestamp:
02/25/2015 03:56:45 PM (6 years ago)
Author:
obenland
Message:

WP.org Themes: Stay local for better performance.

Refrains from doing extra API requests but rather includes the API class
directly.

See #745.

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

Legend:

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

    r1319 r1322  
    2929        'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    3030    ) );
    31 
    32     $themes_allowedtags = array(
    33         'a'       => array( 'href' => array(), 'title' => array(), 'target' => array() ),
    34         'abbr'    => array( 'title' => array() ),
    35         'acronym' => array( 'title' => array() ),
    36         'code'    => array(),
    37         'pre'     => array(),
    38         'em'      => array(),
    39         'strong'  => array(),
    40         'div'     => array(),
    41         'p'       => array(),
    42         'ul'      => array(),
    43         'ol'      => array(),
    44         'li'      => array(),
    45         'h1'      => array(),
    46         'h2'      => array(),
    47         'h3'      => array(),
    48         'h4'      => array(),
    49         'h5'      => array(),
    50         'h6'      => array(),
    51         'img'     => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
    52     );
    5331}
    5432add_action( 'after_setup_theme', 'wporg_themes_setup' );
     
    164142 */
    165143function wporg_themes_query_themes() {
    166     global $themes_allowedtags, $theme_field_defaults;
     144    global $theme_field_defaults, $themes_allowedtags;
    167145
    168146    $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array(
     
    171149    ) );
    172150
    173     $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
    174 
    175     /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
    176     $args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );
    177 
    178     $api = themes_api( 'query_themes', $args );
     151    include_once '/home/api/public_html/themes/info/1.0/class-themes-api.php';
     152    $api = new Themes_API( 'query_themes', $args );
     153    $api = $api->response;
    179154
    180155    if ( is_wp_error( $api ) ) {
     
    182157    }
    183158
    184     foreach ( $api->themes as &$theme ) {
    185         $theme->name           = wp_kses( $theme->name,        $themes_allowedtags );
    186 
    187         // add in the nicename for the url, and the displayname for the display
    188         $user = get_user_by('login', $theme->author);
    189         $theme->authorurl      = $user->user_nicename;
    190         $theme->authordispname = wp_kses( $user->display_name, $themes_allowedtags );
    191 
    192         $theme->author         = wp_kses( $theme->author,      $themes_allowedtags );
    193         $theme->version        = wp_kses( $theme->version,     $themes_allowedtags );
    194         $theme->description    = wp_kses( $theme->description, $themes_allowedtags );
    195         $theme->downloaded     = number_format_i18n( $theme->downloaded );
    196         $theme->num_ratings    = number_format_i18n( $theme->num_ratings );
    197         $theme->preview_url    = set_url_scheme( $theme->preview_url );
    198         wporg_themes_photon_screen_shot( $theme );
     159    foreach ( $api->themes as $key => $theme ) {
     160        $api->themes[ $key ] = wporg_themes_ajax_prepare_theme( $theme );
    199161    }
    200162
     
    205167
    206168function wporg_themes_theme_info() {
    207     global $themes_allowedtags;
    208 
    209169    $args  = wp_unslash( $_REQUEST );
    210     $theme = themes_api( 'theme_information', array( 'slug' => $args['slug'] ) );
    211 
    212     if ( is_wp_error( $theme ) ) {
     170
     171    include_once '/home/api/public_html/themes/info/1.0/class-themes-api.php';
     172    $api = new Themes_API( 'query_themes', array( 'slug' => $args['slug'] ) );
     173    $api = $api->response;
     174
     175    if ( is_wp_error( $api ) ) {
    213176        wp_send_json_error();
    214177    }
    215178
    216     $theme->name           = wp_kses( $theme->name,        $themes_allowedtags );
    217     $theme->author         = wp_kses( $theme->author,      $themes_allowedtags );
    218     $theme->version        = wp_kses( $theme->version,     $themes_allowedtags );
    219     $theme->description    = wp_kses( $theme->description, $themes_allowedtags );
    220     $theme->downloaded     = number_format_i18n( $theme->downloaded );
    221     $theme->num_ratings    = number_format_i18n( $theme->num_ratings );
    222     $theme->preview_url    = set_url_scheme( $theme->preview_url );
    223     wporg_themes_photon_screen_shot( $theme );
    224 
    225     wp_send_json_success( $theme );
     179    $api = wporg_themes_ajax_prepare_theme( $api );
     180
     181    wp_send_json_success( $api );
    226182}
    227183add_action( 'wp_ajax_theme-info',        'wporg_themes_theme_info' );
    228184add_action( 'wp_ajax_nopriv_theme-info', 'wporg_themes_theme_info' );
    229185
    230 /**
    231  * Photon-ifies the screen shot URL.
    232  *
    233  * @param object $theme
    234  * @return object
    235  */
    236 function wporg_themes_photon_screen_shot( $theme ) {
     186function wporg_themes_ajax_prepare_theme( $theme ) {
     187    global $themes_allowedtags;
     188
     189    if ( empty( $themes_allowedtags ) ) {
     190        $themes_allowedtags = array(
     191            'a'       => array( 'href' => array(), 'title' => array(), 'target' => array() ),
     192            'abbr'    => array( 'title' => array() ),
     193            'acronym' => array( 'title' => array() ),
     194            'code'    => array(),
     195            'pre'     => array(),
     196            'em'      => array(),
     197            'strong'  => array(),
     198            'div'     => array(),
     199            'p'       => array(),
     200            'ul'      => array(),
     201            'ol'      => array(),
     202            'li'      => array(),
     203            'h1'      => array(),
     204            'h2'      => array(),
     205            'h3'      => array(),
     206            'h4'      => array(),
     207            'h5'      => array(),
     208            'h6'      => array(),
     209            'img'     => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
     210        );
     211    }
     212
     213    $author        = get_user_by( 'login', $theme->author );
     214    $theme->author = new StdClass;
     215    foreach ( array( 'user_nicename', 'display_name' ) as $property ) {
     216        $theme->author->$property = $author->$property;
     217    }
     218
     219    $theme->name        = wp_kses( $theme->name, $themes_allowedtags );
     220    $theme->version     = wp_kses( $theme->version, $themes_allowedtags );
     221    $theme->description = wp_kses( $theme->description, $themes_allowedtags );
     222    $theme->downloaded  = number_format_i18n( $theme->downloaded );
     223    $theme->num_ratings = number_format_i18n( $theme->num_ratings );
     224    $theme->preview_url = set_url_scheme( $theme->preview_url );
     225
    237226    if ( preg_match( '/screenshot.(jpg|jpeg|png|gif)/', $theme->screenshot_url, $match ) ) {
    238227        $theme->screenshot_url = sprintf( 'https://i0.wp.com/themes.svn.wordpress.org/%1$s/%2$s/%3$s',
     
    242231        );
    243232    }
     233
    244234    return $theme;
    245235}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/view-templates/theme-single.php

    r1293 r1322  
    1717            <div class="theme-head">
    1818                <h3 class="theme-name entry-title">{{{ data.name }}}</h3>
    19                 <h4 class="theme-author"><?php printf( __( 'By %s' ), '<a href="https://profiles.wordpress.org/{{ data.authorurl }}"><span class="author">{{{ data.authordispname }}}</span></a>' ); ?></h4>
     19                <h4 class="theme-author"><?php printf( __( 'By %s' ), '<a href="https://profiles.wordpress.org/{{ data.author.user_nicename }}"><span class="author">{{{ data.author.display_name }}}</span></a>' ); ?></h4>
    2020
    2121                <div class="theme-actions">
Note: See TracChangeset for help on using the changeset viewer.