Making WordPress.org

Changeset 7072


Ignore:
Timestamp:
04/10/2018 02:42:42 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Use geopattern icon assets in the plugins/update-check API response.

This change populates the update_source table which the update-check API uses, another change is needed to the update check itself to pull them through.
Additionally a bin script to trigger an update for a single row (or all) is included.

See #3265.

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/rebuild-update_source-table.php

    r7071 r7072  
    4040
    4141$slugs = $wpdb->get_col( $sql );
     42if ( ! $slugs ) {
     43        fwrite( STDERR, "Error! The plugin(s) could not be located.\n" );
     44        die();
     45}
    4246
    4347foreach ( $slugs as $i => $slug ) {
     48        echo ++$i . '/' . count( $slugs ) . "\t" . $slug . "\n";
    4449
    45         $post = Plugin_Directory::get_plugin_post( $slug );
    46         if ( ! $post ) {
    47                 continue;
    48         }
    49 
    50         echo $i . '/' . count( $slugs ) . "\t" . $post->post_name . "\n";
    51 
    52         update_post_meta(
    53                 $post->ID,
    54                 'rating',
    55                 \WPORG_Ratings::get_avg_rating( 'plugin', $post->post_name )
    56         );
    57 
    58         update_post_meta(
    59                 $post->ID,
    60                 'ratings',
    61                 \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name )
    62         );
     50        Jobs\API_Update_Updater::update_single_plugin( $slug );
    6351
    6452        clear_memory_caches();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r7048 r7072  
    390390                if ( ! $icon || 'publish' !== $plugin->post_status ) {
    391391                        $generated = true;
    392                         $icon = self::get_geopattern_icon_url( $plugin );
     392                        $icon = $svg = self::get_geopattern_icon_url( $plugin );
    393393                }
    394394
    … …  
    441441         *
    442442         * @param int|\WP_Post|null $post   Optional. Post ID or post object. Defaults to global $post.
    443          * @param string            $output Optional. Output type. 'html' or 'raw'. Default: 'raw'.
     443         * @param string            $output Optional. Output type. 'html', 'raw', or 'raw_with_rtl'. Default: 'raw'.
    444444         * @return mixed
    445445         */
    … …  
    473473                }
    474474
    475                 if ( is_rtl() ) {
     475                if ( is_rtl() || 'raw_with_rtl' == $output ) {
    476476                        foreach ( $rtl_banners as $info ) {
    477477                                switch ( $info['resolution'] ) {
    478478                                        case '1544x500':
    479                                                 $banner_2x = self::get_asset_url( $plugin, $info );
     479                                                $field = 'raw_with_rtl' == $output ? 'banner_2x_rtl' : 'banner_2x';
     480                                                $$field = self::get_asset_url( $plugin, $info );
    480481                                                break;
    481482
    482483                                        case '772x250':
    483                                                 $banner = self::get_asset_url( $plugin, $info );
     484                                                $field = 'raw_with_rtl' == $output ? 'banner_rtl' : 'banner';
     485                                                $$field = self::get_asset_url( $plugin, $info );
    484486                                                break;
    485487                                }
    … …  
    506508
    507509                        case 'raw':
     510                        case 'raw_with_rtl':
    508511                        default:
    509                                 return compact( 'banner', 'banner_2x' );
     512                                return compact( 'banner', 'banner_2x', 'banner_rtl', 'banner_2x_rtl' );
    510513                }
    511514        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php

    r6287 r7072  
    33
    44use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     5use WordPressdotorg\Plugin_Directory\Template;
    56
    67/**
    … …  
    6263                }
    6364
    64                 $data           = array(
     65                $data = array(
    6566                        'plugin_id'       => $post->ID,
    6667                        'plugin_slug'     => $post->post_name,
    … …  
    7576                        'requires_php'    => get_post_meta( $post->ID, 'requires_php', true ),
    7677                        'upgrade_notice'  => '',
     78                        'assets'          => serialize( self::get_plugin_assets( $post ) ),
    7779                        'last_updated'    => $post->post_modified,
    7880                );
    … …  
    112114        }
    113115
     116        static function get_plugin_assets( $post ) {
     117                $icons = $banners = $banners_rtl = array();
     118
     119                $raw_icons   = Template::get_plugin_icon( $post, 'raw' );
     120                $raw_banners = Template::get_plugin_banner( $post, 'raw_with_rtl' );
     121
     122                // Banners
     123                if ( !empty( $raw_banners['banner_2x'] ) ) {
     124                        $banners['2x'] = $raw_banners['banner_2x'];
     125                }
     126                if ( !empty( $raw_banners['banner'] ) ) {
     127                        $banners['1x'] = $raw_banners['banner'];
     128                }
     129                if ( $banners ) {
     130                        $banners['default']  = $banners['2x'] ?? $banners['1x'];
     131                }
     132
     133                // RTL Banners (get_plugin_banner 'raw_with_rtl' returns these)
     134                if ( !empty( $raw_banners['banner_2x_rtl'] ) ) {
     135                        $banners_rtl['2x'] = $raw_banners['banner_2x_rtl'];
     136                }
     137                if ( !empty( $raw_banners['banner_rtl'] ) ) {
     138                        $banners_rtl['1x'] = $raw_banners['banner_rtl'];
     139                }
     140                if ( $banners_rtl ) {
     141                        $banners_rtl['default']  = $banners_rtl['2x'] ?? $banners_rtl['1x'];
     142                }
     143
     144                // Icons.
     145                if ( !empty( $raw_icons['icon_2x'] ) ) {
     146                        $icons['2x'] = $raw_icons['icon_2x'];
     147                }
     148                if ( !empty( $raw_icons['icon'] ) ) {
     149                        $icons['1x'] = $raw_icons['icon'];
     150                }
     151                if ( !empty( $raw_icons['svg'] ) ) {
     152                        $icons['svg'] = $raw_icons['svg'];
     153
     154                        // We don't need to set the 1x field when it's the SVG.
     155                        if ( isset( $icons['1x'] ) && $icons['1x'] == $icons['svg'] ) {
     156                                unset( $icons['1x'] );
     157                        }
     158                }
     159                if ( $icons ) {
     160                        $icons['default'] = $icons['svg'] ?? ( $icons['2x'] ?? $icons['1x'] );
     161                }
     162
     163                return (object) compact( 'icons', 'banners', 'banners_rtl' );
     164        }
     165
    114166}
    115167
    … …  
    128180  `requires_php` varchar(128) NOT NULL DEFAULT '',
    129181  `upgrade_notice` text,
     182  `assets` text NOT NULL DEFAULT '',
    130183  `last_updated` datetime NOT NULL,
    131184  PRIMARY KEY (`plugin_id`),
Note: See TracChangeset for help on using the changeset viewer.