2014-05-26 02:30:46 +04:00
|
|
|
<?php
|
|
|
|
class NumeramaBridge extends BridgeAbstract{
|
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
public function loadMetadatas() {
|
2015-11-04 12:47:21 +03:00
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
$this->maintainer = 'mitsukarenai';
|
|
|
|
$this->name = 'Numerama';
|
|
|
|
$this->uri = 'http://www.numerama.com/';
|
|
|
|
$this->description = 'Returns the 5 newest posts from Numerama (full text)';
|
2016-07-19 20:37:06 +03:00
|
|
|
$this->update = '2016-07-19';
|
2015-11-04 12:47:21 +03:00
|
|
|
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|
2015-10-12 18:13:27 +03:00
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
public function collectData(array $param) {
|
|
|
|
|
|
|
|
function NumeramaStripCDATA($string) {
|
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:12:00 +03:00
|
|
|
$feed = $this->getURI().'feed/';
|
|
|
|
$html = $this->file_get_html($feed) or $this->returnError('Could not request Numerama: '.$feed, 500);
|
2016-07-19 20:35:43 +03:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
|
|
|
if($limit < 5) {
|
|
|
|
$item = new \Item();
|
|
|
|
$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 21:12:00 +03:00
|
|
|
|
|
|
|
$article_url = NumeramaStripCDATA($element->find('guid', 0)->plaintext);
|
|
|
|
$article_html = $this->file_get_html($article_url) or $this->returnError('Could not request Numerama: '.$article_url, 500);
|
|
|
|
$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
|
|
|
|
|
|
|
|
$item->content = $contents;
|
2016-07-19 20:35:43 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 21:12:01 +04:00
|
|
|
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
public function getName() {
|
2014-05-26 02:30:46 +04:00
|
|
|
return 'Numerama';
|
|
|
|
}
|
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
public function getURI() {
|
2014-05-26 02:30:46 +04:00
|
|
|
return 'http://www.numerama.com/';
|
|
|
|
}
|
|
|
|
|
2016-07-19 20:35:43 +03:00
|
|
|
public function getCacheDuration() {
|
2014-05-26 02:30:46 +04:00
|
|
|
return 1800; // 30min
|
|
|
|
}
|
|
|
|
}
|