<?php
/**
 * Template Name: Embed
 *
 */

defined( 'ABSPATH' ) || exit; // Exit if accessed directly
$videoid = $_GET['v'];
$part = $_GET['part'];
$thumb_id = get_post_thumbnail_id($videoid);
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
$img = $thumb_url[0];
$post = get_page($videoid); ?>
<?php 
if(!empty($part)) : $i = --$part ; else : $i = 0; endif;
$source = get_post_meta($videoid, "player_{$i}_source", true);
$server = get_post_meta($videoid, "player_{$i}_server", true);
if ($server == 'blogger' ): 
$src = base64_encode($source);
$image = base64_encode($img) ;
$player = "https://cdn.embedz.net/?vid=$src&img=$image&ch=cdn"; endif;
if ($server == 'iframe' ): $player = $source; endif;
if ($server == 'self' ): $src = "hls"; 
$src = base64_encode($source);
$image = base64_encode($img) ;
$player = "https://cdn.embedz.net/?vid=$src&img=$image&ch=hls"; endif;
if (!empty($videoid)):
?>
<!DOCTYPE html>
<html>
<title><?php echo get_the_title($videoid); ?></title>
<head>
<meta name="robots" content="noindex" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="<?php $permalink = get_permalink( $videoid ); echo $permalink; ?>" />
<style>.pembed,.pembed .play-button,.pembed img{cursor:pointer}.pembed iframe,.pembed img{height:100%;width:100%;top:0;left:0}.pembed{background-color:#000;margin-bottom:30px;position:relative;padding-top:56.25%;overflow:hidden}.pembed img{opacity:.7}.pembed .play-button{width:90px;height:60px;background-color:#333;box-shadow:0 0 30px rgba(0,0,0,.6);z-index:1;opacity:.8;border-radius:6px}.pembed .play-button:before{content:"";border-style:solid;border-width:15px 0 15px 26px;border-color:transparent transparent transparent #fff}.pembed .play-button,.pembed .play-button:before,.pembed iframe,.pembed img{position:absolute}.pembed .play-button,.pembed .play-button:before{top:50%;left:50%;transform:translate3d(-50%,-50%,0)}</style>
</head>
<body>
<div class="wrapper" id="<?php  echo $i ;  ?>">
<div class="pembed" data-embed="<?php echo $player; ?>">
<div class="play-button"></div></div></div>
<script>( function() {var pembed = document.querySelectorAll( ".pembed" );for (var i = 0; i < pembed.length; i++) {var source = "<?php echo $thumb_url[0]; ?>";var image = new Image();image.src = source;image.addEventListener( "load", function() {pembed[ i ].appendChild( image );}( i ) );pembed[i].addEventListener( "click", function() {var iframe = document.createElement( "iframe" );iframe.setAttribute( "frameborder", "0" );iframe.setAttribute( "allowfullscreen", "" );iframe.setAttribute( "scrolling", "no" );iframe.setAttribute( "src", "<?php //echo $api?>"+ this.dataset.embed +"" );this.innerHTML = "";this.appendChild( iframe );} );};})();</script>
</body>
</html>
<?php endif; ?>
