GoComicsBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class GoComicsBridge extends BridgeAbstract {
  3. const MAINTAINER = 'sky';
  4. const NAME = 'GoComics Unofficial RSS';
  5. const URI = 'http://www.gocomics.com/';
  6. const CACHE_TIMEOUT = 21600; // 6h
  7. const DESCRIPTION = 'The Unofficial GoComics RSS';
  8. const PARAMETERS = array( array(
  9. 'comicname' => array(
  10. 'name' => 'comicname',
  11. 'type' => 'text',
  12. 'required' => true
  13. )
  14. ));
  15. public function collectData(){
  16. $html = getSimpleHTMLDOM($this->getURI())
  17. or returnServerError('Could not request GoComics: ' . $this->getURI());
  18. foreach($html->find('div.item-comic-container') as $element) {
  19. $img = $element->find('img', 0);
  20. $link = $element->find('a.item-comic-link', 0);
  21. $comic = $img->src;
  22. $title = $link->title;
  23. $url = $html->find('input.js-copy-link', 0)->value;
  24. $date = substr($title, -10);
  25. if (empty($title))
  26. $title = 'GoComics ' . $this->getInput('comicname') . ' on ' . $date;
  27. $date = strtotime($date);
  28. $item = array();
  29. $item['id'] = $url;
  30. $item['uri'] = $url;
  31. $item['title'] = $title;
  32. $item['author'] = preg_replace('/by /', '', $element->find('a.link-blended small', 0)->plaintext);
  33. $item['timestamp'] = $date;
  34. $item['content'] = '<img src="' . $comic . '" alt="' . $title . '" />';
  35. $this->items[] = $item;
  36. }
  37. }
  38. public function getURI(){
  39. if(!is_null($this->getInput('comicname'))) {
  40. return self::URI . urlencode($this->getInput('comicname'));
  41. }
  42. return parent::getURI();
  43. }
  44. public function getName(){
  45. if(!is_null($this->getInput('comicname'))) {
  46. return $this->getInput('comicname') . ' - GoComics';
  47. }
  48. return parent::getName();
  49. }
  50. }