NasaApodBridge.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class NasaApodBridge extends BridgeAbstract{
  3. const MAINTAINER = "corenting";
  4. const NAME = "NASA APOD Bridge";
  5. const URI = "http://apod.nasa.gov/apod/";
  6. const CACHE_TIMEOUT = 43200; // 12h
  7. const DESCRIPTION = "Returns the 3 latest NASA APOD pictures and explanations";
  8. public function collectData(){
  9. $html = getSimpleHTMLDOM(self::URI.'archivepix.html') or returnServerError('Error while downloading the website content');
  10. $list = explode("<br>", $html->find('b', 0)->innertext);
  11. for($i = 0; $i < 3;$i++)
  12. {
  13. $line = $list[$i];
  14. $item = array();
  15. $uri_page = $html->find('a',$i + 3)->href;
  16. $uri = self::URI.$uri_page;
  17. $item['uri'] = $uri;
  18. $picture_html = getSimpleHTMLDOM($uri);
  19. $picture_html_string = $picture_html->innertext;
  20. //Extract image and explanation
  21. $media = $picture_html->find('p',1)->innertext;
  22. $media = strstr($media, '<br>');
  23. $media = preg_replace('/<br>/', '', $media, 1);
  24. $explanation = $picture_html->find('p',2)->innertext;
  25. //Extract date from the picture page
  26. $date = explode(" ", $picture_html->find('p',1)->innertext);
  27. $item['timestamp'] = strtotime($date[4].$date[3].$date[2]);
  28. //Other informations
  29. $item['content'] = $media.'<br />'.$explanation;
  30. $item['title'] = $picture_html->find('b',0)->innertext;
  31. $this->items[] = $item;
  32. }
  33. }
  34. }