refactor(reddit) (#3869)

* refactor

* yup

* fix also reporterre
This commit is contained in:
Dag 2023-12-30 01:33:31 +01:00 committed by GitHub
parent 7dbe106582
commit fac1f5cd88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 66 deletions

View file

@ -1,11 +1,35 @@
<?php
/**
* See https://reporterre.net/spip.php?page=backend-simple
*/
class ReporterreBridge extends BridgeAbstract
{
const MAINTAINER = 'nyutag';
const NAME = 'Reporterre Bridge';
const URI = 'https://www.reporterre.net/';
const DESCRIPTION = 'Returns the newest articles.';
const DESCRIPTION = 'Returns the newest articles. See also their official feed https://reporterre.net/spip.php?page=backend-simple';
public function collectData()
{
//$url = self::URI . 'spip.php?page=backend';
$url = self::URI . 'spip.php?page=backend-simple';
$html = getSimpleHTMLDOM($url);
$limit = 0;
foreach ($html->find('item') as $element) {
if ($limit < 5) {
$item = [];
$item['title'] = html_entity_decode($element->find('title', 0)->plaintext);
$item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
$item['uri'] = $element->find('guid', 0)->innertext;
//$item['content'] = html_entity_decode($this->extractContent($item['uri']));
$item['content'] = htmlspecialchars_decode($element->find('description', 0)->plaintext);
$this->items[] = $item;
$limit++;
}
}
}
private function extractContent($url)
{
@ -22,22 +46,4 @@ class ReporterreBridge extends BridgeAbstract
$text = strip_tags($text, '<p><br><a><img>');
return $text;
}
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . 'spip.php?page=backend');
$limit = 0;
foreach ($html->find('item') as $element) {
if ($limit < 5) {
$item = [];
$item['title'] = html_entity_decode($element->find('title', 0)->plaintext);
$item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
$item['uri'] = $element->find('guid', 0)->innertext;
$item['content'] = html_entity_decode($this->extractContent($item['uri']));
$this->items[] = $item;
$limit++;
}
}
}
}