[PicalaBridge] Fix article without image (#3429)

Co-authored-by: Clement Desmidt <clement@desmidt.fr>
This commit is contained in:
Shikiryu 2023-06-09 17:30:11 +02:00 committed by GitHub
parent ca351edbfe
commit e859497d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 7 deletions

View File

@ -58,17 +58,26 @@ class PicalaBridge extends BridgeAbstract
{
$fullhtml = getSimpleHTMLDOM($this->getURI());
foreach ($fullhtml->find('.list-container-category a') as $article) {
$srcsets = explode(',', $article->find('img', 0)->getAttribute('srcset'));
$image = explode(' ', trim(array_shift($srcsets)))[0];
$firstImage = $article->find('img', 0);
$image = null;
if ($firstImage !== null) {
$srcsets = explode(',', $firstImage->getAttribute('srcset'));
$image = explode(' ', trim(array_shift($srcsets)))[0];
}
$item = [];
$item['uri'] = self::URI . $article->href;
$item['title'] = $article->find('h2', 0)->plaintext;
$item['content'] = sprintf(
'<img src="%s" /><br>%s',
$image,
$article->find('.teaser__text', 0)->plaintext
);
if ($image === null) {
$item['content'] = $article->find('.teaser__text', 0)->plaintext;
} else {
$item['content'] = sprintf(
'<img src="%s" /><br>%s',
$image,
$article->find('.teaser__text', 0)->plaintext
);
}
$this->items[] = $item;
}
}