DilbertBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class DilbertBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = 'kranack';
  5. $this->name = $this->getName();
  6. $this->uri = $this->getURI();
  7. $this->description = $this->getDescription();
  8. $this->update = "14/05/2016";
  9. }
  10. public function collectData(array $param) {
  11. $html = $this->file_get_html($this->getURI()) or $this->returnError('Could not request Dilbert: '.$this->getURI(), 500);
  12. foreach ($html->find('section.comic-item') as $element) {
  13. $img = $element->find('img', 0);
  14. $link = $element->find('a', 0);
  15. $comic = $img->src;
  16. $title = $link->alt;
  17. $url = $link->href;
  18. $date = substr($url, 25);
  19. if (empty($title))
  20. $title = 'Dilbert Comic Strip on '.$date;
  21. $date = strtotime($date);
  22. $item = new \Item();
  23. $item->uri = $url;
  24. $item->thumbnailUri = $comic;
  25. $item->title = $title;
  26. $item->author = 'Scott Adams';
  27. $item->timestamp = $date;
  28. $item->content = '<img src="'.$comic.'" alt="'.$img->alt.'" />';
  29. $this->items[] = $item;
  30. }
  31. }
  32. public function getName() {
  33. return 'Dilbert Daily Strip';
  34. }
  35. public function getURI() {
  36. return 'http://dilbert.com';
  37. }
  38. public function getDescription() {
  39. return 'The Unofficial Dilbert Daily Comic Strip';
  40. }
  41. public function getCacheDuration() {
  42. return 21600; // 6 hours
  43. }
  44. }
  45. ?>