From 52145813861e84cabca2da21a79c7959829382c1 Mon Sep 17 00:00:00 2001 From: Simon Alberny Date: Wed, 15 Jan 2025 20:50:56 +0100 Subject: [PATCH] Fix MondeDiplo empty date (#4407) --- bridges/MondeDiploBridge.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bridges/MondeDiploBridge.php b/bridges/MondeDiploBridge.php index 7c897f8f..e47bb5ad 100644 --- a/bridges/MondeDiploBridge.php +++ b/bridges/MondeDiploBridge.php @@ -19,14 +19,28 @@ class MondeDiploBridge extends BridgeAbstract foreach ($html->find('div.unarticle') as $article) { $element = $article->parent(); - $title = $element->find('h3', 0)->plaintext; - $datesAuteurs = $element->find('div.dates_auteurs', 0)->plaintext; + $titleElement = $element->find('h3', 0); + if (!$titleElement) { + continue; + } + $title = $titleElement->plaintext; + $datesAuteursElement = $element->find('div.dates_auteurs', 0); + $datesAuteurs = is_null($datesAuteursElement) ? '' : $element->find('div.dates_auteurs', 0)->plaintext; $item = []; $item['uri'] = urljoin(self::URI, $element->href); - $item['title'] = $this->cleanText($title) . ' - ' . $this->cleanText($datesAuteurs); + $item['title'] = $this->getItemTitle($title, $datesAuteurs); $item['content'] = $this->cleanText(str_replace([$title, $datesAuteurs], '', $element->plaintext)); $this->items[] = $item; } } + + private function getItemTitle($title, $datesAuteurs) + { + $itemTitle = $this->cleanText($title); + if (strlen($datesAuteurs) > 0) { + $itemTitle .= ' - ' . $this->cleanText($datesAuteurs); + } + return $itemTitle; + } }