2015-07-03 18:43:15 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @name The Oatmeal
|
|
|
|
* @description Un petit site de dessins assez rigolos
|
|
|
|
* @update 20/02/201403/07/2015
|
|
|
|
*/
|
|
|
|
require_once 'bridges/RssExpander.php';
|
|
|
|
define("THE_OATMEAL", "http://theoatmeal.com/");
|
|
|
|
define("RSS", "http://feeds.feedburner.com/oatmealfeed");
|
2015-07-05 15:24:06 +02:00
|
|
|
class TheOatmealBridge extends RssExpander{
|
2015-07-03 18:43:15 +02:00
|
|
|
|
|
|
|
public function collectData(array $param){
|
|
|
|
$param['url'] = RSS;
|
|
|
|
parent::collectData($param);
|
|
|
|
}
|
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];
|
|
|
|
// $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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-03 18:43:15 +02:00
|
|
|
protected function parseRSSItem($newsItem) {
|
|
|
|
$item = new Item();
|
2015-07-05 15:24:06 +02:00
|
|
|
$item->title = trim($newsItem->title);
|
|
|
|
$this->message("browsing Oatmeal item ".var_export($newsItem, true));
|
2015-07-03 18:43:15 +02:00
|
|
|
if(empty($newsItem->guid)) {
|
|
|
|
$item->uri = $newsItem->link;
|
|
|
|
} else {
|
|
|
|
$item->uri = $newsItem->guid;
|
|
|
|
}
|
|
|
|
// now load that uri from cache
|
|
|
|
$this->message("now loading page ".$item->uri);
|
|
|
|
$articlePage = str_get_html($this->get_cached($item->uri));
|
|
|
|
|
|
|
|
$content = $articlePage->find('#comic', 0);
|
|
|
|
if($content==null) {
|
|
|
|
$content = $articlePage->find('#blog');
|
|
|
|
}
|
2015-07-05 15:24:06 +02:00
|
|
|
$item->content = $content->innertext;
|
|
|
|
|
|
|
|
$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);
|
2015-07-03 18:43:15 +02:00
|
|
|
return $item;
|
|
|
|
}
|
2015-07-05 15:24:06 +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
|
|
|
}
|
|
|
|
}
|