Completed
Push — master ( 6a19ed...8870a8 )
by Angus
02:30
created
application/models/Site_Model.php 1 patch
Spacing   +36 added lines, -36 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
 abstract class Site_Model extends CI_Model {
4 4
 	public function __construct() {
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 	abstract public function isValidTitleURL(string $title_url) : bool;
17 17
 	abstract public function isValidChapter(string $chapter) : bool;
18 18
 
19
-	protected function get_content(string $url, string $cookie_string = "", string $cookiejar_path = "", bool $follow_redirect = FALSE){
19
+	protected function get_content(string $url, string $cookie_string = "", string $cookiejar_path = "", bool $follow_redirect = FALSE) {
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($follow_redirect)        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
25 25
 
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 
124 124
 				$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
125 125
 				$chapterURLSegments = explode('/', $link);
126
-				$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
127
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
126
+				$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
127
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
128 128
 			}
129 129
 		} else {
130 130
 			//TODO: Throw ERRORS;
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 
184 184
 				$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
185 185
 				$chapterURLSegments = explode('/', $link);
186
-				$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
187
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
186
+				$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
187
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
188 188
 			}
189 189
 		} else {
190 190
 			//TODO: Throw ERRORS;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 
226 226
 		$chapter_parts = explode(':--:', $chapter);
227 227
 		return [
228
-			'url'    => "http://bato.to/reader#" . $chapter_parts[0],
228
+			'url'    => "http://bato.to/reader#".$chapter_parts[0],
229 229
 			'number' => $chapter_parts[1]
230 230
 		];
231 231
 	}
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 		//Bato.to is annoying and locks stuff behind auth. See: https://github.com/DakuTree/manga-tracker/issues/14#issuecomment-233830855
242 242
 		$cookies = [
243 243
 			"lang_option={$title_lang}",
244
-			"member_id=" . $this->config->item('batoto_cookie_member_id'),
245
-			"pass_hash=" . $this->config->item('batoto_cookie_pass_hash')
244
+			"member_id=".$this->config->item('batoto_cookie_member_id'),
245
+			"pass_hash=".$this->config->item('batoto_cookie_pass_hash')
246 246
 		];
247 247
 		$data = $this->get_content($title_url, implode("; ", $cookies), "", TRUE);
248 248
 		if(!$data) {
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
 					preg_match('/^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)(?:\s?-\s?(?<extra>[0-9]+))?):?.*/', trim($chapter_element->nodeValue), $text);
276 276
 
277 277
 					$titleData['title']          = html_entity_decode(trim($xpath->query('//h1[@class="ipsType_pagetitle"]')->item(0)->nodeValue));
278
-					$titleData['latest_chapter'] = substr($chapter_element->getAttribute('href'), 22) . ':--:' . ((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '') . 'c'.$text['chapter'] . (!empty($text['extra']) ? '-'.$text['extra'] : ''));
278
+					$titleData['latest_chapter'] = substr($chapter_element->getAttribute('href'), 22).':--:'.((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '').'c'.$text['chapter'].(!empty($text['extra']) ? '-'.$text['extra'] : ''));
279 279
 
280 280
 					$dateString = $updated_element->nodeValue;
281 281
 					if($dateString == 'An hour ago') {
282 282
 						$dateString = '1 hour ago';
283 283
 					}
284
-					$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
284
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
285 285
 				} else {
286 286
 					log_message('error', "Batoto: Regex missing <td> ({$title_url})");
287 287
 					return NULL;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		*/
330 330
 
331 331
 		$chapterData = [
332
-			'url'    => 'http://dynasty-scans.com/chapters/' . $title_parts[0].'_'.$chapter,
332
+			'url'    => 'http://dynasty-scans.com/chapters/'.$title_parts[0].'_'.$chapter,
333 333
 			'number' => ''
334 334
 		];
335 335
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
 
370 370
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
371 371
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
372
-			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '') . substr($matchesT[0], 3, -4);
372
+			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '').substr($matchesT[0], 3, -4);
373 373
 
374 374
 			$data = preg_replace('/^[\S\s]*(<dl class=\'chapter-list\'>[\S\s]*<\/dl>)[\S\s]*$/', '$1', $data);
375 375
 			preg_match_all('/<dd>[\s\S]+?(?=<\/dd>)<\/dd>/', $data, $matches);
376 376
 			$latest_chapter_html = array_pop($matches[0]);
377 377
 
378 378
 			preg_match('/\/chapters\/([^"]+)/', $latest_chapter_html, $matches);
379
-			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url)+1);
379
+			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url) + 1);
380 380
 			//FIXME: THIS IS A TEMP FIX, SEE https://github.com/DakuTree/manga-tracker/issues/58
381 381
 			if(!$titleData['latest_chapter']) {
382 382
 				log_message('error', 'DynastyScans::getTitleData cannot parse title properly as it contains oneshot. || URL: '.$title_url);
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 			}
385 385
 
386 386
 			preg_match('/<small>released (.*)<\/small>/', $latest_chapter_html, $matches);
387
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
387
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
388 388
 		} elseif($title_parts[1] == '1') {
389 389
 			$data = $this->get_content('http://dynasty-scans.com/chapters/'.$title_url);
390 390
 
391 391
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
392 392
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
393
-			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '') . substr($matchesT[0], 3, -4);
393
+			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '').substr($matchesT[0], 3, -4);
394 394
 
395 395
 			$titleData['latest_chapter'] = 'oneshot'; //This will never change
396 396
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 				$nodes_chapter = $xpath->query("td[1]/a", $nodes_row[0]);
457 457
 
458 458
 				$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
459
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
459
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
460 460
 			}
461 461
 		} else {
462 462
 			//TODO: Throw ERRORS;
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 				$nodes_chapter = $xpath->query("td[1]/a", $nodes_row[0]);
515 515
 
516 516
 				$titleData['latest_chapter'] = preg_replace('/^.*\/(.*?\/[0-9]+)\/[0-9]+$/', '$1', (string) $nodes_chapter[0]->getAttribute('href'));
517
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
517
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->nodeValue));
518 518
 			}
519 519
 		} else {
520 520
 			//TODO: Throw ERRORS;
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 				$titleData['title'] = trim((string) $xml->channel->title);
580 580
 
581 581
 				$chapterURLSegments = explode('/', ((string) $xml->channel->item[0]->link));
582
-				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]) . ':--:' . $chapterURLSegments[6];
583
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $xml->channel->item[0]->pubDate));
582
+				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]).':--:'.$chapterURLSegments[6];
583
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $xml->channel->item[0]->pubDate));
584 584
 			}
585 585
 		} else {
586 586
 			//TODO: Throw ERRORS;
@@ -659,8 +659,8 @@  discard block
 block discarded – undo
659 659
 
660 660
 					$link = (string) $nodes_chapter[0]->getAttribute('href');
661 661
 					$chapterURLSegments = explode('/', preg_replace('/\?.*$/', '', $link));
662
-					$titleData['latest_chapter'] = $chapterURLSegments[3] . ':--:' . preg_replace('/.*?([0-9]+)$/', '$1', $link);
663
-					$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->textContent));
662
+					$titleData['latest_chapter'] = $chapterURLSegments[3].':--:'.preg_replace('/.*?([0-9]+)$/', '$1', $link);
663
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest[0]->textContent));
664 664
 				}
665 665
 			} else {
666 666
 				//TODO: Throw ERRORS;
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 		$chapter_parts = explode('/', $chapter);
696 696
 		return [
697 697
 			'url'    => "https://reader.kireicake.com/read/{$title_url}/{$chapter}",
698
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
698
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
699 699
 		];
700 700
 	}
701 701
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 
727 727
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
728 728
 				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
729
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
729
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
730 730
 			}
731 731
 		} else {
732 732
 			//TODO: Throw ERRORS;
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 
785 785
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
786 786
 				$titleData['latest_chapter'] = preg_replace('/^projects\/.*?\/(.*?)\/$/', '$1', $link);
787
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", (int) $nodes_latest[0]->getAttribute('data-time'));
787
+				$titleData['last_updated'] = date("Y-m-d H:i:s", (int) $nodes_latest[0]->getAttribute('data-time'));
788 788
 			} else {
789 789
 				log_message('error', "GameOfScanlation: Unable to find nodes.");
790 790
 				return NULL;
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 
844 844
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
845 845
 				$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)\/$/', '$1', $link);
846
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) substr($nodes_latest[0]->getAttribute('title'), 13)));
846
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) substr($nodes_latest[0]->getAttribute('title'), 13)));
847 847
 			} else {
848 848
 				log_message('error', "MangaCow: Unable to find nodes.");
849 849
 				return NULL;
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
 		$chapter_parts = explode('/', $chapter);
878 878
 		return [
879 879
 			'url'    => "https://reader.seaotterscans.com/read/{$title_url}/{$chapter}",
880
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
880
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
881 881
 		];
882 882
 	}
883 883
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 			//SOO sometimes uses volume groups which are above recent chapters (if they haven't been grouped yet), so make sure we check for both.
903 903
 			$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group']/div[@class='title' and text() = 'Chapters']/following-sibling::div[@class='element'][1]");
904 904
 			if($nodes_row->length !== 1) {
905
-				$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
905
+				$nodes_row = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
906 906
 			}
907 907
 			if($nodes_title->length === 1 && $nodes_row->length === 1) {
908 908
 				$titleData['title'] = trim($nodes_title[0]->textContent);
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
 
914 914
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
915 915
 				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
916
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
916
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
917 917
 			}
918 918
 		} else {
919 919
 			//TODO: Throw ERRORS;
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 		$chapter_parts = explode('/', $chapter);
945 945
 		return [
946 946
 			'url'    => "http://helveticascans.com/reader/read/{$title_url}/{$chapter}",
947
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
947
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
948 948
 		];
949 949
 	}
950 950
 
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 			$nodes_title = $xpath->query("//div[@class='large comic']/h1[@class='title']");
968 968
 			$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group']/div[@class='title' and text() = 'Chapters']/following-sibling::div[@class='element'][1]");
969 969
 			if($nodes_row->length !== 1) {
970
-				$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
970
+				$nodes_row = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
971 971
 			}
972 972
 			if($nodes_title->length === 1 && $nodes_row->length === 1) {
973 973
 				$titleData['title'] = trim($nodes_title[0]->textContent);
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 
979 979
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
980 980
 				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
981
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
981
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
982 982
 			}
983 983
 		} else {
984 984
 			//TODO: Throw ERRORS;
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 		$chapter_parts = explode('/', $chapter);
1009 1009
 		return [
1010 1010
 			'url'    => "http://reader.sensescans.com/read/{$title_url}/{$chapter}",
1011
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
1011
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
1012 1012
 		];
1013 1013
 	}
1014 1014
 
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 			$nodes_title = $xpath->query("//div[@class='large comic']/h1[@class='title']");
1032 1032
 			$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group']/div[@class='title' and text() = 'Chapters']/following-sibling::div[@class='element'][1]");
1033 1033
 			if($nodes_row->length !== 1) {
1034
-				$nodes_row   = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
1034
+				$nodes_row = $xpath->query("//div[@class='list']/div[@class='group'][1]/div[@class='element'][1]");
1035 1035
 			}
1036 1036
 			if($nodes_title->length === 1 && $nodes_row->length === 1) {
1037 1037
 				$titleData['title'] = trim($nodes_title[0]->textContent);
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 
1043 1043
 				$link = (string) $nodes_chapter[0]->getAttribute('href');
1044 1044
 				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
1045
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
1045
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $nodes_latest[0]->textContent)[1])));
1046 1046
 			}
1047 1047
 		} else {
1048 1048
 			//TODO: Throw ERRORS;
Please login to merge, or discard this patch.