Some fixes

More fixes needed
This commit is contained in:
Alexandre Alapetite 2025-06-01 01:36:48 +02:00
parent 5fe38204dc
commit cf780084f9
No known key found for this signature in database
GPG key ID: A24378C38E812B23
3 changed files with 66 additions and 33 deletions

View file

@ -5,8 +5,8 @@ declare(strict_types=1);
<small>
<?= _t('ext.webhook.description') ?>
</small>
<form action="<?php echo _url('extension', 'configure', 'e', urlencode($this->getName())); ?>" method="post">
<input type="hidden" name="_csrf" value="<?php echo FreshRSS_Auth::csrfToken(); ?>" />
<form action="<?= _url('extension', 'configure', 'e', urlencode($this->getName())) ?>" method="post">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
<fieldset>
<legend><?= _t('ext.webhook.event_settings') ?> ⚙️</legend>
@ -16,7 +16,7 @@ declare(strict_types=1);
<div class="form-group">
<label class="group-name" for="keywords"><?= _t('ext.webhook.keywords') ?></label>
<div class="group-controls">
<textarea name="keywords" id="keywords"><?php echo $this->getKeywordsData(); ?></textarea>
<textarea name="keywords" id="keywords"><?= $this->getKeywordsData() ?></textarea>
<br />
<small>
<?= _t('ext.webhook.keywords_description') ?>
@ -32,22 +32,22 @@ declare(strict_types=1);
<tr>
<td class="group">
<input type="checkbox" name="search_in_title" id="search_in_title" value="1"
<?= (bool)$this->getSystemConfigurationValue('search_in_title') ? 'checked' : '' ?>>
<?= FreshRSS_Context::userConf()->attributeBool('search_in_title') ? 'checked="checked"' : '' ?> />
<label for="search_in_title"><b><?= _t('ext.webhook.search_in_title_label') ?></b>&nbsp; </label>
</td>
<td class="group">
<input type="checkbox" name="search_in_feed" id="search_in_feed" value="1"
<?= (bool)$this->getSystemConfigurationValue('search_in_feed') ? 'checked' : '' ?>>
<?= FreshRSS_Context::userConf()->attributeBool('search_in_feed') ? 'checked="checked"' : '' ?> />
<label for="search_in_feed"><?= _t('ext.webhook.search_in_feed_label') ?></label>
</td>
<td class="group">
<input type="checkbox" name="search_in_authors" id="search_in_authors" value="1"
<?= (bool)$this->getSystemConfigurationValue('search_in_authors') ? 'checked' : '' ?>>
<?= FreshRSS_Context::userConf()->attributeBool('search_in_authors') ? 'checked="checked"' : '' ?> />
<label for="search_in_authors"><?= _t('ext.webhook.search_in_authors_label') ?></label>
</td>
<td class="group">
<input type="checkbox" name="search_in_content" id="search_in_content" value="1"
<?= (bool)$this->getSystemConfigurationValue('search_in_content') ? 'checked' : '' ?>>
<?= FreshRSS_Context::userConf()->attributeBool('search_in_content') ? 'checked="checked"' : '' ?> />
<label for="search_in_content"><?= _t('ext.webhook.search_in_content_label') ?></label>
</td>
</tr>
@ -59,7 +59,7 @@ declare(strict_types=1);
<label class="group-name" for="mark_as_read"><?= _t('ext.webhook.mark_as_read') ?></label>
<div class="group-controls">
<input type="checkbox" name="mark_as_read" id="mark_as_read" value="1"
<?= (bool)$this->getSystemConfigurationValue('mark_as_read') ? 'checked' : '' ?>>
<?= FreshRSS_Context::userConf()->attributeBool('mark_as_read') ? 'checked="checked"' : '' ?> />
</div>
</div>
@ -78,14 +78,14 @@ declare(strict_types=1);
<div class="group-controls">
<select id="webhook_method" name="webhook_method">
<?php
$currentMethod = $this->getSystemConfigurationValue('webhook_method') ?? $this->webhook_method->value;
$currentMethod = FreshRSS_Context::userConf()->attributeString('webhook_method') ?? $this->webhook_method->value;
$supportedMethods = [HTTP_METHOD::POST, HTTP_METHOD::GET, HTTP_METHOD::PUT];
foreach ($supportedMethods as $method): ?>
<option value="<?= $method->value ?>" <?= $currentMethod === $method->value ? 'selected' : '' ?>><?= $method->value ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="webhook_url" id="webhook_url"
value="<?= $this->getWebhookUrl() ?>"></input>
value="<?= $this->getWebhookUrl() ?>" />
</div>
</div>
@ -190,8 +190,8 @@ declare(strict_types=1);
<!-- ---------------------[ SUBMIT & CANCEL ]-------------------------------------- -->
<div class="form-group form-actions">
<div class="group-controls">
<button type="submit" class="btn btn-important"><?php echo _t('gen.action.submit'); ?></button>
<button type="reset" class="btn"><?php echo _t('gen.action.cancel'); ?></button>
<button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button>
<button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button>
<button type="menu" class="btn"><?= _t('ext.webhook.save_and_send_test_req') ?></button>
</div>
</div>

View file

@ -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 {

View file

@ -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 {