WordPress.org

Making WordPress.org

Changeset 7048


Ignore:
Timestamp:
04/06/2018 04:27:35 AM (19 months ago)
Author:
dd32
Message:

Plugin Directory: Use geopattern icons from a CDN svg rather than using data URI's inline on the page.

See #3265.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r7047 r7048  
    502502        add_rewrite_rule( '^search/([^/]+)/?$', 'index.php?s=$matches[1]', 'top' );
    503503
    504         // Add a rule for generated plugin icons. geopattern-icon/demo.svg | geopattern-icon/demo.abc123.svg
    505         add_rewrite_rule( '^geopattern-icon/([^/]+)(\.([a-f0-9]{6}))?\.svg$', 'index.php?name=$matches[1]&geopattern_icon=$matches[3]', 'top' );
     504        // Add a rule for generated plugin icons. geopattern-icon/demo.svg | geopattern-icon/demo_abc123.svg
     505        add_rewrite_rule( '^geopattern-icon/([^/_]+)(_([a-f0-9]{6}))?\.svg$', 'index.php?name=$matches[1]&geopattern_icon=$matches[3]', 'top' );
    506506
    507507        // Handle plugin admin requests
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r6538 r7048  
    390390        if ( ! $icon || 'publish' !== $plugin->post_status ) {
    391391            $generated = true;
    392 
    393             $icon = new Plugin_Geopattern();
    394             $icon->setString( $plugin->post_name );
    395 
    396             // Use the average color of the first known banner as the icon background color
    397             if ( $color = get_post_meta( $plugin->ID, 'assets_banners_color', true ) ) {
    398                 if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) {
    399                     $icon->setColor( '#' . $color );
    400                 }
    401             }
    402 
    403             $icon = $icon->toDataURI();
     392            $icon = self::get_geopattern_icon_url( $plugin );
    404393        }
    405394
     
    425414
    426415    /**
     416     * Retrieve the Geopattern SVG URL for a given plugin.
     417     */
     418    public static function get_geopattern_icon_url( $post = null, $color = null ) {
     419        $plugin = get_post( $post );
     420
     421        if ( is_null( $color ) ) {
     422            $color = get_post_meta( $plugin->ID, 'assets_banners_color', true );
     423        }
     424
     425        if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) {
     426            $color = "_{$color}";
     427        } else {
     428            $color = '';
     429        }
     430
     431        // This is a cached resource. The slug + color combine to form the cache buster.
     432        $url = "https://s.w.org/plugins/geopattern-icon/{$plugin->post_name}{$color}.svg";
     433
     434        return $url;
     435    }
     436
     437    /**
    427438     * Retrieve the Plugin banner details for a plugin.
    428439     *
Note: See TracChangeset for help on using the changeset viewer.