|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Activity\Formatter; |
|
23
|
|
|
|
|
24
|
|
|
use OCP\Activity\IEvent; |
|
25
|
|
|
use OCP\IConfig; |
|
26
|
|
|
use OCP\IL10N; |
|
27
|
|
|
use OCP\IUserManager; |
|
28
|
|
|
use OCP\Util; |
|
29
|
|
|
|
|
30
|
|
|
class UserFormatter implements IFormatter { |
|
31
|
|
|
/** @var IUserManager */ |
|
32
|
|
|
protected $manager; |
|
33
|
|
|
/** @var IL10N */ |
|
34
|
|
|
protected $l; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param IUserManager $userManager |
|
38
|
|
|
* @param IL10N $l |
|
39
|
|
|
*/ |
|
40
|
8 |
|
public function __construct(IUserManager $userManager, IL10N $l) { |
|
41
|
8 |
|
$this->manager = $userManager; |
|
42
|
8 |
|
$this->l = $l; |
|
43
|
8 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param IEvent $event |
|
47
|
|
|
* @param string $parameter The parameter to be formatted |
|
48
|
|
|
* @return string The formatted parameter |
|
49
|
|
|
*/ |
|
50
|
7 |
|
public function format(IEvent $event, $parameter) { |
|
51
|
|
|
// If the username is empty, the action has been performed by a remote |
|
52
|
|
|
// user, or via a public share. We don't know the username in that case |
|
53
|
7 |
|
if ($parameter === '') { |
|
54
|
1 |
|
return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
6 |
|
$user = $this->manager->get($parameter); |
|
58
|
6 |
|
$displayName = ($user) ? $user->getDisplayName() : $parameter; |
|
59
|
6 |
|
$parameter = Util::sanitizeHTML($parameter); |
|
60
|
|
|
|
|
61
|
6 |
|
return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>'; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|