From 87526650a6acb3b87177678c2da46cf14055cc81 Mon Sep 17 00:00:00 2001 From: corenting Date: Mon, 8 Sep 2014 17:33:27 +0200 Subject: [PATCH] Add NasaApod bridge (fix #17) --- bridges/NasaApodBridge.php | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 bridges/NasaApodBridge.php diff --git a/bridges/NasaApodBridge.php b/bridges/NasaApodBridge.php new file mode 100644 index 00000000..f3f76209 --- /dev/null +++ b/bridges/NasaApodBridge.php @@ -0,0 +1,56 @@ +returnError('Error while downloading the website content', 404); + $list = explode("
", $html->find('b', 0)->innertext); + + for($i = 0; $i < 3;$i++) + { + $line = $list[$i]; + $item = new \Item(); + + $uri_page = $html->find('a',$i + 3)->href; + $uri = 'http://apod.nasa.gov/apod/'.$uri_page; + $item->uri = $uri; + + $picture_html = file_get_html($uri); + $picture_html_string = $picture_html->innertext; + + //Extract image and explanation + $media = $picture_html->find('p',1)->innertext; + $media = strstr($media, '
'); + $media = preg_replace('/
/', '', $media, 1); + $explanation = $picture_html->find('p',2)->innertext; + + //Extract date from the picture page + $date = explode(" ", $picture_html->find('p',1)->innertext); + $item->timestamp = strtotime($date[4].$date[3].$date[2]); + + //Other informations + $item->content = $media.'
'.$explanation; + $item->title = $picture_html->find('b',0)->innertext; + $this->items[] = $item; + } + } + + public function getName(){ + return 'NASA APOD'; + } + + public function getURI(){ + return 'http://apod.nasa.gov/apod/astropix.html'; + } + + public function getCacheDuration(){ + return 3600*12; // 12 hours + } +}