Making WordPress.org

Changeset 3020


Ignore:
Timestamp:
04/27/2016 08:08:11 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Add a REST API endpoint which represents the full plugin data currently exposed through api.wordpress.org.
Although it's unlikely api.wordpress.org will run the API directly, this is a test to verify that all data we have on file is available.

See #1576

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

Legend:

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

    r2994 r3020  
    1313        static function load_routes() {
    1414                new Routes\Internal_Stats();
     15                new Routes\Plugin();
    1516        }
    1617
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3011 r3020  
    386386         */
    387387        public function filter_post_content_to_correct_page( $content ) {
     388                if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     389                        return $content;
     390                }
    388391                if ( 'plugin' === get_post()->post_type ) {
    389392                        $page = get_query_var( 'content_page' );
    … …  
    504507                        return $post;
    505508                }
     509
     510                // TODO: Add caching here.
    506511
    507512                // get_post_by_slug();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r3009 r3020  
    6767         * @return array
    6868         */
    69         static function get_plugin_sections() {
    70                 $plugin      = get_post();
     69        static function get_plugin_sections( $post = null ) {
     70                $plugin      = get_post( $post );
    7171                $plugin_slug = $plugin->post_name;
    7272
    … …  
    173173                $raw_icons = get_post_meta( $plugin->ID, 'assets_icons', true );
    174174
    175                 $icon = $icon_2x = $vector = $generated = false;
     175                $icon = $icon_2x = $svg = $generated = false;
    176176                foreach ( $raw_icons as $file => $info ) {
    177177                        switch ( $info['resolution'] ) {
    … …  
    184184                                        break;
    185185
     186                                /* false = the resolution of the icon, this is NOT disabled */
    186187                                case false && 'icon.svg' == $file:
    187                                         $icon   = self::get_asset_url( $plugin_slug, $info );
    188                                         $vector = true;
    189                                         break;
    190                         }
     188                                        $svg   = self::get_asset_url( $plugin_slug, $info );
     189                                        break;
     190                        }
     191                }
     192
     193                if ( ! $icon && $svg ) {
     194                        $icon = $svg;
    191195                }
    192196
    … …  
    223227                        case 'raw':
    224228                        default:
    225                                 return compact( 'icon', 'icon_2x', 'vector', 'generated' );
     229                                return compact( 'svg', 'icon', 'icon_2x', 'generated' );
    226230                }
    227231        }
    … …  
    333337                return $output;
    334338        }
    335        
     339
     340        /**
     341         * Generate a Download link for a given plugin & version.
     342         *
     343         * @param \WP_Post $post    The Plugin Post.
     344         * @param string   $version The version to link to. Optional. Default: latest.
     345         * @return string The Download URL.
     346         */
     347        static function download_link( $post = null, $version = 'latest' ) {
     348                $post = get_post( $post );
     349
     350                if ( 'latest' == $version || 'latest-stable' == $version ) {
     351                        $version = get_post_meta( $post->ID, 'stable_tag', true );
     352                }
     353
     354                if ( 'trunk' != $version ) {
     355                        return sprintf( "https://downloads.wordpress.org/plugin/%s.%s.zip", $post->post_name, $version );
     356                } else {
     357                        return sprintf( "https://downloads.wordpress.org/plugin/%s.zip", $post->post_name );
     358                }
     359        }
    336360}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php

    r3012 r3020  
    8989                                var $rating = $( '.user-rating div' ),
    9090                                        $stars = $rating.find( '.dashicons' ),
    91                                         current_rating = $rating.data('rating'),
     91                                        current_rating = $rating.data( 'rating' ),
    9292                                        rating_clear_timer = 0;
    9393
    … …  
    9999
    100100                                        if ( rating_clear_timer ) {
    101                                                 rating_clear_timer = clearTimeout( rating_clear_timer );
     101                                                clearTimeout( rating_clear_timer );
     102                                                rating_clear_timer = 0;
    102103                                        }
    103104
    … …  
    115116                                $rating.mouseout( function() {
    116117                                        var clear_callback = function() {
    117                                                 var rating = $rating.data('rating');
     118                                                var rating = $rating.data( 'rating' );
    118119                                                if ( rating == current_rating ) {
    119120                                                        return;
Note: See TracChangeset for help on using the changeset viewer.