Rss-Bridge/bridges/CourrierInternationalBridge.php
logmanoriginal 74f0572d91 bridges: Replace returnError function with more specific
Replacements depend on original error code:
400: returnClientError
404: returnServerError
500: returnServerError
501: returnServerError
2016-08-17 14:45:08 +02:00

69 lines
1.6 KiB
PHP

<?php
class CourrierInternationalBridge extends BridgeAbstract{
public function loadMetadatas() {
$this->maintainer = "teromene";
$this->name = "Courrier International Bridge";
$this->uri = "http://CourrierInternational.fr/";
$this->description = "Courrier International bridge";
$this->update = '2016-08-17';
}
public function collectData(array $param){
$html = '';
$html = $this->file_get_html('http://www.courrierinternational.com/') or $this->returnServerError('Error.');
$element = $html->find("article");
$article_count = 1;
foreach($element as $article) {
$item = new \Item();
$item->uri = $article->parent->getAttribute("href");
if(strpos($item->uri, "http") === FALSE) {
$item->uri = "http://courrierinternational.fr/".$item->uri;
}
$page = $this->file_get_html($item->uri);
$cleaner = new HTMLSanitizer();
$item->content = $cleaner->sanitize($page->find("div.article-text")[0]);
$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;
}
}
public function getCacheDuration(){
return 300; // 5 minutes
}
}
?>