From 7493e2b5b8466b6702e775663abacb518349b724 Mon Sep 17 00:00:00 2001 From: Corentin Garcia Date: Fri, 15 Jun 2018 21:09:09 +0200 Subject: [PATCH] [GrandComicsDatabaseBridge] Add bridge (#717) closes #709 --- bridges/GrandComicsDatabaseBridge.php | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 bridges/GrandComicsDatabaseBridge.php diff --git a/bridges/GrandComicsDatabaseBridge.php b/bridges/GrandComicsDatabaseBridge.php new file mode 100644 index 00000000..2b2fdfe1 --- /dev/null +++ b/bridges/GrandComicsDatabaseBridge.php @@ -0,0 +1,61 @@ + array( + 'name' => 'Series id (from the timeline URL)', + 'required' => true, + 'exampleValue' => '63051', + ), + )); + + public function collectData(){ + + $url = self::URI . 'series/' . $this->getInput('series') . '/details/timeline/'; + $html = getSimpleHTMLDOM($url) + or returnServerError('Error while downloading the website content'); + + $table = $html->find('table', 0); + $list = array_reverse($table->find('[class^=row_even]')); + $seriesName = $html->find('span[id=series_name]', 0)->innertext; + + // Get row headers + $rowHeaders = $table->find('th'); + foreach($list as $article) { + + // Skip empty rows + $emptyRow = $article->find('td.empty_month'); + if (count($emptyRow) != 0) { + continue; + } + + $rows = $article->find('td'); + $key_date = $rows[0]->innertext; + + // Get URL too + $uri = 'https://www.comics.org' . $article->find('a')[0]->href; + + // Build content + $content = ''; + for($i = 0; $i < count($rowHeaders); $i++) { + $headerItem = $rowHeaders[$i]->innertext; + $rowItem = $rows[$i]->innertext; + $content = $content . $headerItem . ': ' . $rowItem . '
'; + } + + // Build final item + $item = array(); + $item['title'] = $seriesName . ' - ' . $key_date; + $item['timestamp'] = strtotime($key_date); + $item['content'] = str_get_html($content); + $item['uri'] = $uri; + + $this->items[] = $item; + } + } +}