<?php
if ( ! defined( 'ABSPATH' ) ) exit;  
 
function wp_aptoide() {
global $opt_themes;
@ini_set('display_errors', ERRORS);
@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');
echo do_shortcode( '[css]' );
$Go_Curl 	= new Go_Curl();
$types			= 'post';
$sources		= 'en.aptoide.com';
$demos			= 'https://mobile-legends.en.aptoide.com/app'; 
$demosx			= 'https://en.aptoide.com/'; 
$checkx			= $Go_Curl->http_responsex($demosx); 

$protocol 		= 'https://'.$sources;
?>


	<div class="wrap">
	<div class="play_menu" style="text-transform:uppercase">
        <b>Add sources from <?php echo parse_url($protocol)['host']; ?></b>
	</div> 
	</div> 
	
    <?php 
    if(isset($_POST['wp_sb'])) {
		@ini_set('display_errors', ERRORS);
        if(isset($_POST['wp_url'])) {
            $url			= trim(strip_tags($_POST['wp_url']));
            if(stristr($url, $sources)) { 
			require_once get_template_directory().'/libs/addons/includes/class/aptoide.class.php'; 
			global $opt_themes;
			$getslinks			= new scrapes;
			$gets_data			= $getslinks->scrape_web_info($url, false);
			require_once get_template_directory().'/libs/addons/includes/inc/top_2.php';


			if (count($gets_data) and !isset($gets_data['error'])) {
			require_once get_template_directory().'/libs/addons/includes/inc/post_content.php';	
			require_once get_template_directory().'/libs/addons/includes/inc/img_gallery.php';	
 
			
			/*
			start from playstore
			*/
			require_once get_template_directory().'/libs/addons/includes/inc/gplaystore.php';	
			 
			if ( $gets_data['version'] ) { 
			update_post_meta( $post_id, 'wp_version_GP', $gets_data['version'] );
			}

			/*
			for apkmody metabox	
			*/
			require_once get_template_directory().'/libs/addons/includes/inc/dlpro.php';	
			 
			
			$download_info_link = array();
			if ( !empty($gets_data['sizes_GP']) ) {
				$size_dwz = $gets_data['sizes_GP'];
			} else {
				$size_dwz = $gets_data['size_sc'];
			}
			
			
			/* if($opt_themes['ouo']){
				$link_urlz = ouo_io_user($gets_data['link_download_aptoide']);
			} else {
				$link_urlz = $gets_data['link_download_aptoide'];
			}
			
			if($opt_themes['shrinkearn']){
				$link_urlz = shrinkearn_user($gets_data['link_download_aptoide']);
			} else {
				$link_urlz = $gets_data['link_download_aptoide'];
			}
			 */
			$link_urlz = $gets_data['link_download_aptoide'];
			
			if ( !empty($gets_data['link_download_aptoide']) ) { 
			$download_info_link_data2 = [
				'name' 		=> $gets_data['title_GP'],
				'title' 	=> $gets_data['title_GP'],
				'url' 		=> $link_urlz,
				'links' 	=> $link_urlz,
				'sizes1' 	=> $gets_data['sizes_GP'],
				'sizes' 	=> $gets_data['sizes_GP'],
				'size' 		=> $gets_data['sizes_GP'],
				'tipes' 	=> '',
				'notes' 	=> '',
			]; 
			 
			array_push($download_info_link, $download_info_link_data2);
			update_post_meta($post_id, "repeatable_fields", $download_info_link);
			update_post_meta($post_id, "group_downloads_links", $download_info_link);
			}
			 
			if ( !empty($gets_data['sizes_GP']) ) {
				$size_dwz = $gets_data['sizes_GP'];
			} else {
				$size_dwz = $gets_data['size_sc'];
			}
			
			if ( !empty($gets_data['title_GP']) ) { 
				$title_dwz = $gets_data['title_GP'].' Apk'; 
			} else {
				$title_dwz = $gets_data['app_name'].' Apk'; 
			}
			
			
			/* 
			if ($opt_themes['ouo']) {
				$linkapkz	= ouo_io_exhemes('https://exthem.es/apk.php?pkg='.$gets_data['GP_ID']);
			} else {
				$linkapkz	= ouo_io_exhemes('https://exthem.es/apk.php?pkg='.$gets_data['GP_ID']);
			}

			if ($opt_themes['shrinkearn']) {
				$linkapkz	= shrinkearn_exhemes('https://exthem.es/apk.php?pkg='.$gets_data['GP_ID']);
			} else {
				$linkapkz	= shrinkearn_exhemes('https://exthem.es/apk.php?pkg='.$gets_data['GP_ID']);
			} 
			*/
			

			$linkapkz	= ouo_io_exhemes('https://exthem.es/apk.php?pkg='.$gets_data['GP_ID']);
			$linkapkz2	= ouo_io_exhemes('https://play.google.com/store/apps/details?id='.$gets_data['GP_ID']);
			 			 
			 
			$download_info_link_data_gps = [
				'name' 		=> $title_dwz,
				'url' 		=> $linkapkz,
				'sizes1' 	=> $size_dwz,
				'sizes' 	=> $size_dwz,
				'title' 	=> $title_dwz,
				'links' 	=> $linkapkz,
				'size' 		=> $size_dwz,
				'tipes' 	=> '',
				'notes' 	=> '',
			]; 
			 
			array_push($download_info_link, $download_info_link_data_gps);
			update_post_meta($post_id, "repeatable_fields", $download_info_link);
			update_post_meta($post_id, "group_downloads_links", $download_info_link);			

			
			   
			wp_set_object_terms( $post_id, $gets_data['title_GP'], 'post_tag', true ); 
			if($post_id)
			$urlX			= get_permalink( $post_id );
			require_once get_template_directory().'/libs/addons/includes/result.php'; 
			}
			} else {
			echo '<div class="play_menu" style="text-transform:uppercase!important;color:#00a0d2"><h3 style="color:#00a0d2">Please check your link.. your link is <b style="color:red">'.$url.'</b></h3></div>';
			}
        }
    }
     
	?>

  
    <div style="clear:both"></div>
	
    
	<div class="wrap" id="play_fixed" >
	<div class=" play_menu" style="margin-bottom: 10px;">
		<ul id="menunya" class="play_menus" style="text-transform:capitalize">
			<li data-tab="tab1"><a><i class="fa fa-home"></i> Home</a></li> 
			<li data-tab="tab2"><a><i class="fa fa-search"></i> Search</a></li>  	
			<li data-tab="tab3"><a><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Add Manual</a></li>  
			<?php if(isset($_POST['wp_sb'])) { ?>
			<li <?php if(isset($_POST['wp_sb'])) { ?>class="active" <?php } ?>data-tab="tab4"><a><i class="fa fa-bullhorn"></i> Debugs</a></li>
			<?php } ?>		
		</ul>
		<div style="clear:both"></div>
	</div>
    </div>
		
	   
    <div class="containerX">
        <div class="tab-content">
          
		<div id="tab1" class="tab-pane fade">  
		<?php global $opt_themes; ?> 			
		<ul class="play_menu" >
			<li>Your Status Post is <?php if($opt_themes['apk_status'] != 'draft') { ?> <blink><strong class="blink blink-one" style="color:green"><?php echo $opt_themes['apk_status']; ?></strong></blink> You ready to Make auto posting now <?php } else { ?><blink><strong class="blink blink-one" style="color:red"><?php echo $opt_themes['apk_status']; ?></strong></blink>. Please Change to <blink><strong class="blink" style="color:green">publish</strong></blink> to make Auto Posting,  you can go to Setting Page <?php } ?> </li>
		</ul>
		</div>     
            
		<div id="tab2" class="tab-pane fade <?php if(isset($_POST['submit'])) { ?>in active <?php } ?>">
			<div class="play_menu" style="text-transform:uppercase"><b>Search</b></div>     

			<center> 
			<?php 
			if (isset($_POST['submit']))  { 
			if ((!isset($_POST['search_query'])) ) { 
			$error = "*" . "Please fill all the required fields"; 
			} else { 
			$search_query = $_POST['search_query'];  
			} 
			} 
			?>
			<ul style=" ">
			<li>Just add your <b>keyword</b> on form and click <b>Search</b></li> 
			</ul>	
			<form id="form1" method="post" action="" class='f'> 
			<?php 
			if (isset($_POST['submit'])) 
			{ 
			if (isset($error)) 
			{ 
			echo "<p style='color:red;'>" 
			. $error . "</p>"; 
			} 
			} 
			?>					
			<input type="text" name="search_query" placeholder="example : whatsapp"/>  
			<input type="submit" name="submit" value="Search"/> 
			</form> 
			</center> 		
				  
			<?php  
			if(isset($_POST['submit'])) { 
			if(!isset($error)) { 
			$search_query	= strtolower($_POST['search_query']); 

			$base_url		= 'https://web-api-cache.aptoide.com/search?query=';
			$search_url		= $base_url . urlencode($search_query) . '&mature=false';
				
			$get_data		= $Go_Curl->file_get_contents_curlx($search_url); 
			$data			= json_decode($get_data, true);
 
			?> 
			<div class="play_menu" style="text-transform:uppercase;"><b><?php echo $data["datalist"]["total"]; ?> Result for "<?php echo $search_query; ?>"</b></div>  
			
			<section>
			<div class="row"> 
			<?php foreach ($data["datalist"]["list"] as $row): ?>


			<div class="col-12 col-md-6 mb-4">
			<span class="position-relative archive-post--remove app-container">
			<div class="flex-shrink-0">
			<img src="<?php echo $row["icon"]; ?>" alt="image"  class="app-logo " width="64" height="64"> 
			</div>
							
			<div class="app-info">
			<h3 class="h5 font-weight-semibold w-100 app-title"><?php echo $row["name"]; ?></h3>	
							 
			<div class="text-truncate text-muted app-desc">
			<span class="clamp-1 w-100">
			Devs : <?php echo $row["developer"]["name"]; ?>	
				
			</span>				
			</div>
							 
			</div>
							 
			<div class="app-get">
							
			<form method="POST" target="_blank">
			<input style="display:none" type="text" name="wp_url" value="https://<?php echo $row["uname"]; ?>.en.aptoide.com/app">
			<input type="submit" id="submit" name="wp_sb" class="get-button" value="<?php echo postnow; ?>" />
			</form>
			<?php if($row["file"]["vername"]){?>
			<span class="app-version text-truncate"> <svg class="mr-1" xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16">
			<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8zm15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-7.5 3.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V11.5z"></path>
			</svg>v.<?php echo $row["file"]["vername"]; ?></span>
			<?php } ?>			
							 
			</div>
							 
			</span>
			</div>	
				 
			<?php endforeach ?>

			</div>
			</section>	
			<?php } } ?>
		</div>
			
		<div id="tab3" class="tab-pane fade <?php if (!isset($_POST["submit"]) && !isset($_POST["wp_sb"])) { ?>in active<?php } ?>">
			
			<div class="play_menu"  style="text-transform:uppercase" ><i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;<b>Paste your link post here</b></div>

			<div class="play_menu" >				 
			<form name="myForm" id="myForm" method="POST" class='f'>
			<input type="text" name="wp_url" placeholder="example : <?php echo $demos; ?>"  >
			<input type="submit" id="Submit" name="wp_sb" value="<?php echo postnow; ?>" />
			</form>
			</div> 
			
			<div class="play_menu" style="text-transform:uppercase"><b>Add manual</b></div>

			<div class="play_menu" style="text-transform:uppercase">
			<ol style="padding-right: 20px !important;">
			<li>Open website <a style="color:var(--color_link_h)!important;font-weight: 700;" href="https://<?php echo $sources; ?>" target="_blank"><?php echo $sources; ?></a></li>
			<li>Copy link post and paste to form</li>
			<li>use the url into this format:  <strong style="color:var(--color_link_h)!important;font-weight: 700;text-transform:lowercase!important"><?php echo $demos; ?></strong> </li>
			</ol>				
			</div>
		</div>
           
		<div id="tab4" class="tab-pane fade <?php if(isset($_POST['wp_sb'])) { ?> in active<?php } ?>"> 			
			<?php require_once get_template_directory().'/libs/addons/includes/debug-aptoide.php'; ?>
		</div>
			
        </div>
    </div>
 
<div style="clear:both"></div>
 
<?php  
echo do_shortcode( '[ft_menu]' );
echo do_shortcode( '[ft_js]' ); 
}