1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @license GNU AGPL version 3 or any later version |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
10
|
|
|
* License, or (at your option) any later version. |
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 |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Activity\Extension; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use OCA\Activity\DataHelper; |
26
|
|
|
use OCA\Activity\PlainTextParser; |
27
|
|
|
use OCP\Activity\IEvent; |
28
|
|
|
use OCP\Activity\IProvider; |
29
|
|
|
use OCP\L10N\IFactory; |
30
|
|
|
|
31
|
|
|
class LegacyParser implements IProvider { |
32
|
|
|
|
33
|
|
|
/** @var IFactory */ |
34
|
|
|
protected $languageFactory; |
35
|
|
|
|
36
|
|
|
/** @var DataHelper */ |
37
|
|
|
protected $dataHelper; |
38
|
|
|
|
39
|
|
|
/** @var PlainTextParser */ |
40
|
|
|
protected $parser; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param IFactory $languageFactory |
44
|
|
|
* @param DataHelper $dataHelper |
45
|
|
|
* @param PlainTextParser $parser |
46
|
|
|
*/ |
47
|
19 |
|
public function __construct(IFactory $languageFactory, DataHelper $dataHelper, PlainTextParser $parser) { |
48
|
19 |
|
$this->languageFactory = $languageFactory; |
49
|
19 |
|
$this->dataHelper = $dataHelper; |
50
|
19 |
|
$this->parser = $parser; |
51
|
19 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $language |
55
|
|
|
* @param IEvent $event |
56
|
|
|
* @param IEvent|null $previousEvent |
57
|
|
|
* @return IEvent |
58
|
|
|
* @throws \InvalidArgumentException |
59
|
|
|
* @since 9.2.0 |
60
|
|
|
*/ |
61
|
4 |
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
62
|
4 |
|
$l = $this->languageFactory->get('activity', $language); |
63
|
4 |
|
$this->dataHelper->setL10n($l); |
64
|
|
|
|
65
|
4 |
|
$event->setParsedSubject($this->parser->parseMessage($this->dataHelper->translation( |
66
|
4 |
|
$event->getApp(), |
67
|
4 |
|
$event->getSubject(), |
68
|
4 |
|
$this->dataHelper->getParameters($event, 'subject', json_encode($event->getSubjectParameters())) |
69
|
|
|
))); |
70
|
|
|
|
71
|
4 |
|
$event->setParsedMessage($this->parser->parseMessage($this->dataHelper->translation( |
72
|
4 |
|
$event->getApp(), |
73
|
4 |
|
$event->getMessage(), |
74
|
4 |
|
$this->dataHelper->getParameters($event, 'message', json_encode($event->getMessageParameters())) |
75
|
|
|
))); |
76
|
|
|
|
77
|
4 |
|
return $event; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|