2014-09-08 17:33:27 +02:00
|
|
|
<?php
|
|
|
|
class NasaApodBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "corenting";
|
|
|
|
const NAME = "NASA APOD Bridge";
|
|
|
|
const URI = "http://apod.nasa.gov/apod/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 43200; // 12h
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Returns the 3 latest NASA APOD pictures and explanations";
|
2015-11-04 10:47:21 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2014-09-08 17:33:27 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.'archivepix.html') or $this->returnServerError('Error while downloading the website content');
|
2014-09-08 17:33:27 +02:00
|
|
|
$list = explode("<br>", $html->find('b', 0)->innertext);
|
|
|
|
|
|
|
|
for($i = 0; $i < 3;$i++)
|
|
|
|
{
|
|
|
|
$line = $list[$i];
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2014-09-08 17:33:27 +02:00
|
|
|
|
|
|
|
$uri_page = $html->find('a',$i + 3)->href;
|
2016-08-30 11:23:55 +02:00
|
|
|
$uri = self::URI.$uri_page;
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['uri'] = $uri;
|
2014-09-08 17:33:27 +02:00
|
|
|
|
2016-07-08 19:06:35 +02:00
|
|
|
$picture_html = $this->getSimpleHTMLDOM($uri);
|
2014-09-08 17:33:27 +02:00
|
|
|
$picture_html_string = $picture_html->innertext;
|
|
|
|
|
|
|
|
//Extract image and explanation
|
|
|
|
$media = $picture_html->find('p',1)->innertext;
|
|
|
|
$media = strstr($media, '<br>');
|
|
|
|
$media = preg_replace('/<br>/', '', $media, 1);
|
|
|
|
$explanation = $picture_html->find('p',2)->innertext;
|
|
|
|
|
|
|
|
//Extract date from the picture page
|
|
|
|
$date = explode(" ", $picture_html->find('p',1)->innertext);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['timestamp'] = strtotime($date[4].$date[3].$date[2]);
|
2014-09-08 17:33:27 +02:00
|
|
|
|
|
|
|
//Other informations
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $media.'<br />'.$explanation;
|
|
|
|
$item['title'] = $picture_html->find('b',0)->innertext;
|
2014-09-08 17:33:27 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|