<?php
  add_action( 'widgets_init', 'tigu_google_plus_load_widgets' );
    function tigu_google_plus_load_widgets() {
	register_widget( 'Tigu_Google_Plus_Widget' );
}
    class Tigu_Google_Plus_Widget extends WP_Widget {
  function Tigu_Google_Plus_Widget() {
  $widget_ops = array(
       'classname' => 'google_plus',
       'description' => 'Google Plus Widget for sidebar');
  $control_ops = array(
       'id_base' => 'tigu_google_plus' );
  $this->WP_Widget( 'tigu_google_plus','GAMELEON: Google Plus', $widget_ops, $control_ops );
}

  function widget( $args, $instance ) {
  extract( $args );

/* User selected settings. */
  $title = apply_filters('widget_title', $instance['title'] );
  $page_url = $instance['page_url'];
  $theme = $instance['theme'];
  $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;
?>
<?php
   if($title) {
   echo $before_title.$title.$after_title;
   }
?>

<!-- START WIDGET -->

   <div class="grid-sidebar">
   <div class="content">
   <div class="google-plus">
      <!-- Google +1 script -->
<script type="text/javascript">
      (function() {
      var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
      po.src = 'https://apis.google.com/js/plusone.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
      })();
</script>
<!-- Link blog to Google+ page -->
   <a href="<?php echo $page_url ?>" data-rel="publisher">&nbsp;</a>
<!-- Google +1 Page badge -->
<div id="social_gplus_circle">
<div id="social_gplus_circle_inner">
 <div class="g-plus" data-width="290" data-href="<?php echo $page_url ?>" data-rel="publisher"></div>

<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
   </div>
   </div>
   </div>
   </div>
   </div>

<!-- END WIDGET -->

<?php
   echo $after_widget;
   }
   }
   function update( $new_instance, $old_instance ) {
   $instance = $old_instance;
   $instance['title'] = strip_tags( $new_instance['title'] );
   $instance['show_home'] = $new_instance['show_home'];
   $instance['show_page'] = $new_instance['show_page'];
   $instance['show_single'] = $new_instance['show_single'];
   $instance['page_url'] = strip_tags( $new_instance['page_url'] );
   $instance['theme'] = $new_instance['theme'];
   return $instance;
}

   function form( $instance ) {
   $defaults = array(
              'title' => 'Follow us on Google+',
              'theme' => 'light',
              'page_url' =>'',
	          'show_home' => 'on',
              'show_single' => 'on',
              'show_page' => 'on');
   $instance = wp_parse_args((array) $instance, $defaults); ?>

<!-- START ADMIN WIDGETS AREA -->

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

	<p>
	  <label for="<?php echo $this->get_field_id('theme'); ?>">Color Theme:</label>
    	<select id="<?php echo $this->get_field_id('theme'); ?>" name="<?php echo $this->get_field_name('theme'); ?>" class="widefat" style="width:100%;">
	      <option <?php if ('light' == $instance['theme']) echo 'selected="selected"'; ?>>light</option>
	      <option <?php if ('dark' == $instance['theme']) echo 'selected="selected"'; ?>>dark</option>
	</select>
    </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>
    <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
}
}
?>