From a0d8724e1ecdcb10580ad26f319b5dcf3696a27b Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Fri, 14 Aug 2020 08:36:30 +0800 Subject: [PATCH] Update version to 1.2.0 --- aliyun-oss-wordpress.php | 85 +++++++++++++++++++++++----------------- uninstall.php | 2 +- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/aliyun-oss-wordpress.php b/aliyun-oss-wordpress.php index 2641d45..3b063da 100644 --- a/aliyun-oss-wordpress.php +++ b/aliyun-oss-wordpress.php @@ -3,7 +3,7 @@ Plugin Name: OSS Aliyun Plugin URI: https://github.com/sy-records/aliyun-oss-wordpress Description: 使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.) -Version: 1.1.1 +Version: 1.2.0 Author: 沈唁 Author URI: https://qq52o.me License: Apache 2.0 @@ -14,7 +14,7 @@ require_once 'sdk/vendor/autoload.php'; use OSS\OssClient; use OSS\Core\OssException; -define('OSS_VERSION', "1.1.1"); +define('OSS_VERSION', '1.2.0'); define('OSS_BASEFOLDER', plugin_basename(dirname(__FILE__))); // 初始化选项 @@ -60,12 +60,9 @@ function oss_get_bucket_name() } /** - * 上传函数 - * - * @param $object - * @param $file - * @param $opt - * @return bool + * @param $object + * @param $file + * @param false $no_local_file */ function oss_file_upload($object, $file, $no_local_file = false) { @@ -167,14 +164,14 @@ function oss_upload_attachments($metadata) if (!in_array($metadata['type'], $image_mime_types)) { //生成object在oss中的存储路径 if (get_option('upload_path') == '.') { - //如果含有“./”则去除之 $metadata['file'] = str_replace("./", '', $metadata['file']); } $object = str_replace("\\", '/', $metadata['file']); - $object = str_replace(get_home_path(), '', $object); + $home_path = get_home_path(); + $object = str_replace($home_path, '', $object); //在本地的存储路径 - $file = get_home_path() . $object; //向上兼容,较早的WordPress版本上$metadata['file']存放的是相对路径 + $file = $home_path . $object; //向上兼容,较早的WordPress版本上$metadata['file']存放的是相对路径 //执行上传操作 oss_file_upload('/' . $object, $file, oss_is_delete_local_file()); @@ -200,8 +197,18 @@ function oss_upload_thumbs($metadata) $oss_options = get_option('oss_options', true); if (isset($metadata['file'])) { // Maybe there is a problem with the old version - $object ='/' . get_option('upload_path') . '/' . $metadata['file']; $file = $basedir . '/' . $metadata['file']; + $upload_path = get_option('upload_path'); + if ($upload_path != '.') { + $path_array = explode($upload_path, $file); + if (isset($path_array[1]) && !empty($path_array[1])) { + $object = '/' . $upload_path . $path_array[1]; + } + } else { + $object = '/' . $metadata['file']; + $file = str_replace('./', '', $file); + } + oss_file_upload($object, $file, (esc_attr($oss_options['nolocalsaving']) == 'true')); } //上传所有缩略图 @@ -214,11 +221,9 @@ function oss_upload_thumbs($metadata) } //得到本地文件夹和远端文件夹 $file_path = $basedir . '/' . dirname($metadata['file']) . '/'; - if (get_option('upload_path') == '.') { - $file_path = str_replace("\\", '/', $file_path); - $file_path = str_replace(get_home_path() . "./", '', $file_path); - } else { - $file_path = str_replace("\\", '/', $file_path); + $file_path = str_replace("\\", '/', $file_path); + if ($upload_path == '.') { + $file_path = str_replace('./', '', $file_path); } $object_path = str_replace(get_home_path(), '', $file_path); @@ -304,8 +309,13 @@ function oss_function_each(&$array) return $res; } +/** + * @param $dir + * @return array + */ function oss_read_dir_queue($dir) { + $dd = []; if (isset($dir)) { $files = array(); $queue = array($dir); @@ -325,17 +335,14 @@ function oss_read_dir_queue($dir) } closedir($handle); } - $i = ''; + $upload_path = get_option('upload_path'); foreach ($files as $v) { - $i++; if (!is_dir($v)) { - $dd[$i]['j'] = $v; - $dd[$i]['x'] = '/' . get_option('upload_path') . explode(get_option('upload_path'), $v)[1]; + $dd[] = ['filepath' => $v, 'key' => '/' . $upload_path . explode($upload_path, $v)[1]]; } } - } else { - $dd = ''; } + return $dd; } @@ -378,24 +385,28 @@ function oss_setting_page() } if (!empty($_POST) and $_POST['type'] == 'aliyun_oss_all') { - $synv = oss_read_dir_queue(get_home_path() . get_option('upload_path')); - $i = 0; - foreach ($synv as $k) { - $i++; - oss_file_upload($k['x'], $k['j']); + $sync = oss_read_dir_queue(get_home_path() . get_option('upload_path')); + foreach ($sync as $k) { + oss_file_upload($k['key'], $k['filepath']); } - echo '
本次操作成功同步' . $i . '个文件
本次操作成功同步' . count($sync) . '个文件
替换成功!共批量执行'.$result.'条!
替换成功!共替换文章内链'.$posts_result.'条、题图链接'.$postmeta_result.'条!
如果觉得此插件对你有所帮助,不妨到 Github 上点个Star
,Watch
关注更新;
如果觉得此插件对你有所帮助,不妨到 GitHub 上点个Star
,Watch
关注更新;欢迎加入云存储插件交流群,QQ群号:887595381;