NovelUpdatesBridge.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class NovelUpdatesBridge extends BridgeAbstract {
  3. const MAINTAINER = 'albirew';
  4. const NAME = 'Novel Updates';
  5. const URI = 'http://www.novelupdates.com/';
  6. const CACHE_TIMEOUT = 21600; // 6h
  7. const DESCRIPTION = 'Returns releases from Novel Updates';
  8. const PARAMETERS = array( array(
  9. 'n' => array(
  10. 'name' => 'Novel name as found in the url',
  11. 'exampleValue' => 'spirit-realm',
  12. 'required' => true
  13. )
  14. ));
  15. private $seriesTitle = '';
  16. public function getURI(){
  17. if(!is_null($this->getInput('n'))) {
  18. return static::URI . '/series/' . $this->getInput('n') . '/';
  19. }
  20. return parent::getURI();
  21. }
  22. public function collectData(){
  23. $fullhtml = getSimpleHTMLDOM($this->getURI())
  24. or returnServerError('Could not request NovelUpdates, novel "' . $this->getInput('n') . '" not found');
  25. $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext;
  26. // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259
  27. // forcefully removes tbody
  28. $html = $fullhtml->find('table#myTable', 0)->innertext;
  29. $html = stristr($html, '<tbody>'); //strip thead
  30. $html = stristr($html, '<tr>'); //remove tbody
  31. $html = str_get_html(stristr($html, '</tbody>', true)); //remove last tbody and get back as an array
  32. foreach($html->find('tr') as $element) {
  33. $item = array();
  34. $item['uri'] = $element->find('td', 2)->find('a', 0)->href;
  35. $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext;
  36. $item['team'] = $element->find('td', 1)->innertext;
  37. $item['timestamp'] = strtotime($element->find('td', 0)->plaintext);
  38. $item['content'] = '<a href="'
  39. . $item['uri']
  40. . '">'
  41. . $this->seriesTitle
  42. . ' - '
  43. . $item['title']
  44. . '</a> by '
  45. . $item['team']
  46. . '<br><a href="'
  47. . $item['uri']
  48. . '">'
  49. . $fullhtml->find('div.seriesimg', 0)->innertext
  50. . '</a>';
  51. $this->items[] = $item;
  52. }
  53. }
  54. public function getName(){
  55. if(!empty($this->seriesTitle)) {
  56. return $this->seriesTitle . ' - ' . static::NAME;
  57. }
  58. return parent::getName();
  59. }
  60. }