|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Circles - Bring cloud-users closer together. |
|
8
|
|
|
* |
|
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
10
|
|
|
* later. See the COPYING file. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Maxence Lange <[email protected]> |
|
13
|
|
|
* @author Vinicius Cubas Brand <[email protected]> |
|
14
|
|
|
* @author Daniel Tygel <[email protected]> |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright 2017 |
|
17
|
|
|
* @license GNU AGPL version 3 or any later version |
|
18
|
|
|
* |
|
19
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
20
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
21
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
22
|
|
|
* License, or (at your option) any later version. |
|
23
|
|
|
* |
|
24
|
|
|
* This program is distributed in the hope that it will be useful, |
|
25
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
27
|
|
|
* GNU Affero General Public License for more details. |
|
28
|
|
|
* |
|
29
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
30
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
namespace OCA\Circles\AppInfo; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
use Closure; |
|
39
|
|
|
use OC; |
|
40
|
|
|
use OCA\Circles\Events\AddingCircleMemberEvent; |
|
41
|
|
|
use OCA\Circles\Events\CircleMemberAddedEvent; |
|
42
|
|
|
use OCA\Circles\Events\MembershipsCreatedEvent; |
|
43
|
|
|
use OCA\Circles\Events\MembershipsRemovedEvent; |
|
44
|
|
|
use OCA\Circles\Handlers\WebfingerHandler; |
|
45
|
|
|
use OCA\Circles\Listeners\Examples\ExampleCircleMemberAdded; |
|
46
|
|
|
use OCA\Circles\Listeners\Examples\ExampleMembershipsCreated; |
|
47
|
|
|
use OCA\Circles\Listeners\Examples\ExampleMembershipsRemoved; |
|
48
|
|
|
use OCA\Circles\Listeners\Files\AddingMember as ListenerFilesAddingMember; |
|
49
|
|
|
use OCA\Circles\Listeners\Files\MemberAdded as ListenerFilesMemberAdded; |
|
50
|
|
|
use OCA\Circles\Listeners\Files\MembershipsRemoved as ListenerFilesMembershipsRemoved; |
|
51
|
|
|
use OCA\Circles\Listeners\GroupCreated; |
|
52
|
|
|
use OCA\Circles\Listeners\GroupDeleted; |
|
53
|
|
|
use OCA\Circles\Listeners\GroupMemberAdded; |
|
54
|
|
|
use OCA\Circles\Listeners\GroupMemberRemoved; |
|
55
|
|
|
use OCA\Circles\Listeners\UserCreated; |
|
56
|
|
|
use OCA\Circles\Listeners\UserDeleted; |
|
57
|
|
|
use OCA\Circles\MountManager\CircleMountProvider; |
|
58
|
|
|
use OCA\Circles\Notification\Notifier; |
|
59
|
|
|
use OCA\Circles\Service\ConfigService; |
|
60
|
|
|
use OCA\Circles\Service\DavService; |
|
61
|
|
|
use OCA\Files\App as FilesApp; |
|
62
|
|
|
use OCP\App\ManagerEvent; |
|
63
|
|
|
use OCP\AppFramework\App; |
|
64
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
65
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
66
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
67
|
|
|
use OCP\AppFramework\IAppContainer; |
|
68
|
|
|
use OCP\Files\Config\IMountProviderCollection; |
|
69
|
|
|
use OCP\Group\Events\GroupCreatedEvent; |
|
70
|
|
|
use OCP\Group\Events\GroupDeletedEvent; |
|
71
|
|
|
use OCP\Group\Events\UserAddedEvent; |
|
72
|
|
|
use OCP\Group\Events\UserRemovedEvent; |
|
73
|
|
|
use OCP\IServerContainer; |
|
74
|
|
|
use OCP\User\Events\UserCreatedEvent; |
|
75
|
|
|
use OCP\User\Events\UserDeletedEvent; |
|
76
|
|
|
use Throwable; |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php'; |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Class Application |
|
84
|
|
|
* |
|
85
|
|
|
* @package OCA\Circles\AppInfo |
|
86
|
|
|
*/ |
|
87
|
|
|
class Application extends App implements IBootstrap { |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
const APP_ID = 'circles'; |
|
91
|
|
|
const APP_NAME = 'Circles'; |
|
92
|
|
|
const APP_TOKEN = 'dvG7laa0_UU'; |
|
93
|
|
|
|
|
94
|
|
|
const APP_SUBJECT = 'http://nextcloud.com/'; |
|
95
|
|
|
const APP_REL = 'https://apps.nextcloud.com/apps/circles'; |
|
96
|
|
|
const APP_API = 1; |
|
97
|
|
|
|
|
98
|
|
|
const CLIENT_TIMEOUT = 3; |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
/** @var ConfigService */ |
|
102
|
|
|
private $configService; |
|
103
|
|
|
|
|
104
|
|
|
/** @var IAppContainer */ |
|
105
|
|
|
private $container; |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Application constructor. |
|
110
|
|
|
* |
|
111
|
|
|
* @param array $params |
|
112
|
|
|
*/ |
|
113
|
|
|
public function __construct(array $params = array()) { |
|
114
|
|
|
parent::__construct(self::APP_ID, $params); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param IRegistrationContext $context |
|
120
|
|
|
*/ |
|
121
|
|
|
public function register(IRegistrationContext $context): void { |
|
122
|
|
|
$context->registerCapability(Capabilities::class); |
|
123
|
|
|
|
|
124
|
|
|
// User Events |
|
125
|
|
|
$context->registerEventListener(UserCreatedEvent::class, UserCreated::class); |
|
126
|
|
|
$context->registerEventListener(UserDeletedEvent::class, UserDeleted::class); |
|
127
|
|
|
|
|
128
|
|
|
// Group Events |
|
129
|
|
|
$context->registerEventListener(GroupCreatedEvent::class, GroupCreated::class); |
|
130
|
|
|
$context->registerEventListener(GroupDeletedEvent::class, GroupDeleted::class); |
|
131
|
|
|
$context->registerEventListener(UserAddedEvent::class, GroupMemberAdded::class); |
|
132
|
|
|
$context->registerEventListener(UserRemovedEvent::class, GroupMemberRemoved::class); |
|
133
|
|
|
|
|
134
|
|
|
// Local Events (for Files/Shares management) |
|
135
|
|
|
$context->registerEventListener(AddingCircleMemberEvent::class, ListenerFilesAddingMember::class); |
|
136
|
|
|
$context->registerEventListener(CircleMemberAddedEvent::class, ListenerFilesMemberAdded::class); |
|
137
|
|
|
$context->registerEventListener( |
|
138
|
|
|
MembershipsRemovedEvent::class, ListenerFilesMembershipsRemoved::class |
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
|
|
$context->registerWellKnownHandler(WebfingerHandler::class); |
|
142
|
|
|
|
|
143
|
|
|
$this->loadExampleEvents($context); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param IBootContext $context |
|
149
|
|
|
* |
|
150
|
|
|
* @throws Throwable |
|
151
|
|
|
*/ |
|
152
|
|
|
public function boot(IBootContext $context): void { |
|
153
|
|
|
$serverContainer = $context->getServerContainer(); |
|
154
|
|
|
|
|
155
|
|
|
// /** @var IManager $shareManager */ |
|
156
|
|
|
// $shareManager = $serverContainer->get(IManager::class); |
|
157
|
|
|
// $shareManager->registerShareProvider(ShareByCircleProvider::class); |
|
158
|
|
|
|
|
159
|
|
|
$manager = $serverContainer->getNotificationManager(); |
|
160
|
|
|
$manager->registerNotifierService(Notifier::class); |
|
161
|
|
|
|
|
162
|
|
|
$this->configService = $context->getAppContainer() |
|
163
|
|
|
->get(ConfigService::class); |
|
164
|
|
|
|
|
165
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerMountProvider'])); |
|
166
|
|
|
// $context->injectFn(Closure::fromCallable([$this, 'registerDavHooks'])); |
|
167
|
|
|
|
|
168
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerFilesNavigation'])); |
|
169
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerFilesPlugin'])); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param IServerContainer $container |
|
175
|
|
|
*/ |
|
176
|
|
|
public function registerMountProvider(IServerContainer $container) { |
|
177
|
|
|
if (!$this->configService->isGSAvailable()) { |
|
178
|
|
|
return; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
$mountProviderCollection = $container->get(IMountProviderCollection::class); |
|
182
|
|
|
$mountProviderCollection->registerProvider($container->get(CircleMountProvider::class)); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param IServerContainer $container |
|
188
|
|
|
*/ |
|
189
|
|
|
public function registerDavHooks(IServerContainer $container) { |
|
190
|
|
|
if (!$this->configService->isContactsBackend()) { |
|
|
|
|
|
|
191
|
|
|
return; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** @var DavService $davService */ |
|
195
|
|
|
$davService = $container->get(DavService::class); |
|
196
|
|
|
|
|
197
|
|
|
$event = OC::$server->getEventDispatcher(); |
|
198
|
|
|
$event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); |
|
199
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); |
|
200
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); |
|
201
|
|
|
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param IRegistrationContext $context |
|
207
|
|
|
*/ |
|
208
|
|
|
private function loadExampleEvents(IRegistrationContext $context): void { |
|
209
|
|
|
$context->registerEventListener(CircleMemberAddedEvent::class, ExampleCircleMemberAdded::class); |
|
210
|
|
|
$context->registerEventListener(MembershipsCreatedEvent::class, ExampleMembershipsCreated::class); |
|
211
|
|
|
$context->registerEventListener(MembershipsRemovedEvent::class, ExampleMembershipsRemoved::class); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param IServerContainer $container |
|
217
|
|
|
*/ |
|
218
|
|
|
public function registerFilesPlugin(IServerContainer $container) { |
|
219
|
|
|
// $eventDispatcher = $container->getEventDispatcher(); |
|
220
|
|
|
// $eventDispatcher->addListener( |
|
221
|
|
|
// 'OCA\Files::loadAdditionalScripts', |
|
222
|
|
|
// function() { |
|
223
|
|
|
// Circles::addJavascriptAPI(); |
|
224
|
|
|
// |
|
225
|
|
|
// Util::addScript('circles', 'files/circles.files.app'); |
|
226
|
|
|
// Util::addScript('circles', 'files/circles.files.list'); |
|
227
|
|
|
// |
|
228
|
|
|
// Util::addStyle('circles', 'files/circles.filelist'); |
|
229
|
|
|
// } |
|
230
|
|
|
// ); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* |
|
236
|
|
|
*/ |
|
237
|
|
|
public function registerFilesNavigation() { |
|
238
|
|
|
$appManager = FilesApp::getNavigationManager(); |
|
239
|
|
|
$appManager->add( |
|
240
|
|
|
function() { |
|
241
|
|
|
$l = OC::$server->getL10N('circles'); |
|
242
|
|
|
|
|
243
|
|
|
return [ |
|
244
|
|
|
'id' => 'circlesfilter', |
|
245
|
|
|
'appname' => 'circles', |
|
246
|
|
|
'script' => 'files/list.php', |
|
247
|
|
|
'order' => 25, |
|
248
|
|
|
'name' => $l->t('Shared to Circles'), |
|
249
|
|
|
]; |
|
250
|
|
|
} |
|
251
|
|
|
); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
|
This method has been deprecated.