NovelUpdatesBridge.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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'] =
  36. '<a href="'.$item['uri'].'">'
  37. .$this->seriesTitle.' - '.$item['title']
  38. .'</a> by '.$item['team'].'<br>'
  39. .'<a href="'.$item['uri'].'">'.$fullhtml->find('div.seriesimg', 0)->innertext.'</a>';
  40. $this->items[] = $item;
  41. }
  42. }
  43. public function getName(){
  44. return $this->seriesTitle. ' - ' . static::NAME;
  45. }
  46. }