2014-05-31 18:58:56 +02:00
|
|
|
<?php
|
2016-08-02 15:40:07 +02:00
|
|
|
class DauphineLibereBridge extends BridgeAbstract {
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "qwertygc";
|
|
|
|
const NAME = "Dauphine Bridge";
|
|
|
|
const URI = "http://www.ledauphine.com/";
|
|
|
|
const DESCRIPTION = "Returns the newest articles.";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'u'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Catégorie de l\'article',
|
|
|
|
'type'=>'list',
|
|
|
|
'values'=>array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'À la une'=>'',
|
|
|
|
'France Monde'=>'france-monde',
|
|
|
|
'Faits Divers'=>'faits-divers',
|
|
|
|
'Économie et Finance'=>'economie-et-finance',
|
|
|
|
'Politique'=>'politique',
|
|
|
|
'Sport'=>'sport',
|
|
|
|
'Ain'=>'ain',
|
|
|
|
'Alpes-de-Haute-Provence'=>'haute-provence',
|
|
|
|
'Hautes-Alpes'=>'hautes-alpes',
|
|
|
|
'Ardèche'=>'ardeche',
|
|
|
|
'Drôme'=>'drome',
|
|
|
|
'Isère Sud'=>'isere-sud',
|
|
|
|
'Savoie'=>'savoie',
|
|
|
|
'Haute-Savoie'=>'haute-savoie',
|
|
|
|
'Vaucluse'=>'vaucluse'
|
2016-08-22 01:25:56 +02:00
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function ExtractContent($url, $context) {
|
2016-08-28 13:57:40 +02:00
|
|
|
$html2 = $this->getSimpleHTMLDOM($url);
|
2014-05-31 18:58:56 +02:00
|
|
|
$text = $html2->find('div.column', 0)->innertext;
|
|
|
|
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
|
|
|
|
return $text;
|
2016-08-02 15:40:07 +02:00
|
|
|
}
|
2016-08-02 15:31:55 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-02 15:31:55 +02:00
|
|
|
|
2016-08-02 15:57:01 +02:00
|
|
|
$context = stream_context_create($opts);
|
|
|
|
|
2016-08-28 13:57:40 +02:00
|
|
|
if (empty($this->getInput('u'))) {
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.$this->getInput('u').'/rss')
|
2016-08-28 13:57:40 +02:00
|
|
|
or $this->returnServerError('Could not request DauphineLibere.');
|
|
|
|
} else {
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.'rss')
|
2016-08-28 13:57:40 +02:00
|
|
|
or $this->returnServerError('Could not request DauphineLibere.');
|
2014-05-31 18:58:56 +02:00
|
|
|
}
|
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
2016-08-02 15:40:07 +02:00
|
|
|
if($limit < 10) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['title'] = $element->find('title', 0)->innertext;
|
|
|
|
$item['uri'] = $element->find('guid', 0)->plaintext;
|
|
|
|
$item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
|
|
|
|
$item['content'] = $this->ExtractContent($item['uri'], $context);
|
2016-08-02 15:57:01 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
2016-08-02 15:40:07 +02:00
|
|
|
}
|
2014-05-31 18:58:56 +02:00
|
|
|
}
|
2016-08-02 15:40:07 +02:00
|
|
|
}
|
2014-05-31 18:58:56 +02:00
|
|
|
|
2016-08-02 15:40:07 +02:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 3600*2; // 2 hours
|
|
|
|
}
|
2014-05-31 18:58:56 +02:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
?>
|