<?php

class core_videos extends white_label_themes {

 
	function __construct(){ global $wpdb;
	
		if(is_admin()){		 
  		 
			add_action('hook_admin_1_pagesetup', array($this, '_hook_admin_1_pagesetup'  ) ); 
 
		}
		
		// MOBILE VERSION
		add_action('hook_mobile_content_listing', array($this, '_hook_mobile_content_listing' ), 1 );
		
		// HOOK IN TEAER
		add_action('wp_footer', array($this, 'TEASER' ) );
 
 		// HOOK HEADER
		add_action('hook_header_style5', array($this, '_hook_header_searchbox' ) );
	
	}// end function
	
	
	
	function _hook_mobile_content_listing(){ $GLOBALS['CUSTOMMOBILECONTENT'] = true; global $post;  
 
	global $post, $userdata, $CORE; 	 
	
	ob_start();
	
	if($post->post_author == $userdata->ID){ ?><a href="[EDIT]">Edit</a><?php } ?>
	
	<div class="listingblock"> 
	
        <h1>[TITLE]</h1>
         
        <div class="text-center">[VIDEO]</div>
        
    	<ul class="menulist"> 
                        
            <li>[FAVS]</li> 
        
        </ul>
        
        <hr />
        
        <?php if(defined('WLT_MICROJOB')){ ?>
        <style>
		#infobarbox li { width:100% !important;}
		</style>
        [INFOBAR]
    	<hr />
     	[BUYBAR]
        <hr />
        
        <?php }elseif(defined('WLT_COMPARISON')){ ?>
        [COMPARISONTABLE] 
        <?php }else{ ?>
        [FIELDS]
        <?php } ?>
        
        <b>{Description}</b>
        
        [CONTENT] 
        
        [GOOGLEMAP]
	
	</div>
	
	<?php
	
	$SavedContent = ob_get_clean(); 
	RETURN $SavedContent;
	 } 

function _hook_header_searchbox($c){ global $CORE, $userdata;

if(strlen($c) > 2){ return $c; }

// COUNT USERS
$result = count_users();

// COUNT LISTINGS
$count_listings = wp_count_posts(THEME_TAXONOMY."_type");
 
 
ob_start();

?>

<div class=" hidden-sm hidden-xs row">

    <div class="col-md-4 headbox text-right">
    
    <i class="fa fa-users"></i>
    
    <h5><?php echo $CORE->_e(array('mjob','44')); ?></h5>
     
    <h4><?php if(defined('WLT_DEMOMODE')){ echo "46,900"; }else{ echo number_format($result['total_users']); } ?></h4>
     
    </div>
    <div class="col-md-4 headbox text-right">
    
    <i class="fa fa-play-circle"></i>
     
    <h5>Videos</h5>
     
    <h4><?php if(defined('WLT_DEMOMODE')){ echo "435,345"; }else{ echo $count_listings->publish; } ?></h4>
     
    </div>
    
    <div class="col-md-4 headbox text-center">
    
    <a class="btn btn-lg btn-primary" href="<?php echo $GLOBALS['CORE_THEME']['links']['add']; ?>">Upload Video</a>                 
    
    </div>

</div>

<?php

return  ob_get_clean();
} 
	
	
	
	
function TEASER(){ global $userdata, $post; $time = "";

if(isset($GLOBALS['CORE_THEME']['videoteaser']) && !empty($GLOBALS['CORE_THEME']['videoteaser'])  ){

// DONT DO IT TO YOUR OWN VIDEOS
if($userdata->ID == $post->post_author){ return; }

	/// CHECK  ACCESS
	if($userdata->ID){
	
		$current_membership	= get_user_meta($userdata->ID,'wlt_membership',true);
		
		// 100 is member access id
		if($current_membership == "" && isset($GLOBALS['CORE_THEME']['videoteaser'][1]['time']) && is_numeric($GLOBALS['CORE_THEME']['videoteaser'][1]['time']) ){
			$time = $GLOBALS['CORE_THEME']['videoteaser'][1]['time'];
			$showid = 1;
		}
		 
	
	}else{ // GUEST
		
		if( isset($GLOBALS['CORE_THEME']['videoteaser'][0]['time']) && is_numeric($GLOBALS['CORE_THEME']['videoteaser'][0]['time']) ){
			$time = $GLOBALS['CORE_THEME']['videoteaser'][0]['time'];
			$showid = 0;
		}
	}	
 
	if(isset($time) && is_numeric($time) ){
	
	ob_start();
	?>    
    <script>
	jQuery(window).load(function() {
	 
		jQuery( ".videotime<?php echo $post->ID; ?>" ).change(function() {
	 
		  if(jQuery(".videotime<?php echo $post->ID; ?>").val() > <?php echo $time; ?>){
		  jQuery(".mejs-pause").trigger('click');   
		  jQuery('.videobox<?php echo $post->ID; ?>').html(jQuery('.thiscodetocopy').html());
		  }
		});
	
	});
	</script>
    <div class="thiscodetocopy" style="display:none">
    <?php echo wpautop(stripslashes($GLOBALS['CORE_THEME']['videoteaser'][$showid]['html'])); ?>
    </div>  
    <?php
	$SavedContent = ob_get_clean();
	echo $SavedContent;
	}

}	
	
}
	
	
 
	
	//  HOOK INTO THE ADMIN MENU TO CREATE A NEW TAB
	function _hook_admin_1_pagesetup(){  global $wpdb, $CORE; $core_admin_values = get_option("core_admin_values");  ?>
	
	<div class="accordion-group">
    <div class="accordion-heading" style="background:#fff;">
        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#pagesetup_according" href="#extra1">
         <h4 style="margin:0xp;font-weight:bold;">
         <img src="<?php echo get_template_directory_uri(); ?>/framework/admin/img/icons/set.png">
        Video Settings <span style="font-size:12px;">(view/hide)</span></h4> 
        </a>
    </div>
    
    <div id="extra1" class="accordion-body collapse">
    <div class="accordion-inner">
    <div class="innerwrap content">
    
<?php $i=0; while($i < 2){ ?>
 
 

<div style="padding:10px;  background: rgb(252, 252, 252);  border: 1px solid rgb(223, 223, 223); margin-top:30px;">

<div style="  font-size: 30px;
  margin-top: -30px;
  background: #fff;
  padding: 10px;
  width: 200px;
  border: 1px solid #ddd;"><?php if($i == 0){ ?>Guest Users<?php }else{ ?> Members <div style="font-size:14px; line-height:30px;">(no subscirption)</div><?php } ?></div>

<hr />

<div class="row-fluid">

<div class="span6">
	<label><b>How long can the user watch a video for?</b></label>
	<small>Leave blank to allow full access.</small>
</div>

<div class="span6">

    <div class="controls input-append">        
            <input name="admin_values[videoteaser][<?php echo $i; ?>][time]" type="text" value="<?php if(isset($core_admin_values['videoteaser'])){ echo $core_admin_values['videoteaser'][$i]['time']; } ?>" style="width:200px;"/>
            <span class="add-on">seconds</span>        
    </div>

</div>

</div>


<hr />
<label><b> What messsage should we display? </b></label>
<p>Enter the content below you want to show to the user once the time period has been reached.</p>
<hr />

<?php 
$content = "";
if(isset($core_admin_values['videoteaser'])){ $content = stripslashes($core_admin_values['videoteaser'][$i]['html']); }

wp_editor( $content, 'videoteaser_editor'.$i, $settings = array('textarea_name' => 'admin_values[videoteaser][' .$i. '][html]' ) ); ?>

</p></div>
 
<?php $i++; } ?>

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

 

<input type="hidden" value="" name="imgIdblock" id="imgIdblock" />
<script type="text/javascript">
function ChangeImgBlock(divname){
document.getElementById("imgIdblock").value = divname;
} 
jQuery(document).ready(function() {
	
	window.restore_send_to_editor = window.send_to_editor;
	
	jQuery('.gicon-search').click(function() {
		window.send_to_editor = function(html) {	 
		 imgurl = jQuery('img',html).attr('src'); 
		 jQuery('#'+document.getElementById("imgIdblock").value).val(imgurl);
		 tb_remove();	 
		  window.send_to_editor = window.restore_send_to_editor;		  
		} 
	});
	
	jQuery('#insert-media-button').click(function() {
	window.send_to_editor = window.restore_send_to_editor;	
	});
	
});


</script>   
     
     
     
     
     <?php }

}

?>