Changeset 29006 for trunk/src/wp-admin/includes/upgrade.php
- Timestamp:
- 07/05/2014 05:13:05 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r28774 r29006 2159 2159 } 2160 2160 endif; 2161 2162 function wp_install_language_form( $body ) { 2163 echo "<fieldset>\n"; 2164 echo "<legend class='screen-reader-text'>Select a default language</legend>\n"; 2165 echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">'; 2166 echo '<label for="language_default">English (United States)</label>'; 2167 echo "\n"; 2168 2169 if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) { 2170 if ( isset( $body['languages'][WPLANG] ) ) { 2171 $language = $body['languages'][WPLANG]; 2172 echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">'; 2173 echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n"; 2174 } 2175 } 2176 2177 foreach ( $body['languages'] as $language ) { 2178 echo '<input type="radio" name="language" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_'. esc_attr( $language['language'] ) .'" value="' . esc_attr( $language['language'] ) . '">'; 2179 echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n"; 2180 } 2181 echo "</fieldset>\n"; 2182 echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="»" /></p>'; 2183 } 2184 2185 /** 2186 * @todo rename, move 2187 */ 2188 function wp_get_available_translations() { 2189 $url = 'http://api.wordpress.org/translations/core/1.0/'; 2190 if ( wp_http_supports( array( 'ssl' ) ) ) { 2191 $url = set_url_scheme( $url, 'https' ); 2192 } 2193 2194 $options = array( 2195 'timeout' => 3, 2196 'body' => array( 'version' => $GLOBALS['wp_version'] ), 2197 ); 2198 2199 $response = wp_remote_post( $url, $options ); 2200 $body = wp_remote_retrieve_body( $response ); 2201 if ( $body && $body = json_decode( $body, true ) ) { 2202 $languages = array(); 2203 // Key the language array with the language code 2204 foreach ( $body['languages'] as $language ) { 2205 $languages[$language['language']] = $language; 2206 } 2207 $body['languages'] = $languages; 2208 return $body; 2209 } 2210 return false; 2211 } 2212 2213 function wp_install_download_language_pack( $language ) { 2214 // Check if the language is already installed. 2215 $available_languages = get_available_languages(); 2216 if ( in_array( $language->language, $available_languages ) ) { 2217 return $language->language; 2218 } 2219 2220 // Confirm the language is one we can download. 2221 $body = wp_get_available_translations(); 2222 $loading_language = false; 2223 if ( $body ) { 2224 foreach ( $body['languages'] as $language ) { 2225 if ( $language['language'] === $_REQUEST['language'] ) { 2226 $loading_language = $_REQUEST['language']; 2227 break; 2228 } 2229 } 2230 } 2231 2232 if ( ! $loading_language ) { 2233 return false; 2234 } 2235 $language = (object) $language; 2236 2237 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 2238 $skin = new Automatic_Upgrader_Skin; 2239 $upgrader = new Language_Pack_Upgrader( $skin ); 2240 $options = array( 'clear_update_cache' => false ); 2241 $language->type = 'core'; 2242 /** 2243 * @todo failures (such as non-direct FS) 2244 */ 2245 $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); 2246 return $language->language; 2247 } 2248 2249 function wp_install_load_language( $request ) { 2250 $loading_language = ''; 2251 if ( ! empty( $request ) ) { 2252 $available_languages = get_available_languages(); 2253 if ( in_array( $request, $available_languages ) ) { 2254 $loading_language = $request; 2255 } 2256 } 2257 2258 if ( $loading_language ) { 2259 load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); 2260 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); 2261 return $loading_language; 2262 } 2263 2264 return false; 2265 }
Note: See TracChangeset
for help on using the changeset viewer.