diff --git a/README.md b/README.md index 1e48ee0baaf288f9488d69fdffaa5f76ac16329d..1ac742c3ef58778edd5e35a0b1cbfcfd3e07e41b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ | ---------- | ------------------------------------------------------------ | | 中文名称 | 腾讯云对象存储(COS)插件 | | 英文名称 | tencentcloud-cos | -| 最新版本 | 1.0.2 (2021.8.20) | +| 最新版本 | 1.0.3 (2021.11.25) | | 适用平台 | [WordPress](https://wordpress.org/) | | 适用产品 | [腾讯云对象存储(COS)](https://cloud.tencent.com/product/cos) | | GitHub项目 | [tencentcloud-wordpress-plugin-cos](https://github.com/Tencent-Cloud-Plugins/tencentcloud-wordpress-plugin-cos) | @@ -33,6 +33,8 @@ - 支持上传文件自动重命名-支持三种命名格式 - API动态获取域名列表 - 本地调试日志功能 +- 支持腾讯云数据万象 CI 文件审核 +- 支持在网页中在线预览 office 文档 ## 3.安装指引 ### 3.1.部署方式一:通过GitHub部署安装 @@ -62,6 +64,8 @@ ![](./images/cos3.png) > 新增调试功能,开启后如果插件报错,错误信息能保留在本地日志文件中,方便排查问题 +![](./images/cos4.png) +> 支持媒体文件在线预览功能,新增腾讯云数据万象 CI 文件审核指引 ### 4.2.名词解释 - **自定义密钥**:插件提供统一密钥管理,既可在多个腾讯云插件之间共享SecretId和SecretKey,也可为插件配置单独定义的腾讯云密钥。 - **SecretId**:在腾讯云云平台API密钥上申请的标识身份的 SecretId。详情参考[腾讯云文档](https://cloud.tencent.com/document/product) @@ -97,9 +101,14 @@ ## 7.版本迭代记录 +### 2021.11.25 tencentcloud-wordpress-plugin-cos v1.0.3 +- 支持腾讯云数据万象 CI 文件审核 +- 支持在网页中在线预览 office 文档 + ### 2021.8.20 tencentcloud-wordpress-plugin-cos v1.0.2 - 更新对象云存储插件上传文件自动重命名的功能,支持三种不同命名格式。 - 新增本地调试日志功能 + ### 2020.12.11 tencentcloud-wordpress-plugin-cos v1.0.1 - 支持在windows环境下运行 diff --git a/images/cos4.png b/images/cos4.png new file mode 100644 index 0000000000000000000000000000000000000000..697a43b48b02595e88962cdf3b5d0f4732b44041 Binary files /dev/null and b/images/cos4.png differ diff --git a/tencentcloud-cos/assets/javascript/txwp_cos_setting.js b/tencentcloud-cos/assets/javascript/txwp_cos_setting.js index a97bd408b7bdfb29c6b346db4c5ad53411949607..545c59d869fc70e7496d4d5b24c8668b57a83f0c 100644 --- a/tencentcloud-cos/assets/javascript/txwp_cos_setting.js +++ b/tencentcloud-cos/assets/javascript/txwp_cos_setting.js @@ -298,7 +298,6 @@ jQuery(function ($) { $('#img_process_style_default').change(function () { if ($('#img_process_style_default')[0].checked) { $('#img_process_style_customize_input')[0].disabled = true; - $('#img_process_style_customize_input')[0].value = ''; } }); diff --git a/tencentcloud-cos/class-tencent-cloud-cos.php b/tencentcloud-cos/class-tencent-cloud-cos.php index 0968988cecd5ef9b3705f70e4970230fdb56bff4..5e33204f54a0f54a05c7e171246934b14be68145 100644 --- a/tencentcloud-cos/class-tencent-cloud-cos.php +++ b/tencentcloud-cos/class-tencent-cloud-cos.php @@ -161,8 +161,12 @@ class TencentWordpressCOS extends TencentWordpressCosBase 'img_process' => array( 'switch' => '', 'style_value' => '' + ), + 'attachment_preview' => array( + 'switch' => '', ) ) + ); $tcwpcos_options = self::getCosOptons(); @@ -271,27 +275,25 @@ class TencentWordpressCOS extends TencentWordpressCosBase CosDebugLog::writeDebugLog('error', 'msg : file not exist!', __FILE__, __LINE__); } $tcwpcos_options = self::getCosOptons(); - if (isset($tcwpcos_options['opt']['auto_rename_config']) + if (isset($tcwpcos_options['opt']['auto_rename_config'], $tcwpcos_options['opt']['auto_rename_config']['auto_rename_switch']) && $tcwpcos_options['opt']['auto_rename_config']['auto_rename_switch'] === 'on') { - $extension = pathinfo($filename, PATHINFO_EXTENSION); - $tmp_filename = pathinfo($filename, PATHINFO_FILENAME); - $time = date('YmdHis', current_time('timestamp')); - $rand = mt_rand(100, 999); if ($tcwpcos_options['opt']['auto_rename_config']['auto_rename_style_choice'] === '0') { // 默认(日期+随机串) - return "{$time}{$rand}.{$extension}"; + return date("YmdHis") . mt_rand(100, 999) + . pathinfo($filename, PATHINFO_EXTENSION); } elseif ($tcwpcos_options['opt']['auto_rename_config']['auto_rename_style_choice'] === '1') { // 格式一(日期+文件名+随机串) - return "{$time}{$tmp_filename}{$rand}.{$extension}"; + return date("YmdHis") . pathinfo($filename)['filename'] . mt_rand(100, 999) . "." + . pathinfo($filename, PATHINFO_EXTENSION); } elseif ($tcwpcos_options['opt']['auto_rename_config']['auto_rename_style_choice'] === '2') { // 格式二(自定义前缀+日期+文件名称+自定义后缀) - return "{$tcwpcos_options['opt']['auto_rename_config']['auto_rename_customize_prefix']}" - . "{$time}{$tmp_filename}" - . "{$tcwpcos_options['opt']['auto_rename_config']['auto_rename_customize_postfix']}.{$extension}"; + return $tcwpcos_options['opt']['auto_rename_config']['auto_rename_customize_prefix'] . + date("YmdHis") . pathinfo($filename)['filename'] . $tcwpcos_options['opt']['auto_rename_config']['auto_rename_customize_postfix'] + . "." . pathinfo($filename, PATHINFO_EXTENSION); } + } else { + return $filename; } - - return $filename; } /** @@ -461,7 +463,7 @@ class TencentWordpressCOS extends TencentWordpressCosBase } /** - * 文章内容中的图片数据万象处理 + * 文章内容中的图片数据万象处理和文档预览功能处理 * @param $content * @return string|string[]|null */ @@ -485,9 +487,71 @@ class TencentWordpressCOS extends TencentWordpressCosBase }, $content); } + + // 文档预览功能 + if (isset($tcwpcos_options['opt']['attachment_preview'], $tcwpcos_options['opt']['attachment_preview']['switch']) + && $tcwpcos_options['opt']['attachment_preview']['switch'] === 'on') { + $flag = false; // 预览替换标记 + + $preg='//is'; + // wordpress 5.8 版本的默认编辑器 + if ($flag === false) { + $iframeString = '
'; + $pattern = '/
/u'; + preg_match_all($pattern, $content, $matches); + $repaceStrings = array_unique($matches[0]); + foreach ($repaceStrings as $urlString) { + preg_match($preg, $urlString, $matche); + if (!empty($matche) && self::validPostFix($matche[1])) { + $newIframeString = str_replace('%uslstring%', $matche[1], $iframeString); + $content = str_replace($urlString, $newIframeString.$urlString, $content); + $flag = true; + } + } + } + + // 使用经典编辑器插件 + if ($flag === false) { + $iframeString = '

'; + $pattern = '/

/u'; + preg_match_all($pattern, $content, $matches); + $repaceUrls = array_unique($matches[0]); + if (!empty($repaceUrls)) { + foreach ($repaceUrls as $urlString) { + preg_match($preg, $urlString, $matche); + if (!empty($matche) && self::validPostFix($matche[1])) { + $newIframeString = str_replace('%uslstring%', $matche[1], $iframeString); + $content = str_replace($urlString, $newIframeString.$urlString, $content); + $flag = true; + } + } + } + } + } return $content; } + /** + * 判断是否支持文件预览 + * @param $fileUrl + * @return bool + */ + public static function validPostFix($fileUrl) + { + // 获取文件后缀 + $pos = strripos($fileUrl, '.'); + $postfix = substr($fileUrl, $pos+1); + if (empty($postfix)) { + return false; + } + $postfixArray = array('pptx', 'ppt', 'pot','potx', 'pps', 'ppsx', 'dps', 'dpt', 'pptm', 'potm', 'ppsm', + 'doc', 'dot', 'wps', 'wpt', 'docx', 'dotx', 'docm', 'dotm', + 'xls', 'xlt', 'et', 'ett', 'xlsx', 'xltx', 'csv', 'xlsb', 'xlsm', 'xltm', 'ets', + 'pdf', 'lrc', 'c', 'cpp', 'h', 'asm', 's', 'java', 'asp', 'bat', 'bas', 'prg', 'cmd', + 'rtf', 'txt', 'log', 'xml', 'htm', 'htm'); + return in_array($postfix, $postfixArray); + } + /** * 插件列表加入"配置"按钮 * @param $links string 插件配置页面的链接地址 @@ -553,6 +617,12 @@ class TencentWordpressCOS extends TencentWordpressCosBase unset($tcwpcos_options['opt']['auto_rename_config']['auto_rename_switch']); } + if (isset($options['attachment_preview_switch']) && $options['attachment_preview_switch'] === 'on') { + $tcwpcos_options['opt']['attachment_preview']['switch'] = 'on'; + } else { + unset($tcwpcos_options['opt']['attachment_preview']); + } + if (isset($options['automatic_logging']) && $options['automatic_logging'] == 'on') { $tcwpcos_options['opt']['automatic_logging'] = 'on'; @@ -635,10 +705,8 @@ class TencentWordpressCOS extends TencentWordpressCosBase $region = sanitize_text_field($_POST['region']); $bucketName = sanitize_text_field($_POST['bucket']); $tcwpcos_options = self::getCosOptons(); - $tcwp_common_options = get_option('tencent_wordpress_common_options'); - if (isset($tcwpcos_options) && isset($tcwpcos_options['customize_secret']) && - $tcwpcos_options['customize_secret'] === false && $tcwp_common_options['site_sec_on'] === true) { - + if (isset($tcwpcos_options) && isset($tcwpcos_options['customize_secret']) && $tcwpcos_options['customize_secret'] === false) { + $tcwp_common_options = get_option('tencent_wordpress_common_options'); $secretId = sanitize_text_field($tcwp_common_options['secret_id']); $secretKey = sanitize_text_field($tcwp_common_options['secret_key']); } else { @@ -764,6 +832,10 @@ class TencentWordpressCOS extends TencentWordpressCosBase $options['img_process_style_customize'] = sanitize_text_field($output['img_process_style_customize']); } + if (isset($output['attachment_preview_switch'])) { + $options['attachment_preview_switch'] = sanitize_text_field($output['attachment_preview_switch']); + } + if (isset($output['auto_rename'])) { $options['auto_rename'] = sanitize_text_field($output['auto_rename']); } diff --git a/tencentcloud-cos/readme.txt b/tencentcloud-cos/readme.txt index 291d93153e7e806adac6548e6a325fe818badf9c..d97f8c8c257b3875bf7cbc0050514b02822a0c97 100644 --- a/tencentcloud-cos/readme.txt +++ b/tencentcloud-cos/readme.txt @@ -5,7 +5,7 @@ Tags:腾讯云wordpress, COS,腾讯云对象存储,腾讯云存储分离,腾讯 Requires at least: 5.5 Tested up to: 5.8 Requires PHP: 8 -Stable tag: 1.0.2 +Stable tag: 1.0.3 License: Apache 2.0 License URI: http://www.apache.org/licenses/LICENSE-2.0.txt @@ -20,6 +20,9 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.txt * 6、支持腾讯云数据万象 CI 图片处理 * 7、支持上传文件自动重命名 * 8、支持同步历史附件到 COS +* 9、新增本地调试日志 +* 10、支持腾讯云数据万象 CI 文件审核 +* 11、支持在网页中在线预览 office 文档 == Installation == * 1、把tencentcloud-cos文件夹上传到/wp-content/plugins/目录下
@@ -37,6 +40,11 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.txt 1. screenshot-1.png == Changelog == += 1.0.3 = +* 1、新增文件审核指引 +* 2、新增文件预览功能 +* 3、数据万象 CI 文件预审核 + = 1.0.2 = * 1、新增本地调试日志 * 2、支持自定义重命名规则 diff --git a/tencentcloud-cos/tencentcloud-cos.php b/tencentcloud-cos/tencentcloud-cos.php index 3fb9903d0932a2ea615337f0382bc8aedbfffe4d..af4b6454aff82f956e4869ba8211dfd64e443e3c 100644 --- a/tencentcloud-cos/tencentcloud-cos.php +++ b/tencentcloud-cos/tencentcloud-cos.php @@ -3,7 +3,7 @@ * Plugin Name: tencentcloud-cos * Plugin URI: https://openapp.qq.com/ * Description: 通过腾讯云对象存储服务使网站中静态文件无缝同步腾讯云对象存储COS,提升网站内容访问速度,降低本地存储开销。 - * Version: 1.0.2 + * Version: 1.0.3 * Author: 腾讯云 * Author URI: https://cloud.tencent.com/ * @@ -27,7 +27,7 @@ if (!defined('ABSPATH')) { die('We\'re sorry, but you can not directly access this file.'); } -defined('TENCENT_WORDPRESS_COS_VERSION') or define('TENCENT_WORDPRESS_COS_VERSION', '1.0.2'); +defined('TENCENT_WORDPRESS_COS_VERSION') or define('TENCENT_WORDPRESS_COS_VERSION', '1.0.3'); defined('TENCENT_WORDPRESS_COS_PLUGIN_DIR') or define('TENCENT_WORDPRESS_COS_PLUGIN_DIR', plugin_dir_path(__FILE__)); defined('TENCENT_WORDPRESS_COS_LOGS') or define('TENCENT_WORDPRESS_COS_LOGS', plugin_dir_path(__FILE__) . 'logs'); diff --git a/tencentcloud-cos/tencentcloud-plugin-cos-setting-page.php b/tencentcloud-cos/tencentcloud-plugin-cos-setting-page.php index ac77c211b117b3d9a79f8f5d99ef11367df0297a..e69a7ef3949443b77f14dc98dea8128ef507004b 100644 --- a/tencentcloud-cos/tencentcloud-plugin-cos-setting-page.php +++ b/tencentcloud-cos/tencentcloud-plugin-cos-setting-page.php @@ -388,7 +388,7 @@ $ajax_url = admin_url(TENCENT_WORDPRESS_COS_ADMIN_AJAX); ?> >
了解详情

@@ -413,8 +413,13 @@ $ajax_url = admin_url(TENCENT_WORDPRESS_COS_ADMIN_AJAX); echo 'checked="TRUE"'; } ?> - > 文字水印 + > 默认(文字水印,不可修改) +
+

+
+ +
+ +
+
+ +
+ +
+ + > + +
+

使用文档预览服务,需要开启存储桶的文档预览服务,点击前往开启

+
+
+ +
+
@@ -480,8 +521,6 @@ $ajax_url = admin_url(TENCENT_WORDPRESS_COS_ADMIN_AJAX);
- - @@ -545,7 +584,6 @@ $ajax_url = admin_url(TENCENT_WORDPRESS_COS_ADMIN_AJAX);