[CourrierInternationalBridge] Switch to FeedExpander (#2107)

This commit is contained in:
Corentin Garcia 2021-05-17 20:36:11 +02:00 committed by GitHub
parent 2b793f04de
commit e8d241e8c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,55 +1,27 @@
<?php
class CourrierInternationalBridge extends BridgeAbstract {
class CourrierInternationalBridge extends FeedExpander {
const MAINTAINER = 'teromene';
const NAME = 'Courrier International Bridge';
const URI = 'https://www.courrierinternational.com/';
const CACHE_TIMEOUT = 300; // 5 min
const DESCRIPTION = 'Courrier International bridge';
const DESCRIPTION = 'Returns the newest articles';
public function collectData(){
$html = getSimpleHTMLDOM(self::URI)
or returnServerError('Error.');
$this->collectExpandableDatas(static::URI . 'feed/all/rss.xml', 20);
}
$element = $html->find('article');
$article_count = 1;
protected function parseItem($feedItem){
$item = parent::parseItem($feedItem);
foreach($element as $article) {
$item = array();
$item['uri'] = $article->parent->getAttribute('href');
if(strpos($item['uri'], 'http') === false) {
$item['uri'] = self::URI . $item['uri'];
}
$page = getSimpleHTMLDOMCached($item['uri']);
$content = $page->find('.article-text', 0);
if(!$content) {
$content = $page->find('.depeche-text', 0);
}
$item['content'] = sanitize($content);
$item['title'] = strip_tags($article->find('.title', 0));
$dateTime = date_parse($page->find('time', 0));
$item['timestamp'] = mktime(
$dateTime['hour'],
$dateTime['minute'],
$dateTime['second'],
$dateTime['month'],
$dateTime['day'],
$dateTime['year']
);
$this->items[] = $item;
$article_count ++;
if($article_count > 5)
break;
$articlePage = getSimpleHTMLDOMCached($feedItem->link);
$content = $articlePage->find('.article-text', 0);
if(!$content) {
$content = $articlePage->find('.depeche-text', 0);
}
$item['content'] = sanitize($content);
return $item;
}
}