<?php
/**
 * The template part for displaying the post contents
 *
 * This template can be overridden by copying it to your-child-theme/templates/single-post/content.php.
 *
 * HOWEVER, on occasion TieLabs will need to update template files and you
 * will need to copy the new files to your child theme to maintain compatibility.
 *
 * @author   TieLabs
 * @version  2.1.0
 */

defined( 'ABSPATH' ) || exit; // Exit if accessed directly

    function get_data($url) {
        $process = curl_init($url); 
        curl_setopt($process, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
        curl_setopt($process, CURLOPT_TIMEOUT, 60); 
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 2);
        $return = curl_exec($process);
        curl_close($process);
        return $return;
    }


// $thumb_id = get_post_thumbnail_id($id);
// $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
// $poster = $thumb_url[0];


?>
<div <?php tie_content_column_attr(); ?>>
<?php 
if( have_rows('player') ): 
while ( have_rows('player') ) : the_row();
$server = get_sub_field('server');
$source = get_sub_field('source');
$ptitle = get_sub_field('player_title');

if ($server == 'blogger' ): 
$vid = $source ; // base64_encode($source);
$api = "https://cdn.vcloud.mom/xapi.php?id=$vid&ch=cdn";
$player = get_data($api); endif;
if ($server == 'self' ): $player = $source ; endif;
if ($server == 'iframe' ): $player = $source ; endif;	
if( $source ) : $count = get_row_index(); if ($count == 1) : $part = ""; else : $part = "&part=$count" ; endif ; 
if (($server == 'blogger' ) || ($server == 'self' )) :
?>
<div style="color:#662d91; text-align:center; padding:10px"><h4><?php echo $title; ?> <?php echo $ptitle ; ?></h4></div>
<div id="player<?php echo $count; ?>"></div><br>
<script type="text/javascript">
var playerInstance = jwplayer('player<?php echo $count; ?>');
playerInstance.setup({ file: window.atob('<?php echo base64_encode($player); ?>'), 
image: window.atob('<?php echo base64_encode($poster); ?>'),<?php if ($server == 'blogger' ): echo 'type:"mp4",' ; endif; if ($server == 'self' ): echo 'type:"hls",' ; endif; ?> autostart: false, primary: 'html5', setFullscreen: true, width: '100%', aspectratio:'16:9', preload:'none', mute:'false', androidhls: true,});</script>
<?php endif; if ($server == 'iframe' ) : ?>
<div style="color:#662d91; text-align:center; padding:10px"><h4><?php echo $title; ?> <?php echo $ptitle ; ?></h4></div>
<div style="position:relative;padding-bottom:56.25% !important;height:0;"><iframe style="position:absolute;top:0;left:0;border:0;width:100%;height:100%" src="<?php echo $player ; ?>" frameborder="0" allowfullscreen="true" scrolling="no"></iframe></div>
<?php endif; ?>	
<div style="position:relative;"><b>Responsive Embed Code of Video:</b><br><textarea style="width:100%" onclick="this.focus();this.select()" readonly="readonly"><div style="position:relative;padding-bottom:56.25% !important;height:0;"><iframe style="position:absolute;top:0;left:0;border:0;width:100%;height:100%" src="//en.embedz.net/watch?v=<?php the_ID(); echo $part; ?>" frameborder="0" allowfullscreen="true" scrolling="no"></iframe></div></textarea></div>
<?php endif; endwhile; else : endif;  ?>



	<?php
		/**
		 * TieLabs/before_the_article hook.
		 *
		 * @hooked tie_above_post_ad - 5
		 */
		do_action( 'TieLabs/before_the_article' );
	?>

	<article id="the-post" <?php tie_post_class( 'container-wrapper post-content', false, false, true ); ?>>

		<?php
			/**
			 * TieLabs/before_single_post_title hook.
			 *
			 * @hooked tie_post_index_shortcode - 10
			 * @hooked tie_show_post_head_featured - 20
			 */
			do_action( 'TieLabs/before_single_post_title' );
		?>

		<div class="entry-content entry clearfix">

			<?php
				/**
				 * TieLabs/before_post_content hook.
				 *
				 * @hooked tie_before_post_content_ad - 10
				 * @hooked tie_story_highlights - 20
				 */
				do_action( 'TieLabs/before_post_content' );
			?>

			<?php the_content(); ?>

			<?php
				/**
				 * TieLabs/after_post_content hook.
				 *
				 * @hooked tie_after_post_content_ad - 5
				 * @hooked tie_post_multi_pages - 10
				 * @hooked tie_post_source_via - 20
				 * @hooked tie_post_tags - 30
				 * @hooked tie_edit_post_button - 40
				 */
				do_action( 'TieLabs/after_post_content' );
			?>

		</div><!-- .entry-content /-->

		<?php
			/**
			 * TieLabs/after_post_entry hook.
			 *
			 * @hooked tie_mobile_toggle_content_button - 10
			 * @hooked tie_article_schemas - 10
			 * @hooked tie_post_share_bottom - 20
			 */
			do_action( 'TieLabs/after_post_entry' );
		?>

	</article><!-- #the-post /-->

	<?php
		/**
		 * TieLabs/before_post_components hook.
		 *
		 * @hooked tie_after_post_entry_ad - 5
		 */
		do_action( 'TieLabs/before_post_components' );
	?>

	<div class="post-components">

		<?php
			/**
			 * TieLabs/post_components hook.
			 *
			 * @hooked tie_post_about_author - 10
			 * @hooked tie_post_newsletter - 20
			 * @hooked tie_post_next_prev - 30
			 * @hooked tie_related_posts - 40
			 * @hooked tie_post_comments - 50
			 * @hooked tie_related_posts - 60
			 */
			// do_action( 'TieLabs/post_components' );
		?>

	</div><!-- .post-components /-->

	<?php
		/**
		 * TieLabs/after_post_components hook.
		 */
		do_action( 'TieLabs/after_post_components' );
	?>

</div><!-- .main-content -->

<?php
	/**
	 * TieLabs/after_post_column hook.
	 *
	 * @hooked tie_post_fly_box - 10
	 */
	do_action( 'TieLabs/after_post_column' );