@@ -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 | } |
@@ -34,213 +34,213 @@ |
||
34 | 34 | |
35 | 35 | class Provider implements IProvider { |
36 | 36 | |
37 | - /** @var IFactory */ |
|
38 | - protected $languageFactory; |
|
39 | - |
|
40 | - /** @var IL10N */ |
|
41 | - protected $l; |
|
42 | - |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $url; |
|
45 | - |
|
46 | - /** @var ICommentsManager */ |
|
47 | - protected $commentsManager; |
|
48 | - |
|
49 | - /** @var IUserManager */ |
|
50 | - protected $userManager; |
|
51 | - |
|
52 | - /** @var IManager */ |
|
53 | - protected $activityManager; |
|
54 | - |
|
55 | - /** @var string[] */ |
|
56 | - protected $displayNames = []; |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IFactory $languageFactory |
|
60 | - * @param IURLGenerator $url |
|
61 | - * @param ICommentsManager $commentsManager |
|
62 | - * @param IUserManager $userManager |
|
63 | - * @param IManager $activityManager |
|
64 | - */ |
|
65 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) { |
|
66 | - $this->languageFactory = $languageFactory; |
|
67 | - $this->url = $url; |
|
68 | - $this->commentsManager = $commentsManager; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->activityManager = $activityManager; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $language |
|
75 | - * @param IEvent $event |
|
76 | - * @param IEvent|null $previousEvent |
|
77 | - * @return IEvent |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @since 11.0.0 |
|
80 | - */ |
|
81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | - if ($event->getApp() !== 'comments') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('comments', $language); |
|
87 | - |
|
88 | - if ($event->getSubject() === 'add_comment_subject') { |
|
89 | - $this->parseMessage($event); |
|
90 | - if ($this->activityManager->getRequirePNG()) { |
|
91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png'))); |
|
92 | - } else { |
|
93 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))); |
|
94 | - } |
|
95 | - |
|
96 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
97 | - try { |
|
98 | - return $this->parseShortVersion($event); |
|
99 | - } catch (\InvalidArgumentException $e) { |
|
100 | - // Ignore and simply use the long version... |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - return $this->parseLongVersion($event); |
|
105 | - } else { |
|
106 | - throw new \InvalidArgumentException(); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param IEvent $event |
|
112 | - * @return IEvent |
|
113 | - * @throws \InvalidArgumentException |
|
114 | - */ |
|
115 | - protected function parseShortVersion(IEvent $event) { |
|
116 | - $subjectParameters = $event->getSubjectParameters(); |
|
117 | - |
|
118 | - if ($event->getSubject() === 'add_comment_subject') { |
|
119 | - if ($subjectParameters[0] === $this->activityManager->getCurrentUserId()) { |
|
120 | - $event->setParsedSubject($this->l->t('You commented')) |
|
121 | - ->setRichSubject($this->l->t('You commented'), []); |
|
122 | - } else { |
|
123 | - $author = $this->generateUserParameter($subjectParameters[0]); |
|
124 | - $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']])) |
|
125 | - ->setRichSubject($this->l->t('{author} commented'), [ |
|
126 | - 'author' => $author, |
|
127 | - ]); |
|
128 | - } |
|
129 | - } else { |
|
130 | - throw new \InvalidArgumentException(); |
|
131 | - } |
|
132 | - |
|
133 | - return $event; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param IEvent $event |
|
138 | - * @return IEvent |
|
139 | - * @throws \InvalidArgumentException |
|
140 | - */ |
|
141 | - protected function parseLongVersion(IEvent $event) { |
|
142 | - $subjectParameters = $event->getSubjectParameters(); |
|
143 | - |
|
144 | - if ($event->getSubject() === 'add_comment_subject') { |
|
145 | - if ($subjectParameters[0] === $this->activityManager->getCurrentUserId()) { |
|
146 | - $event->setParsedSubject($this->l->t('You commented on %1$s', [ |
|
147 | - trim($subjectParameters[1], '/'), |
|
148 | - ])) |
|
149 | - ->setRichSubject($this->l->t('You commented on {file}'), [ |
|
150 | - 'file' => $this->generateFileParameter($event->getObjectId(), $subjectParameters[1]), |
|
151 | - ]); |
|
152 | - } else { |
|
153 | - $author = $this->generateUserParameter($subjectParameters[0]); |
|
154 | - $event->setParsedSubject($this->l->t('%1$s commented on %2$s', [ |
|
155 | - $author['name'], |
|
156 | - trim($subjectParameters[1], '/'), |
|
157 | - ])) |
|
158 | - ->setRichSubject($this->l->t('{author} commented on {file}'), [ |
|
159 | - 'author' => $author, |
|
160 | - 'file' => $this->generateFileParameter($event->getObjectId(), $subjectParameters[1]), |
|
161 | - ]); |
|
162 | - } |
|
163 | - } else { |
|
164 | - throw new \InvalidArgumentException(); |
|
165 | - } |
|
166 | - |
|
167 | - return $event; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param IEvent $event |
|
172 | - */ |
|
173 | - protected function parseMessage(IEvent $event) { |
|
174 | - $messageParameters = $event->getMessageParameters(); |
|
175 | - try { |
|
176 | - $comment = $this->commentsManager->get((int) $messageParameters[0]); |
|
177 | - $message = $comment->getMessage(); |
|
178 | - $message = str_replace("\n", '<br />', str_replace(['<', '>'], ['<', '>'], $message)); |
|
179 | - |
|
180 | - $mentionCount = 1; |
|
181 | - $mentions = []; |
|
182 | - foreach ($comment->getMentions() as $mention) { |
|
183 | - if ($mention['type'] !== 'user') { |
|
184 | - continue; |
|
185 | - } |
|
186 | - |
|
187 | - $message = preg_replace( |
|
188 | - '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/', |
|
189 | - //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}', |
|
190 | - '${1}' . '{mention' . $mentionCount . '}' . '${3}', |
|
191 | - $message |
|
192 | - ); |
|
193 | - $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']); |
|
194 | - $mentionCount++; |
|
195 | - } |
|
196 | - |
|
197 | - $event->setParsedMessage($comment->getMessage()) |
|
198 | - ->setRichMessage($message, $mentions); |
|
199 | - } catch (NotFoundException $e) { |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param int $id |
|
205 | - * @param string $path |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - protected function generateFileParameter($id, $path) { |
|
209 | - return [ |
|
210 | - 'type' => 'file', |
|
211 | - 'id' => $id, |
|
212 | - 'name' => basename($path), |
|
213 | - 'path' => trim($path, '/'), |
|
214 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
215 | - ]; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @param string $uid |
|
220 | - * @return array |
|
221 | - */ |
|
222 | - protected function generateUserParameter($uid) { |
|
223 | - if (!isset($this->displayNames[$uid])) { |
|
224 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
225 | - } |
|
226 | - |
|
227 | - return [ |
|
228 | - 'type' => 'user', |
|
229 | - 'id' => $uid, |
|
230 | - 'name' => $this->displayNames[$uid], |
|
231 | - ]; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @param string $uid |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - protected function getDisplayName($uid) { |
|
239 | - $user = $this->userManager->get($uid); |
|
240 | - if ($user instanceof IUser) { |
|
241 | - return $user->getDisplayName(); |
|
242 | - } else { |
|
243 | - return $uid; |
|
244 | - } |
|
245 | - } |
|
37 | + /** @var IFactory */ |
|
38 | + protected $languageFactory; |
|
39 | + |
|
40 | + /** @var IL10N */ |
|
41 | + protected $l; |
|
42 | + |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $url; |
|
45 | + |
|
46 | + /** @var ICommentsManager */ |
|
47 | + protected $commentsManager; |
|
48 | + |
|
49 | + /** @var IUserManager */ |
|
50 | + protected $userManager; |
|
51 | + |
|
52 | + /** @var IManager */ |
|
53 | + protected $activityManager; |
|
54 | + |
|
55 | + /** @var string[] */ |
|
56 | + protected $displayNames = []; |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IFactory $languageFactory |
|
60 | + * @param IURLGenerator $url |
|
61 | + * @param ICommentsManager $commentsManager |
|
62 | + * @param IUserManager $userManager |
|
63 | + * @param IManager $activityManager |
|
64 | + */ |
|
65 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) { |
|
66 | + $this->languageFactory = $languageFactory; |
|
67 | + $this->url = $url; |
|
68 | + $this->commentsManager = $commentsManager; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->activityManager = $activityManager; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $language |
|
75 | + * @param IEvent $event |
|
76 | + * @param IEvent|null $previousEvent |
|
77 | + * @return IEvent |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @since 11.0.0 |
|
80 | + */ |
|
81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | + if ($event->getApp() !== 'comments') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('comments', $language); |
|
87 | + |
|
88 | + if ($event->getSubject() === 'add_comment_subject') { |
|
89 | + $this->parseMessage($event); |
|
90 | + if ($this->activityManager->getRequirePNG()) { |
|
91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png'))); |
|
92 | + } else { |
|
93 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))); |
|
94 | + } |
|
95 | + |
|
96 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
97 | + try { |
|
98 | + return $this->parseShortVersion($event); |
|
99 | + } catch (\InvalidArgumentException $e) { |
|
100 | + // Ignore and simply use the long version... |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + return $this->parseLongVersion($event); |
|
105 | + } else { |
|
106 | + throw new \InvalidArgumentException(); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param IEvent $event |
|
112 | + * @return IEvent |
|
113 | + * @throws \InvalidArgumentException |
|
114 | + */ |
|
115 | + protected function parseShortVersion(IEvent $event) { |
|
116 | + $subjectParameters = $event->getSubjectParameters(); |
|
117 | + |
|
118 | + if ($event->getSubject() === 'add_comment_subject') { |
|
119 | + if ($subjectParameters[0] === $this->activityManager->getCurrentUserId()) { |
|
120 | + $event->setParsedSubject($this->l->t('You commented')) |
|
121 | + ->setRichSubject($this->l->t('You commented'), []); |
|
122 | + } else { |
|
123 | + $author = $this->generateUserParameter($subjectParameters[0]); |
|
124 | + $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']])) |
|
125 | + ->setRichSubject($this->l->t('{author} commented'), [ |
|
126 | + 'author' => $author, |
|
127 | + ]); |
|
128 | + } |
|
129 | + } else { |
|
130 | + throw new \InvalidArgumentException(); |
|
131 | + } |
|
132 | + |
|
133 | + return $event; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param IEvent $event |
|
138 | + * @return IEvent |
|
139 | + * @throws \InvalidArgumentException |
|
140 | + */ |
|
141 | + protected function parseLongVersion(IEvent $event) { |
|
142 | + $subjectParameters = $event->getSubjectParameters(); |
|
143 | + |
|
144 | + if ($event->getSubject() === 'add_comment_subject') { |
|
145 | + if ($subjectParameters[0] === $this->activityManager->getCurrentUserId()) { |
|
146 | + $event->setParsedSubject($this->l->t('You commented on %1$s', [ |
|
147 | + trim($subjectParameters[1], '/'), |
|
148 | + ])) |
|
149 | + ->setRichSubject($this->l->t('You commented on {file}'), [ |
|
150 | + 'file' => $this->generateFileParameter($event->getObjectId(), $subjectParameters[1]), |
|
151 | + ]); |
|
152 | + } else { |
|
153 | + $author = $this->generateUserParameter($subjectParameters[0]); |
|
154 | + $event->setParsedSubject($this->l->t('%1$s commented on %2$s', [ |
|
155 | + $author['name'], |
|
156 | + trim($subjectParameters[1], '/'), |
|
157 | + ])) |
|
158 | + ->setRichSubject($this->l->t('{author} commented on {file}'), [ |
|
159 | + 'author' => $author, |
|
160 | + 'file' => $this->generateFileParameter($event->getObjectId(), $subjectParameters[1]), |
|
161 | + ]); |
|
162 | + } |
|
163 | + } else { |
|
164 | + throw new \InvalidArgumentException(); |
|
165 | + } |
|
166 | + |
|
167 | + return $event; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param IEvent $event |
|
172 | + */ |
|
173 | + protected function parseMessage(IEvent $event) { |
|
174 | + $messageParameters = $event->getMessageParameters(); |
|
175 | + try { |
|
176 | + $comment = $this->commentsManager->get((int) $messageParameters[0]); |
|
177 | + $message = $comment->getMessage(); |
|
178 | + $message = str_replace("\n", '<br />', str_replace(['<', '>'], ['<', '>'], $message)); |
|
179 | + |
|
180 | + $mentionCount = 1; |
|
181 | + $mentions = []; |
|
182 | + foreach ($comment->getMentions() as $mention) { |
|
183 | + if ($mention['type'] !== 'user') { |
|
184 | + continue; |
|
185 | + } |
|
186 | + |
|
187 | + $message = preg_replace( |
|
188 | + '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/', |
|
189 | + //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}', |
|
190 | + '${1}' . '{mention' . $mentionCount . '}' . '${3}', |
|
191 | + $message |
|
192 | + ); |
|
193 | + $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']); |
|
194 | + $mentionCount++; |
|
195 | + } |
|
196 | + |
|
197 | + $event->setParsedMessage($comment->getMessage()) |
|
198 | + ->setRichMessage($message, $mentions); |
|
199 | + } catch (NotFoundException $e) { |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param int $id |
|
205 | + * @param string $path |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + protected function generateFileParameter($id, $path) { |
|
209 | + return [ |
|
210 | + 'type' => 'file', |
|
211 | + 'id' => $id, |
|
212 | + 'name' => basename($path), |
|
213 | + 'path' => trim($path, '/'), |
|
214 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
215 | + ]; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @param string $uid |
|
220 | + * @return array |
|
221 | + */ |
|
222 | + protected function generateUserParameter($uid) { |
|
223 | + if (!isset($this->displayNames[$uid])) { |
|
224 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
225 | + } |
|
226 | + |
|
227 | + return [ |
|
228 | + 'type' => 'user', |
|
229 | + 'id' => $uid, |
|
230 | + 'name' => $this->displayNames[$uid], |
|
231 | + ]; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @param string $uid |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + protected function getDisplayName($uid) { |
|
239 | + $user = $this->userManager->get($uid); |
|
240 | + if ($user instanceof IUser) { |
|
241 | + return $user->getDisplayName(); |
|
242 | + } else { |
|
243 | + return $uid; |
|
244 | + } |
|
245 | + } |
|
246 | 246 | } |
@@ -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 | } |
@@ -32,311 +32,311 @@ |
||
32 | 32 | |
33 | 33 | class Provider implements IProvider { |
34 | 34 | |
35 | - const CREATE_TAG = 'create_tag'; |
|
36 | - const UPDATE_TAG = 'update_tag'; |
|
37 | - const DELETE_TAG = 'delete_tag'; |
|
38 | - |
|
39 | - const ASSIGN_TAG = 'assign_tag'; |
|
40 | - const UNASSIGN_TAG = 'unassign_tag'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IManager */ |
|
52 | - protected $activityManager; |
|
53 | - |
|
54 | - /** @var IUserManager */ |
|
55 | - protected $userManager; |
|
56 | - |
|
57 | - /** @var string[] */ |
|
58 | - protected $displayNames = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IFactory $languageFactory |
|
62 | - * @param IURLGenerator $url |
|
63 | - * @param IManager $activityManager |
|
64 | - * @param IUserManager $userManager |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
69 | - $this->activityManager = $activityManager; |
|
70 | - $this->userManager = $userManager; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $language |
|
75 | - * @param IEvent $event |
|
76 | - * @param IEvent|null $previousEvent |
|
77 | - * @return IEvent |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @since 11.0.0 |
|
80 | - */ |
|
81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | - if ($event->getApp() !== 'systemtags') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('systemtags', $language); |
|
87 | - |
|
88 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
89 | - try { |
|
90 | - return $this->parseShortVersion($event); |
|
91 | - } catch (\InvalidArgumentException $e) { |
|
92 | - // Ignore and simply use the long version... |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return $this->parseLongVersion($event); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IEvent $event |
|
101 | - * @return IEvent |
|
102 | - * @throws \InvalidArgumentException |
|
103 | - * @since 11.0.0 |
|
104 | - */ |
|
105 | - public function parseShortVersion(IEvent $event) { |
|
106 | - $parsedParameters = $this->getParameters($event); |
|
107 | - |
|
108 | - if ($this->activityManager->getRequirePNG()) { |
|
109 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
110 | - } else { |
|
111 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
112 | - } |
|
113 | - |
|
114 | - if ($event->getSubject() === self::ASSIGN_TAG) { |
|
115 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
116 | - $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
117 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
118 | - ])) |
|
119 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
120 | - 'systemtag' => $parsedParameters['systemtag'], |
|
121 | - ]); |
|
122 | - } else { |
|
123 | - $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
124 | - $parsedParameters['actor']['name'], |
|
125 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
126 | - ])) |
|
127 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
128 | - 'actor' => $parsedParameters['actor'], |
|
129 | - 'systemtag' => $parsedParameters['systemtag'], |
|
130 | - ]); |
|
131 | - } |
|
132 | - } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
133 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
134 | - $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
135 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
136 | - ])) |
|
137 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
138 | - 'systemtag' => $parsedParameters['systemtag'], |
|
139 | - ]); |
|
140 | - } else { |
|
141 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
142 | - $parsedParameters['actor']['name'], |
|
143 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
144 | - ])) |
|
145 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
146 | - 'actor' => $parsedParameters['actor'], |
|
147 | - 'systemtag' => $parsedParameters['systemtag'], |
|
148 | - ]); |
|
149 | - } |
|
150 | - } else { |
|
151 | - throw new \InvalidArgumentException(); |
|
152 | - } |
|
153 | - |
|
154 | - return $event; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param IEvent $event |
|
159 | - * @return IEvent |
|
160 | - * @throws \InvalidArgumentException |
|
161 | - * @since 11.0.0 |
|
162 | - */ |
|
163 | - public function parseLongVersion(IEvent $event) { |
|
164 | - $parsedParameters = $this->getParameters($event); |
|
165 | - |
|
166 | - if ($this->activityManager->getRequirePNG()) { |
|
167 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
168 | - } else { |
|
169 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
170 | - } |
|
171 | - |
|
172 | - if ($event->getSubject() === self::CREATE_TAG) { |
|
173 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
174 | - $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
175 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
176 | - ])) |
|
177 | - ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
178 | - } else { |
|
179 | - $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
180 | - $parsedParameters['actor']['name'], |
|
181 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
182 | - ])) |
|
183 | - ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
184 | - } |
|
185 | - } else if ($event->getSubject() === self::DELETE_TAG) { |
|
186 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
187 | - $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
188 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
189 | - ])) |
|
190 | - ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
191 | - } else { |
|
192 | - $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
193 | - $parsedParameters['actor']['name'], |
|
194 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
195 | - ])) |
|
196 | - ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
197 | - } |
|
198 | - } else if ($event->getSubject() === self::UPDATE_TAG) { |
|
199 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
200 | - $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
201 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
202 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
203 | - ])) |
|
204 | - ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
205 | - } else { |
|
206 | - $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
207 | - $parsedParameters['actor']['name'], |
|
208 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
209 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
210 | - ])) |
|
211 | - ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
212 | - } |
|
213 | - } else if ($event->getSubject() === self::ASSIGN_TAG) { |
|
214 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
215 | - $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
216 | - $parsedParameters['file']['path'], |
|
217 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
218 | - ])) |
|
219 | - ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
220 | - } else { |
|
221 | - $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
222 | - $parsedParameters['actor']['name'], |
|
223 | - $parsedParameters['file']['path'], |
|
224 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
225 | - ])) |
|
226 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
227 | - } |
|
228 | - } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
229 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
230 | - $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
231 | - $parsedParameters['file']['path'], |
|
232 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
233 | - ])) |
|
234 | - ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
235 | - } else { |
|
236 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
237 | - $parsedParameters['actor']['name'], |
|
238 | - $parsedParameters['file']['path'], |
|
239 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
240 | - ])) |
|
241 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
242 | - } |
|
243 | - } else { |
|
244 | - throw new \InvalidArgumentException(); |
|
245 | - } |
|
246 | - |
|
247 | - return $event; |
|
248 | - } |
|
249 | - |
|
250 | - protected function getParameters(IEvent $event) { |
|
251 | - $subject = $event->getSubject(); |
|
252 | - $parameters = $event->getSubjectParameters(); |
|
253 | - |
|
254 | - switch ($subject) { |
|
255 | - case self::CREATE_TAG: |
|
256 | - case self::DELETE_TAG: |
|
257 | - return [ |
|
258 | - 'actor' => $this->getUserParameter($parameters[0]), |
|
259 | - 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
260 | - ]; |
|
261 | - case self::UPDATE_TAG: |
|
262 | - return [ |
|
263 | - 'actor' => $this->getUserParameter($parameters[0]), |
|
264 | - 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
265 | - 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
266 | - ]; |
|
267 | - case self::ASSIGN_TAG: |
|
268 | - case self::UNASSIGN_TAG: |
|
269 | - return [ |
|
270 | - 'actor' => $this->getUserParameter($parameters[0]), |
|
271 | - 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
272 | - 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
273 | - ]; |
|
274 | - } |
|
275 | - return []; |
|
276 | - } |
|
277 | - |
|
278 | - protected function getFileParameter($id, $path) { |
|
279 | - return [ |
|
280 | - 'type' => 'file', |
|
281 | - 'id' => $id, |
|
282 | - 'name' => basename($path), |
|
283 | - 'path' => trim($path, '/'), |
|
284 | - ]; |
|
285 | - } |
|
286 | - |
|
287 | - protected function getSystemTagParameter($parameter) { |
|
288 | - $tagData = json_decode($parameter, true); |
|
289 | - if ($tagData === null) { |
|
290 | - list($name, $status) = explode('|||', substr($parameter, 3, -3)); |
|
291 | - $tagData = [ |
|
292 | - 'id' => 0,// No way to recover the ID |
|
293 | - 'name' => $name, |
|
294 | - 'assignable' => $status === 'assignable', |
|
295 | - 'visible' => $status !== 'invisible', |
|
296 | - ]; |
|
297 | - } |
|
298 | - |
|
299 | - return [ |
|
300 | - 'type' => 'systemtag', |
|
301 | - 'id' => (int) $tagData['id'], |
|
302 | - 'name' => $tagData['name'], |
|
303 | - 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
304 | - 'visibility' => $tagData['visible'] ? '1' : '0', |
|
305 | - ]; |
|
306 | - } |
|
307 | - |
|
308 | - protected function getUserParameter($uid) { |
|
309 | - if (!isset($this->displayNames[$uid])) { |
|
310 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
311 | - } |
|
312 | - |
|
313 | - return [ |
|
314 | - 'type' => 'user', |
|
315 | - 'id' => $uid, |
|
316 | - 'name' => $this->displayNames[$uid], |
|
317 | - ]; |
|
318 | - } |
|
319 | - |
|
320 | - protected function generatePlainSystemTag(array $parameter) { |
|
321 | - if ($parameter['assignable'] === '1') { |
|
322 | - return $parameter['name']; |
|
323 | - } else if ($parameter['visibility'] === '1') { |
|
324 | - return $this->l->t('%s (restricted)', $parameter['name']); |
|
325 | - } else { |
|
326 | - return $this->l->t('%s (invisible)', $parameter['name']); |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $uid |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - protected function getDisplayName($uid) { |
|
335 | - $user = $this->userManager->get($uid); |
|
336 | - if ($user instanceof IUser) { |
|
337 | - return $user->getDisplayName(); |
|
338 | - } else { |
|
339 | - return $uid; |
|
340 | - } |
|
341 | - } |
|
35 | + const CREATE_TAG = 'create_tag'; |
|
36 | + const UPDATE_TAG = 'update_tag'; |
|
37 | + const DELETE_TAG = 'delete_tag'; |
|
38 | + |
|
39 | + const ASSIGN_TAG = 'assign_tag'; |
|
40 | + const UNASSIGN_TAG = 'unassign_tag'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IManager */ |
|
52 | + protected $activityManager; |
|
53 | + |
|
54 | + /** @var IUserManager */ |
|
55 | + protected $userManager; |
|
56 | + |
|
57 | + /** @var string[] */ |
|
58 | + protected $displayNames = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IFactory $languageFactory |
|
62 | + * @param IURLGenerator $url |
|
63 | + * @param IManager $activityManager |
|
64 | + * @param IUserManager $userManager |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
69 | + $this->activityManager = $activityManager; |
|
70 | + $this->userManager = $userManager; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $language |
|
75 | + * @param IEvent $event |
|
76 | + * @param IEvent|null $previousEvent |
|
77 | + * @return IEvent |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @since 11.0.0 |
|
80 | + */ |
|
81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | + if ($event->getApp() !== 'systemtags') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('systemtags', $language); |
|
87 | + |
|
88 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
89 | + try { |
|
90 | + return $this->parseShortVersion($event); |
|
91 | + } catch (\InvalidArgumentException $e) { |
|
92 | + // Ignore and simply use the long version... |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return $this->parseLongVersion($event); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IEvent $event |
|
101 | + * @return IEvent |
|
102 | + * @throws \InvalidArgumentException |
|
103 | + * @since 11.0.0 |
|
104 | + */ |
|
105 | + public function parseShortVersion(IEvent $event) { |
|
106 | + $parsedParameters = $this->getParameters($event); |
|
107 | + |
|
108 | + if ($this->activityManager->getRequirePNG()) { |
|
109 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
110 | + } else { |
|
111 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
112 | + } |
|
113 | + |
|
114 | + if ($event->getSubject() === self::ASSIGN_TAG) { |
|
115 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
116 | + $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
117 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
118 | + ])) |
|
119 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
120 | + 'systemtag' => $parsedParameters['systemtag'], |
|
121 | + ]); |
|
122 | + } else { |
|
123 | + $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
124 | + $parsedParameters['actor']['name'], |
|
125 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
126 | + ])) |
|
127 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
128 | + 'actor' => $parsedParameters['actor'], |
|
129 | + 'systemtag' => $parsedParameters['systemtag'], |
|
130 | + ]); |
|
131 | + } |
|
132 | + } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
133 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
134 | + $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
135 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
136 | + ])) |
|
137 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
138 | + 'systemtag' => $parsedParameters['systemtag'], |
|
139 | + ]); |
|
140 | + } else { |
|
141 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
142 | + $parsedParameters['actor']['name'], |
|
143 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
144 | + ])) |
|
145 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
146 | + 'actor' => $parsedParameters['actor'], |
|
147 | + 'systemtag' => $parsedParameters['systemtag'], |
|
148 | + ]); |
|
149 | + } |
|
150 | + } else { |
|
151 | + throw new \InvalidArgumentException(); |
|
152 | + } |
|
153 | + |
|
154 | + return $event; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param IEvent $event |
|
159 | + * @return IEvent |
|
160 | + * @throws \InvalidArgumentException |
|
161 | + * @since 11.0.0 |
|
162 | + */ |
|
163 | + public function parseLongVersion(IEvent $event) { |
|
164 | + $parsedParameters = $this->getParameters($event); |
|
165 | + |
|
166 | + if ($this->activityManager->getRequirePNG()) { |
|
167 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
168 | + } else { |
|
169 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
170 | + } |
|
171 | + |
|
172 | + if ($event->getSubject() === self::CREATE_TAG) { |
|
173 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
174 | + $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
175 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
176 | + ])) |
|
177 | + ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
178 | + } else { |
|
179 | + $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
180 | + $parsedParameters['actor']['name'], |
|
181 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
182 | + ])) |
|
183 | + ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
184 | + } |
|
185 | + } else if ($event->getSubject() === self::DELETE_TAG) { |
|
186 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
187 | + $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
188 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
189 | + ])) |
|
190 | + ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
191 | + } else { |
|
192 | + $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
193 | + $parsedParameters['actor']['name'], |
|
194 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
195 | + ])) |
|
196 | + ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
197 | + } |
|
198 | + } else if ($event->getSubject() === self::UPDATE_TAG) { |
|
199 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
200 | + $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
201 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
202 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
203 | + ])) |
|
204 | + ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
205 | + } else { |
|
206 | + $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
207 | + $parsedParameters['actor']['name'], |
|
208 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
209 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
210 | + ])) |
|
211 | + ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
212 | + } |
|
213 | + } else if ($event->getSubject() === self::ASSIGN_TAG) { |
|
214 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
215 | + $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
216 | + $parsedParameters['file']['path'], |
|
217 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
218 | + ])) |
|
219 | + ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
220 | + } else { |
|
221 | + $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
222 | + $parsedParameters['actor']['name'], |
|
223 | + $parsedParameters['file']['path'], |
|
224 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
225 | + ])) |
|
226 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
227 | + } |
|
228 | + } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
229 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
230 | + $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
231 | + $parsedParameters['file']['path'], |
|
232 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
233 | + ])) |
|
234 | + ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
235 | + } else { |
|
236 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
237 | + $parsedParameters['actor']['name'], |
|
238 | + $parsedParameters['file']['path'], |
|
239 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
240 | + ])) |
|
241 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
242 | + } |
|
243 | + } else { |
|
244 | + throw new \InvalidArgumentException(); |
|
245 | + } |
|
246 | + |
|
247 | + return $event; |
|
248 | + } |
|
249 | + |
|
250 | + protected function getParameters(IEvent $event) { |
|
251 | + $subject = $event->getSubject(); |
|
252 | + $parameters = $event->getSubjectParameters(); |
|
253 | + |
|
254 | + switch ($subject) { |
|
255 | + case self::CREATE_TAG: |
|
256 | + case self::DELETE_TAG: |
|
257 | + return [ |
|
258 | + 'actor' => $this->getUserParameter($parameters[0]), |
|
259 | + 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
260 | + ]; |
|
261 | + case self::UPDATE_TAG: |
|
262 | + return [ |
|
263 | + 'actor' => $this->getUserParameter($parameters[0]), |
|
264 | + 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
265 | + 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
266 | + ]; |
|
267 | + case self::ASSIGN_TAG: |
|
268 | + case self::UNASSIGN_TAG: |
|
269 | + return [ |
|
270 | + 'actor' => $this->getUserParameter($parameters[0]), |
|
271 | + 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
272 | + 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
273 | + ]; |
|
274 | + } |
|
275 | + return []; |
|
276 | + } |
|
277 | + |
|
278 | + protected function getFileParameter($id, $path) { |
|
279 | + return [ |
|
280 | + 'type' => 'file', |
|
281 | + 'id' => $id, |
|
282 | + 'name' => basename($path), |
|
283 | + 'path' => trim($path, '/'), |
|
284 | + ]; |
|
285 | + } |
|
286 | + |
|
287 | + protected function getSystemTagParameter($parameter) { |
|
288 | + $tagData = json_decode($parameter, true); |
|
289 | + if ($tagData === null) { |
|
290 | + list($name, $status) = explode('|||', substr($parameter, 3, -3)); |
|
291 | + $tagData = [ |
|
292 | + 'id' => 0,// No way to recover the ID |
|
293 | + 'name' => $name, |
|
294 | + 'assignable' => $status === 'assignable', |
|
295 | + 'visible' => $status !== 'invisible', |
|
296 | + ]; |
|
297 | + } |
|
298 | + |
|
299 | + return [ |
|
300 | + 'type' => 'systemtag', |
|
301 | + 'id' => (int) $tagData['id'], |
|
302 | + 'name' => $tagData['name'], |
|
303 | + 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
304 | + 'visibility' => $tagData['visible'] ? '1' : '0', |
|
305 | + ]; |
|
306 | + } |
|
307 | + |
|
308 | + protected function getUserParameter($uid) { |
|
309 | + if (!isset($this->displayNames[$uid])) { |
|
310 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
311 | + } |
|
312 | + |
|
313 | + return [ |
|
314 | + 'type' => 'user', |
|
315 | + 'id' => $uid, |
|
316 | + 'name' => $this->displayNames[$uid], |
|
317 | + ]; |
|
318 | + } |
|
319 | + |
|
320 | + protected function generatePlainSystemTag(array $parameter) { |
|
321 | + if ($parameter['assignable'] === '1') { |
|
322 | + return $parameter['name']; |
|
323 | + } else if ($parameter['visibility'] === '1') { |
|
324 | + return $this->l->t('%s (restricted)', $parameter['name']); |
|
325 | + } else { |
|
326 | + return $this->l->t('%s (invisible)', $parameter['name']); |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $uid |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + protected function getDisplayName($uid) { |
|
335 | + $user = $this->userManager->get($uid); |
|
336 | + if ($user instanceof IUser) { |
|
337 | + return $user->getDisplayName(); |
|
338 | + } else { |
|
339 | + return $uid; |
|
340 | + } |
|
341 | + } |
|
342 | 342 | } |
@@ -25,100 +25,100 @@ |
||
25 | 25 | |
26 | 26 | class Groups extends Base { |
27 | 27 | |
28 | - const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; |
|
29 | - const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; |
|
30 | - const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; |
|
31 | - const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; |
|
28 | + const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; |
|
29 | + const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; |
|
30 | + const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; |
|
31 | + const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IEvent $event |
|
35 | - * @return IEvent |
|
36 | - * @throws \InvalidArgumentException |
|
37 | - * @since 11.0.0 |
|
38 | - */ |
|
39 | - public function parseShortVersion(IEvent $event) { |
|
40 | - $parsedParameters = $this->getParsedParameters($event); |
|
33 | + /** |
|
34 | + * @param IEvent $event |
|
35 | + * @return IEvent |
|
36 | + * @throws \InvalidArgumentException |
|
37 | + * @since 11.0.0 |
|
38 | + */ |
|
39 | + public function parseShortVersion(IEvent $event) { |
|
40 | + $parsedParameters = $this->getParsedParameters($event); |
|
41 | 41 | |
42 | - if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
43 | - $subject = $this->l->t('Shared with group {group}'); |
|
44 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
45 | - $subject = $this->l->t('Removed share for group {group}'); |
|
46 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
47 | - $subject = $this->l->t('{actor} shared with group {group}'); |
|
48 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
49 | - $subject = $this->l->t('{actor} removed share for group {group}'); |
|
50 | - } else { |
|
51 | - throw new \InvalidArgumentException(); |
|
52 | - } |
|
42 | + if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
43 | + $subject = $this->l->t('Shared with group {group}'); |
|
44 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
45 | + $subject = $this->l->t('Removed share for group {group}'); |
|
46 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
47 | + $subject = $this->l->t('{actor} shared with group {group}'); |
|
48 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
49 | + $subject = $this->l->t('{actor} removed share for group {group}'); |
|
50 | + } else { |
|
51 | + throw new \InvalidArgumentException(); |
|
52 | + } |
|
53 | 53 | |
54 | - if ($this->activityManager->getRequirePNG()) { |
|
55 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
56 | - } else { |
|
57 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
58 | - } |
|
59 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
54 | + if ($this->activityManager->getRequirePNG()) { |
|
55 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
56 | + } else { |
|
57 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
58 | + } |
|
59 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
60 | 60 | |
61 | - return $event; |
|
62 | - } |
|
61 | + return $event; |
|
62 | + } |
|
63 | 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); |
|
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 | 72 | |
73 | - if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
74 | - $subject = $this->l->t('You shared {file} with group {group}'); |
|
75 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
76 | - $subject = $this->l->t('You removed group {group} from {file}'); |
|
77 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
78 | - $subject = $this->l->t('{actor} shared {file} with group {group}'); |
|
79 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
80 | - $subject = $this->l->t('{actor} removed group {group} from {file}'); |
|
81 | - } else { |
|
82 | - throw new \InvalidArgumentException(); |
|
83 | - } |
|
73 | + if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
74 | + $subject = $this->l->t('You shared {file} with group {group}'); |
|
75 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
76 | + $subject = $this->l->t('You removed group {group} from {file}'); |
|
77 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
78 | + $subject = $this->l->t('{actor} shared {file} with group {group}'); |
|
79 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
80 | + $subject = $this->l->t('{actor} removed group {group} from {file}'); |
|
81 | + } else { |
|
82 | + throw new \InvalidArgumentException(); |
|
83 | + } |
|
84 | 84 | |
85 | - if ($this->activityManager->getRequirePNG()) { |
|
86 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
87 | - } else { |
|
88 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
89 | - } |
|
90 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
85 | + if ($this->activityManager->getRequirePNG()) { |
|
86 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
87 | + } else { |
|
88 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
89 | + } |
|
90 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
91 | 91 | |
92 | - return $event; |
|
93 | - } |
|
92 | + return $event; |
|
93 | + } |
|
94 | 94 | |
95 | - protected function getParsedParameters(IEvent $event) { |
|
96 | - $subject = $event->getSubject(); |
|
97 | - $parameters = $event->getSubjectParameters(); |
|
95 | + protected function getParsedParameters(IEvent $event) { |
|
96 | + $subject = $event->getSubject(); |
|
97 | + $parameters = $event->getSubjectParameters(); |
|
98 | 98 | |
99 | - switch ($subject) { |
|
100 | - case self::SUBJECT_RESHARED_GROUP_BY: |
|
101 | - case self::SUBJECT_UNSHARED_GROUP_BY: |
|
102 | - return [ |
|
103 | - 'file' => $this->getFile($parameters[0], $event), |
|
104 | - 'group' => [ |
|
105 | - 'type' => 'group', |
|
106 | - 'id' => $parameters[2], |
|
107 | - 'name' => $parameters[2], |
|
108 | - ], |
|
109 | - 'actor' => $this->getUser($parameters[1]), |
|
110 | - ]; |
|
111 | - case self::SUBJECT_SHARED_GROUP_SELF: |
|
112 | - case self::SUBJECT_UNSHARED_GROUP_SELF: |
|
113 | - return [ |
|
114 | - 'file' => $this->getFile($parameters[0], $event), |
|
115 | - 'group' => [ |
|
116 | - 'type' => 'group', |
|
117 | - 'id' => $parameters[1], |
|
118 | - 'name' => $parameters[1], |
|
119 | - ], |
|
120 | - ]; |
|
121 | - } |
|
122 | - return []; |
|
123 | - } |
|
99 | + switch ($subject) { |
|
100 | + case self::SUBJECT_RESHARED_GROUP_BY: |
|
101 | + case self::SUBJECT_UNSHARED_GROUP_BY: |
|
102 | + return [ |
|
103 | + 'file' => $this->getFile($parameters[0], $event), |
|
104 | + 'group' => [ |
|
105 | + 'type' => 'group', |
|
106 | + 'id' => $parameters[2], |
|
107 | + 'name' => $parameters[2], |
|
108 | + ], |
|
109 | + 'actor' => $this->getUser($parameters[1]), |
|
110 | + ]; |
|
111 | + case self::SUBJECT_SHARED_GROUP_SELF: |
|
112 | + case self::SUBJECT_UNSHARED_GROUP_SELF: |
|
113 | + return [ |
|
114 | + 'file' => $this->getFile($parameters[0], $event), |
|
115 | + 'group' => [ |
|
116 | + 'type' => 'group', |
|
117 | + 'id' => $parameters[1], |
|
118 | + 'name' => $parameters[1], |
|
119 | + ], |
|
120 | + ]; |
|
121 | + } |
|
122 | + return []; |
|
123 | + } |
|
124 | 124 | } |
@@ -26,111 +26,111 @@ |
||
26 | 26 | class Users extends Base { |
27 | 27 | |
28 | 28 | |
29 | - const SUBJECT_SHARED_USER_SELF = 'shared_user_self'; |
|
30 | - const SUBJECT_RESHARED_USER_BY = 'reshared_user_by'; |
|
31 | - const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self'; |
|
32 | - const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by'; |
|
33 | - |
|
34 | - const SUBJECT_SHARED_WITH_BY = 'shared_with_by'; |
|
35 | - const SUBJECT_UNSHARED_BY = 'unshared_by'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @param IEvent $event |
|
39 | - * @return IEvent |
|
40 | - * @throws \InvalidArgumentException |
|
41 | - * @since 11.0.0 |
|
42 | - */ |
|
43 | - public function parseShortVersion(IEvent $event) { |
|
44 | - $parsedParameters = $this->getParsedParameters($event); |
|
45 | - |
|
46 | - if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { |
|
47 | - $subject = $this->l->t('Shared with {user}'); |
|
48 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { |
|
49 | - $subject = $this->l->t('Removed share for {user}'); |
|
50 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { |
|
51 | - $subject = $this->l->t('{actor} shared with {user}'); |
|
52 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { |
|
53 | - $subject = $this->l->t('{actor} removed share for {user}'); |
|
54 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { |
|
55 | - $subject = $this->l->t('Shared by {actor}'); |
|
56 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { |
|
57 | - $subject = $this->l->t('{actor} removed share'); |
|
58 | - |
|
59 | - } else { |
|
60 | - throw new \InvalidArgumentException(); |
|
61 | - } |
|
62 | - |
|
63 | - if ($this->activityManager->getRequirePNG()) { |
|
64 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
65 | - } else { |
|
66 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
67 | - } |
|
68 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
69 | - |
|
70 | - return $event; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param IEvent $event |
|
75 | - * @return IEvent |
|
76 | - * @throws \InvalidArgumentException |
|
77 | - * @since 11.0.0 |
|
78 | - */ |
|
79 | - public function parseLongVersion(IEvent $event) { |
|
80 | - $parsedParameters = $this->getParsedParameters($event); |
|
81 | - |
|
82 | - if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { |
|
83 | - $subject = $this->l->t('You shared {file} with {user}'); |
|
84 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { |
|
85 | - $subject = $this->l->t('You removed {user} from {file}'); |
|
86 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { |
|
87 | - $subject = $this->l->t('{actor} shared {file} with {user}'); |
|
88 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { |
|
89 | - $subject = $this->l->t('{actor} removed {user} from {file}'); |
|
90 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { |
|
91 | - $subject = $this->l->t('{actor} shared {file} with you'); |
|
92 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { |
|
93 | - $subject = $this->l->t('{actor} removed you from {file}'); |
|
94 | - |
|
95 | - } else { |
|
96 | - throw new \InvalidArgumentException(); |
|
97 | - } |
|
98 | - |
|
99 | - if ($this->activityManager->getRequirePNG()) { |
|
100 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
101 | - } else { |
|
102 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
103 | - } |
|
104 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
105 | - |
|
106 | - return $event; |
|
107 | - } |
|
108 | - |
|
109 | - protected function getParsedParameters(IEvent $event) { |
|
110 | - $subject = $event->getSubject(); |
|
111 | - $parameters = $event->getSubjectParameters(); |
|
112 | - |
|
113 | - switch ($subject) { |
|
114 | - case self::SUBJECT_SHARED_USER_SELF: |
|
115 | - case self::SUBJECT_UNSHARED_USER_SELF: |
|
116 | - return [ |
|
117 | - 'file' => $this->getFile($parameters[0], $event), |
|
118 | - 'user' => $this->getUser($parameters[1]), |
|
119 | - ]; |
|
120 | - case self::SUBJECT_SHARED_WITH_BY: |
|
121 | - case self::SUBJECT_UNSHARED_BY: |
|
122 | - return [ |
|
123 | - 'file' => $this->getFile($parameters[0], $event), |
|
124 | - 'actor' => $this->getUser($parameters[1]), |
|
125 | - ]; |
|
126 | - case self::SUBJECT_RESHARED_USER_BY: |
|
127 | - case self::SUBJECT_UNSHARED_USER_BY: |
|
128 | - return [ |
|
129 | - 'file' => $this->getFile($parameters[0], $event), |
|
130 | - 'user' => $this->getUser($parameters[2]), |
|
131 | - 'actor' => $this->getUser($parameters[1]), |
|
132 | - ]; |
|
133 | - } |
|
134 | - return []; |
|
135 | - } |
|
29 | + const SUBJECT_SHARED_USER_SELF = 'shared_user_self'; |
|
30 | + const SUBJECT_RESHARED_USER_BY = 'reshared_user_by'; |
|
31 | + const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self'; |
|
32 | + const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by'; |
|
33 | + |
|
34 | + const SUBJECT_SHARED_WITH_BY = 'shared_with_by'; |
|
35 | + const SUBJECT_UNSHARED_BY = 'unshared_by'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @param IEvent $event |
|
39 | + * @return IEvent |
|
40 | + * @throws \InvalidArgumentException |
|
41 | + * @since 11.0.0 |
|
42 | + */ |
|
43 | + public function parseShortVersion(IEvent $event) { |
|
44 | + $parsedParameters = $this->getParsedParameters($event); |
|
45 | + |
|
46 | + if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { |
|
47 | + $subject = $this->l->t('Shared with {user}'); |
|
48 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { |
|
49 | + $subject = $this->l->t('Removed share for {user}'); |
|
50 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { |
|
51 | + $subject = $this->l->t('{actor} shared with {user}'); |
|
52 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { |
|
53 | + $subject = $this->l->t('{actor} removed share for {user}'); |
|
54 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { |
|
55 | + $subject = $this->l->t('Shared by {actor}'); |
|
56 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { |
|
57 | + $subject = $this->l->t('{actor} removed share'); |
|
58 | + |
|
59 | + } else { |
|
60 | + throw new \InvalidArgumentException(); |
|
61 | + } |
|
62 | + |
|
63 | + if ($this->activityManager->getRequirePNG()) { |
|
64 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
65 | + } else { |
|
66 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
67 | + } |
|
68 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
69 | + |
|
70 | + return $event; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param IEvent $event |
|
75 | + * @return IEvent |
|
76 | + * @throws \InvalidArgumentException |
|
77 | + * @since 11.0.0 |
|
78 | + */ |
|
79 | + public function parseLongVersion(IEvent $event) { |
|
80 | + $parsedParameters = $this->getParsedParameters($event); |
|
81 | + |
|
82 | + if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { |
|
83 | + $subject = $this->l->t('You shared {file} with {user}'); |
|
84 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { |
|
85 | + $subject = $this->l->t('You removed {user} from {file}'); |
|
86 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { |
|
87 | + $subject = $this->l->t('{actor} shared {file} with {user}'); |
|
88 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { |
|
89 | + $subject = $this->l->t('{actor} removed {user} from {file}'); |
|
90 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { |
|
91 | + $subject = $this->l->t('{actor} shared {file} with you'); |
|
92 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { |
|
93 | + $subject = $this->l->t('{actor} removed you from {file}'); |
|
94 | + |
|
95 | + } else { |
|
96 | + throw new \InvalidArgumentException(); |
|
97 | + } |
|
98 | + |
|
99 | + if ($this->activityManager->getRequirePNG()) { |
|
100 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
101 | + } else { |
|
102 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
103 | + } |
|
104 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
105 | + |
|
106 | + return $event; |
|
107 | + } |
|
108 | + |
|
109 | + protected function getParsedParameters(IEvent $event) { |
|
110 | + $subject = $event->getSubject(); |
|
111 | + $parameters = $event->getSubjectParameters(); |
|
112 | + |
|
113 | + switch ($subject) { |
|
114 | + case self::SUBJECT_SHARED_USER_SELF: |
|
115 | + case self::SUBJECT_UNSHARED_USER_SELF: |
|
116 | + return [ |
|
117 | + 'file' => $this->getFile($parameters[0], $event), |
|
118 | + 'user' => $this->getUser($parameters[1]), |
|
119 | + ]; |
|
120 | + case self::SUBJECT_SHARED_WITH_BY: |
|
121 | + case self::SUBJECT_UNSHARED_BY: |
|
122 | + return [ |
|
123 | + 'file' => $this->getFile($parameters[0], $event), |
|
124 | + 'actor' => $this->getUser($parameters[1]), |
|
125 | + ]; |
|
126 | + case self::SUBJECT_RESHARED_USER_BY: |
|
127 | + case self::SUBJECT_UNSHARED_USER_BY: |
|
128 | + return [ |
|
129 | + 'file' => $this->getFile($parameters[0], $event), |
|
130 | + 'user' => $this->getUser($parameters[2]), |
|
131 | + 'actor' => $this->getUser($parameters[1]), |
|
132 | + ]; |
|
133 | + } |
|
134 | + return []; |
|
135 | + } |
|
136 | 136 | } |
@@ -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 | } |
@@ -32,124 +32,124 @@ |
||
32 | 32 | |
33 | 33 | class RemoteShares extends Base { |
34 | 34 | |
35 | - protected $cloudIdManager; |
|
36 | - |
|
37 | - const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; |
|
38 | - const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; |
|
39 | - const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; |
|
40 | - const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IFactory $languageFactory |
|
44 | - * @param IURLGenerator $url |
|
45 | - * @param IManager $activityManager |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param ICloudIdManager $cloudIdManager |
|
48 | - */ |
|
49 | - public function __construct(IFactory $languageFactory, |
|
50 | - IURLGenerator $url, |
|
51 | - IManager $activityManager, |
|
52 | - IUserManager $userManager, |
|
53 | - ICloudIdManager $cloudIdManager |
|
54 | - ) { |
|
55 | - parent::__construct($languageFactory, $url, $activityManager, $userManager); |
|
56 | - $this->cloudIdManager = $cloudIdManager; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IEvent $event |
|
61 | - * @return IEvent |
|
62 | - * @throws \InvalidArgumentException |
|
63 | - * @since 11.0.0 |
|
64 | - */ |
|
65 | - public function parseShortVersion(IEvent $event) { |
|
66 | - $parsedParameters = $this->getParsedParameters($event); |
|
67 | - |
|
68 | - if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
69 | - $subject = $this->l->t('{user} accepted the remote share'); |
|
70 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
71 | - $subject = $this->l->t('{user} declined the remote share'); |
|
72 | - } else { |
|
73 | - throw new \InvalidArgumentException(); |
|
74 | - } |
|
75 | - |
|
76 | - if ($this->activityManager->getRequirePNG()) { |
|
77 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
78 | - } else { |
|
79 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
80 | - } |
|
81 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
82 | - |
|
83 | - return $event; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param IEvent $event |
|
88 | - * @return IEvent |
|
89 | - * @throws \InvalidArgumentException |
|
90 | - * @since 11.0.0 |
|
91 | - */ |
|
92 | - public function parseLongVersion(IEvent $event) { |
|
93 | - $parsedParameters = $this->getParsedParameters($event); |
|
94 | - |
|
95 | - if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { |
|
96 | - $subject = $this->l->t('You received a new remote share {file} from {user}'); |
|
97 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
98 | - $subject = $this->l->t('{user} accepted the remote share of {file}'); |
|
99 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
100 | - $subject = $this->l->t('{user} declined the remote share of {file}'); |
|
101 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { |
|
102 | - $subject = $this->l->t('{user} unshared {file} from you'); |
|
103 | - } else { |
|
104 | - throw new \InvalidArgumentException(); |
|
105 | - } |
|
106 | - |
|
107 | - if ($this->activityManager->getRequirePNG()) { |
|
108 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
109 | - } else { |
|
110 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
111 | - } |
|
112 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
113 | - |
|
114 | - return $event; |
|
115 | - } |
|
116 | - |
|
117 | - protected function getParsedParameters(IEvent $event) { |
|
118 | - $subject = $event->getSubject(); |
|
119 | - $parameters = $event->getSubjectParameters(); |
|
120 | - |
|
121 | - switch ($subject) { |
|
122 | - case self::SUBJECT_REMOTE_SHARE_RECEIVED: |
|
123 | - case self::SUBJECT_REMOTE_SHARE_UNSHARED: |
|
124 | - return [ |
|
125 | - 'file' => [ |
|
126 | - 'type' => 'pending-federated-share', |
|
127 | - 'id' => $parameters[1], |
|
128 | - 'name' => $parameters[1], |
|
129 | - ], |
|
130 | - 'user' => $this->getFederatedUser($parameters[0]), |
|
131 | - ]; |
|
132 | - case self::SUBJECT_REMOTE_SHARE_ACCEPTED: |
|
133 | - case self::SUBJECT_REMOTE_SHARE_DECLINED: |
|
134 | - return [ |
|
135 | - 'file' => $this->getFile([$event->getObjectId() => $event->getObjectName()]), |
|
136 | - 'user' => $this->getFederatedUser($parameters[0]), |
|
137 | - ]; |
|
138 | - } |
|
139 | - throw new \InvalidArgumentException(); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $cloudId |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - protected function getFederatedUser($cloudId) { |
|
147 | - $remoteUser = $this->cloudIdManager->resolveCloudId($cloudId); |
|
148 | - return [ |
|
149 | - 'type' => 'user', |
|
150 | - 'id' => $remoteUser->getUser(), |
|
151 | - 'name' => $cloudId,// Todo display name from contacts |
|
152 | - 'server' => $remoteUser->getRemote(), |
|
153 | - ]; |
|
154 | - } |
|
35 | + protected $cloudIdManager; |
|
36 | + |
|
37 | + const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; |
|
38 | + const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; |
|
39 | + const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; |
|
40 | + const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IFactory $languageFactory |
|
44 | + * @param IURLGenerator $url |
|
45 | + * @param IManager $activityManager |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param ICloudIdManager $cloudIdManager |
|
48 | + */ |
|
49 | + public function __construct(IFactory $languageFactory, |
|
50 | + IURLGenerator $url, |
|
51 | + IManager $activityManager, |
|
52 | + IUserManager $userManager, |
|
53 | + ICloudIdManager $cloudIdManager |
|
54 | + ) { |
|
55 | + parent::__construct($languageFactory, $url, $activityManager, $userManager); |
|
56 | + $this->cloudIdManager = $cloudIdManager; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IEvent $event |
|
61 | + * @return IEvent |
|
62 | + * @throws \InvalidArgumentException |
|
63 | + * @since 11.0.0 |
|
64 | + */ |
|
65 | + public function parseShortVersion(IEvent $event) { |
|
66 | + $parsedParameters = $this->getParsedParameters($event); |
|
67 | + |
|
68 | + if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
69 | + $subject = $this->l->t('{user} accepted the remote share'); |
|
70 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
71 | + $subject = $this->l->t('{user} declined the remote share'); |
|
72 | + } else { |
|
73 | + throw new \InvalidArgumentException(); |
|
74 | + } |
|
75 | + |
|
76 | + if ($this->activityManager->getRequirePNG()) { |
|
77 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
78 | + } else { |
|
79 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
80 | + } |
|
81 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
82 | + |
|
83 | + return $event; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param IEvent $event |
|
88 | + * @return IEvent |
|
89 | + * @throws \InvalidArgumentException |
|
90 | + * @since 11.0.0 |
|
91 | + */ |
|
92 | + public function parseLongVersion(IEvent $event) { |
|
93 | + $parsedParameters = $this->getParsedParameters($event); |
|
94 | + |
|
95 | + if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { |
|
96 | + $subject = $this->l->t('You received a new remote share {file} from {user}'); |
|
97 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
98 | + $subject = $this->l->t('{user} accepted the remote share of {file}'); |
|
99 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
100 | + $subject = $this->l->t('{user} declined the remote share of {file}'); |
|
101 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { |
|
102 | + $subject = $this->l->t('{user} unshared {file} from you'); |
|
103 | + } else { |
|
104 | + throw new \InvalidArgumentException(); |
|
105 | + } |
|
106 | + |
|
107 | + if ($this->activityManager->getRequirePNG()) { |
|
108 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
109 | + } else { |
|
110 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
111 | + } |
|
112 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
113 | + |
|
114 | + return $event; |
|
115 | + } |
|
116 | + |
|
117 | + protected function getParsedParameters(IEvent $event) { |
|
118 | + $subject = $event->getSubject(); |
|
119 | + $parameters = $event->getSubjectParameters(); |
|
120 | + |
|
121 | + switch ($subject) { |
|
122 | + case self::SUBJECT_REMOTE_SHARE_RECEIVED: |
|
123 | + case self::SUBJECT_REMOTE_SHARE_UNSHARED: |
|
124 | + return [ |
|
125 | + 'file' => [ |
|
126 | + 'type' => 'pending-federated-share', |
|
127 | + 'id' => $parameters[1], |
|
128 | + 'name' => $parameters[1], |
|
129 | + ], |
|
130 | + 'user' => $this->getFederatedUser($parameters[0]), |
|
131 | + ]; |
|
132 | + case self::SUBJECT_REMOTE_SHARE_ACCEPTED: |
|
133 | + case self::SUBJECT_REMOTE_SHARE_DECLINED: |
|
134 | + return [ |
|
135 | + 'file' => $this->getFile([$event->getObjectId() => $event->getObjectName()]), |
|
136 | + 'user' => $this->getFederatedUser($parameters[0]), |
|
137 | + ]; |
|
138 | + } |
|
139 | + throw new \InvalidArgumentException(); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $cloudId |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + protected function getFederatedUser($cloudId) { |
|
147 | + $remoteUser = $this->cloudIdManager->resolveCloudId($cloudId); |
|
148 | + return [ |
|
149 | + 'type' => 'user', |
|
150 | + 'id' => $remoteUser->getUser(), |
|
151 | + 'name' => $cloudId,// Todo display name from contacts |
|
152 | + 'server' => $remoteUser->getRemote(), |
|
153 | + ]; |
|
154 | + } |
|
155 | 155 | } |