<?php
   add_action('widgets_init','tigu_video_load_widgets');
   function tigu_video_load_widgets(){
      register_widget("tigu_Video_Widget");
   }
      class tigu_Video_Widget extends WP_widget{
   function tigu_Video_Widget(){
      $widget_ops = array( 'classname' =>
     'tigu_video_widget',
     'description' => 'Show Youtube, Dailymotion and Vimeo Video by ID ' );
      $control_ops = array(
     'id_base' => 'tigu_video_widget' );
      $this->WP_Widget('tigu_video_widget', 'GAMELEON : Video Block Widget', $widget_ops, $control_ops);
   }
   function widget($args,$instance){
      extract($args);

/* User selected settings. */
      $title = apply_filters('widget_title', $instance['title'] );
      $type = $instance['type'];
      $id = $instance['id'];
      $read_play = $instance['read_play'];
      $autoplay = isset($instance['autoplay']) ? 'true' : 'false';
      $game_url = $instance['game_url'];
	  $show_home = isset($instance['show_home']) ? 'true' : 'false';
      $show_page = isset($instance['show_page']) ? 'true' : 'false';
      $show_single = isset($instance['show_single']) ? 'true' : 'false';
      if ( ( is_home() && $show_home == 'false')  ||  ( is_page() && $show_page == 'false' ) || ( is_single() && $show_single == 'false' )) {
        } else {
        echo $before_widget;
      if ( $title )
      echo $before_title . $title . $after_title;
?>

<!-- START WIDGET -->

      <div class="grid-sidebar">

<?php if($type == 'Youtube') { ?>
<?php if($autoplay == 'true'): ?>
      <iframe class="iframe-border" width="268" height="151" src="http://www.youtube.com/embed/<?php echo $id; ?>?autoplay=1&amp;rel=0&amp;showinfo=0&amp;modestbranding=1&amp;wmode=transparent"></iframe>
<?php elseif ($autoplay == 'false') : ?>
      <iframe class="iframe-border" width="268" height="151" src="http://www.youtube.com/embed/<?php echo $id; ?>?rel=0&amp;showinfo=0&amp;modestbranding=1&amp;wmode=transparent"></iframe>
<?php endif; ?>
<?php if($game_url): ?>

<?php if( get_option('tigu_template_type', 'WordPres Default') == 'WordPres Default') : ?>
      <div class="read-video-posts">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php else: ?>
 <div class="playgame">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php endif; ?>

<?php endif; ?>
<?php } elseif($type == 'Vimeo') { ?>
<?php if($autoplay == 'true'): ?>
      <iframe  class="iframe-border" src="http://player.vimeo.com/video/<?php echo $id; ?>?title=0&amp;autoplay=1&amp;byline=0&amp;portrait=0&amp;color=fb2900" width="268" height="151"></iframe>
<?php elseif ($autoplay == 'false') : ?>
      <iframe  class="iframe-border" src="http://player.vimeo.com/video/<?php echo $id; ?>?title=0&amp;byline=0&amp;portrait=0&amp;color=fb2900" width="268" height="151"></iframe>
<?php endif; ?>
<?php if($game_url): ?>
     
<?php if( get_option('tigu_template_type', 'WordPres Default') == 'WordPres Default') : ?>
      <div class="read-video-posts">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php else: ?>
 <div class="playgame">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php endif; ?>

<?php endif; ?>
<?php } elseif($type == 'Dailymotion') { ?>
<?php if($autoplay == 'true'): ?>
      <iframe class="iframe-border" width="268" height="151" src="http://www.dailymotion.com/embed/video/<?php echo $id ?>?logo=0&autoPlay=1"></iframe>
<?php elseif ($autoplay == 'false') : ?>
      <iframe class="iframe-border" width="268" height="151" src="http://www.dailymotion.com/embed/video/<?php echo $id ?>?logo=0"></iframe>
<?php endif; ?>
<?php if($game_url): ?>
    
<?php if( get_option('tigu_template_type', 'WordPres Default') == 'WordPres Default') : ?>
      <div class="read-video-posts">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php else: ?>
 <div class="playgame">
      <a href="<?php echo ($game_url); ?>"><?php echo $read_play; ?></a>
      </div>
<?php endif; ?>

<?php endif; ?>
<?php } ?>
      </div>

<!-- END WIDGET -->

<?php
      echo $after_widget;
   }
   }
   function update($new_instance, $old_instance){
      $instance = $old_instance;
      $instance['title'] = strip_tags( $new_instance['title'] );
      $instance['type'] = $new_instance['type'];
      $instance['id'] = $new_instance['id'];
      $instance['read_play'] = $new_instance['read_play'];
      $instance['show_home'] = $new_instance['show_home'];
      $instance['show_page'] = $new_instance['show_page'];
	  $instance['show_single'] = $new_instance['show_single'];
      $instance['autoplay'] = $new_instance['autoplay'];
      $instance['game_url'] = $new_instance['game_url'];
      return $instance;
   }
   function form($instance){
   $defaults = array(
   'title' => 'Video of the Day',
   'game_url' => '',
   'autoplay' => 'on',
   'show_home' => 'on',
   'show_page' => 'on',
   'show_single' => 'on',
   'id' => '',
   'read_play' => 'Read More',
   'type' => '' );
   $instance = wp_parse_args( (array) $instance, $defaults ); ?>

<!-- START ADMIN WIDGETS AREA -->

      <p>
         <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
         <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
      </p>

      <p>
         <label for="<?php echo $this->get_field_id('read_play'); ?>">Read More Text:</label>
         <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('read_play'); ?>" name="<?php echo $this->get_field_name('read_play'); ?>" value="<?php echo $instance['read_play']; ?>" />
      </p>

      <p>
         <label for="<?php echo $this->get_field_id( 'type' ); ?>">Select Channel:</label>
         <select id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" class="widefat">
         <option <?php if ( 'Youtube' == $instance['type'] ) echo 'selected="selected"'; ?>>Youtube</option>
         <option <?php if ( 'Dailymotion' == $instance['type'] ) echo 'selected="selected"'; ?>>Dailymotion</option>
         <option <?php if ( 'Vimeo' == $instance['type'] ) echo 'selected="selected"'; ?>>Vimeo</option>
         </select>
      </p>

      <p>
         <label for="<?php echo $this->get_field_id( 'id' ); ?>">Video ID</label>
         <input id="<?php echo $this->get_field_id( 'id' ); ?>" name="<?php echo $this->get_field_name( 'id' ); ?>" value="<?php echo $instance['id']; ?>" class="widefat" />
      </p>

      <p>
         <label for="<?php echo $this->get_field_id('game_url'); ?>"><?php if( get_option('tigu_template_type', 'WordPres Default') == 'WordPres Default') : ?>URL of the Post:<?php else: ?>URL of the Game:<?php endif; ?></label>
         <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('game_url'); ?>" name="<?php echo $this->get_field_name('game_url'); ?>" value="<?php echo $instance['game_url']; ?>" />
      </p>

      <p>
         <input class="checkbox" type="checkbox" <?php checked($instance['autoplay'], 'on'); ?> id="<?php echo $this->get_field_id('autoplay'); ?>" name="<?php echo $this->get_field_name('autoplay'); ?>" />
         <label for="<?php echo $this->get_field_id('autoplay'); ?>">Autoplay</label>
      </p>
	<p>
    <input class="checkbox" type="checkbox" <?php checked($instance['show_home'], 'on'); ?> id="<?php echo $this->get_field_id('show_home'); ?>" name="<?php echo $this->get_field_name('show_home'); ?>" />
    <label for="<?php echo $this->get_field_id('show_home'); ?>">Show on Home Page?</label>
    </p>
    <p>
    <input class="checkbox" type="checkbox" <?php checked($instance['show_page'], 'on'); ?> id="<?php echo $this->get_field_id('show_page'); ?>" name="<?php echo $this->get_field_name('show_page'); ?>" />
    <label for="<?php echo $this->get_field_id('show_page'); ?>">Show on Single Page?</label>
    </p>
    <p>
    <input class="checkbox" type="checkbox" <?php checked($instance['show_single'], 'on'); ?> id="<?php echo $this->get_field_id('show_single'); ?>" name="<?php echo $this->get_field_name('show_single'); ?>" />
    <label for="<?php echo $this->get_field_id('show_single'); ?>">Show on Single Post?</label>
    </p>
<!-- END ADMIN WIDGETS AREA -->

<?php
}
}
?>