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

class Book_Publisher_Agency_Social_Widget extends WP_Widget {
	
	function __construct() {
		parent::__construct(
			'Book_Publisher_Agency_Social_Widget',
			__('VW Social Icon', 'book-publisher-agency'),
			array( 'description' => __( 'Widget for Social icons section', 'book-publisher-agency' ), ) 
		);
	}

	public function widget( $book_publisher_agency_args, $book_publisher_agency_instance ) { ?>
		<div class="widget">
			<?php
			$book_publisher_agency_title = isset( $book_publisher_agency_instance['title'] ) ? $book_publisher_agency_instance['title'] : '';
			$book_publisher_agency_facebook = isset( $book_publisher_agency_instance['facebook'] ) ? $book_publisher_agency_instance['facebook'] : '';
			$book_publisher_agency_instagram = isset( $book_publisher_agency_instance['instagram'] ) ? $book_publisher_agency_instance['instagram'] : '';
			$book_publisher_agency_twitter = isset( $book_publisher_agency_instance['twitter'] ) ? $book_publisher_agency_instance['twitter'] : '';
			$book_publisher_agency_linkedin = isset( $book_publisher_agency_instance['linkedin'] ) ? $book_publisher_agency_instance['linkedin'] : '';
			$book_publisher_agency_pinterest = isset( $book_publisher_agency_instance['pinterest'] ) ? $book_publisher_agency_instance['pinterest'] : '';
			$book_publisher_agency_tumblr = isset( $book_publisher_agency_instance['tumblr'] ) ? $book_publisher_agency_instance['tumblr'] : '';
			$book_publisher_agency_youtube = isset( $book_publisher_agency_instance['youtube'] ) ? $book_publisher_agency_instance['youtube'] : '';

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

	        if(!empty($book_publisher_agency_title) ){ ?><h3 class="custom_title"><?php echo esc_html($book_publisher_agency_title); ?></h3><?php } ?>
	        <?php if(!empty($book_publisher_agency_facebook) ){ ?><p class="mb-0"><a class="custom_facebook fff" target= "_blank" href="<?php echo esc_url($book_publisher_agency_facebook); ?>"><i class="fab fa-facebook-f"></i><span class="screen-reader-text"><?php esc_html_e( 'Facebook','book-publisher-agency' );?></span></a></p><?php } ?>

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

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

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

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

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

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

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

		$book_publisher_agency_title= ''; $book_publisher_agency_facebook = ''; $book_publisher_agency_twitter = ''; $book_publisher_agency_linkedin = '';  $book_publisher_agency_pinterest = '';$book_publisher_agency_tumblr = ''; $book_publisher_agency_instagram = ''; $book_publisher_agency_youtube = ''; 

		$book_publisher_agency_title = isset( $book_publisher_agency_instance['title'] ) ? $book_publisher_agency_instance['title'] : '';
		$book_publisher_agency_facebook = isset( $book_publisher_agency_instance['facebook'] ) ? $book_publisher_agency_instance['facebook'] : '';
		$book_publisher_agency_instagram = isset( $book_publisher_agency_instance['instagram'] ) ? $book_publisher_agency_instance['instagram'] : '';
		$book_publisher_agency_twitter = isset( $book_publisher_agency_instance['twitter'] ) ? $book_publisher_agency_instance['twitter'] : '';
		$book_publisher_agency_linkedin = isset( $book_publisher_agency_instance['linkedin'] ) ? $book_publisher_agency_instance['linkedin'] : '';
		$book_publisher_agency_pinterest = isset( $book_publisher_agency_instance['pinterest'] ) ? $book_publisher_agency_instance['pinterest'] : '';
		$book_publisher_agency_tumblr = isset( $book_publisher_agency_instance['tumblr'] ) ? $book_publisher_agency_instance['tumblr'] : '';
		$book_publisher_agency_youtube = isset( $book_publisher_agency_instance['youtube'] ) ? $book_publisher_agency_instance['youtube'] : '';
		?>
		<p>
        <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','book-publisher-agency'); ?></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($book_publisher_agency_title); ?>">
    	</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('facebook')); ?>"><?php esc_html_e('Facebook:','book-publisher-agency'); ?></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($book_publisher_agency_facebook); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('twitter')); ?>"><?php esc_html_e('Twitter:','book-publisher-agency'); ?></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($book_publisher_agency_twitter); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('linkedin')); ?>"><?php esc_html_e('Linkedin:','book-publisher-agency'); ?></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($book_publisher_agency_linkedin); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('instagram')); ?>"><?php esc_html_e('Instagram:','book-publisher-agency'); ?></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($book_publisher_agency_instagram); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('pinterest')); ?>"><?php esc_html_e('Pinterest:','book-publisher-agency'); ?></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($book_publisher_agency_pinterest); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('tumblr')); ?>"><?php esc_html_e('Tumblr:','book-publisher-agency'); ?></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($book_publisher_agency_tumblr); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('youtube')); ?>"><?php esc_html_e('Youtube:','book-publisher-agency'); ?></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($book_publisher_agency_youtube); ?>">
		</p>
		<?php 
	}
	
	public function update( $book_publisher_agency_new_instance, $book_publisher_agency_old_instance ) {
		$book_publisher_agency_instance = array();
		$book_publisher_agency_instance['title'] = (!empty($book_publisher_agency_new_instance['title']) ) ? strip_tags($book_publisher_agency_new_instance['title']) : '';	
        $book_publisher_agency_instance['facebook'] = (!empty($book_publisher_agency_new_instance['facebook']) ) ? esc_url_raw($book_publisher_agency_new_instance['facebook']) : '';
        $book_publisher_agency_instance['twitter'] = (!empty($book_publisher_agency_new_instance['twitter']) ) ? esc_url_raw($book_publisher_agency_new_instance['twitter']) : '';
        $book_publisher_agency_instance['instagram'] = (!empty($book_publisher_agency_new_instance['instagram']) ) ? esc_url_raw($book_publisher_agency_new_instance['instagram']) : '';
        $book_publisher_agency_instance['linkedin'] = (!empty($book_publisher_agency_new_instance['linkedin']) ) ? esc_url_raw($book_publisher_agency_new_instance['linkedin']) : '';
        $book_publisher_agency_instance['pinterest'] = (!empty($book_publisher_agency_new_instance['pinterest']) ) ? esc_url_raw($book_publisher_agency_new_instance['pinterest']) : '';
        $book_publisher_agency_instance['tumblr'] = (!empty($book_publisher_agency_new_instance['tumblr']) ) ? esc_url_raw($book_publisher_agency_new_instance['tumblr']) : '';
     	$book_publisher_agency_instance['youtube'] = (!empty($book_publisher_agency_new_instance['youtube']) ) ? esc_url_raw($book_publisher_agency_new_instance['youtube']) : '';
     	
		return $book_publisher_agency_instance;
	}
}

function book_publisher_agency_custom_load_widget() {
	register_widget( 'Book_Publisher_Agency_Social_Widget' );
}
add_action( 'widgets_init', 'book_publisher_agency_custom_load_widget' );