EliteDangerousGalnetBridge.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. }
  11. public function collectData(array $param)
  12. {
  13. $html = $this->getSimpleHTMLDOM('https://community.elitedangerous.com/galnet') or $this->returnServerError('Error while downloading the website content');
  14. foreach($html->find('div.article') as $element) {
  15. $item = array();
  16. $uri = $element->find('h3 a', 0)->href;
  17. $uri = 'https://community.elitedangerous.com' . $uri;
  18. $item['uri'] = $uri;
  19. $title = $element->find('h3 a', 0)->plaintext;
  20. $item['title'] = substr($title, 1); //remove the space between icon and title
  21. $content = $element->find('p', -1)->innertext;
  22. $item['content'] = $content;
  23. $date = $element->find('p.small', 0)->innertext;
  24. $article_year = substr($date, -4) - 1286; //Convert E:D date to actual date
  25. $date = substr($date, 0, -4) . $article_year;
  26. $item['timestamp'] = strtotime($date);
  27. $this->items[] = $item;
  28. }
  29. }
  30. public function getCacheDuration()
  31. {
  32. return 3600 * 2; // 2 hours
  33. }
  34. }