fix: various bug fixes (#3102)

* fix: Undefined offset: 4

* fix: Trying to access array offset on value of type bool

* fix: Undefined variable: photo at bridges/TelegramBridge.php line 287

* fix: Trying to get property innertext of non-object at bridges/ZDNetBridge.php line 186

* fix: Undefined index: Category at bridges/UnraidCommunityApplicationsBridge.php line 42

* fix: Undefined index: fullUrl at bridges/EuronewsBridge.php line 61
This commit is contained in:
Dag 2022-10-16 20:26:33 +02:00 committed by GitHub
parent ffbc107687
commit 37f1ab726b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 71 deletions

View File

@ -187,6 +187,12 @@ EOT;
private function scrapePriceGeneric($html)
{
$default = [
'price' => null,
'displayPrice' => null,
'currency' => null,
'shipping' => null,
];
$priceDiv = null;
foreach (self::PRICE_SELECTORS as $sel) {
@ -197,58 +203,48 @@ EOT;
}
if (!$priceDiv) {
return false;
return $default;
}
$priceString = str_replace(str_split(self::WHITESPACE), '', $priceDiv->plaintext);
preg_match('/(\d+\.\d{0,2})/', $priceString, $matches);
$price = $matches[0];
$price = $matches[0] ?? null;
$currency = str_replace($price, '', $priceString);
if ($price != null && $currency != null) {
return [
'price' => $price,
'displayPrice' => null,
'currency' => $currency,
'shipping' => '0'
];
}
return false;
return $default;
}
private function renderContent($image, $data)
{
$price = $data['displayPrice'];
if (!$price) {
$price = "{$data['price']} {$data['currency']}";
}
$html = "$image<br>Price: $price";
if ($data['shipping'] !== '0') {
$html .= "<br>Shipping: {$data['shipping']} {$data['currency']}</br>";
}
return $html;
}
/**
* Scrape method for Amazon product page
* @return [type] [description]
*/
public function collectData()
{
$html = $this->getHtml();
$this->title = $this->getTitle($html);
$imageTag = $this->getImage($html);
$image = $this->getImage($html);
$data = $this->scrapePriceGeneric($html);
// render
$content = '';
$price = $data['displayPrice'];
if (!$price) {
$price = sprintf('%s %s', $data['price'], $data['currency']);
}
$content .= sprintf('%s<br>Price: %s', $image, $price);
if ($data['shipping'] !== '0') {
$content .= sprintf('<br>Shipping: %s %s</br>', $data['shipping'], $data['currency']);
}
$item = [
'title' => $this->title,
'uri' => $this->getURI(),
'content' => $this->renderContent($imageTag, $data),
'content' => $content,
// This is to ensure that feed readers notice the price change
'uid' => md5($data['price'])
];

View File

@ -58,7 +58,7 @@ class EuronewsBridge extends BridgeAbstract
$data = json_decode($json, true);
foreach ($data as $datum) {
$datum_uri = $root_url . $datum['fullUrl'];
$datum_uri = $root_url . $datum['path'];
$url_datum = $this->getItemContent($datum_uri);
$categories = [];
if (array_key_exists('program', $datum)) {

View File

@ -91,11 +91,14 @@ class PornhubBridge extends BridgeAbstract
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $image . '"></a>';
}
// date hack, guess upload YYYYMMDD from thumbnail URL (format: https://ci.phncdn.com/videos/201907/25/--- )
$uploaded = explode('/', $image);
$uploaded = strtotime($uploaded[4] . $uploaded[5]);
$item['timestamp'] = $uploaded;
if (isset($uploaded[4])) {
// date hack, guess upload YYYYMMDD from thumbnail URL (format: https://ci.phncdn.com/videos/201907/25/--- )
$uploadTimestamp = strtotime($uploaded[4] . $uploaded[5]);
$item['timestamp'] = $uploadTimestamp;
} else {
// The thumbnail url did not have a date in it for some unknown reason
}
$this->items[] = $item;
}
}

View File

@ -282,12 +282,16 @@ EOD;
preg_match($this->backgroundImageRegex, $messageDiv->find('i.link_preview_video_thumb', 0)->style, $photo);
} elseif ($messageDiv->find('i.tgme_widget_message_roundvideo_thumb')) {
preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_roundvideo_thumb', 0)->style, $photo);
} else {
// Not all videos have a poster image
$photo = [null, null];
}
$this->enclosures[] = $photo[1];
// Intentionally omitting preload="none" on <video>
return <<<EOD
<video controls="" poster="{$photo[1]}" style="max-width:100%;" preload="none">
<video controls="" poster="{$photo[1]}" style="max-width:100%;">
<source src="{$messageDiv->find('video', 0)->src}" type="video/mp4">
</video>
EOD;

View File

@ -31,50 +31,52 @@ class UnraidCommunityApplicationsBridge extends BridgeAbstract
{
$this->fetchApps();
$this->sortApps();
Debug::log('Building RSS feed');
foreach ($this->apps as $app) {
if (!array_key_exists('Language', $app)) {
$item = [];
$item['title'] = $app['Name'];
$item['timestamp'] = $app['FirstSeen'];
$item['author'] = explode('\'', $app['Repo'])[0];
$item['categories'] = explode(' ', $app['Category']);
$item['content'] = '';
if (array_key_exists('Language', $app)) {
continue;
}
$item = [];
$item['title'] = $app['Name'];
$item['timestamp'] = $app['FirstSeen'];
$item['author'] = explode('\'', $app['Repo'])[0];
$item['content'] = '';
if (array_key_exists('Icon', $app)) {
$item['content'] .= '<img style="width: 64px" src="'
. $app['Icon']
. '">';
}
if (isset($app['CategoryList'])) {
$item['categories'] = $app['CategoryList'];
}
if (array_key_exists('Overview', $app)) {
$item['content'] .= '<p>'
. $app['Overview']
. '</p>';
}
if (array_key_exists('Icon', $app)) {
$item['content'] .= '<img style="width: 64px" src="'
. $app['Icon']
. '">';
}
if (array_key_exists('Project', $app)) {
$item['uri'] = $app['Project'];
}
if (array_key_exists('Overview', $app)) {
$item['content'] .= '<p>'
. $app['Overview']
. '</p>';
}
if (array_key_exists('Registry', $app)) {
$item['content'] .= '<br><a href="'
. $app['Registry']
. '">Docker Hub</a>';
}
if (array_key_exists('Project', $app)) {
$item['uri'] = $app['Project'];
}
if (array_key_exists('Support', $app)) {
$item['content'] .= '<br><a href="'
. $app['Support']
. '">Support</a>';
}
if (array_key_exists('Registry', $app)) {
$item['content'] .= '<br><a href="'
. $app['Registry']
. '">Docker Hub</a>';
}
$this->items[] = $item;
if (array_key_exists('Support', $app)) {
$item['content'] .= '<br><a href="'
. $app['Support']
. '">Support</a>';
}
if (count($this->items) >= 15) {
break;
}
$this->items[] = $item;
if (count($this->items) >= 150) {
break;
}
}
}

View File

@ -180,10 +180,16 @@ class ZDNetBridge extends FeedExpander
$article = getSimpleHTMLDOMCached($item['uri']);
if (!$article) {
returnServerError('Could not request ZDNet: ' . $url);
Logger::info('Unable to parse the dom from ' . $item['uri']);
return $item;
}
$contents = $article->find('article', 0)->innertext;
$articleTag = $article->find('article', 0) ?? $article->find('.c-articleContent', 0);
if (!$articleTag) {
Logger::info('Unable to parse <article> tag in ' . $item['uri']);
return $item;
}
$contents = $articleTag->innertext;
foreach (
[
'<div class="shareBar"',