mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-18 08:54:20 +03:00
fix: php errors (notices) (#3115)
This commit is contained in:
parent
8795cb252f
commit
52af2ae34c
9 changed files with 33 additions and 20 deletions
|
@ -313,6 +313,7 @@ class BandcampBridge extends BridgeAbstract
|
||||||
private function apiGet($endpoint, $query_data)
|
private function apiGet($endpoint, $query_data)
|
||||||
{
|
{
|
||||||
$url = self::URI . 'api/' . $endpoint . '?' . http_build_query($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));
|
$data = json_decode(getContents($url));
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ class GoogleSearchBridge extends BridgeAbstract
|
||||||
|
|
||||||
public function collectData()
|
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']);
|
$dom = getSimpleHTMLDOM($this->getURI(), ['Accept-language: en-US']);
|
||||||
if (!$dom) {
|
if (!$dom) {
|
||||||
returnServerError('No results for this query.');
|
returnServerError('No results for this query.');
|
||||||
|
|
|
@ -40,6 +40,9 @@ class MoebooruBridge extends BridgeAbstract
|
||||||
|
|
||||||
foreach ($data as $datai) {
|
foreach ($data as $datai) {
|
||||||
$json = json_decode($datai, true);
|
$json = json_decode($datai, true);
|
||||||
|
if ($json === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['uri'] = $this->getURI() . '/post/show/' . $json['id'];
|
$item['uri'] = $this->getURI() . '/post/show/' . $json['id'];
|
||||||
$item['postid'] = $json['id'];
|
$item['postid'] = $json['id'];
|
||||||
|
|
|
@ -26,9 +26,10 @@ class NasaApodBridge extends BridgeAbstract
|
||||||
//Extract image and explanation
|
//Extract image and explanation
|
||||||
$image_wrapper = $picture_html->find('a', 1);
|
$image_wrapper = $picture_html->find('a', 1);
|
||||||
$image_path = $image_wrapper->href;
|
$image_path = $image_wrapper->href;
|
||||||
|
// This image is not present when youtube embed
|
||||||
$img_placeholder = $image_wrapper->find('img', 0);
|
$img_placeholder = $image_wrapper->find('img', 0);
|
||||||
$img_alt = $img_placeholder->alt;
|
$img_alt = $img_placeholder->alt ?? '';
|
||||||
$img_style = $img_placeholder->style;
|
$img_style = $img_placeholder->style ?? '';
|
||||||
$image_uri = self::URI . $image_path;
|
$image_uri = self::URI . $image_path;
|
||||||
$new_img_placeholder = "<img src=\"$image_uri\" alt=\"$img_alt\" style=\"$img_style\">";
|
$new_img_placeholder = "<img src=\"$image_uri\" alt=\"$img_alt\" style=\"$img_style\">";
|
||||||
$media = "<a href=\"$image_uri\">$new_img_placeholder</a>";
|
$media = "<a href=\"$image_uri\">$new_img_placeholder</a>";
|
||||||
|
|
|
@ -170,10 +170,8 @@ class NationalGeographicBridge extends BridgeAbstract
|
||||||
$image = $story['img'];
|
$image = $story['img'];
|
||||||
$item['enclosures'][] = $image['src'];
|
$item['enclosures'][] = $image['src'];
|
||||||
|
|
||||||
$tags = $story['tags'];
|
foreach ($story['tags'] as $tag) {
|
||||||
foreach ($tags as $tag) {
|
$item['categories'][] = $tag['name'] ?? $tag;
|
||||||
$tag_name = $tag['name'];
|
|
||||||
$item['categories'][] = $tag_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
|
|
|
@ -150,8 +150,6 @@ class RedditBridge extends BridgeAbstract
|
||||||
$flair = '';
|
$flair = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($subreddits as $subreddit) {
|
foreach ($subreddits as $subreddit) {
|
||||||
$name = trim($subreddit);
|
$name = trim($subreddit);
|
||||||
$values = getContents(self::URI
|
$values = getContents(self::URI
|
||||||
|
@ -207,14 +205,17 @@ class RedditBridge extends BridgeAbstract
|
||||||
|
|
||||||
$item['content']
|
$item['content']
|
||||||
= htmlspecialchars_decode($data->selftext_html);
|
= 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
|
// Link with preview
|
||||||
|
|
||||||
if (isset($data->media)) {
|
if (isset($data->media)) {
|
||||||
|
// todo: maybe switch on the type
|
||||||
|
if (isset($data->media->oembed->html)) {
|
||||||
// Reddit embeds content for some sites (e.g. Twitter)
|
// Reddit embeds content for some sites (e.g. Twitter)
|
||||||
$embed = htmlspecialchars_decode(
|
$embed = htmlspecialchars_decode($data->media->oembed->html);
|
||||||
$data->media->oembed->html
|
} else {
|
||||||
);
|
$embed = '';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$embed = '';
|
$embed = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,13 +498,15 @@ EOD;
|
||||||
break;
|
break;
|
||||||
case 'table':
|
case 'table':
|
||||||
$table = '<table>';
|
$table = '<table>';
|
||||||
$theaders = $content['header'];
|
$theaders = $content['header'] ?? null;
|
||||||
|
if ($theaders) {
|
||||||
$tr = '<tr>';
|
$tr = '<tr>';
|
||||||
foreach ($theaders as $header) {
|
foreach ($theaders as $header) {
|
||||||
$tr .= '<th>' . $header . '</th>';
|
$tr .= '<th>' . $header . '</th>';
|
||||||
}
|
}
|
||||||
$tr .= '</tr>';
|
$tr .= '</tr>';
|
||||||
$table .= $tr;
|
$table .= $tr;
|
||||||
|
}
|
||||||
$rows = $content['rows'];
|
$rows = $content['rows'];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$tr = '<tr>';
|
$tr = '<tr>';
|
||||||
|
|
|
@ -60,6 +60,7 @@ class FileCache implements CacheInterface
|
||||||
continue;
|
continue;
|
||||||
} elseif ($cacheFile->isFile()) {
|
} elseif ($cacheFile->isFile()) {
|
||||||
if (filemtime($cacheFile->getPathname()) < time() - $seconds) {
|
if (filemtime($cacheFile->getPathname()) < time() - $seconds) {
|
||||||
|
// todo: sometimes this file doesn't exists
|
||||||
unlink($cacheFile->getPathname());
|
unlink($cacheFile->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +69,7 @@ class FileCache implements CacheInterface
|
||||||
|
|
||||||
public function setScope($scope)
|
public function setScope($scope)
|
||||||
{
|
{
|
||||||
if (is_null($scope) || !is_string($scope)) {
|
if (!is_string($scope)) {
|
||||||
throw new \Exception('The given scope is invalid!');
|
throw new \Exception('The given scope is invalid!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,12 @@ final class Logger
|
||||||
'Exception InvalidArgumentException: Format name invalid',
|
'Exception InvalidArgumentException: Format name invalid',
|
||||||
'Exception InvalidArgumentException: Unknown format given',
|
'Exception InvalidArgumentException: Unknown format given',
|
||||||
'Exception InvalidArgumentException: Bridge name invalid',
|
'Exception InvalidArgumentException: Bridge name invalid',
|
||||||
|
'Exception Exception: Invalid action',
|
||||||
'Exception Exception: twitter: No results for this query',
|
'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) {
|
foreach ($ignoredExceptions as $ignoredException) {
|
||||||
if (str_starts_with($context['message'], $ignoredException)) {
|
if (str_starts_with($context['message'], $ignoredException)) {
|
||||||
|
|
Loading…
Reference in a new issue