forked from blallo/rss-bridge
un bridge The Oatmeal qui marche ... principalement pour les comics locaux (et pas pour explodingkittens)
This commit is contained in:
parent
9712d052b4
commit
94ffb22fb0
2 changed files with 33 additions and 10 deletions
|
@ -16,7 +16,7 @@ abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||||
if (empty($param['url'])) {
|
if (empty($param['url'])) {
|
||||||
$this->returnError('There is no $param[\'url\'] for this RSS expander', 404);
|
$this->returnError('There is no $param[\'url\'] for this RSS expander', 404);
|
||||||
}
|
}
|
||||||
// $this->message("Loading from ".$param['url']);
|
// $this->message("Loading from ".$param['url']);
|
||||||
// Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time
|
// Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time
|
||||||
$rssContent = simplexml_load_file($param['url']) or $this->returnError('Could not request '.$param['url'], 404);
|
$rssContent = simplexml_load_file($param['url']) or $this->returnError('Could not request '.$param['url'], 404);
|
||||||
// $this->message("loaded RSS from ".$param['url']);
|
// $this->message("loaded RSS from ".$param['url']);
|
||||||
|
@ -25,7 +25,7 @@ abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||||
$this->collect_RSS_2_0_data($rssContent);
|
$this->collect_RSS_2_0_data($rssContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function collect_RSS_2_0_data($rssContent) {
|
protected function collect_RSS_2_0_data($rssContent) {
|
||||||
$rssContent = $rssContent->channel[0];
|
$rssContent = $rssContent->channel[0];
|
||||||
// $this->message("RSS content is ===========\n".var_export($rssContent, true)."===========");
|
// $this->message("RSS content is ===========\n".var_export($rssContent, true)."===========");
|
||||||
$this->load_RSS_2_0_feed_data($rssContent);
|
$this->load_RSS_2_0_feed_data($rssContent);
|
||||||
|
|
|
@ -8,17 +8,33 @@
|
||||||
require_once 'bridges/RssExpander.php';
|
require_once 'bridges/RssExpander.php';
|
||||||
define("THE_OATMEAL", "http://theoatmeal.com/");
|
define("THE_OATMEAL", "http://theoatmeal.com/");
|
||||||
define("RSS", "http://feeds.feedburner.com/oatmealfeed");
|
define("RSS", "http://feeds.feedburner.com/oatmealfeed");
|
||||||
class TheOatmeal extends RssExpander{
|
class TheOatmealBridge extends RssExpander{
|
||||||
|
|
||||||
public function collectData(array $param){
|
public function collectData(array $param){
|
||||||
$param['url'] = RSS;
|
$param['url'] = RSS;
|
||||||
parent::collectData($param);
|
parent::collectData($param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since the oatmeal produces a weird RSS feed, I have to fix it by loading the items separatly from the feed infos
|
||||||
|
*/
|
||||||
|
protected function collect_RSS_2_0_data($rssContent) {
|
||||||
|
$rssContent->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||||
|
$rssHeaderContent = $rssContent->channel[0];
|
||||||
|
// $this->message("RSS content is ===========\n".var_export($rssHeaderContent, true)."===========");
|
||||||
|
$this->load_RSS_2_0_feed_data($rssHeaderContent);
|
||||||
|
foreach($rssContent->item as $item) {
|
||||||
|
$this->message("parsing item ".var_export($item, true));
|
||||||
|
$this->items[] = $this->parseRSSItem($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function parseRSSItem($newsItem) {
|
protected function parseRSSItem($newsItem) {
|
||||||
$item = new Item();
|
$item = new Item();
|
||||||
$item->title = trim($newsItem->title);
|
$item->title = trim($newsItem->title);
|
||||||
// $this->message("browsing item ".var_export($newsItem, true));
|
$this->message("browsing Oatmeal item ".var_export($newsItem, true));
|
||||||
if(empty($newsItem->guid)) {
|
if(empty($newsItem->guid)) {
|
||||||
$item->uri = $newsItem->link;
|
$item->uri = $newsItem->link;
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,12 +48,19 @@ class TheOatmeal extends RssExpander{
|
||||||
if($content==null) {
|
if($content==null) {
|
||||||
$content = $articlePage->find('#blog');
|
$content = $articlePage->find('#blog');
|
||||||
}
|
}
|
||||||
$item->content = $newsItem->description;
|
$item->content = $content->innertext;
|
||||||
$item->name = $newsItem->author;
|
|
||||||
$item->timestamp = $this->RSS_2_0_time_to_timestamp($newsItem);
|
$namespaces = $newsItem->getNameSpaces(true);
|
||||||
|
|
||||||
|
$dc = $newsItem->children($namespaces['dc']);
|
||||||
|
$this->message("dc content is ".var_export($dc, true));
|
||||||
|
$item->name = $dc->creator;
|
||||||
|
$item->timestamp = DateTime::createFromFormat(DateTime::ISO8601, $dc->date)->getTimestamp();
|
||||||
|
$this->message("writtem by ".$item->name." on ".$item->timestamp);
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheDuration(){
|
public function getCacheDuration(){
|
||||||
return 7200; // 2h hours
|
return 1; // 2h hours
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue