-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.php
More file actions
45 lines (39 loc) · 1.43 KB
/
Copy pathextension.php
File metadata and controls
45 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class WhiteListExtension extends Minz_Extension {
public function init(): void {
$this->registerTranslates();
if (version_compare(FRESHRSS_VERSION, 1.28) >= 0) {
$this->registerHook(Minz_HookType::CheckUrlBeforeAdd, [$this, 'checkWhiteList']);
} else {
$this->registerHook('check_url_before_add', [$this, 'checkWhiteList']);
}
}
public function handleConfigureAction(): void {
$this->registerTranslates();
if (Minz_Request::isPost()) {
$configuration = [
'patterns' => Minz_Request::paramTextToArray('patterns', []),
];
$this->setSystemConfiguration($configuration);
}
}
public function checkWhiteList(string $url): string {
$patterns = $this->getSystemConfigurationValue('patterns') ?? [];
if (is_array($patterns)) {
foreach ($patterns as $pattern) {
if (1 === preg_match("/{$pattern}/i", $url)) {
return $url;
}
}
}
Minz_Log::warning(_t('ext.white_list.warning.not_white_listed', $url));
throw new FreshRSS_FeedNotAdded_Exception($url);
}
public function getPatterns(): string {
$patterns = $this->getSystemConfigurationValue('patterns') ?? [];
if (is_array($patterns)) {
return implode(PHP_EOL, $patterns);
}
return '';
}
}