Skip to content

Commit

Permalink
Fix type bug + update to PHP 7.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed Dec 30, 2023
1 parent b869108 commit 4fbd7ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# xExtension-WhiteList

A FreshRSS extension to validate that new feeds are allowed according to a white-list.
The comparison with the white-list uses regex to find matches. If the format used has
to be recognized by the PHP `preg_match` function.
4 changes: 4 additions & 0 deletions configure.phtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php
declare(strict_types=1);
/** @var WhiteListExtension $this */
?>
<form action="<?= _url('extension', 'configure', 'e', urlencode($this->getName())); ?>" method="post">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken(); ?>" />

Expand Down
27 changes: 17 additions & 10 deletions extension.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
<?php

class WhiteListExtension extends Minz_Extension {
public function init() {
public function init(): void {
$this->registerTranslates();

$this->registerHook('check_url_before_add', [$this, 'checkWhiteList']);
}
public function handleConfigureAction() {

public function handleConfigureAction(): void {
$this->registerTranslates();

if (Minz_Request::isPost()) {
$configuration = [
'patterns' => Minz_Request::paramTextToArray('patterns', ''),
'patterns' => Minz_Request::paramTextToArray('patterns', []),
];
$this->setSystemConfiguration($configuration);
}
}

public function checkWhiteList($url) {
foreach ($this->getSystemConfigurationValue('patterns') as $pattern) {
if (1 === preg_match("/{$pattern}/i", $url)) {
return $url;
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() {
return implode(PHP_EOL, $this->getSystemConfigurationValue('patterns') ?? []);
public function getPatterns(): string {
$patterns = $this->getSystemConfigurationValue('patterns') ?? [];
if (is_array($patterns)) {
return implode(PHP_EOL, $patterns);
}
return '';
}
}

0 comments on commit 4fbd7ed

Please sign in to comment.