GoComicsBridge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class GoComicsBridge extends BridgeAbstract {
  3. const MAINTAINER = 'sky';
  4. const NAME = 'GoComics Unofficial RSS';
  5. const URI = 'https://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. //Get info from first page
  19. $author = preg_replace('/By /', '', $html->find('.media-subheading', 0)->plaintext);
  20. $link = self::URI . $html->find('.gc-deck--cta-0', 0)->find('a', 0)->href;
  21. for($i = 0; $i < 5; $i++) {
  22. $item = array();
  23. $page = getSimpleHTMLDOM($link)
  24. or returnServerError('Could not request GoComics: ' . $link);
  25. $imagelink = $page->find('.img-fluid', 1)->src;
  26. $date = explode('/', $link);
  27. $item['id'] = $imagelink;
  28. $item['uri'] = $link;
  29. $item['author'] = $author;
  30. $item['title'] = 'GoComics ' . $this->getInput('comicname');
  31. $item['timestamp'] = DateTime::createFromFormat('Ymd', $date[5] . $date[6] . $date[7])->getTimestamp();
  32. $item['content'] = '<img src="' . $imagelink . '" />';
  33. $link = self::URI . $page->find('.js-previous-comic', 0)->href;
  34. $this->items[] = $item;
  35. }
  36. }
  37. public function getURI(){
  38. if(!is_null($this->getInput('comicname'))) {
  39. return self::URI . urlencode($this->getInput('comicname'));
  40. }
  41. return parent::getURI();
  42. }
  43. public function getName(){
  44. if(!is_null($this->getInput('comicname'))) {
  45. return $this->getInput('comicname') . ' - GoComics';
  46. }
  47. return parent::getName();
  48. }
  49. }