ReadComicsBridge.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. class ReadComicsBridge extends BridgeAbstract {
  3. const MAINTAINER = 'niawag';
  4. const NAME = 'Read Comics';
  5. const URI = 'http://www.readcomics.tv/';
  6. const DESCRIPTION = 'Enter the comics as they appear in the website uri,
  7. separated by semicolons, ex: good-comic-1;good-comic-2; ...';
  8. const PARAMETERS = array( array(
  9. 'q' => array(
  10. 'name' => 'keywords, separated by semicolons',
  11. 'exampleValue' => 'first list;second list;...',
  12. 'required' => true
  13. ),
  14. ));
  15. public function collectData(){
  16. function parseDateTimestamp($element){
  17. $guessedDate = $element->find('span', 0)->plaintext;
  18. $guessedDate = strptime($guessedDate, '%m/%d/%Y');
  19. $timestamp = mktime(0, 0, 0, $guessedDate['tm_mon'] + 1, $guessedDate['tm_mday'], date('Y'));
  20. return $timestamp;
  21. }
  22. $keywordsList = explode(';', $this->getInput('q'));
  23. foreach($keywordsList as $keywords) {
  24. $html = $this->getSimpleHTMLDOM(self::URI . 'comic/' . rawurlencode($keywords))
  25. or $this->returnServerError('Could not request readcomics.tv.');
  26. foreach($html->find('li') as $element) {
  27. $item = array();
  28. $item['uri'] = $element->find('a.ch-name', 0)->href;
  29. $item['id'] = $item['uri'];
  30. $item['timestamp'] = parseDateTimestamp($element);
  31. $item['title'] = $element->find('a.ch-name', 0)->plaintext;
  32. if(isset($item['title']))
  33. $this->items[] = $item;
  34. }
  35. }
  36. }
  37. }