Changeset 6640
- Timestamp:
- 02/15/2018 10:26:52 AM (7 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/locale-detection/class-detector.php
r6638 r6640 42 42 */ 43 43 public function __construct() { 44 $this->active_locales = array_merge( 45 $this->active_locales, 46 (array) glob( get_template_directory() . '/languages/*.mo' ), 47 (array) glob( get_stylesheet_directory() . '/languages/*.mo' ) 48 ); 49 foreach ( $this->active_locales as &$mo_file ) { 50 $mo_file = basename( $mo_file, '.mo' ); 44 $this->active_locales = $this->get_active_locales(); 45 46 if ( ! empty( $_COOKIE[ 'wporg_locale' ] ) ) { 47 $locale = $this->sanitize_locale( $_COOKIE['wporg_locale'] ); 48 49 if ( in_array( $locale, $this->active_locales, true ) ) { 50 $this->locale = $locale; 51 return; 52 } 51 53 } 52 unset( $mo_file );53 54 54 55 if ( isset( $_GET['locale'] ) ) { 55 $get_locale = preg_replace( '/[^A-Z_-]/i', '',$_GET['locale'] );56 $get_locale = $this->sanitize_locale( $_GET['locale'] ); 56 57 57 58 $this->locale = $this->check_variants( $get_locale ) ?: $this->locale; … … 59 60 $this->locale = $this->guess_locale() ?: $this->locale; 60 61 } 62 63 setcookie( 'wporg_locale', $this->locale, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 61 64 } 62 65 … … 68 71 public function get_locale() { 69 72 return $this->locale; 73 } 74 75 /** 76 * Returns the list of available locales. 77 * 78 * @return array 79 */ 80 public function get_active_locales() { 81 wp_cache_add_global_groups( [ 'locale-associations' ] ); 82 83 $locales = wp_cache_get( 'locale-list', 'locale-associations' ); 84 if ( false === $locales ) { 85 $locales = (array) $GLOBALS['wpdb']->get_col( 'SELECT locale FROM wporg_locales' ); 86 wp_cache_set( 'locale-list', $locales, 'locale-associations' ); 87 } 88 89 return $locales; 70 90 } 71 91 … … 165 185 return ''; 166 186 } 187 188 /** 189 * Returns a valid locale string. 190 * 191 * @param string $locale Locale string to be sanitized. 192 * @return string 193 */ 194 protected function sanitize_locale( $locale ) { 195 return preg_replace( '/[^a-zA-Z0-9_]/', '', $locale ); 196 } 167 197 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations.php
r5339 r6640 195 195 196 196 wp_cache_delete( 'subdomains', 'locale-associations' ); 197 wp_cache_delete( 'local-list', 'locale-associations' ); 197 198 wp_cache_delete( 'local-sites', 'locale-associations' ); 198 199 wp_cache_delete( 'id-locale', 'locale-associations' );
Note: See TracChangeset
for help on using the changeset viewer.