|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Circles - Bring cloud-users closer together. |
|
7
|
|
|
* |
|
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
9
|
|
|
* later. See the COPYING file. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Maxence Lange <[email protected]> |
|
12
|
|
|
* @author Vinicius Cubas Brand <[email protected]> |
|
13
|
|
|
* @author Daniel Tygel <[email protected]> |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright 2017 |
|
16
|
|
|
* @license GNU AGPL version 3 or any later version |
|
17
|
|
|
* |
|
18
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
19
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
20
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
21
|
|
|
* License, or (at your option) any later version. |
|
22
|
|
|
* |
|
23
|
|
|
* This program is distributed in the hope that it will be useful, |
|
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26
|
|
|
* GNU Affero General Public License for more details. |
|
27
|
|
|
* |
|
28
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
29
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
30
|
|
|
* |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
namespace OCA\Circles\AppInfo; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
use Closure; |
|
38
|
|
|
use OC; |
|
39
|
|
|
use OCA\Circles\Api\v1\Circles; |
|
40
|
|
|
use OCA\Circles\Exceptions\GSStatusException; |
|
41
|
|
|
use OCA\Circles\GlobalScale\GSMount\MountProvider; |
|
42
|
|
|
use OCA\Circles\Notification\Notifier; |
|
43
|
|
|
use OCA\Circles\Service\ConfigService; |
|
44
|
|
|
use OCA\Circles\Service\DavService; |
|
45
|
|
|
use OCA\Files\App as FilesApp; |
|
46
|
|
|
use OCP\App\ManagerEvent; |
|
47
|
|
|
use OCP\AppFramework\App; |
|
48
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
49
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
50
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
51
|
|
|
use OCP\AppFramework\IAppContainer; |
|
52
|
|
|
use OCP\AppFramework\QueryException; |
|
53
|
|
|
use OCP\IServerContainer; |
|
54
|
|
|
use OCP\Util; |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Class Application |
|
59
|
|
|
* |
|
60
|
|
|
* @package OCA\Circles\AppInfo |
|
61
|
|
|
*/ |
|
62
|
|
|
class Application extends App implements IBootstrap { |
|
63
|
|
|
|
|
64
|
|
|
const APP_NAME = 'circles'; |
|
65
|
|
|
|
|
66
|
|
|
const TEST_URL_ASYNC = '/index.php/apps/circles/admin/testAsync'; |
|
67
|
|
|
|
|
68
|
|
|
const CLIENT_TIMEOUT = 3; |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** @var ConfigService */ |
|
72
|
|
|
private $configService; |
|
73
|
|
|
|
|
74
|
|
|
/** @var IAppContainer */ |
|
75
|
|
|
private $container; |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param array $params |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __construct(array $params = array()) { |
|
82
|
|
|
parent::__construct(self::APP_NAME, $params); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param IRegistrationContext $context |
|
88
|
|
|
*/ |
|
89
|
|
|
public function register(IRegistrationContext $context): void { |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param IBootContext $context |
|
95
|
|
|
* |
|
96
|
|
|
* @throws \Throwable |
|
97
|
|
|
*/ |
|
98
|
|
|
public function boot(IBootContext $context): void { |
|
99
|
|
|
$manager = $context->getServerContainer() |
|
100
|
|
|
->getNotificationManager(); |
|
101
|
|
|
$manager->registerNotifierService(Notifier::class); |
|
102
|
|
|
|
|
103
|
|
|
$this->configService = $context->getAppContainer() |
|
104
|
|
|
->get(ConfigService::class); |
|
105
|
|
|
|
|
106
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerMountProvider'])); |
|
107
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerHooks'])); |
|
108
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerDavHooks'])); |
|
109
|
|
|
|
|
110
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation'])); |
|
111
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerFilesNavigation'])); |
|
112
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerFilesPlugin'])); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param IServerContainer $container |
|
118
|
|
|
* |
|
119
|
|
|
* @throws GSStatusException |
|
120
|
|
|
* @throws QueryException |
|
121
|
|
|
*/ |
|
122
|
|
|
public function registerMountProvider(IServerContainer $container) { |
|
123
|
|
|
if (!$this->configService->getGSStatus(ConfigService::GS_ENABLED)) { |
|
124
|
|
|
return; |
|
125
|
|
|
} |
|
126
|
|
|
$mountProviderCollection = $container->getMountProviderCollection(); |
|
127
|
|
|
$mountProviderCollection->registerProvider($this->container->query(MountProvider::class)); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Register Hooks |
|
133
|
|
|
*/ |
|
134
|
|
|
public function registerHooks() { |
|
135
|
|
|
Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Circles\Hooks\UserHooks', 'onUserDeleted'); |
|
136
|
|
|
Util::connectHook('OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
public function registerDavHooks(IServerContainer $container) { |
|
141
|
|
|
// /** @var ConfigService $configService */ |
|
142
|
|
|
// |
|
143
|
|
|
// $configService = OC::$server->query(ConfigService::class); |
|
144
|
|
|
if (!$this->configService->isContactsBackend()) { |
|
145
|
|
|
return; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** @var DavService $davService */ |
|
149
|
|
|
$davService = $container->get(DavService::class); |
|
150
|
|
|
|
|
151
|
|
|
$event = OC::$server->getEventDispatcher(); |
|
152
|
|
|
$event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); |
|
153
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); |
|
154
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); |
|
155
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Register Navigation elements |
|
161
|
|
|
* |
|
162
|
|
|
* @param IServerContainer $container |
|
163
|
|
|
*/ |
|
164
|
|
|
public function registerNavigation(IServerContainer $container) { |
|
165
|
|
|
if (!$this->configService->stillFrontEnd()) { |
|
166
|
|
|
return; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$appManager = $container->getNavigationManager(); |
|
170
|
|
|
$appManager->add( |
|
171
|
|
|
function() { |
|
172
|
|
|
$urlGen = OC::$server->getURLGenerator(); |
|
173
|
|
|
$navName = OC::$server->getL10N(self::APP_NAME) |
|
174
|
|
|
->t('Circles'); |
|
175
|
|
|
|
|
176
|
|
|
return [ |
|
177
|
|
|
'id' => self::APP_NAME, |
|
178
|
|
|
'order' => 5, |
|
179
|
|
|
'href' => $urlGen->linkToRoute('circles.Navigation.navigate'), |
|
180
|
|
|
'icon' => $urlGen->imagePath(self::APP_NAME, 'circles.svg'), |
|
181
|
|
|
'name' => $navName |
|
182
|
|
|
]; |
|
183
|
|
|
} |
|
184
|
|
|
); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function registerFilesPlugin(IServerContainer $container) { |
|
188
|
|
|
$eventDispatcher = $container->getEventDispatcher(); |
|
189
|
|
|
$eventDispatcher->addListener( |
|
190
|
|
|
'OCA\Files::loadAdditionalScripts', |
|
191
|
|
|
function() { |
|
192
|
|
|
Circles::addJavascriptAPI(); |
|
193
|
|
|
|
|
194
|
|
|
Util::addScript('circles', 'files/circles.files.app'); |
|
195
|
|
|
Util::addScript('circles', 'files/circles.files.list'); |
|
196
|
|
|
|
|
197
|
|
|
Util::addStyle('circles', 'files/circles.filelist'); |
|
198
|
|
|
} |
|
199
|
|
|
); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* |
|
205
|
|
|
*/ |
|
206
|
|
|
public function registerFilesNavigation() { |
|
207
|
|
|
$appManager = FilesApp::getNavigationManager(); |
|
208
|
|
|
$appManager->add( |
|
209
|
|
|
function() { |
|
210
|
|
|
$l = OC::$server->getL10N('circles'); |
|
211
|
|
|
|
|
212
|
|
|
return [ |
|
213
|
|
|
'id' => 'circlesfilter', |
|
214
|
|
|
'appname' => 'circles', |
|
215
|
|
|
'script' => 'files/list.php', |
|
216
|
|
|
'order' => 25, |
|
217
|
|
|
'name' => $l->t('Shared to Circles'), |
|
218
|
|
|
]; |
|
219
|
|
|
} |
|
220
|
|
|
); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
|