DilbertBridge.php 1.3 KB

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