DilbertBridge.php 1.2 KB

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