Merge pull request #317 from LogMANOriginal/LeJournalDuGeekBridge

Le journal du geek bridge
This commit is contained in:
Mitsu 2016-08-03 22:57:39 +02:00 committed by GitHub
commit 2044a34bae

View file

@ -2,68 +2,67 @@
class LeJournalDuGeekBridge extends BridgeAbstract{ class LeJournalDuGeekBridge extends BridgeAbstract{
public function loadMetadatas() { public function loadMetadatas() {
$this->maintainer = "polopollo"; $this->maintainer = "polopollo";
$this->name = "journaldugeek.com (FR)"; $this->name = "journaldugeek.com (FR)";
$this->uri = "http://www.journaldugeek.com/"; $this->uri = "http://www.journaldugeek.com/";
$this->description = "Returns the 5 newest posts from LeJournalDuGeek (full text)."; $this->description = "Returns the 5 newest posts from LeJournalDuGeek (full text).";
$this->update = "2014-07-14"; $this->update = "2016-08-03";
} }
public function collectData(array $param){ function LeJournalDuGeekStripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string);
return $string;
}
function LeJournalDuGeekStripCDATA($string) { function LeJournalDuGeekExtractContent($url) {
$string = str_replace('<![CDATA[', '', $string); $articleHTMLContent = $this->file_get_html($url);
$string = str_replace(']]>', '', $string); $text = $articleHTMLContent->find('div.post-content', 0)->innertext;
return $string;
}
function LeJournalDuGeekExtractContent($url) { foreach($articleHTMLContent->find('a.more') as $element) {
$articleHTMLContent = $this->file_get_html($url); if ($element->innertext == "Source") {
$text = $text.$articleHTMLContent->find('div.post-content', 0)->innertext; $text = $text . '<p><a href="' . $element->href . '">Source : ' . $element->href . '</a></p>';
foreach($articleHTMLContent->find('a.more') as $element) { break;
if ($element->innertext == "Source") { }
$text = $text.'<p><a href="'.$element->href.'">Source : '.$element->href.'</a></p>'; }
break;
}
}
foreach($articleHTMLContent->find('iframe') as $element) {
if (preg_match("/youtube/i", $element->src)) {
$text = $text.'// An IFRAME to Youtube was included in the article: <a href="'.$element->src.'">'.$element->src.'</a><br>';
}
}
$text = strip_tags($text, '<p><b><a><blockquote><img><em><br/><br><ul><li>'); foreach($articleHTMLContent->find('iframe') as $element) {
return $text; if (preg_match("/youtube/i", $element->src)) {
} $text = $text . '// An IFRAME to Youtube was included in the article: <a href="' . $element->src . '">' . $element->src . '</a><br>';
}
}
$rssFeed = $this->file_get_html('http://www.journaldugeek.com/rss') or $this->returnError('Could not request http://www.journaldugeek.com/rss', 404); $text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $text);
$limit = 0; $text = strip_tags($text, '<p><b><a><blockquote><img><em><br/><br><ul><li>');
return $text;
}
foreach($rssFeed->find('item') as $element) { public function collectData(array $param){
if($limit < 5) { $rssFeed = $this->file_get_html('http://www.journaldugeek.com/rss') or $this->returnError('Could not request http://www.journaldugeek.com/rss', 404);
$item = new \Item(); $limit = 0;
$item->title = LeJournalDuGeekStripCDATA($element->find('title', 0)->innertext);
$item->uri = LeJournalDuGeekStripCDATA($element->find('guid', 0)->plaintext);
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = LeJournalDuGeekExtractContent($item->uri);
$this->items[] = $item;
$limit++;
}
}
} foreach($rssFeed->find('item') as $element) {
if($limit < 5) {
$item = new \Item();
$item->title = $this->LeJournalDuGeekStripCDATA($element->find('title', 0)->innertext);
$item->uri = $this->LeJournalDuGeekStripCDATA($element->find('guid', 0)->plaintext);
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = $this->LeJournalDuGeekExtractContent($item->uri);
$this->items[] = $item;
$limit++;
}
}
}
public function getName(){ public function getName(){
return 'LeJournalDuGeek'; return 'LeJournalDuGeek';
} }
public function getURI(){ public function getURI(){
return 'http://www.journaldugeek.com/'; return 'http://www.journaldugeek.com/';
} }
public function getCacheDuration(){ public function getCacheDuration(){
return 1800; // 30min return 1800; // 30min
} }
} }