From 4b3c3c58d2e2d961a12f78593fe4abe4e172036d Mon Sep 17 00:00:00 2001 From: somini Date: Sun, 1 Dec 2019 10:18:45 +0000 Subject: [PATCH] =?UTF-8?q?[Di=C3=A1rioDoAlentejo]=20Add=20new=20bridge=20?= =?UTF-8?q?(#1360)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bridges/DiarioDoAlentejoBridge.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bridges/DiarioDoAlentejoBridge.php diff --git a/bridges/DiarioDoAlentejoBridge.php b/bridges/DiarioDoAlentejoBridge.php new file mode 100644 index 00000000..806f8031 --- /dev/null +++ b/bridges/DiarioDoAlentejoBridge.php @@ -0,0 +1,60 @@ +30s!), keep the cache timeout high to avoid killing the host */ + $html = getSimpleHTMLDOMCached($this->getURI() . '/pt/noticias-listagem.aspx') + or returnServerError('Could not load content'); + + foreach($html->find('.list_news .item') as $element) { + $item = array(); + + $item_link = $element->find('.body h2.title a', 0); + /* Another broken URL, see also `bridges/ComboiosDePortugalBridge.php` */ + $item['uri'] = self::URI . implode('/', array_map('urlencode', explode('/', $item_link->href))); + $item['title'] = $item_link->innertext; + + $item['timestamp'] = str_ireplace( + array_map(function($name) { return ' ' . $name . ' '; }, self::PT_MONTH_NAMES), + array_map(function($num) { return sprintf('-%02d-', $num); }, range(1, sizeof(self::PT_MONTH_NAMES))), + $element->find('span.date', 0)->innertext); + + /* Fix the Image URL */ + $item_image = $element->find('img.thumb', 0); + $item_image->src = preg_replace('/.*&img=([^&]+).*/', '\1', $item_image->getAttribute('data-src')); + + /* Content: */ + /* - Image */ + /* - Category */ + $content = $item_image . + '
' . $element->find('a.category', 0) . '
'; + $item['content'] = defaultLinkTo($content, self::URI); + + $this->items[] = $item; + } + } +}