diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index 20b4ea93..c041b2b3 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -313,6 +313,7 @@ class BandcampBridge extends BridgeAbstract private function apiGet($endpoint, $query_data) { $url = self::URI . 'api/' . $endpoint . '?' . http_build_query($query_data); + // todo: 429 Too Many Requests happens a lot $data = json_decode(getContents($url)); return $data; } diff --git a/bridges/GoogleSearchBridge.php b/bridges/GoogleSearchBridge.php index 406cf2a9..59465e89 100644 --- a/bridges/GoogleSearchBridge.php +++ b/bridges/GoogleSearchBridge.php @@ -23,6 +23,7 @@ class GoogleSearchBridge extends BridgeAbstract public function collectData() { + // todo: wrap this in try..catch because 429 too many requests happens a lot $dom = getSimpleHTMLDOM($this->getURI(), ['Accept-language: en-US']); if (!$dom) { returnServerError('No results for this query.'); diff --git a/bridges/MoebooruBridge.php b/bridges/MoebooruBridge.php index 1af08575..a7793c39 100644 --- a/bridges/MoebooruBridge.php +++ b/bridges/MoebooruBridge.php @@ -40,6 +40,9 @@ class MoebooruBridge extends BridgeAbstract foreach ($data as $datai) { $json = json_decode($datai, true); + if ($json === null) { + continue; + } $item = []; $item['uri'] = $this->getURI() . '/post/show/' . $json['id']; $item['postid'] = $json['id']; diff --git a/bridges/NasaApodBridge.php b/bridges/NasaApodBridge.php index 5aff63aa..1f6d351a 100644 --- a/bridges/NasaApodBridge.php +++ b/bridges/NasaApodBridge.php @@ -26,9 +26,10 @@ class NasaApodBridge extends BridgeAbstract //Extract image and explanation $image_wrapper = $picture_html->find('a', 1); $image_path = $image_wrapper->href; + // This image is not present when youtube embed $img_placeholder = $image_wrapper->find('img', 0); - $img_alt = $img_placeholder->alt; - $img_style = $img_placeholder->style; + $img_alt = $img_placeholder->alt ?? ''; + $img_style = $img_placeholder->style ?? ''; $image_uri = self::URI . $image_path; $new_img_placeholder = "\"$img_alt\""; $media = "$new_img_placeholder"; diff --git a/bridges/NationalGeographicBridge.php b/bridges/NationalGeographicBridge.php index 146da79c..79a0600b 100644 --- a/bridges/NationalGeographicBridge.php +++ b/bridges/NationalGeographicBridge.php @@ -170,10 +170,8 @@ class NationalGeographicBridge extends BridgeAbstract $image = $story['img']; $item['enclosures'][] = $image['src']; - $tags = $story['tags']; - foreach ($tags as $tag) { - $tag_name = $tag['name']; - $item['categories'][] = $tag_name; + foreach ($story['tags'] as $tag) { + $item['categories'][] = $tag['name'] ?? $tag; } $this->items[] = $item; diff --git a/bridges/RedditBridge.php b/bridges/RedditBridge.php index 7350e849..de80f09d 100644 --- a/bridges/RedditBridge.php +++ b/bridges/RedditBridge.php @@ -150,8 +150,6 @@ class RedditBridge extends BridgeAbstract $flair = ''; } - - foreach ($subreddits as $subreddit) { $name = trim($subreddit); $values = getContents(self::URI @@ -207,14 +205,17 @@ class RedditBridge extends BridgeAbstract $item['content'] = htmlspecialchars_decode($data->selftext_html); - } elseif (isset($data->post_hint) ? $data->post_hint == 'link' : false) { + } elseif (isset($data->post_hint) && $data->post_hint == 'link') { // Link with preview if (isset($data->media)) { - // Reddit embeds content for some sites (e.g. Twitter) - $embed = htmlspecialchars_decode( - $data->media->oembed->html - ); + // todo: maybe switch on the type + if (isset($data->media->oembed->html)) { + // Reddit embeds content for some sites (e.g. Twitter) + $embed = htmlspecialchars_decode($data->media->oembed->html); + } else { + $embed = ''; + } } else { $embed = ''; } diff --git a/bridges/ReutersBridge.php b/bridges/ReutersBridge.php index 17f6a705..77370d65 100644 --- a/bridges/ReutersBridge.php +++ b/bridges/ReutersBridge.php @@ -498,13 +498,15 @@ EOD; break; case 'table': $table = ''; - $theaders = $content['header']; - $tr = ''; - foreach ($theaders as $header) { - $tr .= ''; + $theaders = $content['header'] ?? null; + if ($theaders) { + $tr = ''; + foreach ($theaders as $header) { + $tr .= ''; + } + $tr .= ''; + $table .= $tr; } - $tr .= ''; - $table .= $tr; $rows = $content['rows']; foreach ($rows as $row) { $tr = ''; diff --git a/caches/FileCache.php b/caches/FileCache.php index fde7d18d..d5817a2d 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -60,6 +60,7 @@ class FileCache implements CacheInterface continue; } elseif ($cacheFile->isFile()) { if (filemtime($cacheFile->getPathname()) < time() - $seconds) { + // todo: sometimes this file doesn't exists unlink($cacheFile->getPathname()); } } @@ -68,7 +69,7 @@ class FileCache implements CacheInterface public function setScope($scope) { - if (is_null($scope) || !is_string($scope)) { + if (!is_string($scope)) { throw new \Exception('The given scope is invalid!'); } diff --git a/lib/Logger.php b/lib/Logger.php index 3f4f1034..0b01c07f 100644 --- a/lib/Logger.php +++ b/lib/Logger.php @@ -38,7 +38,12 @@ final class Logger 'Exception InvalidArgumentException: Format name invalid', 'Exception InvalidArgumentException: Unknown format given', 'Exception InvalidArgumentException: Bridge name invalid', + 'Exception Exception: Invalid action', 'Exception Exception: twitter: No results for this query', + // telegram + 'Exception Exception: Unable to find channel. The channel is non-existing or non-public', + // fb + 'Exception Exception: This group is not public! RSS-Bridge only supports public groups!', ]; foreach ($ignoredExceptions as $ignoredException) { if (str_starts_with($context['message'], $ignoredException)) {
' . $header . '
' . $header . '