1
0
Fork 0
forked from blallo/rss-bridge
rss-bridge/bridges/LeJournalDuGeekBridge.php

59 lines
2 KiB
PHP
Raw Normal View History

2014-07-14 20:12:52 +02:00
<?php
class LeJournalDuGeekBridge extends BridgeAbstract{
public $maintainer = "polopollo";
public $name = "journaldugeek.com (FR)";
public $uri = "http://www.journaldugeek.com/";
public $description = "Returns the 5 newest posts from LeJournalDuGeek (full text).";
private function LeJournalDuGeekStripCDATA($string) {
2016-08-03 20:14:59 +02:00
$string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string);
return $string;
}
private function LeJournalDuGeekExtractContent($url) {
$articleHTMLContent = $this->getSimpleHTMLDOM($url);
2016-08-03 20:34:30 +02:00
$text = $articleHTMLContent->find('div.post-content', 0)->innertext;
2014-07-14 20:12:52 +02:00
2016-08-03 20:14:59 +02:00
foreach($articleHTMLContent->find('a.more') as $element) {
if ($element->innertext == "Source") {
$text = $text . '<p><a href="' . $element->href . '">Source : ' . $element->href . '</a></p>';
break;
}
}
2014-07-14 20:12:52 +02:00
2016-08-03 20:14:59 +02:00
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>';
}
}
2016-08-03 20:32:26 +02:00
$text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $text);
2016-08-03 20:14:59 +02:00
$text = strip_tags($text, '<p><b><a><blockquote><img><em><br/><br><ul><li>');
return $text;
}
2014-07-14 20:12:52 +02:00
public function collectData(){
$rssFeed = $this->getSimpleHTMLDOM($this->uri.'rss')
or $this->returnServerError('Could not request '.$this->uri.'/rss');
2016-08-03 20:14:59 +02:00
$limit = 0;
2014-07-14 20:12:52 +02:00
2016-08-03 20:14:59 +02:00
foreach($rssFeed->find('item') as $element) {
if($limit < 5) {
$item = array();
$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']);
2016-08-03 20:14:59 +02:00
$this->items[] = $item;
$limit++;
}
}
}
2014-07-14 20:12:52 +02:00
2016-08-03 20:14:59 +02:00
public function getCacheDuration(){
return 1800; // 30min
}
2014-07-14 20:12:52 +02:00
}