Ticket #3935: 3935.3.diff
File 3935.3.diff, 4.4 KB (added by , 6 years ago) |
---|
-
wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php index d407c1295..bf8a0ef50 100644
class Import { 362 362 $svn_assets_folder = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/assets/", true /* verbose */ ); 363 363 if ( $svn_assets_folder ) { // /assets/ may not exist. 364 364 foreach ( $svn_assets_folder as $asset ) { 365 // screenshot-0(-rtl) .(png|jpg|jpeg|gif) || icon.svg366 if ( ! preg_match( '!^(?P<type>screenshot|banner|icon)( -(?P<resolution>[\dx]+)(-rtl)?\.(png|jpg|jpeg|gif)|\.svg)$!i', $asset['filename'], $m ) ) {365 // screenshot-0(-rtl)(-de_DE).(png|jpg|jpeg|gif) || icon.svg 366 if ( ! preg_match( '!^(?P<type>screenshot|banner|icon)(?:-(?P<resolution>[\dx]+)(-rtl)?(?:-(?P<locale>[a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?))?\.(png|jpg|jpeg|gif)|\.svg)$!i', $asset['filename'], $m ) ) { 367 367 continue; 368 368 } 369 369 … … class Import { 372 372 $revision = $asset['revision']; 373 373 $location = 'assets'; 374 374 $resolution = isset( $m['resolution'] ) ? $m['resolution'] : false; 375 $locale = isset( $m['locale'] ) ? $m['locale'] : false; 375 376 376 $assets[ $type ][ $asset['filename'] ] = compact( 'filename', 'revision', 'resolution', 'location' );377 $assets[ $type ][ $asset['filename'] ] = compact( 'filename', 'revision', 'resolution', 'location', 'locale' ); 377 378 } 378 379 } 379 380 -
wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php index 4bfe1400a..470e1ff1d 100644
use WordPressdotorg\Plugin_Directory\Plugin_i18n; 11 11 */ 12 12 class Screenshots { 13 13 14 /** 15 * Reduce the screenshots metadata to group and sort the best matched locale screenshots 16 * 17 * @param array $screen_shots An array with screenshots metadata for the plugin. 18 * @param string $user_locale The locale of the current request. 19 * @return array screenshots grouped by resolution(ID), sorted by the best matched locale first. 20 */ 21 private static function reduce_screenshots_with_locale( $screen_shots, $user_locale ) { 22 23 $reduced = array(); 24 25 foreach ( $screen_shots as $image ) { 26 27 if ( ! isset( $reduced[ $image['resolution'] ] ) ) { 28 $reduced[ $image['resolution'] ] = array(); 29 } 30 31 if ( get_locale() === $image['locale'] ) { 32 // if the locale is a full match, always insert to the first element (highest priority). 33 array_unshift( $reduced[ $image['resolution'] ], $image ); 34 } elseif ( empty( $image['locale'] ) ) { 35 // if the image has no locale, always insert to the last element (lowerst priority). 36 $reduced[ $image['resolution'] ][] = $image; 37 } else { 38 $array1 = explode( '_', $image['locale'] ); 39 $array2 = explode( '_', $user_locale ); 40 // if only language is matched. 41 if ( $array1[0] === $array2[0] ) { 42 // image with locale has a higher priority than image without locale. 43 if ( '' === end( $reduced[ $image['resolution'] ] )['locale'] ) { 44 array_splice( $reduced[ $image['resolution'] ], count( $reduced[ $image['resolution'] ] ), 0, array( $image ) ); 45 } else { 46 $reduced[ $image['resolution'] ][] = $image; 47 } 48 } 49 } 50 } 51 52 return $reduced; 53 } 54 14 55 /** 15 56 * @return string 16 57 */ … … class Screenshots { 26 67 return ''; 27 68 } 28 69 29 ksort( $screen_shots, SORT_NATURAL ); 70 $reduced = self::reduce_screenshots_with_locale( $screen_shots, get_locale() ); 71 72 ksort( $reduced, SORT_NATURAL ); 30 73 31 74 /* 32 75 * Find the image that corresponds with the text. 33 76 * The image numbers are stored within the 'resolution' key. 77 * The same key can have more than one screenshot with different locales. 34 78 */ 35 foreach ( $screen_shots as $image ) { 79 foreach ( $reduced as $screen_shots ) { 80 81 $image = $screen_shots[0]; 82 36 83 $screen_shot = sprintf( 37 84 '<a href="%1$s" rel="nofollow"><img class="screenshot" src="%1$s" alt="" /></a>', 38 85 esc_url( Template::get_asset_url( $plugin, $image ) )