DilbertBridge.php 992 B

123456789101112131415161718192021222324252627282930313233343536
  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 CACHE_TIMEOUT = 21600; // 6h
  7. const DESCRIPTION = 'The Unofficial Dilbert Daily Comic Strip';
  8. public function collectData(){
  9. $html = getSimpleHTMLDOM($this->getURI())
  10. or 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. }