1 | <?php |
||
18 | class PlainTextParser { |
||
19 | |||
20 | /** @var IL10N */ |
||
21 | protected $l; |
||
22 | |||
23 | /** |
||
24 | * @param IL10N $l |
||
25 | */ |
||
26 | 8 | public function __construct(IL10N $l) { |
|
29 | |||
30 | /** |
||
31 | * Parse the parameters in the subject and message |
||
32 | * |
||
33 | * @param string $message |
||
34 | * @return string |
||
35 | */ |
||
36 | 5 | public function parseMessage($message) { |
|
41 | |||
42 | /** |
||
43 | * Parse collections |
||
44 | * |
||
45 | * @param string $message |
||
46 | * @return string |
||
47 | */ |
||
48 | 5 | protected function parseCollections($message) { |
|
49 | return preg_replace_callback('/<collection>(.*?)<\/collection>/', function($match) { |
||
50 | $parameterList = explode('><', $match[1]); |
||
51 | $parameterListLength = sizeof($parameterList); |
||
52 | |||
53 | $parameters = []; |
||
54 | for ($i = 0; $i < $parameterListLength; $i++) { |
||
55 | $parameter = $parameterList[$i]; |
||
56 | if ($i > 0) { |
||
57 | $parameter = '<' . $parameter; |
||
58 | } |
||
59 | if ($i + 1 < $parameterListLength) { |
||
60 | $parameter = $parameter . '>'; |
||
61 | } |
||
62 | |||
63 | $parameters[] = $this->parseParameters($parameter); |
||
64 | } |
||
65 | if ($parameterListLength === 1) { |
||
66 | return array_pop($parameters); |
||
67 | } else { |
||
68 | $lastParameter = array_pop($parameters); |
||
69 | return $this->l->t('%s and %s', [ |
||
70 | implode($this->l->t(', '), $parameters), |
||
71 | $lastParameter, |
||
72 | ]); |
||
73 | } |
||
74 | 5 | }, $message); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Parse the parameters in the subject and message |
||
79 | * |
||
80 | * @param string $message |
||
81 | * @return string |
||
82 | */ |
||
83 | 5 | protected function parseParameters($message) { |
|
90 | |||
91 | /** |
||
92 | * Display the parameter value |
||
93 | * |
||
94 | * @param string $message |
||
95 | * @return string |
||
96 | */ |
||
97 | 5 | protected function parseUntypedParameters($message) { |
|
98 | return preg_replace_callback('/<parameter>(.*?)<\/parameter>/', function($match) { |
||
99 | return $match[1]; |
||
100 | 5 | }, $message); |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Display the users display name |
||
105 | * |
||
106 | * @param string $message |
||
107 | * @return string |
||
108 | */ |
||
109 | 5 | protected function parseUserParameters($message) { |
|
114 | |||
115 | /** |
||
116 | * Display the full cloud id |
||
117 | * |
||
118 | * @param string $message |
||
119 | * @return string |
||
120 | */ |
||
121 | 5 | protected function parseFederatedCloudIDParameters($message) { |
|
122 | return preg_replace_callback('/<federated-cloud-id\ display\-name=\"(.*?)\"\ user=\"(.*?)\"\ server=\"(.*?)\">(.*?)<\/federated-cloud-id>/', function($match) { |
||
123 | return $match[1]; |
||
124 | 5 | }, $message); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Display the path for files |
||
129 | * |
||
130 | * @param string $message |
||
131 | * @return string |
||
132 | */ |
||
133 | protected function parseFileParameters($message) { |
||
138 | } |
||
139 |