From cf780084f9879aa4275aa8ba35332bae843977f6 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 1 Jun 2025 01:36:48 +0200 Subject: [PATCH] Some fixes More fixes needed --- xExtension-Webhook/configure.phtml | 24 ++++++------ xExtension-Webhook/extension.php | 62 ++++++++++++++++++++---------- xExtension-Webhook/request.php | 13 +++++++ 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/xExtension-Webhook/configure.phtml b/xExtension-Webhook/configure.phtml index 36bab79..824f009 100644 --- a/xExtension-Webhook/configure.phtml +++ b/xExtension-Webhook/configure.phtml @@ -5,8 +5,8 @@ declare(strict_types=1); -
- + +
⚙️ @@ -16,7 +16,7 @@ declare(strict_types=1);
- +
@@ -32,22 +32,22 @@ declare(strict_types=1); getSystemConfigurationValue('search_in_title') ? 'checked' : '' ?>> + attributeBool('search_in_title') ? 'checked="checked"' : '' ?> /> getSystemConfigurationValue('search_in_feed') ? 'checked' : '' ?>> + attributeBool('search_in_feed') ? 'checked="checked"' : '' ?> /> getSystemConfigurationValue('search_in_authors') ? 'checked' : '' ?>> + attributeBool('search_in_authors') ? 'checked="checked"' : '' ?> /> getSystemConfigurationValue('search_in_content') ? 'checked' : '' ?>> + attributeBool('search_in_content') ? 'checked="checked"' : '' ?> /> @@ -59,7 +59,7 @@ declare(strict_types=1);
getSystemConfigurationValue('mark_as_read') ? 'checked' : '' ?>> + attributeBool('mark_as_read') ? 'checked="checked"' : '' ?> />
@@ -78,14 +78,14 @@ declare(strict_types=1);
+ value="getWebhookUrl() ?>" />
@@ -190,8 +190,8 @@ declare(strict_types=1);
- - + +
diff --git a/xExtension-Webhook/extension.php b/xExtension-Webhook/extension.php index cd5e8cd..598a989 100644 --- a/xExtension-Webhook/extension.php +++ b/xExtension-Webhook/extension.php @@ -110,6 +110,7 @@ class WebhookExtension extends Minz_Extension { * sends a test webhook request. * * @return void + * @throws Minz_PermissionDeniedException */ public function handleConfigureAction(): void { $this->registerTranslates(); @@ -164,6 +165,9 @@ class WebhookExtension extends Minz_Extension { * * @param FreshRSS_Entry $entry The RSS entry to process * + * @throws FreshRSS_Context_Exception + * @throws Minz_PermissionDeniedException + * * @return FreshRSS_Entry The processed entry (potentially marked as read) */ public function processArticle($entry): FreshRSS_Entry { @@ -171,19 +175,19 @@ class WebhookExtension extends Minz_Extension { return $entry; } - if ((bool)$this->getSystemConfigurationValue("ignore_updated") && $entry->isUpdated()) { + if (FreshRSS_Context::userConf()->attributeBool('ignore_updated') && $entry->isUpdated()) { logWarning(true, "⚠️ ignore_updated: " . $entry->link() . " ♦♦ " . $entry->title()); return $entry; } - $searchInTitle = (bool)($this->getSystemConfigurationValue("search_in_title") ?? false); - $searchInFeed = (bool)($this->getSystemConfigurationValue("search_in_feed") ?? false); - $searchInAuthors = (bool)($this->getSystemConfigurationValue("search_in_authors") ?? false); - $searchInContent = (bool)($this->getSystemConfigurationValue("search_in_content") ?? false); + $searchInTitle = FreshRSS_Context::userConf()->attributeBool('search_in_title') ?? false; + $searchInFeed = FreshRSS_Context::userConf()->attributeBool('search_in_feed') ?? false; + $searchInAuthors = FreshRSS_Context::userConf()->attributeBool('search_in_authors') ?? false; + $searchInContent = FreshRSS_Context::userConf()->attributeBool('search_in_content') ?? false; - $patterns = $this->getSystemConfigurationValue("keywords") ?? []; - $markAsRead = (bool)($this->getSystemConfigurationValue("mark_as_read") ?? false); - $logsEnabled = (bool)($this->getSystemConfigurationValue("enable_logging") ?? false); + $patterns = FreshRSS_Context::userConf()->attributeArray('keywords') ?? []; + $markAsRead = FreshRSS_Context::userConf()->attributeBool('mark_as_read') ?? false; + $logsEnabled = FreshRSS_Context::userConf()->attributeBool('enable_logging') ?? false; $this->logsEnabled = $logsEnabled; // Validate patterns @@ -257,11 +261,13 @@ class WebhookExtension extends Minz_Extension { * @param FreshRSS_Entry $entry The RSS entry to send * @param string $additionalLog Additional context for logging * + * @throws Minz_PermissionDeniedException + * * @return void */ private function sendArticle(FreshRSS_Entry $entry, string $additionalLog = ""): void { try { - $bodyStr = (string)$this->getSystemConfigurationValue("webhook_body"); + $bodyStr = FreshRSS_Context::userConf()->attributeString('webhook_body'); // Replace placeholders with actual values $replacements = [ @@ -278,12 +284,12 @@ class WebhookExtension extends Minz_Extension { $bodyStr = str_replace(array_keys($replacements), array_values($replacements), $bodyStr); sendReq( - (string)$this->getSystemConfigurationValue("webhook_url"), - (string)$this->getSystemConfigurationValue("webhook_method"), - (string)$this->getSystemConfigurationValue("webhook_body_type"), + FreshRSS_Context::userConf()->attributeString('webhook_url'), + FreshRSS_Context::userConf()->attributeString('webhook_method'), + FreshRSS_Context::userConf()->attributeString('webhook_body_type'), $bodyStr, - (array)$this->getSystemConfigurationValue("webhook_headers"), - (bool)$this->getSystemConfigurationValue("enable_logging"), + FreshRSS_Context::userConf()->attributeArray('webhook_headers'), + FreshRSS_Context::userConf()->attributeBool('enable_logging'), $additionalLog, ); } catch (Throwable $err) { @@ -348,11 +354,13 @@ class WebhookExtension extends Minz_Extension { * Returns the configured keywords as a newline-separated string * for display in the configuration form. * + * @throws FreshRSS_Context_Exception + * * @return string Keywords separated by newlines */ public function getKeywordsData(): string { - $keywords = $this->getSystemConfigurationValue("keywords"); - return implode(PHP_EOL, is_array($keywords) ? $keywords : []); + $keywords = FreshRSS_Context::userConf()->attributeArray('keywords') ?? []; + return implode(PHP_EOL, $keywords); } /** @@ -361,10 +369,12 @@ class WebhookExtension extends Minz_Extension { * Returns the configured HTTP headers as a newline-separated string * for display in the configuration form. * + * @throws FreshRSS_Context_Exception + * * @return string HTTP headers separated by newlines */ public function getWebhookHeaders(): string { - $headers = $this->getSystemConfigurationValue("webhook_headers"); + $headers = FreshRSS_Context::userConf()->attributeArray('webhook_headers'); return implode( PHP_EOL, is_array($headers) ? $headers : ($this->webhook_headers ?? []), @@ -376,10 +386,12 @@ class WebhookExtension extends Minz_Extension { * * Returns the configured webhook URL or the default if none is set. * + * @throws FreshRSS_Context_Exception + * * @return string The webhook URL */ public function getWebhookUrl(): string { - return (string)($this->getSystemConfigurationValue("webhook_url") ?? $this->webhook_url); + return FreshRSS_Context::userConf()->attributeString('webhook_url') ?? $this->webhook_url; } /** @@ -387,11 +399,13 @@ class WebhookExtension extends Minz_Extension { * * Returns the configured webhook body template or the default if none is set. * + * @throws FreshRSS_Context_Exception + * * @return string The webhook body template */ public function getWebhookBody(): string { - $body = $this->getSystemConfigurationValue("webhook_body"); - return (!$body || $body === "") ? $this->webhook_body : (string)$body; + $body = FreshRSS_Context::userConf()->attributeString('webhook_body'); + return ($body === null || $body === '') ? $this->webhook_body : $body; } /** @@ -399,10 +413,12 @@ class WebhookExtension extends Minz_Extension { * * Returns the configured body type (json/form) or the default if none is set. * + * @throws FreshRSS_Context_Exception + * * @return string The webhook body type */ public function getWebhookBodyType(): string { - return (string)($this->getSystemConfigurationValue("webhook_body_type") ?? $this->webhook_body_type->value); + return FreshRSS_Context::userConf()->attributeString('webhook_body_type') ?? $this->webhook_body_type->value; } } @@ -413,6 +429,8 @@ class WebhookExtension extends Minz_Extension { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log * + * @throws Minz_PermissionDeniedException + * * @return void */ function _LOG(bool $logEnabled, $data): void { @@ -426,6 +444,8 @@ function _LOG(bool $logEnabled, $data): void { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log * + * @throws Minz_PermissionDeniedException + * * @return void */ function _LOG_ERR(bool $logEnabled, $data): void { diff --git a/xExtension-Webhook/request.php b/xExtension-Webhook/request.php index 56f93ab..5a4143d 100644 --- a/xExtension-Webhook/request.php +++ b/xExtension-Webhook/request.php @@ -18,6 +18,7 @@ declare(strict_types=1); * * @throws InvalidArgumentException When invalid parameters are provided * @throws JsonException When JSON encoding/decoding fails + * @throws Minz_PermissionDeniedException * @throws RuntimeException When cURL operations fail * * @return void @@ -124,6 +125,7 @@ function configureHttpMethod(CurlHandle $ch, string $method): void { * * @throws JsonException When JSON processing fails * @throws InvalidArgumentException When unsupported body type is provided + * @throws Minz_PermissionDeniedException * * @return string|null Processed body content or null if no body needed */ @@ -183,6 +185,8 @@ function configureHeaders(array $headers, string $bodyType): array { * @param string|null $body Processed request body * @param string[] $headers Array of HTTP headers * + * @throws Minz_PermissionDeniedException + * * @return void */ function logRequest( @@ -217,6 +221,7 @@ function logRequest( * @param bool $logEnabled Whether logging is enabled * * @throws RuntimeException When cURL execution fails + * @throws Minz_PermissionDeniedException * * @return void */ @@ -244,6 +249,8 @@ function executeRequest(CurlHandle $ch, bool $logEnabled): void { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log (will be converted to string) * + * @throws Minz_PermissionDeniedException + * * @return void */ function logWarning(bool $logEnabled, $data): void { @@ -261,6 +268,8 @@ function logWarning(bool $logEnabled, $data): void { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log (will be converted to string) * + * @throws Minz_PermissionDeniedException + * * @return void */ function logError(bool $logEnabled, $data): void { @@ -276,6 +285,8 @@ function logError(bool $logEnabled, $data): void { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log * + * @throws Minz_PermissionDeniedException + * * @return void */ function LOG_WARN(bool $logEnabled, $data): void { @@ -289,6 +300,8 @@ function LOG_WARN(bool $logEnabled, $data): void { * @param bool $logEnabled Whether logging is enabled * @param mixed $data Data to log * + * @throws Minz_PermissionDeniedException + * * @return void */ function LOG_ERR(bool $logEnabled, $data): void {