2015-07-03 18:43:15 +02:00
|
|
|
<?php
|
2015-07-05 15:24:06 +02:00
|
|
|
class TheOatmealBridge extends RssExpander{
|
2015-07-03 18:43:15 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "Riduidel";
|
|
|
|
const NAME = "The Oatmeal";
|
|
|
|
const URI = "http://theoatmeal.com/";
|
|
|
|
const DESCRIPTION = "Un petit site de dessins assez rigolos";
|
2015-11-05 12:20:11 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-29 23:26:32 +02:00
|
|
|
$this->collectExpandableDatas('http://feeds.feedburner.com/oatmealfeed');
|
2015-07-03 18:43:15 +02:00
|
|
|
}
|
2015-07-05 15:24:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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];
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("RSS content is ===========\n".var_export($rssHeaderContent, true)."===========");
|
2015-07-05 15:24:06 +02:00
|
|
|
$this->load_RSS_2_0_feed_data($rssHeaderContent);
|
|
|
|
foreach($rssContent->item as $item) {
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("parsing item ".var_export($item, true));
|
2015-07-05 15:24:06 +02:00
|
|
|
$this->items[] = $this->parseRSSItem($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-03 18:43:15 +02:00
|
|
|
protected function parseRSSItem($newsItem) {
|
2015-07-05 15:51:17 +02:00
|
|
|
$namespaces = $newsItem->getNameSpaces(true);
|
|
|
|
$dc = $newsItem->children($namespaces['dc']);
|
|
|
|
$rdf = $newsItem->children($namespaces['rdf']);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['title'] = trim($newsItem->title);
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("browsing Oatmeal item ".var_export($newsItem, true));
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['uri']=(string) $newsItem->attributes($namespaces['rdf'])->about;
|
2015-07-03 18:43:15 +02:00
|
|
|
// now load that uri from cache
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("now loading page ".$item['uri']);
|
2016-08-28 19:38:34 +02:00
|
|
|
$articlePage = $this->get_cached($item['uri']);
|
2015-07-03 18:43:15 +02:00
|
|
|
|
|
|
|
$content = $articlePage->find('#comic', 0);
|
|
|
|
if($content==null) {
|
|
|
|
$content = $articlePage->find('#blog');
|
|
|
|
}
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $content->innertext;
|
2016-08-25 17:11:49 +02:00
|
|
|
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("dc content is ".var_export($dc, true));
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['author'] = (string) $dc->creator;
|
|
|
|
$item['timestamp'] = DateTime::createFromFormat(DateTime::ISO8601, $dc->date)->getTimestamp();
|
2016-08-24 20:19:30 +02:00
|
|
|
$this->debugMessage("writtem by ".$item['author']." on ".$item['timestamp']);
|
2015-07-03 18:43:15 +02:00
|
|
|
return $item;
|
|
|
|
}
|
2016-08-25 17:11:49 +02:00
|
|
|
|
2015-07-03 18:43:15 +02:00
|
|
|
public function getCacheDuration(){
|
2015-07-05 15:27:39 +02:00
|
|
|
return 7200; // 2h hours
|
2015-07-03 18:43:15 +02:00
|
|
|
}
|
|
|
|
}
|