@@ -30,33 +30,33 @@ |
||
30 | 30 | |
31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * Server container |
|
35 | - * |
|
36 | - * @var IServerContainer |
|
37 | - */ |
|
38 | - private $serverContainer; |
|
33 | + /** |
|
34 | + * Server container |
|
35 | + * |
|
36 | + * @var IServerContainer |
|
37 | + */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for the comments manager factory |
|
42 | - * |
|
43 | - * @param IServerContainer $serverContainer server container |
|
44 | - */ |
|
45 | - public function __construct(IServerContainer $serverContainer) { |
|
46 | - $this->serverContainer = $serverContainer; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Constructor for the comments manager factory |
|
42 | + * |
|
43 | + * @param IServerContainer $serverContainer server container |
|
44 | + */ |
|
45 | + public function __construct(IServerContainer $serverContainer) { |
|
46 | + $this->serverContainer = $serverContainer; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * creates and returns an instance of the ICommentsManager |
|
51 | - * |
|
52 | - * @return ICommentsManager |
|
53 | - * @since 9.0.0 |
|
54 | - */ |
|
55 | - public function getManager() { |
|
56 | - return new Manager( |
|
57 | - $this->serverContainer->getDatabaseConnection(), |
|
58 | - $this->serverContainer->getLogger(), |
|
59 | - $this->serverContainer->getConfig() |
|
60 | - ); |
|
61 | - } |
|
49 | + /** |
|
50 | + * creates and returns an instance of the ICommentsManager |
|
51 | + * |
|
52 | + * @return ICommentsManager |
|
53 | + * @since 9.0.0 |
|
54 | + */ |
|
55 | + public function getManager() { |
|
56 | + return new Manager( |
|
57 | + $this->serverContainer->getDatabaseConnection(), |
|
58 | + $this->serverContainer->getLogger(), |
|
59 | + $this->serverContainer->getConfig() |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -24,16 +24,16 @@ |
||
24 | 24 | use Sabre\DAV\Tree; |
25 | 25 | |
26 | 26 | class CachingTree extends Tree { |
27 | - /** |
|
28 | - * Store a node in the cache |
|
29 | - * |
|
30 | - * @param Node $node |
|
31 | - * @param null|string $path |
|
32 | - */ |
|
33 | - public function cacheNode(Node $node, $path = null) { |
|
34 | - if (is_null($path)) { |
|
35 | - $path = $node->getPath(); |
|
36 | - } |
|
37 | - $this->cache[trim($path, '/')] = $node; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Store a node in the cache |
|
29 | + * |
|
30 | + * @param Node $node |
|
31 | + * @param null|string $path |
|
32 | + */ |
|
33 | + public function cacheNode(Node $node, $path = null) { |
|
34 | + if (is_null($path)) { |
|
35 | + $path = $node->getPath(); |
|
36 | + } |
|
37 | + $this->cache[trim($path, '/')] = $node; |
|
38 | + } |
|
39 | 39 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | * @see \Sabre\DAV\Server |
34 | 34 | */ |
35 | 35 | class Server extends \Sabre\DAV\Server { |
36 | - /** @var CachingTree $tree */ |
|
36 | + /** @var CachingTree $tree */ |
|
37 | 37 | |
38 | - /** |
|
39 | - * @see \Sabre\DAV\Server |
|
40 | - */ |
|
41 | - public function __construct($treeOrNode = null) { |
|
42 | - parent::__construct($treeOrNode); |
|
43 | - self::$exposeVersion = false; |
|
44 | - $this->enablePropfindDepthInfinity = true; |
|
45 | - } |
|
38 | + /** |
|
39 | + * @see \Sabre\DAV\Server |
|
40 | + */ |
|
41 | + public function __construct($treeOrNode = null) { |
|
42 | + parent::__construct($treeOrNode); |
|
43 | + self::$exposeVersion = false; |
|
44 | + $this->enablePropfindDepthInfinity = true; |
|
45 | + } |
|
46 | 46 | } |
@@ -362,77 +362,77 @@ |
||
362 | 362 | $policy .= "base-uri 'none';"; |
363 | 363 | $policy .= "manifest-src 'self';"; |
364 | 364 | |
365 | - if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) { |
|
365 | + if (!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) { |
|
366 | 366 | $policy .= 'script-src '; |
367 | - if(is_string($this->useJsNonce)) { |
|
367 | + if (is_string($this->useJsNonce)) { |
|
368 | 368 | $policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\''; |
369 | 369 | $allowedScriptDomains = array_flip($this->allowedScriptDomains); |
370 | 370 | unset($allowedScriptDomains['\'self\'']); |
371 | 371 | $this->allowedScriptDomains = array_flip($allowedScriptDomains); |
372 | - if(count($allowedScriptDomains) !== 0) { |
|
372 | + if (count($allowedScriptDomains) !== 0) { |
|
373 | 373 | $policy .= ' '; |
374 | 374 | } |
375 | 375 | } |
376 | - if(is_array($this->allowedScriptDomains)) { |
|
376 | + if (is_array($this->allowedScriptDomains)) { |
|
377 | 377 | $policy .= implode(' ', $this->allowedScriptDomains); |
378 | 378 | } |
379 | - if($this->inlineScriptAllowed) { |
|
379 | + if ($this->inlineScriptAllowed) { |
|
380 | 380 | $policy .= ' \'unsafe-inline\''; |
381 | 381 | } |
382 | - if($this->evalScriptAllowed) { |
|
382 | + if ($this->evalScriptAllowed) { |
|
383 | 383 | $policy .= ' \'unsafe-eval\''; |
384 | 384 | } |
385 | 385 | $policy .= ';'; |
386 | 386 | } |
387 | 387 | |
388 | - if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) { |
|
388 | + if (!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) { |
|
389 | 389 | $policy .= 'style-src '; |
390 | - if(is_array($this->allowedStyleDomains)) { |
|
390 | + if (is_array($this->allowedStyleDomains)) { |
|
391 | 391 | $policy .= implode(' ', $this->allowedStyleDomains); |
392 | 392 | } |
393 | - if($this->inlineStyleAllowed) { |
|
393 | + if ($this->inlineStyleAllowed) { |
|
394 | 394 | $policy .= ' \'unsafe-inline\''; |
395 | 395 | } |
396 | 396 | $policy .= ';'; |
397 | 397 | } |
398 | 398 | |
399 | - if(!empty($this->allowedImageDomains)) { |
|
400 | - $policy .= 'img-src ' . implode(' ', $this->allowedImageDomains); |
|
399 | + if (!empty($this->allowedImageDomains)) { |
|
400 | + $policy .= 'img-src '.implode(' ', $this->allowedImageDomains); |
|
401 | 401 | $policy .= ';'; |
402 | 402 | } |
403 | 403 | |
404 | - if(!empty($this->allowedFontDomains)) { |
|
405 | - $policy .= 'font-src ' . implode(' ', $this->allowedFontDomains); |
|
404 | + if (!empty($this->allowedFontDomains)) { |
|
405 | + $policy .= 'font-src '.implode(' ', $this->allowedFontDomains); |
|
406 | 406 | $policy .= ';'; |
407 | 407 | } |
408 | 408 | |
409 | - if(!empty($this->allowedConnectDomains)) { |
|
410 | - $policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains); |
|
409 | + if (!empty($this->allowedConnectDomains)) { |
|
410 | + $policy .= 'connect-src '.implode(' ', $this->allowedConnectDomains); |
|
411 | 411 | $policy .= ';'; |
412 | 412 | } |
413 | 413 | |
414 | - if(!empty($this->allowedMediaDomains)) { |
|
415 | - $policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains); |
|
414 | + if (!empty($this->allowedMediaDomains)) { |
|
415 | + $policy .= 'media-src '.implode(' ', $this->allowedMediaDomains); |
|
416 | 416 | $policy .= ';'; |
417 | 417 | } |
418 | 418 | |
419 | - if(!empty($this->allowedObjectDomains)) { |
|
420 | - $policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains); |
|
419 | + if (!empty($this->allowedObjectDomains)) { |
|
420 | + $policy .= 'object-src '.implode(' ', $this->allowedObjectDomains); |
|
421 | 421 | $policy .= ';'; |
422 | 422 | } |
423 | 423 | |
424 | - if(!empty($this->allowedFrameDomains)) { |
|
425 | - $policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains); |
|
424 | + if (!empty($this->allowedFrameDomains)) { |
|
425 | + $policy .= 'frame-src '.implode(' ', $this->allowedFrameDomains); |
|
426 | 426 | $policy .= ';'; |
427 | 427 | } |
428 | 428 | |
429 | - if(!empty($this->allowedChildSrcDomains)) { |
|
430 | - $policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains); |
|
429 | + if (!empty($this->allowedChildSrcDomains)) { |
|
430 | + $policy .= 'child-src '.implode(' ', $this->allowedChildSrcDomains); |
|
431 | 431 | $policy .= ';'; |
432 | 432 | } |
433 | 433 | |
434 | - if(!empty($this->allowedFrameAncestors)) { |
|
435 | - $policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors); |
|
434 | + if (!empty($this->allowedFrameAncestors)) { |
|
435 | + $policy .= 'frame-ancestors '.implode(' ', $this->allowedFrameAncestors); |
|
436 | 436 | $policy .= ';'; |
437 | 437 | } |
438 | 438 |
@@ -34,408 +34,408 @@ |
||
34 | 34 | * @since 9.0.0 |
35 | 35 | */ |
36 | 36 | class EmptyContentSecurityPolicy { |
37 | - /** @var bool Whether inline JS snippets are allowed */ |
|
38 | - protected $inlineScriptAllowed = null; |
|
39 | - /** @var string Whether JS nonces should be used */ |
|
40 | - protected $useJsNonce = null; |
|
41 | - /** |
|
42 | - * @var bool Whether eval in JS scripts is allowed |
|
43 | - * TODO: Disallow per default |
|
44 | - * @link https://github.com/owncloud/core/issues/11925 |
|
45 | - */ |
|
46 | - protected $evalScriptAllowed = null; |
|
47 | - /** @var array Domains from which scripts can get loaded */ |
|
48 | - protected $allowedScriptDomains = null; |
|
49 | - /** |
|
50 | - * @var bool Whether inline CSS is allowed |
|
51 | - * TODO: Disallow per default |
|
52 | - * @link https://github.com/owncloud/core/issues/13458 |
|
53 | - */ |
|
54 | - protected $inlineStyleAllowed = null; |
|
55 | - /** @var array Domains from which CSS can get loaded */ |
|
56 | - protected $allowedStyleDomains = null; |
|
57 | - /** @var array Domains from which images can get loaded */ |
|
58 | - protected $allowedImageDomains = null; |
|
59 | - /** @var array Domains to which connections can be done */ |
|
60 | - protected $allowedConnectDomains = null; |
|
61 | - /** @var array Domains from which media elements can be loaded */ |
|
62 | - protected $allowedMediaDomains = null; |
|
63 | - /** @var array Domains from which object elements can be loaded */ |
|
64 | - protected $allowedObjectDomains = null; |
|
65 | - /** @var array Domains from which iframes can be loaded */ |
|
66 | - protected $allowedFrameDomains = null; |
|
67 | - /** @var array Domains from which fonts can be loaded */ |
|
68 | - protected $allowedFontDomains = null; |
|
69 | - /** @var array Domains from which web-workers and nested browsing content can load elements */ |
|
70 | - protected $allowedChildSrcDomains = null; |
|
71 | - /** @var array Domains which can embed this Nextcloud instance */ |
|
72 | - protected $allowedFrameAncestors = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * Whether inline JavaScript snippets are allowed or forbidden |
|
76 | - * @param bool $state |
|
77 | - * @return $this |
|
78 | - * @since 8.1.0 |
|
79 | - * @deprecated 10.0 CSP tokens are now used |
|
80 | - */ |
|
81 | - public function allowInlineScript($state = false) { |
|
82 | - $this->inlineScriptAllowed = $state; |
|
83 | - return $this; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Use the according JS nonce |
|
88 | - * |
|
89 | - * @param string $nonce |
|
90 | - * @return $this |
|
91 | - * @since 11.0.0 |
|
92 | - */ |
|
93 | - public function useJsNonce($nonce) { |
|
94 | - $this->useJsNonce = $nonce; |
|
95 | - return $this; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Whether eval in JavaScript is allowed or forbidden |
|
100 | - * @param bool $state |
|
101 | - * @return $this |
|
102 | - * @since 8.1.0 |
|
103 | - */ |
|
104 | - public function allowEvalScript($state = true) { |
|
105 | - $this->evalScriptAllowed = $state; |
|
106 | - return $this; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Allows to execute JavaScript files from a specific domain. Use * to |
|
111 | - * allow JavaScript from all domains. |
|
112 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
113 | - * @return $this |
|
114 | - * @since 8.1.0 |
|
115 | - */ |
|
116 | - public function addAllowedScriptDomain($domain) { |
|
117 | - $this->allowedScriptDomains[] = $domain; |
|
118 | - return $this; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Remove the specified allowed script domain from the allowed domains. |
|
123 | - * |
|
124 | - * @param string $domain |
|
125 | - * @return $this |
|
126 | - * @since 8.1.0 |
|
127 | - */ |
|
128 | - public function disallowScriptDomain($domain) { |
|
129 | - $this->allowedScriptDomains = array_diff($this->allowedScriptDomains, [$domain]); |
|
130 | - return $this; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Whether inline CSS snippets are allowed or forbidden |
|
135 | - * @param bool $state |
|
136 | - * @return $this |
|
137 | - * @since 8.1.0 |
|
138 | - */ |
|
139 | - public function allowInlineStyle($state = true) { |
|
140 | - $this->inlineStyleAllowed = $state; |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Allows to execute CSS files from a specific domain. Use * to allow |
|
146 | - * CSS from all domains. |
|
147 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
148 | - * @return $this |
|
149 | - * @since 8.1.0 |
|
150 | - */ |
|
151 | - public function addAllowedStyleDomain($domain) { |
|
152 | - $this->allowedStyleDomains[] = $domain; |
|
153 | - return $this; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Remove the specified allowed style domain from the allowed domains. |
|
158 | - * |
|
159 | - * @param string $domain |
|
160 | - * @return $this |
|
161 | - * @since 8.1.0 |
|
162 | - */ |
|
163 | - public function disallowStyleDomain($domain) { |
|
164 | - $this->allowedStyleDomains = array_diff($this->allowedStyleDomains, [$domain]); |
|
165 | - return $this; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Allows using fonts from a specific domain. Use * to allow |
|
170 | - * fonts from all domains. |
|
171 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
172 | - * @return $this |
|
173 | - * @since 8.1.0 |
|
174 | - */ |
|
175 | - public function addAllowedFontDomain($domain) { |
|
176 | - $this->allowedFontDomains[] = $domain; |
|
177 | - return $this; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Remove the specified allowed font domain from the allowed domains. |
|
182 | - * |
|
183 | - * @param string $domain |
|
184 | - * @return $this |
|
185 | - * @since 8.1.0 |
|
186 | - */ |
|
187 | - public function disallowFontDomain($domain) { |
|
188 | - $this->allowedFontDomains = array_diff($this->allowedFontDomains, [$domain]); |
|
189 | - return $this; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Allows embedding images from a specific domain. Use * to allow |
|
194 | - * images from all domains. |
|
195 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
196 | - * @return $this |
|
197 | - * @since 8.1.0 |
|
198 | - */ |
|
199 | - public function addAllowedImageDomain($domain) { |
|
200 | - $this->allowedImageDomains[] = $domain; |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Remove the specified allowed image domain from the allowed domains. |
|
206 | - * |
|
207 | - * @param string $domain |
|
208 | - * @return $this |
|
209 | - * @since 8.1.0 |
|
210 | - */ |
|
211 | - public function disallowImageDomain($domain) { |
|
212 | - $this->allowedImageDomains = array_diff($this->allowedImageDomains, [$domain]); |
|
213 | - return $this; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * To which remote domains the JS connect to. |
|
218 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
219 | - * @return $this |
|
220 | - * @since 8.1.0 |
|
221 | - */ |
|
222 | - public function addAllowedConnectDomain($domain) { |
|
223 | - $this->allowedConnectDomains[] = $domain; |
|
224 | - return $this; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Remove the specified allowed connect domain from the allowed domains. |
|
229 | - * |
|
230 | - * @param string $domain |
|
231 | - * @return $this |
|
232 | - * @since 8.1.0 |
|
233 | - */ |
|
234 | - public function disallowConnectDomain($domain) { |
|
235 | - $this->allowedConnectDomains = array_diff($this->allowedConnectDomains, [$domain]); |
|
236 | - return $this; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * From which domains media elements can be embedded. |
|
241 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
242 | - * @return $this |
|
243 | - * @since 8.1.0 |
|
244 | - */ |
|
245 | - public function addAllowedMediaDomain($domain) { |
|
246 | - $this->allowedMediaDomains[] = $domain; |
|
247 | - return $this; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Remove the specified allowed media domain from the allowed domains. |
|
252 | - * |
|
253 | - * @param string $domain |
|
254 | - * @return $this |
|
255 | - * @since 8.1.0 |
|
256 | - */ |
|
257 | - public function disallowMediaDomain($domain) { |
|
258 | - $this->allowedMediaDomains = array_diff($this->allowedMediaDomains, [$domain]); |
|
259 | - return $this; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * From which domains objects such as <object>, <embed> or <applet> are executed |
|
264 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
265 | - * @return $this |
|
266 | - * @since 8.1.0 |
|
267 | - */ |
|
268 | - public function addAllowedObjectDomain($domain) { |
|
269 | - $this->allowedObjectDomains[] = $domain; |
|
270 | - return $this; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Remove the specified allowed object domain from the allowed domains. |
|
275 | - * |
|
276 | - * @param string $domain |
|
277 | - * @return $this |
|
278 | - * @since 8.1.0 |
|
279 | - */ |
|
280 | - public function disallowObjectDomain($domain) { |
|
281 | - $this->allowedObjectDomains = array_diff($this->allowedObjectDomains, [$domain]); |
|
282 | - return $this; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Which domains can be embedded in an iframe |
|
287 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
288 | - * @return $this |
|
289 | - * @since 8.1.0 |
|
290 | - */ |
|
291 | - public function addAllowedFrameDomain($domain) { |
|
292 | - $this->allowedFrameDomains[] = $domain; |
|
293 | - return $this; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Remove the specified allowed frame domain from the allowed domains. |
|
298 | - * |
|
299 | - * @param string $domain |
|
300 | - * @return $this |
|
301 | - * @since 8.1.0 |
|
302 | - */ |
|
303 | - public function disallowFrameDomain($domain) { |
|
304 | - $this->allowedFrameDomains = array_diff($this->allowedFrameDomains, [$domain]); |
|
305 | - return $this; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Domains from which web-workers and nested browsing content can load elements |
|
310 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
311 | - * @return $this |
|
312 | - * @since 8.1.0 |
|
313 | - */ |
|
314 | - public function addAllowedChildSrcDomain($domain) { |
|
315 | - $this->allowedChildSrcDomains[] = $domain; |
|
316 | - return $this; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Remove the specified allowed child src domain from the allowed domains. |
|
321 | - * |
|
322 | - * @param string $domain |
|
323 | - * @return $this |
|
324 | - * @since 8.1.0 |
|
325 | - */ |
|
326 | - public function disallowChildSrcDomain($domain) { |
|
327 | - $this->allowedChildSrcDomains = array_diff($this->allowedChildSrcDomains, [$domain]); |
|
328 | - return $this; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Domains which can embed an iFrame of the Nextcloud instance |
|
333 | - * |
|
334 | - * @param string $domain |
|
335 | - * @return $this |
|
336 | - * @since 13.0.0 |
|
337 | - */ |
|
338 | - public function addAllowedFrameAncestorDomain($domain) { |
|
339 | - $this->allowedFrameAncestors[] = $domain; |
|
340 | - return $this; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Domains which can embed an iFrame of the Nextcloud instance |
|
345 | - * |
|
346 | - * @param string $domain |
|
347 | - * @return $this |
|
348 | - * @since 13.0.0 |
|
349 | - */ |
|
350 | - public function disallowFrameAncestorDomain($domain) { |
|
351 | - $this->allowedFrameAncestors = array_diff($this->allowedFrameAncestors, [$domain]); |
|
352 | - return $this; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Get the generated Content-Security-Policy as a string |
|
357 | - * @return string |
|
358 | - * @since 8.1.0 |
|
359 | - */ |
|
360 | - public function buildPolicy() { |
|
361 | - $policy = "default-src 'none';"; |
|
362 | - $policy .= "base-uri 'none';"; |
|
363 | - $policy .= "manifest-src 'self';"; |
|
364 | - |
|
365 | - if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) { |
|
366 | - $policy .= 'script-src '; |
|
367 | - if(is_string($this->useJsNonce)) { |
|
368 | - $policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\''; |
|
369 | - $allowedScriptDomains = array_flip($this->allowedScriptDomains); |
|
370 | - unset($allowedScriptDomains['\'self\'']); |
|
371 | - $this->allowedScriptDomains = array_flip($allowedScriptDomains); |
|
372 | - if(count($allowedScriptDomains) !== 0) { |
|
373 | - $policy .= ' '; |
|
374 | - } |
|
375 | - } |
|
376 | - if(is_array($this->allowedScriptDomains)) { |
|
377 | - $policy .= implode(' ', $this->allowedScriptDomains); |
|
378 | - } |
|
379 | - if($this->inlineScriptAllowed) { |
|
380 | - $policy .= ' \'unsafe-inline\''; |
|
381 | - } |
|
382 | - if($this->evalScriptAllowed) { |
|
383 | - $policy .= ' \'unsafe-eval\''; |
|
384 | - } |
|
385 | - $policy .= ';'; |
|
386 | - } |
|
387 | - |
|
388 | - if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) { |
|
389 | - $policy .= 'style-src '; |
|
390 | - if(is_array($this->allowedStyleDomains)) { |
|
391 | - $policy .= implode(' ', $this->allowedStyleDomains); |
|
392 | - } |
|
393 | - if($this->inlineStyleAllowed) { |
|
394 | - $policy .= ' \'unsafe-inline\''; |
|
395 | - } |
|
396 | - $policy .= ';'; |
|
397 | - } |
|
398 | - |
|
399 | - if(!empty($this->allowedImageDomains)) { |
|
400 | - $policy .= 'img-src ' . implode(' ', $this->allowedImageDomains); |
|
401 | - $policy .= ';'; |
|
402 | - } |
|
403 | - |
|
404 | - if(!empty($this->allowedFontDomains)) { |
|
405 | - $policy .= 'font-src ' . implode(' ', $this->allowedFontDomains); |
|
406 | - $policy .= ';'; |
|
407 | - } |
|
408 | - |
|
409 | - if(!empty($this->allowedConnectDomains)) { |
|
410 | - $policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains); |
|
411 | - $policy .= ';'; |
|
412 | - } |
|
413 | - |
|
414 | - if(!empty($this->allowedMediaDomains)) { |
|
415 | - $policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains); |
|
416 | - $policy .= ';'; |
|
417 | - } |
|
418 | - |
|
419 | - if(!empty($this->allowedObjectDomains)) { |
|
420 | - $policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains); |
|
421 | - $policy .= ';'; |
|
422 | - } |
|
423 | - |
|
424 | - if(!empty($this->allowedFrameDomains)) { |
|
425 | - $policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains); |
|
426 | - $policy .= ';'; |
|
427 | - } |
|
428 | - |
|
429 | - if(!empty($this->allowedChildSrcDomains)) { |
|
430 | - $policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains); |
|
431 | - $policy .= ';'; |
|
432 | - } |
|
433 | - |
|
434 | - if(!empty($this->allowedFrameAncestors)) { |
|
435 | - $policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors); |
|
436 | - $policy .= ';'; |
|
437 | - } |
|
438 | - |
|
439 | - return rtrim($policy, ';'); |
|
440 | - } |
|
37 | + /** @var bool Whether inline JS snippets are allowed */ |
|
38 | + protected $inlineScriptAllowed = null; |
|
39 | + /** @var string Whether JS nonces should be used */ |
|
40 | + protected $useJsNonce = null; |
|
41 | + /** |
|
42 | + * @var bool Whether eval in JS scripts is allowed |
|
43 | + * TODO: Disallow per default |
|
44 | + * @link https://github.com/owncloud/core/issues/11925 |
|
45 | + */ |
|
46 | + protected $evalScriptAllowed = null; |
|
47 | + /** @var array Domains from which scripts can get loaded */ |
|
48 | + protected $allowedScriptDomains = null; |
|
49 | + /** |
|
50 | + * @var bool Whether inline CSS is allowed |
|
51 | + * TODO: Disallow per default |
|
52 | + * @link https://github.com/owncloud/core/issues/13458 |
|
53 | + */ |
|
54 | + protected $inlineStyleAllowed = null; |
|
55 | + /** @var array Domains from which CSS can get loaded */ |
|
56 | + protected $allowedStyleDomains = null; |
|
57 | + /** @var array Domains from which images can get loaded */ |
|
58 | + protected $allowedImageDomains = null; |
|
59 | + /** @var array Domains to which connections can be done */ |
|
60 | + protected $allowedConnectDomains = null; |
|
61 | + /** @var array Domains from which media elements can be loaded */ |
|
62 | + protected $allowedMediaDomains = null; |
|
63 | + /** @var array Domains from which object elements can be loaded */ |
|
64 | + protected $allowedObjectDomains = null; |
|
65 | + /** @var array Domains from which iframes can be loaded */ |
|
66 | + protected $allowedFrameDomains = null; |
|
67 | + /** @var array Domains from which fonts can be loaded */ |
|
68 | + protected $allowedFontDomains = null; |
|
69 | + /** @var array Domains from which web-workers and nested browsing content can load elements */ |
|
70 | + protected $allowedChildSrcDomains = null; |
|
71 | + /** @var array Domains which can embed this Nextcloud instance */ |
|
72 | + protected $allowedFrameAncestors = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * Whether inline JavaScript snippets are allowed or forbidden |
|
76 | + * @param bool $state |
|
77 | + * @return $this |
|
78 | + * @since 8.1.0 |
|
79 | + * @deprecated 10.0 CSP tokens are now used |
|
80 | + */ |
|
81 | + public function allowInlineScript($state = false) { |
|
82 | + $this->inlineScriptAllowed = $state; |
|
83 | + return $this; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Use the according JS nonce |
|
88 | + * |
|
89 | + * @param string $nonce |
|
90 | + * @return $this |
|
91 | + * @since 11.0.0 |
|
92 | + */ |
|
93 | + public function useJsNonce($nonce) { |
|
94 | + $this->useJsNonce = $nonce; |
|
95 | + return $this; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Whether eval in JavaScript is allowed or forbidden |
|
100 | + * @param bool $state |
|
101 | + * @return $this |
|
102 | + * @since 8.1.0 |
|
103 | + */ |
|
104 | + public function allowEvalScript($state = true) { |
|
105 | + $this->evalScriptAllowed = $state; |
|
106 | + return $this; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Allows to execute JavaScript files from a specific domain. Use * to |
|
111 | + * allow JavaScript from all domains. |
|
112 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
113 | + * @return $this |
|
114 | + * @since 8.1.0 |
|
115 | + */ |
|
116 | + public function addAllowedScriptDomain($domain) { |
|
117 | + $this->allowedScriptDomains[] = $domain; |
|
118 | + return $this; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Remove the specified allowed script domain from the allowed domains. |
|
123 | + * |
|
124 | + * @param string $domain |
|
125 | + * @return $this |
|
126 | + * @since 8.1.0 |
|
127 | + */ |
|
128 | + public function disallowScriptDomain($domain) { |
|
129 | + $this->allowedScriptDomains = array_diff($this->allowedScriptDomains, [$domain]); |
|
130 | + return $this; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Whether inline CSS snippets are allowed or forbidden |
|
135 | + * @param bool $state |
|
136 | + * @return $this |
|
137 | + * @since 8.1.0 |
|
138 | + */ |
|
139 | + public function allowInlineStyle($state = true) { |
|
140 | + $this->inlineStyleAllowed = $state; |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Allows to execute CSS files from a specific domain. Use * to allow |
|
146 | + * CSS from all domains. |
|
147 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
148 | + * @return $this |
|
149 | + * @since 8.1.0 |
|
150 | + */ |
|
151 | + public function addAllowedStyleDomain($domain) { |
|
152 | + $this->allowedStyleDomains[] = $domain; |
|
153 | + return $this; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Remove the specified allowed style domain from the allowed domains. |
|
158 | + * |
|
159 | + * @param string $domain |
|
160 | + * @return $this |
|
161 | + * @since 8.1.0 |
|
162 | + */ |
|
163 | + public function disallowStyleDomain($domain) { |
|
164 | + $this->allowedStyleDomains = array_diff($this->allowedStyleDomains, [$domain]); |
|
165 | + return $this; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Allows using fonts from a specific domain. Use * to allow |
|
170 | + * fonts from all domains. |
|
171 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
172 | + * @return $this |
|
173 | + * @since 8.1.0 |
|
174 | + */ |
|
175 | + public function addAllowedFontDomain($domain) { |
|
176 | + $this->allowedFontDomains[] = $domain; |
|
177 | + return $this; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Remove the specified allowed font domain from the allowed domains. |
|
182 | + * |
|
183 | + * @param string $domain |
|
184 | + * @return $this |
|
185 | + * @since 8.1.0 |
|
186 | + */ |
|
187 | + public function disallowFontDomain($domain) { |
|
188 | + $this->allowedFontDomains = array_diff($this->allowedFontDomains, [$domain]); |
|
189 | + return $this; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Allows embedding images from a specific domain. Use * to allow |
|
194 | + * images from all domains. |
|
195 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
196 | + * @return $this |
|
197 | + * @since 8.1.0 |
|
198 | + */ |
|
199 | + public function addAllowedImageDomain($domain) { |
|
200 | + $this->allowedImageDomains[] = $domain; |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Remove the specified allowed image domain from the allowed domains. |
|
206 | + * |
|
207 | + * @param string $domain |
|
208 | + * @return $this |
|
209 | + * @since 8.1.0 |
|
210 | + */ |
|
211 | + public function disallowImageDomain($domain) { |
|
212 | + $this->allowedImageDomains = array_diff($this->allowedImageDomains, [$domain]); |
|
213 | + return $this; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * To which remote domains the JS connect to. |
|
218 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
219 | + * @return $this |
|
220 | + * @since 8.1.0 |
|
221 | + */ |
|
222 | + public function addAllowedConnectDomain($domain) { |
|
223 | + $this->allowedConnectDomains[] = $domain; |
|
224 | + return $this; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Remove the specified allowed connect domain from the allowed domains. |
|
229 | + * |
|
230 | + * @param string $domain |
|
231 | + * @return $this |
|
232 | + * @since 8.1.0 |
|
233 | + */ |
|
234 | + public function disallowConnectDomain($domain) { |
|
235 | + $this->allowedConnectDomains = array_diff($this->allowedConnectDomains, [$domain]); |
|
236 | + return $this; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * From which domains media elements can be embedded. |
|
241 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
242 | + * @return $this |
|
243 | + * @since 8.1.0 |
|
244 | + */ |
|
245 | + public function addAllowedMediaDomain($domain) { |
|
246 | + $this->allowedMediaDomains[] = $domain; |
|
247 | + return $this; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Remove the specified allowed media domain from the allowed domains. |
|
252 | + * |
|
253 | + * @param string $domain |
|
254 | + * @return $this |
|
255 | + * @since 8.1.0 |
|
256 | + */ |
|
257 | + public function disallowMediaDomain($domain) { |
|
258 | + $this->allowedMediaDomains = array_diff($this->allowedMediaDomains, [$domain]); |
|
259 | + return $this; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * From which domains objects such as <object>, <embed> or <applet> are executed |
|
264 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
265 | + * @return $this |
|
266 | + * @since 8.1.0 |
|
267 | + */ |
|
268 | + public function addAllowedObjectDomain($domain) { |
|
269 | + $this->allowedObjectDomains[] = $domain; |
|
270 | + return $this; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Remove the specified allowed object domain from the allowed domains. |
|
275 | + * |
|
276 | + * @param string $domain |
|
277 | + * @return $this |
|
278 | + * @since 8.1.0 |
|
279 | + */ |
|
280 | + public function disallowObjectDomain($domain) { |
|
281 | + $this->allowedObjectDomains = array_diff($this->allowedObjectDomains, [$domain]); |
|
282 | + return $this; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Which domains can be embedded in an iframe |
|
287 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
288 | + * @return $this |
|
289 | + * @since 8.1.0 |
|
290 | + */ |
|
291 | + public function addAllowedFrameDomain($domain) { |
|
292 | + $this->allowedFrameDomains[] = $domain; |
|
293 | + return $this; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Remove the specified allowed frame domain from the allowed domains. |
|
298 | + * |
|
299 | + * @param string $domain |
|
300 | + * @return $this |
|
301 | + * @since 8.1.0 |
|
302 | + */ |
|
303 | + public function disallowFrameDomain($domain) { |
|
304 | + $this->allowedFrameDomains = array_diff($this->allowedFrameDomains, [$domain]); |
|
305 | + return $this; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Domains from which web-workers and nested browsing content can load elements |
|
310 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
311 | + * @return $this |
|
312 | + * @since 8.1.0 |
|
313 | + */ |
|
314 | + public function addAllowedChildSrcDomain($domain) { |
|
315 | + $this->allowedChildSrcDomains[] = $domain; |
|
316 | + return $this; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Remove the specified allowed child src domain from the allowed domains. |
|
321 | + * |
|
322 | + * @param string $domain |
|
323 | + * @return $this |
|
324 | + * @since 8.1.0 |
|
325 | + */ |
|
326 | + public function disallowChildSrcDomain($domain) { |
|
327 | + $this->allowedChildSrcDomains = array_diff($this->allowedChildSrcDomains, [$domain]); |
|
328 | + return $this; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Domains which can embed an iFrame of the Nextcloud instance |
|
333 | + * |
|
334 | + * @param string $domain |
|
335 | + * @return $this |
|
336 | + * @since 13.0.0 |
|
337 | + */ |
|
338 | + public function addAllowedFrameAncestorDomain($domain) { |
|
339 | + $this->allowedFrameAncestors[] = $domain; |
|
340 | + return $this; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Domains which can embed an iFrame of the Nextcloud instance |
|
345 | + * |
|
346 | + * @param string $domain |
|
347 | + * @return $this |
|
348 | + * @since 13.0.0 |
|
349 | + */ |
|
350 | + public function disallowFrameAncestorDomain($domain) { |
|
351 | + $this->allowedFrameAncestors = array_diff($this->allowedFrameAncestors, [$domain]); |
|
352 | + return $this; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Get the generated Content-Security-Policy as a string |
|
357 | + * @return string |
|
358 | + * @since 8.1.0 |
|
359 | + */ |
|
360 | + public function buildPolicy() { |
|
361 | + $policy = "default-src 'none';"; |
|
362 | + $policy .= "base-uri 'none';"; |
|
363 | + $policy .= "manifest-src 'self';"; |
|
364 | + |
|
365 | + if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) { |
|
366 | + $policy .= 'script-src '; |
|
367 | + if(is_string($this->useJsNonce)) { |
|
368 | + $policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\''; |
|
369 | + $allowedScriptDomains = array_flip($this->allowedScriptDomains); |
|
370 | + unset($allowedScriptDomains['\'self\'']); |
|
371 | + $this->allowedScriptDomains = array_flip($allowedScriptDomains); |
|
372 | + if(count($allowedScriptDomains) !== 0) { |
|
373 | + $policy .= ' '; |
|
374 | + } |
|
375 | + } |
|
376 | + if(is_array($this->allowedScriptDomains)) { |
|
377 | + $policy .= implode(' ', $this->allowedScriptDomains); |
|
378 | + } |
|
379 | + if($this->inlineScriptAllowed) { |
|
380 | + $policy .= ' \'unsafe-inline\''; |
|
381 | + } |
|
382 | + if($this->evalScriptAllowed) { |
|
383 | + $policy .= ' \'unsafe-eval\''; |
|
384 | + } |
|
385 | + $policy .= ';'; |
|
386 | + } |
|
387 | + |
|
388 | + if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) { |
|
389 | + $policy .= 'style-src '; |
|
390 | + if(is_array($this->allowedStyleDomains)) { |
|
391 | + $policy .= implode(' ', $this->allowedStyleDomains); |
|
392 | + } |
|
393 | + if($this->inlineStyleAllowed) { |
|
394 | + $policy .= ' \'unsafe-inline\''; |
|
395 | + } |
|
396 | + $policy .= ';'; |
|
397 | + } |
|
398 | + |
|
399 | + if(!empty($this->allowedImageDomains)) { |
|
400 | + $policy .= 'img-src ' . implode(' ', $this->allowedImageDomains); |
|
401 | + $policy .= ';'; |
|
402 | + } |
|
403 | + |
|
404 | + if(!empty($this->allowedFontDomains)) { |
|
405 | + $policy .= 'font-src ' . implode(' ', $this->allowedFontDomains); |
|
406 | + $policy .= ';'; |
|
407 | + } |
|
408 | + |
|
409 | + if(!empty($this->allowedConnectDomains)) { |
|
410 | + $policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains); |
|
411 | + $policy .= ';'; |
|
412 | + } |
|
413 | + |
|
414 | + if(!empty($this->allowedMediaDomains)) { |
|
415 | + $policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains); |
|
416 | + $policy .= ';'; |
|
417 | + } |
|
418 | + |
|
419 | + if(!empty($this->allowedObjectDomains)) { |
|
420 | + $policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains); |
|
421 | + $policy .= ';'; |
|
422 | + } |
|
423 | + |
|
424 | + if(!empty($this->allowedFrameDomains)) { |
|
425 | + $policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains); |
|
426 | + $policy .= ';'; |
|
427 | + } |
|
428 | + |
|
429 | + if(!empty($this->allowedChildSrcDomains)) { |
|
430 | + $policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains); |
|
431 | + $policy .= ';'; |
|
432 | + } |
|
433 | + |
|
434 | + if(!empty($this->allowedFrameAncestors)) { |
|
435 | + $policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors); |
|
436 | + $policy .= ';'; |
|
437 | + } |
|
438 | + |
|
439 | + return rtrim($policy, ';'); |
|
440 | + } |
|
441 | 441 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <div class="error"> |
2 | 2 | <h2><?php p($l->t('Error')) ?></h2> |
3 | 3 | <ul> |
4 | - <?php foreach($_["errors"] as $error):?> |
|
4 | + <?php foreach ($_["errors"] as $error):?> |
|
5 | 5 | <li> |
6 | 6 | <p><?php p($error['error']) ?></p> |
7 | - <?php if(isset($error['hint']) && $error['hint']): ?> |
|
7 | + <?php if (isset($error['hint']) && $error['hint']): ?> |
|
8 | 8 | <p class='hint'><?php p($error['hint']) ?></p> |
9 | - <?php endif;?> |
|
9 | + <?php endif; ?> |
|
10 | 10 | </li> |
11 | 11 | <?php endforeach ?> |
12 | 12 | </ul> |
@@ -33,304 +33,304 @@ |
||
33 | 33 | |
34 | 34 | class Activity implements IProvider { |
35 | 35 | |
36 | - /** @var IFactory */ |
|
37 | - protected $languageFactory; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $activityManager; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - protected $userManager; |
|
50 | - /** @var IContactsManager */ |
|
51 | - protected $contactsManager; |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - protected $displayNames = []; |
|
55 | - |
|
56 | - /** @var array */ |
|
57 | - protected $contactNames = []; |
|
58 | - |
|
59 | - const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | - const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IFactory $languageFactory |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IManager $activityManager |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IContactsManager $contactsManager |
|
70 | - */ |
|
71 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | - $this->languageFactory = $languageFactory; |
|
73 | - $this->url = $url; |
|
74 | - $this->activityManager = $activityManager; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->contactsManager = $contactsManager; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $language |
|
81 | - * @param IEvent $event |
|
82 | - * @param IEvent|null $previousEvent |
|
83 | - * @return IEvent |
|
84 | - * @throws \InvalidArgumentException |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | - if ($event->getApp() !== 'sharebymail') { |
|
89 | - throw new \InvalidArgumentException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | - |
|
94 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | - try { |
|
96 | - return $this->parseShortVersion($event); |
|
97 | - } catch (\InvalidArgumentException $e) { |
|
98 | - // Ignore and simply use the long version... |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $this->parseLongVersion($event); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param IEvent $event |
|
107 | - * @return IEvent |
|
108 | - * @throws \InvalidArgumentException |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function parseShortVersion(IEvent $event) { |
|
112 | - $parsedParameters = $this->getParsedParameters($event); |
|
113 | - |
|
114 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | - $parsedParameters['email']['name'], |
|
117 | - ])) |
|
118 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | - 'email' => $parsedParameters['email'], |
|
120 | - ]); |
|
121 | - if ($this->activityManager->getRequirePNG()) { |
|
122 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
123 | - } else { |
|
124 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
125 | - } |
|
126 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
127 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
128 | - $parsedParameters['email']['name'], |
|
129 | - $parsedParameters['actor']['name'], |
|
130 | - ])) |
|
131 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
132 | - 'email' => $parsedParameters['email'], |
|
133 | - 'actor' => $parsedParameters['actor'], |
|
134 | - ]); |
|
135 | - if ($this->activityManager->getRequirePNG()) { |
|
136 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
137 | - } else { |
|
138 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
139 | - } |
|
140 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
141 | - $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
142 | - $parsedParameters['email']['name'] |
|
143 | - ])) |
|
144 | - ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
145 | - 'email' => $parsedParameters['email'] |
|
146 | - ]); |
|
147 | - if ($this->activityManager->getRequirePNG()) { |
|
148 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
149 | - } else { |
|
150 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
151 | - } |
|
152 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
153 | - $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
154 | - ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
155 | - if ($this->activityManager->getRequirePNG()) { |
|
156 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
157 | - } else { |
|
158 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
159 | - } |
|
160 | - } else { |
|
161 | - throw new \InvalidArgumentException(); |
|
162 | - } |
|
163 | - |
|
164 | - return $event; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param IEvent $event |
|
169 | - * @return IEvent |
|
170 | - * @throws \InvalidArgumentException |
|
171 | - * @since 11.0.0 |
|
172 | - */ |
|
173 | - public function parseLongVersion(IEvent $event) { |
|
174 | - $parsedParameters = $this->getParsedParameters($event); |
|
175 | - |
|
176 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
177 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
178 | - $parsedParameters['file']['path'], |
|
179 | - $parsedParameters['email']['name'], |
|
180 | - ])) |
|
181 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
182 | - if ($this->activityManager->getRequirePNG()) { |
|
183 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
184 | - } else { |
|
185 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
186 | - } |
|
187 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
188 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
189 | - $parsedParameters['file']['path'], |
|
190 | - $parsedParameters['email']['name'], |
|
191 | - $parsedParameters['actor']['name'], |
|
192 | - ])) |
|
193 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
194 | - if ($this->activityManager->getRequirePNG()) { |
|
195 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
196 | - } else { |
|
197 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
198 | - } |
|
199 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
200 | - $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
201 | - $parsedParameters['file']['path'], |
|
202 | - $parsedParameters['email']['name'] |
|
203 | - ])) |
|
204 | - ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
205 | - if ($this->activityManager->getRequirePNG()) { |
|
206 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
207 | - } else { |
|
208 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
209 | - } |
|
210 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
211 | - $event->setParsedSubject( |
|
212 | - $this->l->t('Password to access %1$s was sent to you', |
|
213 | - [$parsedParameters['file']['path']])) |
|
214 | - ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
215 | - if ($this->activityManager->getRequirePNG()) { |
|
216 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
217 | - } else { |
|
218 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
219 | - } |
|
220 | - |
|
221 | - } else { |
|
222 | - throw new \InvalidArgumentException(); |
|
223 | - } |
|
224 | - |
|
225 | - return $event; |
|
226 | - } |
|
227 | - |
|
228 | - protected function getParsedParameters(IEvent $event) { |
|
229 | - $subject = $event->getSubject(); |
|
230 | - $parameters = $event->getSubjectParameters(); |
|
231 | - |
|
232 | - switch ($subject) { |
|
233 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
234 | - return [ |
|
235 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
236 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
237 | - ]; |
|
238 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
239 | - return [ |
|
240 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
241 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
242 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
243 | - ]; |
|
244 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
245 | - return [ |
|
246 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
247 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
248 | - ]; |
|
249 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
250 | - return [ |
|
251 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
252 | - ]; |
|
253 | - } |
|
254 | - throw new \InvalidArgumentException(); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @param int $id |
|
259 | - * @param string $path |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - protected function generateFileParameter($id, $path) { |
|
263 | - return [ |
|
264 | - 'type' => 'file', |
|
265 | - 'id' => $id, |
|
266 | - 'name' => basename($path), |
|
267 | - 'path' => trim($path, '/'), |
|
268 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
269 | - ]; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $email |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - protected function generateEmailParameter($email) { |
|
277 | - if (!isset($this->contactNames[$email])) { |
|
278 | - $this->contactNames[$email] = $this->getContactName($email); |
|
279 | - } |
|
280 | - |
|
281 | - return [ |
|
282 | - 'type' => 'email', |
|
283 | - 'id' => $email, |
|
284 | - 'name' => $this->contactNames[$email], |
|
285 | - ]; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * @param string $uid |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - protected function generateUserParameter($uid) { |
|
293 | - if (!isset($this->displayNames[$uid])) { |
|
294 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
295 | - } |
|
296 | - |
|
297 | - return [ |
|
298 | - 'type' => 'user', |
|
299 | - 'id' => $uid, |
|
300 | - 'name' => $this->displayNames[$uid], |
|
301 | - ]; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param string $email |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - protected function getContactName($email) { |
|
309 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
310 | - |
|
311 | - foreach ($addressBookContacts as $contact) { |
|
312 | - if (isset($contact['isLocalSystemBook'])) { |
|
313 | - continue; |
|
314 | - } |
|
315 | - |
|
316 | - if (in_array($email, $contact['EMAIL'])) { |
|
317 | - return $contact['FN']; |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - return $email; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $uid |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - protected function getDisplayName($uid) { |
|
329 | - $user = $this->userManager->get($uid); |
|
330 | - if ($user instanceof IUser) { |
|
331 | - return $user->getDisplayName(); |
|
332 | - } else { |
|
333 | - return $uid; |
|
334 | - } |
|
335 | - } |
|
36 | + /** @var IFactory */ |
|
37 | + protected $languageFactory; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $activityManager; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + protected $userManager; |
|
50 | + /** @var IContactsManager */ |
|
51 | + protected $contactsManager; |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + protected $displayNames = []; |
|
55 | + |
|
56 | + /** @var array */ |
|
57 | + protected $contactNames = []; |
|
58 | + |
|
59 | + const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | + const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IFactory $languageFactory |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IManager $activityManager |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IContactsManager $contactsManager |
|
70 | + */ |
|
71 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | + $this->languageFactory = $languageFactory; |
|
73 | + $this->url = $url; |
|
74 | + $this->activityManager = $activityManager; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->contactsManager = $contactsManager; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $language |
|
81 | + * @param IEvent $event |
|
82 | + * @param IEvent|null $previousEvent |
|
83 | + * @return IEvent |
|
84 | + * @throws \InvalidArgumentException |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | + if ($event->getApp() !== 'sharebymail') { |
|
89 | + throw new \InvalidArgumentException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | + |
|
94 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | + try { |
|
96 | + return $this->parseShortVersion($event); |
|
97 | + } catch (\InvalidArgumentException $e) { |
|
98 | + // Ignore and simply use the long version... |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $this->parseLongVersion($event); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param IEvent $event |
|
107 | + * @return IEvent |
|
108 | + * @throws \InvalidArgumentException |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function parseShortVersion(IEvent $event) { |
|
112 | + $parsedParameters = $this->getParsedParameters($event); |
|
113 | + |
|
114 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | + $parsedParameters['email']['name'], |
|
117 | + ])) |
|
118 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | + 'email' => $parsedParameters['email'], |
|
120 | + ]); |
|
121 | + if ($this->activityManager->getRequirePNG()) { |
|
122 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
123 | + } else { |
|
124 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
125 | + } |
|
126 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
127 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
128 | + $parsedParameters['email']['name'], |
|
129 | + $parsedParameters['actor']['name'], |
|
130 | + ])) |
|
131 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
132 | + 'email' => $parsedParameters['email'], |
|
133 | + 'actor' => $parsedParameters['actor'], |
|
134 | + ]); |
|
135 | + if ($this->activityManager->getRequirePNG()) { |
|
136 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
137 | + } else { |
|
138 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
139 | + } |
|
140 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
141 | + $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
142 | + $parsedParameters['email']['name'] |
|
143 | + ])) |
|
144 | + ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
145 | + 'email' => $parsedParameters['email'] |
|
146 | + ]); |
|
147 | + if ($this->activityManager->getRequirePNG()) { |
|
148 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
149 | + } else { |
|
150 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
151 | + } |
|
152 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
153 | + $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
154 | + ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
155 | + if ($this->activityManager->getRequirePNG()) { |
|
156 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
157 | + } else { |
|
158 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
159 | + } |
|
160 | + } else { |
|
161 | + throw new \InvalidArgumentException(); |
|
162 | + } |
|
163 | + |
|
164 | + return $event; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param IEvent $event |
|
169 | + * @return IEvent |
|
170 | + * @throws \InvalidArgumentException |
|
171 | + * @since 11.0.0 |
|
172 | + */ |
|
173 | + public function parseLongVersion(IEvent $event) { |
|
174 | + $parsedParameters = $this->getParsedParameters($event); |
|
175 | + |
|
176 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
177 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
178 | + $parsedParameters['file']['path'], |
|
179 | + $parsedParameters['email']['name'], |
|
180 | + ])) |
|
181 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
182 | + if ($this->activityManager->getRequirePNG()) { |
|
183 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
184 | + } else { |
|
185 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
186 | + } |
|
187 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
188 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
189 | + $parsedParameters['file']['path'], |
|
190 | + $parsedParameters['email']['name'], |
|
191 | + $parsedParameters['actor']['name'], |
|
192 | + ])) |
|
193 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
194 | + if ($this->activityManager->getRequirePNG()) { |
|
195 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
196 | + } else { |
|
197 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
198 | + } |
|
199 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
200 | + $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
201 | + $parsedParameters['file']['path'], |
|
202 | + $parsedParameters['email']['name'] |
|
203 | + ])) |
|
204 | + ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
205 | + if ($this->activityManager->getRequirePNG()) { |
|
206 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
207 | + } else { |
|
208 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
209 | + } |
|
210 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
211 | + $event->setParsedSubject( |
|
212 | + $this->l->t('Password to access %1$s was sent to you', |
|
213 | + [$parsedParameters['file']['path']])) |
|
214 | + ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
215 | + if ($this->activityManager->getRequirePNG()) { |
|
216 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
217 | + } else { |
|
218 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
219 | + } |
|
220 | + |
|
221 | + } else { |
|
222 | + throw new \InvalidArgumentException(); |
|
223 | + } |
|
224 | + |
|
225 | + return $event; |
|
226 | + } |
|
227 | + |
|
228 | + protected function getParsedParameters(IEvent $event) { |
|
229 | + $subject = $event->getSubject(); |
|
230 | + $parameters = $event->getSubjectParameters(); |
|
231 | + |
|
232 | + switch ($subject) { |
|
233 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
234 | + return [ |
|
235 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
236 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
237 | + ]; |
|
238 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
239 | + return [ |
|
240 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
241 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
242 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
243 | + ]; |
|
244 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
245 | + return [ |
|
246 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
247 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
248 | + ]; |
|
249 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
250 | + return [ |
|
251 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
252 | + ]; |
|
253 | + } |
|
254 | + throw new \InvalidArgumentException(); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @param int $id |
|
259 | + * @param string $path |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + protected function generateFileParameter($id, $path) { |
|
263 | + return [ |
|
264 | + 'type' => 'file', |
|
265 | + 'id' => $id, |
|
266 | + 'name' => basename($path), |
|
267 | + 'path' => trim($path, '/'), |
|
268 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
269 | + ]; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $email |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + protected function generateEmailParameter($email) { |
|
277 | + if (!isset($this->contactNames[$email])) { |
|
278 | + $this->contactNames[$email] = $this->getContactName($email); |
|
279 | + } |
|
280 | + |
|
281 | + return [ |
|
282 | + 'type' => 'email', |
|
283 | + 'id' => $email, |
|
284 | + 'name' => $this->contactNames[$email], |
|
285 | + ]; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * @param string $uid |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + protected function generateUserParameter($uid) { |
|
293 | + if (!isset($this->displayNames[$uid])) { |
|
294 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
295 | + } |
|
296 | + |
|
297 | + return [ |
|
298 | + 'type' => 'user', |
|
299 | + 'id' => $uid, |
|
300 | + 'name' => $this->displayNames[$uid], |
|
301 | + ]; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param string $email |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + protected function getContactName($email) { |
|
309 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
310 | + |
|
311 | + foreach ($addressBookContacts as $contact) { |
|
312 | + if (isset($contact['isLocalSystemBook'])) { |
|
313 | + continue; |
|
314 | + } |
|
315 | + |
|
316 | + if (in_array($email, $contact['EMAIL'])) { |
|
317 | + return $contact['FN']; |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + return $email; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $uid |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + protected function getDisplayName($uid) { |
|
329 | + $user = $this->userManager->get($uid); |
|
330 | + if ($user instanceof IUser) { |
|
331 | + return $user->getDisplayName(); |
|
332 | + } else { |
|
333 | + return $uid; |
|
334 | + } |
|
335 | + } |
|
336 | 336 | } |
@@ -31,47 +31,47 @@ |
||
31 | 31 | |
32 | 32 | class Provider implements IProvider { |
33 | 33 | |
34 | - /** @var L10nFactory */ |
|
35 | - private $l10n; |
|
34 | + /** @var L10nFactory */ |
|
35 | + private $l10n; |
|
36 | 36 | |
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | 39 | |
40 | - /** @var IManager */ |
|
41 | - private $activityManager; |
|
40 | + /** @var IManager */ |
|
41 | + private $activityManager; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param L10nFactory $l10n |
|
45 | - * @param IURLGenerator $urlGenerator |
|
46 | - * @param IManager $activityManager |
|
47 | - */ |
|
48 | - public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
49 | - $this->urlGenerator = $urlGenerator; |
|
50 | - $this->activityManager = $activityManager; |
|
51 | - $this->l10n = $l10n; |
|
52 | - } |
|
43 | + /** |
|
44 | + * @param L10nFactory $l10n |
|
45 | + * @param IURLGenerator $urlGenerator |
|
46 | + * @param IManager $activityManager |
|
47 | + */ |
|
48 | + public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
49 | + $this->urlGenerator = $urlGenerator; |
|
50 | + $this->activityManager = $activityManager; |
|
51 | + $this->l10n = $l10n; |
|
52 | + } |
|
53 | 53 | |
54 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
55 | - if ($event->getApp() !== 'twofactor_backupcodes') { |
|
56 | - throw new InvalidArgumentException(); |
|
57 | - } |
|
54 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
55 | + if ($event->getApp() !== 'twofactor_backupcodes') { |
|
56 | + throw new InvalidArgumentException(); |
|
57 | + } |
|
58 | 58 | |
59 | - $l = $this->l10n->get('twofactor_backupcodes', $language); |
|
59 | + $l = $this->l10n->get('twofactor_backupcodes', $language); |
|
60 | 60 | |
61 | - switch ($event->getSubject()) { |
|
62 | - case 'codes_generated': |
|
63 | - $event->setParsedSubject($l->t('You created two-factor backup codes for your account')); |
|
61 | + switch ($event->getSubject()) { |
|
62 | + case 'codes_generated': |
|
63 | + $event->setParsedSubject($l->t('You created two-factor backup codes for your account')); |
|
64 | 64 | |
65 | - if ($this->activityManager->getRequirePNG()) { |
|
66 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
67 | - } else { |
|
68 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
69 | - } |
|
70 | - break; |
|
71 | - default: |
|
72 | - throw new InvalidArgumentException(); |
|
73 | - } |
|
74 | - return $event; |
|
75 | - } |
|
65 | + if ($this->activityManager->getRequirePNG()) { |
|
66 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
67 | + } else { |
|
68 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
69 | + } |
|
70 | + break; |
|
71 | + default: |
|
72 | + throw new InvalidArgumentException(); |
|
73 | + } |
|
74 | + return $event; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | } |
@@ -25,105 +25,105 @@ |
||
25 | 25 | |
26 | 26 | class PublicLinks extends Base { |
27 | 27 | |
28 | - const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; |
|
29 | - const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; |
|
30 | - const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; |
|
31 | - const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; |
|
32 | - const SUBJECT_LINK_EXPIRED = 'link_expired'; |
|
33 | - const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param IEvent $event |
|
37 | - * @return IEvent |
|
38 | - * @throws \InvalidArgumentException |
|
39 | - * @since 11.0.0 |
|
40 | - */ |
|
41 | - public function parseShortVersion(IEvent $event) { |
|
42 | - $parsedParameters = $this->getParsedParameters($event); |
|
43 | - |
|
44 | - if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
45 | - $subject = $this->l->t('Shared as public link'); |
|
46 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
47 | - $subject = $this->l->t('Removed public link'); |
|
48 | - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
49 | - $subject = $this->l->t('Public link expired'); |
|
50 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
51 | - $subject = $this->l->t('{actor} shared as public link'); |
|
52 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
53 | - $subject = $this->l->t('{actor} removed public link'); |
|
54 | - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
55 | - $subject = $this->l->t('Public link of {actor} expired'); |
|
56 | - |
|
57 | - } else { |
|
58 | - throw new \InvalidArgumentException(); |
|
59 | - } |
|
60 | - |
|
61 | - if ($this->activityManager->getRequirePNG()) { |
|
62 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
63 | - } else { |
|
64 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
65 | - } |
|
66 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
67 | - |
|
68 | - return $event; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param IEvent $event |
|
73 | - * @return IEvent |
|
74 | - * @throws \InvalidArgumentException |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function parseLongVersion(IEvent $event) { |
|
78 | - $parsedParameters = $this->getParsedParameters($event); |
|
79 | - |
|
80 | - if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
81 | - $subject = $this->l->t('You shared {file} as public link'); |
|
82 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
83 | - $subject = $this->l->t('You removed public link for {file}'); |
|
84 | - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
85 | - $subject = $this->l->t('Public link expired for {file}'); |
|
86 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
87 | - $subject = $this->l->t('{actor} shared {file} as public link'); |
|
88 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
89 | - $subject = $this->l->t('{actor} removed public link for {file}'); |
|
90 | - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
91 | - $subject = $this->l->t('Public link of {actor} for {file} expired'); |
|
92 | - |
|
93 | - } else { |
|
94 | - throw new \InvalidArgumentException(); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->activityManager->getRequirePNG()) { |
|
98 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
99 | - } else { |
|
100 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | - } |
|
102 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
103 | - |
|
104 | - return $event; |
|
105 | - } |
|
106 | - |
|
107 | - protected function getParsedParameters(IEvent $event) { |
|
108 | - $subject = $event->getSubject(); |
|
109 | - $parameters = $event->getSubjectParameters(); |
|
110 | - |
|
111 | - switch ($subject) { |
|
112 | - case self::SUBJECT_SHARED_LINK_SELF: |
|
113 | - case self::SUBJECT_UNSHARED_LINK_SELF: |
|
114 | - case self::SUBJECT_LINK_EXPIRED: |
|
115 | - return [ |
|
116 | - 'file' => $this->getFile($parameters[0], $event), |
|
117 | - ]; |
|
118 | - case self::SUBJECT_RESHARED_LINK_BY: |
|
119 | - case self::SUBJECT_UNSHARED_LINK_BY: |
|
120 | - case self::SUBJECT_LINK_BY_EXPIRED: |
|
121 | - return [ |
|
122 | - 'file' => $this->getFile($parameters[0], $event), |
|
123 | - 'actor' => $this->getUser($parameters[1]), |
|
124 | - ]; |
|
125 | - } |
|
126 | - return []; |
|
127 | - } |
|
28 | + const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; |
|
29 | + const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; |
|
30 | + const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; |
|
31 | + const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; |
|
32 | + const SUBJECT_LINK_EXPIRED = 'link_expired'; |
|
33 | + const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param IEvent $event |
|
37 | + * @return IEvent |
|
38 | + * @throws \InvalidArgumentException |
|
39 | + * @since 11.0.0 |
|
40 | + */ |
|
41 | + public function parseShortVersion(IEvent $event) { |
|
42 | + $parsedParameters = $this->getParsedParameters($event); |
|
43 | + |
|
44 | + if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
45 | + $subject = $this->l->t('Shared as public link'); |
|
46 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
47 | + $subject = $this->l->t('Removed public link'); |
|
48 | + } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
49 | + $subject = $this->l->t('Public link expired'); |
|
50 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
51 | + $subject = $this->l->t('{actor} shared as public link'); |
|
52 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
53 | + $subject = $this->l->t('{actor} removed public link'); |
|
54 | + } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
55 | + $subject = $this->l->t('Public link of {actor} expired'); |
|
56 | + |
|
57 | + } else { |
|
58 | + throw new \InvalidArgumentException(); |
|
59 | + } |
|
60 | + |
|
61 | + if ($this->activityManager->getRequirePNG()) { |
|
62 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
63 | + } else { |
|
64 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
65 | + } |
|
66 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
67 | + |
|
68 | + return $event; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param IEvent $event |
|
73 | + * @return IEvent |
|
74 | + * @throws \InvalidArgumentException |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function parseLongVersion(IEvent $event) { |
|
78 | + $parsedParameters = $this->getParsedParameters($event); |
|
79 | + |
|
80 | + if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
81 | + $subject = $this->l->t('You shared {file} as public link'); |
|
82 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
83 | + $subject = $this->l->t('You removed public link for {file}'); |
|
84 | + } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
85 | + $subject = $this->l->t('Public link expired for {file}'); |
|
86 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
87 | + $subject = $this->l->t('{actor} shared {file} as public link'); |
|
88 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
89 | + $subject = $this->l->t('{actor} removed public link for {file}'); |
|
90 | + } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
91 | + $subject = $this->l->t('Public link of {actor} for {file} expired'); |
|
92 | + |
|
93 | + } else { |
|
94 | + throw new \InvalidArgumentException(); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->activityManager->getRequirePNG()) { |
|
98 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
99 | + } else { |
|
100 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | + } |
|
102 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
103 | + |
|
104 | + return $event; |
|
105 | + } |
|
106 | + |
|
107 | + protected function getParsedParameters(IEvent $event) { |
|
108 | + $subject = $event->getSubject(); |
|
109 | + $parameters = $event->getSubjectParameters(); |
|
110 | + |
|
111 | + switch ($subject) { |
|
112 | + case self::SUBJECT_SHARED_LINK_SELF: |
|
113 | + case self::SUBJECT_UNSHARED_LINK_SELF: |
|
114 | + case self::SUBJECT_LINK_EXPIRED: |
|
115 | + return [ |
|
116 | + 'file' => $this->getFile($parameters[0], $event), |
|
117 | + ]; |
|
118 | + case self::SUBJECT_RESHARED_LINK_BY: |
|
119 | + case self::SUBJECT_UNSHARED_LINK_BY: |
|
120 | + case self::SUBJECT_LINK_BY_EXPIRED: |
|
121 | + return [ |
|
122 | + 'file' => $this->getFile($parameters[0], $event), |
|
123 | + 'actor' => $this->getUser($parameters[1]), |
|
124 | + ]; |
|
125 | + } |
|
126 | + return []; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -26,97 +26,97 @@ |
||
26 | 26 | class Downloads extends Base { |
27 | 27 | |
28 | 28 | |
29 | - const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; |
|
30 | - const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; |
|
31 | - |
|
32 | - const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; |
|
33 | - const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param IEvent $event |
|
37 | - * @return IEvent |
|
38 | - * @throws \InvalidArgumentException |
|
39 | - * @since 11.0.0 |
|
40 | - */ |
|
41 | - public function parseShortVersion(IEvent $event) { |
|
42 | - $parsedParameters = $this->getParsedParameters($event); |
|
43 | - |
|
44 | - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
45 | - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
46 | - $subject = $this->l->t('Downloaded via public link'); |
|
47 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
48 | - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
49 | - $subject = $this->l->t('Downloaded by {email}'); |
|
50 | - } else { |
|
51 | - throw new \InvalidArgumentException(); |
|
52 | - } |
|
53 | - |
|
54 | - if ($this->activityManager->getRequirePNG()) { |
|
55 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
56 | - } else { |
|
57 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
58 | - } |
|
59 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
60 | - |
|
61 | - return $event; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IEvent $event |
|
66 | - * @return IEvent |
|
67 | - * @throws \InvalidArgumentException |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function parseLongVersion(IEvent $event) { |
|
71 | - $parsedParameters = $this->getParsedParameters($event); |
|
72 | - |
|
73 | - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
74 | - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
75 | - $subject = $this->l->t('{file} downloaded via public link'); |
|
76 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
77 | - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
78 | - $subject = $this->l->t('{email} downloaded {file}'); |
|
79 | - } else { |
|
80 | - throw new \InvalidArgumentException(); |
|
81 | - } |
|
82 | - |
|
83 | - if ($this->activityManager->getRequirePNG()) { |
|
84 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
85 | - } else { |
|
86 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
87 | - } |
|
88 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
89 | - |
|
90 | - return $event; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param IEvent $event |
|
95 | - * @return array |
|
96 | - * @throws \InvalidArgumentException |
|
97 | - */ |
|
98 | - protected function getParsedParameters(IEvent $event) { |
|
99 | - $subject = $event->getSubject(); |
|
100 | - $parameters = $event->getSubjectParameters(); |
|
101 | - |
|
102 | - switch ($subject) { |
|
103 | - case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: |
|
104 | - case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: |
|
105 | - return [ |
|
106 | - 'file' => $this->getFile($parameters[0], $event), |
|
107 | - ]; |
|
108 | - case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: |
|
109 | - case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: |
|
110 | - return [ |
|
111 | - 'file' => $this->getFile($parameters[0], $event), |
|
112 | - 'email' => [ |
|
113 | - 'type' => 'email', |
|
114 | - 'id' => $parameters[1], |
|
115 | - 'name' => $parameters[1], |
|
116 | - ], |
|
117 | - ]; |
|
118 | - } |
|
119 | - |
|
120 | - throw new \InvalidArgumentException(); |
|
121 | - } |
|
29 | + const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; |
|
30 | + const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; |
|
31 | + |
|
32 | + const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; |
|
33 | + const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param IEvent $event |
|
37 | + * @return IEvent |
|
38 | + * @throws \InvalidArgumentException |
|
39 | + * @since 11.0.0 |
|
40 | + */ |
|
41 | + public function parseShortVersion(IEvent $event) { |
|
42 | + $parsedParameters = $this->getParsedParameters($event); |
|
43 | + |
|
44 | + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
45 | + $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
46 | + $subject = $this->l->t('Downloaded via public link'); |
|
47 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
48 | + $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
49 | + $subject = $this->l->t('Downloaded by {email}'); |
|
50 | + } else { |
|
51 | + throw new \InvalidArgumentException(); |
|
52 | + } |
|
53 | + |
|
54 | + if ($this->activityManager->getRequirePNG()) { |
|
55 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
56 | + } else { |
|
57 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
58 | + } |
|
59 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
60 | + |
|
61 | + return $event; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IEvent $event |
|
66 | + * @return IEvent |
|
67 | + * @throws \InvalidArgumentException |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function parseLongVersion(IEvent $event) { |
|
71 | + $parsedParameters = $this->getParsedParameters($event); |
|
72 | + |
|
73 | + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
74 | + $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
75 | + $subject = $this->l->t('{file} downloaded via public link'); |
|
76 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
77 | + $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
78 | + $subject = $this->l->t('{email} downloaded {file}'); |
|
79 | + } else { |
|
80 | + throw new \InvalidArgumentException(); |
|
81 | + } |
|
82 | + |
|
83 | + if ($this->activityManager->getRequirePNG()) { |
|
84 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
85 | + } else { |
|
86 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
87 | + } |
|
88 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
89 | + |
|
90 | + return $event; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param IEvent $event |
|
95 | + * @return array |
|
96 | + * @throws \InvalidArgumentException |
|
97 | + */ |
|
98 | + protected function getParsedParameters(IEvent $event) { |
|
99 | + $subject = $event->getSubject(); |
|
100 | + $parameters = $event->getSubjectParameters(); |
|
101 | + |
|
102 | + switch ($subject) { |
|
103 | + case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: |
|
104 | + case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: |
|
105 | + return [ |
|
106 | + 'file' => $this->getFile($parameters[0], $event), |
|
107 | + ]; |
|
108 | + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: |
|
109 | + case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: |
|
110 | + return [ |
|
111 | + 'file' => $this->getFile($parameters[0], $event), |
|
112 | + 'email' => [ |
|
113 | + 'type' => 'email', |
|
114 | + 'id' => $parameters[1], |
|
115 | + 'name' => $parameters[1], |
|
116 | + ], |
|
117 | + ]; |
|
118 | + } |
|
119 | + |
|
120 | + throw new \InvalidArgumentException(); |
|
121 | + } |
|
122 | 122 | } |