From 24e6a23fd121b1167b1a577c00c4856cfe8148d6 Mon Sep 17 00:00:00 2001 From: sunxiyuan Date: Fri, 10 Apr 2020 15:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=AE=BE=E7=BD=AE=E9=A1=B5ta?= =?UTF-8?q?b=EF=BC=8C=E5=B9=B6=E5=B0=86=E7=A4=BE=E5=8C=BA=E6=BA=90?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=9A=84select=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=BB=E6=BA=90=E5=92=8C=E5=A4=87=E6=BA=90?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 25 +++++---- settings.html | 146 ++++++++++++++++++++------------------------------ 2 files changed, 73 insertions(+), 98 deletions(-) diff --git a/index.php b/index.php index ca15fea..969b737 100644 --- a/index.php +++ b/index.php @@ -77,9 +77,18 @@ class WP_CHINA_YES { return false; } - $options = get_option('wp_china_yes_options'); - $api_server = $options["custom_api_server"] ?: $options["api_server"]; - $download_server = $options["custom_download_server"] ?: $options["download_server"]; + $options = get_option('wp_china_yes_options'); + + if ($options["community"] == 1) { + $api_server = 'api.w.org.ixmu.net'; + $download_server = 'd.w.org.ixmu.net'; + } else { + $api_server = 'api.w.org.ibadboy.net'; + $download_server = 'd.w.org.ibadboy.net'; + } + + $api_server = $options["custom_api_server"] ?: $api_server; + $download_server = $options["custom_download_server"] ?: $download_server; $url = str_replace('api.wordpress.org', $api_server, $url); $url = str_replace('downloads.wordpress.org', $download_server, $url); @@ -146,15 +155,13 @@ EOT; } public static function set_config() { - if (( ! array_key_exists('api_server', $_POST) && ! array_key_exists('download_server', $_POST)) || - ( ! array_key_exists('community', $_POST) && ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) { + if ( ! array_key_exists('community', $_POST) || + ( ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) { self::error('参数错误', - 1); } self::set_wp_option( sanitize_text_field(trim($_POST['community'])), - sanitize_text_field(trim($_POST['api_server'])), - sanitize_text_field(trim($_POST['download_server'])), sanitize_text_field(trim($_POST['custom_api_server'])), sanitize_text_field(trim($_POST['custom_download_server'])) ); @@ -192,15 +199,11 @@ EOT; private static function set_wp_option( $community = 0, - $api_server = 'api.w.org.ibadboy.net', - $download_server = 'd.w.org.ibadboy.net', $custom_api_server = '', $custom_download_server = '' ) { $options = array(); $options['community'] = (int) $community; - $options['api_server'] = $api_server; - $options['download_server'] = $download_server; $options['custom_api_server'] = $custom_api_server; $options['custom_download_server'] = $custom_download_server; update_option("wp_china_yes_options", $options); diff --git a/settings.html b/settings.html index fd285a2..90df378 100644 --- a/settings.html +++ b/settings.html @@ -16,80 +16,65 @@ - - - - - - -
- 使用社区源 -
- - - - - - - -
- -
- 自定义源 - 若配置自定义源则会覆盖社区源 - 搭建方法 - -
- - - - - - - - - - -
- - 保存配置 - - -
-
-
-
- - - - -
+ + + + +
+ 使用社区仓库源 +
+ + + + 主源 + + + 备源 + + + +
+ +
+ 自定义源 + 若配置自定义源则会覆盖社区仓库源 + 搭建方法 + +
+ + + + + + + + + + +
+ + 保存配置 + + +
+
+
@@ -120,7 +105,6 @@ data() { return { external_api: {}, - server_desc: '', token: { get_config: '', set_config: '' @@ -129,19 +113,10 @@ community: '0', custom_api_server: '', custom_download_server: '', - api_server: '', - download_server: '', } } }, methods: { - changeServer() { - let server = this.external_api.server[this.mirrors_form.community]; - - this.server_desc = server.desc; - this.mirrors_form.api_server = server.api_server; - this.mirrors_form.download_server = server.download_server; - }, getConfig() { let vm = this; let data = new FormData(); @@ -154,7 +129,6 @@ axios.get('https://wp-china-yes.ibadboy.net') .then(function (response) { vm.external_api = response.data; - vm.changeServer(); }) .catch(function (error) { vm.$message({ @@ -191,8 +165,6 @@ data.append('community', vm.mirrors_form.community); data.append('custom_api_server', vm.mirrors_form.custom_api_server); data.append('custom_download_server', vm.mirrors_form.custom_download_server); - data.append('api_server', vm.mirrors_form.api_server); - data.append('download_server', vm.mirrors_form.download_server); axios.post(root_url + 'wp-admin/admin-ajax.php', data) .then(function (response) {