<?php
/** "Video_player" block 
 * 
 * 
 * Video Player
**/

	function video_player_wpthematic_js_loader() 
{
	
	$script = '<script type="text/javascript" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-pager/assets/js/flowplayer.js"></script>';
	
	echo $script;
	$script_ipad = '<script type="text/javascript" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-pager/assets/js/flowplayer.ipad.js"></script>';
	
	echo $script_ipad;
	wp_enqueue_style( 'minimalist', plugins_url('assets/skin/minimalist.css' , dirname(__FILE__) ) );
		
}
add_action('wp_head', 'video_player_wpthematic_js_loader');
add_action( 'admin_enqueue_scripts', 'video_player_wpthematic_js_loader' );

function add_allowed_mime_types_wpthematic($mimes) {
    $my_new_mimes = array (
        'webm' => 'video/webm'
    );
    return array_merge($mimes,$my_new_mimes);
}
add_filter('upload_mimes','add_allowed_mime_types_wpthematic');
 
// Add an extension to (2) function wp_ext2type
function add_ext2_ext2type_wpthematic($ext) {
    $my_new_extensions = array (
        'video' => array( 'webm' )
    );
    return array_merge($ext,$my_new_extensions);
}

add_filter('upload_mimes','add_ext2_ext2type_wpthematic');

// Define class
class AQ_Video_Player_Block extends AQ_Block {
	
	//set and create block
	function __construct() {
		$block_options = array(
			'name' => 'Lecteur Video',
			'size' => 'span12',
			
		);
		
		//create the block
		parent::__construct('aq_video_player_block', $block_options);
	}
	
	function form($instance) {
	
		
		$instance = wp_parse_args($instance, $defaults);
		extract($instance);
		
		$line_color = isset($line_color) ? $line_color : '#353535';
		
		?>
		<p class="description note">
			<?php _e('Utiliser ce bloc  pour afficher une vidéo au format MP4/H.264/AAC   <em>(.mp4, .mov, .m4v)</em>.', 'wpthematic') ?>
		</p>
     
         <p class="description">
       <label for="<?php echo $this->get_field_id('title') ?>">
				 Titre
				<?php echo aq_field_input('title', $block_id, $title, $size = 'full') ?>
			</label>
            
</p>
                    
                    
<p class="description note">
    <label for="<?php echo $this->get_field_id('video') ?>">
       Téléchargez une Video (mp4)<br/>
        <?php echo aq_field_upload_video('video', $block_id, $video, $media_type = 'video') ?>
    </label>
    <?php echo'
    <div class="flowplayer">
      <video>
		<source type="video/mp4" src="'.$video.'"/>
	  </video>
   </div>';?>
</p>

<p class="description note">
    <label for="<?php echo $this->get_field_id('video_image') ?>">
       Téléchargez une image de démarage pour la vidéo<br/>
        <?php echo aq_field_upload('video_image', $block_id, $video_image, $media_type = 'image') ?>
    </label>
<div class="video-image-admin"><img src="<?php echo $video_image;?>"/></div> </p>
<p class="description note">
<label for="<?php echo $this->get_field_id('bg_video_color') ?>">
				Couleur de fond si il ni a pas d'image
				<?php echo aq_field_color_picker('bg_video_color', $block_id, $bg_video_color, $defaults['bg_video_color']) ?>
			</label>
            <p class="description note">
         <label for="<?php echo $this->get_field_id('text_video') ?>">
				Description
				<?php echo aq_field_textarea('text_video', $block_id, $text_video, $size = 'full') ?>
			</label>
		</p>
		<?php
		
	}
	

	function block($instance) {
		extract($instance);
		$output .= '<h2 class="title-video"><span>'.$title.'</span></h2>';
		$output .= '<div class="flowplayer" style="background:'.$bg_video_color.' url('.$video_image.') no-repeat;
													background-repeat:no-repeat;
													background-size:contain;
													background-position:center;" preload="true">
      <video>
		<source type="video/mp4" src="'.$video.'"/>
		
	  </video>
	 
   </div>
	  '.$text_video.'';
	  
	
	echo $output;
		
	}
	
}