rss-bridge/bridges/CourrierInternationalBridge.php

62 lines
1.5 KiB
PHP
Raw Normal View History

<?php
class CourrierInternationalBridge extends BridgeAbstract{
public $maintainer = "teromene";
public $name = "Courrier International Bridge";
public $uri = "http://CourrierInternational.com/";
public $description = "Courrier International bridge";
public function collectData(){
$html = $this->getSimpleHTMLDOM($this->uri)
or $this->returnServerError('Error.');
2016-03-02 14:49:27 +03:00
$element = $html->find("article");
$article_count = 1;
2016-03-02 14:49:27 +03:00
foreach($element as $article) {
$item = array();
$item['uri'] = $article->parent->getAttribute("href");
2016-03-02 14:49:27 +03:00
if(strpos($item['uri'], "http") === FALSE) {
$item['uri'] = $this->uri.$item['uri'];
2016-03-02 14:49:27 +03:00
}
$page = $this->getSimpleHTMLDOM($item['uri']);
2016-03-02 14:49:27 +03:00
$cleaner = new HTMLSanitizer();
$item['content'] = $cleaner->sanitize($page->find("div.article-text")[0]);
$item['title'] = strip_tags($article->find(".title")[0]);
2016-03-02 14:49:27 +03:00
$dateTime = date_parse($page->find("time")[0]);
$item['timestamp'] = mktime(
$dateTime['hour'],
$dateTime['minute'],
$dateTime['second'],
$dateTime['month'],
$dateTime['day'],
$dateTime['year']
2016-03-02 14:49:27 +03:00
);
2016-03-02 14:49:27 +03:00
$this->items[] = $item;
$article_count ++;
if($article_count > 5) break;
2016-03-02 14:49:27 +03:00
}
}
public function getCacheDuration(){
return 300; // 5 minutes
}
}
?>