<?php /** @noinspection ALL */
use Symfony\Component\DomCrawler\Crawler;
class mangatoku
{
public $app;
public $options;
function __construct()
{
$this->app = new setup();
$this->options = ['http' => ['method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" . "Referer: https://mangatoku.com/\r\n"]];
}
function DSTruyen($page, $type = 'TruyenMoi')
{
$url = 'https://mangatoku.com/page/' . $page;
$html = $this->ajax_list($page);
$crawler = new Crawler($html);
$data = $crawler->filter('.item-thumb a')->each(function (Crawler $node) {
$data['name'] = trim($node->attr('title'));
$data['url'] = trim($node->attr('href'));
return $data;
});
return $data;
}
function ThongTinTruyen($url)
{
// $url = "https://hentai20.io/manga/just-once-raw/";
$html = getContent($url, $this->options);
$crawler = new Crawler($html);
if ($manga = $crawler->filter('.site-content')) {
$outerHtml = $manga->outerHtml();
} else {
die('Có lỗi khi lấy dữ liệu!');
}
$data['name'] = $manga->filter('.post-title h1')->text();
$data["name"] = str_replace("HOT ", "", $data['name']);
$data["name"] = str_replace("NEW ", "", $data['name']);
$data['other_name'] = remove_html(explode_by("Alternative </h5>\n</div>", '</div>', $outerHtml));
$data['cover'] = $crawler->filter('meta[property="og:image"]')->attr('content');
$data['description'] = $crawler->filter('.summary__content.show-more')->count() > 0 ? $crawler->filter('.summary__content.show-more')->text() : "";
$data['authors'] = remove_html(explode_by("Author(s) </h5>\n</div>", '</div>', $outerHtml));
$data['authors'] = $data['authors'] !== "Updating" ? $data['authors'] : NULL;
$data['status'] = remove_html(explode_by("Status </h5>\n</div>", '</div>', $outerHtml));
$data['status'] = trim($data['status']) === 'OnGoing' ? 0 : 2;
$data['list_categories'] = $manga->filter('.genres-content a')->each(function ($node) {
return $node->text();
});
$manga_id = $manga->filter('.rating-post-id')->attr('value');
$chapter_list = $crawler->filter('.listing-chapters_wrap');
if ($chapter_list->count() > 0) {
$data['list_chapter'] = $chapter_list->filter('ul li')->each(function (Crawler $node, $i) {
$node = $node->filter('a')->eq(0);
$data['name'] = $node->text();
if (preg_match('#(chapter|chương|chap)(.[\d.]+)#is', $data['name'], $name) && !empty($name[0])) {
$data['name'] = $name[0];
}
$data['url'] = trim($node->attr('href'));
return $data;
});
$data['list_chapter'] = array_reverse($data['list_chapter']);
}
return $data;
}
function ThongTinChuong($url, $proxy = true)
{
$html = getContent($url, $this->options);
$crawler = new Crawler($html);
$response['server1'] = $crawler->filter(".reading-content .page-break img")->each(function ($node) {
return $node->attr('src');
});
if ($proxy) {
foreach ($response['server1'] as $key => $img) {
$response['server1'][$key] = $this->AddProxy($img);
}
}
$response['referrer'] = 'https://mangatoku.com/';
$response['info'] = $crawler->filter('title')->text();
return $response;
}
function AddProxy($url)
{
$url = trim($url);
$domain = parse_url($url, PHP_URL_HOST);
$url = str_replace($domain, "$domain", $url);
return $url;
}
function ajax_list($page)
{
$url = "https://mangatoku.com/wp-admin/admin-ajax.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array("Content-Type: application/x-www-form-urlencoded",);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = "action=madara_load_more&page=$page&template=madara-core%2Fcontent%2Fcontent-archive&vars%5Borderby%5D=meta_value_num&vars%5Bpaged%5D=5&vars%5Bposts_per_page%5D=20&vars%5Btax_query%5D%5Brelation%5D=OR&vars%5Bmeta_query%5D%5B0%5D%5Brelation%5D=AND&vars%5Bmeta_query%5D%5Brelation%5D%3A%20OR=&vars%5Bpost_type%5D=wp-manga&vars%5Bpost_status%5D=publish&vars%5Bmeta_key%5D=_latest_update&vars%5Border%5D=desc&vars%5Bsidebar%5D=right&vars%5Bmanga_archives_item_layout%5D=default";
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
}