<?php 
if ( ! defined( 'ABSPATH' ) ) exit;

if (!function_exists('file_get_contents_curl')) {
function file_get_contents_curl($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_curl($url, --$retries);
        }
    }    

    return $result;
}
}

if (!function_exists('get_linkz')) {
function get_linkz($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('scrape_site')) {
function scrape_site($url, $ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', $referer = 'http://www.google.com/') {
  if (function_exists('curl_exec')) {
	$header[0] 	= "Accept-Language: en-us,en;q=0.5";
	$agent 		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';
	$agent2		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';
	$agent3		= 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)';
	$agent4		= 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148';
	$agent5		= 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36';
	$agent6		= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36';
	$referer 	= 'http://www.google.com/';
	$ip 		= rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
	$ips 		= '51.68.87.157:49320';
		
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');   
	curl_setopt($ch, CURLOPT_USERAGENT, $agent);
	curl_setopt($ch, CURLOPT_REFERER, $referer);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	//curl_setopt($ch, CURLOPT_TIMEOUT, 10);	
	curl_setopt($ch, CURLOPT_HEADER, false); 
	curl_setopt($ch, CURLOPT_HTTPHEADER, ["REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"]);
	
    $html = curl_exec($ch);
    curl_close($ch);
  } else { 
    //$html = file_get_contents($url);
    $html = file_get_contents($url);
  }
  return $html;
}
}

if (!function_exists('zenrows')) {
function zenrows($url) {
	if (function_exists('curl_exec')) {
	global $opt_themes;
	$header[0] 	= "Accept-Language: en-us,en;q=0.5";
	$agent 		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';
	$agent2		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';
	$agent3		= 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)';
	$agent4		= 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148';
	$agent5		= 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36';
	$agent6		= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36';
	$referer 	= 'http://www.google.com/';
	$ip 		= rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
	$ips1 		= rand(0, 255).'.'.rand(0, 255).'.'.rand(0, 255).'.'.rand(0, 255);
	$ips 		= '51.68.87.157:49320';
	//$apikey2 	= '95f660f257e73a51ba192184dbea4e406dad619b';
	//$apikey 	= 'edc59b46f57e903008608201d4617ed06a1e152c';
	//$apikey3 	= 'cc754414a56f77aa004e412b8c1b310224629a3b';
	//$apikeys 	= '6756391d4b79b9d8a7b1f780';
	$apikey		= $opt_themes['api_zenrow'];  
	$ch 		= curl_init();
	curl_setopt($ch, CURLOPT_URL, 'https://api.zenrows.com/v1/?apikey='.$apikey.'&url='.$url);	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, false); 		
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');  
	//curl_setopt($ch, CURLOPT_URL, 'https://api.scrapingdog.com/scrape?api_key='.$apikeys.'&url='.$url);	
	//curl_setopt($ch, CURLOPT_URL, $url);
	//curl_setopt($ch, CURLOPT_USERAGENT, $agent5);
	//curl_setopt($ch, CURLOPT_REFERER, $referer);
	//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	//curl_setopt($ch, CURLOPT_TIMEOUT, 10);	
	$html 		= curl_exec($ch);
	curl_close($ch);
	} else { 
	$html 		= file_get_contents($url);
	}
	  return $html;
}
}


if (!function_exists('scraperapi')) {
function scraperapi($url){
	global $opt_themes;
	$apikey		= $opt_themes['api_zenrow']; 
	$country	= 'us'; 
	$url 		= "http://api.scraperapi.com?api_key=".$apikey."&url=".$url."&render=true&country_code=".$country;
	$ch 		= curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	$response 	= curl_exec($ch);
	curl_close($ch);
	return $response;
}
}

if (!function_exists('get_url')) {
function get_url($url){
		$agent 		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';
		$agent2		= 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';
		$agent3		= 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)';
		$referer 	= 'http://www.google.com/';
		$ip 		= rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
		$ch 		= curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
		curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
		curl_setopt($ch, CURLOPT_USERAGENT, $agent);
		curl_setopt($ch, CURLOPT_REFERER, $referer);
		curl_setopt($ch, CURLOPT_AUTOREFERER, true);
		$html 		= curl_exec($ch);
		curl_close($ch);
		return $html;
}
}


if (!function_exists('http_response')) {
function http_response($url) { 
	$ch			= curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $url); 
	curl_setopt($ch, CURLOPT_HEADER, TRUE); 
	curl_setopt($ch, CURLOPT_NOBODY, TRUE); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
	$head		= curl_exec($ch); 
	$httpCode	= curl_getinfo($ch, CURLINFO_HTTP_CODE); 
	curl_close($ch); 
	if(!$head){  
	return FALSE; 
	}
	return $httpCode;
	sleep(rand(1, 5));
}
}

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;
}
}

if (!function_exists('warna_rgbs')) {
function warna_rgbs($hex, $asString = true) {
	if (0 === strpos($hex, '#')) {
	$hex		= substr($hex, 1);
	} else if (0 === strpos($hex, '&H')) {
	$hex		= substr($hex, 2);
	}      
	$cutpoint	= ceil(strlen($hex) / 2)-1;
	$rgb		= explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
	$rgb[0]		= (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
	$rgb[1]		= (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
	$rgb[2]		= (isset($rgb[2]) ? hexdec($rgb[2]) : 0);
	return ($asString ? "rgba({$rgb[0]},{$rgb[1]},{$rgb[2]}, .8)" : $rgb);
} 
}

if (!function_exists('formatBytes')) {
function formatBytes($size, $precision = 2){
    $base 		= log($size, 1024);
    $suffixes 	= array('', 'KB', 'MB', 'GB', 'TB');   

    return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}
}

if (!function_exists('unicode_conv')) {
function unicode_conv($originalString) {
  // The four \\\\ in the pattern here are necessary to match \u in the original string
  $replacedString	= preg_replace("/\\\\u(\w{4})/", "&#$1;", $originalString);
  $unicodeString	= mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');
  return $unicodeString;
}
}
 
define('ex_themes_name_extractor_','Extractor APK');
define('ex_themes_version_extractor_','1.0');
define('spacescore','v');
define('BY', EXTHEMES_AUTHOR);
define('FB', EXTHEMES_FACEBOOK_URL);
define('TW', EXTHEMES_TWITTER_URL);
define('IG', EXTHEMES_INSTAGRAM_URL);
define('YT', EXTHEMES_YOUTUBE_URL);
define('webs', EXTHEMES_API_URL);
define('TELE', EXTHEMES_TELEGRAM_URL_ALT);
define('setting_opt','_options&tab=1');
define('options_setting','_options&tab=1');
define('addscriptx', 'libs/addons/libs/addscript');
define('footerx', 'libs/addons/libs/footer');
define('stylex', 'libs/addons/libs/style');
define('postnow', 'Get Now');
define('postnow2', postnow);
define('colors', '#000000');
define('colors_2', '#ffffff');
define('colors_rgb', warna_rgbs(colors));
define('colors_url', warna_rgbs(colors));
define('colors2', warna_rgbs(colors_2));
define('font_size', '2.5rem');
define('font_size_alt', '1.1em');
define('font_size_alts', '1.7rem');
define('NO_ID', '<h1 style="text-align: center;font-size: large;font-weight: 700;">Sorry.... <u style="color: '.colors.';">ID Play Store</u> No Found</h1><h3 style="text-align: center;font-size: small;">Please Refresh Agains </h3>');
define('NO_ID_PS', '<h2 style="text-align: center;font-size: large;font-weight: 700;">Sorry, the requested URL was not found on <u style="color: '.colors.';">Play Store</u>.</h2><h3 style="text-align: center;font-size: small;">Please Search Another </h3>');
define('NOIMAGES', EX_THEMES_URI.'/assets/img/lazy.png' );
// ~~~~~~~~~~~~~~~~~~~~~ EX_THEMES ~~~~~~~~~~~~~~~~~~~~~~~~ \\


add_action( 'admin_menu', 'menu_apk_extractors');
function menu_apk_extractors() { 

add_menu_page('Extractor APK', 'Extractor APK', 'manage_options', 'apk_menu', 'wp_docs', EX_THEMES_URI.'/assets/img/playstore.png', 100);
add_submenu_page( 'apk_menu', 'play.google.com', 'PLAY STORE', 'manage_options', 'sc-googleplay', 'wp_googleplay' ); 
add_submenu_page( 'apk_menu', 'aptoide', 'APTOIDE', 'manage_options', 'sc-aptoide', 'wp_aptoide' );
add_submenu_page( 'apk_menu', '5play', '5PLAY', 'manage_options', 'sc-5play', 'play5' ); 
//add_submenu_page( 'apk_menu', 'androeed.STORE', 'ANDROEED', 'manage_options', 'sc-androeed', 'wp_androeed' ); 
//add_submenu_page( 'apk_menu', 'coffeeapps.IR', 'COFFEEAPPS (for RTL)', 'manage_options', 'sc-coffeeapps', 'wp_coffeeapps' ); 
//add_submenu_page( 'apk_menu', 'gamedva.COM', 'GAMEDVA', 'manage_options', 'sc-gamedva', 'wp_gamedva' ); 
add_submenu_page( 'apk_menu', 'getmodsapk.COM', 'GETMODSAPK', 'manage_options', 'sc-getmodsapk', 'wp_getmodsapk' );  
add_submenu_page( 'apk_menu', 'happymod.COM', 'HAPPYMOD', 'manage_options', 'sc-happymod', 'wp_happymod' );
add_submenu_page( 'apk_menu', 'liteapks.COM', 'LITEAPKS', 'manage_options', 'sc-liteapks', 'wp_liteapks' );
add_submenu_page( 'apk_menu', 'modcombo.COM', 'MODCOMBO', 'manage_options', 'sc-modcombo', 'wp_modcombo' );
//add_submenu_page( 'apk_menu', 'modfyp.com', 'MODFYP', 'manage_options', 'sc-modfyp', 'wp_modfyp' );  
add_submenu_page( 'apk_menu', 'setting', 'SETTING', 'manage_options', setting_opt, 'wpwm_settings' );
}

require_once 'includes/googleplay.php';
require_once 'includes/aptoide.php'; 
require_once 'includes/apkgody.php';  
require_once 'includes/5play.php';  
require_once 'includes/androeed.php';   
require_once 'includes/modcombo.php'; 
require_once 'includes/getmodsapk.php'; 
require_once 'includes/gamedva.php'; 
require_once 'includes/happymod.php';
require_once 'includes/modfyp.php'; 
require_once 'includes/liteapks.php';    
require_once 'includes/docs.php';
require_once 'includes/dom.php';
require_once 'includes/core.php';  
require_once 'vendor/autoload.php';
require 'libs/addscript.php'; 
require 'libs/versi.php'; 
require 'libs/title.php'; 
// ~~~~~~~~~~~~~~~~~~~~~ EX_THEMES ~~~~~~~~~~~~~~~~~~~~~~~~ \\ 
//enable upload for webp image files. 

function upload_mimes_types( $mimes ) {
    $mimes['webp']	= 'image/webp';
    $mimes['svg']	= 'image/svg+xml';
    $mimes['apk']	= 'application/vnd.android.package-archive';
    $mimes['apks']	= 'application/vnd.android.package-archive';
    $mimes['xapk']	= 'application/vnd.android.package-archive';
    return $mimes;
}
add_filter( 'upload_mimes', 'upload_mimes_types' );

//enable preview / thumbnail for webp image files.
function webps_is_displayable($result, $path) {
    if ($result === false) {
        $displayable_image_types = array( IMAGETYPE_WEBP );
        $info = @getimagesize( $path );

        if (empty($info)) {
            $result = false;
        } elseif (!in_array($info[2], $displayable_image_types)) {
            $result = false;
        } else {
            $result = true;
        }
    }

    return $result;
}
add_filter('file_is_displayable_image', 'webps_is_displayable', 10, 2);


function ex_themes_notices_php() {
if (!(PHP_VERSION_ID >= 70400)) {
     printf('<div class="notice notice-error is-dismissible"><p><b>'.strtoupper(THEMES_NAMES).'</b> require a PHP version 7.4 or UP. You site running '.PHP_VERSION.'. please update your PHP</p></div> ');
}
}
add_action( 'admin_notices', 'ex_themes_notices_php' ); 