2021-03-17 19:30:47 +03:00
|
|
|
<?php
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class PresidenciaPTBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Presidência da República Portuguesa';
|
|
|
|
const URI = 'https://www.presidencia.pt';
|
|
|
|
const DESCRIPTION = 'Presidência da República Portuguesa';
|
|
|
|
const MAINTAINER = 'somini';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'Section' => [
|
|
|
|
'/atualidade/noticias' => [
|
|
|
|
'name' => 'Notícias',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
],
|
|
|
|
'/atualidade/mensagens' => [
|
|
|
|
'name' => 'Mensagens',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
],
|
|
|
|
'/atualidade/atividade-legislativa' => [
|
|
|
|
'name' => 'Atividade Legislativa',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
],
|
|
|
|
'/atualidade/notas-informativas' => [
|
|
|
|
'name' => 'Notas Informativas',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
2021-03-17 19:30:47 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PT_MONTH_NAMES = [
|
|
|
|
'janeiro',
|
|
|
|
'fevereiro',
|
|
|
|
'março',
|
|
|
|
'abril',
|
|
|
|
'maio',
|
|
|
|
'junho',
|
|
|
|
'julho',
|
|
|
|
'agosto',
|
|
|
|
'setembro',
|
|
|
|
'outubro',
|
|
|
|
'novembro',
|
|
|
|
'dezembro'];
|
2021-05-09 22:22:10 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return 'https://www.presidencia.pt/Theme/favicon/apple-touch-icon.png';
|
|
|
|
}
|
2021-03-17 19:30:47 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
foreach (array_keys($this->getParameters()['Section']) as $k) {
|
|
|
|
Debug::log('Key: ' . var_export($k, true));
|
|
|
|
if ($this->getInput($k)) {
|
|
|
|
$html = getSimpleHTMLDOMCached($this->getURI() . $k);
|
2021-03-17 19:30:47 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($html->find('#atualidade-list article.card-block') as $element) {
|
|
|
|
$item = [];
|
2021-03-17 19:30:47 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$link = $element->find('a', 0);
|
|
|
|
$etitle = $element->find('.content-box h2', 0);
|
|
|
|
$edts = $element->find('p', 1);
|
|
|
|
$edt = html_entity_decode($edts->innertext, ENT_HTML5);
|
2021-03-17 19:30:47 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$item['title'] = strip_tags($etitle->innertext);
|
|
|
|
$item['uri'] = self::URI . $link->href;
|
|
|
|
$item['description'] = $element;
|
|
|
|
$item['timestamp'] = str_ireplace(
|
|
|
|
array_map(function ($name) {
|
|
|
|
return ' de ' . $name . ' de ';
|
|
|
|
}, self::PT_MONTH_NAMES),
|
|
|
|
array_map(function ($num) {
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
return sprintf('-%02d-', $num);
|
2022-07-01 16:10:30 +03:00
|
|
|
}, range(1, sizeof(self::PT_MONTH_NAMES))),
|
|
|
|
$edt
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-17 19:30:47 +03:00
|
|
|
}
|