function on_ajax_wp_native_dashboard_download_language() { if (is_user_logged_in() && current_user_can('manage_options')) { global $wp_filesystem, $parent_file; $current_parent = $parent_file; $parent_file = 'tools.php'; //needed for screen icon :-) if (function_exists('set_current_screen')) { set_current_screen('tools'); } //WP 3.0 fix //check the file system ob_start(); $url = 'admin-ajax.php'; if (false === ($credentials = request_filesystem_credentials($url))) { $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { header('Status: 401 Unauthorized'); header('HTTP/1.1 401 Unauthorized'); echo $data; exit; } return; } if (!WP_Filesystem($credentials)) { request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { header('Status: 401 Unauthorized'); header('HTTP/1.1 401 Unauthorized'); echo $data; exit; } return; } ob_end_clean(); $parent_file = $current_parent; $file = basename($_POST['file']); $lang = substr($file, 0, -3); $tagged = $this->tagged_version; if (preg_match('/\\/tags\\/(\\d+\\.\\d+|\\d+\\.\\d+\\.\\d+)\\/messages/', $_POST['file'], $h)) { $tagged = $h[1]; } //disable snitch $snitch = $this->_snitch_off(); $response_mo = @wp_remote_get("http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/messages/" . $file); if ($snitch) { $this->_snitch_on(); } if (!is_wp_error($response_mo) && $response_mo['response']['code'] != 404) { ob_start(); if (WP_Filesystem($credentials) && is_object($wp_filesystem)) { $dir = $wp_filesystem->find_folder(WP_LANG_DIR . '/'); if (!$wp_filesystem->is_dir($dir)) { //US original versions doesn't contain any languages folder ! if ($wp_filesystem->method == 'direct') { $dir = WP_LANG_DIR . '/'; } else { $dir = '/' . str_replace(ABSPATH, '', WP_LANG_DIR . '/'); } if ($wp_filesystem->mkdir($dir) === false) { ob_end_clean(); header('Status: 404 Not Found'); header('HTTP/1.1 404 Not Found'); echo sprintf(__("The missing languages directory could not be created at '%s'.", 'wp-native-dashboard'), $dir); exit; } } $done = $wp_filesystem->put_contents($dir . $file, $response_mo['body']); if ($done) { global $wp_version; $additional_download_files = array($dir . 'continents-cities-' . $file => array('min-version' => '2.8', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/continents-cities-" . $file, 'alternative' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/messages/continents-cities-" . $file), $dir . 'ms-' . $file => array('min-version' => '3.0', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/ms-" . $file, 'alternative' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/messages/ms-" . $file), $dir . 'admin-' . $file => array('min-version' => '3.4', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/admin-" . $file, 'alternative' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/messages/admin-" . $file), $dir . 'admin-network-' . $file => array('min-version' => '3.4', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/admin-network-" . $file, 'alternative' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/messages/admin-network-" . $file), $dir . $lang . '.php' => array('min-version' => '2.0', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/" . $lang . '.php', 'alternative' => false), $dir . $lang . '.css' => array('min-version' => '3.0', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/" . $lang . '.css', 'alternative' => false), $dir . $lang . '-ie.css' => array('min-version' => '3.0', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/" . $lang . '-ie.css', 'alternative' => false), $dir . 'ms-' . $lang . '.css' => array('min-version' => '3.0', 'location' => "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $tagged . "/dist/wp-content/languages/ms-" . $lang . '.css', 'alternative' => false)); foreach ($additional_download_files as $fsf => $desc) { if (version_compare($wp_version, $desc['min-version'], '>=')) { $snitch = $this->_snitch_off(); $response_additional = @wp_remote_get($desc['location']); if ($snitch) { $this->_snitch_on(); } if (is_wp_error($response_additional) || $response_additional['response']['code'] == 404) { if ($desc['alternative'] !== false) { $snitch = $this->_snitch_off(); $response_additional = @wp_remote_get($desc['alternative']); if ($snitch) { $this->_snitch_on(); } } } if (!is_wp_error($response_additional) && $response_additional['response']['code'] != 404) { $wp_filesystem->put_contents($fsf, $response_additional['body']); } else { //special turn for required but not yet provided RTL extension files //enables RTL support for affected languages anyway if ($fsf == $dir . $lang . '.php' && wp_native_dashboard_is_rtl_language($lang) && version_compare($wp_version, '3.4-alpha', '<')) { $wp_filesystem->put_contents($fsf, wp_native_dashboard_rtl_extension_file_content()); } } } } ob_end_clean(); $mo = str_replace('\\', '/', WP_LANG_DIR . '/' . $file); ?> <tr id="tr-i18n-installed-<?php echo $lang; ?> "> <td><span class="i18n-file csp-<?php echo $lang; ?> "><?php echo wp_native_dashboard_get_name_of($lang); ?> </span></td> <td><?php echo wp_native_dashboard_is_rtl_language($lang) ? __('right to left', 'wp-native-dashboard') : ' '; ?> </td> <td><?php echo filesize($mo) . ' Bytes'; ?> </td> <td><?php if ($lang != 'en_US') { ?> <a class="csp-delete-local-file" href="<?php echo $mo; ?> "><?php _e('Delete', 'wp-native-dashboard'); ?> </a> <span><img src="images/loading.gif" class="ajax-feedback" title="" alt="" /></span><?php } ?> </td> </tr> <?php exit; } } ob_end_clean(); } } header('Status: 404 Not Found'); header('HTTP/1.1 404 Not Found'); _e("The download is currently not available.", 'wp-native-dashboard'); exit; }
function on_print_metabox_installed_i18n() { $installed = wp_native_dashboard_collect_installed_languages(); ?> <p><?php _e('Your WordPress installation currectly supports this list of languages at your Dashboard.', 'wp-native-dashboard'); ?> </p> <table id="table_local_i18n" class="widefat fixed" cellspacing="0"> <tbody> <?php $state = 0; foreach ($installed as $lang) { $state = ($state + 1) % 2; $mo = str_replace('\\', '/', WP_LANG_DIR . '/' . $lang . '.mo'); ?> <tr id="tr-i18n-installed-<?php echo $lang; ?> " class="<?php if ($state) { echo 'alternate'; } ?> "> <td><span class="i18n-file csp-<?php echo $lang; ?> "><?php echo wp_native_dashboard_get_name_of($lang); ?> </span></td> <td><?php echo wp_native_dashboard_is_rtl_language($lang) ? __('right to left', 'wp-native-dashboard') : ' '; ?> </td> <td><?php echo is_file($mo) ? filesize($mo) . ' Bytes' : '-n.a.-'; ?> </td> <td><?php if ($lang != 'en_US') { ?> <a class="csp-delete-local-file" href="<?php echo $mo; ?> "><?php _e('Delete', 'wp-native-dashboard'); ?> </a> <span><img src="images/loading.gif" class="ajax-feedback" title="" alt="" /></span><?php } ?> </td> </tr> <?php } ?> </tbody> </table> <?php }