<?php
/**
 * Custom Social Widget
 */

class Forest_Jungle_Safari_Social_Widget extends WP_Widget {
	
	function __construct() {
		parent::__construct(
			'Forest_Jungle_Safari_Social_Widget',
			__('VW Social Icon', 'forest-jungle-safari'),
			array( 'description' => __( 'Widget for Social icons section', 'forest-jungle-safari' ), ) 
		);
	}

	public function widget( $forest_jungle_safari_args, $forest_jungle_safari_instance ) { ?>
		<div class="widget">
			<?php
			$forest_jungle_safari_title = isset( $forest_jungle_safari_instance['title'] ) ? $forest_jungle_safari_instance['title'] : '';
			$forest_jungle_safari_facebook = isset( $forest_jungle_safari_instance['facebook'] ) ? $forest_jungle_safari_instance['facebook'] : '';
			$forest_jungle_safari_instagram = isset( $forest_jungle_safari_instance['instagram'] ) ? $forest_jungle_safari_instance['instagram'] : '';
			$forest_jungle_safari_twitter = isset( $forest_jungle_safari_instance['twitter'] ) ? $forest_jungle_safari_instance['twitter'] : '';
			$forest_jungle_safari_linkedin = isset( $forest_jungle_safari_instance['linkedin'] ) ? $forest_jungle_safari_instance['linkedin'] : '';
			$forest_jungle_safari_pinterest = isset( $forest_jungle_safari_instance['pinterest'] ) ? $forest_jungle_safari_instance['pinterest'] : '';
			$forest_jungle_safari_tumblr = isset( $forest_jungle_safari_instance['tumblr'] ) ? $forest_jungle_safari_instance['tumblr'] : '';
			$forest_jungle_safari_youtube = isset( $forest_jungle_safari_instance['youtube'] ) ? $forest_jungle_safari_instance['youtube'] : '';

	        echo '<div class="custom-social-icons">';

	        if(!empty($forest_jungle_safari_title) ){ ?><span class="top-arrow-icon"></span><h3 class="custom_title"><?php echo esc_html($forest_jungle_safari_title); ?></h3><?php } ?>
	        <div class="slider-icons">
	        <?php if(!empty($forest_jungle_safari_facebook) ){ ?><p class="mb-0"><a class="custom_facebook fff" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_facebook); ?>"><i class="fab fa-facebook-f"></i><span class="screen-reader-text"><?php esc_html_e( 'Facebook','forest-jungle-safari' );?></span></a></p><?php } ?>

	        <?php if(!empty($forest_jungle_safari_twitter) ){ ?><p class="mb-0"><a class="custom_twitter" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_twitter); ?>"><i class="fab fa-twitter"></i><span class="screen-reader-text"><?php esc_html_e( 'Twitter','forest-jungle-safari' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($forest_jungle_safari_linkedin) ){ ?><p class="mb-0"><a class="custom_linkedin" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_linkedin); ?>"><i class="fab fa-linkedin-in"></i><span class="screen-reader-text"><?php esc_html_e( 'Linkedin','forest-jungle-safari' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($forest_jungle_safari_pinterest) ){ ?><p class="mb-0"><a class="custom_pinterest" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_pinterest); ?>"><i class="fab fa-pinterest-p"></i><span class="screen-reader-text"><?php esc_html_e( 'Pinterest','forest-jungle-safari' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($forest_jungle_safari_tumblr) ){ ?><p class="mb-0"><a class="custom_tumblr" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_tumblr); ?>"><i class="fab fa-tumblr"></i><span class="screen-reader-text"><?php esc_html_e( 'Tumblr','forest-jungle-safari' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($forest_jungle_safari_instagram) ){ ?><p class="mb-0"><a class="custom_instagram" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_instagram); ?>"><i class="fab fa-instagram"></i><span class="screen-reader-text"><?php esc_html_e( 'Instagram','forest-jungle-safari' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($forest_jungle_safari_youtube) ){ ?><p class="mb-0"><a class="custom_youtube" target= "_blank" href="<?php echo esc_url($forest_jungle_safari_youtube); ?>"><i class="fab fa-youtube"></i><span class="screen-reader-text"><?php esc_html_e( 'Youtube','forest-jungle-safari' );?></span></a></p><?php } ?>

	    	</div>

	        <?php echo '</div>';
			?>
		</div>
		<?php
	}
	
	// Widget Backend 
	public function form( $forest_jungle_safari_instance ) {

		$forest_jungle_safari_title= ''; $forest_jungle_safari_facebook = ''; $forest_jungle_safari_twitter = ''; $forest_jungle_safari_linkedin = '';  $forest_jungle_safari_pinterest = '';$forest_jungle_safari_tumblr = ''; $forest_jungle_safari_instagram = ''; $forest_jungle_safari_youtube = ''; 

		$forest_jungle_safari_title = isset( $forest_jungle_safari_instance['title'] ) ? $forest_jungle_safari_instance['title'] : '';
		$forest_jungle_safari_facebook = isset( $forest_jungle_safari_instance['facebook'] ) ? $forest_jungle_safari_instance['facebook'] : '';
		$forest_jungle_safari_instagram = isset( $forest_jungle_safari_instance['instagram'] ) ? $forest_jungle_safari_instance['instagram'] : '';
		$forest_jungle_safari_twitter = isset( $forest_jungle_safari_instance['twitter'] ) ? $forest_jungle_safari_instance['twitter'] : '';
		$forest_jungle_safari_linkedin = isset( $forest_jungle_safari_instance['linkedin'] ) ? $forest_jungle_safari_instance['linkedin'] : '';
		$forest_jungle_safari_pinterest = isset( $forest_jungle_safari_instance['pinterest'] ) ? $forest_jungle_safari_instance['pinterest'] : '';
		$forest_jungle_safari_tumblr = isset( $forest_jungle_safari_instance['tumblr'] ) ? $forest_jungle_safari_instance['tumblr'] : '';
		$forest_jungle_safari_youtube = isset( $forest_jungle_safari_instance['youtube'] ) ? $forest_jungle_safari_instance['youtube'] : '';
		?>
		<p>
        <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','forest-jungle-safari'); ?></label>
        <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_title); ?>">
    	</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('facebook')); ?>"><?php esc_html_e('Facebook:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('facebook')); ?>" name="<?php echo esc_attr($this->get_field_name('facebook')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_facebook); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('twitter')); ?>"><?php esc_html_e('Twitter:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('twitter')); ?>" name="<?php echo esc_attr($this->get_field_name('twitter')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_twitter); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('linkedin')); ?>"><?php esc_html_e('Linkedin:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('linkedin')); ?>" name="<?php echo esc_attr($this->get_field_name('linkedin')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_linkedin); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('instagram')); ?>"><?php esc_html_e('Instagram:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('instagram')); ?>" name="<?php echo esc_attr($this->get_field_name('instagram')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_instagram); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('pinterest')); ?>"><?php esc_html_e('Pinterest:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('pinterest')); ?>" name="<?php echo esc_attr($this->get_field_name('pinterest')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_pinterest); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('tumblr')); ?>"><?php esc_html_e('Tumblr:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('tumblr')); ?>" name="<?php echo esc_attr($this->get_field_name('tumblr')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_tumblr); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('youtube')); ?>"><?php esc_html_e('Youtube:','forest-jungle-safari'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('youtube')); ?>" name="<?php echo esc_attr($this->get_field_name('youtube')); ?>" type="text" value="<?php echo esc_attr($forest_jungle_safari_youtube); ?>">
		</p>
		<?php 
	}
	
	public function update( $forest_jungle_safari_new_instance, $forest_jungle_safari_old_instance ) {
		$forest_jungle_safari_instance = array();
		$forest_jungle_safari_instance['title'] = (!empty($forest_jungle_safari_new_instance['title']) ) ? strip_tags($forest_jungle_safari_new_instance['title']) : '';	
        $forest_jungle_safari_instance['facebook'] = (!empty($forest_jungle_safari_new_instance['facebook']) ) ? esc_url_raw($forest_jungle_safari_new_instance['facebook']) : '';
        $forest_jungle_safari_instance['twitter'] = (!empty($forest_jungle_safari_new_instance['twitter']) ) ? esc_url_raw($forest_jungle_safari_new_instance['twitter']) : '';
        $forest_jungle_safari_instance['instagram'] = (!empty($forest_jungle_safari_new_instance['instagram']) ) ? esc_url_raw($forest_jungle_safari_new_instance['instagram']) : '';
        $forest_jungle_safari_instance['linkedin'] = (!empty($forest_jungle_safari_new_instance['linkedin']) ) ? esc_url_raw($forest_jungle_safari_new_instance['linkedin']) : '';
        $forest_jungle_safari_instance['pinterest'] = (!empty($forest_jungle_safari_new_instance['pinterest']) ) ? esc_url_raw($forest_jungle_safari_new_instance['pinterest']) : '';
        $forest_jungle_safari_instance['tumblr'] = (!empty($forest_jungle_safari_new_instance['tumblr']) ) ? esc_url_raw($forest_jungle_safari_new_instance['tumblr']) : '';
     	$forest_jungle_safari_instance['youtube'] = (!empty($forest_jungle_safari_new_instance['youtube']) ) ? esc_url_raw($forest_jungle_safari_new_instance['youtube']) : '';
     	
		return $forest_jungle_safari_instance;
	}
}

function forest_jungle_safari_custom_load_widget() {
	register_widget( 'Forest_Jungle_Safari_Social_Widget' );
}
add_action( 'widgets_init', 'forest_jungle_safari_custom_load_widget' );