@@ -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,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 | } |
@@ -31,147 +31,147 @@ |
||
31 | 31 | |
32 | 32 | class FavoriteProvider implements IProvider { |
33 | 33 | |
34 | - const SUBJECT_ADDED = 'added_favorite'; |
|
35 | - const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | - |
|
37 | - /** @var IFactory */ |
|
38 | - protected $languageFactory; |
|
39 | - |
|
40 | - /** @var IL10N */ |
|
41 | - protected $l; |
|
42 | - |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $url; |
|
45 | - |
|
46 | - /** @var IManager */ |
|
47 | - protected $activityManager; |
|
48 | - |
|
49 | - /** @var IEventMerger */ |
|
50 | - protected $eventMerger; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param IFactory $languageFactory |
|
54 | - * @param IURLGenerator $url |
|
55 | - * @param IManager $activityManager |
|
56 | - * @param IEventMerger $eventMerger |
|
57 | - */ |
|
58 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | - $this->languageFactory = $languageFactory; |
|
60 | - $this->url = $url; |
|
61 | - $this->activityManager = $activityManager; |
|
62 | - $this->eventMerger = $eventMerger; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $language |
|
67 | - * @param IEvent $event |
|
68 | - * @param IEvent|null $previousEvent |
|
69 | - * @return IEvent |
|
70 | - * @throws \InvalidArgumentException |
|
71 | - * @since 11.0.0 |
|
72 | - */ |
|
73 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | - if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | - throw new \InvalidArgumentException(); |
|
76 | - } |
|
77 | - |
|
78 | - $this->l = $this->languageFactory->get('files', $language); |
|
79 | - |
|
80 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | - try { |
|
82 | - return $this->parseShortVersion($event); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - // Ignore and simply use the long version... |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - return $this->parseLongVersion($event, $previousEvent); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IEvent $event |
|
93 | - * @return IEvent |
|
94 | - * @throws \InvalidArgumentException |
|
95 | - * @since 11.0.0 |
|
96 | - */ |
|
97 | - public function parseShortVersion(IEvent $event) { |
|
98 | - |
|
99 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | - $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | - if ($this->activityManager->getRequirePNG()) { |
|
102 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | - } else { |
|
104 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | - } |
|
106 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | - $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | - if ($this->activityManager->getRequirePNG()) { |
|
109 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | - } else { |
|
111 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | - } |
|
113 | - } else { |
|
114 | - throw new \InvalidArgumentException(); |
|
115 | - } |
|
116 | - |
|
117 | - return $event; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param IEvent $event |
|
122 | - * @param IEvent|null $previousEvent |
|
123 | - * @return IEvent |
|
124 | - * @throws \InvalidArgumentException |
|
125 | - * @since 11.0.0 |
|
126 | - */ |
|
127 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | - |
|
129 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | - $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | - if ($this->activityManager->getRequirePNG()) { |
|
132 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | - } else { |
|
134 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | - } |
|
136 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | - $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | - if ($this->activityManager->getRequirePNG()) { |
|
139 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | - } else { |
|
141 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | - } |
|
143 | - } else { |
|
144 | - throw new \InvalidArgumentException(); |
|
145 | - } |
|
146 | - |
|
147 | - $this->setSubjects($event, $subject); |
|
148 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | - return $event; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param IEvent $event |
|
154 | - * @param string $subject |
|
155 | - */ |
|
156 | - protected function setSubjects(IEvent $event, $subject) { |
|
157 | - $subjectParams = $event->getSubjectParameters(); |
|
158 | - if (empty($subjectParams)) { |
|
159 | - // Try to fall back to the old way, but this does not work for emails. |
|
160 | - // But at least old activities still work. |
|
161 | - $subjectParams = [ |
|
162 | - 'id' => $event->getObjectId(), |
|
163 | - 'path' => $event->getObjectName(), |
|
164 | - ]; |
|
165 | - } |
|
166 | - $parameter = [ |
|
167 | - 'type' => 'file', |
|
168 | - 'id' => $subjectParams['id'], |
|
169 | - 'name' => basename($subjectParams['path']), |
|
170 | - 'path' => trim($subjectParams['path'], '/'), |
|
171 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | - ]; |
|
173 | - |
|
174 | - $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | - ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | - } |
|
34 | + const SUBJECT_ADDED = 'added_favorite'; |
|
35 | + const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | + |
|
37 | + /** @var IFactory */ |
|
38 | + protected $languageFactory; |
|
39 | + |
|
40 | + /** @var IL10N */ |
|
41 | + protected $l; |
|
42 | + |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $url; |
|
45 | + |
|
46 | + /** @var IManager */ |
|
47 | + protected $activityManager; |
|
48 | + |
|
49 | + /** @var IEventMerger */ |
|
50 | + protected $eventMerger; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param IFactory $languageFactory |
|
54 | + * @param IURLGenerator $url |
|
55 | + * @param IManager $activityManager |
|
56 | + * @param IEventMerger $eventMerger |
|
57 | + */ |
|
58 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | + $this->languageFactory = $languageFactory; |
|
60 | + $this->url = $url; |
|
61 | + $this->activityManager = $activityManager; |
|
62 | + $this->eventMerger = $eventMerger; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $language |
|
67 | + * @param IEvent $event |
|
68 | + * @param IEvent|null $previousEvent |
|
69 | + * @return IEvent |
|
70 | + * @throws \InvalidArgumentException |
|
71 | + * @since 11.0.0 |
|
72 | + */ |
|
73 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | + if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | + throw new \InvalidArgumentException(); |
|
76 | + } |
|
77 | + |
|
78 | + $this->l = $this->languageFactory->get('files', $language); |
|
79 | + |
|
80 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | + try { |
|
82 | + return $this->parseShortVersion($event); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + // Ignore and simply use the long version... |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + return $this->parseLongVersion($event, $previousEvent); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IEvent $event |
|
93 | + * @return IEvent |
|
94 | + * @throws \InvalidArgumentException |
|
95 | + * @since 11.0.0 |
|
96 | + */ |
|
97 | + public function parseShortVersion(IEvent $event) { |
|
98 | + |
|
99 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | + $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | + if ($this->activityManager->getRequirePNG()) { |
|
102 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | + } else { |
|
104 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | + } |
|
106 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | + $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | + if ($this->activityManager->getRequirePNG()) { |
|
109 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | + } else { |
|
111 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | + } |
|
113 | + } else { |
|
114 | + throw new \InvalidArgumentException(); |
|
115 | + } |
|
116 | + |
|
117 | + return $event; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param IEvent $event |
|
122 | + * @param IEvent|null $previousEvent |
|
123 | + * @return IEvent |
|
124 | + * @throws \InvalidArgumentException |
|
125 | + * @since 11.0.0 |
|
126 | + */ |
|
127 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | + |
|
129 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | + $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | + if ($this->activityManager->getRequirePNG()) { |
|
132 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | + } else { |
|
134 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | + } |
|
136 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | + $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | + if ($this->activityManager->getRequirePNG()) { |
|
139 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | + } else { |
|
141 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | + } |
|
143 | + } else { |
|
144 | + throw new \InvalidArgumentException(); |
|
145 | + } |
|
146 | + |
|
147 | + $this->setSubjects($event, $subject); |
|
148 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | + return $event; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param IEvent $event |
|
154 | + * @param string $subject |
|
155 | + */ |
|
156 | + protected function setSubjects(IEvent $event, $subject) { |
|
157 | + $subjectParams = $event->getSubjectParameters(); |
|
158 | + if (empty($subjectParams)) { |
|
159 | + // Try to fall back to the old way, but this does not work for emails. |
|
160 | + // But at least old activities still work. |
|
161 | + $subjectParams = [ |
|
162 | + 'id' => $event->getObjectId(), |
|
163 | + 'path' => $event->getObjectName(), |
|
164 | + ]; |
|
165 | + } |
|
166 | + $parameter = [ |
|
167 | + 'type' => 'file', |
|
168 | + 'id' => $subjectParams['id'], |
|
169 | + 'name' => basename($subjectParams['path']), |
|
170 | + 'path' => trim($subjectParams['path'], '/'), |
|
171 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | + ]; |
|
173 | + |
|
174 | + $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | + ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | + } |
|
177 | 177 | } |
@@ -32,157 +32,157 @@ |
||
32 | 32 | |
33 | 33 | class Provider implements IProvider { |
34 | 34 | |
35 | - const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | - const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | - const PASSWORD_RESET = 'password_changed'; |
|
38 | - const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | - const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | - const EMAIL_CHANGED = 'email_changed'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IManager */ |
|
55 | - private $activityManager; |
|
56 | - |
|
57 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | - protected $displayNames = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IFactory $languageFactory |
|
62 | - * @param IURLGenerator $url |
|
63 | - * @param IUserManager $userManager |
|
64 | - * @param IManager $activityManager |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
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() !== 'settings') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('settings', $language); |
|
87 | - |
|
88 | - if ($this->activityManager->getRequirePNG()) { |
|
89 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | - } else { |
|
91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | - } |
|
93 | - |
|
94 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | - $subject = $this->l->t('{actor} changed your password'); |
|
96 | - } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | - $subject = $this->l->t('You changed your password'); |
|
98 | - } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | - |
|
101 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | - $subject = $this->l->t('{actor} changed your email address'); |
|
103 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | - $subject = $this->l->t('You changed your email address'); |
|
105 | - } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | - |
|
108 | - } else { |
|
109 | - throw new \InvalidArgumentException(); |
|
110 | - } |
|
111 | - |
|
112 | - $parsedParameters = $this->getParameters($event); |
|
113 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | - |
|
115 | - return $event; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param IEvent $event |
|
120 | - * @return array |
|
121 | - * @throws \InvalidArgumentException |
|
122 | - */ |
|
123 | - protected function getParameters(IEvent $event) { |
|
124 | - $subject = $event->getSubject(); |
|
125 | - $parameters = $event->getSubjectParameters(); |
|
126 | - |
|
127 | - switch ($subject) { |
|
128 | - case self::PASSWORD_CHANGED_SELF: |
|
129 | - case self::PASSWORD_RESET: |
|
130 | - case self::EMAIL_CHANGED_SELF: |
|
131 | - case self::EMAIL_CHANGED: |
|
132 | - return []; |
|
133 | - case self::PASSWORD_CHANGED_BY: |
|
134 | - case self::EMAIL_CHANGED_BY: |
|
135 | - return [ |
|
136 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | - ]; |
|
138 | - } |
|
139 | - |
|
140 | - throw new \InvalidArgumentException(); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IEvent $event |
|
145 | - * @param string $subject |
|
146 | - * @param array $parameters |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - */ |
|
149 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | - $placeholders = $replacements = []; |
|
151 | - foreach ($parameters as $placeholder => $parameter) { |
|
152 | - $placeholders[] = '{' . $placeholder . '}'; |
|
153 | - $replacements[] = $parameter['name']; |
|
154 | - } |
|
155 | - |
|
156 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | - ->setRichSubject($subject, $parameters); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $uid |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function generateUserParameter($uid) { |
|
165 | - if (!isset($this->displayNames[$uid])) { |
|
166 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | - } |
|
168 | - |
|
169 | - return [ |
|
170 | - 'type' => 'user', |
|
171 | - 'id' => $uid, |
|
172 | - 'name' => $this->displayNames[$uid], |
|
173 | - ]; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $uid |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - protected function getDisplayName($uid) { |
|
181 | - $user = $this->userManager->get($uid); |
|
182 | - if ($user instanceof IUser) { |
|
183 | - return $user->getDisplayName(); |
|
184 | - } |
|
185 | - |
|
186 | - return $uid; |
|
187 | - } |
|
35 | + const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | + const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | + const PASSWORD_RESET = 'password_changed'; |
|
38 | + const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | + const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | + const EMAIL_CHANGED = 'email_changed'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IManager */ |
|
55 | + private $activityManager; |
|
56 | + |
|
57 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | + protected $displayNames = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IFactory $languageFactory |
|
62 | + * @param IURLGenerator $url |
|
63 | + * @param IUserManager $userManager |
|
64 | + * @param IManager $activityManager |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
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() !== 'settings') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('settings', $language); |
|
87 | + |
|
88 | + if ($this->activityManager->getRequirePNG()) { |
|
89 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | + } else { |
|
91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | + } |
|
93 | + |
|
94 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | + $subject = $this->l->t('{actor} changed your password'); |
|
96 | + } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | + $subject = $this->l->t('You changed your password'); |
|
98 | + } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | + |
|
101 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | + $subject = $this->l->t('{actor} changed your email address'); |
|
103 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | + $subject = $this->l->t('You changed your email address'); |
|
105 | + } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | + |
|
108 | + } else { |
|
109 | + throw new \InvalidArgumentException(); |
|
110 | + } |
|
111 | + |
|
112 | + $parsedParameters = $this->getParameters($event); |
|
113 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | + |
|
115 | + return $event; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param IEvent $event |
|
120 | + * @return array |
|
121 | + * @throws \InvalidArgumentException |
|
122 | + */ |
|
123 | + protected function getParameters(IEvent $event) { |
|
124 | + $subject = $event->getSubject(); |
|
125 | + $parameters = $event->getSubjectParameters(); |
|
126 | + |
|
127 | + switch ($subject) { |
|
128 | + case self::PASSWORD_CHANGED_SELF: |
|
129 | + case self::PASSWORD_RESET: |
|
130 | + case self::EMAIL_CHANGED_SELF: |
|
131 | + case self::EMAIL_CHANGED: |
|
132 | + return []; |
|
133 | + case self::PASSWORD_CHANGED_BY: |
|
134 | + case self::EMAIL_CHANGED_BY: |
|
135 | + return [ |
|
136 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | + ]; |
|
138 | + } |
|
139 | + |
|
140 | + throw new \InvalidArgumentException(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IEvent $event |
|
145 | + * @param string $subject |
|
146 | + * @param array $parameters |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + */ |
|
149 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | + $placeholders = $replacements = []; |
|
151 | + foreach ($parameters as $placeholder => $parameter) { |
|
152 | + $placeholders[] = '{' . $placeholder . '}'; |
|
153 | + $replacements[] = $parameter['name']; |
|
154 | + } |
|
155 | + |
|
156 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | + ->setRichSubject($subject, $parameters); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $uid |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function generateUserParameter($uid) { |
|
165 | + if (!isset($this->displayNames[$uid])) { |
|
166 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | + } |
|
168 | + |
|
169 | + return [ |
|
170 | + 'type' => 'user', |
|
171 | + 'id' => $uid, |
|
172 | + 'name' => $this->displayNames[$uid], |
|
173 | + ]; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $uid |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + protected function getDisplayName($uid) { |
|
181 | + $user = $this->userManager->get($uid); |
|
182 | + if ($user instanceof IUser) { |
|
183 | + return $user->getDisplayName(); |
|
184 | + } |
|
185 | + |
|
186 | + return $uid; |
|
187 | + } |
|
188 | 188 | } |
@@ -39,262 +39,262 @@ |
||
39 | 39 | * @since 6.0.0 |
40 | 40 | */ |
41 | 41 | interface IManager { |
42 | - /** |
|
43 | - * Generates a new IEvent object |
|
44 | - * |
|
45 | - * Make sure to call at least the following methods before sending it to the |
|
46 | - * app with via the publish() method: |
|
47 | - * - setApp() |
|
48 | - * - setType() |
|
49 | - * - setAffectedUser() |
|
50 | - * - setSubject() |
|
51 | - * |
|
52 | - * @return IEvent |
|
53 | - * @since 8.2.0 |
|
54 | - */ |
|
55 | - public function generateEvent(); |
|
56 | - |
|
57 | - /** |
|
58 | - * Publish an event to the activity consumers |
|
59 | - * |
|
60 | - * Make sure to call at least the following methods before sending an Event: |
|
61 | - * - setApp() |
|
62 | - * - setType() |
|
63 | - * - setAffectedUser() |
|
64 | - * - setSubject() |
|
65 | - * |
|
66 | - * @param IEvent $event |
|
67 | - * @throws \BadMethodCallException if required values have not been set |
|
68 | - * @since 8.2.0 |
|
69 | - */ |
|
70 | - public function publish(IEvent $event); |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $app The app where this event is associated with |
|
74 | - * @param string $subject A short description of the event |
|
75 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | - * @param string $message A longer description of the event |
|
77 | - * @param array $messageParams Array with parameters that are filled in the message |
|
78 | - * @param string $file The file including path where this event is associated with |
|
79 | - * @param string $link A link where this event is associated with |
|
80 | - * @param string $affectedUser Recipient of the activity |
|
81 | - * @param string $type Type of the notification |
|
82 | - * @param int $priority Priority of the notification |
|
83 | - * @since 6.0.0 |
|
84 | - * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
85 | - */ |
|
86 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
87 | - |
|
88 | - /** |
|
89 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
90 | - * activity consumers are actually requested |
|
91 | - * |
|
92 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
93 | - * |
|
94 | - * @param \Closure $callable |
|
95 | - * @return void |
|
96 | - * @since 6.0.0 |
|
97 | - */ |
|
98 | - public function registerConsumer(\Closure $callable); |
|
99 | - |
|
100 | - /** |
|
101 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
102 | - * activity consumers are actually requested |
|
103 | - * |
|
104 | - * $callable has to return an instance of \OCP\Activity\IExtension |
|
105 | - * |
|
106 | - * @param \Closure $callable |
|
107 | - * @return void |
|
108 | - * @since 8.0.0 |
|
109 | - */ |
|
110 | - public function registerExtension(\Closure $callable); |
|
111 | - |
|
112 | - /** |
|
113 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
114 | - * @return void |
|
115 | - * @since 11.0.0 |
|
116 | - */ |
|
117 | - public function registerFilter($filter); |
|
118 | - |
|
119 | - /** |
|
120 | - * @return IFilter[] |
|
121 | - * @since 11.0.0 |
|
122 | - */ |
|
123 | - public function getFilters(); |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $id |
|
127 | - * @return IFilter |
|
128 | - * @throws \InvalidArgumentException when the filter was not found |
|
129 | - * @since 11.0.0 |
|
130 | - */ |
|
131 | - public function getFilterById($id); |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
135 | - * @return void |
|
136 | - * @since 11.0.0 |
|
137 | - */ |
|
138 | - public function registerSetting($setting); |
|
139 | - |
|
140 | - /** |
|
141 | - * @return ISetting[] |
|
142 | - * @since 11.0.0 |
|
143 | - */ |
|
144 | - public function getSettings(); |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
148 | - * @return void |
|
149 | - * @since 11.0.0 |
|
150 | - */ |
|
151 | - public function registerProvider($provider); |
|
152 | - |
|
153 | - /** |
|
154 | - * @return IProvider[] |
|
155 | - * @since 11.0.0 |
|
156 | - */ |
|
157 | - public function getProviders(); |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $id |
|
161 | - * @return ISetting |
|
162 | - * @throws \InvalidArgumentException when the setting was not found |
|
163 | - * @since 11.0.0 |
|
164 | - */ |
|
165 | - public function getSettingById($id); |
|
166 | - |
|
167 | - /** |
|
168 | - * Will return additional notification types as specified by other apps |
|
169 | - * |
|
170 | - * @param string $languageCode |
|
171 | - * @return array Array "stringID of the type" => "translated string description for the setting" |
|
172 | - * or Array "stringID of the type" => [ |
|
173 | - * 'desc' => "translated string description for the setting" |
|
174 | - * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
175 | - * ] |
|
176 | - * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
177 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
178 | - */ |
|
179 | - public function getNotificationTypes($languageCode); |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $method |
|
183 | - * @return array |
|
184 | - * @since 8.0.0 |
|
185 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
186 | - */ |
|
187 | - public function getDefaultTypes($method); |
|
188 | - |
|
189 | - /** |
|
190 | - * @param string $type |
|
191 | - * @return string |
|
192 | - * @since 8.0.0 |
|
193 | - */ |
|
194 | - public function getTypeIcon($type); |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $type |
|
198 | - * @param int $id |
|
199 | - * @since 8.2.0 |
|
200 | - */ |
|
201 | - public function setFormattingObject($type, $id); |
|
202 | - |
|
203 | - /** |
|
204 | - * @return bool |
|
205 | - * @since 8.2.0 |
|
206 | - */ |
|
207 | - public function isFormattingFilteredObject(); |
|
208 | - |
|
209 | - /** |
|
210 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
211 | - * @since 12.0.1 |
|
212 | - */ |
|
213 | - public function setRequirePNG($status); |
|
214 | - |
|
215 | - /** |
|
216 | - * @return bool |
|
217 | - * @since 12.0.1 |
|
218 | - */ |
|
219 | - public function getRequirePNG(); |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $app |
|
223 | - * @param string $text |
|
224 | - * @param array $params |
|
225 | - * @param boolean $stripPath |
|
226 | - * @param boolean $highlightParams |
|
227 | - * @param string $languageCode |
|
228 | - * @return string|false |
|
229 | - * @since 8.0.0 |
|
230 | - */ |
|
231 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $app |
|
235 | - * @param string $text |
|
236 | - * @return array|false |
|
237 | - * @since 8.0.0 |
|
238 | - */ |
|
239 | - public function getSpecialParameterList($app, $text); |
|
240 | - |
|
241 | - /** |
|
242 | - * @param array $activity |
|
243 | - * @return integer|false |
|
244 | - * @since 8.0.0 |
|
245 | - */ |
|
246 | - public function getGroupParameter($activity); |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Set the user we need to use |
|
251 | - * |
|
252 | - * @param string|null $currentUserId |
|
253 | - * @throws \UnexpectedValueException If the user is invalid |
|
254 | - * @since 9.0.1 |
|
255 | - */ |
|
256 | - public function setCurrentUserId($currentUserId); |
|
257 | - |
|
258 | - /** |
|
259 | - * Get the user we need to use |
|
260 | - * |
|
261 | - * Either the user is logged in, or we try to get it from the token |
|
262 | - * |
|
263 | - * @return string |
|
264 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
265 | - * @since 8.1.0 |
|
266 | - */ |
|
267 | - public function getCurrentUserId(); |
|
268 | - |
|
269 | - /** |
|
270 | - * @return array |
|
271 | - * @since 8.0.0 |
|
272 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
273 | - */ |
|
274 | - public function getNavigation(); |
|
275 | - |
|
276 | - /** |
|
277 | - * @param string $filterValue |
|
278 | - * @return boolean |
|
279 | - * @since 8.0.0 |
|
280 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
281 | - */ |
|
282 | - public function isFilterValid($filterValue); |
|
283 | - |
|
284 | - /** |
|
285 | - * @param array $types |
|
286 | - * @param string $filter |
|
287 | - * @return array |
|
288 | - * @since 8.0.0 |
|
289 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
290 | - */ |
|
291 | - public function filterNotificationTypes($types, $filter); |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $filter |
|
295 | - * @return array |
|
296 | - * @since 8.0.0 |
|
297 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
298 | - */ |
|
299 | - public function getQueryForFilter($filter); |
|
42 | + /** |
|
43 | + * Generates a new IEvent object |
|
44 | + * |
|
45 | + * Make sure to call at least the following methods before sending it to the |
|
46 | + * app with via the publish() method: |
|
47 | + * - setApp() |
|
48 | + * - setType() |
|
49 | + * - setAffectedUser() |
|
50 | + * - setSubject() |
|
51 | + * |
|
52 | + * @return IEvent |
|
53 | + * @since 8.2.0 |
|
54 | + */ |
|
55 | + public function generateEvent(); |
|
56 | + |
|
57 | + /** |
|
58 | + * Publish an event to the activity consumers |
|
59 | + * |
|
60 | + * Make sure to call at least the following methods before sending an Event: |
|
61 | + * - setApp() |
|
62 | + * - setType() |
|
63 | + * - setAffectedUser() |
|
64 | + * - setSubject() |
|
65 | + * |
|
66 | + * @param IEvent $event |
|
67 | + * @throws \BadMethodCallException if required values have not been set |
|
68 | + * @since 8.2.0 |
|
69 | + */ |
|
70 | + public function publish(IEvent $event); |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $app The app where this event is associated with |
|
74 | + * @param string $subject A short description of the event |
|
75 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | + * @param string $message A longer description of the event |
|
77 | + * @param array $messageParams Array with parameters that are filled in the message |
|
78 | + * @param string $file The file including path where this event is associated with |
|
79 | + * @param string $link A link where this event is associated with |
|
80 | + * @param string $affectedUser Recipient of the activity |
|
81 | + * @param string $type Type of the notification |
|
82 | + * @param int $priority Priority of the notification |
|
83 | + * @since 6.0.0 |
|
84 | + * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
85 | + */ |
|
86 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
87 | + |
|
88 | + /** |
|
89 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
90 | + * activity consumers are actually requested |
|
91 | + * |
|
92 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
93 | + * |
|
94 | + * @param \Closure $callable |
|
95 | + * @return void |
|
96 | + * @since 6.0.0 |
|
97 | + */ |
|
98 | + public function registerConsumer(\Closure $callable); |
|
99 | + |
|
100 | + /** |
|
101 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
102 | + * activity consumers are actually requested |
|
103 | + * |
|
104 | + * $callable has to return an instance of \OCP\Activity\IExtension |
|
105 | + * |
|
106 | + * @param \Closure $callable |
|
107 | + * @return void |
|
108 | + * @since 8.0.0 |
|
109 | + */ |
|
110 | + public function registerExtension(\Closure $callable); |
|
111 | + |
|
112 | + /** |
|
113 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
114 | + * @return void |
|
115 | + * @since 11.0.0 |
|
116 | + */ |
|
117 | + public function registerFilter($filter); |
|
118 | + |
|
119 | + /** |
|
120 | + * @return IFilter[] |
|
121 | + * @since 11.0.0 |
|
122 | + */ |
|
123 | + public function getFilters(); |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $id |
|
127 | + * @return IFilter |
|
128 | + * @throws \InvalidArgumentException when the filter was not found |
|
129 | + * @since 11.0.0 |
|
130 | + */ |
|
131 | + public function getFilterById($id); |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
135 | + * @return void |
|
136 | + * @since 11.0.0 |
|
137 | + */ |
|
138 | + public function registerSetting($setting); |
|
139 | + |
|
140 | + /** |
|
141 | + * @return ISetting[] |
|
142 | + * @since 11.0.0 |
|
143 | + */ |
|
144 | + public function getSettings(); |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
148 | + * @return void |
|
149 | + * @since 11.0.0 |
|
150 | + */ |
|
151 | + public function registerProvider($provider); |
|
152 | + |
|
153 | + /** |
|
154 | + * @return IProvider[] |
|
155 | + * @since 11.0.0 |
|
156 | + */ |
|
157 | + public function getProviders(); |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $id |
|
161 | + * @return ISetting |
|
162 | + * @throws \InvalidArgumentException when the setting was not found |
|
163 | + * @since 11.0.0 |
|
164 | + */ |
|
165 | + public function getSettingById($id); |
|
166 | + |
|
167 | + /** |
|
168 | + * Will return additional notification types as specified by other apps |
|
169 | + * |
|
170 | + * @param string $languageCode |
|
171 | + * @return array Array "stringID of the type" => "translated string description for the setting" |
|
172 | + * or Array "stringID of the type" => [ |
|
173 | + * 'desc' => "translated string description for the setting" |
|
174 | + * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
175 | + * ] |
|
176 | + * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
177 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
178 | + */ |
|
179 | + public function getNotificationTypes($languageCode); |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $method |
|
183 | + * @return array |
|
184 | + * @since 8.0.0 |
|
185 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
186 | + */ |
|
187 | + public function getDefaultTypes($method); |
|
188 | + |
|
189 | + /** |
|
190 | + * @param string $type |
|
191 | + * @return string |
|
192 | + * @since 8.0.0 |
|
193 | + */ |
|
194 | + public function getTypeIcon($type); |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $type |
|
198 | + * @param int $id |
|
199 | + * @since 8.2.0 |
|
200 | + */ |
|
201 | + public function setFormattingObject($type, $id); |
|
202 | + |
|
203 | + /** |
|
204 | + * @return bool |
|
205 | + * @since 8.2.0 |
|
206 | + */ |
|
207 | + public function isFormattingFilteredObject(); |
|
208 | + |
|
209 | + /** |
|
210 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
211 | + * @since 12.0.1 |
|
212 | + */ |
|
213 | + public function setRequirePNG($status); |
|
214 | + |
|
215 | + /** |
|
216 | + * @return bool |
|
217 | + * @since 12.0.1 |
|
218 | + */ |
|
219 | + public function getRequirePNG(); |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $app |
|
223 | + * @param string $text |
|
224 | + * @param array $params |
|
225 | + * @param boolean $stripPath |
|
226 | + * @param boolean $highlightParams |
|
227 | + * @param string $languageCode |
|
228 | + * @return string|false |
|
229 | + * @since 8.0.0 |
|
230 | + */ |
|
231 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $app |
|
235 | + * @param string $text |
|
236 | + * @return array|false |
|
237 | + * @since 8.0.0 |
|
238 | + */ |
|
239 | + public function getSpecialParameterList($app, $text); |
|
240 | + |
|
241 | + /** |
|
242 | + * @param array $activity |
|
243 | + * @return integer|false |
|
244 | + * @since 8.0.0 |
|
245 | + */ |
|
246 | + public function getGroupParameter($activity); |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Set the user we need to use |
|
251 | + * |
|
252 | + * @param string|null $currentUserId |
|
253 | + * @throws \UnexpectedValueException If the user is invalid |
|
254 | + * @since 9.0.1 |
|
255 | + */ |
|
256 | + public function setCurrentUserId($currentUserId); |
|
257 | + |
|
258 | + /** |
|
259 | + * Get the user we need to use |
|
260 | + * |
|
261 | + * Either the user is logged in, or we try to get it from the token |
|
262 | + * |
|
263 | + * @return string |
|
264 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
265 | + * @since 8.1.0 |
|
266 | + */ |
|
267 | + public function getCurrentUserId(); |
|
268 | + |
|
269 | + /** |
|
270 | + * @return array |
|
271 | + * @since 8.0.0 |
|
272 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
273 | + */ |
|
274 | + public function getNavigation(); |
|
275 | + |
|
276 | + /** |
|
277 | + * @param string $filterValue |
|
278 | + * @return boolean |
|
279 | + * @since 8.0.0 |
|
280 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
281 | + */ |
|
282 | + public function isFilterValid($filterValue); |
|
283 | + |
|
284 | + /** |
|
285 | + * @param array $types |
|
286 | + * @param string $filter |
|
287 | + * @return array |
|
288 | + * @since 8.0.0 |
|
289 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
290 | + */ |
|
291 | + public function filterNotificationTypes($types, $filter); |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $filter |
|
295 | + * @return array |
|
296 | + * @since 8.0.0 |
|
297 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
298 | + */ |
|
299 | + public function getQueryForFilter($filter); |
|
300 | 300 | } |
@@ -21,5 +21,5 @@ |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | |
24 | - # used for Personal/Additional settings as fallback for legacy settings |
|
24 | + # used for Personal/Additional settings as fallback for legacy settings |
|
25 | 25 | ?> |
@@ -29,58 +29,58 @@ |
||
29 | 29 | use OCP\Settings\IIconSection; |
30 | 30 | |
31 | 31 | class PersonalSection implements IIconSection { |
32 | - /** @var IURLGenerator */ |
|
33 | - private $urlGenerator; |
|
34 | - /** @var IL10N */ |
|
35 | - private $l; |
|
32 | + /** @var IURLGenerator */ |
|
33 | + private $urlGenerator; |
|
34 | + /** @var IL10N */ |
|
35 | + private $l; |
|
36 | 36 | |
37 | - public function __construct(IURLGenerator $urlGenerator, IL10N $l) { |
|
38 | - $this->urlGenerator = $urlGenerator; |
|
39 | - $this->l = $l; |
|
40 | - } |
|
37 | + public function __construct(IURLGenerator $urlGenerator, IL10N $l) { |
|
38 | + $this->urlGenerator = $urlGenerator; |
|
39 | + $this->l = $l; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * returns the relative path to an 16*16 icon describing the section. |
|
44 | - * e.g. '/core/img/places/files.svg' |
|
45 | - * |
|
46 | - * @returns string |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function getIcon() { |
|
50 | - return $this->urlGenerator->imagePath('core', 'actions/share.svg'); |
|
51 | - } |
|
42 | + /** |
|
43 | + * returns the relative path to an 16*16 icon describing the section. |
|
44 | + * e.g. '/core/img/places/files.svg' |
|
45 | + * |
|
46 | + * @returns string |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function getIcon() { |
|
50 | + return $this->urlGenerator->imagePath('core', 'actions/share.svg'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * returns the ID of the section. It is supposed to be a lower case string, |
|
55 | - * e.g. 'ldap' |
|
56 | - * |
|
57 | - * @returns string |
|
58 | - * @since 9.1 |
|
59 | - */ |
|
60 | - public function getID() { |
|
61 | - return 'sharing'; |
|
62 | - } |
|
53 | + /** |
|
54 | + * returns the ID of the section. It is supposed to be a lower case string, |
|
55 | + * e.g. 'ldap' |
|
56 | + * |
|
57 | + * @returns string |
|
58 | + * @since 9.1 |
|
59 | + */ |
|
60 | + public function getID() { |
|
61 | + return 'sharing'; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
66 | - * integration'. Use the L10N service to translate it. |
|
67 | - * |
|
68 | - * @return string |
|
69 | - * @since 9.1 |
|
70 | - */ |
|
71 | - public function getName() { |
|
72 | - return $this->l->t('Sharing'); |
|
73 | - } |
|
64 | + /** |
|
65 | + * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
66 | + * integration'. Use the L10N service to translate it. |
|
67 | + * |
|
68 | + * @return string |
|
69 | + * @since 9.1 |
|
70 | + */ |
|
71 | + public function getName() { |
|
72 | + return $this->l->t('Sharing'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return int whether the form should be rather on the top or bottom of |
|
77 | - * the settings navigation. The sections are arranged in ascending order of |
|
78 | - * the priority values. It is required to return a value between 0 and 99. |
|
79 | - * |
|
80 | - * E.g.: 70 |
|
81 | - * @since 9.1 |
|
82 | - */ |
|
83 | - public function getPriority() { |
|
84 | - return 15; |
|
85 | - } |
|
75 | + /** |
|
76 | + * @return int whether the form should be rather on the top or bottom of |
|
77 | + * the settings navigation. The sections are arranged in ascending order of |
|
78 | + * the priority values. It is required to return a value between 0 and 99. |
|
79 | + * |
|
80 | + * E.g.: 70 |
|
81 | + * @since 9.1 |
|
82 | + */ |
|
83 | + public function getPriority() { |
|
84 | + return 15; |
|
85 | + } |
|
86 | 86 | } |