Skip to content

Commit

Permalink
[PicalaBridge] Fix article without image
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Desmidt committed Jun 9, 2023
1 parent ca351ed commit 3dbdbfb
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions bridges/PicalaBridge.php
Expand Up @@ -58,17 +58,26 @@ public function collectData()
{
$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;
}
}
Expand Down

0 comments on commit 3dbdbfb

Please sign in to comment.