NovelUpdatesBridge.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 DESCRIPTION = "Returns releases from Novel Updates";
  7. const PARAMETERS = array( array(
  8. 'n'=>array(
  9. 'name'=>'Novel name as found in the url',
  10. 'exampleValue'=>'spirit-realm',
  11. 'required'=>true
  12. )
  13. ));
  14. private $seriesTitle='';
  15. public function getURI(){
  16. return static::URI.'/series/'.$this->getInput('n').'/';
  17. }
  18. public function collectData(){
  19. $fullhtml = getSimpleHTMLDOM($this->getURI())
  20. or returnServerError('Could not request NovelUpdates, novel "'.$this->getInput('n').'" not found');
  21. $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext;
  22. // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259
  23. // forcefully removes tbody
  24. $html = $fullhtml->find('table#myTable', 0)->innertext;
  25. $html = stristr($html, '<tbody>'); //strip thead
  26. $html = stristr($html, '<tr>'); //remove tbody
  27. $html = str_get_html(stristr($html, '</tbody>', true)); //remove last tbody and get back as an array
  28. foreach($html->find('tr') as $element){
  29. $item = array();
  30. $item['uri'] = $element->find('td', 2)->find('a', 0)->href;
  31. $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext;
  32. $item['team'] = $element->find('td', 1)->innertext;
  33. $item['timestamp'] = strtotime($element->find('td', 0)->plaintext);
  34. $item['content'] =
  35. '<a href="'.$item['uri'].'">'
  36. .$this->seriesTitle.' - '.$item['title']
  37. .'</a> by '.$item['team'].'<br>'
  38. .'<a href="'.$item['uri'].'">'.$fullhtml->find('div.seriesimg', 0)->innertext.'</a>';
  39. $this->items[] = $item;
  40. }
  41. }
  42. public function getName(){
  43. return $this->seriesTitle. ' - ' . static::NAME;
  44. }
  45. public function getCacheDuration(){
  46. return 21600; // 6 hours
  47. }
  48. }