From 6343b1dfbc8491c51b6d61a82b1d707bf8c7469b Mon Sep 17 00:00:00 2001 From: sunxiyuan Date: Thu, 12 Mar 2020 17:14:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=A4=BE=E5=8C=BA=E6=BA=90?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E3=80=81=E8=87=AA=E5=AE=9A=E4=B9=89=E6=BA=90?= =?UTF-8?q?=20=E6=9C=AC=E6=AC=A1=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BE=83=E5=A4=9A=EF=BC=8C=E9=9A=BE=E5=85=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?BUG=EF=BC=8C=E4=B8=8D=E5=BB=BA=E8=AE=AE=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=8E=AF=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 55 +++++++++++++ index.php | 134 +++++++++++++++++------------- readme.md | 23 ++++-- readme.txt | 14 +++- settings.html | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 383 insertions(+), 66 deletions(-) create mode 100644 api.php create mode 100644 settings.html diff --git a/api.php b/api.php new file mode 100644 index 0000000..df2ca1f --- /dev/null +++ b/api.php @@ -0,0 +1,55 @@ + 0, + 'message' => $message, + 'data' => $data + ], JSON_UNESCAPED_UNICODE); + exit; +} + +function error($message = '', $code = - 1) { + header('Status:500'); + echo json_encode([ + 'code' => $code, + 'message' => $message + ], JSON_UNESCAPED_UNICODE); + exit; +} diff --git a/index.php b/index.php index 00844e5..5b2572d 100644 --- a/index.php +++ b/index.php @@ -1,21 +1,33 @@ is_enabled() && $proxy->send_through_proxy($url)) { $options['proxy'] = new Requests_Proxy_HTTP($proxy->host() . ':' . $proxy->port()); @@ -145,17 +162,14 @@ class WP_CHINA_YES { } } - // Avoid issues where mbstring.func_overload is enabled mbstring_binary_safe_encoding(); try { $requests_response = Requests::request($url, $headers, $data, $type, $options); - // Convert the response into an array $http_response = new WP_HTTP_Requests_Response($requests_response, $r['filename']); $response = $http_response->to_array(); - // Add the original object to the array. $response['http_response'] = $http_response; } catch (Requests_Exception $e) { $response = new WP_Error('http_request_failed', $e->getMessage()); @@ -163,18 +177,6 @@ class WP_CHINA_YES { reset_mbstring_encoding(); - /** - * Fires after an HTTP API response is received and before the response is returned. - * - * @param array|WP_Error $response HTTP response or WP_Error object. - * @param string $context Context under which the hook is fired. - * @param string $class HTTP transport used. - * @param array $r HTTP request arguments. - * @param string $url The request URL. - * - * @since 2.8.0 - * - */ do_action('http_api_debug', $response, 'response', 'Requests', $r, $url); if (is_wp_error($response)) { return $response; @@ -193,25 +195,47 @@ class WP_CHINA_YES { ); } - /** - * Filters the HTTP API response immediately before the response is returned. - * - * @param array $response HTTP response. - * @param array $r HTTP request arguments. - * @param string $url The request URL. - * - * @since 2.9.0 - * - */ return apply_filters('http_response', $response, $r, $url); } public static function plugin_row_meta($links, $file) { $base = plugin_basename(WP_CHINA_YES_BASE_FILE); if ($file == $base) { - $links[] = '插件发布页'; + $links[] = '发布地址'; + $links[] = 'GitHub'; } return $links; } + + public static function action_links($links, $file) { + if ($file != plugin_basename(WP_CHINA_YES_BASE_FILE)) { + return $links; + } + + $settings_link = '设置'; + + array_unshift($links, $settings_link); + + return $links; + } + + public static function admin_menu() { + add_options_page( + 'WP-China-Yes', + 'WP-China-Yes', + 'manage_options', + self::$name, + array(__CLASS__, 'settings') + ); + } + + public static function settings() { + echo << + +EOT; + } } \ No newline at end of file diff --git a/readme.md b/readme.md index 13197b6..18bbb2b 100644 --- a/readme.md +++ b/readme.md @@ -2,20 +2,29 @@ ## 介绍 -因为WordPress的服务器都在国外,所以中国大陆的用户在访问由WordPress官方提供的服务时总是很缓慢。 +因为WordPress官方的服务器都在国外,所以中国大陆的用户在访问由WordPress官方提供的服务(插件、主题商城,WP程序版本更新等)时总是很缓慢。 近期又因为被攻击的原因,WordPress的CDN提供商屏蔽了中国大陆的流量,导致大陆用户访问插件主题商城等服务时报429错误。 -为解决上述问题,我在大陆境内架设了缓存加速节点,用以加快WordPress官方服务在中国大陆的访问速度,并规避429报错问题。 +为解决上述问题,我在大陆境内架设了基于反向代理的缓存加速节点,用以加快WordPress官方服务在中国大陆的访问速度,并规避429报错问题。 -为使更多的使用WordPress的同学能够用上大陆加速节点,我开发了WP-China-Yes插件,以求帮助大家方便简洁的替换服务链接。 +此加速节点是直接为你的站点与WordPress总部服务器的一切通信做加速,加速范围包括但不限于:插件、主题商城的资源下载、作品图片、作者头像、主题预览等…… + +为使更多的使用WordPress的同学能够用上大陆加速节点,我开发了WP-China-Yes插件,以求帮助大家方便简洁的替换官方服务链接为大陆节点。 + +这个是一个公益项目,我始终都不会以任何借口对插件、加速节点的使用权等进行收费。 ## 使用方法 +Master上的是开发中的版本,可能存在BUG。推荐安装最新稳定版:[点击下载](https://github.com/sunxiyuan/wp-china-yes/releases/download/v1.0.1/wp-china-yes.zip) + 下载并安装插件后直接启用即可,该插件会自动接管所有WP访问境外服务器的流量。 -## 广告 +## 开发计划 -我在开发一个WordPress数据库实时增量备份的插件,该插件可以做到回溯数据到任意时间点。 - -插件最终会以开源的形式放出,对此感兴趣的朋友请加我QQ:1642491905,提供你的宝贵建议并担任测试人员 ^_^ \ No newline at end of file +### v2.0.0 + - 社区源列表 已完成,等待测试 + - 自定义源支持 已完成,等待测试 + +### v1.0.0 + - 基本功能 已完成 \ No newline at end of file diff --git a/readme.txt b/readme.txt index 80a89d2..1f28048 100644 --- a/readme.txt +++ b/readme.txt @@ -5,15 +5,17 @@ Tags: China Super, 429, WP China Yes, wp-china-yes, WP-China-Yes Requires at least: 4.5 Tested up to: 5.4.0 Requires PHP: 5.2 -Stable tag: 1.0.1 +Stable tag: 2.0.0 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -WP-China-Yes将接管WP站点访问官方服务时的一切流量到大陆加速节点,包括但不限于:插件主题的安装、商城图片的展示、作者的头像、主题的预览等……从而全面加快WP站点后台的访问速度,并解决429报错问题 +W此插件将全面改善中国大陆站点在访问官方服务时的用户体验,原理是将官方仓库源替换为由社区志愿者维护的国内源。 == Description == -WP-China-Yes将接管WP站点访问官方服务时的一切流量到大陆加速节点,包括但不限于:插件主题的安装、商城图片的展示、作者的头像、主题的预览等……从而全面加快WP站点后台的访问速度,并解决429报错问题 +因为WordPress官方的服务器都在国外,所以中国大陆的用户在访问由WordPress官方提供的服务(插件、主题商城,WP程序版本更新等)时总是很缓慢。 +近期又因为被攻击的原因,WordPress的CDN提供商屏蔽了中国大陆的流量,导致大陆用户访问插件主题商城等服务时报429错误。 +为解决上述问题,我开发了WP-China-Yes插件,该插件可以将WP站点访问官方服务的一切流量迁移到由社区志愿者维护的大陆源上,从而全面优化用户体验。 == Frequently Asked Questions == @@ -23,5 +25,9 @@ WP-China-Yes将接管WP站点访问官方服务时的一切流量到大陆加速 == Changelog == += 2.0.0 = +* 社区源列表 完成 +* 自定义源支持 完成 + = 1.0.1 = -* 基本功能完成 \ No newline at end of file +* 基本功能 完成 \ No newline at end of file diff --git a/settings.html b/settings.html new file mode 100644 index 0000000..e41583f --- /dev/null +++ b/settings.html @@ -0,0 +1,223 @@ + + + + WP-China-Yes设置页 + + + +
+ + +

WP-China-Yes

+ 这是一个颠覆性的插件,她将全面改善中国大陆站点在访问官方服务时的用户体验
+ 原理是将官方仓库源替换为由社区志愿者维护的国内源,以此达到加速的目的 +
+ + + + + + + + +
+ 使用社区源 +
+ + + + + + + +
+ +
+ 自定义源 + 若配置自定义源则会覆盖社区源 + 搭建方法 + +
+ + + + + + + + + + +
+ + 保存配置 + + +
+
+
+
+ + + + +
+
+ + + 这是一个开源项目,她需要每个人的支持和贡献才能健康长久的发展。
+ 项目地址:GitHub +
+
+
+ + + + + + + \ No newline at end of file