GrandComicsDatabaseBridge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class GrandComicsDatabaseBridge extends BridgeAbstract {
  3. const MAINTAINER = 'corenting';
  4. const NAME = 'Grand Comics Database Bridge';
  5. const URI = 'https://www.comics.org/';
  6. const CACHE_TIMEOUT = 7200; // 2h
  7. const DESCRIPTION = 'Returns the latest comics added to a series timeline';
  8. const PARAMETERS = array( array(
  9. 'series' => array(
  10. 'name' => 'Series id (from the timeline URL)',
  11. 'required' => true,
  12. 'exampleValue' => '63051',
  13. ),
  14. ));
  15. public function collectData(){
  16. $url = self::URI . 'series/' . $this->getInput('series') . '/details/timeline/';
  17. $html = getSimpleHTMLDOM($url)
  18. or returnServerError('Error while downloading the website content');
  19. $table = $html->find('table', 0);
  20. $list = array_reverse($table->find('[class^=row_even]'));
  21. $seriesName = $html->find('span[id=series_name]', 0)->innertext;
  22. // Get row headers
  23. $rowHeaders = $table->find('th');
  24. foreach($list as $article) {
  25. // Skip empty rows
  26. $emptyRow = $article->find('td.empty_month');
  27. if (count($emptyRow) != 0) {
  28. continue;
  29. }
  30. $rows = $article->find('td');
  31. $key_date = $rows[0]->innertext;
  32. // Get URL too
  33. $uri = 'https://www.comics.org' . $article->find('a')[0]->href;
  34. // Build content
  35. $content = '';
  36. for($i = 0; $i < count($rowHeaders); $i++) {
  37. $headerItem = $rowHeaders[$i]->innertext;
  38. $rowItem = $rows[$i]->innertext;
  39. $content = $content . $headerItem . ': ' . $rowItem . '<br/>';
  40. }
  41. // Build final item
  42. $item = array();
  43. $item['title'] = $seriesName . ' - ' . $key_date;
  44. $item['timestamp'] = strtotime($key_date);
  45. $item['content'] = str_get_html($content);
  46. $item['uri'] = $uri;
  47. $this->items[] = $item;
  48. }
  49. }
  50. }