<?php
class rst_facebook_widget extends WP_Widget {
	
	function rst_facebook_widget() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'widget_facebook', 'description' => 'A widget that show like page facebook' );

		/* Create the widget. */
		parent::__construct( 'rst-facebook-widget', 'Laza - Like Page Facebook', $widget_ops);	
	}
	 
	function widget($args, $instance) {
		$html = '';
		$html .= $args['before_widget'];
		
		$html .= '<div id="fb-root"></div>';
		$html .= '<script>(function(d, s, id) {
		  var js, fjs = d.getElementsByTagName(s)[0];
		  if (d.getElementById(id)) return;
		  js = d.createElement(s); js.id = id;
		  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3";
		  fjs.parentNode.insertBefore(js, fjs);
		}(document, \'script\', \'facebook-jssdk\'));</script>
		<div class="fb-page" data-href="'. esc_url($instance['link']) .'" data-hide-cover="false" data-show-facepile="true" data-show-posts="false"><div class="fb-xfbml-parse-ignore"></div></div>';
		
		$html .= $args['after_widget'];
		echo force_balance_tags($html);
	}
 
	function update($new_instance, $old_instance) {
		return $new_instance;		
	}
 
	function form($instance) {
		?><br/>
		<label>Link Facebook Page:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'link' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'link' )); ?>" value="<?php echo isset($instance['link']) ? esc_attr($instance['link']) : ''; ?>" style="width:100%" /></label>
		
		<?php	
	}
	
}

add_action( 'widgets_init', 'create_facebook_widget' );

function create_facebook_widget(){
	return register_widget("rst_facebook_widget");
}