fix: various small fixes (#3517)

* fix(asrocknews): Trying to get property src of non-object

Trying to get property 'src' of non-object at bridges/ASRockNewsBridge.php line 37

* refactor(http): tweak max redirs config

* fix(tiktok)

* fix(gizmodo)

* fix(craig)

* fix(nationalg)

* fix(roadandtrack)

* fix(etsy)
This commit is contained in:
Dag 2023-07-08 23:21:55 +02:00 committed by GitHub
parent 1a529fac46
commit 7881c87bed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 11 deletions

View file

@ -34,7 +34,12 @@ class ASRockNewsBridge extends BridgeAbstract
$item['content'] = $contents->innertext;
$item['timestamp'] = $this->extractDate($a->plaintext);
$item['enclosures'][] = $a->find('img', 0)->src;
$img = $a->find('img', 0);
if ($img) {
$item['enclosures'][] = $img->src;
}
$this->items[] = $item;
if (count($this->items) >= 10) {

View file

@ -63,7 +63,7 @@ class CraigslistBridge extends BridgeAbstract
$html = getSimpleHTMLDOM($uri);
// Check if no results page is shown (nearby results)
if ($html->find('.displaycountShow', 0)->plaintext == '0') {
if (($html->find('.displaycountShow', 0)->plaintext ?? '') == '0') {
return;
}

View file

@ -50,8 +50,8 @@ class EtsyBridge extends BridgeAbstract
$item['author'] = $result->find('p.wt-text-gray > span', 2)->plaintext;
$item['content'] = '<p>'
. $result->find('span.currency-symbol', 0)->plaintext
. $result->find('span.currency-value', 0)->plaintext
. ($result->find('span.currency-symbol', 0)->plaintext ?? '')
. ($result->find('span.currency-value', 0)->plaintext ?? '')
. '</p><p>'
. $result->find('a', 0)->title
. '</p>';

View file

@ -22,7 +22,7 @@ class GizmodoBridge extends FeedExpander
// Get header image
$image = $html->find('meta[property="og:image"]', 0)->content;
$item['content'] = $html->find('div.js_post-content', 0)->innertext;
$item['content'] = $html->find('div.js_post-content', 0)->innertext ?? '';
// Get categories
$categories = explode(',', $html->find('meta[name="keywords"]', 0)->content);

View file

@ -319,7 +319,7 @@ EOD;
$content .= $module['note'];
break;
case 'listicle':
$content .= '<h2>' . $module['title'] . '</h2>';
$content .= '<h2>' . ($module['title'] ?? '(no title)') . '</h2>';
if (isset($module['image'])) {
$content .= $this->handleImages($module['image'], $module['image']['cmsType']);
}

View file

@ -49,7 +49,7 @@ class RoadAndTrackBridge extends BridgeAbstract
$item['title'] = $title->innertext;
}
$item['author'] = $article->find('.byline-name', 0)->innertext;
$item['author'] = $article->find('.byline-name', 0)->innertext ?? '';
$item['timestamp'] = strtotime($article->find('.content-info-date', 0)->getAttribute('datetime'));
$content = $article->find('.content-container', 0);

View file

@ -39,7 +39,8 @@ class TikTokBridge extends BridgeAbstract
// todo: find proper link to tiktok item
$link = $div->find('a', 0)->href;
$image = $div->find('img', 0)->src;
$image = $div->find('img', 0)->src ?? '';
$views = $div->find('strong.video-count', 0)->plaintext;
if ($link === 'https://www.tiktok.com/') {

View file

@ -222,13 +222,14 @@ function _http_request(string $url, array $config = []): array
'if_not_modified_since' => null,
'retries' => 3,
'max_filesize' => null,
'max_redirections' => 5,
];
$config = array_merge($defaults, $config);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_MAXREDIRS, $config['max_redirections']);
curl_setopt($ch, CURLOPT_HEADER, false);
$httpHeaders = [];
foreach ($config['headers'] as $name => $value) {
@ -302,10 +303,12 @@ function _http_request(string $url, array $config = []): array
}
if ($attempts > $config['retries']) {
// Finally give up
$curl_error = curl_error($ch);
$curl_errno = curl_errno($ch);
throw new HttpException(sprintf(
'cURL error %s: %s (%s) for %s',
curl_error($ch),
curl_errno($ch),
$curl_error,
$curl_errno,
'https://curl.haxx.se/libcurl/c/libcurl-errors.html',
$url
));