Completed
Push — master ( a4295f...ead2e4 )
by Angus
03:30
created
application/models/Site_Model.php 3 patches
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
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			$nodes_row   = $xpath->query($node_row_string);
109 109
 			if($nodes_title->length === 1 && $nodes_row->length === 1) {
110 110
 				$firstRow      = $nodes_row->item(0);
111
-				$nodes_latest  = $xpath->query($node_latest_string,  $firstRow);
111
+				$nodes_latest  = $xpath->query($node_latest_string, $firstRow);
112 112
 				$nodes_chapter = $xpath->query($node_chapter_string, $firstRow);
113 113
 
114 114
 				if($nodes_latest->length === 1 && $nodes_chapter->length === 1) {
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 
232 232
 			$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
233 233
 			$chapterURLSegments = explode('/', $link);
234
-			$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
235
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
234
+			$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
235
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
236 236
 		}
237 237
 
238 238
 		return (!empty($titleData) ? $titleData : NULL);
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 
277 277
 			$link = preg_replace('/^(.*\/)(?:[0-9]+\.html)?$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
278 278
 			$chapterURLSegments = explode('/', $link);
279
-			$titleData['latest_chapter'] = $chapterURLSegments[5] . (isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
280
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
279
+			$titleData['latest_chapter'] = $chapterURLSegments[5].(isset($chapterURLSegments[6]) && !empty($chapterURLSegments[6]) ? "/{$chapterURLSegments[6]}" : "");
280
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
281 281
 		}
282 282
 
283 283
 		return (!empty($titleData) ? $titleData : NULL);
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 
309 309
 		$chapter_parts = explode(':--:', $chapter);
310 310
 		return [
311
-			'url'    => "http://bato.to/reader#" . $chapter_parts[0],
311
+			'url'    => "http://bato.to/reader#".$chapter_parts[0],
312 312
 			'number' => $chapter_parts[1]
313 313
 		];
314 314
 	}
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
 
345 345
 			///^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)(?:\s?-\s?(?<extra>[0-9]+))?):?.*/
346 346
 			preg_match('/^(?:Vol\.(?<volume>\S+) )?(?:Ch.(?<chapter>[^\s:]+)(?:\s?-\s?(?<extra>[0-9]+))?):?.*/', trim($data['nodes_chapter']->nodeValue), $text);
347
-			$titleData['latest_chapter'] = substr($data['nodes_chapter']->getAttribute('href'), 22) . ':--:' . ((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '') . 'c'.$text['chapter'] . (!empty($text['extra']) ? '-'.$text['extra'] : ''));
347
+			$titleData['latest_chapter'] = substr($data['nodes_chapter']->getAttribute('href'), 22).':--:'.((!empty($text['volume']) ? 'v'.$text['volume'].'/' : '').'c'.$text['chapter'].(!empty($text['extra']) ? '-'.$text['extra'] : ''));
348 348
 
349 349
 			$dateString = $data['nodes_latest']->nodeValue;
350 350
 			if($dateString == 'An hour ago') {
351 351
 				$dateString = '1 hour ago';
352 352
 			}
353
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
353
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
354 354
 		}
355 355
 
356 356
 		return (!empty($titleData) ? $titleData : NULL);
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 		*/
390 390
 
391 391
 		$chapterData = [
392
-			'url'    => 'http://dynasty-scans.com/chapters/' . $title_parts[0].'_'.$chapter,
392
+			'url'    => 'http://dynasty-scans.com/chapters/'.$title_parts[0].'_'.$chapter,
393 393
 			'number' => ''
394 394
 		];
395 395
 
@@ -430,14 +430,14 @@  discard block
 block discarded – undo
430 430
 
431 431
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
432 432
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
433
-			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '') . substr($matchesT[0], 3, -4);
433
+			$titleData['title'] = (!empty($matchesD) ? (substr($matchesD[1], 0, -7) !== 'Original' ? substr($matchesD[1], 0, -7).' - ' : '') : '').substr($matchesT[0], 3, -4);
434 434
 
435 435
 			$data = preg_replace('/^[\S\s]*(<dl class=\'chapter-list\'>[\S\s]*<\/dl>)[\S\s]*$/', '$1', $data);
436 436
 			preg_match_all('/<dd>[\s\S]+?(?=<\/dd>)<\/dd>/', $data, $matches);
437 437
 			$latest_chapter_html = array_pop($matches[0]);
438 438
 
439 439
 			preg_match('/\/chapters\/([^"]+)/', $latest_chapter_html, $matches);
440
-			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url)+1);
440
+			$titleData['latest_chapter'] = substr($matches[1], strlen($title_url) + 1);
441 441
 			//FIXME: THIS IS A TEMP FIX, SEE https://github.com/DakuTree/manga-tracker/issues/58
442 442
 			if(!$titleData['latest_chapter']) {
443 443
 				log_message('error', 'DynastyScans::getTitleData cannot parse title properly as it contains oneshot. || URL: '.$title_url);
@@ -445,14 +445,14 @@  discard block
 block discarded – undo
445 445
 			}
446 446
 
447 447
 			preg_match('/<small>released (.*)<\/small>/', $latest_chapter_html, $matches);
448
-			$titleData['last_updated']   = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
448
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime(str_replace('\'', '', $matches[1])));
449 449
 		} elseif($title_parts[1] == '1') {
450 450
 			$content = $this->get_content('http://dynasty-scans.com/chapters/'.$title_url);
451 451
 			$data = $content['body'];
452 452
 
453 453
 			preg_match('/<b>.*<\/b>/', $data, $matchesT);
454 454
 			preg_match('/\/doujins\/[^"]+">(.+)?(?=<\/a>)<\/a>/', $data, $matchesD);
455
-			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '') . substr($matchesT[0], 3, -4);
455
+			$titleData['title'] = (!empty($matchesD) ? ($matchesD[1] !== 'Original' ? $matchesD[1].' - ' : '') : '').substr($matchesT[0], 3, -4);
456 456
 
457 457
 			$titleData['latest_chapter'] = 'oneshot'; //This will never change
458 458
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 
507 507
 			$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
508 508
 
509
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
509
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
510 510
 		}
511 511
 
512 512
 		return (!empty($titleData) ? $titleData : NULL);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 
551 551
 			$titleData['latest_chapter'] = preg_replace('/^.*\/(.*?\/[0-9]+)\/[0-9]+$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
552 552
 
553
-			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
553
+			$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->nodeValue));
554 554
 		}
555 555
 
556 556
 		return (!empty($titleData) ? $titleData : NULL);
@@ -606,8 +606,8 @@  discard block
 block discarded – undo
606 606
 				$titleData['title'] = trim((string) $xml->{'channel'}->title);
607 607
 
608 608
 				$chapterURLSegments = explode('/', ((string) $xml->{'channel'}->item[0]->link));
609
-				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]) . ':--:' . $chapterURLSegments[6];
610
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $xml->{'channel'}->item[0]->pubDate));
609
+				$titleData['latest_chapter'] = preg_replace('/^.*?([0-9]+)$/', '$1', $chapterURLSegments[7]).':--:'.$chapterURLSegments[6];
610
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $xml->{'channel'}->item[0]->pubDate));
611 611
 			}
612 612
 		} else {
613 613
 			log_message('error', "Series missing? (WebToons): {$title_url}");
@@ -678,13 +678,13 @@  discard block
 block discarded – undo
678 678
 					$titleData['title'] = $nodes_title->item(0)->textContent;
679 679
 
680 680
 					$firstRow      = $nodes_row->item(0);
681
-					$nodes_latest  = $xpath->query("td[2]",   $firstRow);
681
+					$nodes_latest  = $xpath->query("td[2]", $firstRow);
682 682
 					$nodes_chapter = $xpath->query("td[1]/a", $firstRow);
683 683
 
684 684
 					$link = (string) $nodes_chapter->item(0)->getAttribute('href');
685 685
 					$chapterURLSegments = explode('/', preg_replace('/\?.*$/', '', $link));
686
-					$titleData['latest_chapter'] = $chapterURLSegments[3] . ':--:' . preg_replace('/.*?([0-9]+)$/', '$1', $link);
687
-					$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) $nodes_latest->item(0)->textContent));
686
+					$titleData['latest_chapter'] = $chapterURLSegments[3].':--:'.preg_replace('/.*?([0-9]+)$/', '$1', $link);
687
+					$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $nodes_latest->item(0)->textContent));
688 688
 				}
689 689
 			} else {
690 690
 				//TODO: Throw ERRORS;
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 		$chapter_parts = explode('/', $chapter);
713 713
 		return [
714 714
 			'url'    => "https://reader.kireicake.com/read/{$title_url}/{$chapter}/",
715
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
715
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
716 716
 		];
717 717
 	}
718 718
 
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 
763 763
 				$firstRow      = $nodes_row->item(0);
764 764
 				$nodes_latest  = $xpath->query("p[@class='author']/span|p[@class='author']/abbr", $firstRow);
765
-				$nodes_chapter = $xpath->query("p[@class='text_work']/a",                         $firstRow);
765
+				$nodes_chapter = $xpath->query("p[@class='text_work']/a", $firstRow);
766 766
 
767 767
 				$link = (string) $nodes_chapter->item(0)->getAttribute('href');
768 768
 				$titleData['latest_chapter'] = preg_replace('/^projects\/.*?\/(.*?)\/$/', '$1', $link);
769
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", (int) $nodes_latest->item(0)->getAttribute('data-time'));
769
+				$titleData['last_updated'] = date("Y-m-d H:i:s", (int) $nodes_latest->item(0)->getAttribute('data-time'));
770 770
 			} else {
771 771
 				log_message('error', "GameOfScanlation: Unable to find nodes.");
772 772
 				return NULL;
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 
821 821
 				$link = (string) $nodes_chapter->item(0)->getAttribute('href');
822 822
 				$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9]+)\/$/', '$1', $link);
823
-				$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) substr($nodes_latest->item(0)->getAttribute('title'), 13)));
823
+				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) substr($nodes_latest->item(0)->getAttribute('title'), 13)));
824 824
 			} else {
825 825
 				log_message('error', "MangaCow: Unable to find nodes.");
826 826
 				return NULL;
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 		$chapter_parts = explode('/', $chapter);
848 848
 		return [
849 849
 			'url'    => "https://reader.seaotterscans.com/read/{$title_url}/{$chapter}/",
850
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
850
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
851 851
 		];
852 852
 	}
853 853
 
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 		$chapter_parts = explode('/', $chapter);
872 872
 		return [
873 873
 			'url'    => "http://helveticascans.com/reader/read/{$title_url}/{$chapter}/",
874
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
874
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
875 875
 		];
876 876
 	}
877 877
 
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 		$chapter_parts = explode('/', $chapter);
896 896
 		return [
897 897
 			'url'    => "http://reader.sensescans.com/read/{$title_url}/{$chapter}/",
898
-			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
898
+			'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/
899 899
 		];
900 900
 	}
901 901
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,12 +20,16 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function isValidTitleURL(string $title_url, string $regex) : bool {
22 22
 		$success = (bool) preg_match($regex, $title_url);
23
-		if(!$success) log_message('error', "Invalid Title URL ({$this->site}): {$title_url}");
23
+		if(!$success) {
24
+			log_message('error', "Invalid Title URL ({$this->site}): {$title_url}");
25
+		}
24 26
 		return $success;
25 27
 	}
26 28
 	public function isValidChapter(string $chapter, string $regex) : bool {
27 29
 		$success = (bool) preg_match($regex, $chapter);
28
-		if(!$success) log_message('error', "Invalid Chapter ({$this->site}): {$chapter}");
30
+		if(!$success) {
31
+			log_message('error', "Invalid Chapter ({$this->site}): {$chapter}");
32
+		}
29 33
 		return $success;
30 34
 	}
31 35
 
@@ -36,10 +40,16 @@  discard block
 block discarded – undo
36 40
 		//curl_setopt($ch, CURLOPT_VERBOSE, 1);
37 41
 		curl_setopt($ch, CURLOPT_HEADER, 1);
38 42
 
39
-		if($follow_redirect)        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
43
+		if($follow_redirect) {
44
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
45
+		}
40 46
 
41
-		if(!empty($cookie_string))  curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
42
-		if(!empty($cookiejar_path)) curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar_path);
47
+		if(!empty($cookie_string)) {
48
+			curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
49
+		}
50
+		if(!empty($cookiejar_path)) {
51
+			curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar_path);
52
+		}
43 53
 
44 54
 		//Some sites check the useragent for stuff, use a pre-defined user-agent to avoid stuff.
45 55
 		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2824.0 Safari/537.36');
@@ -600,7 +610,8 @@  discard block
 block discarded – undo
600 610
 
601 611
 		$content = $this->get_content($fullURL);
602 612
 		$data = $content['body'];
603
-		if($data !== 'Can\'t find the manga series.') { //FIXME: We should check for he proper error here.
613
+		if($data !== 'Can\'t find the manga series.') {
614
+//FIXME: We should check for he proper error here.
604 615
 			$xml = simplexml_load_string($data) or die("Error: Cannot create object");
605 616
 			if(isset($xml->{'channel'}->item[0])) {
606 617
 				$titleData['title'] = trim((string) $xml->{'channel'}->title);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +7 added lines, -7 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          = '';
@@ -666,9 +666,9 @@  discard block
 block discarded – undo
666 666
 				$data = preg_replace('/^[\S\s]*(<div id="leftside">[\S\s]*)<div id="rightside">[\S\s]*$/', '$1', $data);
667 667
 
668 668
 				$dom = new DOMDocument();
669
-				libxml_use_internal_errors(true);
669
+				libxml_use_internal_errors(TRUE);
670 670
 				$dom->loadHTML($data);
671
-				libxml_use_internal_errors(false);
671
+				libxml_use_internal_errors(FALSE);
672 672
 
673 673
 				$xpath = new DOMXPath($dom);
674 674
 
@@ -749,9 +749,9 @@  discard block
 block discarded – undo
749 749
 			//$data = preg_replace('/^[\S\s]*(<ol[\S\s]*)<\/ol>[\S\s]*$/', '$1', $data);
750 750
 
751 751
 			$dom = new DOMDocument();
752
-			libxml_use_internal_errors(true);
752
+			libxml_use_internal_errors(TRUE);
753 753
 			$dom->loadHTML($data);
754
-			libxml_use_internal_errors(false);
754
+			libxml_use_internal_errors(FALSE);
755 755
 
756 756
 			$xpath = new DOMXPath($dom);
757 757
 
@@ -804,9 +804,9 @@  discard block
 block discarded – undo
804 804
 		$data = $content['body'];
805 805
 		if(strpos($data, '404 Page Not Found') === FALSE) {
806 806
 			$dom = new DOMDocument();
807
-			libxml_use_internal_errors(true);
807
+			libxml_use_internal_errors(TRUE);
808 808
 			$dom->loadHTML($data);
809
-			libxml_use_internal_errors(false);
809
+			libxml_use_internal_errors(FALSE);
810 810
 
811 811
 			$xpath = new DOMXPath($dom);
812 812
 
Please login to merge, or discard this patch.