<?php
   add_action('widgets_init', 'tigu_social_tabs_load_widgets');
   function tigu_social_tabs_load_widgets()
   {
      register_widget('Tigu_Social_Tabs_Widget');
   }
      class Tigu_Social_Tabs_Widget extends WP_Widget {
   function Tigu_Social_Tabs_Widget()
   {
      $widget_ops = array( 'classname' => 
     'tigu_social_tabs', 
     'description' => 'Social Tabs Widget for Sidebar' );
      $control_ops = array( 
     'id_base' => 'tigu_social_tabs' );
      $this->WP_Widget('tigu_social_tabs', 'GAMELEON: Social Tabs', $widget_ops, $control_ops);
   }
   function widget($args, $instance)
   {
      extract($args);
/* User selected settings. */
	$show_facebook = isset($instance['show_facebook']) ? 'true' : 'false';
	$show_twitter = isset($instance['show_twitter']) ? 'true' : 'false';
	$show_google = isset($instance['show_google']) ? 'true' : 'false';
    $fb_id = $instance['fb_id'];
    $color_scheme = 'light';
    $show_faces = true;
    $show_stream = false;
    $show_header = false;
    $width  = '287';
    $height = '310';
    $twitter_username = $instance['twitter_username'];
    $widget_id = $instance['widget_id'];
    $twitter_height = $instance['twitter_height'];
    $twitter_theme = $instance['twitter_theme'];
    $twitter_link_color = $instance['twitter_link_color'];
    $google_page = $instance['google_page'];
	$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;
?>

<!-- START WIDGET -->

<div class="tabs-wrapper">

<ul class="tabs" style="padding:0px; width:298px; border-bottom:none;">

<?php if($show_facebook == 'true'): ?>
<li class="" style="border-bottom:none; width:106px;">
<a style="width:76px;" href="#tab-social-1"><?php _e('Facebook', 'Gameleon'); ?></a>
</li>
<?php endif; ?>

<?php if($show_twitter == 'true'): ?>
<li class="" style="border-bottom:none; width:95px;">
<a style="width:65px;" href="#tab-social-2"><?php _e('Twitter', 'Gameleon'); ?></a>
</li>
<?php endif; ?>

<?php if($show_google == 'true'): ?>
<li class="" style="border-bottom:none; border-right:none;">
<a style="width:65px;" href="#tab-social-3"><?php _e('Google', 'Gameleon'); ?></a>
</li>
<?php endif; ?>

</ul>

<!-- ********************************** Facebook Area ************************************** -->

<?php if($show_facebook == 'true'): ?>
<div id="tab-social-1" class="tab_content" style="display:block;">

      <div class="facebooklike">
      <div class="facebookInner">
      <div id="likebox-frame">
      <div class="fb-like-box" data-href="http://www.facebook.com/<?php echo $fb_id; ?>" data-width="<?php echo $width; ?>" data-show-faces="<?php echo $show_faces; ?>" data-stream="false" data-header="false" data-height="<?php echo $height; ?>" data-show-border="false" data-colorscheme="<?php echo $color_scheme; ?>"></div>
      </div>
      </div>
      </div>
</div>
<?php endif; ?>

<!-- ************************************ Twitter Area ************************************ -->

<?php if($show_twitter == 'true'): ?>
<div id="tab-social-2" class="tab_content" style="display:none;">
<div class="grid-sidebar">

     <a class="twitter-timeline" data-chrome="nofooter noborders noscrollbar" data-theme="<?php echo $twitter_theme; ?>" data-link-color="<?php echo $twitter_link_color; ?>" height="<?php echo $twitter_height; ?>"  href="https://twitter.com/twitterapi" data-widget-id="<?php echo $widget_id; ?>">Tweets by @<?php echo $twitter_username; ?></a>

    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

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


<!-- ********************************* Google + Area **************************************** -->
<?php if($show_google == 'true'): ?>
<div id="tab-social-3" class="tab_content" style="display:none;">
<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>
   <a href="<?php echo $google_page ?>" 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 $google_page ?>" 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>
</div>
<?php endif; ?>

<!-- **********************************End Socials Areas*********************************** -->

</div>

<!-- END SOCIAL TABS -->

<?php
      echo $after_widget;
   }
   }

  function update($new_instance, $old_instance)
   {
   $instance = $old_instance;
   $instance['show_facebook'] = $new_instance['show_facebook'];
   $instance['show_twitter'] = $new_instance['show_twitter'];
   $instance['show_google'] = $new_instance['show_google'];    
   $instance['fb_id'] = $new_instance['fb_id'];   
   $instance['twitter_username'] = strip_tags($new_instance['twitter_username']);
   $instance['widget_id'] = strip_tags($new_instance['widget_id']);
   $instance['twitter_height'] = strip_tags($new_instance['twitter_height']);
   $instance['twitter_theme'] = strip_tags($new_instance['twitter_theme']);
   $instance['twitter_link_color'] = strip_tags($new_instance['twitter_link_color']);
   $instance['show_home'] = $new_instance['show_home'];
   $instance['show_page'] = $new_instance['show_page'];
   $instance['show_single'] = $new_instance['show_single'];
   $instance['google_page'] = strip_tags( $new_instance['google_page'] );
   return $instance;
   }
   function form($instance)
   {
      $defaults = array( 'show_facebook' => 'on', 
     'show_twitter' => 'on', 
     'show_google' =>  'on', 
     'fb_id' => '', 
     'width' => '292', 
     'color_scheme' => 'light', 
     'show_faces' => 'on', 
     'show_stream' => false, 
     'show_header' => false, 
     'twitter_username' => '',
     'widget_id' => '',
     'twitter_height' => 400,
     'twitter_theme' => '',
     'twitter_link_color' => '#00B2FF',
 	 'show_home' => 'on',
     'show_page' => 'on',
     'show_single' => 'on',
     'google_page' => '' 
);
      $instance = wp_parse_args((array) $instance, $defaults); ?>

<!-- START ADMIN WIDGETS AREA -->
<div style="border:1px solid #008EFF; padding:10px;"> 
		<p>
			<input class="checkbox" type="checkbox" <?php checked($instance['show_facebook'], 'on'); ?> id="<?php echo $this->get_field_id('show_facebook'); ?>" name="<?php echo $this->get_field_name('show_facebook'); ?>" /> 
			<label for="<?php echo $this->get_field_id('show_facebook'); ?>">Show Facebook Tab</label>
		</p>
		<p>
			<input class="checkbox" type="checkbox" <?php checked($instance['show_twitter'], 'on'); ?> id="<?php echo $this->get_field_id('show_twitter'); ?>" name="<?php echo $this->get_field_name('show_twitter'); ?>" /> 
			<label for="<?php echo $this->get_field_id('show_twitter'); ?>">Show Twitter Tab</label>
		</p>
		<p>
			<input class="checkbox" type="checkbox" <?php checked($instance['show_google'], 'on'); ?> id="<?php echo $this->get_field_id('show_google'); ?>" name="<?php echo $this->get_field_name('show_google'); ?>" /> 
			<label for="<?php echo $this->get_field_id('show_google'); ?>">Show Google+ Tab</label>
		</p>
</div><br />
<div style="border:1px solid #008EFF; padding:10px;"> 
	<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>
</div><br />

 <div style="border:1px solid #fb2900; padding:10px;">
<h3 style='margin-top: 30px;'>Facebook</h3>
      <p>
      <label for="<?php echo $this->get_field_id('fb_id'); ?>"><strong>Facebook ID:</strong></label>
      <input class="widefat" type="text" id="<?php echo $this->get_field_id('fb_id'); ?>" name="<?php echo $this->get_field_name('fb_id'); ?>" value="<?php echo $instance['fb_id']; ?>" />
     <br /><br />
<small>If your facebook page address is http://facebook.com/gameleon, your facebook id is "gameleon". If your facebook page ID has numbers for e.x: http://facebook.com/gameleon/46327774632 then your facebook ID is "46327774632".</small>

 </p>
</div><br /> 
 <div style="border:1px solid #fb2900; padding:10px;"> 
<h3 style='margin-top: 10px;'>Twitter</h3>
	<p>
	<label for="<?php echo $this->get_field_id('twitter_username'); ?>"><strong>Twitter Username:</strong></label>
	<input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_username'); ?>" name="<?php echo $this->get_field_name('twitter_username'); ?>" value="<?php echo $instance['twitter_username']; ?>" />
	</p>

    <p>
<small>Now, <a style="color:red;" target="blank" href="https://twitter.com/settings/widgets">create a Twitter widget</a> and obtain a widget ID. After widget creation, the Widget ID will be a number on the url between the widgets and edit portion of the url. Example: <br />www.twitter.com/settings/widgets/<span style="color:red">3469915</span>/edit... See the theme documentation for more info.</small><br /><br />

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

    <p>
	<label for="<?php echo $this->get_field_id('twitter_height'); ?>"><strong>Height of Timeline:</strong><br /><small>*The minimum height is 200</small></label>
	<input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_height'); ?>" name="<?php echo $this->get_field_name('twitter_height'); ?>" value="<?php echo $instance['twitter_height']; ?>" />
	</p>

    <p>
	<label for="<?php echo $this->get_field_id('twitter_theme'); ?>"><strong>Timeline Theme Background Color:</strong><br /><small>*Leave the field empty for default theme(white) or enter <em>dark</em> for a dark theme</small></label>
	<input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_theme'); ?>" name="<?php echo $this->get_field_name('twitter_theme'); ?>" value="<?php echo $instance['twitter_theme']; ?>" />
	</p>

    <p>
	<label for="<?php echo $this->get_field_id('twitter_link_color'); ?>"><strong>Timeline Links Color:</strong><br /><small>*Set the links color by adding the desired hex code. The default links color is <em>#00B2FF</em>. Please use hex format color e.g. <em>#00B2FF</em></small></label>
	<input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_link_color'); ?>" name="<?php echo $this->get_field_name('twitter_link_color'); ?>" value="<?php echo $instance['twitter_link_color']; ?>" />
	</p>

 </div><br /> 
 <div style="border:1px solid #fb2900; padding:10px;"> 
<h3 style='margin-top: 10px;'>Google +</h3>

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

<!-- END ADMIN WIDGETS AREA -->

<?php }
}
?>