2014-05-26 00:30:46 +02:00
|
|
|
<?php
|
|
|
|
class NumeramaBridge extends BridgeAbstract{
|
|
|
|
|
2015-11-04 10:47:21 +01:00
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "mitsukarenai";
|
|
|
|
$this->name = "Numerama";
|
|
|
|
$this->uri = "http://www.numerama.com/";
|
|
|
|
$this->description = "Returns the 5 newest posts from Numerama (full text)";
|
|
|
|
$this->update = "2015-10-12";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-26 00:30:46 +02:00
|
|
|
public function collectData(array $param){
|
|
|
|
|
|
|
|
function NumeramaStripCDATA($string) {
|
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
2015-10-12 17:13:27 +02:00
|
|
|
|
|
|
|
function NumeramaExtractContent($url)
|
|
|
|
{
|
2016-07-18 20:57:27 +02:00
|
|
|
$html2 = file_get_html($url);
|
2015-10-12 17:13:27 +02:00
|
|
|
$text = $html2->find('section[class=related-article]', 0)->innertext = ''; // remove related articles block
|
|
|
|
$text = '<img alt="" style="max-width:300px;" src="'.$html2->find('meta[property=og:image]', 0)->getAttribute('content').'">'; // add post picture
|
|
|
|
$text = $text.$html2->find('article[class=post-content]', 0)->innertext; // extract the post
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2016-06-25 23:17:42 +02:00
|
|
|
$html = $this->file_get_html('http://www.numerama.com/feed/') or $this->returnError('Could not request Numerama.', 404);
|
2014-05-26 00:30:46 +02:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
|
|
|
if($limit < 5) {
|
|
|
|
$item = new \Item();
|
2015-10-13 00:37:55 +02:00
|
|
|
$item->title = html_entity_decode(NumeramaStripCDATA($element->find('title', 0)->innertext));
|
2015-10-13 17:59:55 +02:00
|
|
|
$item->author = NumeramaStripCDATA($element->find('dc:creator', 0)->innertext);
|
2014-05-26 00:30:46 +02:00
|
|
|
$item->uri = NumeramaStripCDATA($element->find('guid', 0)->plaintext);
|
|
|
|
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
|
|
|
$item->content = NumeramaExtractContent($item->uri);
|
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 19:12:01 +02:00
|
|
|
|
2014-05-26 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
return 'Numerama';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
return 'http://www.numerama.com/';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 1800; // 30min
|
|
|
|
}
|
|
|
|
}
|