parent
04023f72eb
commit
2d7be1839d
|
@ -5,3 +5,6 @@
|
|||
/sdk/composer.lock
|
||||
/sdk/vendor/aliyuncs/oss-sdk-php/samples/
|
||||
/sdk/vendor/aliyuncs/oss-sdk-php/tests/
|
||||
/sdk/vendor/aliyuncs/oss-sdk-php/.coveralls.yml
|
||||
*.github
|
||||
*.php_cs*
|
|
@ -2,8 +2,8 @@
|
|||
/*
|
||||
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.4.21
|
||||
Description: 使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.)
|
||||
Version: 1.5.0
|
||||
Author: 沈唁
|
||||
Author URI: https://qq52o.me
|
||||
License: Apache2.0
|
||||
|
@ -18,8 +18,9 @@ use OSS\OssClient;
|
|||
use OSS\Credentials\CredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Credential;
|
||||
use OSS\Credentials\StaticCredentialsProvider;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
define('OSS_VERSION', '1.4.21');
|
||||
define('OSS_VERSION', '1.5.0');
|
||||
define('OSS_BASEFOLDER', plugin_basename(dirname(__FILE__)));
|
||||
|
||||
if (!function_exists('get_home_path')) {
|
||||
|
@ -58,6 +59,7 @@ function oss_get_default_options()
|
|||
return [
|
||||
'bucket' => '',
|
||||
'regional' => 'oss-cn-shanghai',
|
||||
'origin_region' => '',
|
||||
'accessKeyId' => '',
|
||||
'accessKeySecret' => '',
|
||||
'is_internal' => 'false',
|
||||
|
@ -95,11 +97,31 @@ function oss_get_client()
|
|||
} else {
|
||||
$provider = new StaticCredentialsProvider(esc_attr($oss_options['accessKeyId']), esc_attr($oss_options['accessKeySecret']));
|
||||
}
|
||||
|
||||
$region = !empty($oss_options['origin_region']) ? esc_attr($oss_options['origin_region']) : esc_attr($oss_options['regional']);
|
||||
if (in_array($region, ['oss-accelerate', 'oss-accelerate-overseas']) && empty($oss_options['origin_region'])) {
|
||||
try {
|
||||
$config = [
|
||||
'provider' => $provider,
|
||||
'endpoint' => $region == 'oss-accelerate' ? 'https://oss-cn-hangzhou.aliyuncs.com' : 'https://oss-cn-hongkong.aliyuncs.com',
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4,
|
||||
'region' => $region == 'oss-accelerate' ? 'cn-hangzhou' : 'cn-hongkong',
|
||||
];
|
||||
$region = (new OssClient($config))->getBucketInfo(esc_attr($oss_options['bucket']))->getLocation();
|
||||
$oss_options['origin_region'] = sanitize_text_field($region);
|
||||
update_option('oss_options', $oss_options);
|
||||
} catch (OssException $e) {
|
||||
error_log("get bucket location failed: {$e->getMessage()}");
|
||||
}
|
||||
}
|
||||
|
||||
$region = str_replace('oss-', '', $region);
|
||||
|
||||
$config = [
|
||||
'provider' => $provider,
|
||||
'endpoint' => $endpoint,
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4,
|
||||
'region' => str_replace('oss-', '', esc_attr($oss_options['regional'])),
|
||||
'region' => $region,
|
||||
];
|
||||
return new OssClient($config);
|
||||
}
|
||||
|
@ -118,7 +140,7 @@ function oss_get_bucket_endpoint($oss_options)
|
|||
function oss_get_bucket_name()
|
||||
{
|
||||
$oss_options = get_option('oss_options', oss_get_default_options());
|
||||
return $oss_options['bucket'];
|
||||
return esc_attr($oss_options['bucket']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -766,12 +788,13 @@ function oss_setting_page()
|
|||
$options['is_internal'] = isset($_POST['is_internal']) ? 'true' : 'false';
|
||||
$options['nothumb'] = isset($_POST['nothumb']) ? 'true' : 'false';
|
||||
$options['nolocalsaving'] = isset($_POST['nolocalsaving']) ? 'true' : 'false';
|
||||
//仅用于插件卸载时比较使用
|
||||
$options['upload_url_path'] = isset($_POST['upload_url_path']) ? sanitize_text_field(stripslashes($_POST['upload_url_path'])) : '';
|
||||
$options['style'] = isset($_POST['style']) ? sanitize_text_field($_POST['style']) : '';
|
||||
$options['update_file_name'] = isset($_POST['update_file_name']) ? sanitize_text_field($_POST['update_file_name']) : 'false';
|
||||
$options['origin_protect'] = isset($_POST['origin_protect']) ? sanitize_text_field($_POST['origin_protect']) : 'off';
|
||||
|
||||
$options['origin_region'] = in_array($options['regional'], ['oss-accelerate', 'oss-accelerate-overseas']) ? '' : $options['regional'];
|
||||
|
||||
if ($options['regional'] === 'oss-rg-china-mainland' && $options['is_internal'] === 'true') {
|
||||
echo '<div class="error"><p><strong>无地域属性不支持内网,请重新填写配置!</strong></p></div>';
|
||||
$options = [];
|
||||
|
@ -829,14 +852,10 @@ function oss_setting_page()
|
|||
|
||||
$oss_regional = esc_attr($oss_options['regional']);
|
||||
|
||||
$oss_is_internal = esc_attr($oss_options['is_internal']);
|
||||
$oss_is_internal = $oss_is_internal == 'true';
|
||||
$oss_is_internal = esc_attr($oss_options['is_internal']) == 'true';
|
||||
$oss_nothumb = esc_attr($oss_options['nothumb']) == 'true';
|
||||
$oss_nolocalsaving = esc_attr($oss_options['nolocalsaving']) == 'true';
|
||||
|
||||
$oss_nothumb = esc_attr($oss_options['nothumb']);
|
||||
$oss_nothumb = $oss_nothumb == 'true';
|
||||
|
||||
$oss_nolocalsaving = esc_attr($oss_options['nolocalsaving']);
|
||||
$oss_nolocalsaving = $oss_nolocalsaving == 'true';
|
||||
$oss_update_file_name = esc_attr($oss_options['update_file_name']);
|
||||
$oss_origin_protect = esc_attr($oss_options['origin_protect'] ?? 'off') !== 'off' ? 'checked="checked"' : '';
|
||||
|
||||
|
|
10
readme.txt
10
readme.txt
|
@ -5,15 +5,15 @@ Tags: oss, 阿里云, 对象存储, aliyun
|
|||
Requires at least: 4.6
|
||||
Tested up to: 6.7
|
||||
Requires PHP: 7.1
|
||||
Stable tag: 1.4.21
|
||||
Stable tag: 1.5.0
|
||||
License: Apache2.0
|
||||
License URI: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.)
|
||||
使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.)
|
||||
|
||||
== Description ==
|
||||
|
||||
使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.)
|
||||
使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.)
|
||||
|
||||
- 依赖阿里云 OSS 服务:https://www.aliyun.com/product/oss
|
||||
|
||||
|
@ -78,6 +78,10 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.html
|
|||
|
||||
== Changelog ==
|
||||
|
||||
= 1.5.0 =
|
||||
|
||||
- Enhance region handling for OSS configuration
|
||||
|
||||
= 1.4.21 =
|
||||
|
||||
- Optimize uninstall code
|
||||
|
|
Loading…
Reference in New Issue