| | <?php |
| |
|
| | if (!defined('ABSPATH')) { |
| | exit; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | class UMS_Madara_Fetcher { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static function get_manga_data($page = 0, $query = '', $type = '') { |
| | |
| | $url = get_option('manga_fetch_url', 'https://manhuaus.com/wp-admin/admin-ajax.php'); |
| |
|
| | |
| | $vars = [ |
| | 's' => $query, |
| | 'orderby' => 'meta_value_num', |
| | 'paged' => $page, |
| | 'template' => 'search', |
| | 'meta_query' => [ |
| | [ |
| | 'relation' => 'AND' |
| | ] |
| | ], |
| | 'post_type' => 'wp-manga', |
| | 'post_status' => 'publish', |
| | 'meta_key' => '_latest_update', |
| | 'order' => 'desc', |
| | 'manga_archives_item_layout' => 'big_thumbnail' |
| | ]; |
| |
|
| | |
| | switch ($type) { |
| | case 'new': |
| | $vars['orderby'] = 'date'; |
| | break; |
| | case 'latest': |
| | $vars['orderby'] = 'meta_value_num'; |
| | $vars['meta_key'] = '_latest_update'; |
| | $vars['order'] = 'desc'; |
| | break; |
| | case 'trending': |
| | $vars['orderby'] = 'meta_value_num'; |
| | $vars['meta_key'] = '_wp_manga_week_views_value'; |
| | $vars['order'] = 'desc'; |
| | break; |
| | case 'most_viewed': |
| | $vars['orderby'] = 'meta_value_num'; |
| | $vars['meta_key'] = '_wp_manga_views'; |
| | $vars['order'] = 'desc'; |
| | break; |
| | case 'rating': |
| | $vars['orderby'] = [ |
| | ['query_avarage_reviews' => 'DESC'], |
| | ['query_total_reviews' => 'DESC'] |
| | ]; |
| | $vars['meta_query'][] = [ |
| | 'query_avarage_reviews' => [ |
| | 'key' => '_manga_avarage_reviews' |
| | ], |
| | 'query_total_reviews' => [ |
| | 'key' => '_manga_total_votes' |
| | ] |
| | ]; |
| | break; |
| | case 'a_z': |
| | $vars['orderby'] = 'post_title'; |
| | $vars['order'] = 'ASC'; |
| | break; |
| | case 'relevance': |
| | |
| | break; |
| | } |
| |
|
| | |
| | $args = [ |
| | 'sslverify' => false, |
| | 'body' => [ |
| | 'action' => 'madara_load_more', |
| | 'page' => $page, |
| | 'template' => 'madara-core/content/content-search', |
| | 'vars' => $vars |
| | ] |
| | ]; |
| |
|
| | |
| | $response = wp_remote_post($url, $args); |
| |
|
| | |
| | if (is_wp_error($response)) { |
| | return ['error' => $response->get_error_message()]; |
| | } |
| |
|
| | |
| | $html = wp_remote_retrieve_body($response); |
| | $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
| | if(empty($html)) |
| | { |
| | return ['error' => 'Empty response from the server']; |
| | } |
| | |
| | libxml_use_internal_errors(true); |
| | $dom = new DOMDocument(); |
| | $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); |
| | libxml_clear_errors(); |
| |
|
| | |
| | $xpath = new DOMXPath($dom); |
| | $manga_items = $xpath->query('//div[contains(@class, "c-tabs-item__content")]'); |
| | $manga_list = []; |
| |
|
| | |
| | foreach ($manga_items as $item) { |
| | $title = $xpath->query('.//div[@class="post-title"]/h3[@class="h4"]/a', $item)->item(0)->nodeValue; |
| | $cover_image = $xpath->query('.//div[@class="tab-thumb c-image-hover"]/a/img', $item)->item(0)->getAttribute('data-src'); |
| | $description = ''; |
| | $genres = []; |
| | $status = ''; |
| | |
| | $index = 0; |
| | $summary_headings = $xpath->query('.//div[@class="summary-heading"]/h5', $item); |
| |
|
| | |
| | foreach ($summary_headings as $heading) { |
| | $heading_text = trim($heading->nodeValue); |
| | if ($heading_text === 'Alternative') { |
| | $description = $xpath->query('.//div[@class="summary-content"]', $item)->item($index)->nodeValue; |
| | $index++; |
| | } elseif ($heading_text === 'Authors' || $heading_text === 'Artists') { |
| | $index++; |
| | } elseif ($heading_text === 'Genres') { |
| | $genres = []; |
| | $genre_elements = $xpath->query('.//div[@class="summary-content"]', $item)->item($index)->getElementsByTagName('a'); |
| | foreach ($genre_elements as $genre) { |
| | $genres[] = $genre->nodeValue; |
| | } |
| | $index++; |
| | } elseif ($heading_text === 'Status') { |
| | $status = $xpath->query('.//div[@class="summary-content"]', $item)->item($index)->nodeValue; |
| | $index++; |
| | } |
| | } |
| |
|
| | |
| | if($last_updated = $xpath->query('.//div[@class="meta-item post-on"]/span[@class="font-meta"]', $item)->item(0)) |
| | { |
| | $last_updated = $xpath->query('.//div[@class="meta-item post-on"]/span[@class="font-meta"]', $item)->item(0)->nodeValue; |
| | } |
| | else |
| | { |
| | $last_updated = ''; |
| | } |
| | if($xpath->query('.//div[@class="meta-item latest-chap"]/span[@class="font-meta chapter"]/a', $item)->item(0)) |
| | { |
| | $latest_chapter = $xpath->query('.//div[@class="meta-item latest-chap"]/span[@class="font-meta chapter"]/a', $item)->item(0)->nodeValue; |
| | } |
| | else |
| | { |
| | $latest_chapter = ''; |
| | } |
| | if($xpath->query('.//div[@class="post-title"]/h3[@class="h4"]/a', $item)->item(0)) |
| | { |
| | $url = $xpath->query('.//div[@class="post-title"]/h3[@class="h4"]/a', $item)->item(0)->getAttribute('href'); |
| | } |
| | else |
| | { |
| | $url = ''; |
| | } |
| |
|
| | |
| | $manga_list[] = [ |
| | 'title' => $title, |
| | 'url' => $url, |
| | 'cover_image' => $cover_image, |
| | 'description' => trim($description), |
| | 'genres' => implode(', ', $genres), |
| | 'status' => trim($status), |
| | 'last_updated' => trim($last_updated), |
| | 'latest_chapter' => $latest_chapter, |
| | ]; |
| | } |
| |
|
| | |
| | if (empty($manga_list)) { |
| | return ['error' => 'No manga found on the provided URL.']; |
| | } |
| |
|
| | |
| | return $manga_list; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public static function get_manga_details($url) { |
| | |
| | $response = wp_remote_get($url, ['sslverify' => false]); |
| |
|
| | |
| | if (is_wp_error($response)) { |
| | return ['error' => $response->get_error_message()]; |
| | } |
| |
|
| | |
| | $html = wp_remote_retrieve_body($response); |
| | $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
| |
|
| | |
| | libxml_use_internal_errors(true); |
| | $dom = new DOMDocument(); |
| | $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); |
| | libxml_clear_errors(); |
| |
|
| | |
| | $xpath = new DOMXPath($dom); |
| |
|
| | |
| | $title = $xpath->query('//h1[@class="title"]')->item(0)->nodeValue; |
| | $cover_image = $xpath->query('//div[@class="thumb"]/img')->item(0)->getAttribute('src'); |
| | $description = $xpath->query('//div[@class="description-summary"]/div[@class="summary__content show-more"]')->item(0)->nodeValue; |
| | $genres = []; |
| | $genre_elements = $xpath->query('//div[@class="genres-content"]/a'); |
| | foreach ($genre_elements as $genre) { |
| | $genres[] = $genre->nodeValue; |
| | } |
| | $status = $xpath->query('//div[@class="post-status"]/div[@class="summary-content"]/a')->item(0)->nodeValue; |
| |
|
| | |
| | return [ |
| | 'title' => trim($title), |
| | 'cover_image' => $cover_image, |
| | 'description' => trim($description), |
| | 'genres' => implode(', ', $genres), |
| | 'status' => trim($status) |
| | ]; |
| | } |
| | } |