2015-10-22 14:52:15 +02:00
|
|
|
<?php
|
2016-09-05 18:43:56 +02:00
|
|
|
class LeMondeInformatiqueBridge extends FeedExpander {
|
2015-10-22 14:52:15 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "ORelio";
|
|
|
|
const NAME = "Le Monde Informatique";
|
|
|
|
const URI = "http://www.lemondeinformatique.fr/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 1800; // 30min
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Returns the newest articles.";
|
2015-11-03 23:28:44 +01:00
|
|
|
|
2016-09-05 20:26:45 +02:00
|
|
|
public function collectData(){
|
|
|
|
$this->collectExpandableDatas(self::URI . 'rss/rss.xml', 10);
|
|
|
|
}
|
2016-09-05 18:43:56 +02:00
|
|
|
|
2016-09-05 20:26:45 +02:00
|
|
|
protected function parseItem($newsItem){
|
2016-09-12 10:42:27 +02:00
|
|
|
$item = parent::parseItem($newsItem);
|
2016-09-25 23:22:33 +02:00
|
|
|
$article_html = getSimpleHTMLDOMCached($item['uri'])
|
|
|
|
or returnServerError('Could not request LeMondeInformatique: ' . $item['uri']);
|
2016-09-05 18:43:56 +02:00
|
|
|
$item['content'] = $this->CleanArticle($article_html->find('div#article', 0)->innertext);
|
|
|
|
$item['title'] = $article_html->find('h1.cleanprint-title', 0)->plaintext;
|
2016-09-05 20:26:45 +02:00
|
|
|
return $item;
|
|
|
|
}
|
2016-09-05 18:43:56 +02:00
|
|
|
|
2016-12-17 16:39:18 +01:00
|
|
|
private function StripCDATA($string) {
|
2016-09-05 18:43:56 +02:00
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
2015-10-22 14:52:15 +02:00
|
|
|
|
2016-12-17 16:39:18 +01:00
|
|
|
private function StripWithDelimiters($string, $start, $end) {
|
2016-09-05 18:43:56 +02:00
|
|
|
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;
|
|
|
|
}
|
2015-10-22 14:52:15 +02:00
|
|
|
|
2016-12-17 16:39:18 +01:00
|
|
|
private function CleanArticle($article_html) {
|
2016-09-05 18:43:56 +02:00
|
|
|
$article_html = $this->StripWithDelimiters($article_html, '<script', '</script>');
|
|
|
|
$article_html = $this->StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
|
|
|
|
return $article_html;
|
2015-10-22 14:52:15 +02:00
|
|
|
}
|
|
|
|
}
|