-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
217 lines (185 loc) · 5.42 KB
/
Plugin.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* @file
* Plugin to store files in Blob.
*/
declare(strict_types=1);
namespace Kanboard\Plugin\BlobStorage;
require __DIR__ . '/vendor/autoload.php';
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Plugin\BlobStorage\BlobObjectStorage;
use Kanboard\Plugin\BlobStorage\Model\BlobTaskFileModel;
use Kanboard\Plugin\BlobStorage\Model\BlobProjectFileModel;
class Plugin extends Base
{
public function initialize(): void
{
$this->container['objectStorage'] = function () {
return new BlobObjectStorage(
$this->getConfigBlobKey(),
$this->getConfigBlobBucketId(),
$this->getConfigBlobApiHost(),
$this->getConfigOauthIDPUrl(),
$this->getConfigClientID(),
$this->getConfigClientSecret()
);
};
//HELPER
$this->helper->register('blobHelper', '\Kanboard\Plugin\BlobStorage\Helper\BlobHelper');
// Register file models.
$this->container['taskFileModel'] = $this->container->factory(
function ($c) {
return new BlobTaskFileModel($c);
}
);
$this->container['projectFileModel'] = $this->container->factory(
function ($c) {
return new BlobProjectFileModel($c);
}
);
// Config form.
$this->template->hook->attach('template:config:integrations', 'BlobStorage:config');
// Add custom CSS.
$this->hook->on('template:layout:css', array('template' => 'plugins/BlobStorage/Assets/css/blob-storage.css'));
// Override file upload and delete forms.
$this->template->setTemplateOverride('project_file/create', 'BlobStorage:project_file/create');
$this->template->setTemplateOverride('project_file/remove', 'BlobStorage:project_file/remove');
$this->template->setTemplateOverride('task_file/create', 'BlobStorage:task_file/create');
$this->template->setTemplateOverride('task_file/remove', 'BlobStorage:task_file/remove');
}
public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__ . '/Locale');
}
/**
* Returns all classes that needs to be stored in the DI container
*
* @access public
* @return array<mixed>
*/
public function getClasses()
{
return array(
'Plugin\BlobStorage\Model' => array(
'BlobProjectFileModel',
'BlobTaskFileModel',
)
);
}
public function isConfigured(): bool
{
if (
!$this->getConfigBlobKey() || !$this->getConfigBlobBucketId() || !$this->getConfigBlobApiHost() ||
!$this->getConfigOauthIDPUrl() || !$this->getConfigClientID() || !$this->getConfigClientSecret()
) {
$this->logger->info('Plugin Blob Storage not configured!');
return false;
}
return true;
}
public function getPluginName()
{
return 'Blob Object Storage';
}
public function getPluginDescription()
{
return 'Use Blob as a storage backend of plan.';
}
public function getPluginAuthor()
{
return 'David Zsuffa';
}
public function getPluginVersion()
{
return '0.1';
}
public function getPluginHomepage()
{
return 'https://github.com/digital-blueprint/plan-blob-storage-plugin';
}
/**
* Get config blob key
*
* @access private
*
* @return string
*/
private function getConfigBlobKey()
{
if (defined('BLOB_KEY') && BLOB_KEY) {
return BLOB_KEY;
}
return $this->configModel->get('blob_key');
}
/**
* Get config blob bucket id
*
* @access private
*
* @return string
*/
private function getConfigBlobBucketId()
{
if (defined('BLOB_BUCKET_ID') && BLOB_BUCKET_ID) {
return BLOB_BUCKET_ID;
}
return $this->configModel->get('blob_bucket_id');
}
/**
* Get config blob api hostname
*
* @access private
*
* @return string
*/
private function getConfigBlobApiHost()
{
if (defined('BLOB_API_HOST') && BLOB_API_HOST) {
return rtrim(BLOB_API_HOST, '/');
}
return rtrim($this->configModel->get('blob_api_host'), '/');
}
/**
* Get config blob api hostname
*
* @access private
*
* @return string
*/
private function getConfigOauthIDPUrl()
{
if (defined('BLOB_OAUTH_IDP_URL') && BLOB_OAUTH_IDP_URL) {
return rtrim(BLOB_OAUTH_IDP_URL, '/');
}
return rtrim($this->configModel->get('blob_oauth_idp_url'), '/');
}
/**
* Get config blob api hostname
*
* @access private
*
* @return string
*/
private function getConfigClientID()
{
if (defined('BLOB_CLIENT_ID') && BLOB_CLIENT_ID) {
return BLOB_CLIENT_ID;
}
return $this->configModel->get('blob_client_id');
}
/**
* Get config blob api hostname
*
* @access private
*
* @return string
*/
private function getConfigClientSecret()
{
if (defined('BLOB_CLIENT_SECRET') && BLOB_CLIENT_SECRET) {
return BLOB_CLIENT_SECRET;
}
return $this->configModel->get('blob_client_secret');
}
}