2014-05-26 00:30:46 +02:00
|
|
|
<?php
|
2016-09-05 18:43:56 +02:00
|
|
|
class NumeramaBridge extends FeedExpander {
|
2014-05-26 00:30:46 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = 'mitsukarenai';
|
|
|
|
const NAME = 'Numerama';
|
|
|
|
const URI = 'http://www.numerama.com/';
|
|
|
|
const DESCRIPTION = 'Returns the 5 newest posts from Numerama (full text)';
|
2015-10-12 17:13:27 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-09-05 20:26:45 +02:00
|
|
|
$this->collectExpandableDatas(self::URI . 'feed/', 5);
|
2016-09-05 18:43:56 +02:00
|
|
|
}
|
2016-07-19 19:35:43 +02:00
|
|
|
|
2016-09-05 18:43:56 +02:00
|
|
|
protected function parseItem($newsItem){
|
|
|
|
$item = $this->parseRSS_2_0_Item($newsItem);
|
|
|
|
$item['content'] = $this->ExtractContent($item['uri']);
|
|
|
|
return $item;
|
|
|
|
}
|
2016-08-28 20:07:56 +02:00
|
|
|
|
2016-09-05 18:43:56 +02:00
|
|
|
private function ExtractContent($url){
|
|
|
|
if($this->get_cached_time($url) <= strtotime('-24 hours'))
|
|
|
|
$this->remove_from_cache($url);
|
2016-07-19 20:12:00 +02:00
|
|
|
|
2016-09-05 18:43:56 +02:00
|
|
|
$article_html = $this->get_cached($url) or $this->returnServerError('Could not request Numerama: '.$url);
|
|
|
|
$contents = $article_html->find('section[class=related-article]', 0)->innertext = ''; // remove related articles block
|
|
|
|
$contents = '<img alt="" style="max-width:300px;" src="'.$article_html->find('meta[property=og:image]', 0)->getAttribute('content').'">'; // add post picture
|
|
|
|
return $contents . $article_html->find('article[class=post-content]', 0)->innertext; // extract the post
|
2014-05-26 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
2016-07-19 19:35:43 +02:00
|
|
|
public function getCacheDuration() {
|
2014-05-26 00:30:46 +02:00
|
|
|
return 1800; // 30min
|
|
|
|
}
|
|
|
|
}
|