|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2015 Victor Dubiniuk <[email protected]> |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. |
|
6
|
|
|
* See the COPYING-README file. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OCA\Files_Antivirus; |
|
10
|
|
|
|
|
11
|
|
|
use OC\L10N\Factory; |
|
12
|
|
|
use OCP\Activity\IExtension; |
|
13
|
|
|
use OCP\IURLGenerator; |
|
14
|
|
|
|
|
15
|
|
|
class Activity implements IExtension { |
|
16
|
|
|
|
|
17
|
|
|
const APP_NAME = 'files_antivirus'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Filter with all app related activities |
|
21
|
|
|
*/ |
|
22
|
|
|
const FILTER_AVIR = 'files_antivirus'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Activity types known to this extension |
|
26
|
|
|
*/ |
|
27
|
|
|
const TYPE_VIRUS_DETECTED = 'virus_detected'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Subject keys for translation of the subjections |
|
31
|
|
|
*/ |
|
32
|
|
|
const SUBJECT_VIRUS_DETECTED = 'virus_detected'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Infected file deletion notice |
|
36
|
|
|
*/ |
|
37
|
|
|
const MESSAGE_FILE_DELETED = 'file_deleted'; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** @var Factory */ |
|
41
|
|
|
protected $languageFactory; |
|
42
|
|
|
|
|
43
|
|
|
/** @var IURLGenerator */ |
|
44
|
|
|
protected $URLGenerator; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Factory $languageFactory |
|
48
|
|
|
* @param IURLGenerator $URLGenerator |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator) { |
|
51
|
3 |
|
$this->languageFactory = $languageFactory; |
|
52
|
3 |
|
$this->URLGenerator = $URLGenerator; |
|
53
|
3 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getL10N($languageCode = null) { |
|
56
|
|
|
return $this->languageFactory->get(self::APP_NAME, $languageCode); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* The extension can return an array of additional notification types. |
|
61
|
|
|
* If no additional types are to be added false is to be returned |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $languageCode |
|
64
|
|
|
* @return array|false |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getNotificationTypes($languageCode) { |
|
67
|
|
|
$l = $this->getL10N($languageCode); |
|
68
|
|
|
|
|
69
|
|
|
return [ |
|
70
|
|
|
self::TYPE_VIRUS_DETECTED => (string) $l->t('<strong>Infected file</strong> has been <strong>found</strong>'), |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* For a given method additional types to be displayed in the settings can be returned. |
|
76
|
|
|
* In case no additional types are to be added false is to be returned. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $method |
|
79
|
|
|
* @return array|false |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getDefaultTypes($method) { |
|
82
|
|
|
$defaultTypes = [ |
|
83
|
|
|
self::TYPE_VIRUS_DETECTED, |
|
84
|
|
|
]; |
|
85
|
|
|
|
|
86
|
|
|
return $defaultTypes; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* A string naming the css class for the icon to be used can be returned. |
|
91
|
|
|
* If no icon is known for the given type false is to be returned. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $type |
|
94
|
|
|
* @return string|false |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function getTypeIcon($type) { |
|
97
|
|
|
switch ($type) { |
|
98
|
1 |
|
case self::TYPE_VIRUS_DETECTED: |
|
99
|
1 |
|
return 'icon-info'; |
|
100
|
|
|
} |
|
101
|
1 |
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* The extension can translate a given message to the requested languages. |
|
106
|
|
|
* If no translation is available false is to be returned. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $app |
|
109
|
|
|
* @param string $text |
|
110
|
|
|
* @param array $params |
|
111
|
|
|
* @param boolean $stripPath |
|
112
|
|
|
* @param boolean $highlightParams |
|
113
|
|
|
* @param string $languageCode |
|
114
|
|
|
* @return string|false |
|
115
|
|
|
*/ |
|
116
|
|
|
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
117
|
|
|
$l = $this->getL10N($languageCode); |
|
118
|
|
|
|
|
119
|
|
|
if ($app === self::APP_NAME) { |
|
120
|
|
|
switch ($text) { |
|
121
|
|
|
case self::SUBJECT_VIRUS_DETECTED: |
|
122
|
|
|
return (string) $l->t('File %s is infected with %s', $params); |
|
123
|
|
|
case self::MESSAGE_FILE_DELETED: |
|
124
|
|
|
return (string) $l->t('It is going to be deleted', $params); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* The extension can define the type of parameters for translation |
|
133
|
|
|
* |
|
134
|
|
|
* Currently known types are: |
|
135
|
|
|
* * file => will strip away the path of the file and add a tooltip with it |
|
136
|
|
|
* * username => will add the avatar of the user |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $app |
|
139
|
|
|
* @param string $text |
|
140
|
|
|
* @return array|false |
|
141
|
|
|
*/ |
|
142
|
1 |
|
public function getSpecialParameterList($app, $text) { |
|
143
|
1 |
|
return false; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* The extension can define the parameter grouping by returning the index as integer. |
|
148
|
|
|
* In case no grouping is required false is to be returned. |
|
149
|
|
|
* |
|
150
|
|
|
* @param array $activity |
|
151
|
|
|
* @return integer|false |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function getGroupParameter($activity) { |
|
154
|
1 |
|
return false; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* The extension can define additional navigation entries. The array returned has to contain two keys 'top' |
|
159
|
|
|
* and 'apps' which hold arrays with the relevant entries. |
|
160
|
|
|
* If no further entries are to be added false is no be returned. |
|
161
|
|
|
* |
|
162
|
|
|
* @return array|false |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getNavigation() { |
|
165
|
|
|
$l = $this->getL10N(); |
|
166
|
|
|
return [ |
|
167
|
|
|
'apps' => [ |
|
168
|
|
|
self::FILTER_AVIR => [ |
|
169
|
|
|
'id' => self::FILTER_AVIR, |
|
170
|
|
|
'name' => (string) $l->t('Antivirus'), |
|
171
|
|
|
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_AVIR]), |
|
172
|
|
|
], |
|
173
|
|
|
], |
|
174
|
|
|
'top' => [] |
|
175
|
|
|
]; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* The extension can check if a customer filter (given by a query string like filter=abc) is valid or not. |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $filterValue |
|
182
|
|
|
* @return boolean |
|
183
|
|
|
*/ |
|
184
|
|
|
public function isFilterValid($filterValue) { |
|
185
|
|
|
return $filterValue === self::FILTER_AVIR; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* The extension can filter the types based on the filter if required. |
|
190
|
|
|
* In case no filter is to be applied false is to be returned unchanged. |
|
191
|
|
|
* |
|
192
|
|
|
* @param array $types |
|
193
|
|
|
* @param string $filter |
|
194
|
|
|
* @return array|false |
|
195
|
|
|
*/ |
|
196
|
|
|
public function filterNotificationTypes($types, $filter) { |
|
197
|
|
|
return $filter === self::FILTER_AVIR ? [self::TYPE_VIRUS_DETECTED] : $types; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* For a given filter the extension can specify the sql query conditions including parameters for that query. |
|
202
|
|
|
* In case the extension does not know the filter false is to be returned. |
|
203
|
|
|
* The query condition and the parameters are to be returned as array with two elements. |
|
204
|
|
|
* E.g. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%')); |
|
205
|
|
|
* |
|
206
|
|
|
* @param string $filter |
|
207
|
|
|
* @return array|false |
|
208
|
|
|
*/ |
|
209
|
|
|
public function getQueryForFilter($filter) { |
|
210
|
|
|
if ($filter === self::FILTER_AVIR) { |
|
211
|
|
|
return [ |
|
212
|
|
|
'(`app` = ?)', |
|
213
|
|
|
[self::APP_NAME], |
|
214
|
|
|
]; |
|
215
|
|
|
} |
|
216
|
|
|
return false; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|