<?php
//@error_reporting(-1);
//@ini_set('display_errors', 0);
 
global $wpdb, $post, $wp_query, $opt_themes;  
	
	//$long_url 	= urlencode($_POST['longurl']);
	//$apikey		= $_POST['apikey'];	
	$random		= md5(substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ-"), -10));
	
		
	$long_url 	= isset($_POST['longurl']) ? urlencode($_POST['longurl']) : '';
	$apikey   	= isset($_POST['apikey']) ? trim($_POST['apikey']) : '';
	$service  	= isset($_POST['service']) ? $_POST['service'] : '';

	if($service == 'ouo'){ 
	$api_url	= "http://ouo.io/api/{$apikey}?s=".urlencode($long_url); 
	$result 	= @file_get_contents($api_url); 
	?>
	 
	<?php } elseif($service == 'shrinkearn'){
	$api_url 	= "https://shrinkearn.com/api?api={$apikey}&url={$long_url}&format=text";
	$result 	= @file_get_contents($api_url);
	?>
	 
	<?php } elseif($service == 'paid4link'){
	$api_url	= "https://paid4link.com/api?api={$apikey}&url={$long_url}&alias={$random}&format=text"; 
	$api_url2 	= "https://paid4link.com/api?api={$apikey}&url={$long_url}&format=text";
	$result 	= @file_get_contents($api_url);
	?>
	 
	<?php } elseif($service == 'adurl'){
	$api_url2	= "https://paid4link.com/api?api={$apikey}&url={$long_url}&format=text"; 
	$api_url 	= "https://adurl.io/api?api={$apikey}&url={$long_url}&format=text";
	$result 	= @file_get_contents($api_url);
	?>
 
	<?php } if (!empty($result)) { ?>	
	<textarea readonly onclick="this.select()" class="aps-textarea" name="<?php echo $result; ?>"><?php echo $result; ?></textarea>
	<?php } else { ?>
	<div style="padding:15px; background:#ffebee; border:1px solid red; border-radius:4px; margin-top:10px;">
	<p style="color:red; font-weight:bold;">Failed to shorten link from <?php echo $service; ?> !</p>
	<p>No response (service down or invalid token). Check your Token/API Key or try another service.</p>
	</div>
	<?php } ?>
 