NovelUpdatesBridge.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. return static::URI . '/series/' . $this->getInput('n') . '/';
  18. }
  19. public function collectData(){
  20. $fullhtml = getSimpleHTMLDOM($this->getURI())
  21. or returnServerError('Could not request NovelUpdates, novel "' . $this->getInput('n') . '" not found');
  22. $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext;
  23. // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259
  24. // forcefully removes tbody
  25. $html = $fullhtml->find('table#myTable', 0)->innertext;
  26. $html = stristr($html, '<tbody>'); //strip thead
  27. $html = stristr($html, '<tr>'); //remove tbody
  28. $html = str_get_html(stristr($html, '</tbody>', true)); //remove last tbody and get back as an array
  29. foreach($html->find('tr') as $element){
  30. $item = array();
  31. $item['uri'] = $element->find('td', 2)->find('a', 0)->href;
  32. $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext;
  33. $item['team'] = $element->find('td', 1)->innertext;
  34. $item['timestamp'] = strtotime($element->find('td', 0)->plaintext);
  35. $item['content'] = '<a href="'
  36. . $item['uri']
  37. . '">'
  38. . $this->seriesTitle
  39. . ' - '
  40. . $item['title']
  41. . '</a> by '
  42. . $item['team']
  43. . '<br><a href="'
  44. . $item['uri']
  45. . '">'
  46. . $fullhtml->find('div.seriesimg', 0)->innertext
  47. . '</a>';
  48. $this->items[] = $item;
  49. }
  50. }
  51. public function getName(){
  52. return $this->seriesTitle . ' - ' . static::NAME;
  53. }
  54. }