1
0
Fork 0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2024-12-29 23:58:23 +03:00
rss-bridge/bridges/PicalaBridge.php

85 lines
2.5 KiB
PHP
Raw Normal View History

2022-04-13 14:25:32 +03:00
<?php
class PicalaBridge extends BridgeAbstract
{
const TYPES = [
'Actualités' => 'actualites',
'Économie' => 'economie',
'Tests' => 'tests',
'Pratique' => 'pratique',
];
const NAME = 'Picala Bridge';
const URI = 'https://www.picala.fr';
const DESCRIPTION = 'Dernière nouvelles du média indépendant sur le vélo électrique';
const MAINTAINER = 'Chouchen';
const PARAMETERS = [
[
'type' => [
'name' => 'Type',
'type' => 'list',
'values' => self::TYPES,
],
],
];
2022-04-13 14:25:32 +03:00
public function getURI()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s/%s', static::URI, $this->getInput('type'));
}
2022-04-13 14:25:32 +03:00
return parent::getURI();
}
2022-04-13 14:25:32 +03:00
public function getIcon()
{
return 'https://picala-static.s3.amazonaws.com/static/img/favicon/favicon-32x32.png';
}
2022-04-13 14:25:32 +03:00
public function getDescription()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s - %s', static::DESCRIPTION, array_search($this->getInput('type'), self::TYPES));
}
2022-04-13 14:25:32 +03:00
return parent::getDescription();
}
2022-04-13 14:25:32 +03:00
public function getName()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s - %s', static::NAME, array_search($this->getInput('type'), self::TYPES));
}
2022-04-13 14:25:32 +03:00
return parent::getName();
}
2022-04-13 14:25:32 +03:00
public function collectData()
{
$fullhtml = getSimpleHTMLDOM($this->getURI());
foreach ($fullhtml->find('.list-container-category a') as $article) {
$firstImage = $article->find('img', 0);
$image = null;
if ($firstImage !== null) {
$srcsets = explode(',', $firstImage->getAttribute('srcset'));
$image = explode(' ', trim(array_shift($srcsets)))[0];
}
2022-04-13 14:25:32 +03:00
$item = [];
$item['uri'] = self::URI . $article->href;
$item['title'] = $article->find('h2', 0)->plaintext;
if ($image === null) {
$item['content'] = $article->find('.teaser__text', 0)->plaintext;
} else {
$item['content'] = sprintf(
'<img src="%s" /><br>%s',
$image,
$article->find('.teaser__text', 0)->plaintext
);
}
$this->items[] = $item;
}
}
2022-04-13 14:25:32 +03:00
}