Completed
Push — master ( 83a0f0...004135 )
by Angus
03:33
created
application/models/Site_Model.php 1 patch
Spacing   +29 added lines, -29 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 $site          = '';
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	final protected function get_content(string $url, string $cookie_string = "", string $cookiejar_path = "", bool $follow_redirect = FALSE) {
33 33
 		$ch = curl_init();
34 34
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
35
-		curl_setopt($ch, CURLOPT_ENCODING , "gzip");
35
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
36 36
 		//curl_setopt($ch, CURLOPT_VERBOSE, 1);
37 37
 		curl_setopt($ch, CURLOPT_HEADER, 1);
38 38
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 			$nodes_row   = $xpath->query($node_row_string);
112 112
 			if($nodes_title->length === 1 && $nodes_row->length === 1) {
113 113
 				$firstRow      = $nodes_row->item(0);
114
-				$nodes_latest  = $xpath->query($node_latest_string,  $firstRow);
114
+				$nodes_latest  = $xpath->query($node_latest_string, $firstRow);
115 115
 
116 116
 				if($node_chapter_string !== '') {
117 117
 					$nodes_chapter = $xpath->query($node_chapter_string, $firstRow);
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 
240 240
 			$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
241 241
 			$chapterURLSegments = explode('/', $link);
242
-			$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
243
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
242
+			$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
243
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
244 244
 		}
245 245
 
246 246
 		return (!empty($titleData) ? $titleData : NULL);
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 
285 285
 			$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
286 286
 			$chapterURLSegments = explode('/', $link);
287
-			$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
288
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
287
+			$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
288
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
289 289
 		}
290 290
 
291 291
 		return (!empty($titleData) ? $titleData : NULL);
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 
317 317
 		$chapter_parts = explode(':--:', $chapter);
318 318
 		return [
319
-			'url'    => "http://bato.to/reader#" . $chapter_parts[0],
319
+			'url'    => "http://bato.to/reader#".$chapter_parts[0],
320 320
 			'number' => $chapter_parts[1]
321 321
 		];
322 322
 	}
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 
353 353
 			///^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)(?:\s?-\s?(?<extra>[0-9]+))?):?.*/
354 354
 			preg_match('/^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)(?:\s?-\s?(?<extra>[0-9]+))?):?.*/', trim($data['nodes_chapter']->nodeValue), $text);
355
-			$titleData['latest_chapter'] = substr($data['nodes_chapter']->getAttribute('href'), 22) . ':--:' . ((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '') . 'c'.$text['chapter'] . (!empty($text['extra']) ? '-'.$text['extra'] : ''));
355
+			$titleData['latest_chapter'] = substr($data['nodes_chapter']->getAttribute('href'), 22).':--:'.((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '').'c'.$text['chapter'].(!empty($text['extra']) ? '-'.$text['extra'] : ''));
356 356
 
357 357
 			$dateString = $data['nodes_latest']->nodeValue;
358 358
 			if($dateString == 'An hour ago') {
359 359
 				$dateString = '1 hour ago';
360 360
 			}
361
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
361
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
362 362
 		}
363 363
 
364 364
 		return (!empty($titleData) ? $titleData : NULL);
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 		*/
398 398
 
399 399
 		$chapterData = [
400
-			'url'    => 'http://dynasty-scans.com/chapters/' . $title_parts[0].'_'.$chapter,
400
+			'url'    => 'http://dynasty-scans.com/chapters/'.$title_parts[0].'_'.$chapter,
401 401
 			'number' => ''
402 402
 		];
403 403
 
@@ -438,14 +438,14 @@  discard block
 block discarded – undo
438 438
 
439 439
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
440 440
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
441
-			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '') . substr($matchesT[0], 3, -4);
441
+			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '').substr($matchesT[0], 3, -4);
442 442
 
443 443
 			$data = preg_replace('/^[\S\s]*(<dl class=\'chapter-list\'>[\S\s]*<\/dl>)[\S\s]*$/', '$1', $data);
444 444
 			preg_match_all('/<dd>[\s\S]+?(?=<\/dd>)<\/dd>/', $data, $matches);
445 445
 			$latest_chapter_html = array_pop($matches[0]);
446 446
 
447 447
 			preg_match('/\/chapters\/([^"]+)/', $latest_chapter_html, $matches);
448
-			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url)+1);
448
+			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url) + 1);
449 449
 			//FIXME: THIS IS A TEMP FIX, SEE https://github.com/DakuTree/manga-tracker/issues/58
450 450
 			if(!$titleData['latest_chapter']) {
451 451
 				log_message('error', 'DynastyScans::getTitleData cannot parse title properly as it contains oneshot. || URL: '.$title_url);
@@ -453,14 +453,14 @@  discard block
 block discarded – undo
453 453
 			}
454 454
 
455 455
 			preg_match('/<small>released (.*)<\/small>/', $latest_chapter_html, $matches);
456
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
456
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
457 457
 		} elseif($title_parts[1] == '1') {
458 458
 			$content = $this->get_content('http://dynasty-scans.com/chapters/'.$title_url);
459 459
 			$data = $content['body'];
460 460
 
461 461
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
462 462
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
463
-			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '') . substr($matchesT[0], 3, -4);
463
+			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '').substr($matchesT[0], 3, -4);
464 464
 
465 465
 			$titleData['latest_chapter'] = 'oneshot'; //This will never change
466 466
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
 			$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
516 516
 
517
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
517
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
518 518
 		}
519 519
 
520 520
 		return (!empty($titleData) ? $titleData : NULL);
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 
559 559
 			$titleData['latest_chapter'] = preg_replace('/^.*\/(.*?\/[0-9]+)\/[0-9]+$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
560 560
 
561
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
561
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
562 562
 		}
563 563
 
564 564
 		return (!empty($titleData) ? $titleData : NULL);
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
 				$titleData['title'] = trim((string) $xml->{'channel'}->title);
618 618
 
619 619
 				$chapterURLSegments = explode('/', ((string) $xml->{'channel'}->item[0]->link));
620
-				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]) . ':--:' . $chapterURLSegments[6];
621
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $xml->{'channel'}->item[0]->pubDate));
620
+				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]).':--:'.$chapterURLSegments[6];
621
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $xml->{'channel'}->item[0]->pubDate));
622 622
 			}
623 623
 		} else {
624 624
 			log_message('error', "Series missing? (WebToons): {$title_url}");
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
 					$titleData['title'] = $nodes_title->item(0)->textContent;
690 690
 
691 691
 					$firstRow      = $nodes_row->item(0);
692
-					$nodes_latest  = $xpath->query("td[2]",   $firstRow);
692
+					$nodes_latest  = $xpath->query("td[2]", $firstRow);
693 693
 					$nodes_chapter = $xpath->query("td[1]/a", $firstRow);
694 694
 
695 695
 					$link = (string) $nodes_chapter->item(0)->getAttribute('href');
696 696
 					$chapterURLSegments = explode('/', preg_replace('/\?.*$/', '', $link));
697
-					$titleData['latest_chapter'] = $chapterURLSegments[3] . ':--:' . preg_replace('/.*?([0-9]+)$/', '$1', $link);
698
-					$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest->item(0)->textContent));
697
+					$titleData['latest_chapter'] = $chapterURLSegments[3].':--:'.preg_replace('/.*?([0-9]+)$/', '$1', $link);
698
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest->item(0)->textContent));
699 699
 				}
700 700
 			} else {
701 701
 				//TODO: Throw ERRORS;
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 		         The bad thing is these are interchangeable, despite them showing the exact same listing page.
720 720
 		         Thankfully the title_url of manga which use /forums/ seem to be appended with ".%ID%" which means we can easily check them. */
721 721
 
722
-		if (strpos($title_url, '.') !== FALSE) {
722
+		if(strpos($title_url, '.') !== FALSE) {
723 723
 			$format = "https://gameofscanlation.moe/forums/{$title_url}/";
724 724
 		} else {
725 725
 			$format = "https://gameofscanlation.moe/projects/{$title_url}/";
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 
756 756
 			$titleData['latest_chapter'] = preg_replace('/^projects\/.*?\/(.*?)\/$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
757 757
 
758
-			$titleData['last_updated'] =  date("Y-m-d H:i:s",(int) $data['nodes_latest']->getAttribute('title'));
758
+			$titleData['last_updated'] = date("Y-m-d H:i:s", (int) $data['nodes_latest']->getAttribute('title'));
759 759
 		}
760 760
 
761 761
 		return (!empty($titleData) ? $titleData : NULL);
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 
801 801
 			$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)\/$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
802 802
 
803
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) substr($data['nodes_latest']->getAttribute('title'), 13)));
803
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) substr($data['nodes_latest']->getAttribute('title'), 13)));
804 804
 		}
805 805
 
806 806
 		return (!empty($titleData) ? $titleData : NULL);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 		$chapter_parts = explode('/', $chapter);
822 822
 		return [
823 823
 			'url'    => "https://reader.kireicake.com/read/{$title_url}/{$chapter}/",
824
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
824
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
825 825
 		];
826 826
 	}
827 827
 
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 		$chapter_parts = explode('/', $chapter);
846 846
 		return [
847 847
 			'url'    => "https://reader.seaotterscans.com/read/{$title_url}/{$chapter}/",
848
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
848
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
849 849
 		];
850 850
 	}
851 851
 
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 		$chapter_parts = explode('/', $chapter);
870 870
 		return [
871 871
 			'url'    => "http://helveticascans.com/reader/read/{$title_url}/{$chapter}/",
872
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
872
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
873 873
 		];
874 874
 	}
875 875
 
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 		$chapter_parts = explode('/', $chapter);
894 894
 		return [
895 895
 			'url'    => "http://reader.sensescans.com/read/{$title_url}/{$chapter}/",
896
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
896
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
897 897
 		];
898 898
 	}
899 899
 
Please login to merge, or discard this patch.