2020-08-27 08:38:51 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DiarioDeNoticiasBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2020-08-27 08:38:51 +03:00
|
|
|
const NAME = 'Diário de Notícias (PT)';
|
|
|
|
const URI = 'https://dn.pt';
|
|
|
|
const DESCRIPTION = 'Diário de Notícias (DN.PT)';
|
|
|
|
const MAINTAINER = 'somini';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'Tag' => [
|
|
|
|
'n' => [
|
|
|
|
'name' => 'Tag Name',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'rogerio-casanova',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2020-08-27 08:38:51 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
const MONPT = [
|
2022-07-01 16:10:30 +03:00
|
|
|
'jan',
|
|
|
|
'fev',
|
|
|
|
'mar',
|
|
|
|
'abr',
|
2020-08-27 08:38:51 +03:00
|
|
|
'mai',
|
2022-07-01 16:10:30 +03:00
|
|
|
'jun',
|
|
|
|
'jul',
|
2020-08-27 08:38:51 +03:00
|
|
|
'ago',
|
|
|
|
'set',
|
2022-07-01 16:10:30 +03:00
|
|
|
'out',
|
2020-08-27 08:38:51 +03:00
|
|
|
'nov',
|
2022-07-01 16:10:30 +03:00
|
|
|
'dez',
|
2020-08-27 08:38:51 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return 'https://static.globalnoticias.pt/dn/common/images/favicons/favicon-128.png';
|
|
|
|
}
|
2020-10-15 10:53:19 +03:00
|
|
|
|
2020-08-27 08:38:51 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Tag':
|
|
|
|
$name = self::NAME . ' | Tag | ' . $this->getInput('n');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$name = self::NAME;
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI()
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2020-08-27 08:38:51 +03:00
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Tag':
|
|
|
|
$url = self::URI . '/tag/' . $this->getInput('n') . '.html';
|
2022-07-01 16:10:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-02 12:36:09 +03:00
|
|
|
$url = self::URI;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2022-01-02 12:36:09 +03:00
|
|
|
return $url;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-08-27 08:38:51 +03:00
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
2022-07-09 09:13:07 +03:00
|
|
|
$archives = $this->getURI();
|
2020-08-27 08:38:51 +03:00
|
|
|
$html = getSimpleHTMLDOMCached($archives);
|
|
|
|
|
|
|
|
foreach ($html->find('article') as $element) {
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$title = $element->find('.t-am-title', 0);
|
|
|
|
$link = $element->find('a.t-am-text', 0);
|
|
|
|
|
|
|
|
$item['title'] = $title->plaintext;
|
|
|
|
$item['uri'] = self::URI . $link->href;
|
|
|
|
|
|
|
|
$snippet = $element->find('.t-am-lead', 0);
|
|
|
|
if ($snippet) {
|
|
|
|
$item['content'] = $snippet->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-08-27 08:38:51 +03:00
|
|
|
preg_match('|edicao-do-dia\\/(?P<day>\d\d)-(?P<monpt>\w\w\w)-(?P<year>\d\d\d\d)|', $link->href, $d);
|
|
|
|
if ($d) {
|
|
|
|
$item['timestamp'] = sprintf('%s-%s-%s', $d['year'], array_search($d['monpt'], self::MONPT) + 1, $d['day']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-08-27 08:38:51 +03:00
|
|
|
}
|