<?php
   add_action('widgets_init', 'facebook_likebox_load_widgets');
   function facebook_likebox_load_widgets()
   {
      register_widget('Facebook_Likebox_Widget');
   }
      class Facebook_Likebox_Widget extends WP_Widget {
   function Facebook_Likebox_Widget()
   {
      $widget_ops = array('classname' => 'facebook_likebox', 'description' => 'Facebook Like Box Widget for sidebar.');
      $control_ops = array(
     'id_base' => 'facebook-likebox');
      $this->WP_Widget('facebook-likebox', 'GAMELEON: Facebook Like Box', $widget_ops, $control_ops);
   }
   function widget($args, $instance)
   {
      extract($args);

/* User selected settings. */
      $title = apply_filters('widget_title', $instance['title']);
      $fb_id = $instance['fb_id'];
      $color_scheme = 'light';
      $show_faces = true;
      $show_stream = false;
      $show_header = false;
      $width  = '287';
      $height = '310';
      $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;
   }
      if($fb_id): ?>

<!-- START WIDGET -->

      <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>

<!-- END WIDGET -->

<?php endif;
      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['fb_id'] = $new_instance['fb_id'];
      return $instance;
   }
   function form($instance)
   {
      $defaults = array(
               'title' => 'We are on Facebook',
              'fb_id' => '',
              'width' => '292',
              'color_scheme' => 'light',
              'show_home' => 'on',
              'show_page' => 'on',
              'show_single' => 'on',
              'show_faces' => 'on',
              'show_stream' => false,
              'show_header' => false);
      $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('fb_id'); ?>">Facebook ID</label>
      <input class="widefat" style="width: 216px;" 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>
          <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
}
}
?>