[JornalNBridge] getName() fix (#3456)

* [JornalNBridge] getName() fix

* [JornalNBridge] feed fixes
This commit is contained in:
rmscoelho 2023-06-30 14:54:53 +01:00 committed by GitHub
parent fece9ed344
commit cc91ee1e37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ class JornalNBridge extends BridgeAbstract
const URI = 'https://www.jornaln.pt/'; const URI = 'https://www.jornaln.pt/';
const DESCRIPTION = 'Returns news from the Portuguese local newspaper Jornal N'; const DESCRIPTION = 'Returns news from the Portuguese local newspaper Jornal N';
const MAINTAINER = 'rmscoelho'; const MAINTAINER = 'rmscoelho';
const CACHE_TIMEOUT = 86400; const CACHE_TIMEOUT = 3600;
const PARAMETERS = [ const PARAMETERS = [
[ [
'feed' => [ 'feed' => [
@ -19,12 +19,12 @@ class JornalNBridge extends BridgeAbstract
'Ovar' => 'ovar', 'Ovar' => 'ovar',
'Santa Maria da Feira' => 'santa-maria-da-feira', 'Santa Maria da Feira' => 'santa-maria-da-feira',
], ],
'Cultura' => 'cultura', 'Cultura' => 'ovar/cultura',
'Desporto' => 'desporto', 'Desporto' => 'desporto',
'Economia' => 'economia', 'Economia' => 'santa-maria-da-feira/economia',
'Política' => 'politica', 'Política' => 'santa-maria-da-feira/politica',
'Opinião' => 'opiniao', 'Opinião' => 'santa-maria-da-feira/opiniao',
'Sociedade' => 'sociedade', 'Sociedade' => 'santa-maria-da-feira/sociedade',
] ]
] ]
] ]
@ -52,16 +52,7 @@ class JornalNBridge extends BridgeAbstract
public function getName() public function getName()
{ {
$feed = $this->getInput('feed'); return !is_null($this->getKey('feed')) ? self::NAME . ' | ' . $this->getKey('feed') : self::NAME;
if ($this->getInput('feed') !== null && $this->getInput('feed') !== '') {
if ($feed === 'santa-maria-da-feira') {
$name = 'Santa Maria da Feira';
} else {
$name = ucfirst($feed);
}
return self::NAME . ' | ' . $name;
}
return self::NAME;
} }
public function getURI() public function getURI()
@ -71,7 +62,7 @@ class JornalNBridge extends BridgeAbstract
public function collectData() public function collectData()
{ {
$url = sprintf('https://www.jornaln.pt/%s', $this->getInput('feed')); $url = sprintf(self::URI . '/%s', $this->getInput('feed'));
$dom = getSimpleHTMLDOMCached($url); $dom = getSimpleHTMLDOMCached($url);
$domSelector = '.elementor-widget-container > .elementor-posts-container'; $domSelector = '.elementor-widget-container > .elementor-posts-container';
$dom = $dom->find($domSelector, 0); $dom = $dom->find($domSelector, 0);
@ -81,7 +72,7 @@ class JornalNBridge extends BridgeAbstract
$dom = defaultLinkTo($dom, $this->getURI()); $dom = defaultLinkTo($dom, $this->getURI());
foreach ($dom->find('article') as $article) { foreach ($dom->find('article') as $article) {
//Get thumbnail //Get thumbnail
$image = $article->find('img', 0)->src; $image = $article->find('.elementor-post__thumbnail img', 0)->src;
//Timestamp //Timestamp
$date = $article->find('.elementor-post-date', 0)->plaintext; $date = $article->find('.elementor-post-date', 0)->plaintext;
$date = preg_replace('/ de /i', '/', $date); $date = preg_replace('/ de /i', '/', $date);