<?php 

add_action('widgets_init','mom_video_widget');

function mom_video_widget() {
	register_widget('mom_video_widget');
	
	}

class mom_video_widget extends WP_Widget {
	function mom_video_widget() {
			
		$widget_ops = array('classname' => 'momizat-video','description' => __('Widget display viddeo support Youtube, vimeo, dailymotion or self hosted HTML5 video','theme'));
		$this->WP_Widget('momizatVideo',__('Momizat - Video','theme'),$widget_ops);

		}
		
	function widget( $args, $instance ) {
		extract( $args );
		/* User-selected settings. */
		$title = apply_filters('widget_title', $instance['title'] );
		$type = $instance['type'];
		$id = $instance['id'];
		$poster = $instance['poster'];
		$mp4 = $instance['mp4'];
		$m4v = $instance['m4v'];
		$webm = $instance['webm'];
		$ogv = $instance['ogv'];
		$wmv = $instance['wmv'];
		$flv = $instance['flv'];
		

		/* Before widget (defined by themes). */
		echo $before_widget;

		/* Title of widget (before and after defined by themes). */
		if ( $title )
			echo $before_title . $title . $after_title;
?>
	<?php if($type == 'Youtube') { ?>
	<iframe width="220" height="180" src="http://www.youtube.com/embed/<?php echo $id; ?>?rel=0" frameborder="0" allowfullscreen></iframe>
	<?php } elseif($type == 'Vimeo') { ?>
	<iframe src="http://player.vimeo.com/video/<?php echo $id; ?>?title=0&amp;byline=0&amp;portrait=0&amp;color=ba0d16" width="220" height="180" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
	<?php } elseif($type == 'Dialymotion') { ?>
<iframe frameborder="0" width="220" height="180" src="http://www.dailymotion.com/embed/video/<?php echo $id ?>?logo=0"></iframe>
	<?php } ?>
<?php 
		/* After widget (defined by themes). */
		echo $after_widget;
	}
	
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		/* Strip tags (if needed) and update the widget settings. */
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['type'] = $new_instance['type'];
		$instance['id'] = $new_instance['id'];
		$instance['poster'] = $new_instance['poster'];
		$instance['mp4'] = $new_instance['mp4'];
		$instance['m4v'] = $new_instance['m4v'];
		$instance['webm'] = $new_instance['webm'];
		$instance['ogv'] = $new_instance['ogv']; 
		$instance['wmv'] = $new_instance['wmv'];
		$instance['flv'] = $new_instance['flv'];		

		return $instance;
	}
	
function form( $instance ) {

		/* Set up some default widget settings. */
		$defaults = array( 'title' => __('Video','theme'), 
 			);
		$instance = wp_parse_args( (array) $instance, $defaults );
	
	$id = isset($instance['id']) ? $instance['id'] : '';
	$type = isset($instance['type']) ? $instance['type'] : '';

		?>
	
		<p>
		<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'theme') ?></label>
		<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>"  class="widefat" />
		</p>

	<p>
<label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php _e('type', 'theme') ?></label>
<select id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" class="widefat">
<option value="youtube"><?php _e('Youtube', 'theme'); ?></option>
<option value="vimeo"><?php _e('Vimeo', 'theme'); ?></option>
<option value="daily"><?php _e('Dailymotion', 'theme'); ?></option>
<option value="html5"><?php _e('Self hosted HTML5', 'theme'); ?></option>
</select>
	</p>

		<p>
		<label for="<?php echo $this->get_field_id( 'id' ); ?>"><?php _e('Video ID:', 'theme') ?></label>
		<input type="text" id="<?php echo $this->get_field_id( 'id' ); ?>" name="<?php echo $this->get_field_name( 'id' ); ?>" value="<?php echo $ids; ?>" class="widefat" />
		</p>


        
   <?php 
}
	} //end class