QiniuPlugin.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\qiniu;
use cmf\lib\Plugin;
use Qiniu\Auth;
class QiniuPlugin extends Plugin
{
public $info = [
'name' => 'Qiniu',
'title' => '七牛云存储',
'description' => '七牛云存储',
'status' => 1,
'author' => 'ThinkCMF',
'version' => '1.0'
];
public $hasAdmin = 0;//插件是否有后台管理界面
// 插件安装
public function install()
{
$storageOption = cmf_get_option('storage');
if (empty($storageOption)) {
$storageOption = [];
}
$storageOption['storages']['Qiniu'] = ['name' => '七牛云存储', 'driver' => '\\plugins\\qiniu\\lib\\Qiniu'];
cmf_set_option('storage', $storageOption);
return true;//安装成功返回true,失败false
}
// 插件卸载
public function uninstall()
{
$storageOption = cmf_get_option('storage');
if (empty($storageOption)) {
$storageOption = [];
}
unset($storageOption['storages']['Qiniu']);
cmf_set_option('storage', $storageOption);
return true;//卸载成功返回true,失败false
}
public function fetchUploadView(&$param)
{
$config = $this->getConfig();
$accessKey = $config['accessKey'];
$secretKey = $config['secretKey'];
$zone = $config['zone'];
$uploadHost = 'upload.qiniup.com';
if (!empty($zone) && $zone != 'z0') {
$uploadHost = "upload-{$zone}.qiniup.com";
}
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($config['bucket']);
$this->assign('upload_host', $uploadHost);
$this->assign('qiniu_up_token', $token);
return $this->fetch('upload');
}
public function cloudStorageTab(&$param)
{
}
}