2015-10-22 14:52:15 +02:00
|
|
|
<?php
|
|
|
|
class LeMondeInformatiqueBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "ORelio";
|
|
|
|
const NAME = "Le Monde Informatique";
|
|
|
|
const URI = "http://www.lemondeinformatique.fr/";
|
|
|
|
const DESCRIPTION = "Returns the newest articles.";
|
2015-11-03 23:28:44 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2015-10-22 14:52:15 +02:00
|
|
|
|
|
|
|
function StripCDATA($string) {
|
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function StripWithDelimiters($string, $start, $end) {
|
|
|
|
while (strpos($string, $start) !== false) {
|
|
|
|
$section_to_remove = substr($string, strpos($string, $start));
|
|
|
|
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
|
|
|
$string = str_replace($section_to_remove, '', $string);
|
|
|
|
} return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CleanArticle($article_html) {
|
|
|
|
$article_html = StripWithDelimiters($article_html, '<script', '</script>');
|
2016-02-03 20:36:16 +01:00
|
|
|
$article_html = StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
|
2015-10-22 14:52:15 +02:00
|
|
|
return $article_html;
|
|
|
|
}
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.'rss/rss.xml')
|
2016-08-29 12:46:48 +02:00
|
|
|
or $this->returnServerError('Could not request LeMondeInformatique: '
|
2016-08-30 11:23:55 +02:00
|
|
|
.self::URI.'rss/rss.xml');
|
2015-10-22 14:52:15 +02:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
|
|
|
if($limit < 5) {
|
|
|
|
|
|
|
|
//Retrieve article details
|
|
|
|
$article_uri = $element->innertext;
|
|
|
|
$article_uri = substr($article_uri, strpos($article_uri, '<link>') + 6);
|
|
|
|
$article_uri = substr($article_uri, 0, strpos($article_uri, '</link>'));
|
2016-07-08 19:06:35 +02:00
|
|
|
$article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request LeMondeInformatique: '.$article_uri);
|
2015-10-22 14:52:15 +02:00
|
|
|
$article_content = CleanArticle($article_html->find('div#article', 0)->innertext);
|
|
|
|
$article_title = $article_html->find('h1.cleanprint-title', 0)->plaintext;
|
|
|
|
|
|
|
|
//Build and add final item
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $article_uri;
|
|
|
|
$item['title'] = $article_title;
|
|
|
|
$item['author'] = StripCDATA($element->find('dc:creator', 0)->innertext);
|
|
|
|
$item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
|
|
|
|
$item['content'] = $article_content;
|
2015-10-22 14:52:15 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration() {
|
|
|
|
return 1800; // 30 minutes
|
|
|
|
}
|
|
|
|
}
|