From 2fc4779f033a8e3c7b7073fd6c279d5247747ca3 Mon Sep 17 00:00:00 2001 From: Scrub000 Date: Tue, 3 Jun 2025 20:04:08 +1000 Subject: [PATCH] [ClimateCouncilBridge] Add bridge --- bridges/ClimateCouncilBridge.php | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 bridges/ClimateCouncilBridge.php diff --git a/bridges/ClimateCouncilBridge.php b/bridges/ClimateCouncilBridge.php new file mode 100644 index 00000000..85c66e1b --- /dev/null +++ b/bridges/ClimateCouncilBridge.php @@ -0,0 +1,84 @@ +find('article.post') as $article) { + $a = $article->find('h3.post__title a', 0); + if (!$a) { + continue; + } + + $title = trim($a->plaintext); + $url = $a->href; + if (strpos($url, 'http') !== 0) { + $url = 'https://www.climatecouncil.org.au' . $url; + } + + $img = $article->find('div.post__image img', 0); + $thumbnailUrl = $img ? $img->src : ''; + + $categorySpan = $article->find('span.post__meta__category', 0); + $categories = $categorySpan ? [trim($categorySpan->plaintext)] : []; + + $content = ''; + $timestamp = time(); + $author = 'Climate Council'; + + $articleHtml = @getSimpleHTMLDOM($url); + if ($articleHtml) { + $contentDiv = $articleHtml->find('div.entry-content', 0); + if ($contentDiv) { + $endsFound = false; + + foreach ($contentDiv->find('p') as $p) { + $text = trim($p->plaintext); + if (strtoupper($text) === 'ENDS') { + $endsFound = true; + $p->outertext = ''; + continue; + } + if ($endsFound) { + $p->outertext = ''; + } + } + + if ($thumbnailUrl) { + $thumbnailHtml = '
'; + $content = $thumbnailHtml . $contentDiv->innertext; + } else { + $content = $contentDiv->innertext; + } + } + + $timeEl = $articleHtml->find('time', 0); + if ($timeEl && isset($timeEl->datetime)) { + $timestamp = strtotime($timeEl->datetime); + } + + $authorEl = $articleHtml->find('a[rel=author]', 0); + if ($authorEl) { + $author = trim($authorEl->plaintext); + } + } + + $this->items[] = [ + 'title' => $title, + 'uri' => $url, + 'author' => $author, + 'timestamp' => $timestamp, + 'content' => $content ?: 'Content not found.', + 'categories' => $categories, + ]; + } + } +}