From 66822ea6a99581ba33e14ff8a1fb5fe95979d288 Mon Sep 17 00:00:00 2001 From: aoaoa1 <84662035+aoaoa1@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E5=B7=B2?= =?UTF-8?q?=E7=9F=A5=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++ admin/preload.php | 2 +- assets/admin.css | 192 +++++++++++++++------------------------ class/local.php | 43 +++++---- class/log.php | 8 +- config.php | 12 ++- nicen-localize-image.php | 2 +- readme.txt | 20 ++-- tinymcc/local.js | 62 ++++++++----- 9 files changed, 179 insertions(+), 168 deletions(-) diff --git a/README.md b/README.md index 67500e6..432382a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ nicen-localize-image,是一款用于本地化文章的外部图片的插件, # 更新日志: +## 1.3.91 + +1. 修复编辑器插件存在相同图片链接时,只会替换一次的问题 +2. 修复本地化图片验证图片链接状态码,没有模拟Referer导致触发防盗链,刚好链接返回异常状态码时,会本地化报错的问题。 +3. 新增本地化时是否记录日志的选项,关闭后将不在记录日志。 + ## 1.3.9 1. 修复分类名包含特殊字符时,批量本地化时,分类无法正常显示的问题 diff --git a/admin/preload.php b/admin/preload.php index ec6b0ec..594bd38 100644 --- a/admin/preload.php +++ b/admin/preload.php @@ -23,7 +23,7 @@ } } -const NICEN_VERSION = '1.3.9'; //插件版本 +const NICEN_VERSION = '1.3.91'; //插件版本 /* * 定时任务接口 * */ diff --git a/assets/admin.css b/assets/admin.css index c83d451..bedca72 100644 --- a/assets/admin.css +++ b/assets/admin.css @@ -1,19 +1,16 @@ @charset "UTF-8"; [v-cloak] { - display: none; -} + display: none; } #VueApp .ant-form-item-children dd, #VueApp .ant-form-item-children li { - margin-bottom: 0; -} + margin-bottom: 0; } #VueApp .info { line-height: 1.8; width: 150%; word-wrap: break-word; word-spacing: normal; - word-break: break-all; -} + word-break: break-all; } #VueApp .ant-input, #VueApp .ant-time-picker-input { box-sizing: border-box; @@ -33,121 +30,80 @@ background-image: none; border: 1px solid #d9d9d9; border-radius: 4px; - transition: all .3s; -} - -#VueApp .ant-input:focus, #VueApp .ant-time-picker-input:focus { - outline: 0 !important; - box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2) !important; -} - -#VueApp .ant-input:focus, #VueApp .ant-input:hover, #VueApp .ant-time-picker-input:focus, #VueApp .ant-time-picker-input:hover { - border-color: #40a9ff !important; - border-right-width: 1px !important; -} + transition: all .3s; } + #VueApp .ant-input:focus, #VueApp .ant-time-picker-input:focus { + outline: 0 !important; + box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2) !important; } + #VueApp .ant-input:focus, #VueApp .ant-input:hover, #VueApp .ant-time-picker-input:focus, #VueApp .ant-time-picker-input:hover { + border-color: #40a9ff !important; + border-right-width: 1px !important; } #VueApp .ant-form-item { - margin-bottom: 15px; -} + margin-bottom: 15px; } #VueApp .card-container { background: #f5f5f5; overflow: hidden; - padding: 24px; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-bar { - border-color: #fff; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-bar .ant-tabs-tab { - border-color: transparent; - background: transparent; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-bar .ant-tabs-tab-active { - border-color: #fff; - background: #fff; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content { - min-height: 150px; - margin-top: -16px; - /* VIP页面说明 */ -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip { - padding-bottom: 30px; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .top { - color: red; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features { - list-style: decimal; - margin-top: 32px; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .item { - display: flex; - justify-content: flex-start; - align-items: center; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .item:after { - background-color: black; - border-radius: 50%; - padding: 0 6px; - margin-left: 10px; - font-size: 12px; - font-weight: bold; - color: white; - content: "×"; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .ok:after { - background-color: #07c160; - border-radius: 50%; - padding: 0 6px; - margin-left: 10px; - font-size: 12px; - font-weight: bold; - color: white; - content: "√"; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .bottom { - margin-top: 32px; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content > .ant-tabs-tabpane { - background: #fff; - padding: 36px 42px 10px 42px; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .ant-form-item-label label { - display: flex; - align-items: center; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker { - display: inline-flex; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker .colorBtn { - width: 25px; - height: 25px; - border-radius: 50%; - margin-right: 15px; - cursor: pointer; - border: 1px solid #818181; -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker .box { - box-shadow: 0 0 15px 10px rgba(0, 0, 0, 0.15); -} - -#VueApp .card-container > .ant-tabs-card > .ant-tabs-content input { - background-color: inherit; -} + padding: 24px; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-bar { + border-color: #fff; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-bar .ant-tabs-tab { + border-color: transparent; + background: transparent; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-bar .ant-tabs-tab-active { + border-color: #fff; + background: #fff; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content { + min-height: 150px; + margin-top: -16px; + /* VIP页面说明 */ } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip { + padding-bottom: 30px; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .top { + color: red; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features { + list-style: decimal; + margin-top: 32px; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .item { + display: flex; + justify-content: flex-start; + align-items: center; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .item:after { + background-color: black; + border-radius: 50%; + padding: 0 6px; + margin-left: 10px; + font-size: 12px; + font-weight: bold; + color: white; + content: "×"; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .features .ok:after { + background-color: #07c160; + border-radius: 50%; + padding: 0 6px; + margin-left: 10px; + font-size: 12px; + font-weight: bold; + color: white; + content: "√"; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .vip .bottom { + margin-top: 32px; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content > .ant-tabs-tabpane { + background: #fff; + padding: 36px 42px 10px 42px; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .ant-form-item-label label { + display: flex; + align-items: center; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker { + display: inline-flex; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker .colorBtn { + width: 25px; + height: 25px; + border-radius: 50%; + margin-right: 15px; + cursor: pointer; + border: 1px solid #818181; } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content .m-colorPicker .box { + box-shadow: 0 0 15px 10px rgba(0, 0, 0, 0.15); } + #VueApp .card-container > .ant-tabs-card > .ant-tabs-content input { + background-color: inherit; } diff --git a/class/local.php b/class/local.php index 8b19079..0f39b51 100644 --- a/class/local.php +++ b/class/local.php @@ -166,7 +166,7 @@ function localImage( $url, $flag = true ) { /* * 判断链接是否可以访问 * */ - if ( $this->getHttpcode( $url ) != 200 ) { + if ( $this->getImage( $url, true ) != 200 ) { if ( $flag ) { exit( json_encode( ( [ 'code' => 0, @@ -311,26 +311,13 @@ function getLink( $filename ) { return $link; } - /** - * 获取网站状态码 - * */ - function getHttpcode( $url ) { - $response = wp_remote_get( $url, [ - 'sslverify' => false, - 'timeout' => 60, - ] ); - $http_code = wp_remote_retrieve_response_code( $response ); - - return $http_code; - } - /** * 获取图片内容 * * @param $url string,图片的链接 + * @param bool $option ,获取状态码 * */ - function getImage( $url ) { - + function getImage( $url, $option = false ) { $link = parse_url( $url );//解析链接 /* @@ -347,10 +334,17 @@ function getImage( $url ) { $res = wp_remote_get( $url, [ 'headers' => $headers, 'sslverify' => false, - 'timeout' => 120, + 'timeout' => 180, ] ); - return wp_remote_retrieve_body( $res ); + /* + * 是否是状态码判断 + * */ + if ( $option ) { + return wp_remote_retrieve_response_code( $res ); + } else { + return wp_remote_retrieve_body( $res ); + } } /** @@ -405,5 +399,18 @@ function saveAsData( $filename ) { $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); } + + /** + * 获取网站状态码 + * */ + function getHttpcode( $url ) { + $response = wp_remote_get( $url, [ + 'sslverify' => false, + 'timeout' => 60, + ] ); + $http_code = wp_remote_retrieve_response_code( $response ); + + return $http_code; + } } diff --git a/class/log.php b/class/log.php index 8ea413c..1988a9f 100644 --- a/class/log.php +++ b/class/log.php @@ -10,11 +10,13 @@ class Nicen_Log { private static $self; private $option = 'nicen_plugin_error_log'; + private $record_log; //是否需要记录日志 private $logs; private function __construct() { add_option( $this->option );//初始化选项 - $this->logs = get_option( $this->option ); + $this->logs = get_option( $this->option ); + $this->record_log = get_option( 'nicen_make_plugin_record_log' ); } /** @@ -38,6 +40,10 @@ public static function getInstance() { */ public function add( $log ) { + if ( ! $this->record_log ) { + return $log; + } + $now = date( "Y-m-d H:i:s", time() ); /* diff --git a/config.php b/config.php index b7d2203..b44ebdc 100644 --- a/config.php +++ b/config.php @@ -54,7 +54,7 @@ 'title' => '功能设置说明', 'callback' => 'nicen_make_plugin_form_text', 'args' => [ - 'info' => '插件提供两种本地化外部图片的功能:
编辑器本地化插件】启用后会在文章编辑器上方显示一个小图标,点击之后可以自动检测并本地化所有外部图片;
发布时自动本地化】启用后会在文章发布时自动本地化所有外部图片;推荐使用【编辑器本地化插件】在发布前进行本地化,当图片数量过多或者文件太大【发布时自动本地化】可能会导致请求卡死。' + 'info' => '插件提供两种本地化外部图片的功能,本地化时自动跳过重复链接的图片:
编辑器本地化插件】启用后会在文章编辑器上方显示一个小图标,点击之后可以自动检测并本地化所有外部图片;
发布时自动本地化】启用后会在文章发布时自动本地化所有外部图片;推荐使用【编辑器本地化插件】在发布前进行本地化,当图片数量过多或者文件太大【发布时自动本地化】可能会导致请求卡死。
保存到数据库】启用后会将图片信息保存到数据库,可在媒体库内看到这张图片,同时会生成多张不同大小的内容一样图片。' ] ], [ @@ -251,6 +251,13 @@ 'callback' => [ "render" => "nicen_plugin_local_log" ], + 'fields' => [ + [ + 'id' => 'nicen_make_plugin_record_log', + 'title' => '本地化时记录日志', + 'callback' => 'nicen_make_form_switch', + ], + ] ], [ "id" => "nicen_make_plugin_update", @@ -302,6 +309,9 @@ /*白名单*/ 'nicen_make_publish_white' => '', + + /*插件日志*/ + 'nicen_make_plugin_record_log' => '1' ] ); diff --git a/nicen-localize-image.php b/nicen-localize-image.php index 21e87ce..2e6518d 100644 --- a/nicen-localize-image.php +++ b/nicen-localize-image.php @@ -3,7 +3,7 @@ * Plugin Name: nicen-localize-image * Plugin URI:https://nicen.cn/2893.html * Description: 用于本地化文章的外部图片的插件,支持文章发布前通过编辑器插件本地化、文章发布时自动本地化、定时发布文章时自动本地化、已发布的文章批量本地化。 - * Version: 1.3.9 + * Version: 1.3.91 * Author: 友人a丶 * Author URI: https://nicen.cn * Text Domain: nicen-localize-image diff --git a/readme.txt b/readme.txt index 8e4e8f3..3023bee 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Donate link: https://nicen.cn/donate Requires at least: 5.6 Tested up to: 6.2 Requires PHP: 7.3 -Stable tag: 1.3.9 +Stable tag: 1.3.91 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -28,14 +28,20 @@ Gitee:https://gitee.com/friend-nicen/nicen-localize-image == Changelog == +v1.3.91 + +1. 修复编辑器插件存在相同图片链接时,只会替换一次的问题 +2. 修复本地化图片验证图片链接状态码,没有模拟Referer导致触发防盗链,刚好链接返回异常状态码时,会本地化报错的问题。 +3. 新增本地化时是否记录日志的选项,关闭后将不在记录日志。 + v1.3.9 -修复分类名包含特殊字符时,批量本地化时,分类无法正常显示的问题 -新增系统时间校准的功能开关,定时任务页面将展示当前系统时间和默认时区,避免由时区导致定时任务无法正常运行 -新增图片本地化后自动关联文章 -更新img匹配规则,兼容一些不规则的img标签 -修复开启图片本地化时保存到数据库功能后,本地化报错的问题 -优化插件后台的样式 +1. 修复分类名包含特殊字符时,批量本地化时,分类无法正常显示的问题 +2. 新增系统时间校准的功能开关,定时任务页面将展示当前系统时间和默认时区,避免由时区导致定时任务无法正常运行 +3. 新增图片本地化后自动关联文章 +4. 更新img匹配规则,兼容一些不规则的img标签 +5. 修复开启图片本地化时保存到数据库功能后,本地化报错的问题 +6. 优化插件后台的样式 v1.3.83 diff --git a/tinymcc/local.js b/tinymcc/local.js index f92bf40..d27585f 100644 --- a/tinymcc/local.js +++ b/tinymcc/local.js @@ -11,6 +11,20 @@ tinymce.create('tinymce.plugins.local', { init: function (ed, url) { + + /** + * 替换所有 + * @param old + * @param search + * @param re + */ + function replaceAll(old, search, re) { + while (old.indexOf(search) > -1) { + old = old.replace(search, re); + } + return old; + } + /* * 替换编辑器内容 * */ @@ -164,32 +178,38 @@ let code = await new Promise((resolve) => { - /* - * 请求服务器接口 - * */ - $.post('/?nicen_make_replace=1', { - private: POST_KEY, - img: i - }, function (res) { + try { - if (res.code === -1) { - layer.msg(res.result); - resolve(0); - } else if (res.code === 1) { - /* - * 替换变量里的内容 - * */ - content = content.replace(html2Escape(i), res.result); - } else { - number--; //未成功 - layer.msg(res.result); - } + /* + * 请求服务器接口 + * */ + $.post('/?nicen_make_replace=1', { + private: POST_KEY, + img: i + }, function (res) { - resolve(1); //退出本次任务 + if (res.code === -1) { + layer.msg(res.result); + resolve(0); + } else if (res.code === 1) { + /* + * 替换变量里的内容 + * */ + content = replaceAll(content, html2Escape(i), res.result); - }, 'json') + } else { + number--; //未成功 + layer.msg(res.result); + } + resolve(1); //退出本次任务 + + }, 'json'); + + } catch (e) { + resolve(0); //退出本次任务 + } })