Completed
Push — master ( bad5d9...4e991e )
by Angus
03:11
created
application/models/Site_Model.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
1
+<?php declare(strict_types = 1); defined('BASEPATH') OR exit('No direct script access allowed');
2 2
 
3 3
 class Site_Model extends CI_Model {
4 4
 	public function __construct() {
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 	public function isValidTitleURL(string $title_url) : bool {}
17 17
 	public function isValidChapter(string $chapter): bool {}
18 18
 
19
-	protected function get_content(string $url, string $cookie_string = "", string $cookiejar_path = ""){
19
+	protected function get_content(string $url, string $cookie_string = "", string $cookiejar_path = "") {
20 20
 		$ch = curl_init();
21 21
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22
-		curl_setopt($ch, CURLOPT_ENCODING , "gzip");
22
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
23 23
 
24 24
 		if(!empty($cookie_string))  curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
25 25
 		if(!empty($cookiejar_path)) curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar_path);
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 
114 114
 				$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
115 115
 				$chapterURLSegments = explode('/', $link);
116
-				$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
117
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
116
+				$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
117
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
118 118
 			}
119 119
 		} else {
120 120
 			//TODO: Throw ERRORS;
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 
174 174
 				$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
175 175
 				$chapterURLSegments = explode('/', $link);
176
-				$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
177
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
176
+				$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
177
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
178 178
 			}
179 179
 		} else {
180 180
 			//TODO: Throw ERRORS;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
 		$chapter_parts = explode(':--:', $chapter);
216 216
 		return [
217
-			'url'    => "http://bato.to/reader#" . $chapter_parts[0],
217
+			'url'    => "http://bato.to/reader#".$chapter_parts[0],
218 218
 			'number' => $chapter_parts[1]
219 219
 		];
220 220
 	}
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 		//Bato.to is annoying and locks stuff behind auth. See: https://github.com/DakuTree/manga-tracker/issues/14#issuecomment-233830855
231 231
 		$cookies = [
232 232
 			"lang_option={$title_lang}",
233
-		    "member_id=" . $this->config->item('batoto_cookie_member_id'),
234
-		    "pass_hash=" . $this->config->item('batoto_cookie_pass_hash')
233
+		    "member_id=".$this->config->item('batoto_cookie_member_id'),
234
+		    "pass_hash=".$this->config->item('batoto_cookie_pass_hash')
235 235
 		];
236 236
 		$data = $this->get_content($title_url, implode("; ", $cookies));
237 237
 		if(!$data) {
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
 					preg_match('/^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)):?.*/', trim($chapter_element->nodeValue), $text);
264 264
 
265 265
 					$titleData['title']          = html_entity_decode(trim($xpath->query('//h1[@class="ipsType_pagetitle"]')->item(0)->nodeValue));
266
-					$titleData['latest_chapter'] = substr($chapter_element->getAttribute('href'), 22) . ':--:' . ((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '') . 'c'.$text['chapter']);
266
+					$titleData['latest_chapter'] = substr($chapter_element->getAttribute('href'), 22).':--:'.((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '').'c'.$text['chapter']);
267 267
 
268 268
 					$dateString = $updated_element->nodeValue;
269 269
 					if($dateString == 'An hour ago') {
270 270
 						$dateString = '1 hour ago';
271 271
 					}
272
-					$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
272
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
273 273
 				} else {
274 274
 					log_message('error', "Batoto: Regex missing <td> ({$title_url})");
275 275
 					return NULL;
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		*/
318 318
 
319 319
 		$chapterData = [
320
-			'url'    => 'http://dynasty-scans.com/chapters/' . $title_parts[0].'_'.$chapter,
320
+			'url'    => 'http://dynasty-scans.com/chapters/'.$title_parts[0].'_'.$chapter,
321 321
 			'number' => ''
322 322
 		];
323 323
 
@@ -357,14 +357,14 @@  discard block
 block discarded – undo
357 357
 
358 358
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
359 359
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
360
-			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '') . substr($matchesT[0], 3, -4);
360
+			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '').substr($matchesT[0], 3, -4);
361 361
 
362 362
 			$data = preg_replace('/^[\S\s]*(<dl class=\'chapter-list\'>[\S\s]*<\/dl>)[\S\s]*$/', '$1', $data);
363 363
 			preg_match_all('/<dd>[\s\S]+?(?=<\/dd>)<\/dd>/', $data, $matches);
364 364
 			$latest_chapter_html = array_pop($matches[0]);
365 365
 
366 366
 			preg_match('/\/chapters\/([^"]+)/', $latest_chapter_html, $matches);
367
-			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url)+1);
367
+			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url) + 1);
368 368
 			//FIXME: THIS IS A TEMP FIX, SEE https://github.com/DakuTree/manga-tracker/issues/58
369 369
 			if(!$titleData['latest_chapter']) {
370 370
 				log_message('error', 'DynastyScans::getTitleData cannot parse title properly as it contains oneshot. || URL: '.$title_url);
@@ -372,13 +372,13 @@  discard block
 block discarded – undo
372 372
 			}
373 373
 
374 374
 			preg_match('/<small>released (.*)<\/small>/', $latest_chapter_html, $matches);
375
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
375
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
376 376
 		} elseif($title_parts[1] == '1') {
377 377
 			$data = $this->get_content('http://dynasty-scans.com/chapters/'.$title_url);
378 378
 
379 379
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
380 380
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
381
-			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '') . substr($matchesT[0], 3, -4);
381
+			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '').substr($matchesT[0], 3, -4);
382 382
 
383 383
 			$titleData['latest_chapter'] = 'oneshot'; //This will never change
384 384
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 				$nodes_chapter = $xpath->query("td[1]/a", $nodes_row[0]);
445 445
 
446 446
 				$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
447
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
447
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
448 448
 			}
449 449
 		} else {
450 450
 			//TODO: Throw ERRORS;
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 				$nodes_chapter = $xpath->query("td[1]/a", $nodes_row[0]);
503 503
 
504 504
 				$titleData['latest_chapter'] = preg_replace('/^.*\/(.*?\/[0-9]+)\/[0-9]+$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
505
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
505
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
506 506
 			}
507 507
 		} else {
508 508
 			//TODO: Throw ERRORS;
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 				$titleData['title'] = trim((string) $xml->channel->title);
568 568
 
569 569
 				$chapterURLSegments = explode('/', ((string) $xml->channel->item[0]->link));
570
-				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]) . ':--:' . $chapterURLSegments[6];
571
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $xml->channel->item[0]->pubDate));
570
+				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]).':--:'.$chapterURLSegments[6];
571
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $xml->channel->item[0]->pubDate));
572 572
 			}
573 573
 		} else {
574 574
 			//TODO: Throw ERRORS;
@@ -647,8 +647,8 @@  discard block
 block discarded – undo
647 647
 
648 648
 					$link = (string) $nodes_chapter[0]->getAttribute('href');
649 649
 					$chapterURLSegments = explode('/', preg_replace('/\?.*$/', '', $link));
650
-					$titleData['latest_chapter'] = $chapterURLSegments[3] . ':--:' . preg_replace('/.*?([0-9]+)$/', '$1', $link);
651
-					$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->textContent));
650
+					$titleData['latest_chapter'] = $chapterURLSegments[3].':--:'.preg_replace('/.*?([0-9]+)$/', '$1', $link);
651
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->textContent));
652 652
 				}
653 653
 			} else {
654 654
 				//TODO: Throw ERRORS;
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 		$chapter_parts = explode('/', $chapter);
684 684
 		return [
685 685
 			'url'    => "https://reader.kireicake.com/read/{$title_url}/{$chapter}",
686
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
686
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
687 687
 		];
688 688
 	}
689 689
 
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 
715 715
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
716 716
 				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
717
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
717
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
718 718
 			}
719 719
 		} else {
720 720
 			//TODO: Throw ERRORS;
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 
773 773
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
774 774
 				$titleData['latest_chapter'] = preg_replace('/^projects\/.*?\/(.*?)\/$/', '$1', $link);
775
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", (int) $nodes_latest[0]->getAttribute('data-time'));
775
+				$titleData['last_updated'] = date("Y-m-d H:i:s", (int) $nodes_latest[0]->getAttribute('data-time'));
776 776
 			} else {
777 777
 				log_message('error', "GameOfScanlation: Unable to find nodes.");
778 778
 				return NULL;
Please login to merge, or discard this patch.