<?php
/*-----------------------------------------------*/
/*  EXTHEM.ES
/*  PREMIUM WORDRESS THEMES
/*
/*  STOP DON'T TRY EDIT
/*  IF YOU DON'T KNOW PHP 
/*
/*  As Errors In Your Themes
/*  Are Not The Responsibility
/*  Of The DEVELOPERS
/*  @EXTHEM.ES
/*  
/*  Follow Social Media Exthem.es
/*  Youtube : https://www.youtube.com/channel/UCpcZNXk6ySLtwRSBN6fVyLA
/*  Facebook : https://www.facebook.com/groups/exthem.es
/*  Twitter : https://x.com/bangreyblog
/*  Instagram : https://www.instagram.com/exthem.es/
/*  Telegram : https://t.me/exthemes_helps
/*  TikTok : https://www.tiktok.com/@exthemes
/*	More Premium Themes Visit Now On https://exthem.es/
/*-----------------------------------------------*/
if ( ! defined( 'ABSPATH' ) ) exit; 
// Silence is golden.

function add_shortlink_metaboxes() {
	global $post, $opt_themes;
	if($opt_themes['shortlink_post']){
		add_meta_box( 'box_shortlink',  __( 'Manual Short link', THEMES_NAMES ), 'plug_short_link', 'post', 'normal', 'low' );  
	}
}
add_action( 'add_meta_boxes', 'add_shortlink_metaboxes', 0 );
  

function plug_short_link(){
/*
https://tecadmin.net/submit-form-without-page-refresh-php-jquery/
*/ 
global $opt_themes;
$ouo_apikey			= $opt_themes['ouo_apikey']; 
$shrinkearn_apikey	= $opt_themes['shrinkearn_apikey'];  
$paid4link_apikey	= ''; 
$adurl_apikey		= $opt_themes['adurl_apikey'];  
?>

<style>
.modal {position: absolute;z-index: 10000;top: 0;left: 0;visibility: hidden;width: 100%;height: 100%;}.modal.is-visible {visibility: visible;}.modal-overlay {position: fixed;z-index: 10;top: 0;left: 0;width: 100%;height: 100%;background: hsla(0, 0%, 0%, 0.5);visibility: hidden;opacity: 0;transition: visibility 0s linear 0.3s, opacity 0.3s;}.modal.is-visible .modal-overlay {opacity: 1;visibility: visible;transition-delay: 0s;}.modal-wrapper {position: absolute;z-index: 9999;top: 6em;left: 50%;width: 32em;margin-left: -16em;background-color: #fff;box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);}.modal-transition {transition: all 0.3s 0.12s;transform: translateY(-10%);opacity: 0;}.modal.is-visible .modal-transition {transform: translateY(0);opacity: 1;}.modal-header, .modal-content {padding: 1em;}.modal-header {position: relative;background-color: #fff;box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.06);border-bottom: 1px solid #e8e8e8;}.modal-close {position: absolute;top: 0;right: 0;padding: 1em;color: #aaa;background: none;border: 0;}.modal-close:hover {color: #777;}.modal-heading {font-size: 1.125em;margin: 0;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}.modal-content > *:first-child {margin-top: 0;}.modal-content > *:last-child {margin-bottom: 0;}
</style>

<div class="admin-inside-box clearfix">
	<div class="aps-wrap">
 
	<!-- open tab container -->
	<div class="aps-tabs-container">

	<!-- tab 1 -->
	<div id="aps-tb-shortlink" class="aps-tab-contents active"> 
	<div class="aps-group-inputs">
	
	<ul class="aps-features">
	  
	<li>  
	<div class="aps-col-6" style="text-transform:uppercase">
	<span style="font-size: small;"><a href="http://ouo.io/ref/mH4aOrLs" target="_blank"><b class="cool-link f2" style="color:red;">Register on OUO.IO</b></a> to get your Token</span> 
	</div> 	
	</li> 
	 
	<li>  
	<div class="aps-col-6" style="text-transform:uppercase">
	<span style="font-size: small;"><a href="https://shrinkearn.com/ref/exthemes" target="_blank"><b class="cool-link f2" style="color:red;">Register on SHRINKEARN.COM </b></a> to get your Token</span> 
	</div> 	
	</li> 
	 
	<li>  
	<div class="aps-col-6" style="text-transform:uppercase">
	<span style="font-size: small;"><a href="https://paid4link.com/ref/exthemes" target="_blank"><b class="cool-link f2" style="color:red;">Register on PAID4LINK.COM</b></a> to get your Token</span> 
	</div>	
	</li> 
	 
	<li>  
	<div class="aps-col-6" style="text-transform:uppercase">
	<span style="font-size: small;"><a href="https://adurl.io/ref/exthemes" target="_blank"><b class="cool-link f2" style="color:red;">Register on ADURL.IO</b></a> to get your Token</span> 
	</div>	
	</li> 
	
	<li>	
	<div class="aps-col-6" style="text-transform:uppercase">
	<button class="modal-toggle">CLICK HERE SHORT YOUR LINK</button>
	</div> 
	</li> 
	
	</ul>
	
	</div>
	
	</div>
	
	 
	 
	</div>
	<!-- close tab container -->
 
     
	</div>
</div> 

<div class="modal">
    <div class="modal-overlay modal-toggle"></div>
    <div class="modal-wrapper modal-transition">
      <div class="modal-header">
        <button class="modal-close modal-toggle"><svg class="icon-close icon" viewBox="0 0 32 32"><use xlink:href="#icon-close"></use></svg></button>
        <h2 class="modal-heading">Shorten Your Link</h2>
      </div>
      
      <div class="modal-body">
        <div class="modal-content">
		 
			<div class="admin-inside-box clearfix">
			<div class="aps-wrap">

			<!-- open tab container -->
			<div class="aps-tabs-container">

			<div id="aps-tb-shortlink" class="aps-tab-contents active"> 
			<div class="aps-group-inputs">
	
			 
			<ul class="aps-features">
			<li>   
			<div class="aps-col-6" style="text-transform:uppercase">
			<label for="ouo_apikey">My Token OUO </label>
			<input readonly onclick="this.select()" type="text" id="ouo_apikey" class=" aps-text-input" name="ouo_apikey" value="<?= $ouo_apikey ?>" placeholder="<?= $ouo_apikey ?>" />  
			</div> 
			   
			<div class="aps-col-6" style="text-transform:uppercase">
			<label for="shrinkearn_apikey">My Token SHRINKEARN </label>
			<input readonly onclick="this.select()" type="text" id="shrinkearn_apikey" class=" aps-text-input" name="shrinkearn_apikey" value="<?= $shrinkearn_apikey ?>" placeholder="<?= $shrinkearn_apikey ?>" />  
			</div> 
			   
			<div class="aps-col-6" style="text-transform:uppercase">
			<label for="paid4link_apikey">My Token PAID4LINK </label>
			<input readonly onclick="this.select()" type="text" id="paid4link_apikey" class=" aps-text-input" name="paid4link_apikey" value="<?= $paid4link_apikey ?>" placeholder="<?= $paid4link_apikey ?>" />  
			</div> 
			   
			<div class="aps-col-6" style="text-transform:uppercase">
			<label for="adurl_apikey">My Token ADURL </label>
			<input readonly onclick="this.select()" type="text" id="adurl_apikey" class=" aps-text-input" name="adurl_apikey" value="<?= $adurl_apikey ?>" placeholder="<?= $adurl_apikey ?>" />  
			</div> 
			</li> 
			</ul>
			
			<div class="form-row">
			<div id="results"></div>
			</div> 
			
			<form id="myForm" method="post">
			
			<div class="form-row"> 			
			<div class="form-group">
			<label>Services <span class="text-danger">*</span></label>
			<select name="service" id="service" class="form-control form_data">
			<option value="ouo">OUO</option>
			<option value="shrinkearn">SHRINKEARN</option>
			<option value="paid4link">PAID4LINK</option>
			<option value="adurl">ADURL</option>
			<option disabled value="others">others</option>
			</select>
			</div>
			</div>
			
			<div class="form-row">
			<label for="apikey">Token :</label>
			<input class=" aps-text-input" name="apikey" id="apikey" type="text" />
			</div> 
			<div class="form-row">
			<label for="longurl">Long Url :</label>
			<input class=" aps-text-input" name="longurl" id="longurl" type="text" />
			</div> 
			
			<button type="button" id="submitFormData"  onclick="SubmitShortLink();">Submit</button>
			</form>
			

        </div>
        </div>
        </div>
        </div>
        </div>
      </div>
    </div>
</div>
</div>


<?php	
}


add_action( 'admin_footer-post.php', 'flink_scripts',  );
add_action( 'admin_footer-post-new.php', 'flink_scripts',  );

function flink_scripts() { 
global $post, $opt_themes;
if( 'post' != $post->post_type ) 
return;
if($opt_themes['shortlink_post']){
?>  
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script id="rendered-js" >
// Quick & dirty toggle to demonstrate modal toggle behavior
$('.modal-toggle').on('click', function (e) {
  e.preventDefault();
  $('.modal').toggleClass('is-visible');
});
</script>
<script src="https://code.jquery.com/jquery-latest.js"></script>


<script> 

function SubmitShortLink() {
    var longurl = $("#longurl").val(); 
    var service = $("#service").val();
    var apikey = $("#apikey").val();
    $.post("<?php echo get_template_directory_uri(); ?>/libs/addons/inc/slink.php", { longurl: longurl, apikey: apikey, service: service },
    function(data) {
	 $('#results').html(data);
	 $('#myForm')[0].reset();
    });
}

</script>
<?php
}
}
