EliteDangerousGalnetBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class EliteDangerousGalnetBridge extends BridgeAbstract
  3. {
  4. public function loadMetadatas()
  5. {
  6. $this->maintainer = "corenting";
  7. $this->name = "Elite: Dangerous Galnet";
  8. $this->uri = "https://community.elitedangerous.com/galnet";
  9. $this->description = "Returns the latest page of news from Galnet";
  10. $this->update = "2016-04-06";
  11. }
  12. public function collectData(array $param)
  13. {
  14. $html = $this->file_get_html('https://community.elitedangerous.com/galnet') or $this->returnError('Error while downloading the website content', 404);
  15. foreach($html->find('div.article') as $element) {
  16. $item = new Item();
  17. $uri = $element->find('h3 a', 0)->href;
  18. $uri = 'https://community.elitedangerous.com' . $uri;
  19. $item->uri = $uri;
  20. $title = $element->find('h3 a', 0)->plaintext;
  21. $item->title = substr($title, 1); //remove the space between icon and title
  22. $content = $element->find('p', -1)->innertext;
  23. $item->content = $content;
  24. $date = $element->find('p.small', 0)->innertext;
  25. $article_year = substr($date, -4) - 1286; //Convert E:D date to actual date
  26. $date = substr($date, 0, -4) . $article_year;
  27. $item->timestamp = strtotime($date);
  28. $this->items[] = $item;
  29. }
  30. }
  31. public function getName()
  32. {
  33. return 'Elite: Dangerous Galnet';
  34. }
  35. public function getURI()
  36. {
  37. return 'https://community.elitedangerous.com/galnet';
  38. }
  39. public function getCacheDuration()
  40. {
  41. return 3600 * 2; // 2 hours
  42. }
  43. }