2014-05-26 00:30:46 +02:00
|
|
|
<?php
|
2016-08-28 20:07:56 +02:00
|
|
|
class NumeramaBridge extends HttpCachingBridgeAbstract {
|
2014-05-26 00:30:46 +02:00
|
|
|
|
2016-07-19 19:35:43 +02:00
|
|
|
public function loadMetadatas() {
|
2015-11-04 10:47:21 +01:00
|
|
|
|
2016-07-19 19:35:43 +02:00
|
|
|
$this->maintainer = 'mitsukarenai';
|
|
|
|
$this->name = 'Numerama';
|
|
|
|
$this->uri = 'http://www.numerama.com/';
|
|
|
|
$this->description = 'Returns the 5 newest posts from Numerama (full text)';
|
2015-11-04 10:47:21 +01:00
|
|
|
|
2014-05-26 00:30:46 +02:00
|
|
|
}
|
2015-10-12 17:13:27 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-07-19 19:35:43 +02:00
|
|
|
|
|
|
|
function NumeramaStripCDATA($string) {
|
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2016-08-09 20:01:21 +02:00
|
|
|
$feed = $this->uri.'feed/';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($feed) or $this->returnServerError('Could not request Numerama: '.$feed);
|
2016-07-19 19:35:43 +02:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
|
|
|
if($limit < 5) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['title'] = html_entity_decode(NumeramaStripCDATA($element->find('title', 0)->innertext));
|
|
|
|
$item['author'] = NumeramaStripCDATA($element->find('dc:creator', 0)->innertext);
|
|
|
|
$item['uri'] = NumeramaStripCDATA($element->find('guid', 0)->plaintext);
|
|
|
|
$item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
|
2016-07-19 20:12:00 +02:00
|
|
|
|
|
|
|
$article_url = NumeramaStripCDATA($element->find('guid', 0)->plaintext);
|
2016-08-28 20:07:56 +02:00
|
|
|
if($this->get_cached_time($article_url) <= strtotime('-24 hours'))
|
|
|
|
$this->remove_from_cache($article_url);
|
|
|
|
|
|
|
|
$article_html = $this->get_cached($article_url) or $this->returnServerError('Could not request Numerama: '.$article_url);
|
2016-07-19 20:12:00 +02:00
|
|
|
$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
|
|
|
|
$contents = $contents.$article_html->find('article[class=post-content]', 0)->innertext; // extract the post
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $contents;
|
2016-07-19 19:35:43 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|