rss-bridge/bridges/PresidenciaPTBridge.php
Jan Tojnar 951092eef3
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 13:00:52 +02:00

86 lines
2.8 KiB
PHP

<?php
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',
]
]
];
const PT_MONTH_NAMES = [
'janeiro',
'fevereiro',
'março',
'abril',
'maio',
'junho',
'julho',
'agosto',
'setembro',
'outubro',
'novembro',
'dezembro'];
public function getIcon()
{
return 'https://www.presidencia.pt/Theme/favicon/apple-touch-icon.png';
}
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);
foreach ($html->find('#atualidade-list article.card-block') as $element) {
$item = [];
$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);
$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) {
return sprintf('-%02d-', $num);
}, range(1, sizeof(self::PT_MONTH_NAMES))),
$edt
);
$this->items[] = $item;
}
}
}
}
}