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

function wp_modcombo(){
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		= 'modcombo.com';
$demos		= 'https://facebook-lite.modcombo.com/'; 
$checkx		= $Go_Curl->http_responsex($demos);

$keyz		= $opt_themes['api_key_scrape'];
//if($keyz){
//$rand_apikey 	= array_rand($keyz);
//$apikey 		= $keyz[$rand_apikey]; 
//}

$protocol 		= 'https://'.$sources;
$status 		= $Go_Curl->http_responsex($demos); 
?>
	
    <div class="play_menu" style="text-transform:uppercase">
        <b>Add sources from <?php echo parse_url($protocol)['host']; ?></b>
    </div> 
	 
	<?php		
	//echo api_rand();
	if($checkx === 403) {
	?>
	<div class="wrap">
    <div class="containerX">
	<h2></h2>
	<h3></h3>	 
	<!--<h5 style="text-align: center;">because its blocked by cloudflare</h5>-->
	<?php		
	if($keyz) {
	?>
	<h3 style="text-align: center;">because <?php echo parse_url($protocol)['host']; ?>  blocked by cloudflare</h3>
	<h4 style="text-align: center;">Your using by Api Key</h4>
	<input onclick="this.select()" readonly type="text" id="api_key_scrape" name="api_key_scrape" value="<?php echo api_rand(); ?>" class="regular-text" style="text-align: center;display: block;margin-right: auto;margin-left: auto;"/>
 
	<?php } else { ?>	
	<h1 style="text-align: center;">Sorry.... scraping from <?php echo parse_url($demos)['host']; ?> blocked by cloudflare</h1>
	<h4 style="text-align: center;">Please add your API key</h4>
	<h5 style="text-align: center;"><a href="/wp-admin/admin.php?page=_options&tab=13" target="_blank">Click HERE to add API key </a></h5>
	<?php } 
	
	$errorcode = $Go_Curl->http_responsex($demos); 
 
	if($errorcode === 403 && !$keyz) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Forbidden (blocked by cloudflare)</h5> ';

	} elseif($errorcode === 400) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Bad Request </h5> ';
		
	} elseif($errorcode === 404) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Not Found </h5> ';
		
	} elseif($errorcode === 500) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Internal Server Error </h5> ';
		
	} elseif($errorcode === 502) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Bad Gateway </h5> ';
		
	} elseif($errorcode === 503) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' Service Unavailable </h5> ';
		
	} elseif($errorcode === 200) {
    echo '<h5 style="text-align: center;">Status : '.$errorcode.' OK </h5> ';
		
	}
	?>
	
    </div>
    </div>
	<?php } ?>
	
	
	
	<?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/modcombo.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.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/playstore.php';	
		
		
		/*
		start from sources
		*/ 
		require_once get_template_directory().'/libs/addons/includes/inc/mcm.php';	
		
		/*
		for apkmody metabox	
		*/
		require_once get_template_directory().'/libs/addons/includes/inc/dlpro.php';	
		

		if ( !empty($gets_data['title_GP']) ) { 
		wp_set_object_terms( $post_id, $gets_data['title_GP'], 'post_tag', true ); 
		} else {
		wp_set_object_terms( $post_id, $gets_data['app_name'], 'post_tag', true ); 
		}

		$download_info_link = array();
		$count		= count($gets_data['name_downloadlinks_gma']);
		for ($i = 0; $i < $count; $i++) {

		if (!empty($gets_data['sizes_GP'])) {
		$size_dw = $gets_data['sizes_GP'];
		} else {
		$size_dw = $gets_data['size_sc'];
		}


		/* if($opt_themes['ouo']){
		$link_urlz = ouo_io_user($gets_data['link_apk']);
		} else {
		$link_urlz = $gets_data['link_apk'];
		}
		
		if($opt_themes['shrinkearn']){
		$link_urlz = shrinkearn_user($gets_data['link_apk']);
		} else {
		$link_urlz = $gets_data['link_apk'];
		} */
		//$link_urlz = $gets_data['link_apk'];
		
		
		if($opt_themes['import_apk']){	 
		$linkapkzURL	= $gets_data['apklink'][$i];
		$attach_id		= upload_remote_file_apk( $linkapkzURL );
		$link_urlz		= esc_url(wp_get_attachment_url($attach_id));
		
		if ( is_wp_error( $attach_id ) ) {
			echo 'Error: ' . $attach_id->get_error_message();
		} else {
			echo 'File uploaded! Attachment ID: ' . $attach_id . '<br>';
			echo 'URL: ' . wp_get_attachment_url( $attach_id );
		}
		
		} else {
		$link_urlz 		= $gets_data['apklink'][$i];
		}
		
		
		
		if ( !empty($gets_data['apklink']) ) { 
		$download_info_link_data = [
		'name' 		=> $gets_data['name_downloadlinks_gma'][$i],
		'title' 	=> $gets_data['name_downloadlinks_gma'][$i],
		'url' 		=> $link_urlz,
		'links' 	=> $link_urlz,
		'sizes1' 	=> $gets_data['size_downloadlinks_gma'][$i],
		'sizes' 	=> $gets_data['size_downloadlinks_gma'][$i],
		'size' 		=> $gets_data['size_downloadlinks_gma'][$i],
		'tipes' 	=> $gets_data['type_downloadlink_gma_'[$i]],
		'notes' 	=> '',
		];
		array_push($download_info_link, $download_info_link_data);
		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);		
		
		require_once get_template_directory().'/libs/addons/includes/inc/dw_apt.php';	
		require_once get_template_directory().'/libs/addons/includes/inc/dw_apkgk.php';	
		 
		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">
		<div class="play_fixedx play_menu" id="play_fixed" 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 <?php if (isset($_POST['submit'])) { ?> class="active" <?php } ?> data-tab="tab2"><a><i class="fa fa-search"></i> Search</a></li>
		<li <?php if (!isset($_POST["submit"]) && !isset($_POST["wp_sb"])) { ?>class="active" <?php } ?>data-tab="tab3"><a><i class="fa fa-rss"></i> Latest Games</a></li>
		<li data-tab="tab4"><a><i class="fa fa-rss"></i> Latest Apps</a></li>
		<li data-tab="tab5"><a><i class="fa fa-pencil-square-o"></i> add manual</a></li>
		<?php if (isset($_POST['wp_sb'])) { ?>
		<li <?php if (isset($_POST['wp_sb'])) { ?>class="active" <?php } ?>data-tab="tab6"><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)) {
		ini_set('display_errors', 'off'); 
 
		@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');

		$search_query	= strtolower($_POST['search_query']);
		$base_url		= 'https://modcombo.com/?s=';
		$search_url		= $base_url.urlencode($search_query);
		$link_cari		= $search_url;
		//$html		= file_get_html($link_cari, false, stream_context_create($ssl));
		
		 
		if($status === 403) { 
		$html		= scrapedo($link_cari);  
		} else {
		$html		= file_get_html($link_cari);	
		} 
		 
		?>

		<div class="play_menu" style="text-transform:uppercase"><b> Result for "<?php echo $search_query; ?>"</b></div>
		<section>
		<div class="row">
		
		<?php 
		 
		
		foreach ($html->find("ul.blogs.w3 li") as $items) {
		if (!empty($items->find('a.blog.search', 0)->href)) {
		?>
		<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 $items->find('img', 0)->{'data-src'}; ?>" class="app-logo " width="64" height="64">
		</div>

		<div class="app-info">
		<h3 class="h5 font-weight-semibold w-100 app-title"><?php echo $items->find('.title', 0)->{'plaintext'}; ?> </h3>

		<div class="text-truncate text-muted app-desc">
		<span class="clamp-1 w-100"> 
		<?php echo $items->find('time', 0)->{'plaintext'}; ?>
		</span>
		</div>
		</div>

		<div class="app-get">
		<form method="POST" target="_blank">
		<input style="display:none" type="text" name="wp_url" value="<?php echo $items->find('a.blog.search', 0)->href; ?>">
		<input type="submit" id="submit" name="wp_sb" class="get-button" value="<?php echo postnow; ?>" />
		</form>
		</div>

		</span>
		</div>
		<?php }
		} ?>
		</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">
		<b>Latest Post Games </b>
		</div>

		<section>
		<div class="row">
		<?php
		$halaman_gm		= isset($_GET['hal_gm']) ? (int)$_GET['hal_gm'] : 1;
		$sc_url		= 'https://modcombo.com/games/page/' . $halaman_gm;
		//$html		= file_get_html($sc_url);
		
		 
		$status 		= $Go_Curl->http_responsex($sc_url); 
			if($status === 403) {
			//$html			= scraperapi($sc_url);	
			//$html			= $Go_Curl->scrapedox($sc_url);  
			$html			= $Go_Curl->scrapedox($sc_url);  
			} else {
			//$html			= $Go_Curl->scrapedox($sc_url);	
			$html			= $Go_Curl->scrape_sitex($sc_url);	
			} 
		
		foreach ($html->find("ul.apks.w3.apkincategories.box-space li") as $items) {
		if (!empty($items->find('a', 0)->href)) {
		?>
		<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 $items->find('img', 0)->{'data-src'}; ?>" class="app-logo " width="64" height="64">
		</div>

		<div class="app-info">
		<h3 class="h5 font-weight-semibold w-100 app-title"><?php echo $items->find('.title.truncate', 0)->{'plaintext'}; ?> v.<?php echo trim($items->find('div.version.truncate', 0)->{'plaintext'}); ?></h3>

		<div class="text-truncate text-muted app-desc">
		<span class="clamp-1 w-100"> 
		<?php echo $items->find('div.mod.truncate.mod-feature', 0)->{'plaintext'}; ?>
		</span>
		</div>
		</div>

		<div class="app-get">
		<form method="POST" target="_blank">
		<input style="display:none" type="text" name="wp_url" value="<?php echo $items->find('a', 0)->href; ?>">
		<input type="submit" id="submit" name="wp_sb" class="get-button" value="<?php echo postnow; ?>" />
		</form>
		</div>

		</span>
		</div>
		<?php }
		} ?>
		</div>
		</section>

		<nav class="paginate">
		<ul class="pagination">
		<?php
		$jumlah_page		= 9999;
		$jumlah_number		= 3;
		$start_number		= ($halaman_gm > $jumlah_number) ? $halaman_gm - $jumlah_number : 1;
		$end_number		= ($halaman_gm < ($jumlah_page - $jumlah_number)) ? $halaman_gm + $jumlah_number : $jumlah_page;

		if ($halaman_gm == 1) {
		?>
		<!--<li class="page-item disable"><a class="page-link" >First</a></li>
		<li class="page-item disable"><a class="page-link" >&laquo;</a></li>-->
		<?php
		} else {
		$link_prev_gm		= ($halaman_gm > 1) ? $halaman_gm - 1 : 1;
		?>
		<li class="page-item"><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_gm=1'"; ?>>First</a></li>
		<li class="page-item"><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_gm=$link_prev_gm'"; ?>>&laquo;</a></li>
		<?php
		}
		for ($i = $start_number; $i <= $end_number; $i++) {
		$link_active_gm		= ($halaman_gm == $i) ? ' class="page-item active"' : '';
		?>
		<li<?php echo $link_active_gm; ?>><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_gm=$i'"; ?>><?php echo $i; ?></a></li>
		<?php
		}
		if ($halaman_gm == $jumlah_page) {
		?>
		<li class="page-item "><a class="page-link" href="#">&raquo;</a></li>
		<?php
		} else {
		$link_next_gm		= ($halaman_gm < $jumlah_page) ? $halaman_gm + 1 : $jumlah_page;
		?>
		<li class="page-item "><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_gm=$link_next_gm'"; ?>>&raquo;</a></li>
		<?php
		}
		?>
		</ul>
		</nav>



		</div>

		<div id="tab4" class="tab-pane fade">
		<div class="play_menu" style="text-transform:uppercase">
		<b>Latest Post Apps</b>
		</div>

		<section>
		<div class="row">
		<?php
		$halaman_ap		= isset($_GET['hal_ap']) ? (int)$_GET['hal_ap'] : 1;
		$sc_url		= 'https://modcombo.com/apps/page/' . $halaman_ap;
		//$html		= file_get_html($sc_url);
		 
		if($status === 403) { 
		$html		= scrapedo($sc_url);  
		} else {
		$html		= file_get_html($sc_url);	
		} 
		foreach ($html->find("ul.apks.w3.apkincategories.box-space li") as $items) {
		if (!empty($items->find('a', 0)->href)) {
		?>
		<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 $items->find('img', 0)->{'data-src'}; ?>" class="app-logo " width="64" height="64">
		</div>

		<div class="app-info">
		<h3 class="h5 font-weight-semibold w-100 app-title"><?php echo $items->find('.title.truncate', 0)->{'plaintext'}; ?> v.<?php echo trim($items->find('div.version.truncate', 0)->{'plaintext'}); ?></h3>

		<div class="text-truncate text-muted app-desc">
		<span class="clamp-1 w-100">
		<?php echo $items->find('div.mod.truncate.mod-feature', 0)->{'plaintext'}; ?>
		</span>
		</div>
		</div>

		<div class="app-get">
		<form method="POST" target="_blank">
		<input style="display:none" type="text" name="wp_url" value="<?php echo $items->find('a', 0)->href; ?>">
		<input type="submit" id="submit" name="wp_sb" class="get-button" value="<?php echo postnow; ?>" />
		</form>
		</div>

		</span>
		</div>
		<?php }
		} ?>
		</div>
		</section>

		<nav class="paginate">
		<ul class="pagination">
		<?php
		$jumlah_page		= 9999;
		$jumlah_number		= 3;
		$start_number		= ($halaman_ap > $jumlah_number) ? $halaman_ap - $jumlah_number : 1;
		$end_number		= ($halaman_ap < ($jumlah_page - $jumlah_number)) ? $halaman_ap + $jumlah_number : $jumlah_page;

		if ($halaman_ap == 1) {
		?>
		<!--<li class="page-item disable"><a class="page-link" >First</a></li>
		<li class="page-item disable"><a class="page-link" >&laquo;</a></li>-->
		<?php
		} else {
		$link_prev_ap		= ($halaman_ap > 1) ? $halaman_ap - 1 : 1;
		?>
		<li class="page-item"><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_ap=1'"; ?>>First</a></li>
		<li class="page-item"><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_ap=$link_prev_ap'"; ?>>&laquo;</a></li>
		<?php
		}
		for ($i = $start_number; $i <= $end_number; $i++) {
		$link_active_ap		= ($halaman_ap == $i) ? ' class="page-item active"' : '';
		?>
		<li<?php echo $link_active_ap; ?>><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_ap=$i'"; ?>><?php echo $i; ?></a></li>
		<?php
		}
		if ($halaman_ap == $jumlah_page) {
		?>
		<li class="page-item "><a class="page-link" href="#">&raquo;</a></li>
		<?php
		} else {
		$link_next_ap		= ($halaman_ap < $jumlah_page) ? $halaman_ap + 1 : $jumlah_page;
		?>
		<li class="page-item "><a class="page-link" <?php echo "href='admin.php?page=sc-modcombo&hal_ap=$link_next_ap'"; ?>>&raquo;</a></li>
		<?php
		}
		?>
		</ul>
		</nav>



		</div>

		<div id="tab5" class="tab-pane fade">
		<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 parse_url($demos)['host']; ?>" target="_blank"><?php echo parse_url($demos)['host']; ?></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="tab6" class="tab-pane fade <?php if (isset($_POST['wp_sb'])) { ?> in active<?php } ?>">
		<?php require_once get_template_directory().'/libs/addons/includes/debug.php'; ?>
		
		</div>


		</div>
	</div>


	<div style="clear:both"></div>


<?php
	echo do_shortcode('[ft_menu]');
	echo do_shortcode('[ft_js]');
}
