|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Björn Schießle <[email protected]> |
|
6
|
|
|
* @author Joas Schilling <[email protected]> |
|
7
|
|
|
* @author Thomas Müller <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace OC\Activity; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
use OCP\Activity\IConsumer; |
|
28
|
|
|
use OCP\Activity\IEvent; |
|
29
|
|
|
use OCP\Activity\IExtension; |
|
30
|
|
|
use OCP\Activity\IFilter; |
|
31
|
|
|
use OCP\Activity\IManager; |
|
32
|
|
|
use OCP\Activity\IProvider; |
|
33
|
|
|
use OCP\Activity\ISetting; |
|
34
|
|
|
use OCP\IConfig; |
|
35
|
|
|
use OCP\IRequest; |
|
36
|
|
|
use OCP\IUser; |
|
37
|
|
|
use OCP\IUserSession; |
|
38
|
|
|
use OCP\RichObjectStrings\IValidator; |
|
39
|
|
|
|
|
40
|
|
|
class Manager implements IManager { |
|
41
|
|
|
/** @var IRequest */ |
|
42
|
|
|
protected $request; |
|
43
|
|
|
|
|
44
|
|
|
/** @var IUserSession */ |
|
45
|
|
|
protected $session; |
|
46
|
|
|
|
|
47
|
|
|
/** @var IConfig */ |
|
48
|
|
|
protected $config; |
|
49
|
|
|
|
|
50
|
|
|
/** @var IValidator */ |
|
51
|
|
|
protected $validator; |
|
52
|
|
|
|
|
53
|
|
|
/** @var string */ |
|
54
|
|
|
protected $formattingObjectType; |
|
55
|
|
|
|
|
56
|
|
|
/** @var int */ |
|
57
|
|
|
protected $formattingObjectId; |
|
58
|
|
|
|
|
59
|
|
|
/** @var string */ |
|
60
|
|
|
protected $currentUserId; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* constructor of the controller |
|
64
|
|
|
* |
|
65
|
|
|
* @param IRequest $request |
|
66
|
|
|
* @param IUserSession $session |
|
67
|
|
|
* @param IConfig $config |
|
68
|
|
|
* @param IValidator $validator |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct(IRequest $request, |
|
71
|
|
|
IUserSession $session, |
|
72
|
|
|
IConfig $config, |
|
73
|
|
|
IValidator $validator) { |
|
74
|
|
|
$this->request = $request; |
|
75
|
|
|
$this->session = $session; |
|
76
|
|
|
$this->config = $config; |
|
77
|
|
|
$this->validator = $validator; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** @var \Closure[] */ |
|
81
|
|
|
private $consumersClosures = array(); |
|
82
|
|
|
|
|
83
|
|
|
/** @var IConsumer[] */ |
|
84
|
|
|
private $consumers = array(); |
|
85
|
|
|
|
|
86
|
|
|
/** @var \Closure[] */ |
|
87
|
|
|
private $extensionsClosures = array(); |
|
88
|
|
|
|
|
89
|
|
|
/** @var IExtension[] */ |
|
90
|
|
|
private $extensions = array(); |
|
91
|
|
|
|
|
92
|
|
|
/** @var array list of filters "name" => "is valid" */ |
|
93
|
|
|
protected $validFilters = array( |
|
94
|
|
|
'all' => true, |
|
95
|
|
|
'by' => true, |
|
96
|
|
|
'self' => true, |
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
/** @var array list of type icons "type" => "css class" */ |
|
100
|
|
|
protected $typeIcons = array(); |
|
101
|
|
|
|
|
102
|
|
|
/** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
103
|
|
|
protected $specialParameters = array(); |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return \OCP\Activity\IConsumer[] |
|
107
|
|
|
*/ |
|
108
|
|
View Code Duplication |
protected function getConsumers() { |
|
|
|
|
|
|
109
|
|
|
if (!empty($this->consumers)) { |
|
110
|
|
|
return $this->consumers; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$this->consumers = []; |
|
114
|
|
|
foreach($this->consumersClosures as $consumer) { |
|
115
|
|
|
$c = $consumer(); |
|
116
|
|
|
if ($c instanceof IConsumer) { |
|
117
|
|
|
$this->consumers[] = $c; |
|
118
|
|
|
} else { |
|
119
|
|
|
throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $this->consumers; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return \OCP\Activity\IExtension[] |
|
128
|
|
|
*/ |
|
129
|
|
View Code Duplication |
protected function getExtensions() { |
|
|
|
|
|
|
130
|
|
|
if (!empty($this->extensions)) { |
|
131
|
|
|
return $this->extensions; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$this->extensions = []; |
|
135
|
|
|
foreach($this->extensionsClosures as $extension) { |
|
136
|
|
|
$e = $extension(); |
|
137
|
|
|
if ($e instanceof IExtension) { |
|
138
|
|
|
$this->extensions[] = $e; |
|
139
|
|
|
} else { |
|
140
|
|
|
throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $this->extensions; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Generates a new IEvent object |
|
149
|
|
|
* |
|
150
|
|
|
* Make sure to call at least the following methods before sending it to the |
|
151
|
|
|
* app with via the publish() method: |
|
152
|
|
|
* - setApp() |
|
153
|
|
|
* - setType() |
|
154
|
|
|
* - setAffectedUser() |
|
155
|
|
|
* - setSubject() |
|
156
|
|
|
* |
|
157
|
|
|
* @return IEvent |
|
158
|
|
|
*/ |
|
159
|
|
|
public function generateEvent() { |
|
160
|
|
|
return new Event($this->validator); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Publish an event to the activity consumers |
|
165
|
|
|
* |
|
166
|
|
|
* Make sure to call at least the following methods before sending an Event: |
|
167
|
|
|
* - setApp() |
|
168
|
|
|
* - setType() |
|
169
|
|
|
* - setAffectedUser() |
|
170
|
|
|
* - setSubject() |
|
171
|
|
|
* |
|
172
|
|
|
* @param IEvent $event |
|
173
|
|
|
* @throws \BadMethodCallException if required values have not been set |
|
174
|
|
|
*/ |
|
175
|
|
|
public function publish(IEvent $event) { |
|
176
|
|
|
if ($event->getAuthor() === '') { |
|
177
|
|
|
if ($this->session->getUser() instanceof IUser) { |
|
178
|
|
|
$event->setAuthor($this->session->getUser()->getUID()); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
if (!$event->getTimestamp()) { |
|
183
|
|
|
$event->setTimestamp(time()); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (!$event->isValid()) { |
|
187
|
|
|
throw new \BadMethodCallException('The given event is invalid'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
foreach ($this->getConsumers() as $c) { |
|
191
|
|
|
$c->receive($event); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param string $app The app where this event is associated with |
|
197
|
|
|
* @param string $subject A short description of the event |
|
198
|
|
|
* @param array $subjectParams Array with parameters that are filled in the subject |
|
199
|
|
|
* @param string $message A longer description of the event |
|
200
|
|
|
* @param array $messageParams Array with parameters that are filled in the message |
|
201
|
|
|
* @param string $file The file including path where this event is associated with |
|
202
|
|
|
* @param string $link A link where this event is associated with |
|
203
|
|
|
* @param string $affectedUser Recipient of the activity |
|
204
|
|
|
* @param string $type Type of the notification |
|
205
|
|
|
* @param int $priority Priority of the notification |
|
206
|
|
|
*/ |
|
207
|
|
|
public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
208
|
|
|
$event = $this->generateEvent(); |
|
209
|
|
|
$event->setApp($app) |
|
210
|
|
|
->setType($type) |
|
211
|
|
|
->setAffectedUser($affectedUser) |
|
212
|
|
|
->setSubject($subject, $subjectParams) |
|
213
|
|
|
->setMessage($message, $messageParams) |
|
214
|
|
|
->setObject('', 0, $file) |
|
215
|
|
|
->setLink($link); |
|
216
|
|
|
|
|
217
|
|
|
$this->publish($event); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* In order to improve lazy loading a closure can be registered which will be called in case |
|
222
|
|
|
* activity consumers are actually requested |
|
223
|
|
|
* |
|
224
|
|
|
* $callable has to return an instance of OCA\Activity\IConsumer |
|
225
|
|
|
* |
|
226
|
|
|
* @param \Closure $callable |
|
227
|
|
|
*/ |
|
228
|
|
|
public function registerConsumer(\Closure $callable) { |
|
229
|
|
|
array_push($this->consumersClosures, $callable); |
|
230
|
|
|
$this->consumers = []; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* In order to improve lazy loading a closure can be registered which will be called in case |
|
235
|
|
|
* activity consumers are actually requested |
|
236
|
|
|
* |
|
237
|
|
|
* $callable has to return an instance of OCA\Activity\IExtension |
|
238
|
|
|
* |
|
239
|
|
|
* @param \Closure $callable |
|
240
|
|
|
*/ |
|
241
|
|
|
public function registerExtension(\Closure $callable) { |
|
242
|
|
|
array_push($this->extensionsClosures, $callable); |
|
243
|
|
|
$this->extensions = []; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** @var string[] */ |
|
247
|
|
|
protected $filterClasses = []; |
|
248
|
|
|
|
|
249
|
|
|
/** @var IFilter[] */ |
|
250
|
|
|
protected $filters = []; |
|
251
|
|
|
|
|
252
|
|
|
/** @var bool */ |
|
253
|
|
|
protected $loadedLegacyFilters = false; |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param string $filter Class must implement OCA\Activity\IFilter |
|
257
|
|
|
* @return void |
|
258
|
|
|
*/ |
|
259
|
|
|
public function registerFilter($filter) { |
|
260
|
|
|
$this->filterClasses[$filter] = false; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @return IFilter[] |
|
265
|
|
|
* @throws \InvalidArgumentException |
|
266
|
|
|
*/ |
|
267
|
|
|
public function getFilters() { |
|
268
|
|
|
if (!$this->loadedLegacyFilters) { |
|
269
|
|
|
$legacyFilters = $this->getNavigation(); |
|
|
|
|
|
|
270
|
|
|
|
|
271
|
|
View Code Duplication |
foreach ($legacyFilters['top'] as $filter => $data) { |
|
|
|
|
|
|
272
|
|
|
$this->filters[$filter] = new LegacyFilter( |
|
273
|
|
|
$this, $filter, $data['name'], true |
|
274
|
|
|
); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
View Code Duplication |
foreach ($legacyFilters['apps'] as $filter => $data) { |
|
|
|
|
|
|
278
|
|
|
$this->filters[$filter] = new LegacyFilter( |
|
279
|
|
|
$this, $filter, $data['name'], false |
|
280
|
|
|
); |
|
281
|
|
|
} |
|
282
|
|
|
$this->loadedLegacyFilters = true; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
View Code Duplication |
foreach ($this->filterClasses as $class => $false) { |
|
|
|
|
|
|
286
|
|
|
/** @var IFilter $filter */ |
|
287
|
|
|
$filter = \OC::$server->query($class); |
|
288
|
|
|
|
|
289
|
|
|
if (!$filter instanceof IFilter) { |
|
290
|
|
|
throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
$this->filters[$filter->getIdentifier()] = $filter; |
|
294
|
|
|
|
|
295
|
|
|
unset($this->filterClasses[$class]); |
|
296
|
|
|
} |
|
297
|
|
|
return $this->filters; |
|
|
|
|
|
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @param string $id |
|
302
|
|
|
* @return IFilter |
|
303
|
|
|
* @throws \InvalidArgumentException when the filter was not found |
|
304
|
|
|
* @since 11.0.0 |
|
305
|
|
|
*/ |
|
306
|
|
|
public function getFilterById($id) { |
|
307
|
|
|
$filters = $this->getFilters(); |
|
308
|
|
|
|
|
309
|
|
|
if (isset($filters[$id])) { |
|
310
|
|
|
return $filters[$id]; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
throw new \InvalidArgumentException('Requested filter does not exist'); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** @var string[] */ |
|
317
|
|
|
protected $providerClasses = []; |
|
318
|
|
|
|
|
319
|
|
|
/** @var IProvider[] */ |
|
320
|
|
|
protected $providers = []; |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* @param string $provider Class must implement OCA\Activity\IProvider |
|
324
|
|
|
* @return void |
|
325
|
|
|
*/ |
|
326
|
|
|
public function registerProvider($provider) { |
|
327
|
|
|
$this->providerClasses[$provider] = false; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @return IProvider[] |
|
332
|
|
|
* @throws \InvalidArgumentException |
|
333
|
|
|
*/ |
|
334
|
|
|
public function getProviders() { |
|
335
|
|
|
foreach ($this->providerClasses as $class => $false) { |
|
336
|
|
|
/** @var IProvider $provider */ |
|
337
|
|
|
$provider = \OC::$server->query($class); |
|
338
|
|
|
|
|
339
|
|
|
if (!$provider instanceof IProvider) { |
|
340
|
|
|
throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
$this->providers[] = $provider; |
|
344
|
|
|
|
|
345
|
|
|
unset($this->providerClasses[$class]); |
|
346
|
|
|
} |
|
347
|
|
|
return $this->providers; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** @var string[] */ |
|
351
|
|
|
protected $settingsClasses = []; |
|
352
|
|
|
|
|
353
|
|
|
/** @var ISetting[] */ |
|
354
|
|
|
protected $settings = []; |
|
355
|
|
|
|
|
356
|
|
|
/** @var bool */ |
|
357
|
|
|
protected $loadedLegacyTypes = false; |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* @param string $setting Class must implement OCA\Activity\ISetting |
|
361
|
|
|
* @return void |
|
362
|
|
|
*/ |
|
363
|
|
|
public function registerSetting($setting) { |
|
364
|
|
|
$this->settingsClasses[$setting] = false; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* @return ISetting[] |
|
369
|
|
|
* @throws \InvalidArgumentException |
|
370
|
|
|
*/ |
|
371
|
|
|
public function getSettings() { |
|
372
|
|
|
if (!$this->loadedLegacyTypes) { |
|
373
|
|
|
$l = \OC::$server->getL10N('core'); |
|
374
|
|
|
$legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
|
|
|
|
|
375
|
|
|
$streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
|
|
|
|
|
376
|
|
|
$mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
|
|
|
|
|
377
|
|
|
foreach ($legacyTypes as $type => $data) { |
|
378
|
|
|
if (is_string($data)) { |
|
379
|
|
|
$desc = $data; |
|
380
|
|
|
$canChangeStream = true; |
|
381
|
|
|
$canChangeMail = true; |
|
382
|
|
|
} else { |
|
383
|
|
|
$desc = $data['desc']; |
|
384
|
|
|
$canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
385
|
|
|
$canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
$this->settings[$type] = new LegacySetting( |
|
389
|
|
|
$type, $desc, |
|
390
|
|
|
$canChangeStream, in_array($type, $streamTypes), |
|
391
|
|
|
$canChangeMail, in_array($type, $mailTypes) |
|
392
|
|
|
); |
|
393
|
|
|
} |
|
394
|
|
|
$this->loadedLegacyTypes = true; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
View Code Duplication |
foreach ($this->settingsClasses as $class => $false) { |
|
|
|
|
|
|
398
|
|
|
/** @var ISetting $setting */ |
|
399
|
|
|
$setting = \OC::$server->query($class); |
|
400
|
|
|
|
|
401
|
|
|
if (!$setting instanceof ISetting) { |
|
402
|
|
|
throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
$this->settings[$setting->getIdentifier()] = $setting; |
|
406
|
|
|
|
|
407
|
|
|
unset($this->settingsClasses[$class]); |
|
408
|
|
|
} |
|
409
|
|
|
return $this->settings; |
|
|
|
|
|
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* @param string $id |
|
414
|
|
|
* @return ISetting |
|
415
|
|
|
* @throws \InvalidArgumentException when the setting was not found |
|
416
|
|
|
* @since 11.0.0 |
|
417
|
|
|
*/ |
|
418
|
|
|
public function getSettingById($id) { |
|
419
|
|
|
$settings = $this->getSettings(); |
|
420
|
|
|
|
|
421
|
|
|
if (isset($settings[$id])) { |
|
422
|
|
|
return $settings[$id]; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
throw new \InvalidArgumentException('Requested setting does not exist'); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* @param string $type |
|
430
|
|
|
* @return string |
|
431
|
|
|
*/ |
|
432
|
|
|
public function getTypeIcon($type) { |
|
433
|
|
|
if (isset($this->typeIcons[$type])) { |
|
434
|
|
|
return $this->typeIcons[$type]; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
foreach ($this->getExtensions() as $c) { |
|
438
|
|
|
$icon = $c->getTypeIcon($type); |
|
439
|
|
|
if (is_string($icon)) { |
|
440
|
|
|
$this->typeIcons[$type] = $icon; |
|
441
|
|
|
return $icon; |
|
442
|
|
|
} |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
$this->typeIcons[$type] = ''; |
|
446
|
|
|
return ''; |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @param string $type |
|
451
|
|
|
* @param string $id |
|
452
|
|
|
*/ |
|
453
|
|
|
public function setFormattingObject($type, $id) { |
|
454
|
|
|
$this->formattingObjectType = $type; |
|
455
|
|
|
$this->formattingObjectId = (string) $id; |
|
|
|
|
|
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* @return bool |
|
460
|
|
|
*/ |
|
461
|
|
|
public function isFormattingFilteredObject() { |
|
462
|
|
|
return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
463
|
|
|
&& $this->formattingObjectType === $this->request->getParam('object_type') |
|
464
|
|
|
&& $this->formattingObjectId === $this->request->getParam('object_id'); |
|
|
|
|
|
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
/** |
|
468
|
|
|
* @param string $app |
|
469
|
|
|
* @param string $text |
|
470
|
|
|
* @param array $params |
|
471
|
|
|
* @param boolean $stripPath |
|
472
|
|
|
* @param boolean $highlightParams |
|
473
|
|
|
* @param string $languageCode |
|
474
|
|
|
* @return string|false |
|
475
|
|
|
*/ |
|
476
|
|
|
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
477
|
|
|
foreach ($this->getExtensions() as $c) { |
|
478
|
|
|
$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
479
|
|
|
if (is_string($translation)) { |
|
480
|
|
|
return $translation; |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
return false; |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* @param string $app |
|
489
|
|
|
* @param string $text |
|
490
|
|
|
* @return array|false |
|
491
|
|
|
*/ |
|
492
|
|
|
public function getSpecialParameterList($app, $text) { |
|
493
|
|
|
if (isset($this->specialParameters[$app][$text])) { |
|
494
|
|
|
return $this->specialParameters[$app][$text]; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
if (!isset($this->specialParameters[$app])) { |
|
498
|
|
|
$this->specialParameters[$app] = array(); |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
foreach ($this->getExtensions() as $c) { |
|
502
|
|
|
$specialParameter = $c->getSpecialParameterList($app, $text); |
|
503
|
|
|
if (is_array($specialParameter)) { |
|
504
|
|
|
$this->specialParameters[$app][$text] = $specialParameter; |
|
505
|
|
|
return $specialParameter; |
|
506
|
|
|
} |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
$this->specialParameters[$app][$text] = false; |
|
510
|
|
|
return false; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
/** |
|
514
|
|
|
* @param array $activity |
|
515
|
|
|
* @return integer|false |
|
516
|
|
|
*/ |
|
517
|
|
|
public function getGroupParameter($activity) { |
|
518
|
|
|
foreach ($this->getExtensions() as $c) { |
|
519
|
|
|
$parameter = $c->getGroupParameter($activity); |
|
520
|
|
|
if ($parameter !== false) { |
|
521
|
|
|
return $parameter; |
|
522
|
|
|
} |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
return false; |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
/** |
|
529
|
|
|
* Set the user we need to use |
|
530
|
|
|
* |
|
531
|
|
|
* @param string|null $currentUserId |
|
532
|
|
|
* @throws \UnexpectedValueException If the user is invalid |
|
533
|
|
|
*/ |
|
534
|
|
|
public function setCurrentUserId($currentUserId) { |
|
535
|
|
|
if (!is_string($currentUserId) && $currentUserId !== null) { |
|
536
|
|
|
throw new \UnexpectedValueException('The given current user is invalid'); |
|
537
|
|
|
} |
|
538
|
|
|
$this->currentUserId = $currentUserId; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
/** |
|
542
|
|
|
* Get the user we need to use |
|
543
|
|
|
* |
|
544
|
|
|
* Either the user is logged in, or we try to get it from the token |
|
545
|
|
|
* |
|
546
|
|
|
* @return string |
|
547
|
|
|
* @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
548
|
|
|
*/ |
|
549
|
|
|
public function getCurrentUserId() { |
|
550
|
|
|
if ($this->currentUserId !== null) { |
|
551
|
|
|
return $this->currentUserId; |
|
552
|
|
|
} else if (!$this->session->isLoggedIn()) { |
|
553
|
|
|
return $this->getUserFromToken(); |
|
554
|
|
|
} else { |
|
555
|
|
|
return $this->session->getUser()->getUID(); |
|
556
|
|
|
} |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* Get the user for the token |
|
561
|
|
|
* |
|
562
|
|
|
* @return string |
|
563
|
|
|
* @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
564
|
|
|
*/ |
|
565
|
|
|
protected function getUserFromToken() { |
|
566
|
|
|
$token = (string) $this->request->getParam('token', ''); |
|
567
|
|
|
if (strlen($token) !== 30) { |
|
568
|
|
|
throw new \UnexpectedValueException('The token is invalid'); |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
$users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
572
|
|
|
|
|
573
|
|
|
if (sizeof($users) !== 1) { |
|
574
|
|
|
// No unique user found |
|
575
|
|
|
throw new \UnexpectedValueException('The token is invalid'); |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
// Token found login as that user |
|
579
|
|
|
return array_shift($users); |
|
580
|
|
|
} |
|
581
|
|
|
|
|
582
|
|
|
/** |
|
583
|
|
|
* @return array |
|
584
|
|
|
* @deprecated 11.0.0 - Use getFilters() instead |
|
585
|
|
|
*/ |
|
586
|
|
|
public function getNavigation() { |
|
587
|
|
|
$entries = array( |
|
588
|
|
|
'apps' => array(), |
|
589
|
|
|
'top' => array(), |
|
590
|
|
|
); |
|
591
|
|
|
foreach ($this->getExtensions() as $c) { |
|
592
|
|
|
$additionalEntries = $c->getNavigation(); |
|
|
|
|
|
|
593
|
|
|
if (is_array($additionalEntries)) { |
|
594
|
|
|
$entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
595
|
|
|
$entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
596
|
|
|
} |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
return $entries; |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
/** |
|
603
|
|
|
* @param string $filterValue |
|
604
|
|
|
* @return boolean |
|
605
|
|
|
* @deprecated 11.0.0 - Use getFilterById() instead |
|
606
|
|
|
*/ |
|
607
|
|
|
public function isFilterValid($filterValue) { |
|
608
|
|
|
if (isset($this->validFilters[$filterValue])) { |
|
609
|
|
|
return $this->validFilters[$filterValue]; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
foreach ($this->getExtensions() as $c) { |
|
613
|
|
|
if ($c->isFilterValid($filterValue) === true) { |
|
|
|
|
|
|
614
|
|
|
$this->validFilters[$filterValue] = true; |
|
615
|
|
|
return true; |
|
616
|
|
|
} |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
$this->validFilters[$filterValue] = false; |
|
620
|
|
|
return false; |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
/** |
|
624
|
|
|
* @param array $types |
|
625
|
|
|
* @param string $filter |
|
626
|
|
|
* @return array |
|
627
|
|
|
* @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
628
|
|
|
*/ |
|
629
|
|
|
public function filterNotificationTypes($types, $filter) { |
|
630
|
|
|
if (!$this->isFilterValid($filter)) { |
|
|
|
|
|
|
631
|
|
|
return $types; |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
foreach ($this->getExtensions() as $c) { |
|
635
|
|
|
$result = $c->filterNotificationTypes($types, $filter); |
|
|
|
|
|
|
636
|
|
|
if (is_array($result)) { |
|
637
|
|
|
$types = $result; |
|
638
|
|
|
} |
|
639
|
|
|
} |
|
640
|
|
|
return $types; |
|
641
|
|
|
} |
|
642
|
|
|
|
|
643
|
|
|
/** |
|
644
|
|
|
* @param string $filter |
|
645
|
|
|
* @return array |
|
646
|
|
|
* @deprecated 11.0.0 - Use getFilterById() instead |
|
647
|
|
|
*/ |
|
648
|
|
|
public function getQueryForFilter($filter) { |
|
649
|
|
|
if (!$this->isFilterValid($filter)) { |
|
|
|
|
|
|
650
|
|
|
return [null, null]; |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
$conditions = array(); |
|
654
|
|
|
$parameters = array(); |
|
655
|
|
|
|
|
656
|
|
|
foreach ($this->getExtensions() as $c) { |
|
657
|
|
|
$result = $c->getQueryForFilter($filter); |
|
|
|
|
|
|
658
|
|
|
if (is_array($result)) { |
|
659
|
|
|
list($condition, $parameter) = $result; |
|
660
|
|
|
if ($condition && is_array($parameter)) { |
|
661
|
|
|
$conditions[] = $condition; |
|
662
|
|
|
$parameters = array_merge($parameters, $parameter); |
|
663
|
|
|
} |
|
664
|
|
|
} |
|
665
|
|
|
} |
|
666
|
|
|
|
|
667
|
|
|
if (empty($conditions)) { |
|
668
|
|
|
return array(null, null); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
/** |
|
675
|
|
|
* Will return additional notification types as specified by other apps |
|
676
|
|
|
* |
|
677
|
|
|
* @param string $languageCode |
|
678
|
|
|
* @return array |
|
679
|
|
|
* @deprecated 11.0.0 - Use getSettings() instead |
|
680
|
|
|
*/ |
|
681
|
|
|
public function getNotificationTypes($languageCode) { |
|
682
|
|
|
$notificationTypes = $sharingNotificationTypes = []; |
|
683
|
|
|
foreach ($this->getExtensions() as $c) { |
|
684
|
|
|
$result = $c->getNotificationTypes($languageCode); |
|
685
|
|
|
if (is_array($result)) { |
|
686
|
|
|
if (class_exists('\OCA\Files_Sharing\Activity', false) && $c instanceof \OCA\Files_Sharing\Activity) { |
|
687
|
|
|
$sharingNotificationTypes = $result; |
|
688
|
|
|
continue; |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
$notificationTypes = array_merge($notificationTypes, $result); |
|
692
|
|
|
} |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
|
return array_merge($sharingNotificationTypes, $notificationTypes); |
|
696
|
|
|
} |
|
697
|
|
|
|
|
698
|
|
|
/** |
|
699
|
|
|
* @param string $method |
|
700
|
|
|
* @return array |
|
701
|
|
|
* @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
702
|
|
|
*/ |
|
703
|
|
|
public function getDefaultTypes($method) { |
|
704
|
|
|
$defaultTypes = array(); |
|
705
|
|
|
foreach ($this->getExtensions() as $c) { |
|
706
|
|
|
$types = $c->getDefaultTypes($method); |
|
707
|
|
|
if (is_array($types)) { |
|
708
|
|
|
$defaultTypes = array_merge($types, $defaultTypes); |
|
709
|
|
|
} |
|
710
|
|
|
} |
|
711
|
|
|
return $defaultTypes; |
|
712
|
|
|
} |
|
713
|
|
|
} |
|
714
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.