<?php

class Deep_Socials_Text_Widget extends WP_Widget {
	function __construct() {
		$widget_ops = array('classname' => 'deep_socials_text_widget', 'description' => esc_html__('Display Social Text', 'deep'));
		parent::__construct(false, 'Boldway _ Social Text', $widget_ops);
	}
	
	function form($instance) {
		if (isset($instance['title'])){
			$title = esc_attr($instance['title']); 
		} else $title = "";
		
		if (isset($instance['align'])){
			$align = esc_attr($instance['align']);
		} else $align = "center";

		if (isset($instance['usePanelOptions'])){
			$usePanelOptions = esc_attr($instance['usePanelOptions']);
		} else $usePanelOptions = "yes";
		
		$socials = ["facebook", "twitter", "tumblr", "stumbleupon", "flickr", "linkedin", "delicious", "skype", "digg", "vimeo-square", "deviantart", "behance", "instagram", "blogger", "wordpress", "youtube", "reddit", "rss", "soundcloud", "pinterest", "dribbble", "vk", "twitch", "foursquare", "slack", "whatsapp", "line", "weixin", "imdb", "tiktok", "amazon", "apple", "google-play", "snapchat", "tripadvisor", "xing"];
		
		$socials_labels = ["Facebook", "Twitter", "Tumblr", "StumbleUpon", "Flickr", "LinkedIn", "Delicious", "Skype", "Digg", "Vimeo", "DeviantArt", "Behance", "Instagram", "Blogger", "WordPress", "Youtube", "Reddit", "RSS", "SoundCloud", "Pinterest", "Dribbble", "Vk", "Twitch", "Foursquare", "Slack", "Whatsapp", "Line", "Weixin", "Imdb", "Tiktok", "Amazon", "Apple", "Google-play", "Snapchat", "Tripadvisor", "Xing"];
				
		foreach ($socials as $social){
			if (isset($instance[$social])){
				$$social = esc_attr(esc_url($instance[$social]));
			} else $$social = "";
		}
		
		?>
		<div class="deep_socials_text_widget <?php echo esc_attr( $this->id ); ?>">
			<p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>">&#8212; <?php esc_html_e('Widget Title','deep'); ?> &#8212;<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_html($title); ?>" ></label></p> 
			
			<p class="widget-option-container-title"><label><strong><?php esc_html_e('Style Options','deep'); ?></strong></label></p>
			<p class="widget-option-container"><label for="<?php echo esc_attr($this->get_field_id('align')); ?>">&#8212; <?php esc_html_e('Alignment','deep'); ?> &nbsp;
				<select class="smaller-option align" id="<?php echo esc_attr($this->get_field_id('align')); ?>" name="<?php echo esc_attr($this->get_field_name('align')); ?>" >
					<option value="left" <?php if ($align == "left") echo "selected"; ?> ><?php _e('Left', 'deep'); ?></option>
					<option value="center" <?php if ($align == "center") echo "selected"; ?> ><?php _e('Center', 'deep'); ?></option>
					<option value="right" <?php if ($align == "right") echo "selected"; ?> ><?php _e('Right', 'deep'); ?></option>
				</select>
			</p>
			<!-- <p class="widget-option-container"><label for="<?php echo esc_attr($this->get_field_id('color')); ?>">&#8212; <?php esc_html_e('Color','deep'); ?> &#8212;<input class="smaller-option" id="<?php echo esc_attr($this->get_field_id('color')); ?>" name="<?php echo esc_attr($this->get_field_name('color')); ?>" type="color" value="<?php echo esc_attr($color); ?>" /></label></p>
			<p class="widget-option-container"><label for="<?php echo esc_attr($this->get_field_id('colorHover')); ?>">&#8212; <?php esc_html_e('Color Hover','deep'); ?> &#8212;<input class="smaller-option" id="<?php echo esc_attr($this->get_field_id('colorHover')); ?>" name="<?php echo esc_attr($this->get_field_name('colorHover')); ?>" type="color" value="<?php echo esc_attr($colorHover); ?>" /></label></p>
			 -->
			<p class="widget-option-container-title"><label><strong><?php esc_html_e('Social Networks','deep'); ?></strong></label></p>
			<p class="widget-option-container"><label for="<?php echo esc_attr($this->get_field_id('usePanelOptions')); ?>">&#8212; <?php esc_html_e('Use Panel Options','deep'); ?> &nbsp;
				<select class="smaller-option custom-socials-widget-select" id="<?php echo esc_attr($this->get_field_id('usePanelOptions')); ?>" name="<?php echo esc_attr($this->get_field_name('usePanelOptions')); ?>" >
					<option value="yes" <?php if ($usePanelOptions == "yes") echo "selected"; ?> ><?php _e('Yes', 'deep'); ?></option>
					<option value="no" <?php if ($usePanelOptions == "no") echo "selected"; ?> ><?php _e('No', 'deep'); ?></option>
				</select>
			</p>
			
			<div <?php if ($usePanelOptions == "yes") echo 'hidden' ?> class="custom-socials-group">
				<p class="widget-option-container-title"><label><strong><?php esc_html_e('Custom Networks','deep'); ?></strong></label></p>
				<?php
					foreach($socials as $key => $social){
						?>
						<p><label for="<?php echo esc_attr($this->get_field_id($social)); ?>">&#8212; <?php esc_html_e( $socials_labels[$key] ,'deep'); ?> &#8212;<input class="widefat" id="<?php echo esc_attr($this->get_field_id($social)); ?>" name="<?php echo esc_attr($this->get_field_name($social)); ?>" type="text" value="<?php echo esc_html($$social); ?>" ></label></p> 
						<?php
					}
				?>
			</div>
			<p class="options-clear"></p>
		</div>
		<?php
	}
	
	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = $new_instance['title'];
		$instance['align'] = $new_instance['align'];
		// $instance['color'] = $new_instance['color'];
		// $instance['colorHover'] = $new_instance['colorHover'];
		$instance['usePanelOptions'] = $new_instance['usePanelOptions'];
		$socials = ["facebook", "twitter", "tumblr", "stumbleupon", "flickr", "linkedin", "delicious", "skype", "digg", "vimeo-square", "deviantart", "behance", "instagram", "blogger", "wordpress", "youtube", "reddit", "rss", "soundcloud", "pinterest", "dribbble", "vk", "twitch", "foursquare", "slack", "whatsapp", "line", "weixin", "imdb", "tiktok", "amazon", "apple", "google-play", "snapchat", "tripadvisor", "xing"];
		foreach ($socials as $social) $instance[$social] = $new_instance[$social];
		return $instance;
	}
	
	function widget($args, $instance) {
			
		extract($args);
		
		echo '<div id="'.$this->id.'" class="widget deep_socials_text_widget">';
			$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
			if (!empty($title)) { echo wp_kses_post("<h4 class='widget_title_span'>$title</h4><hr>"); }
			echo '<div class="social-icons-fa align-'.esc_attr( $instance['align'] ). '"><ul>';
			$socials = ["facebook", "twitter", "tumblr", "stumbleupon", "flickr", "linkedin", "delicious", "skype", "digg", "vimeo-square", "deviantart", "behance", "instagram", "blogger", "wordpress", "youtube", "reddit", "rss", "soundcloud", "pinterest", "dribbble", "vk", "twitch", "foursquare", "slack", "whatsapp", "line", "weixin", "imdb", "tiktok", "amazon", "apple", "google-play", "snapchat", "tripadvisor", "xing", "email"];
		
			$socials_labels = ["Facebook", "Twitter", "Tumblr", "StumbleUpon", "Flickr", "LinkedIn", "Delicious", "Skype", "Digg", "Vimeo", "DeviantArt", "Behance", "Instagram", "Blogger", "WordPress", "Youtube", "Reddit", "RSS", "SoundCloud", "Pinterest", "Dribbble", "Vk", "Twitch", "Foursquare", "Slack", "Whatsapp", "Line", "Weixin", "Imdb", "Tiktok", "Amazon", "Apple", "Google-play", "Snapchat", "Tripadvisor", "Xing", "Email"];
			if ($instance['usePanelOptions'] == "yes"){
				foreach ($socials as $key => $social){
					if (is_string(get_option("deep_icon-".$social)) && get_option("deep_icon-".$social) != "") echo '<li><a href="'.esc_attr(esc_url(get_option("deep_icon-".$social))).'" target="_blank" rel="nofollow noopener" class="social-network '.$social.' link-hover-anim align-middle" data-link-animate="y" title="'.esc_attr($socials_labels[$key]).'">'.esc_attr($socials_labels[$key]).'					
					</a></li>';
					
				}
				if (is_string(get_option("deep_icon-envelope")) && get_option("deep_icon-envelope") != "") echo '<li><a href="'.esc_attr(esc_url(get_option("deep_icon-".$social))).'" target="_blank" rel="nofollow noopener" class="social-network '.$social.' link-hover-anim align-middle" data-link-animate="y" title="'.esc_attr($socials_labels[$key]).'">'.esc_attr($socials_labels[$key]).'					
				</a></li>';
			} else {
				foreach ($socials as $key => $social){
					if (isset($instance[$social]) && $instance[$social] != "") echo '<li><a href="'.esc_attr(esc_url(get_option("deep_icon-".$social))).'" target="_blank" rel="nofollow noopener" class="social-network '.$social.' link-hover-anim align-middle" data-link-animate="y" title="'.esc_attr($socials_labels[$key]).'">'.esc_attr($socials_labels[$key]).'					
					</a></li>';
				}
			}
			echo '</ul></div>';
		echo '</div>';
		
		wp_enqueue_style( 'deep-cpt' );
		
	}
}
register_widget('Deep_Socials_Text_Widget');

?>
