Skip to content

Commit

Permalink
Add cos_local2remote method (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Nov 18, 2023
1 parent 819ae1f commit f7a6398
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: COS, 腾讯云, 对象存储, Tencent, Qcloud
Requires at least: 4.2
Tested up to: 6.4
Requires PHP: 7.0
Stable tag: 2.3.4
Stable tag: 2.3.5
License: Apache2.0
License URI: http://www.apache.org/licenses/LICENSE-2.0.html

Expand Down Expand Up @@ -99,7 +99,7 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.html

= Stable =

- 优化删除配置信息选项
- Added `cos_append_ci_style` and `cos_local2remote` methods.

= Other =

Expand Down
28 changes: 22 additions & 6 deletions sync-qcloud-cos.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Sync QCloud COS
Plugin URI: https://qq52o.me/2518.html
Description: 使用腾讯云对象存储服务 COS 作为附件存储空间。(This is a plugin that uses Tencent Cloud Cloud Object Storage for attachments remote saving.)
Version: 2.3.4
Version: 2.3.5
Author: 沈唁
Author URI: https://qq52o.me
License: Apache2.0
Expand All @@ -25,7 +25,7 @@
use SyncQcloudCos\Monitor\Charts;
use SyncQcloudCos\Monitor\DataPoints;

define('COS_VERSION', '2.3.4');
define('COS_VERSION', '2.3.5');
define('COS_PLUGIN_SLUG', 'sync-qcloud-cos');
define('COS_PLUGIN_PAGE', plugin_basename(dirname(__FILE__)) . '%2F' . basename(__FILE__));

Expand Down Expand Up @@ -612,10 +612,26 @@ function cos_append_ci_style($url, $options = null)
{
if (empty($options)) $options = get_option('cos_options');

if (!empty($options['ci_style']) && !empty($options['upload_url_path'])) {
if (strpos($url, esc_attr($options['upload_url_path'])) !== false) {
$url .= esc_attr($options['ci_style']);
}
if (!empty($options['ci_style']) && !empty($options['upload_url_path']) && strpos($url, esc_attr($options['upload_url_path'])) !== false) {
$url .= esc_attr($options['ci_style']);
}

return $url;
}

/**
* @param string $url
* @param array|null $options
* @return string
*/
function cos_local2remote($url, $options = null)
{
if (empty($options)) $options = get_option('cos_options');

$upload_path = get_option('upload_path');

if ($upload_path != '.' && !empty($options['upload_url_path']) && strpos($url, $upload_path) !== false) {
return $options['upload_url_path'] . explode($upload_path, $url)[1];
}

return $url;
Expand Down

0 comments on commit f7a6398

Please sign in to comment.