@@ -30,523 +30,523 @@ |
||
30 | 30 | |
31 | 31 | class Event implements IEvent { |
32 | 32 | |
33 | - /** @var string */ |
|
34 | - protected $app = ''; |
|
35 | - /** @var string */ |
|
36 | - protected $type = ''; |
|
37 | - /** @var string */ |
|
38 | - protected $affectedUser = ''; |
|
39 | - /** @var string */ |
|
40 | - protected $author = ''; |
|
41 | - /** @var int */ |
|
42 | - protected $timestamp = 0; |
|
43 | - /** @var string */ |
|
44 | - protected $subject = ''; |
|
45 | - /** @var array */ |
|
46 | - protected $subjectParameters = []; |
|
47 | - /** @var string */ |
|
48 | - protected $subjectParsed; |
|
49 | - /** @var string */ |
|
50 | - protected $subjectRich; |
|
51 | - /** @var array */ |
|
52 | - protected $subjectRichParameters; |
|
53 | - /** @var string */ |
|
54 | - protected $message = ''; |
|
55 | - /** @var array */ |
|
56 | - protected $messageParameters = []; |
|
57 | - /** @var string */ |
|
58 | - protected $messageParsed; |
|
59 | - /** @var string */ |
|
60 | - protected $messageRich; |
|
61 | - /** @var array */ |
|
62 | - protected $messageRichParameters; |
|
63 | - /** @var string */ |
|
64 | - protected $objectType = ''; |
|
65 | - /** @var int */ |
|
66 | - protected $objectId = 0; |
|
67 | - /** @var string */ |
|
68 | - protected $objectName = ''; |
|
69 | - /** @var string */ |
|
70 | - protected $link = ''; |
|
71 | - /** @var string */ |
|
72 | - protected $icon = ''; |
|
73 | - |
|
74 | - /** @var IEvent */ |
|
75 | - protected $child = null; |
|
76 | - /** @var IValidator */ |
|
77 | - protected $richValidator; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IValidator $richValidator |
|
81 | - */ |
|
82 | - public function __construct(IValidator $richValidator) { |
|
83 | - $this->richValidator = $richValidator; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Set the app of the activity |
|
88 | - * |
|
89 | - * @param string $app |
|
90 | - * @return IEvent |
|
91 | - * @throws \InvalidArgumentException if the app id is invalid |
|
92 | - * @since 8.2.0 |
|
93 | - */ |
|
94 | - public function setApp($app) { |
|
95 | - if (!is_string($app) || $app === '' || isset($app[32])) { |
|
96 | - throw new \InvalidArgumentException('The given app is invalid'); |
|
97 | - } |
|
98 | - $this->app = (string) $app; |
|
99 | - return $this; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function getApp() { |
|
106 | - return $this->app; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Set the type of the activity |
|
111 | - * |
|
112 | - * @param string $type |
|
113 | - * @return IEvent |
|
114 | - * @throws \InvalidArgumentException if the type is invalid |
|
115 | - * @since 8.2.0 |
|
116 | - */ |
|
117 | - public function setType($type) { |
|
118 | - if (!is_string($type) || $type === '' || isset($type[255])) { |
|
119 | - throw new \InvalidArgumentException('The given type is invalid'); |
|
120 | - } |
|
121 | - $this->type = (string) $type; |
|
122 | - return $this; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function getType() { |
|
129 | - return $this->type; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Set the affected user of the activity |
|
134 | - * |
|
135 | - * @param string $affectedUser |
|
136 | - * @return IEvent |
|
137 | - * @throws \InvalidArgumentException if the affected user is invalid |
|
138 | - * @since 8.2.0 |
|
139 | - */ |
|
140 | - public function setAffectedUser($affectedUser) { |
|
141 | - if (!is_string($affectedUser) || $affectedUser === '' || isset($affectedUser[64])) { |
|
142 | - throw new \InvalidArgumentException('The given affected user is invalid'); |
|
143 | - } |
|
144 | - $this->affectedUser = (string) $affectedUser; |
|
145 | - return $this; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function getAffectedUser() { |
|
152 | - return $this->affectedUser; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Set the author of the activity |
|
157 | - * |
|
158 | - * @param string $author |
|
159 | - * @return IEvent |
|
160 | - * @throws \InvalidArgumentException if the author is invalid |
|
161 | - * @since 8.2.0 |
|
162 | - */ |
|
163 | - public function setAuthor($author) { |
|
164 | - if (!is_string($author) || isset($author[64])) { |
|
165 | - throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
166 | - } |
|
167 | - $this->author = (string) $author; |
|
168 | - return $this; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function getAuthor() { |
|
175 | - return $this->author; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Set the timestamp of the activity |
|
180 | - * |
|
181 | - * @param int $timestamp |
|
182 | - * @return IEvent |
|
183 | - * @throws \InvalidArgumentException if the timestamp is invalid |
|
184 | - * @since 8.2.0 |
|
185 | - */ |
|
186 | - public function setTimestamp($timestamp) { |
|
187 | - if (!is_int($timestamp)) { |
|
188 | - throw new \InvalidArgumentException('The given timestamp is invalid'); |
|
189 | - } |
|
190 | - $this->timestamp = (int) $timestamp; |
|
191 | - return $this; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @return int |
|
196 | - */ |
|
197 | - public function getTimestamp() { |
|
198 | - return $this->timestamp; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Set the subject of the activity |
|
203 | - * |
|
204 | - * @param string $subject |
|
205 | - * @param array $parameters |
|
206 | - * @return IEvent |
|
207 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
208 | - * @since 8.2.0 |
|
209 | - */ |
|
210 | - public function setSubject($subject, array $parameters = []) { |
|
211 | - if (!is_string($subject) || isset($subject[255])) { |
|
212 | - throw new \InvalidArgumentException('The given subject is invalid'); |
|
213 | - } |
|
214 | - $this->subject = (string) $subject; |
|
215 | - $this->subjectParameters = $parameters; |
|
216 | - return $this; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function getSubject() { |
|
223 | - return $this->subject; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function getSubjectParameters() { |
|
230 | - return $this->subjectParameters; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $subject |
|
235 | - * @return $this |
|
236 | - * @throws \InvalidArgumentException if the subject is invalid |
|
237 | - * @since 11.0.0 |
|
238 | - */ |
|
239 | - public function setParsedSubject($subject) { |
|
240 | - if (!is_string($subject) || $subject === '') { |
|
241 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
242 | - } |
|
243 | - $this->subjectParsed = $subject; |
|
244 | - return $this; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @return string |
|
249 | - * @since 11.0.0 |
|
250 | - */ |
|
251 | - public function getParsedSubject() { |
|
252 | - return $this->subjectParsed; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $subject |
|
257 | - * @param array $parameters |
|
258 | - * @return $this |
|
259 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
260 | - * @since 11.0.0 |
|
261 | - */ |
|
262 | - public function setRichSubject($subject, array $parameters = []) { |
|
263 | - if (!is_string($subject) || $subject === '') { |
|
264 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
265 | - } |
|
266 | - $this->subjectRich = $subject; |
|
267 | - |
|
268 | - if (!is_array($parameters)) { |
|
269 | - throw new \InvalidArgumentException('The given subject parameters are invalid'); |
|
270 | - } |
|
271 | - $this->subjectRichParameters = $parameters; |
|
272 | - |
|
273 | - return $this; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @return string |
|
278 | - * @since 11.0.0 |
|
279 | - */ |
|
280 | - public function getRichSubject() { |
|
281 | - return $this->subjectRich; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @return array[] |
|
286 | - * @since 11.0.0 |
|
287 | - */ |
|
288 | - public function getRichSubjectParameters() { |
|
289 | - return $this->subjectRichParameters; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Set the message of the activity |
|
294 | - * |
|
295 | - * @param string $message |
|
296 | - * @param array $parameters |
|
297 | - * @return IEvent |
|
298 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
299 | - * @since 8.2.0 |
|
300 | - */ |
|
301 | - public function setMessage($message, array $parameters = []) { |
|
302 | - if (!is_string($message) || isset($message[255])) { |
|
303 | - throw new \InvalidArgumentException('The given message is invalid'); |
|
304 | - } |
|
305 | - $this->message = (string) $message; |
|
306 | - $this->messageParameters = $parameters; |
|
307 | - return $this; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - public function getMessage() { |
|
314 | - return $this->message; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - public function getMessageParameters() { |
|
321 | - return $this->messageParameters; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $message |
|
326 | - * @return $this |
|
327 | - * @throws \InvalidArgumentException if the message is invalid |
|
328 | - * @since 11.0.0 |
|
329 | - */ |
|
330 | - public function setParsedMessage($message) { |
|
331 | - if (!is_string($message)) { |
|
332 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
333 | - } |
|
334 | - $this->messageParsed = $message; |
|
335 | - return $this; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @return string |
|
340 | - * @since 11.0.0 |
|
341 | - */ |
|
342 | - public function getParsedMessage() { |
|
343 | - return $this->messageParsed; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $message |
|
348 | - * @param array $parameters |
|
349 | - * @return $this |
|
350 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
351 | - * @since 11.0.0 |
|
352 | - */ |
|
353 | - public function setRichMessage($message, array $parameters = []) { |
|
354 | - if (!is_string($message)) { |
|
355 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
356 | - } |
|
357 | - $this->messageRich = $message; |
|
358 | - |
|
359 | - if (!is_array($parameters)) { |
|
360 | - throw new \InvalidArgumentException('The given message parameters are invalid'); |
|
361 | - } |
|
362 | - $this->messageRichParameters = $parameters; |
|
363 | - |
|
364 | - return $this; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @return string |
|
369 | - * @since 11.0.0 |
|
370 | - */ |
|
371 | - public function getRichMessage() { |
|
372 | - return $this->messageRich; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * @return array[] |
|
377 | - * @since 11.0.0 |
|
378 | - */ |
|
379 | - public function getRichMessageParameters() { |
|
380 | - return $this->messageRichParameters; |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Set the object of the activity |
|
385 | - * |
|
386 | - * @param string $objectType |
|
387 | - * @param int $objectId |
|
388 | - * @param string $objectName |
|
389 | - * @return IEvent |
|
390 | - * @throws \InvalidArgumentException if the object is invalid |
|
391 | - * @since 8.2.0 |
|
392 | - */ |
|
393 | - public function setObject($objectType, $objectId, $objectName = '') { |
|
394 | - if (!is_string($objectType) || isset($objectType[255])) { |
|
395 | - throw new \InvalidArgumentException('The given object type is invalid'); |
|
396 | - } |
|
397 | - if (!is_int($objectId)) { |
|
398 | - throw new \InvalidArgumentException('The given object id is invalid'); |
|
399 | - } |
|
400 | - if (!is_string($objectName) || isset($objectName[4000])) { |
|
401 | - throw new \InvalidArgumentException('The given object name is invalid'); |
|
402 | - } |
|
403 | - $this->objectType = (string) $objectType; |
|
404 | - $this->objectId = (int) $objectId; |
|
405 | - $this->objectName = (string) $objectName; |
|
406 | - return $this; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * @return string |
|
411 | - */ |
|
412 | - public function getObjectType() { |
|
413 | - return $this->objectType; |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function getObjectId() { |
|
420 | - return $this->objectId; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function getObjectName() { |
|
427 | - return $this->objectName; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Set the link of the activity |
|
432 | - * |
|
433 | - * @param string $link |
|
434 | - * @return IEvent |
|
435 | - * @throws \InvalidArgumentException if the link is invalid |
|
436 | - * @since 8.2.0 |
|
437 | - */ |
|
438 | - public function setLink($link) { |
|
439 | - if (!is_string($link) || isset($link[4000])) { |
|
440 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
441 | - } |
|
442 | - $this->link = (string) $link; |
|
443 | - return $this; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public function getLink() { |
|
450 | - return $this->link; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @param string $icon |
|
455 | - * @return $this |
|
456 | - * @throws \InvalidArgumentException if the icon is invalid |
|
457 | - * @since 11.0.0 |
|
458 | - */ |
|
459 | - public function setIcon($icon) { |
|
460 | - if (!is_string($icon) || isset($icon[4000])) { |
|
461 | - throw new \InvalidArgumentException('The given icon is invalid'); |
|
462 | - } |
|
463 | - $this->icon = $icon; |
|
464 | - return $this; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * @return string |
|
469 | - * @since 11.0.0 |
|
470 | - */ |
|
471 | - public function getIcon() { |
|
472 | - return $this->icon; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * @param IEvent $child |
|
477 | - * @since 11.0.0 |
|
478 | - */ |
|
479 | - public function setChildEvent(IEvent $child) { |
|
480 | - $this->child = $child; |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * @return IEvent|null |
|
485 | - * @since 11.0.0 |
|
486 | - */ |
|
487 | - public function getChildEvent() { |
|
488 | - return $this->child; |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @return bool |
|
493 | - * @since 8.2.0 |
|
494 | - */ |
|
495 | - public function isValid() { |
|
496 | - return |
|
497 | - $this->isValidCommon() |
|
498 | - && |
|
499 | - $this->getSubject() !== '' |
|
500 | - ; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * @return bool |
|
505 | - * @since 8.2.0 |
|
506 | - */ |
|
507 | - public function isValidParsed() { |
|
508 | - if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
509 | - try { |
|
510 | - $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
511 | - } catch (InvalidObjectExeption $e) { |
|
512 | - return false; |
|
513 | - } |
|
514 | - } |
|
515 | - |
|
516 | - if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
517 | - try { |
|
518 | - $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
519 | - } catch (InvalidObjectExeption $e) { |
|
520 | - return false; |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - return |
|
525 | - $this->isValidCommon() |
|
526 | - && |
|
527 | - $this->getParsedSubject() !== '' |
|
528 | - ; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * @return bool |
|
533 | - */ |
|
534 | - protected function isValidCommon() { |
|
535 | - return |
|
536 | - $this->getApp() !== '' |
|
537 | - && |
|
538 | - $this->getType() !== '' |
|
539 | - && |
|
540 | - $this->getAffectedUser() !== '' |
|
541 | - && |
|
542 | - $this->getTimestamp() !== 0 |
|
543 | - /** |
|
544 | - * Disabled for BC with old activities |
|
33 | + /** @var string */ |
|
34 | + protected $app = ''; |
|
35 | + /** @var string */ |
|
36 | + protected $type = ''; |
|
37 | + /** @var string */ |
|
38 | + protected $affectedUser = ''; |
|
39 | + /** @var string */ |
|
40 | + protected $author = ''; |
|
41 | + /** @var int */ |
|
42 | + protected $timestamp = 0; |
|
43 | + /** @var string */ |
|
44 | + protected $subject = ''; |
|
45 | + /** @var array */ |
|
46 | + protected $subjectParameters = []; |
|
47 | + /** @var string */ |
|
48 | + protected $subjectParsed; |
|
49 | + /** @var string */ |
|
50 | + protected $subjectRich; |
|
51 | + /** @var array */ |
|
52 | + protected $subjectRichParameters; |
|
53 | + /** @var string */ |
|
54 | + protected $message = ''; |
|
55 | + /** @var array */ |
|
56 | + protected $messageParameters = []; |
|
57 | + /** @var string */ |
|
58 | + protected $messageParsed; |
|
59 | + /** @var string */ |
|
60 | + protected $messageRich; |
|
61 | + /** @var array */ |
|
62 | + protected $messageRichParameters; |
|
63 | + /** @var string */ |
|
64 | + protected $objectType = ''; |
|
65 | + /** @var int */ |
|
66 | + protected $objectId = 0; |
|
67 | + /** @var string */ |
|
68 | + protected $objectName = ''; |
|
69 | + /** @var string */ |
|
70 | + protected $link = ''; |
|
71 | + /** @var string */ |
|
72 | + protected $icon = ''; |
|
73 | + |
|
74 | + /** @var IEvent */ |
|
75 | + protected $child = null; |
|
76 | + /** @var IValidator */ |
|
77 | + protected $richValidator; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IValidator $richValidator |
|
81 | + */ |
|
82 | + public function __construct(IValidator $richValidator) { |
|
83 | + $this->richValidator = $richValidator; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Set the app of the activity |
|
88 | + * |
|
89 | + * @param string $app |
|
90 | + * @return IEvent |
|
91 | + * @throws \InvalidArgumentException if the app id is invalid |
|
92 | + * @since 8.2.0 |
|
93 | + */ |
|
94 | + public function setApp($app) { |
|
95 | + if (!is_string($app) || $app === '' || isset($app[32])) { |
|
96 | + throw new \InvalidArgumentException('The given app is invalid'); |
|
97 | + } |
|
98 | + $this->app = (string) $app; |
|
99 | + return $this; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function getApp() { |
|
106 | + return $this->app; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Set the type of the activity |
|
111 | + * |
|
112 | + * @param string $type |
|
113 | + * @return IEvent |
|
114 | + * @throws \InvalidArgumentException if the type is invalid |
|
115 | + * @since 8.2.0 |
|
116 | + */ |
|
117 | + public function setType($type) { |
|
118 | + if (!is_string($type) || $type === '' || isset($type[255])) { |
|
119 | + throw new \InvalidArgumentException('The given type is invalid'); |
|
120 | + } |
|
121 | + $this->type = (string) $type; |
|
122 | + return $this; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function getType() { |
|
129 | + return $this->type; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Set the affected user of the activity |
|
134 | + * |
|
135 | + * @param string $affectedUser |
|
136 | + * @return IEvent |
|
137 | + * @throws \InvalidArgumentException if the affected user is invalid |
|
138 | + * @since 8.2.0 |
|
139 | + */ |
|
140 | + public function setAffectedUser($affectedUser) { |
|
141 | + if (!is_string($affectedUser) || $affectedUser === '' || isset($affectedUser[64])) { |
|
142 | + throw new \InvalidArgumentException('The given affected user is invalid'); |
|
143 | + } |
|
144 | + $this->affectedUser = (string) $affectedUser; |
|
145 | + return $this; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function getAffectedUser() { |
|
152 | + return $this->affectedUser; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Set the author of the activity |
|
157 | + * |
|
158 | + * @param string $author |
|
159 | + * @return IEvent |
|
160 | + * @throws \InvalidArgumentException if the author is invalid |
|
161 | + * @since 8.2.0 |
|
162 | + */ |
|
163 | + public function setAuthor($author) { |
|
164 | + if (!is_string($author) || isset($author[64])) { |
|
165 | + throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
166 | + } |
|
167 | + $this->author = (string) $author; |
|
168 | + return $this; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function getAuthor() { |
|
175 | + return $this->author; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Set the timestamp of the activity |
|
180 | + * |
|
181 | + * @param int $timestamp |
|
182 | + * @return IEvent |
|
183 | + * @throws \InvalidArgumentException if the timestamp is invalid |
|
184 | + * @since 8.2.0 |
|
185 | + */ |
|
186 | + public function setTimestamp($timestamp) { |
|
187 | + if (!is_int($timestamp)) { |
|
188 | + throw new \InvalidArgumentException('The given timestamp is invalid'); |
|
189 | + } |
|
190 | + $this->timestamp = (int) $timestamp; |
|
191 | + return $this; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @return int |
|
196 | + */ |
|
197 | + public function getTimestamp() { |
|
198 | + return $this->timestamp; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Set the subject of the activity |
|
203 | + * |
|
204 | + * @param string $subject |
|
205 | + * @param array $parameters |
|
206 | + * @return IEvent |
|
207 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
208 | + * @since 8.2.0 |
|
209 | + */ |
|
210 | + public function setSubject($subject, array $parameters = []) { |
|
211 | + if (!is_string($subject) || isset($subject[255])) { |
|
212 | + throw new \InvalidArgumentException('The given subject is invalid'); |
|
213 | + } |
|
214 | + $this->subject = (string) $subject; |
|
215 | + $this->subjectParameters = $parameters; |
|
216 | + return $this; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function getSubject() { |
|
223 | + return $this->subject; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function getSubjectParameters() { |
|
230 | + return $this->subjectParameters; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $subject |
|
235 | + * @return $this |
|
236 | + * @throws \InvalidArgumentException if the subject is invalid |
|
237 | + * @since 11.0.0 |
|
238 | + */ |
|
239 | + public function setParsedSubject($subject) { |
|
240 | + if (!is_string($subject) || $subject === '') { |
|
241 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
242 | + } |
|
243 | + $this->subjectParsed = $subject; |
|
244 | + return $this; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @return string |
|
249 | + * @since 11.0.0 |
|
250 | + */ |
|
251 | + public function getParsedSubject() { |
|
252 | + return $this->subjectParsed; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $subject |
|
257 | + * @param array $parameters |
|
258 | + * @return $this |
|
259 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
260 | + * @since 11.0.0 |
|
261 | + */ |
|
262 | + public function setRichSubject($subject, array $parameters = []) { |
|
263 | + if (!is_string($subject) || $subject === '') { |
|
264 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
265 | + } |
|
266 | + $this->subjectRich = $subject; |
|
267 | + |
|
268 | + if (!is_array($parameters)) { |
|
269 | + throw new \InvalidArgumentException('The given subject parameters are invalid'); |
|
270 | + } |
|
271 | + $this->subjectRichParameters = $parameters; |
|
272 | + |
|
273 | + return $this; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @return string |
|
278 | + * @since 11.0.0 |
|
279 | + */ |
|
280 | + public function getRichSubject() { |
|
281 | + return $this->subjectRich; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @return array[] |
|
286 | + * @since 11.0.0 |
|
287 | + */ |
|
288 | + public function getRichSubjectParameters() { |
|
289 | + return $this->subjectRichParameters; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Set the message of the activity |
|
294 | + * |
|
295 | + * @param string $message |
|
296 | + * @param array $parameters |
|
297 | + * @return IEvent |
|
298 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
299 | + * @since 8.2.0 |
|
300 | + */ |
|
301 | + public function setMessage($message, array $parameters = []) { |
|
302 | + if (!is_string($message) || isset($message[255])) { |
|
303 | + throw new \InvalidArgumentException('The given message is invalid'); |
|
304 | + } |
|
305 | + $this->message = (string) $message; |
|
306 | + $this->messageParameters = $parameters; |
|
307 | + return $this; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + public function getMessage() { |
|
314 | + return $this->message; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + public function getMessageParameters() { |
|
321 | + return $this->messageParameters; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $message |
|
326 | + * @return $this |
|
327 | + * @throws \InvalidArgumentException if the message is invalid |
|
328 | + * @since 11.0.0 |
|
329 | + */ |
|
330 | + public function setParsedMessage($message) { |
|
331 | + if (!is_string($message)) { |
|
332 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
333 | + } |
|
334 | + $this->messageParsed = $message; |
|
335 | + return $this; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @return string |
|
340 | + * @since 11.0.0 |
|
341 | + */ |
|
342 | + public function getParsedMessage() { |
|
343 | + return $this->messageParsed; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $message |
|
348 | + * @param array $parameters |
|
349 | + * @return $this |
|
350 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
351 | + * @since 11.0.0 |
|
352 | + */ |
|
353 | + public function setRichMessage($message, array $parameters = []) { |
|
354 | + if (!is_string($message)) { |
|
355 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
356 | + } |
|
357 | + $this->messageRich = $message; |
|
358 | + |
|
359 | + if (!is_array($parameters)) { |
|
360 | + throw new \InvalidArgumentException('The given message parameters are invalid'); |
|
361 | + } |
|
362 | + $this->messageRichParameters = $parameters; |
|
363 | + |
|
364 | + return $this; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @return string |
|
369 | + * @since 11.0.0 |
|
370 | + */ |
|
371 | + public function getRichMessage() { |
|
372 | + return $this->messageRich; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * @return array[] |
|
377 | + * @since 11.0.0 |
|
378 | + */ |
|
379 | + public function getRichMessageParameters() { |
|
380 | + return $this->messageRichParameters; |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Set the object of the activity |
|
385 | + * |
|
386 | + * @param string $objectType |
|
387 | + * @param int $objectId |
|
388 | + * @param string $objectName |
|
389 | + * @return IEvent |
|
390 | + * @throws \InvalidArgumentException if the object is invalid |
|
391 | + * @since 8.2.0 |
|
392 | + */ |
|
393 | + public function setObject($objectType, $objectId, $objectName = '') { |
|
394 | + if (!is_string($objectType) || isset($objectType[255])) { |
|
395 | + throw new \InvalidArgumentException('The given object type is invalid'); |
|
396 | + } |
|
397 | + if (!is_int($objectId)) { |
|
398 | + throw new \InvalidArgumentException('The given object id is invalid'); |
|
399 | + } |
|
400 | + if (!is_string($objectName) || isset($objectName[4000])) { |
|
401 | + throw new \InvalidArgumentException('The given object name is invalid'); |
|
402 | + } |
|
403 | + $this->objectType = (string) $objectType; |
|
404 | + $this->objectId = (int) $objectId; |
|
405 | + $this->objectName = (string) $objectName; |
|
406 | + return $this; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * @return string |
|
411 | + */ |
|
412 | + public function getObjectType() { |
|
413 | + return $this->objectType; |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function getObjectId() { |
|
420 | + return $this->objectId; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function getObjectName() { |
|
427 | + return $this->objectName; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Set the link of the activity |
|
432 | + * |
|
433 | + * @param string $link |
|
434 | + * @return IEvent |
|
435 | + * @throws \InvalidArgumentException if the link is invalid |
|
436 | + * @since 8.2.0 |
|
437 | + */ |
|
438 | + public function setLink($link) { |
|
439 | + if (!is_string($link) || isset($link[4000])) { |
|
440 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
441 | + } |
|
442 | + $this->link = (string) $link; |
|
443 | + return $this; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public function getLink() { |
|
450 | + return $this->link; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @param string $icon |
|
455 | + * @return $this |
|
456 | + * @throws \InvalidArgumentException if the icon is invalid |
|
457 | + * @since 11.0.0 |
|
458 | + */ |
|
459 | + public function setIcon($icon) { |
|
460 | + if (!is_string($icon) || isset($icon[4000])) { |
|
461 | + throw new \InvalidArgumentException('The given icon is invalid'); |
|
462 | + } |
|
463 | + $this->icon = $icon; |
|
464 | + return $this; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * @return string |
|
469 | + * @since 11.0.0 |
|
470 | + */ |
|
471 | + public function getIcon() { |
|
472 | + return $this->icon; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * @param IEvent $child |
|
477 | + * @since 11.0.0 |
|
478 | + */ |
|
479 | + public function setChildEvent(IEvent $child) { |
|
480 | + $this->child = $child; |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * @return IEvent|null |
|
485 | + * @since 11.0.0 |
|
486 | + */ |
|
487 | + public function getChildEvent() { |
|
488 | + return $this->child; |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @return bool |
|
493 | + * @since 8.2.0 |
|
494 | + */ |
|
495 | + public function isValid() { |
|
496 | + return |
|
497 | + $this->isValidCommon() |
|
498 | + && |
|
499 | + $this->getSubject() !== '' |
|
500 | + ; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * @return bool |
|
505 | + * @since 8.2.0 |
|
506 | + */ |
|
507 | + public function isValidParsed() { |
|
508 | + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
509 | + try { |
|
510 | + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
511 | + } catch (InvalidObjectExeption $e) { |
|
512 | + return false; |
|
513 | + } |
|
514 | + } |
|
515 | + |
|
516 | + if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
517 | + try { |
|
518 | + $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
519 | + } catch (InvalidObjectExeption $e) { |
|
520 | + return false; |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + return |
|
525 | + $this->isValidCommon() |
|
526 | + && |
|
527 | + $this->getParsedSubject() !== '' |
|
528 | + ; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * @return bool |
|
533 | + */ |
|
534 | + protected function isValidCommon() { |
|
535 | + return |
|
536 | + $this->getApp() !== '' |
|
537 | + && |
|
538 | + $this->getType() !== '' |
|
539 | + && |
|
540 | + $this->getAffectedUser() !== '' |
|
541 | + && |
|
542 | + $this->getTimestamp() !== 0 |
|
543 | + /** |
|
544 | + * Disabled for BC with old activities |
|
545 | 545 | && |
546 | 546 | $this->getObjectType() !== '' |
547 | 547 | && |
548 | 548 | $this->getObjectId() !== 0 |
549 | - */ |
|
550 | - ; |
|
551 | - } |
|
549 | + */ |
|
550 | + ; |
|
551 | + } |
|
552 | 552 | } |
@@ -162,7 +162,7 @@ |
||
162 | 162 | */ |
163 | 163 | public function setAuthor($author) { |
164 | 164 | if (!is_string($author) || isset($author[64])) { |
165 | - throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
165 | + throw new \InvalidArgumentException('The given author user is invalid'.serialize($author)); |
|
166 | 166 | } |
167 | 167 | $this->author = (string) $author; |
168 | 168 | return $this; |
@@ -26,83 +26,83 @@ |
||
26 | 26 | |
27 | 27 | class LegacyFilter implements IFilter { |
28 | 28 | |
29 | - /** @var IManager */ |
|
30 | - protected $manager; |
|
31 | - /** @var string */ |
|
32 | - protected $identifier; |
|
33 | - /** @var string */ |
|
34 | - protected $name; |
|
35 | - /** @var bool */ |
|
36 | - protected $isTopFilter; |
|
29 | + /** @var IManager */ |
|
30 | + protected $manager; |
|
31 | + /** @var string */ |
|
32 | + protected $identifier; |
|
33 | + /** @var string */ |
|
34 | + protected $name; |
|
35 | + /** @var bool */ |
|
36 | + protected $isTopFilter; |
|
37 | 37 | |
38 | - /** |
|
39 | - * LegacySetting constructor. |
|
40 | - * |
|
41 | - * @param IManager $manager |
|
42 | - * @param string $identifier |
|
43 | - * @param string $name |
|
44 | - * @param bool $isTopFilter |
|
45 | - */ |
|
46 | - public function __construct(IManager $manager, |
|
47 | - $identifier, |
|
48 | - $name, |
|
49 | - $isTopFilter) { |
|
50 | - $this->manager = $manager; |
|
51 | - $this->identifier = $identifier; |
|
52 | - $this->name = $name; |
|
53 | - $this->isTopFilter = $isTopFilter; |
|
54 | - } |
|
38 | + /** |
|
39 | + * LegacySetting constructor. |
|
40 | + * |
|
41 | + * @param IManager $manager |
|
42 | + * @param string $identifier |
|
43 | + * @param string $name |
|
44 | + * @param bool $isTopFilter |
|
45 | + */ |
|
46 | + public function __construct(IManager $manager, |
|
47 | + $identifier, |
|
48 | + $name, |
|
49 | + $isTopFilter) { |
|
50 | + $this->manager = $manager; |
|
51 | + $this->identifier = $identifier; |
|
52 | + $this->name = $name; |
|
53 | + $this->isTopFilter = $isTopFilter; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string Lowercase a-z and underscore only identifier |
|
58 | - * @since 11.0.0 |
|
59 | - */ |
|
60 | - public function getIdentifier() { |
|
61 | - return $this->identifier; |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string Lowercase a-z and underscore only identifier |
|
58 | + * @since 11.0.0 |
|
59 | + */ |
|
60 | + public function getIdentifier() { |
|
61 | + return $this->identifier; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string A translated string |
|
66 | - * @since 11.0.0 |
|
67 | - */ |
|
68 | - public function getName() { |
|
69 | - return $this->name; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return string A translated string |
|
66 | + * @since 11.0.0 |
|
67 | + */ |
|
68 | + public function getName() { |
|
69 | + return $this->name; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return int whether the filter should be rather on the top or bottom of |
|
74 | - * the admin section. The filters are arranged in ascending order of the |
|
75 | - * priority values. It is required to return a value between 0 and 100. |
|
76 | - * @since 11.0.0 |
|
77 | - */ |
|
78 | - public function getPriority() { |
|
79 | - return $this->isTopFilter ? 40 : 50; |
|
80 | - } |
|
72 | + /** |
|
73 | + * @return int whether the filter should be rather on the top or bottom of |
|
74 | + * the admin section. The filters are arranged in ascending order of the |
|
75 | + * priority values. It is required to return a value between 0 and 100. |
|
76 | + * @since 11.0.0 |
|
77 | + */ |
|
78 | + public function getPriority() { |
|
79 | + return $this->isTopFilter ? 40 : 50; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return string Full URL to an icon, empty string when none is given |
|
84 | - * @since 11.0.0 |
|
85 | - */ |
|
86 | - public function getIcon() { |
|
87 | - // Old API was CSS class, so we can not use this... |
|
88 | - return ''; |
|
89 | - } |
|
82 | + /** |
|
83 | + * @return string Full URL to an icon, empty string when none is given |
|
84 | + * @since 11.0.0 |
|
85 | + */ |
|
86 | + public function getIcon() { |
|
87 | + // Old API was CSS class, so we can not use this... |
|
88 | + return ''; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string[] $types |
|
93 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
94 | - * @since 11.0.0 |
|
95 | - */ |
|
96 | - public function filterTypes(array $types) { |
|
97 | - return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @param string[] $types |
|
93 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
94 | + * @since 11.0.0 |
|
95 | + */ |
|
96 | + public function filterTypes(array $types) { |
|
97 | + return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
102 | - * @since 11.0.0 |
|
103 | - */ |
|
104 | - public function allowedApps() { |
|
105 | - return []; |
|
106 | - } |
|
100 | + /** |
|
101 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
102 | + * @since 11.0.0 |
|
103 | + */ |
|
104 | + public function allowedApps() { |
|
105 | + return []; |
|
106 | + } |
|
107 | 107 | } |
108 | 108 |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | $this->consumers = []; |
115 | - foreach($this->consumersClosures as $consumer) { |
|
115 | + foreach ($this->consumersClosures as $consumer) { |
|
116 | 116 | $c = $consumer(); |
117 | 117 | if ($c instanceof IConsumer) { |
118 | 118 | $this->consumers[] = $c; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $this->extensions = []; |
136 | - foreach($this->extensionsClosures as $extension) { |
|
136 | + foreach ($this->extensionsClosures as $extension) { |
|
137 | 137 | $e = $extension(); |
138 | 138 | if ($e instanceof IExtension) { |
139 | 139 | $this->extensions[] = $e; |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | return array(null, null); |
670 | 670 | } |
671 | 671 | |
672 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
672 | + return array(' and (('.implode(') or (', $conditions).'))', $parameters); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -40,688 +40,688 @@ |
||
40 | 40 | use OCP\RichObjectStrings\IValidator; |
41 | 41 | |
42 | 42 | class Manager implements IManager { |
43 | - /** @var IRequest */ |
|
44 | - protected $request; |
|
45 | - |
|
46 | - /** @var IUserSession */ |
|
47 | - protected $session; |
|
48 | - |
|
49 | - /** @var IConfig */ |
|
50 | - protected $config; |
|
51 | - |
|
52 | - /** @var IValidator */ |
|
53 | - protected $validator; |
|
54 | - |
|
55 | - /** @var string */ |
|
56 | - protected $formattingObjectType; |
|
57 | - |
|
58 | - /** @var int */ |
|
59 | - protected $formattingObjectId; |
|
60 | - |
|
61 | - /** @var bool */ |
|
62 | - protected $requirePNG; |
|
63 | - |
|
64 | - /** @var string */ |
|
65 | - protected $currentUserId; |
|
66 | - |
|
67 | - /** |
|
68 | - * constructor of the controller |
|
69 | - * |
|
70 | - * @param IRequest $request |
|
71 | - * @param IUserSession $session |
|
72 | - * @param IConfig $config |
|
73 | - * @param IValidator $validator |
|
74 | - */ |
|
75 | - public function __construct(IRequest $request, |
|
76 | - IUserSession $session, |
|
77 | - IConfig $config, |
|
78 | - IValidator $validator) { |
|
79 | - $this->request = $request; |
|
80 | - $this->session = $session; |
|
81 | - $this->config = $config; |
|
82 | - $this->validator = $validator; |
|
83 | - } |
|
84 | - |
|
85 | - /** @var \Closure[] */ |
|
86 | - private $consumersClosures = array(); |
|
87 | - |
|
88 | - /** @var IConsumer[] */ |
|
89 | - private $consumers = array(); |
|
90 | - |
|
91 | - /** @var \Closure[] */ |
|
92 | - private $extensionsClosures = array(); |
|
93 | - |
|
94 | - /** @var IExtension[] */ |
|
95 | - private $extensions = array(); |
|
96 | - |
|
97 | - /** @var array list of filters "name" => "is valid" */ |
|
98 | - protected $validFilters = array( |
|
99 | - 'all' => true, |
|
100 | - 'by' => true, |
|
101 | - 'self' => true, |
|
102 | - ); |
|
103 | - |
|
104 | - /** @var array list of type icons "type" => "css class" */ |
|
105 | - protected $typeIcons = array(); |
|
106 | - |
|
107 | - /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | - protected $specialParameters = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return \OCP\Activity\IConsumer[] |
|
112 | - */ |
|
113 | - protected function getConsumers() { |
|
114 | - if (!empty($this->consumers)) { |
|
115 | - return $this->consumers; |
|
116 | - } |
|
117 | - |
|
118 | - $this->consumers = []; |
|
119 | - foreach($this->consumersClosures as $consumer) { |
|
120 | - $c = $consumer(); |
|
121 | - if ($c instanceof IConsumer) { |
|
122 | - $this->consumers[] = $c; |
|
123 | - } else { |
|
124 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - return $this->consumers; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return \OCP\Activity\IExtension[] |
|
133 | - */ |
|
134 | - protected function getExtensions() { |
|
135 | - if (!empty($this->extensions)) { |
|
136 | - return $this->extensions; |
|
137 | - } |
|
138 | - |
|
139 | - $this->extensions = []; |
|
140 | - foreach($this->extensionsClosures as $extension) { |
|
141 | - $e = $extension(); |
|
142 | - if ($e instanceof IExtension) { |
|
143 | - $this->extensions[] = $e; |
|
144 | - } else { |
|
145 | - throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - return $this->extensions; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Generates a new IEvent object |
|
154 | - * |
|
155 | - * Make sure to call at least the following methods before sending it to the |
|
156 | - * app with via the publish() method: |
|
157 | - * - setApp() |
|
158 | - * - setType() |
|
159 | - * - setAffectedUser() |
|
160 | - * - setSubject() |
|
161 | - * |
|
162 | - * @return IEvent |
|
163 | - */ |
|
164 | - public function generateEvent() { |
|
165 | - return new Event($this->validator); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Publish an event to the activity consumers |
|
170 | - * |
|
171 | - * Make sure to call at least the following methods before sending an Event: |
|
172 | - * - setApp() |
|
173 | - * - setType() |
|
174 | - * - setAffectedUser() |
|
175 | - * - setSubject() |
|
176 | - * |
|
177 | - * @param IEvent $event |
|
178 | - * @throws \BadMethodCallException if required values have not been set |
|
179 | - */ |
|
180 | - public function publish(IEvent $event) { |
|
181 | - if ($event->getAuthor() === '') { |
|
182 | - if ($this->session->getUser() instanceof IUser) { |
|
183 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - if (!$event->getTimestamp()) { |
|
188 | - $event->setTimestamp(time()); |
|
189 | - } |
|
190 | - |
|
191 | - if (!$event->isValid()) { |
|
192 | - throw new \BadMethodCallException('The given event is invalid'); |
|
193 | - } |
|
194 | - |
|
195 | - foreach ($this->getConsumers() as $c) { |
|
196 | - $c->receive($event); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $app The app where this event is associated with |
|
202 | - * @param string $subject A short description of the event |
|
203 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
204 | - * @param string $message A longer description of the event |
|
205 | - * @param array $messageParams Array with parameters that are filled in the message |
|
206 | - * @param string $file The file including path where this event is associated with |
|
207 | - * @param string $link A link where this event is associated with |
|
208 | - * @param string $affectedUser Recipient of the activity |
|
209 | - * @param string $type Type of the notification |
|
210 | - * @param int $priority Priority of the notification |
|
211 | - */ |
|
212 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
213 | - $event = $this->generateEvent(); |
|
214 | - $event->setApp($app) |
|
215 | - ->setType($type) |
|
216 | - ->setAffectedUser($affectedUser) |
|
217 | - ->setSubject($subject, $subjectParams) |
|
218 | - ->setMessage($message, $messageParams) |
|
219 | - ->setObject('', 0, $file) |
|
220 | - ->setLink($link); |
|
221 | - |
|
222 | - $this->publish($event); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
227 | - * activity consumers are actually requested |
|
228 | - * |
|
229 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
230 | - * |
|
231 | - * @param \Closure $callable |
|
232 | - */ |
|
233 | - public function registerConsumer(\Closure $callable) { |
|
234 | - $this->consumersClosures[] = $callable; |
|
235 | - $this->consumers = []; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
240 | - * activity consumers are actually requested |
|
241 | - * |
|
242 | - * $callable has to return an instance of OCA\Activity\IExtension |
|
243 | - * |
|
244 | - * @param \Closure $callable |
|
245 | - */ |
|
246 | - public function registerExtension(\Closure $callable) { |
|
247 | - $this->extensionsClosures[] = $callable; |
|
248 | - $this->extensions = []; |
|
249 | - } |
|
250 | - |
|
251 | - /** @var string[] */ |
|
252 | - protected $filterClasses = []; |
|
253 | - |
|
254 | - /** @var IFilter[] */ |
|
255 | - protected $filters = []; |
|
256 | - |
|
257 | - /** @var bool */ |
|
258 | - protected $loadedLegacyFilters = false; |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
262 | - * @return void |
|
263 | - */ |
|
264 | - public function registerFilter($filter) { |
|
265 | - $this->filterClasses[$filter] = false; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return IFilter[] |
|
270 | - * @throws \InvalidArgumentException |
|
271 | - */ |
|
272 | - public function getFilters() { |
|
273 | - if (!$this->loadedLegacyFilters) { |
|
274 | - $legacyFilters = $this->getNavigation(); |
|
275 | - |
|
276 | - foreach ($legacyFilters['top'] as $filter => $data) { |
|
277 | - $this->filters[$filter] = new LegacyFilter( |
|
278 | - $this, $filter, $data['name'], true |
|
279 | - ); |
|
280 | - } |
|
281 | - |
|
282 | - foreach ($legacyFilters['apps'] as $filter => $data) { |
|
283 | - $this->filters[$filter] = new LegacyFilter( |
|
284 | - $this, $filter, $data['name'], false |
|
285 | - ); |
|
286 | - } |
|
287 | - $this->loadedLegacyFilters = true; |
|
288 | - } |
|
289 | - |
|
290 | - foreach ($this->filterClasses as $class => $false) { |
|
291 | - /** @var IFilter $filter */ |
|
292 | - $filter = \OC::$server->query($class); |
|
293 | - |
|
294 | - if (!$filter instanceof IFilter) { |
|
295 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
296 | - } |
|
297 | - |
|
298 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
299 | - |
|
300 | - unset($this->filterClasses[$class]); |
|
301 | - } |
|
302 | - return $this->filters; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @param string $id |
|
307 | - * @return IFilter |
|
308 | - * @throws \InvalidArgumentException when the filter was not found |
|
309 | - * @since 11.0.0 |
|
310 | - */ |
|
311 | - public function getFilterById($id) { |
|
312 | - $filters = $this->getFilters(); |
|
313 | - |
|
314 | - if (isset($filters[$id])) { |
|
315 | - return $filters[$id]; |
|
316 | - } |
|
317 | - |
|
318 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
319 | - } |
|
320 | - |
|
321 | - /** @var string[] */ |
|
322 | - protected $providerClasses = []; |
|
323 | - |
|
324 | - /** @var IProvider[] */ |
|
325 | - protected $providers = []; |
|
326 | - |
|
327 | - /** |
|
328 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
329 | - * @return void |
|
330 | - */ |
|
331 | - public function registerProvider($provider) { |
|
332 | - $this->providerClasses[$provider] = false; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * @return IProvider[] |
|
337 | - * @throws \InvalidArgumentException |
|
338 | - */ |
|
339 | - public function getProviders() { |
|
340 | - foreach ($this->providerClasses as $class => $false) { |
|
341 | - /** @var IProvider $provider */ |
|
342 | - $provider = \OC::$server->query($class); |
|
343 | - |
|
344 | - if (!$provider instanceof IProvider) { |
|
345 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
346 | - } |
|
347 | - |
|
348 | - $this->providers[] = $provider; |
|
349 | - |
|
350 | - unset($this->providerClasses[$class]); |
|
351 | - } |
|
352 | - return $this->providers; |
|
353 | - } |
|
354 | - |
|
355 | - /** @var string[] */ |
|
356 | - protected $settingsClasses = []; |
|
357 | - |
|
358 | - /** @var ISetting[] */ |
|
359 | - protected $settings = []; |
|
360 | - |
|
361 | - /** @var bool */ |
|
362 | - protected $loadedLegacyTypes = false; |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
366 | - * @return void |
|
367 | - */ |
|
368 | - public function registerSetting($setting) { |
|
369 | - $this->settingsClasses[$setting] = false; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @return ISetting[] |
|
374 | - * @throws \InvalidArgumentException |
|
375 | - */ |
|
376 | - public function getSettings() { |
|
377 | - if (!$this->loadedLegacyTypes) { |
|
378 | - $l = \OC::$server->getL10N('core'); |
|
379 | - $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
380 | - $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
381 | - $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
382 | - foreach ($legacyTypes as $type => $data) { |
|
383 | - if (is_string($data)) { |
|
384 | - $desc = $data; |
|
385 | - $canChangeStream = true; |
|
386 | - $canChangeMail = true; |
|
387 | - } else { |
|
388 | - $desc = $data['desc']; |
|
389 | - $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
390 | - $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
391 | - } |
|
392 | - |
|
393 | - $this->settings[$type] = new LegacySetting( |
|
394 | - $type, $desc, |
|
395 | - $canChangeStream, in_array($type, $streamTypes), |
|
396 | - $canChangeMail, in_array($type, $mailTypes) |
|
397 | - ); |
|
398 | - } |
|
399 | - $this->loadedLegacyTypes = true; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ($this->settingsClasses as $class => $false) { |
|
403 | - /** @var ISetting $setting */ |
|
404 | - $setting = \OC::$server->query($class); |
|
405 | - |
|
406 | - if (!$setting instanceof ISetting) { |
|
407 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
408 | - } |
|
409 | - |
|
410 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
411 | - |
|
412 | - unset($this->settingsClasses[$class]); |
|
413 | - } |
|
414 | - return $this->settings; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * @param string $id |
|
419 | - * @return ISetting |
|
420 | - * @throws \InvalidArgumentException when the setting was not found |
|
421 | - * @since 11.0.0 |
|
422 | - */ |
|
423 | - public function getSettingById($id) { |
|
424 | - $settings = $this->getSettings(); |
|
425 | - |
|
426 | - if (isset($settings[$id])) { |
|
427 | - return $settings[$id]; |
|
428 | - } |
|
429 | - |
|
430 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param string $type |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function getTypeIcon($type) { |
|
438 | - if (isset($this->typeIcons[$type])) { |
|
439 | - return $this->typeIcons[$type]; |
|
440 | - } |
|
441 | - |
|
442 | - foreach ($this->getExtensions() as $c) { |
|
443 | - $icon = $c->getTypeIcon($type); |
|
444 | - if (is_string($icon)) { |
|
445 | - $this->typeIcons[$type] = $icon; |
|
446 | - return $icon; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - $this->typeIcons[$type] = ''; |
|
451 | - return ''; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @param string $type |
|
456 | - * @param string $id |
|
457 | - */ |
|
458 | - public function setFormattingObject($type, $id) { |
|
459 | - $this->formattingObjectType = $type; |
|
460 | - $this->formattingObjectId = (string) $id; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function isFormattingFilteredObject() { |
|
467 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
468 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
469 | - && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
474 | - */ |
|
475 | - public function setRequirePNG($status) { |
|
476 | - $this->requirePNG = $status; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @return bool |
|
481 | - */ |
|
482 | - public function getRequirePNG() { |
|
483 | - return $this->requirePNG; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $app |
|
488 | - * @param string $text |
|
489 | - * @param array $params |
|
490 | - * @param boolean $stripPath |
|
491 | - * @param boolean $highlightParams |
|
492 | - * @param string $languageCode |
|
493 | - * @return string|false |
|
494 | - */ |
|
495 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
496 | - foreach ($this->getExtensions() as $c) { |
|
497 | - $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
498 | - if (is_string($translation)) { |
|
499 | - return $translation; |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - return false; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @param string $app |
|
508 | - * @param string $text |
|
509 | - * @return array|false |
|
510 | - */ |
|
511 | - public function getSpecialParameterList($app, $text) { |
|
512 | - if (isset($this->specialParameters[$app][$text])) { |
|
513 | - return $this->specialParameters[$app][$text]; |
|
514 | - } |
|
515 | - |
|
516 | - if (!isset($this->specialParameters[$app])) { |
|
517 | - $this->specialParameters[$app] = array(); |
|
518 | - } |
|
519 | - |
|
520 | - foreach ($this->getExtensions() as $c) { |
|
521 | - $specialParameter = $c->getSpecialParameterList($app, $text); |
|
522 | - if (is_array($specialParameter)) { |
|
523 | - $this->specialParameters[$app][$text] = $specialParameter; |
|
524 | - return $specialParameter; |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - $this->specialParameters[$app][$text] = false; |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @param array $activity |
|
534 | - * @return integer|false |
|
535 | - */ |
|
536 | - public function getGroupParameter($activity) { |
|
537 | - foreach ($this->getExtensions() as $c) { |
|
538 | - $parameter = $c->getGroupParameter($activity); |
|
539 | - if ($parameter !== false) { |
|
540 | - return $parameter; |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - return false; |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the user we need to use |
|
549 | - * |
|
550 | - * @param string|null $currentUserId |
|
551 | - * @throws \UnexpectedValueException If the user is invalid |
|
552 | - */ |
|
553 | - public function setCurrentUserId($currentUserId) { |
|
554 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
555 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
556 | - } |
|
557 | - $this->currentUserId = $currentUserId; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Get the user we need to use |
|
562 | - * |
|
563 | - * Either the user is logged in, or we try to get it from the token |
|
564 | - * |
|
565 | - * @return string |
|
566 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
567 | - */ |
|
568 | - public function getCurrentUserId() { |
|
569 | - if ($this->currentUserId !== null) { |
|
570 | - return $this->currentUserId; |
|
571 | - } else if (!$this->session->isLoggedIn()) { |
|
572 | - return $this->getUserFromToken(); |
|
573 | - } else { |
|
574 | - return $this->session->getUser()->getUID(); |
|
575 | - } |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Get the user for the token |
|
580 | - * |
|
581 | - * @return string |
|
582 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
583 | - */ |
|
584 | - protected function getUserFromToken() { |
|
585 | - $token = (string) $this->request->getParam('token', ''); |
|
586 | - if (strlen($token) !== 30) { |
|
587 | - throw new \UnexpectedValueException('The token is invalid'); |
|
588 | - } |
|
589 | - |
|
590 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
591 | - |
|
592 | - if (count($users) !== 1) { |
|
593 | - // No unique user found |
|
594 | - throw new \UnexpectedValueException('The token is invalid'); |
|
595 | - } |
|
596 | - |
|
597 | - // Token found login as that user |
|
598 | - return array_shift($users); |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * @return array |
|
603 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
604 | - */ |
|
605 | - public function getNavigation() { |
|
606 | - $entries = array( |
|
607 | - 'apps' => array(), |
|
608 | - 'top' => array(), |
|
609 | - ); |
|
610 | - foreach ($this->getExtensions() as $c) { |
|
611 | - $additionalEntries = $c->getNavigation(); |
|
612 | - if (is_array($additionalEntries)) { |
|
613 | - $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
614 | - $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
615 | - } |
|
616 | - } |
|
617 | - |
|
618 | - return $entries; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * @param string $filterValue |
|
623 | - * @return boolean |
|
624 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
625 | - */ |
|
626 | - public function isFilterValid($filterValue) { |
|
627 | - if (isset($this->validFilters[$filterValue])) { |
|
628 | - return $this->validFilters[$filterValue]; |
|
629 | - } |
|
630 | - |
|
631 | - foreach ($this->getExtensions() as $c) { |
|
632 | - if ($c->isFilterValid($filterValue) === true) { |
|
633 | - $this->validFilters[$filterValue] = true; |
|
634 | - return true; |
|
635 | - } |
|
636 | - } |
|
637 | - |
|
638 | - $this->validFilters[$filterValue] = false; |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * @param array $types |
|
644 | - * @param string $filter |
|
645 | - * @return array |
|
646 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
647 | - */ |
|
648 | - public function filterNotificationTypes($types, $filter) { |
|
649 | - if (!$this->isFilterValid($filter)) { |
|
650 | - return $types; |
|
651 | - } |
|
652 | - |
|
653 | - foreach ($this->getExtensions() as $c) { |
|
654 | - $result = $c->filterNotificationTypes($types, $filter); |
|
655 | - if (is_array($result)) { |
|
656 | - $types = $result; |
|
657 | - } |
|
658 | - } |
|
659 | - return $types; |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * @param string $filter |
|
664 | - * @return array |
|
665 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
666 | - */ |
|
667 | - public function getQueryForFilter($filter) { |
|
668 | - if (!$this->isFilterValid($filter)) { |
|
669 | - return [null, null]; |
|
670 | - } |
|
671 | - |
|
672 | - $conditions = array(); |
|
673 | - $parameters = array(); |
|
674 | - |
|
675 | - foreach ($this->getExtensions() as $c) { |
|
676 | - $result = $c->getQueryForFilter($filter); |
|
677 | - if (is_array($result)) { |
|
678 | - list($condition, $parameter) = $result; |
|
679 | - if ($condition && is_array($parameter)) { |
|
680 | - $conditions[] = $condition; |
|
681 | - $parameters = array_merge($parameters, $parameter); |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - if (empty($conditions)) { |
|
687 | - return array(null, null); |
|
688 | - } |
|
689 | - |
|
690 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Will return additional notification types as specified by other apps |
|
695 | - * |
|
696 | - * @param string $languageCode |
|
697 | - * @return array |
|
698 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
699 | - */ |
|
700 | - public function getNotificationTypes($languageCode) { |
|
701 | - $notificationTypes = $sharingNotificationTypes = []; |
|
702 | - foreach ($this->getExtensions() as $c) { |
|
703 | - $result = $c->getNotificationTypes($languageCode); |
|
704 | - if (is_array($result)) { |
|
705 | - $notificationTypes = array_merge($notificationTypes, $result); |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - return array_merge($sharingNotificationTypes, $notificationTypes); |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * @param string $method |
|
714 | - * @return array |
|
715 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
716 | - */ |
|
717 | - public function getDefaultTypes($method) { |
|
718 | - $defaultTypes = array(); |
|
719 | - foreach ($this->getExtensions() as $c) { |
|
720 | - $types = $c->getDefaultTypes($method); |
|
721 | - if (is_array($types)) { |
|
722 | - $defaultTypes = array_merge($types, $defaultTypes); |
|
723 | - } |
|
724 | - } |
|
725 | - return $defaultTypes; |
|
726 | - } |
|
43 | + /** @var IRequest */ |
|
44 | + protected $request; |
|
45 | + |
|
46 | + /** @var IUserSession */ |
|
47 | + protected $session; |
|
48 | + |
|
49 | + /** @var IConfig */ |
|
50 | + protected $config; |
|
51 | + |
|
52 | + /** @var IValidator */ |
|
53 | + protected $validator; |
|
54 | + |
|
55 | + /** @var string */ |
|
56 | + protected $formattingObjectType; |
|
57 | + |
|
58 | + /** @var int */ |
|
59 | + protected $formattingObjectId; |
|
60 | + |
|
61 | + /** @var bool */ |
|
62 | + protected $requirePNG; |
|
63 | + |
|
64 | + /** @var string */ |
|
65 | + protected $currentUserId; |
|
66 | + |
|
67 | + /** |
|
68 | + * constructor of the controller |
|
69 | + * |
|
70 | + * @param IRequest $request |
|
71 | + * @param IUserSession $session |
|
72 | + * @param IConfig $config |
|
73 | + * @param IValidator $validator |
|
74 | + */ |
|
75 | + public function __construct(IRequest $request, |
|
76 | + IUserSession $session, |
|
77 | + IConfig $config, |
|
78 | + IValidator $validator) { |
|
79 | + $this->request = $request; |
|
80 | + $this->session = $session; |
|
81 | + $this->config = $config; |
|
82 | + $this->validator = $validator; |
|
83 | + } |
|
84 | + |
|
85 | + /** @var \Closure[] */ |
|
86 | + private $consumersClosures = array(); |
|
87 | + |
|
88 | + /** @var IConsumer[] */ |
|
89 | + private $consumers = array(); |
|
90 | + |
|
91 | + /** @var \Closure[] */ |
|
92 | + private $extensionsClosures = array(); |
|
93 | + |
|
94 | + /** @var IExtension[] */ |
|
95 | + private $extensions = array(); |
|
96 | + |
|
97 | + /** @var array list of filters "name" => "is valid" */ |
|
98 | + protected $validFilters = array( |
|
99 | + 'all' => true, |
|
100 | + 'by' => true, |
|
101 | + 'self' => true, |
|
102 | + ); |
|
103 | + |
|
104 | + /** @var array list of type icons "type" => "css class" */ |
|
105 | + protected $typeIcons = array(); |
|
106 | + |
|
107 | + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | + protected $specialParameters = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return \OCP\Activity\IConsumer[] |
|
112 | + */ |
|
113 | + protected function getConsumers() { |
|
114 | + if (!empty($this->consumers)) { |
|
115 | + return $this->consumers; |
|
116 | + } |
|
117 | + |
|
118 | + $this->consumers = []; |
|
119 | + foreach($this->consumersClosures as $consumer) { |
|
120 | + $c = $consumer(); |
|
121 | + if ($c instanceof IConsumer) { |
|
122 | + $this->consumers[] = $c; |
|
123 | + } else { |
|
124 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + return $this->consumers; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return \OCP\Activity\IExtension[] |
|
133 | + */ |
|
134 | + protected function getExtensions() { |
|
135 | + if (!empty($this->extensions)) { |
|
136 | + return $this->extensions; |
|
137 | + } |
|
138 | + |
|
139 | + $this->extensions = []; |
|
140 | + foreach($this->extensionsClosures as $extension) { |
|
141 | + $e = $extension(); |
|
142 | + if ($e instanceof IExtension) { |
|
143 | + $this->extensions[] = $e; |
|
144 | + } else { |
|
145 | + throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + return $this->extensions; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Generates a new IEvent object |
|
154 | + * |
|
155 | + * Make sure to call at least the following methods before sending it to the |
|
156 | + * app with via the publish() method: |
|
157 | + * - setApp() |
|
158 | + * - setType() |
|
159 | + * - setAffectedUser() |
|
160 | + * - setSubject() |
|
161 | + * |
|
162 | + * @return IEvent |
|
163 | + */ |
|
164 | + public function generateEvent() { |
|
165 | + return new Event($this->validator); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Publish an event to the activity consumers |
|
170 | + * |
|
171 | + * Make sure to call at least the following methods before sending an Event: |
|
172 | + * - setApp() |
|
173 | + * - setType() |
|
174 | + * - setAffectedUser() |
|
175 | + * - setSubject() |
|
176 | + * |
|
177 | + * @param IEvent $event |
|
178 | + * @throws \BadMethodCallException if required values have not been set |
|
179 | + */ |
|
180 | + public function publish(IEvent $event) { |
|
181 | + if ($event->getAuthor() === '') { |
|
182 | + if ($this->session->getUser() instanceof IUser) { |
|
183 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + if (!$event->getTimestamp()) { |
|
188 | + $event->setTimestamp(time()); |
|
189 | + } |
|
190 | + |
|
191 | + if (!$event->isValid()) { |
|
192 | + throw new \BadMethodCallException('The given event is invalid'); |
|
193 | + } |
|
194 | + |
|
195 | + foreach ($this->getConsumers() as $c) { |
|
196 | + $c->receive($event); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $app The app where this event is associated with |
|
202 | + * @param string $subject A short description of the event |
|
203 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
204 | + * @param string $message A longer description of the event |
|
205 | + * @param array $messageParams Array with parameters that are filled in the message |
|
206 | + * @param string $file The file including path where this event is associated with |
|
207 | + * @param string $link A link where this event is associated with |
|
208 | + * @param string $affectedUser Recipient of the activity |
|
209 | + * @param string $type Type of the notification |
|
210 | + * @param int $priority Priority of the notification |
|
211 | + */ |
|
212 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
213 | + $event = $this->generateEvent(); |
|
214 | + $event->setApp($app) |
|
215 | + ->setType($type) |
|
216 | + ->setAffectedUser($affectedUser) |
|
217 | + ->setSubject($subject, $subjectParams) |
|
218 | + ->setMessage($message, $messageParams) |
|
219 | + ->setObject('', 0, $file) |
|
220 | + ->setLink($link); |
|
221 | + |
|
222 | + $this->publish($event); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
227 | + * activity consumers are actually requested |
|
228 | + * |
|
229 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
230 | + * |
|
231 | + * @param \Closure $callable |
|
232 | + */ |
|
233 | + public function registerConsumer(\Closure $callable) { |
|
234 | + $this->consumersClosures[] = $callable; |
|
235 | + $this->consumers = []; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
240 | + * activity consumers are actually requested |
|
241 | + * |
|
242 | + * $callable has to return an instance of OCA\Activity\IExtension |
|
243 | + * |
|
244 | + * @param \Closure $callable |
|
245 | + */ |
|
246 | + public function registerExtension(\Closure $callable) { |
|
247 | + $this->extensionsClosures[] = $callable; |
|
248 | + $this->extensions = []; |
|
249 | + } |
|
250 | + |
|
251 | + /** @var string[] */ |
|
252 | + protected $filterClasses = []; |
|
253 | + |
|
254 | + /** @var IFilter[] */ |
|
255 | + protected $filters = []; |
|
256 | + |
|
257 | + /** @var bool */ |
|
258 | + protected $loadedLegacyFilters = false; |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
262 | + * @return void |
|
263 | + */ |
|
264 | + public function registerFilter($filter) { |
|
265 | + $this->filterClasses[$filter] = false; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return IFilter[] |
|
270 | + * @throws \InvalidArgumentException |
|
271 | + */ |
|
272 | + public function getFilters() { |
|
273 | + if (!$this->loadedLegacyFilters) { |
|
274 | + $legacyFilters = $this->getNavigation(); |
|
275 | + |
|
276 | + foreach ($legacyFilters['top'] as $filter => $data) { |
|
277 | + $this->filters[$filter] = new LegacyFilter( |
|
278 | + $this, $filter, $data['name'], true |
|
279 | + ); |
|
280 | + } |
|
281 | + |
|
282 | + foreach ($legacyFilters['apps'] as $filter => $data) { |
|
283 | + $this->filters[$filter] = new LegacyFilter( |
|
284 | + $this, $filter, $data['name'], false |
|
285 | + ); |
|
286 | + } |
|
287 | + $this->loadedLegacyFilters = true; |
|
288 | + } |
|
289 | + |
|
290 | + foreach ($this->filterClasses as $class => $false) { |
|
291 | + /** @var IFilter $filter */ |
|
292 | + $filter = \OC::$server->query($class); |
|
293 | + |
|
294 | + if (!$filter instanceof IFilter) { |
|
295 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
296 | + } |
|
297 | + |
|
298 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
299 | + |
|
300 | + unset($this->filterClasses[$class]); |
|
301 | + } |
|
302 | + return $this->filters; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @param string $id |
|
307 | + * @return IFilter |
|
308 | + * @throws \InvalidArgumentException when the filter was not found |
|
309 | + * @since 11.0.0 |
|
310 | + */ |
|
311 | + public function getFilterById($id) { |
|
312 | + $filters = $this->getFilters(); |
|
313 | + |
|
314 | + if (isset($filters[$id])) { |
|
315 | + return $filters[$id]; |
|
316 | + } |
|
317 | + |
|
318 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
319 | + } |
|
320 | + |
|
321 | + /** @var string[] */ |
|
322 | + protected $providerClasses = []; |
|
323 | + |
|
324 | + /** @var IProvider[] */ |
|
325 | + protected $providers = []; |
|
326 | + |
|
327 | + /** |
|
328 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
329 | + * @return void |
|
330 | + */ |
|
331 | + public function registerProvider($provider) { |
|
332 | + $this->providerClasses[$provider] = false; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * @return IProvider[] |
|
337 | + * @throws \InvalidArgumentException |
|
338 | + */ |
|
339 | + public function getProviders() { |
|
340 | + foreach ($this->providerClasses as $class => $false) { |
|
341 | + /** @var IProvider $provider */ |
|
342 | + $provider = \OC::$server->query($class); |
|
343 | + |
|
344 | + if (!$provider instanceof IProvider) { |
|
345 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
346 | + } |
|
347 | + |
|
348 | + $this->providers[] = $provider; |
|
349 | + |
|
350 | + unset($this->providerClasses[$class]); |
|
351 | + } |
|
352 | + return $this->providers; |
|
353 | + } |
|
354 | + |
|
355 | + /** @var string[] */ |
|
356 | + protected $settingsClasses = []; |
|
357 | + |
|
358 | + /** @var ISetting[] */ |
|
359 | + protected $settings = []; |
|
360 | + |
|
361 | + /** @var bool */ |
|
362 | + protected $loadedLegacyTypes = false; |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
366 | + * @return void |
|
367 | + */ |
|
368 | + public function registerSetting($setting) { |
|
369 | + $this->settingsClasses[$setting] = false; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @return ISetting[] |
|
374 | + * @throws \InvalidArgumentException |
|
375 | + */ |
|
376 | + public function getSettings() { |
|
377 | + if (!$this->loadedLegacyTypes) { |
|
378 | + $l = \OC::$server->getL10N('core'); |
|
379 | + $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
380 | + $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
381 | + $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
382 | + foreach ($legacyTypes as $type => $data) { |
|
383 | + if (is_string($data)) { |
|
384 | + $desc = $data; |
|
385 | + $canChangeStream = true; |
|
386 | + $canChangeMail = true; |
|
387 | + } else { |
|
388 | + $desc = $data['desc']; |
|
389 | + $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
390 | + $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
391 | + } |
|
392 | + |
|
393 | + $this->settings[$type] = new LegacySetting( |
|
394 | + $type, $desc, |
|
395 | + $canChangeStream, in_array($type, $streamTypes), |
|
396 | + $canChangeMail, in_array($type, $mailTypes) |
|
397 | + ); |
|
398 | + } |
|
399 | + $this->loadedLegacyTypes = true; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ($this->settingsClasses as $class => $false) { |
|
403 | + /** @var ISetting $setting */ |
|
404 | + $setting = \OC::$server->query($class); |
|
405 | + |
|
406 | + if (!$setting instanceof ISetting) { |
|
407 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
408 | + } |
|
409 | + |
|
410 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
411 | + |
|
412 | + unset($this->settingsClasses[$class]); |
|
413 | + } |
|
414 | + return $this->settings; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * @param string $id |
|
419 | + * @return ISetting |
|
420 | + * @throws \InvalidArgumentException when the setting was not found |
|
421 | + * @since 11.0.0 |
|
422 | + */ |
|
423 | + public function getSettingById($id) { |
|
424 | + $settings = $this->getSettings(); |
|
425 | + |
|
426 | + if (isset($settings[$id])) { |
|
427 | + return $settings[$id]; |
|
428 | + } |
|
429 | + |
|
430 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param string $type |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function getTypeIcon($type) { |
|
438 | + if (isset($this->typeIcons[$type])) { |
|
439 | + return $this->typeIcons[$type]; |
|
440 | + } |
|
441 | + |
|
442 | + foreach ($this->getExtensions() as $c) { |
|
443 | + $icon = $c->getTypeIcon($type); |
|
444 | + if (is_string($icon)) { |
|
445 | + $this->typeIcons[$type] = $icon; |
|
446 | + return $icon; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + $this->typeIcons[$type] = ''; |
|
451 | + return ''; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @param string $type |
|
456 | + * @param string $id |
|
457 | + */ |
|
458 | + public function setFormattingObject($type, $id) { |
|
459 | + $this->formattingObjectType = $type; |
|
460 | + $this->formattingObjectId = (string) $id; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function isFormattingFilteredObject() { |
|
467 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
468 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
469 | + && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
474 | + */ |
|
475 | + public function setRequirePNG($status) { |
|
476 | + $this->requirePNG = $status; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @return bool |
|
481 | + */ |
|
482 | + public function getRequirePNG() { |
|
483 | + return $this->requirePNG; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $app |
|
488 | + * @param string $text |
|
489 | + * @param array $params |
|
490 | + * @param boolean $stripPath |
|
491 | + * @param boolean $highlightParams |
|
492 | + * @param string $languageCode |
|
493 | + * @return string|false |
|
494 | + */ |
|
495 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
496 | + foreach ($this->getExtensions() as $c) { |
|
497 | + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
498 | + if (is_string($translation)) { |
|
499 | + return $translation; |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + return false; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @param string $app |
|
508 | + * @param string $text |
|
509 | + * @return array|false |
|
510 | + */ |
|
511 | + public function getSpecialParameterList($app, $text) { |
|
512 | + if (isset($this->specialParameters[$app][$text])) { |
|
513 | + return $this->specialParameters[$app][$text]; |
|
514 | + } |
|
515 | + |
|
516 | + if (!isset($this->specialParameters[$app])) { |
|
517 | + $this->specialParameters[$app] = array(); |
|
518 | + } |
|
519 | + |
|
520 | + foreach ($this->getExtensions() as $c) { |
|
521 | + $specialParameter = $c->getSpecialParameterList($app, $text); |
|
522 | + if (is_array($specialParameter)) { |
|
523 | + $this->specialParameters[$app][$text] = $specialParameter; |
|
524 | + return $specialParameter; |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + $this->specialParameters[$app][$text] = false; |
|
529 | + return false; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @param array $activity |
|
534 | + * @return integer|false |
|
535 | + */ |
|
536 | + public function getGroupParameter($activity) { |
|
537 | + foreach ($this->getExtensions() as $c) { |
|
538 | + $parameter = $c->getGroupParameter($activity); |
|
539 | + if ($parameter !== false) { |
|
540 | + return $parameter; |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + return false; |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the user we need to use |
|
549 | + * |
|
550 | + * @param string|null $currentUserId |
|
551 | + * @throws \UnexpectedValueException If the user is invalid |
|
552 | + */ |
|
553 | + public function setCurrentUserId($currentUserId) { |
|
554 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
555 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
556 | + } |
|
557 | + $this->currentUserId = $currentUserId; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Get the user we need to use |
|
562 | + * |
|
563 | + * Either the user is logged in, or we try to get it from the token |
|
564 | + * |
|
565 | + * @return string |
|
566 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
567 | + */ |
|
568 | + public function getCurrentUserId() { |
|
569 | + if ($this->currentUserId !== null) { |
|
570 | + return $this->currentUserId; |
|
571 | + } else if (!$this->session->isLoggedIn()) { |
|
572 | + return $this->getUserFromToken(); |
|
573 | + } else { |
|
574 | + return $this->session->getUser()->getUID(); |
|
575 | + } |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Get the user for the token |
|
580 | + * |
|
581 | + * @return string |
|
582 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
583 | + */ |
|
584 | + protected function getUserFromToken() { |
|
585 | + $token = (string) $this->request->getParam('token', ''); |
|
586 | + if (strlen($token) !== 30) { |
|
587 | + throw new \UnexpectedValueException('The token is invalid'); |
|
588 | + } |
|
589 | + |
|
590 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
591 | + |
|
592 | + if (count($users) !== 1) { |
|
593 | + // No unique user found |
|
594 | + throw new \UnexpectedValueException('The token is invalid'); |
|
595 | + } |
|
596 | + |
|
597 | + // Token found login as that user |
|
598 | + return array_shift($users); |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * @return array |
|
603 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
604 | + */ |
|
605 | + public function getNavigation() { |
|
606 | + $entries = array( |
|
607 | + 'apps' => array(), |
|
608 | + 'top' => array(), |
|
609 | + ); |
|
610 | + foreach ($this->getExtensions() as $c) { |
|
611 | + $additionalEntries = $c->getNavigation(); |
|
612 | + if (is_array($additionalEntries)) { |
|
613 | + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
614 | + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
615 | + } |
|
616 | + } |
|
617 | + |
|
618 | + return $entries; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * @param string $filterValue |
|
623 | + * @return boolean |
|
624 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
625 | + */ |
|
626 | + public function isFilterValid($filterValue) { |
|
627 | + if (isset($this->validFilters[$filterValue])) { |
|
628 | + return $this->validFilters[$filterValue]; |
|
629 | + } |
|
630 | + |
|
631 | + foreach ($this->getExtensions() as $c) { |
|
632 | + if ($c->isFilterValid($filterValue) === true) { |
|
633 | + $this->validFilters[$filterValue] = true; |
|
634 | + return true; |
|
635 | + } |
|
636 | + } |
|
637 | + |
|
638 | + $this->validFilters[$filterValue] = false; |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * @param array $types |
|
644 | + * @param string $filter |
|
645 | + * @return array |
|
646 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
647 | + */ |
|
648 | + public function filterNotificationTypes($types, $filter) { |
|
649 | + if (!$this->isFilterValid($filter)) { |
|
650 | + return $types; |
|
651 | + } |
|
652 | + |
|
653 | + foreach ($this->getExtensions() as $c) { |
|
654 | + $result = $c->filterNotificationTypes($types, $filter); |
|
655 | + if (is_array($result)) { |
|
656 | + $types = $result; |
|
657 | + } |
|
658 | + } |
|
659 | + return $types; |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * @param string $filter |
|
664 | + * @return array |
|
665 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
666 | + */ |
|
667 | + public function getQueryForFilter($filter) { |
|
668 | + if (!$this->isFilterValid($filter)) { |
|
669 | + return [null, null]; |
|
670 | + } |
|
671 | + |
|
672 | + $conditions = array(); |
|
673 | + $parameters = array(); |
|
674 | + |
|
675 | + foreach ($this->getExtensions() as $c) { |
|
676 | + $result = $c->getQueryForFilter($filter); |
|
677 | + if (is_array($result)) { |
|
678 | + list($condition, $parameter) = $result; |
|
679 | + if ($condition && is_array($parameter)) { |
|
680 | + $conditions[] = $condition; |
|
681 | + $parameters = array_merge($parameters, $parameter); |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + if (empty($conditions)) { |
|
687 | + return array(null, null); |
|
688 | + } |
|
689 | + |
|
690 | + return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Will return additional notification types as specified by other apps |
|
695 | + * |
|
696 | + * @param string $languageCode |
|
697 | + * @return array |
|
698 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
699 | + */ |
|
700 | + public function getNotificationTypes($languageCode) { |
|
701 | + $notificationTypes = $sharingNotificationTypes = []; |
|
702 | + foreach ($this->getExtensions() as $c) { |
|
703 | + $result = $c->getNotificationTypes($languageCode); |
|
704 | + if (is_array($result)) { |
|
705 | + $notificationTypes = array_merge($notificationTypes, $result); |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + return array_merge($sharingNotificationTypes, $notificationTypes); |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * @param string $method |
|
714 | + * @return array |
|
715 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
716 | + */ |
|
717 | + public function getDefaultTypes($method) { |
|
718 | + $defaultTypes = array(); |
|
719 | + foreach ($this->getExtensions() as $c) { |
|
720 | + $types = $c->getDefaultTypes($method); |
|
721 | + if (is_array($types)) { |
|
722 | + $defaultTypes = array_merge($types, $defaultTypes); |
|
723 | + } |
|
724 | + } |
|
725 | + return $defaultTypes; |
|
726 | + } |
|
727 | 727 | } |
@@ -25,99 +25,99 @@ |
||
25 | 25 | |
26 | 26 | class LegacySetting implements ISetting { |
27 | 27 | |
28 | - /** @var string */ |
|
29 | - protected $identifier; |
|
30 | - /** @var string */ |
|
31 | - protected $name; |
|
32 | - /** @var bool */ |
|
33 | - protected $canChangeStream; |
|
34 | - /** @var bool */ |
|
35 | - protected $isDefaultEnabledStream; |
|
36 | - /** @var bool */ |
|
37 | - protected $canChangeMail; |
|
38 | - /** @var bool */ |
|
39 | - protected $isDefaultEnabledMail; |
|
28 | + /** @var string */ |
|
29 | + protected $identifier; |
|
30 | + /** @var string */ |
|
31 | + protected $name; |
|
32 | + /** @var bool */ |
|
33 | + protected $canChangeStream; |
|
34 | + /** @var bool */ |
|
35 | + protected $isDefaultEnabledStream; |
|
36 | + /** @var bool */ |
|
37 | + protected $canChangeMail; |
|
38 | + /** @var bool */ |
|
39 | + protected $isDefaultEnabledMail; |
|
40 | 40 | |
41 | - /** |
|
42 | - * LegacySetting constructor. |
|
43 | - * |
|
44 | - * @param string $identifier |
|
45 | - * @param string $name |
|
46 | - * @param bool $canChangeStream |
|
47 | - * @param bool $isDefaultEnabledStream |
|
48 | - * @param bool $canChangeMail |
|
49 | - * @param bool $isDefaultEnabledMail |
|
50 | - */ |
|
51 | - public function __construct($identifier, |
|
52 | - $name, |
|
53 | - $canChangeStream, |
|
54 | - $isDefaultEnabledStream, |
|
55 | - $canChangeMail, |
|
56 | - $isDefaultEnabledMail) { |
|
57 | - $this->identifier = $identifier; |
|
58 | - $this->name = $name; |
|
59 | - $this->canChangeStream = $canChangeStream; |
|
60 | - $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | - $this->canChangeMail = $canChangeMail; |
|
62 | - $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | - } |
|
41 | + /** |
|
42 | + * LegacySetting constructor. |
|
43 | + * |
|
44 | + * @param string $identifier |
|
45 | + * @param string $name |
|
46 | + * @param bool $canChangeStream |
|
47 | + * @param bool $isDefaultEnabledStream |
|
48 | + * @param bool $canChangeMail |
|
49 | + * @param bool $isDefaultEnabledMail |
|
50 | + */ |
|
51 | + public function __construct($identifier, |
|
52 | + $name, |
|
53 | + $canChangeStream, |
|
54 | + $isDefaultEnabledStream, |
|
55 | + $canChangeMail, |
|
56 | + $isDefaultEnabledMail) { |
|
57 | + $this->identifier = $identifier; |
|
58 | + $this->name = $name; |
|
59 | + $this->canChangeStream = $canChangeStream; |
|
60 | + $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | + $this->canChangeMail = $canChangeMail; |
|
62 | + $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return string Lowercase a-z and underscore only identifier |
|
67 | - * @since 11.0.0 |
|
68 | - */ |
|
69 | - public function getIdentifier() { |
|
70 | - return $this->identifier; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return string Lowercase a-z and underscore only identifier |
|
67 | + * @since 11.0.0 |
|
68 | + */ |
|
69 | + public function getIdentifier() { |
|
70 | + return $this->identifier; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return string A translated string |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
73 | + /** |
|
74 | + * @return string A translated string |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return int whether the filter should be rather on the top or bottom of |
|
83 | - * the admin section. The filters are arranged in ascending order of the |
|
84 | - * priority values. It is required to return a value between 0 and 100. |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function getPriority() { |
|
88 | - return 70; |
|
89 | - } |
|
81 | + /** |
|
82 | + * @return int whether the filter should be rather on the top or bottom of |
|
83 | + * the admin section. The filters are arranged in ascending order of the |
|
84 | + * priority values. It is required to return a value between 0 and 100. |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function getPriority() { |
|
88 | + return 70; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return bool True when the option can be changed for the stream |
|
93 | - * @since 11.0.0 |
|
94 | - */ |
|
95 | - public function canChangeStream() { |
|
96 | - return $this->canChangeStream; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return bool True when the option can be changed for the stream |
|
93 | + * @since 11.0.0 |
|
94 | + */ |
|
95 | + public function canChangeStream() { |
|
96 | + return $this->canChangeStream; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return bool True when the option can be changed for the stream |
|
101 | - * @since 11.0.0 |
|
102 | - */ |
|
103 | - public function isDefaultEnabledStream() { |
|
104 | - return $this->isDefaultEnabledStream; |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return bool True when the option can be changed for the stream |
|
101 | + * @since 11.0.0 |
|
102 | + */ |
|
103 | + public function isDefaultEnabledStream() { |
|
104 | + return $this->isDefaultEnabledStream; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return bool True when the option can be changed for the mail |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function canChangeMail() { |
|
112 | - return $this->canChangeMail; |
|
113 | - } |
|
107 | + /** |
|
108 | + * @return bool True when the option can be changed for the mail |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function canChangeMail() { |
|
112 | + return $this->canChangeMail; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return bool True when the option can be changed for the stream |
|
117 | - * @since 11.0.0 |
|
118 | - */ |
|
119 | - public function isDefaultEnabledMail() { |
|
120 | - return $this->isDefaultEnabledMail; |
|
121 | - } |
|
115 | + /** |
|
116 | + * @return bool True when the option can be changed for the stream |
|
117 | + * @since 11.0.0 |
|
118 | + */ |
|
119 | + public function isDefaultEnabledMail() { |
|
120 | + return $this->isDefaultEnabledMail; |
|
121 | + } |
|
122 | 122 | } |
123 | 123 |
@@ -34,93 +34,93 @@ |
||
34 | 34 | */ |
35 | 35 | class CredentialsManager implements ICredentialsManager { |
36 | 36 | |
37 | - const DB_TABLE = 'credentials'; |
|
37 | + const DB_TABLE = 'credentials'; |
|
38 | 38 | |
39 | - /** @var ICrypto */ |
|
40 | - protected $crypto; |
|
39 | + /** @var ICrypto */ |
|
40 | + protected $crypto; |
|
41 | 41 | |
42 | - /** @var IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ICrypto $crypto |
|
47 | - * @param IDBConnection $dbConnection |
|
48 | - */ |
|
49 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | - $this->crypto = $crypto; |
|
51 | - $this->dbConnection = $dbConnection; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param ICrypto $crypto |
|
47 | + * @param IDBConnection $dbConnection |
|
48 | + */ |
|
49 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | + $this->crypto = $crypto; |
|
51 | + $this->dbConnection = $dbConnection; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Store a set of credentials |
|
56 | - * |
|
57 | - * @param string|null $userId Null for system-wide credentials |
|
58 | - * @param string $identifier |
|
59 | - * @param mixed $credentials |
|
60 | - */ |
|
61 | - public function store($userId, $identifier, $credentials) { |
|
62 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
54 | + /** |
|
55 | + * Store a set of credentials |
|
56 | + * |
|
57 | + * @param string|null $userId Null for system-wide credentials |
|
58 | + * @param string $identifier |
|
59 | + * @param mixed $credentials |
|
60 | + */ |
|
61 | + public function store($userId, $identifier, $credentials) { |
|
62 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
63 | 63 | |
64 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | - 'user' => $userId, |
|
66 | - 'identifier' => $identifier, |
|
67 | - ], [ |
|
68 | - 'credentials' => $value, |
|
69 | - ]); |
|
70 | - } |
|
64 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | + 'user' => $userId, |
|
66 | + 'identifier' => $identifier, |
|
67 | + ], [ |
|
68 | + 'credentials' => $value, |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Retrieve a set of credentials |
|
74 | - * |
|
75 | - * @param string|null $userId Null for system-wide credentials |
|
76 | - * @param string $identifier |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function retrieve($userId, $identifier) { |
|
80 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | - $qb->select('credentials') |
|
82 | - ->from(self::DB_TABLE) |
|
83 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | - ; |
|
86 | - $result = $qb->execute()->fetch(); |
|
72 | + /** |
|
73 | + * Retrieve a set of credentials |
|
74 | + * |
|
75 | + * @param string|null $userId Null for system-wide credentials |
|
76 | + * @param string $identifier |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function retrieve($userId, $identifier) { |
|
80 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | + $qb->select('credentials') |
|
82 | + ->from(self::DB_TABLE) |
|
83 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | + ; |
|
86 | + $result = $qb->execute()->fetch(); |
|
87 | 87 | |
88 | - if (!$result) { |
|
89 | - return null; |
|
90 | - } |
|
91 | - $value = $result['credentials']; |
|
88 | + if (!$result) { |
|
89 | + return null; |
|
90 | + } |
|
91 | + $value = $result['credentials']; |
|
92 | 92 | |
93 | - return json_decode($this->crypto->decrypt($value), true); |
|
94 | - } |
|
93 | + return json_decode($this->crypto->decrypt($value), true); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Delete a set of credentials |
|
98 | - * |
|
99 | - * @param string|null $userId Null for system-wide credentials |
|
100 | - * @param string $identifier |
|
101 | - * @return int rows removed |
|
102 | - */ |
|
103 | - public function delete($userId, $identifier) { |
|
104 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | - $qb->delete(self::DB_TABLE) |
|
106 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | - ; |
|
109 | - return $qb->execute(); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Delete a set of credentials |
|
98 | + * |
|
99 | + * @param string|null $userId Null for system-wide credentials |
|
100 | + * @param string $identifier |
|
101 | + * @return int rows removed |
|
102 | + */ |
|
103 | + public function delete($userId, $identifier) { |
|
104 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | + $qb->delete(self::DB_TABLE) |
|
106 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | + ; |
|
109 | + return $qb->execute(); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Erase all credentials stored for a user |
|
114 | - * |
|
115 | - * @param string $userId |
|
116 | - * @return int rows removed |
|
117 | - */ |
|
118 | - public function erase($userId) { |
|
119 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | - $qb->delete(self::DB_TABLE) |
|
121 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | - ; |
|
123 | - return $qb->execute(); |
|
124 | - } |
|
112 | + /** |
|
113 | + * Erase all credentials stored for a user |
|
114 | + * |
|
115 | + * @param string $userId |
|
116 | + * @return int rows removed |
|
117 | + */ |
|
118 | + public function erase($userId) { |
|
119 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | + $qb->delete(self::DB_TABLE) |
|
121 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | + ; |
|
123 | + return $qb->execute(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -27,104 +27,104 @@ |
||
27 | 27 | use OCP\ICertificate; |
28 | 28 | |
29 | 29 | class Certificate implements ICertificate { |
30 | - protected $name; |
|
31 | - |
|
32 | - protected $commonName; |
|
33 | - |
|
34 | - protected $organization; |
|
35 | - |
|
36 | - protected $serial; |
|
37 | - |
|
38 | - protected $issueDate; |
|
39 | - |
|
40 | - protected $expireDate; |
|
41 | - |
|
42 | - protected $issuerName; |
|
43 | - |
|
44 | - protected $issuerOrganization; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $data base64 encoded certificate |
|
48 | - * @param string $name |
|
49 | - * @throws \Exception If the certificate could not get parsed |
|
50 | - */ |
|
51 | - public function __construct($data, $name) { |
|
52 | - $this->name = $name; |
|
53 | - $gmt = new \DateTimeZone('GMT'); |
|
54 | - |
|
55 | - // If string starts with "file://" ignore the certificate |
|
56 | - $query = 'file://'; |
|
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | - throw new \Exception('Certificate could not get parsed.'); |
|
59 | - } |
|
60 | - |
|
61 | - $info = openssl_x509_parse($data); |
|
62 | - if(!is_array($info)) { |
|
63 | - throw new \Exception('Certificate could not get parsed.'); |
|
64 | - } |
|
65 | - |
|
66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string|null |
|
83 | - */ |
|
84 | - public function getCommonName() { |
|
85 | - return $this->commonName; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getOrganization() { |
|
92 | - return $this->organization; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return \DateTime |
|
97 | - */ |
|
98 | - public function getIssueDate() { |
|
99 | - return $this->issueDate; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return \DateTime |
|
104 | - */ |
|
105 | - public function getExpireDate() { |
|
106 | - return $this->expireDate; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isExpired() { |
|
113 | - $now = new \DateTime(); |
|
114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string|null |
|
119 | - */ |
|
120 | - public function getIssuerName() { |
|
121 | - return $this->issuerName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getIssuerOrganization() { |
|
128 | - return $this->issuerOrganization; |
|
129 | - } |
|
30 | + protected $name; |
|
31 | + |
|
32 | + protected $commonName; |
|
33 | + |
|
34 | + protected $organization; |
|
35 | + |
|
36 | + protected $serial; |
|
37 | + |
|
38 | + protected $issueDate; |
|
39 | + |
|
40 | + protected $expireDate; |
|
41 | + |
|
42 | + protected $issuerName; |
|
43 | + |
|
44 | + protected $issuerOrganization; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $data base64 encoded certificate |
|
48 | + * @param string $name |
|
49 | + * @throws \Exception If the certificate could not get parsed |
|
50 | + */ |
|
51 | + public function __construct($data, $name) { |
|
52 | + $this->name = $name; |
|
53 | + $gmt = new \DateTimeZone('GMT'); |
|
54 | + |
|
55 | + // If string starts with "file://" ignore the certificate |
|
56 | + $query = 'file://'; |
|
57 | + if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | + throw new \Exception('Certificate could not get parsed.'); |
|
59 | + } |
|
60 | + |
|
61 | + $info = openssl_x509_parse($data); |
|
62 | + if(!is_array($info)) { |
|
63 | + throw new \Exception('Certificate could not get parsed.'); |
|
64 | + } |
|
65 | + |
|
66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string|null |
|
83 | + */ |
|
84 | + public function getCommonName() { |
|
85 | + return $this->commonName; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getOrganization() { |
|
92 | + return $this->organization; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return \DateTime |
|
97 | + */ |
|
98 | + public function getIssueDate() { |
|
99 | + return $this->issueDate; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return \DateTime |
|
104 | + */ |
|
105 | + public function getExpireDate() { |
|
106 | + return $this->expireDate; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isExpired() { |
|
113 | + $now = new \DateTime(); |
|
114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string|null |
|
119 | + */ |
|
120 | + public function getIssuerName() { |
|
121 | + return $this->issuerName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getIssuerOrganization() { |
|
128 | + return $this->issuerOrganization; |
|
129 | + } |
|
130 | 130 | } |
@@ -54,19 +54,19 @@ |
||
54 | 54 | |
55 | 55 | // If string starts with "file://" ignore the certificate |
56 | 56 | $query = 'file://'; |
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | 58 | throw new \Exception('Certificate could not get parsed.'); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $info = openssl_x509_parse($data); |
62 | - if(!is_array($info)) { |
|
62 | + if (!is_array($info)) { |
|
63 | 63 | throw new \Exception('Certificate could not get parsed.'); |
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
72 | 72 | } |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
68 | + if ($postFix !== '') { |
|
69 | + $postFix = '.'.ltrim($postFix, '.'); |
|
70 | 70 | $postFix = str_replace(['\\', '/'], '', $postFix); |
71 | 71 | $absolutePath .= '-'; |
72 | 72 | } |
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
74 | + return $absolutePath.$postFix; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | // If a postfix got specified sanitize it and create a postfixed |
93 | 93 | // temporary file |
94 | - if($postFix !== '') { |
|
94 | + if ($postFix !== '') { |
|
95 | 95 | $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
96 | 96 | touch($fileNameWithPostfix); |
97 | 97 | chmod($fileNameWithPostfix, 0600); |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | $this->current[] = $uniqueFileName; |
128 | 128 | |
129 | 129 | // Build a name without postfix |
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix); |
|
131 | 131 | mkdir($path, 0700); |
132 | 132 | $this->current[] = $path; |
133 | 133 | |
134 | - return $path . '/'; |
|
134 | + return $path.'/'; |
|
135 | 135 | } else { |
136 | 136 | $this->log->warning( |
137 | 137 | 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if ($dh) { |
191 | 191 | while (($file = readdir($dh)) !== false) { |
192 | 192 | if (substr($file, 0, 7) === self::TMP_PREFIX) { |
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
193 | + $path = $this->tmpBaseDir.'/'.$file; |
|
194 | 194 | $mtime = filemtime($path); |
195 | 195 | if ($mtime < $cutOfTime) { |
196 | 196 | $files[] = $path; |
@@ -34,246 +34,246 @@ |
||
34 | 34 | use OCP\ITempManager; |
35 | 35 | |
36 | 36 | class TempManager implements ITempManager { |
37 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | - protected $current = []; |
|
39 | - /** @var string i.e. /tmp on linux systems */ |
|
40 | - protected $tmpBaseDir; |
|
41 | - /** @var ILogger */ |
|
42 | - protected $log; |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
37 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | + protected $current = []; |
|
39 | + /** @var string i.e. /tmp on linux systems */ |
|
40 | + protected $tmpBaseDir; |
|
41 | + /** @var ILogger */ |
|
42 | + protected $log; |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | 45 | |
46 | - /** Prefix */ |
|
47 | - const TMP_PREFIX = 'oc_tmp_'; |
|
46 | + /** Prefix */ |
|
47 | + const TMP_PREFIX = 'oc_tmp_'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param \OCP\ILogger $logger |
|
51 | - * @param \OCP\IConfig $config |
|
52 | - */ |
|
53 | - public function __construct(ILogger $logger, IConfig $config) { |
|
54 | - $this->log = $logger; |
|
55 | - $this->config = $config; |
|
56 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param \OCP\ILogger $logger |
|
51 | + * @param \OCP\IConfig $config |
|
52 | + */ |
|
53 | + public function __construct(ILogger $logger, IConfig $config) { |
|
54 | + $this->log = $logger; |
|
55 | + $this->config = $config; |
|
56 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Builds the filename with suffix and removes potential dangerous characters |
|
61 | - * such as directory separators. |
|
62 | - * |
|
63 | - * @param string $absolutePath Absolute path to the file / folder |
|
64 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
70 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | - $absolutePath .= '-'; |
|
72 | - } |
|
59 | + /** |
|
60 | + * Builds the filename with suffix and removes potential dangerous characters |
|
61 | + * such as directory separators. |
|
62 | + * |
|
63 | + * @param string $absolutePath Absolute path to the file / folder |
|
64 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | + if($postFix !== '') { |
|
69 | + $postFix = '.' . ltrim($postFix, '.'); |
|
70 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | + $absolutePath .= '-'; |
|
72 | + } |
|
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
75 | - } |
|
74 | + return $absolutePath . $postFix; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Create a temporary file and return the path |
|
79 | - * |
|
80 | - * @param string $postFix Postfix appended to the temporary file name |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getTemporaryFile($postFix = '') { |
|
84 | - if (is_writable($this->tmpBaseDir)) { |
|
85 | - // To create an unique file and prevent the risk of race conditions |
|
86 | - // or duplicated temporary files by other means such as collisions |
|
87 | - // we need to create the file using `tempnam` and append a possible |
|
88 | - // postfix to it later |
|
89 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | - $this->current[] = $file; |
|
77 | + /** |
|
78 | + * Create a temporary file and return the path |
|
79 | + * |
|
80 | + * @param string $postFix Postfix appended to the temporary file name |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getTemporaryFile($postFix = '') { |
|
84 | + if (is_writable($this->tmpBaseDir)) { |
|
85 | + // To create an unique file and prevent the risk of race conditions |
|
86 | + // or duplicated temporary files by other means such as collisions |
|
87 | + // we need to create the file using `tempnam` and append a possible |
|
88 | + // postfix to it later |
|
89 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | + $this->current[] = $file; |
|
91 | 91 | |
92 | - // If a postfix got specified sanitize it and create a postfixed |
|
93 | - // temporary file |
|
94 | - if($postFix !== '') { |
|
95 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | - touch($fileNameWithPostfix); |
|
97 | - chmod($fileNameWithPostfix, 0600); |
|
98 | - $this->current[] = $fileNameWithPostfix; |
|
99 | - return $fileNameWithPostfix; |
|
100 | - } |
|
92 | + // If a postfix got specified sanitize it and create a postfixed |
|
93 | + // temporary file |
|
94 | + if($postFix !== '') { |
|
95 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | + touch($fileNameWithPostfix); |
|
97 | + chmod($fileNameWithPostfix, 0600); |
|
98 | + $this->current[] = $fileNameWithPostfix; |
|
99 | + return $fileNameWithPostfix; |
|
100 | + } |
|
101 | 101 | |
102 | - return $file; |
|
103 | - } else { |
|
104 | - $this->log->warning( |
|
105 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | - [ |
|
107 | - 'dir' => $this->tmpBaseDir, |
|
108 | - ] |
|
109 | - ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - } |
|
102 | + return $file; |
|
103 | + } else { |
|
104 | + $this->log->warning( |
|
105 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | + [ |
|
107 | + 'dir' => $this->tmpBaseDir, |
|
108 | + ] |
|
109 | + ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Create a temporary folder and return the path |
|
116 | - * |
|
117 | - * @param string $postFix Postfix appended to the temporary folder name |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getTemporaryFolder($postFix = '') { |
|
121 | - if (is_writable($this->tmpBaseDir)) { |
|
122 | - // To create an unique directory and prevent the risk of race conditions |
|
123 | - // or duplicated temporary files by other means such as collisions |
|
124 | - // we need to create the file using `tempnam` and append a possible |
|
125 | - // postfix to it later |
|
126 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | - $this->current[] = $uniqueFileName; |
|
114 | + /** |
|
115 | + * Create a temporary folder and return the path |
|
116 | + * |
|
117 | + * @param string $postFix Postfix appended to the temporary folder name |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getTemporaryFolder($postFix = '') { |
|
121 | + if (is_writable($this->tmpBaseDir)) { |
|
122 | + // To create an unique directory and prevent the risk of race conditions |
|
123 | + // or duplicated temporary files by other means such as collisions |
|
124 | + // we need to create the file using `tempnam` and append a possible |
|
125 | + // postfix to it later |
|
126 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | + $this->current[] = $uniqueFileName; |
|
128 | 128 | |
129 | - // Build a name without postfix |
|
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | - mkdir($path, 0700); |
|
132 | - $this->current[] = $path; |
|
129 | + // Build a name without postfix |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | + mkdir($path, 0700); |
|
132 | + $this->current[] = $path; |
|
133 | 133 | |
134 | - return $path . '/'; |
|
135 | - } else { |
|
136 | - $this->log->warning( |
|
137 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | - [ |
|
139 | - 'dir' => $this->tmpBaseDir, |
|
140 | - ] |
|
141 | - ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - } |
|
134 | + return $path . '/'; |
|
135 | + } else { |
|
136 | + $this->log->warning( |
|
137 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | + [ |
|
139 | + 'dir' => $this->tmpBaseDir, |
|
140 | + ] |
|
141 | + ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Remove the temporary files and folders generated during this request |
|
148 | - */ |
|
149 | - public function clean() { |
|
150 | - $this->cleanFiles($this->current); |
|
151 | - } |
|
146 | + /** |
|
147 | + * Remove the temporary files and folders generated during this request |
|
148 | + */ |
|
149 | + public function clean() { |
|
150 | + $this->cleanFiles($this->current); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string[] $files |
|
155 | - */ |
|
156 | - protected function cleanFiles($files) { |
|
157 | - foreach ($files as $file) { |
|
158 | - if (file_exists($file)) { |
|
159 | - try { |
|
160 | - \OC_Helper::rmdirr($file); |
|
161 | - } catch (\UnexpectedValueException $ex) { |
|
162 | - $this->log->warning( |
|
163 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | - [ |
|
165 | - 'file' => $file, |
|
166 | - 'error' => $ex->getMessage(), |
|
167 | - ] |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
153 | + /** |
|
154 | + * @param string[] $files |
|
155 | + */ |
|
156 | + protected function cleanFiles($files) { |
|
157 | + foreach ($files as $file) { |
|
158 | + if (file_exists($file)) { |
|
159 | + try { |
|
160 | + \OC_Helper::rmdirr($file); |
|
161 | + } catch (\UnexpectedValueException $ex) { |
|
162 | + $this->log->warning( |
|
163 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | + [ |
|
165 | + 'file' => $file, |
|
166 | + 'error' => $ex->getMessage(), |
|
167 | + ] |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Remove old temporary files and folders that were failed to be cleaned |
|
176 | - */ |
|
177 | - public function cleanOld() { |
|
178 | - $this->cleanFiles($this->getOldFiles()); |
|
179 | - } |
|
174 | + /** |
|
175 | + * Remove old temporary files and folders that were failed to be cleaned |
|
176 | + */ |
|
177 | + public function cleanOld() { |
|
178 | + $this->cleanFiles($this->getOldFiles()); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get all temporary files and folders generated by oc older than an hour |
|
183 | - * |
|
184 | - * @return string[] |
|
185 | - */ |
|
186 | - protected function getOldFiles() { |
|
187 | - $cutOfTime = time() - 3600; |
|
188 | - $files = []; |
|
189 | - $dh = opendir($this->tmpBaseDir); |
|
190 | - if ($dh) { |
|
191 | - while (($file = readdir($dh)) !== false) { |
|
192 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
194 | - $mtime = filemtime($path); |
|
195 | - if ($mtime < $cutOfTime) { |
|
196 | - $files[] = $path; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - return $files; |
|
202 | - } |
|
181 | + /** |
|
182 | + * Get all temporary files and folders generated by oc older than an hour |
|
183 | + * |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | + protected function getOldFiles() { |
|
187 | + $cutOfTime = time() - 3600; |
|
188 | + $files = []; |
|
189 | + $dh = opendir($this->tmpBaseDir); |
|
190 | + if ($dh) { |
|
191 | + while (($file = readdir($dh)) !== false) { |
|
192 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | + $path = $this->tmpBaseDir . '/' . $file; |
|
194 | + $mtime = filemtime($path); |
|
195 | + if ($mtime < $cutOfTime) { |
|
196 | + $files[] = $path; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + return $files; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get the temporary base directory configured on the server |
|
206 | - * |
|
207 | - * @return string Path to the temporary directory or null |
|
208 | - * @throws \UnexpectedValueException |
|
209 | - */ |
|
210 | - public function getTempBaseDir() { |
|
211 | - if ($this->tmpBaseDir) { |
|
212 | - return $this->tmpBaseDir; |
|
213 | - } |
|
204 | + /** |
|
205 | + * Get the temporary base directory configured on the server |
|
206 | + * |
|
207 | + * @return string Path to the temporary directory or null |
|
208 | + * @throws \UnexpectedValueException |
|
209 | + */ |
|
210 | + public function getTempBaseDir() { |
|
211 | + if ($this->tmpBaseDir) { |
|
212 | + return $this->tmpBaseDir; |
|
213 | + } |
|
214 | 214 | |
215 | - $directories = []; |
|
216 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | - $directories[] = $temp; |
|
218 | - } |
|
219 | - if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | - $directories[] = $temp; |
|
221 | - } |
|
222 | - if ($temp = getenv('TMP')) { |
|
223 | - $directories[] = $temp; |
|
224 | - } |
|
225 | - if ($temp = getenv('TEMP')) { |
|
226 | - $directories[] = $temp; |
|
227 | - } |
|
228 | - if ($temp = getenv('TMPDIR')) { |
|
229 | - $directories[] = $temp; |
|
230 | - } |
|
231 | - if ($temp = sys_get_temp_dir()) { |
|
232 | - $directories[] = $temp; |
|
233 | - } |
|
215 | + $directories = []; |
|
216 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | + $directories[] = $temp; |
|
218 | + } |
|
219 | + if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | + $directories[] = $temp; |
|
221 | + } |
|
222 | + if ($temp = getenv('TMP')) { |
|
223 | + $directories[] = $temp; |
|
224 | + } |
|
225 | + if ($temp = getenv('TEMP')) { |
|
226 | + $directories[] = $temp; |
|
227 | + } |
|
228 | + if ($temp = getenv('TMPDIR')) { |
|
229 | + $directories[] = $temp; |
|
230 | + } |
|
231 | + if ($temp = sys_get_temp_dir()) { |
|
232 | + $directories[] = $temp; |
|
233 | + } |
|
234 | 234 | |
235 | - foreach ($directories as $dir) { |
|
236 | - if ($this->checkTemporaryDirectory($dir)) { |
|
237 | - return $dir; |
|
238 | - } |
|
239 | - } |
|
235 | + foreach ($directories as $dir) { |
|
236 | + if ($this->checkTemporaryDirectory($dir)) { |
|
237 | + return $dir; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - $temp = tempnam(dirname(__FILE__), ''); |
|
242 | - if (file_exists($temp)) { |
|
243 | - unlink($temp); |
|
244 | - return dirname($temp); |
|
245 | - } |
|
246 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | - } |
|
241 | + $temp = tempnam(dirname(__FILE__), ''); |
|
242 | + if (file_exists($temp)) { |
|
243 | + unlink($temp); |
|
244 | + return dirname($temp); |
|
245 | + } |
|
246 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Check if a temporary directory is ready for use |
|
251 | - * |
|
252 | - * @param mixed $directory |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - private function checkTemporaryDirectory($directory) { |
|
256 | - // suppress any possible errors caused by is_writable |
|
257 | - // checks missing or invalid path or characters, wrong permissions etc |
|
258 | - try { |
|
259 | - if (is_writable($directory)) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - } catch (\Exception $e) { |
|
263 | - } |
|
264 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | - ['dir' => $directory] |
|
266 | - ); |
|
267 | - return false; |
|
268 | - } |
|
249 | + /** |
|
250 | + * Check if a temporary directory is ready for use |
|
251 | + * |
|
252 | + * @param mixed $directory |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + private function checkTemporaryDirectory($directory) { |
|
256 | + // suppress any possible errors caused by is_writable |
|
257 | + // checks missing or invalid path or characters, wrong permissions etc |
|
258 | + try { |
|
259 | + if (is_writable($directory)) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + } catch (\Exception $e) { |
|
263 | + } |
|
264 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | + ['dir' => $directory] |
|
266 | + ); |
|
267 | + return false; |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Override the temporary base directory |
|
272 | - * |
|
273 | - * @param string $directory |
|
274 | - */ |
|
275 | - public function overrideTempBaseDir($directory) { |
|
276 | - $this->tmpBaseDir = $directory; |
|
277 | - } |
|
270 | + /** |
|
271 | + * Override the temporary base directory |
|
272 | + * |
|
273 | + * @param string $directory |
|
274 | + */ |
|
275 | + public function overrideTempBaseDir($directory) { |
|
276 | + $this->tmpBaseDir = $directory; |
|
277 | + } |
|
278 | 278 | |
279 | 279 | } |
@@ -28,74 +28,74 @@ |
||
28 | 28 | use OCP\ILogger; |
29 | 29 | |
30 | 30 | class ErrorHandler { |
31 | - /** @var ILogger */ |
|
32 | - private static $logger; |
|
31 | + /** @var ILogger */ |
|
32 | + private static $logger; |
|
33 | 33 | |
34 | - /** |
|
35 | - * remove password in URLs |
|
36 | - * @param string $msg |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected static function removePassword($msg) { |
|
40 | - return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
41 | - } |
|
34 | + /** |
|
35 | + * remove password in URLs |
|
36 | + * @param string $msg |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected static function removePassword($msg) { |
|
40 | + return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
41 | + } |
|
42 | 42 | |
43 | - public static function register($debug=false) { |
|
44 | - $handler = new ErrorHandler(); |
|
43 | + public static function register($debug=false) { |
|
44 | + $handler = new ErrorHandler(); |
|
45 | 45 | |
46 | - if ($debug) { |
|
47 | - set_error_handler(array($handler, 'onAll'), E_ALL); |
|
48 | - if (\OC::$CLI) { |
|
49 | - set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); |
|
50 | - } |
|
51 | - } else { |
|
52 | - set_error_handler(array($handler, 'onError')); |
|
53 | - } |
|
54 | - register_shutdown_function(array($handler, 'onShutdown')); |
|
55 | - set_exception_handler(array($handler, 'onException')); |
|
56 | - } |
|
46 | + if ($debug) { |
|
47 | + set_error_handler(array($handler, 'onAll'), E_ALL); |
|
48 | + if (\OC::$CLI) { |
|
49 | + set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); |
|
50 | + } |
|
51 | + } else { |
|
52 | + set_error_handler(array($handler, 'onError')); |
|
53 | + } |
|
54 | + register_shutdown_function(array($handler, 'onShutdown')); |
|
55 | + set_exception_handler(array($handler, 'onException')); |
|
56 | + } |
|
57 | 57 | |
58 | - public static function setLogger(ILogger $logger) { |
|
59 | - self::$logger = $logger; |
|
60 | - } |
|
58 | + public static function setLogger(ILogger $logger) { |
|
59 | + self::$logger = $logger; |
|
60 | + } |
|
61 | 61 | |
62 | - //Fatal errors handler |
|
63 | - public static function onShutdown() { |
|
64 | - $error = error_get_last(); |
|
65 | - if($error && self::$logger) { |
|
66 | - //ob_end_clean(); |
|
67 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
68 | - self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
|
69 | - } |
|
70 | - } |
|
62 | + //Fatal errors handler |
|
63 | + public static function onShutdown() { |
|
64 | + $error = error_get_last(); |
|
65 | + if($error && self::$logger) { |
|
66 | + //ob_end_clean(); |
|
67 | + $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
68 | + self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Uncaught exception handler |
|
74 | - * |
|
75 | - * @param \Exception $exception |
|
76 | - */ |
|
77 | - public static function onException($exception) { |
|
78 | - $class = get_class($exception); |
|
79 | - $msg = $exception->getMessage(); |
|
80 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
81 | - self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
82 | - } |
|
72 | + /** |
|
73 | + * Uncaught exception handler |
|
74 | + * |
|
75 | + * @param \Exception $exception |
|
76 | + */ |
|
77 | + public static function onException($exception) { |
|
78 | + $class = get_class($exception); |
|
79 | + $msg = $exception->getMessage(); |
|
80 | + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
81 | + self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
82 | + } |
|
83 | 83 | |
84 | - //Recoverable errors handler |
|
85 | - public static function onError($number, $message, $file, $line) { |
|
86 | - if (error_reporting() === 0) { |
|
87 | - return; |
|
88 | - } |
|
89 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
90 | - self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
|
84 | + //Recoverable errors handler |
|
85 | + public static function onError($number, $message, $file, $line) { |
|
86 | + if (error_reporting() === 0) { |
|
87 | + return; |
|
88 | + } |
|
89 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
90 | + self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - //Recoverable handler which catch all errors, warnings and notices |
|
95 | - public static function onAll($number, $message, $file, $line) { |
|
96 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
97 | - self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
|
94 | + //Recoverable handler which catch all errors, warnings and notices |
|
95 | + public static function onAll($number, $message, $file, $line) { |
|
96 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
97 | + self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
41 | 41 | } |
42 | 42 | |
43 | - public static function register($debug=false) { |
|
43 | + public static function register($debug = false) { |
|
44 | 44 | $handler = new ErrorHandler(); |
45 | 45 | |
46 | 46 | if ($debug) { |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | //Fatal errors handler |
63 | 63 | public static function onShutdown() { |
64 | 64 | $error = error_get_last(); |
65 | - if($error && self::$logger) { |
|
65 | + if ($error && self::$logger) { |
|
66 | 66 | //ob_end_clean(); |
67 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
67 | + $msg = $error['message'].' at '.$error['file'].'#'.$error['line']; |
|
68 | 68 | self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
69 | 69 | } |
70 | 70 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public static function onException($exception) { |
78 | 78 | $class = get_class($exception); |
79 | 79 | $msg = $exception->getMessage(); |
80 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
80 | + $msg = "$class: $msg at ".$exception->getFile().'#'.$exception->getLine(); |
|
81 | 81 | self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
82 | 82 | } |
83 | 83 | |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | if (error_reporting() === 0) { |
87 | 87 | return; |
88 | 88 | } |
89 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
89 | + $msg = $message.' at '.$file.'#'.$line; |
|
90 | 90 | self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | 94 | //Recoverable handler which catch all errors, warnings and notices |
95 | 95 | public static function onAll($number, $message, $file, $line) { |
96 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
96 | + $msg = $message.' at '.$file.'#'.$line; |
|
97 | 97 | self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
98 | 98 | |
99 | 99 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
60 | 60 | $this->initProviders(); |
61 | 61 | $results = array(); |
62 | - foreach($this->providers as $provider) { |
|
62 | + foreach ($this->providers as $provider) { |
|
63 | 63 | /** @var $provider Provider */ |
64 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
64 | + if (!$provider->providesResultsFor($inApps)) { |
|
65 | 65 | continue; |
66 | 66 | } |
67 | 67 | if ($provider instanceof PagedProvider) { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function removeProvider($provider) { |
97 | 97 | $this->registeredProviders = array_filter( |
98 | 98 | $this->registeredProviders, |
99 | - function ($element) use ($provider) { |
|
99 | + function($element) use ($provider) { |
|
100 | 100 | return ($element['class'] != $provider); |
101 | 101 | } |
102 | 102 | ); |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | * Create instances of all the registered search providers |
118 | 118 | */ |
119 | 119 | private function initProviders() { |
120 | - if( ! empty($this->providers) ) { |
|
120 | + if (!empty($this->providers)) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - foreach($this->registeredProviders as $provider) { |
|
123 | + foreach ($this->registeredProviders as $provider) { |
|
124 | 124 | $class = $provider['class']; |
125 | 125 | $options = $provider['options']; |
126 | 126 | $this->providers[] = new $class($options); |
@@ -34,86 +34,86 @@ |
||
34 | 34 | */ |
35 | 35 | class Search implements ISearch { |
36 | 36 | |
37 | - private $providers = array(); |
|
38 | - private $registeredProviders = array(); |
|
37 | + private $providers = array(); |
|
38 | + private $registeredProviders = array(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * Search all providers for $query |
|
42 | - * @param string $query |
|
43 | - * @param string[] $inApps optionally limit results to the given apps |
|
44 | - * @param int $page pages start at page 1 |
|
45 | - * @param int $size, 0 = all |
|
46 | - * @return array An array of OC\Search\Result's |
|
47 | - */ |
|
48 | - public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
49 | - $this->initProviders(); |
|
50 | - $results = array(); |
|
51 | - foreach($this->providers as $provider) { |
|
52 | - /** @var $provider Provider */ |
|
53 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - if ($provider instanceof PagedProvider) { |
|
57 | - $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
58 | - } else if ($provider instanceof Provider) { |
|
59 | - $providerResults = $provider->search($query); |
|
60 | - if ($size > 0) { |
|
61 | - $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
62 | - $results = array_merge($results, $slicedResults); |
|
63 | - } else { |
|
64 | - $results = array_merge($results, $providerResults); |
|
65 | - } |
|
66 | - } else { |
|
67 | - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
68 | - } |
|
69 | - } |
|
70 | - return $results; |
|
71 | - } |
|
40 | + /** |
|
41 | + * Search all providers for $query |
|
42 | + * @param string $query |
|
43 | + * @param string[] $inApps optionally limit results to the given apps |
|
44 | + * @param int $page pages start at page 1 |
|
45 | + * @param int $size, 0 = all |
|
46 | + * @return array An array of OC\Search\Result's |
|
47 | + */ |
|
48 | + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
49 | + $this->initProviders(); |
|
50 | + $results = array(); |
|
51 | + foreach($this->providers as $provider) { |
|
52 | + /** @var $provider Provider */ |
|
53 | + if ( ! $provider->providesResultsFor($inApps) ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + if ($provider instanceof PagedProvider) { |
|
57 | + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
58 | + } else if ($provider instanceof Provider) { |
|
59 | + $providerResults = $provider->search($query); |
|
60 | + if ($size > 0) { |
|
61 | + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
62 | + $results = array_merge($results, $slicedResults); |
|
63 | + } else { |
|
64 | + $results = array_merge($results, $providerResults); |
|
65 | + } |
|
66 | + } else { |
|
67 | + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
68 | + } |
|
69 | + } |
|
70 | + return $results; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Remove all registered search providers |
|
75 | - */ |
|
76 | - public function clearProviders() { |
|
77 | - $this->providers = array(); |
|
78 | - $this->registeredProviders = array(); |
|
79 | - } |
|
73 | + /** |
|
74 | + * Remove all registered search providers |
|
75 | + */ |
|
76 | + public function clearProviders() { |
|
77 | + $this->providers = array(); |
|
78 | + $this->registeredProviders = array(); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Remove one existing search provider |
|
83 | - * @param string $provider class name of a OC\Search\Provider |
|
84 | - */ |
|
85 | - public function removeProvider($provider) { |
|
86 | - $this->registeredProviders = array_filter( |
|
87 | - $this->registeredProviders, |
|
88 | - function ($element) use ($provider) { |
|
89 | - return ($element['class'] != $provider); |
|
90 | - } |
|
91 | - ); |
|
92 | - // force regeneration of providers on next search |
|
93 | - $this->providers = array(); |
|
94 | - } |
|
81 | + /** |
|
82 | + * Remove one existing search provider |
|
83 | + * @param string $provider class name of a OC\Search\Provider |
|
84 | + */ |
|
85 | + public function removeProvider($provider) { |
|
86 | + $this->registeredProviders = array_filter( |
|
87 | + $this->registeredProviders, |
|
88 | + function ($element) use ($provider) { |
|
89 | + return ($element['class'] != $provider); |
|
90 | + } |
|
91 | + ); |
|
92 | + // force regeneration of providers on next search |
|
93 | + $this->providers = array(); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Register a new search provider to search with |
|
98 | - * @param string $class class name of a OC\Search\Provider |
|
99 | - * @param array $options optional |
|
100 | - */ |
|
101 | - public function registerProvider($class, array $options = array()) { |
|
102 | - $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
103 | - } |
|
96 | + /** |
|
97 | + * Register a new search provider to search with |
|
98 | + * @param string $class class name of a OC\Search\Provider |
|
99 | + * @param array $options optional |
|
100 | + */ |
|
101 | + public function registerProvider($class, array $options = array()) { |
|
102 | + $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Create instances of all the registered search providers |
|
107 | - */ |
|
108 | - private function initProviders() { |
|
109 | - if( ! empty($this->providers) ) { |
|
110 | - return; |
|
111 | - } |
|
112 | - foreach($this->registeredProviders as $provider) { |
|
113 | - $class = $provider['class']; |
|
114 | - $options = $provider['options']; |
|
115 | - $this->providers[] = new $class($options); |
|
116 | - } |
|
117 | - } |
|
105 | + /** |
|
106 | + * Create instances of all the registered search providers |
|
107 | + */ |
|
108 | + private function initProviders() { |
|
109 | + if( ! empty($this->providers) ) { |
|
110 | + return; |
|
111 | + } |
|
112 | + foreach($this->registeredProviders as $provider) { |
|
113 | + $class = $provider['class']; |
|
114 | + $options = $provider['options']; |
|
115 | + $this->providers[] = new $class($options); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |