From c30056dddc28dfdcb080cd4b58892b78c80bd9f4 Mon Sep 17 00:00:00 2001 From: Dag Date: Sat, 6 Apr 2024 17:59:53 +0200 Subject: [PATCH] tweaks --- bridges/FilterBridge.php | 2 +- bridges/TrelloBridge.php | 34 ++++++++++------------------------ bridges/TwitchBridge.php | 2 +- formats/HtmlFormat.php | 2 +- lib/BridgeAbstract.php | 9 +++++++++ lib/contents.php | 2 ++ 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/bridges/FilterBridge.php b/bridges/FilterBridge.php index 1add47f49cf..3448a8c7cfe 100644 --- a/bridges/FilterBridge.php +++ b/bridges/FilterBridge.php @@ -77,7 +77,7 @@ public function collectData() { $url = $this->getInput('url'); if (!Url::validate($url)) { - returnClientError('The url parameter must either refer to http or https protocol.'); + throw new \Exception('The url parameter must either refer to http or https protocol.'); } $this->collectExpandableDatas($this->getURI()); } diff --git a/bridges/TrelloBridge.php b/bridges/TrelloBridge.php index cab2bde2880..42651fd13fc 100644 --- a/bridges/TrelloBridge.php +++ b/bridges/TrelloBridge.php @@ -553,10 +553,8 @@ class TrelloBridge extends BridgeAbstract private function queryAPI($path, $params = []) { - $data = json_decode(getContents('https://trello.com/1/' - . $path - . '?' - . http_build_query($params))); + $url = 'https://trello.com/1/' . $path . '?' . http_build_query($params); + $data = json_decode(getContents($url)); return $data; } @@ -576,33 +574,21 @@ private function renderAction($action, $textOnly = false) && !$textOnly && isset($entity->originalUrl) ) { - $string = '

'; + $string = sprintf( + '

', + $entity->originalUrl, + $entity->previewUrl ?? '' + ); } elseif ($type === 'card' && !$textOnly) { - $string = '' - . $entity->text - . ''; + $string = sprintf('%s', $entity->shortLink, $entity->text); } elseif ($type === 'member' && !$textOnly) { - $string = '' - . $entity->text - . ''; + $string = sprintf('%s', $entity->username, $entity->text); } elseif ($type === 'date') { $string = gmdate('M j, Y \a\t g:i A T', strtotime($entity->date)); } elseif ($type === 'translatable') { $string = self::ACTION_TEXTS[$entity->translationKey]; } else { - if (isset($entity->text)) { - $string = $entity->text; - } else { - $string = ''; - } + $string = $entity->text ?? ''; } $strings['{' . $entity_name . '}'] = $string; } diff --git a/bridges/TwitchBridge.php b/bridges/TwitchBridge.php index 9e70944e1fa..424cd6e3b20 100644 --- a/bridges/TwitchBridge.php +++ b/bridges/TwitchBridge.php @@ -99,7 +99,7 @@ public function collectData() $user = $data->user; if ($user->videos === null) { // twitch regularly does this for unknown reasons - $this->logger->info('Twitch returned empty set of videos', ['data' => $data]); + //$this->logger->info('Twitch returned empty set of videos', ['data' => $data]); return; } diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 1e2f60e62cf..37ef3a930db 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -6,7 +6,7 @@ class HtmlFormat extends FormatAbstract public function stringify() { - // This query string comes in already url decoded + // This query string is url encoded $queryString = $_SERVER['QUERY_STRING']; $feedArray = $this->getFeed(); diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 1456e1c3e24..2467dec60e1 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -6,8 +6,17 @@ abstract class BridgeAbstract const URI = ''; const DONATION_URI = ''; const DESCRIPTION = 'No description provided'; + + /** + * Preferably a github username + */ const MAINTAINER = 'No maintainer'; + + /** + * Cache TTL in seconds + */ const CACHE_TIMEOUT = 3600; + const CONFIGURATION = []; const PARAMETERS = []; const TEST_DETECT_PARAMETERS = []; diff --git a/lib/contents.php b/lib/contents.php index 43db8c031dc..ba6dd531a10 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -17,6 +17,8 @@ function getContents( $httpClient = RssBridge::getHttpClient(); $cache = RssBridge::getCache(); + // TODO: consider url validation at this point + $httpHeadersNormalized = []; foreach ($httpHeaders as $httpHeader) { $parts = explode(':', $httpHeader);