-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CourrierInternationalBridge] Switch to FeedExpander (fix #778)
- Loading branch information
Showing
1 changed file
with
13 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
|
||
$element = $html->find('article'); | ||
$article_count = 1; | ||
|
||
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)); | ||
$this->collectExpandableDatas(static::URI . 'feed/all/rss.xml', 20); | ||
} | ||
|
||
$dateTime = date_parse($page->find('time', 0)); | ||
protected function parseItem($feedItem){ | ||
$item = parent::parseItem($feedItem); | ||
|
||
$item['timestamp'] = mktime( | ||
$dateTime['hour'], | ||
$dateTime['minute'], | ||
$dateTime['second'], | ||
$dateTime['month'], | ||
$dateTime['day'], | ||
$dateTime['year'] | ||
); | ||
$articlePage = getSimpleHTMLDOMCached($feedItem->link); | ||
$content = $articlePage->find('.article-text', 0); | ||
if(!$content) { | ||
$content = $articlePage->find('.depeche-text', 0); | ||
} | ||
|
||
$this->items[] = $item; | ||
$article_count ++; | ||
$item['content'] = sanitize($content); | ||
|
||
if($article_count > 5) | ||
break; | ||
} | ||
return $item; | ||
} | ||
} |