From ba5baaf7c982dd87751aad898305ec2e5f567c70 Mon Sep 17 00:00:00 2001 From: somini Date: Thu, 7 Oct 2021 12:15:21 +0100 Subject: [PATCH] [JornalDeNoticiasBridge] Add bridge (#2293) --- bridges/JornalDeNoticiasBridge.php | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 bridges/JornalDeNoticiasBridge.php diff --git a/bridges/JornalDeNoticiasBridge.php b/bridges/JornalDeNoticiasBridge.php new file mode 100644 index 00000000..e61a7a42 --- /dev/null +++ b/bridges/JornalDeNoticiasBridge.php @@ -0,0 +1,54 @@ + array( + 'url' => array( + 'name' => 'URL (relative)', + 'exampleValue' => 'opiniao/catia-domingues.html', + ) + ) + ); + + public function getIcon() { + return 'https://static.globalnoticias.pt/jn/common/images/favicons/favicon-128.png'; + } + + public function getURI() { + switch($this->queriedContext) { + case 'URL': + $url = self::URI . '/' . $this->getInput('url'); + break; + default: + $url = self::URI; + } + return $url; + } + + public function collectData() { + $archives = self::getURI(); + $html = getSimpleHTMLDOMCached($archives); + + foreach($html->find('article') as $element) { + $item = array(); + + $title = $element->find('h2 a', 0); + $link = $element->find('h2 a', 0); + $auth = $element->find('h3 a', 0); + + $item['title'] = $title->plaintext; + $item['uri'] = self::URI . $link->href; + $item['author'] = $auth->plaintext; + + $snippet = $element->find('h4 a', 0); + if ($snippet) { + $item['content'] = $snippet->plaintext; + } + + $this->items[] = $item; + } + } +}