Completed
Push — master ( 40cff3...c302c1 )
by Angus
02:30
created

JaiminisBox::getTitleData()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 18
nc 6
nop 2
dl 0
loc 22
ccs 0
cts 18
cp 0
crap 20
rs 8.9197
c 0
b 0
f 0
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class JaiminisBox extends Base_FoolSlide_Site_Model {
4
	public $baseURL = 'https://jaiminisbox.com/reader';
5
6
	//NOTE: Jaimini's Box appears to have disabled API support for some reason. Fallback to using the old method.
7
	public function getTitleData(string $title_url, bool $firstGet = FALSE) : ?array {
8
		$fullURL = $this->getFullTitleURL($title_url);
9
		$titleData = [];
10
		if($content = $this->get_content($fullURL, "", "", FALSE, TRUE, ['adult' => 'true'])) {
11
			$content['body'] = preg_replace('/^[\S\s]*(<article[\S\s]*)<\/article>[\S\s]*$/', '$1', $content['body']);
12
			$data = $this->parseTitleDataDOM(
13
				$content,
14
				$title_url,
15
				"//div[@class='large comic']/h1[@class='title']",
16
				"(//div[@class='list']/div[@class='group']/div[@class='title' and text() = 'Chapters']/following-sibling::div[@class='element'][1] | //div[@class='list']/div[@class='element'][1] | //div[@class='list']/div[@class='group'][1]/div[@class='element'][1])[1]",
17
				"div[@class='meta_r']",
18
				"div[@class='title']/a"
19
			);
20
			if($data) {
21
				$titleData['title'] = trim($data['nodes_title']->textContent);
22
				$link                        = (string) $data['nodes_chapter']->getAttribute('href');
23
				$titleData['latest_chapter'] = preg_replace('/.*\/read\/.*?\/(.*?)\/$/', '$1', $link);
24
				$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) str_replace('.', '', explode(',', $data['nodes_latest']->nodeValue)[1])));
25
			}
26
		}
27
		return (!empty($titleData) ? $titleData : NULL);
28
	}
29
	public function doCustomUpdate() {}
30
}
31