<?php 
 
@ini_set('user_agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');   
@ini_set('user_agent', 'My-Application/2.5'); 

if (!function_exists('get_linkz1')) {
	function get_linkz1($url){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
		$ip = rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
		curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
		//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1");
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
		//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0");
		curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
		curl_setopt($ch, CURLOPT_AUTOREFERER, true);
		$html = curl_exec($ch);
		curl_close($ch);
		return $html;
	}
}

if (!function_exists('file_get_contents_curl1')) {
	function file_get_contents_curl1($url, $retries=5){
		$ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36';

		if (extension_loaded('curl') === true) {
			$ch = curl_init();

			curl_setopt($ch, CURLOPT_URL, $url); // The URL to fetch. This can also be set when initializing a session with curl_init().
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // The number of seconds to wait while trying to connect.
			curl_setopt($ch, CURLOPT_USERAGENT, $ua); // The contents of the "User-Agent: " header to be used in a HTTP request.
			curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // To fail silently if the HTTP code returned is greater than or equal to 400.
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // To follow any "Location: " header that the server sends as part of the HTTP header.
			curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); // To automatically set the Referer: field in requests where it follows a Location: redirect.
			curl_setopt($ch, CURLOPT_TIMEOUT, 10); // The maximum number of seconds to allow cURL functions to execute.
			curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // The maximum number of redirects

			$result = curl_exec($ch);

			curl_close($ch);
		} else {
			$result = @file_get_contents($url);
		} if (empty($result) === true) {
			$result = false;

			if ($retries >= 1) {
				sleep(1);
				return file_get_contents_curl1($url, --$retries);
			}
		}    

		return $result;
	}
}

if (!function_exists('match_all')) {
	function match_all($regex, $str, $i = 0){
		if(preg_match_all($regex, $str, $matches) === false)
			return false;
		else
			return $matches[$i];
	}
}

if (!function_exists('matchx')) {
	function matchx($regex, $str, $i = 0){
		if(preg_match($regex, $str, $match) == 1)
			return $match[$i];
		else
			return false;
	}
}
 
global $opt_themes;
@ini_set('user_agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');   
@ini_set('user_agent', 'My-Application/2.5'); 

$actual_link 	= (empty($_SERVER['HTTPS']) ? 'http' : 'https')."://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 

if ( ($_GET['pkgid']!="")){
		
	//$language1	= $opt_themes['apk_language'];  
	//$language		= 'en-US';  
	//$post_id		= $_GET['post_id'];  
	//$language		= $_GET['pkglang']; 
	 
	$language		= 'en-US';  
	$pkgid 			= $_GET['pkgid']; 
	$gp				= "https://play.google.com/store/apps/details?id=".$pkgid."&hl=".$language;
	$gp_en_usa		= "https://play.google.com/store/apps/details?id=".$pkgid."&hl=en-US"; 
	$url 			= (empty($_SERVER['HTTPS']) ? 'http' : 'https').'://'.$_SERVER['HTTP_HOST'].'/gps/?pkgid='.$pkgid; 
	$url2 			= 'https://apks.exthem.es/gps/?pkgid='.$pkgid; 
	$url3 			= 'https://apks.exthem.es/?pkgid='.$pkgid; 
	$url4			= (empty($_SERVER['HTTPS']) ? 'http' : 'https').'//apks.exthem.es/?pkgid='.$pkgid; 

	$get_infos		= @get_linkz1($gp);  
	$g_data			= @file_get_contents($url3);
	//$g_data2		= @file_get_contents($url);
	//$g_data3		= @file_get_contents_curl1($url2);
	 
	$apk_name		= matchx('/<h1><span.*?itemprop="name">(.*?)<\/span><\/h1>/ms', $get_infos, 1);  
	$new_youtube2	= matchx('/<video.*?poster="https:\/\/i.ytimg.com\/vi\/(.*?)\/hqdefault.jpg".*?>/', $get_infos, 1); 
	$appname		= matchx('/<div class="appname">(.*?)<\/div>/ms', $g_data, 1);  
	$new_version	= matchx('/<div class="version">(.*?)<\/div>/ms', $g_data, 1);  
	$new_size		= matchx('/<div class="size">(.*?)<\/div>/ms', $g_data, 1);  
	$new_youtube	= matchx('/<div class="youtube">(.*?)<\/div>/ms', $g_data, 1);  
	$new_desck_GP	= matchx('/<div class="description">(.*?)<\/div>/ms', $g_data, 1);  
	$idgps			= matchx('/<div class="pkgids">(.*?)<\/div>/ms', $g_data, 1);  
	$linkgps		= matchx('/<div class="url_ps">(.*?)<\/div>/ms', $g_data, 1);  
	$developer		= matchx('/<div class="developer">(.*?)<\/div>/ms', $g_data, 1);  
	$content		= matchx('/<div class="bARER".*?>(.*?)<\/div>.*?<div class="TKjAsc">/ms', $get_infos, 1);
	$content2		= matchx('/<div class="content">(.*?)<\/div>/ms', $g_data, 1);   
	$description	= matchx('/<div class="description">(.*?)<\/div>/ms', $g_data, 1);  
	$whatsnew		= matchx('/<div class="whatsnew">(.*?)<\/div>/ms', $g_data, 1);  
	$os				= matchx('/<div class="os">(.*?)<\/div>/ms', $g_data, 1);  
	$update			= matchx('/<div class="update">(.*?)<\/div>/ms', $g_data, 1);  
	$rate			= matchx('/<div class="rate">(.*?)<\/div>/ms', $g_data, 1);  
	$vote			= matchx('/<div class="vote">(.*?)<\/div>/ms', $g_data, 1);  
	$poster			= matchx('/<div class="poster">(.*?)<\/div>/ms', $g_data, 1);  
	$background		= matchx('/<div class="background">(.*?)<\/div>/ms', $g_data, 1);  
	$category		= matchx('/<div class="category">(.*?)<\/div>/ms', $g_data, 1);  
	$developer		= matchx('/<div class="developer">(.*?)<\/div>/ms', $g_data, 1);  
	$images_GP		= match_all('/<img.*?src="(.*?)".*?>/ms', matchx('/<div id="gallery">(.*?)<\/div>/ms', $g_data, 1), 1);
	$images_GP2		= match_all('/<img.*?src=(.*?)width.*?>/ms', matchx('/<div id="gallery">(.*?)<\/div>/ms', $g_data, 1), 1); 
	$tag			= matchx('/<div class="tag">(.*?)<\/div>/ms', $g_data, 1);  

	$json['pkgid'] = $idgps;
	$json['linkgps'] = $linkgps;
	$json['name'] = $appname;
	$json['versi'] = $new_version;
	$json['size'] = $new_size;
	$json['developer'] = $developer;
	$json['content'] = $content;
	$json['description'] = $description;
	$json['whatsnew'] = $whatsnew;
	$json['os'] = $os;
	$json['category'] = $category; 
	$json['update'] = $update;
	$json['youtube'] = $new_youtube;
	$json['rate'] = $rate;
	$json['vote'] = $vote;
	$json['poster'] = $poster;
	$json['background'] = $background;
	$json['images_GP'] = $images_GP;
	$json['images_GP2'] = $images_GP2; 
	$json['tag'] = $appname.', '.$tag;
	 
	echo json_encode($json);
}  