<?php
class rst_about_widget extends WP_Widget {
	
	function rst_about_widget() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'widget_about', 'description' => 'A widget that show about' );

		/* Create the widget. */
		parent::__construct( 'rst-about-widget', 'Laza - About', $widget_ops);	
	}
	 
	function widget($args, $instance) {
		$html = '';
		$html .= $args['before_widget'];
		if( !empty($instance['title']) ) {
			$html .= $args['before_title'];
				$html .= $instance['title'];
			$html .= $args['after_title'];
		}
		$html .= '<div class="text-center widget-wrap">';
		if( !empty($instance['avatar']) ){
			$html .= '<img class="img-circle  author-img" src="'. rst_get_attachment_image_src($instance['avatar'],'full') .'" alt="" />';
		}
		if( !empty($instance['name']) ){
			$html .= '<h5>'. $instance['name'] .'</h5>';
		}
		$html .= '<p>'. $instance['description'] .'</p>';
		$html .= '<ul class="list-inline social">';
			if( isset($instance['facebook']) && $instance['facebook'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['facebook']) .'" class="rst-icon-facebook"><i class="fa fa-facebook"></i></a></li>';
			}
			if( isset($instance['twitter']) && $instance['twitter'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['twitter']) .'" class="rst-icon-twitter"><i class="fa fa-twitter"></i></a></li>';
			}
			if( isset($instance['google']) && $instance['google'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['google']) .'" class="rst-icon-google-plus"><i class="fa fa-google-plus"></i></a></li>';
			}
			if( isset($instance['linkedin']) && $instance['linkedin'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['linkedin']) .'" class="rst-icon-linkedin"><i class="fa fa-linkedin"></i></a></li>';
			}
			if( isset($instance['pinterest']) && $instance['pinterest'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['pinterest']) .'" class="rst-icon-pinterest"><i class="fa fa-pinterest"></i></a></li>';
			}
			if( isset($instance['tumblr']) && $instance['tumblr'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['tumblr']) .'" class="rst-icon-tumblr"><i class="fa fa-tumblr"></i></a></li>';
			}
			if( isset($instance['instagram']) && $instance['instagram'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['instagram']) .'" class="rst-icon-instagram"><i class="fa fa-instagram"></i></a></li>';
			}
			if( isset($instance['youtube']) && $instance['youtube'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['youtube']) .'" class="rst-icon-youtube"><i class="fa fa-youtube"></i></a></li>';
			}
			if( isset($instance['flickr']) && $instance['flickr'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['flickr']) .'" class="rst-icon-flickr"><i class="fa fa-flickr"></i></a></li>';
			}
			if( isset($instance['vimeo']) && $instance['vimeo'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['vimeo']) .'" class="rst-icon-vimeo"><i class="fa fa-vimeo-square"></i></a></li>';
			}
			if( isset($instance['dribbble']) && $instance['dribbble'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['dribbble']) .'" class="rst-icon-dribbble"><i class="fa fa-dribbble"></i></a></li>';
			}
			if( isset($instance['digg']) && $instance['digg'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['digg']) .'" class="rst-icon-digg"><i class="fa fa-digg"></i></a></li>';
			}
			if( isset($instance['deviantart']) && $instance['deviantart'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['deviantart']) .'" class="rst-icon-deviantart"><i class="fa fa-deviantart"></i></a></li>';
			}
			if( isset($instance['reddit']) && $instance['reddit'] != null ) {
				$html .= '<li>
				<a target="_blank" href="'. esc_url($instance['reddit']) .'" class="rst-icon-reddit"><i class="fa fa-reddit"></i></a></li>';
			}
		$html .= '</ul>';
		$html .= '</div>';
		
		$html .= $args['after_widget'];
		echo force_balance_tags($html);
	}
 
	function update($new_instance, $old_instance) {
		return $new_instance;		
	}
 
	function form($instance) {
		?><br/>
		<label>Title:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'title' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" value="<?php echo isset($instance['title']) ? esc_attr($instance['title']) : ''; ?>" style="width:100%" /></label>
		<br /><br />
		<label>Avatar:</label>
		<?php
			rs::upload(
				array(
					'name' => $this->get_field_name( 'avatar' ), 
					'type' => 'image',
					'value' => isset($instance['avatar']) ? esc_attr($instance['avatar']) : ''
				)
			);
		?>
		<br /><br />
		<label>Name:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'name' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'name' )); ?>" value="<?php echo isset($instance['name']) ? esc_attr($instance['name']) : ''; ?>" style="width:100%" /></label>
		<br /><br />
		<label>Description:
		<textarea id="<?php echo esc_attr($this->get_field_id( 'description' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'description' )); ?>" cols="30" rows="6" style="width:100%"><?php echo isset($instance['description']) ? esc_attr($instance['description']) : ''; ?></textarea></label>
		<br/><br/>
		<label>Facebook:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'facebook' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'facebook' )); ?>" value="<?php echo isset($instance['facebook']) ? esc_attr($instance['facebook']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Twitter:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'twitter' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'twitter' )); ?>" value="<?php echo isset($instance['twitter']) ? esc_attr($instance['twitter']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Google+:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'google' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'google' )); ?>" value="<?php echo isset($instance['google']) ? esc_attr($instance['google']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Linkedin:		
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'linkedin' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'linkedin' )); ?>" value="<?php echo isset($instance['linkedin']) ? esc_attr($instance['linkedin']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Pinterest:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'pinterest' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'pinterest' )); ?>" value="<?php echo isset($instance['pinterest']) ? esc_attr($instance['pinterest']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Tumblr:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'tumblr' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'tumblr' )); ?>" value="<?php echo isset($instance['tumblr']) ? esc_attr($instance['tumblr']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Instagram:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'instagram' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'instagram' )); ?>" value="<?php echo isset($instance['instagram']) ? esc_attr($instance['instagram']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Youtube:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'youtube' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'youtube' )); ?>" value="<?php echo isset($instance['youtube']) ? esc_attr($instance['youtube']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Flickr:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'flickr' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'flickr' )); ?>" value="<?php echo isset($instance['flickr']) ? esc_attr($instance['flickr']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Vimeo:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'vimeo' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'vimeo' )); ?>" value="<?php echo isset($instance['vimeo']) ? esc_attr($instance['vimeo']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Dribbble:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'dribbble' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'dribbble' )); ?>" value="<?php echo isset($instance['dribbble']) ? esc_attr($instance['dribbble']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Digg:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'digg' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'digg' )); ?>" value="<?php echo isset($instance['digg']) ? esc_attr($instance['digg']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Deviantart:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'deviantart' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'deviantart' )); ?>" value="<?php echo isset($instance['deviantart']) ? esc_attr($instance['deviantart']) : ''; ?>" style="width:100%"/></label>
		<br/><br/>
		<label>Reddit:
		<input type="text" id="<?php echo esc_attr($this->get_field_id( 'reddit' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'reddit' )); ?>" value="<?php echo isset($instance['reddit']) ? esc_attr($instance['reddit']) : ''; ?>" style="width:100%"/></label>
		<?php	
	}
	
}

add_action( 'widgets_init', 'create_about_widget' );

function create_about_widget(){
	return register_widget("rst_about_widget");
}