From 4fbd7ed4cf6d33df78f72fa8168be6391418f9a8 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 30 Dec 2023 16:56:38 +0100 Subject: [PATCH] Fix type bug + update to PHP 7.4+ Related to https://github.com/FreshRSS/Extensions/pull/185 fix https://github.com/FreshRSS/FreshRSS/issues/5989#issuecomment-1872530041 --- README.md | 1 + configure.phtml | 4 ++++ extension.php | 27 +++++++++++++++++---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3c2daa0..3f60249 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/configure.phtml b/configure.phtml index 722b23c..401f193 100644 --- a/configure.phtml +++ b/configure.phtml @@ -1,3 +1,7 @@ +
diff --git a/extension.php b/extension.php index f5d8c3f..5cf129a 100644 --- a/extension.php +++ b/extension.php @@ -1,34 +1,41 @@ 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 ''; } }