<?php 
/*
Plugin Name: ThemeTrust Social
Plugin URI: http://themetrust.com/themetrust-social
Description: A minimalistic social sharing plugin.
Version: 1.0.3
Author: ThemeTrust
Author URI: http://themetrust.com
License: GPLv2
*/

/*
This plugin is adapted from WP-Simple-Social (http://wordpress.org/extend/plugins/wp-simple-social/).
*/

//Register widget
add_action( 'widgets_init', 'ttrust_register_social' );

function ttrust_register_social() {
    register_widget( 'TTrust_Social' );
} 


//Load the stylesheet
function ttrust_social_styles() {
	wp_enqueue_style( 'themetrust-social-style', plugin_dir_url( __FILE__ ) . 'styles.css', array(), '0.1', 'screen' );
}
add_action( 'wp_enqueue_scripts', 'ttrust_social_styles' );


//Load the color picker

function load_color_picker_script() {
	wp_enqueue_script('farbtastic');
}
function load_color_picker_style() {
	wp_enqueue_style('farbtastic');	
}
add_action('admin_print_scripts-widgets.php', 'load_color_picker_script');
add_action('admin_print_styles-widgets.php', 'load_color_picker_style');

// Localization 
function ttrust_social_localize() {
    load_plugin_textdomain('ttlocalize', false, dirname(plugin_basename(__FILE__)) . '/lang/');
} 
add_action('after_theme_setup', 'ttrust_social_localize');


//TTrust_Social 
class TTrust_Social extends WP_Widget {

    //process the new widget
    function TTrust_Social() {
        $widget_ops = array( 
			'classname' => 'ttrustSocial', 
			'description' => 'Clean Minimal Social Widget' 
			); 
        $this->WP_Widget( 'ttrust_social', 'ThemeTrust Social', $widget_ops );
    }
    
  //build the widget settings form
    function form($instance) {
        $defaults = array(         	
        	'icon_size' => '',         	
        	'icon_color' => '', 
            'icon_color_hover' => '',          	
        	'amazon' => '', 
        	'blogger' => '', 
        	'delicious' => '', 
        	'deviantart' => '', 
        	'dribbble' => '', 
        	'facebook' => '', 
        	'flickr' => '', 
        	'forrst' => '', 
        	'github' => '', 
        	'googleplus' => '', 
        	'lastfm' => '', 
        	'picassa' => '', 
        	'pinterest' => '', 
        	'reddit' => '', 
        	'rss' => '', 
        	'skype' => '', 
        	'soundcloud' => '', 
        	'tumblr' => '',
        	'twitter' => '', 
        	'vimeo' => '' 
        
        ); 
        $instance = wp_parse_args( (array) $instance, $defaults );        
        
        $icon_size = esc_attr($instance['icon_size']);        
        $icon_color = esc_attr($instance['icon_color']); 
        $icon_color_hover = esc_attr($instance['icon_color_hover']);        
        $amazon = esc_attr($instance['amazon']);
        $blogger = esc_attr($instance['blogger']);
        $delicious = esc_attr($instance['delicious']);
        $deviantart = esc_attr($instance['deviantart']);
        $dribbble = esc_attr($instance['dribbble']);
        $facebook = esc_attr($instance['facebook']);
        $flickr = esc_attr($instance['flickr']);
        $forrst = esc_attr($instance['forrst']);
        $github = esc_attr($instance['github']);
        $googleplus = esc_attr($instance['googleplus']);
        $lastfm = esc_attr($instance['lastfm']);
        $picassa = esc_attr($instance['picassa']);
        $pinterest = esc_attr($instance['pinterest']);
        $reddit = esc_attr($instance['reddit']);
        $rss = esc_attr($instance['rss']);
        $skype = esc_attr($instance['skype']);
        $soundcloud = esc_attr($instance['soundcloud']);
        $tumblr = esc_attr($instance['tumblr']);
        $twitter = esc_attr($instance['twitter']);
        $vimeo = esc_attr($instance['vimeo']);
        
        ?>
        
    	<script type="text/javascript">
		//<![CDATA[
			jQuery(document).ready(function()
			{
				// colorpicker field
				jQuery('.cw-color-picker').each(function(){
					var $this = jQuery(this),
						id = $this.attr('rel');

					$this.farbtastic('#' + id);
				});
			});
		//]]>   
	  </script>

<!-- Show icon options -->


	
	<p>
		<label for="<?php echo $this->get_field_id('icon_size'); ?>"><?php _e('Icon Size', 'ttlocalize'); ?></label>
		<select name="<?php echo $this->get_field_name('icon_size'); ?>" id="<?php echo $this->get_field_id('icon_size'); ?>" class="widefat">
			<?php
			$options = array('Tiny', 'Small', 'Medium', 'Large',);
			foreach ($options as $option) {
				echo '<option value="' . $option . '" id="' . $option . '"', $icon_size == $option ? ' selected="selected"' : '', '>', $option, '</option>';
			}
			?>
		</select>
	</p>
	
	<label for="<?php echo $this->get_field_id('icon_color'); ?>"><?php _e('Icon Color:', 'ttlocalize'); ?></label> 
	<input class="widefat" id="<?php echo $this->get_field_id('icon_color'); ?>" name="<?php echo $this->get_field_name('icon_color'); ?>" type="text" value="<?php if($icon_color) { echo $icon_color; } else { echo '#aaaaaa'; } ?>" />
	<div class="cw-color-picker" rel="<?php echo $this->get_field_id('icon_color'); ?>"></div>
	
	<label for="<?php echo $this->get_field_id('icon_color_hover'); ?>"><?php _e('Icon Hover Color:', 'ttlocalize'); ?></label> 
	<input class="widefat" id="<?php echo $this->get_field_id('icon_color_hover'); ?>" name="<?php echo $this->get_field_name('icon_color_hover'); ?>" type="text" value="<?php if($icon_color_hover) { echo $icon_color_hover; } else { echo '#828282'; } ?>" />
	<div class="cw-color-picker" rel="<?php echo $this->get_field_id('icon_color_hover'); ?>"></div>
	
<!-- End icon properties -->

<!-- Show social options -->

	<p><?php _e('For each social icon you want to display, enter your corresponding URL.', 'ttlocalize'); ?></p>
	
	<p>Delicious: <input class="widefat" name="<?php echo $this->get_field_name( 'delicious' ); ?>"  type="text" value="<?php echo esc_attr( $delicious ); ?>" /></p>
	
	<p>Deviant Art: <input class="widefat" name="<?php echo $this->get_field_name( 'deviantart' ); ?>"  type="text" value="<?php echo esc_attr( $deviantart ); ?>" /></p>
	
	<p>Dribbble: <input class="widefat" name="<?php echo $this->get_field_name( 'dribbble' ); ?>"  type="text" value="<?php echo esc_attr( $dribbble ); ?>" /></p>
	
	<p>Facebook: <input class="widefat" name="<?php echo $this->get_field_name( 'facebook' ); ?>"  type="text" value="<?php echo esc_attr( $facebook ); ?>" /></p>   
	        
	<p>Flickr: <input class="widefat" name="<?php echo $this->get_field_name( 'flickr' ); ?>"  type="text" value="<?php echo esc_attr( $flickr ); ?>" /></p>
	
	<p>Forrst: <input class="widefat" name="<?php echo $this->get_field_name( 'forrst' ); ?>"  type="text" value="<?php echo esc_attr( $forrst ); ?>" /></p>
	
	<p>github: <input class="widefat" name="<?php echo $this->get_field_name( 'github' ); ?>"  type="text" value="<?php echo esc_attr( $github ); ?>" /></p>           
	
	<p>Google Plus: <input class="widefat" name="<?php echo $this->get_field_name( 'googleplus' ); ?>"  type="text" value="<?php echo esc_attr( $googleplus ); ?>" /></p>
	
	<p>Last FM: <input class="widefat" name="<?php echo $this->get_field_name( 'lastfm' ); ?>"  type="text" value="<?php echo esc_attr( $lastfm ); ?>" /></p>
	
	<p>Picassa: <input class="widefat" name="<?php echo $this->get_field_name( 'picassa' ); ?>"  type="text" value="<?php echo esc_attr( $picassa ); ?>" /></p>
	
	<p>Pinterest: <input class="widefat" name="<?php echo $this->get_field_name( 'pinterest' ); ?>"  type="text" value="<?php echo esc_attr( $pinterest ); ?>" /></p>
	
	<p>Reddit: <input class="widefat" name="<?php echo $this->get_field_name( 'reddit' ); ?>"  type="text" value="<?php echo esc_attr( $reddit ); ?>" /></p>
	
	<p>RSS: <input class="widefat" name="<?php echo $this->get_field_name( 'rss' ); ?>"  type="text" value="<?php echo esc_attr( $rss ); ?>" /></p>      
	     
	<p>Skype: <input class="widefat" name="<?php echo $this->get_field_name( 'skype' ); ?>"  type="text" value="<?php echo esc_attr( $skype ); ?>" /></p>
	
	<p>Sound Cloud: <input class="widefat" name="<?php echo $this->get_field_name( 'soundcloud' ); ?>"  type="text" value="<?php echo esc_attr( $soundcloud ); ?>" /></p>
	
	<p>Tumblr: <input class="widefat" name="<?php echo $this->get_field_name( 'tumblr' ); ?>"  type="text" value="<?php echo esc_attr( $tumblr ); ?>" /></p>
	
	<p>Twitter: <input class="widefat" name="<?php echo $this->get_field_name( 'twitter' ); ?>"  type="text" value="<?php echo esc_attr( $twitter ); ?>" /></p>
	
	<p>Vimeo: <input class="widefat" name="<?php echo $this->get_field_name( 'vimeo' ); ?>"  type="text" value="<?php echo esc_attr( $vimeo ); ?>" /></p>	
         
<!-- End social options-->            
		    
<?php
    }
 
    //Save widget settings
    function update($new_instance, $old_instance) {
        $instance = $old_instance;        
        $instance['icon_size'] = strip_tags( $new_instance['icon_size'] );        
        $instance['icon_color'] = strip_tags( $new_instance['icon_color'] );   
        $instance['icon_color_hover'] = strip_tags( $new_instance['icon_color_hover'] );        
        $instance['amazon'] = strip_tags( $new_instance['amazon'] );
        $instance['blogger'] = strip_tags( $new_instance['blogger'] );
        $instance['delicious'] = strip_tags( $new_instance['delicious'] );
        $instance['deviantart'] = strip_tags($new_instance['deviantart']);
        $instance['dribbble'] = strip_tags( $new_instance['dribbble'] );
        $instance['facebook'] = strip_tags( $new_instance['facebook'] );
        $instance['flickr'] = strip_tags($new_instance['flickr']);
        $instance['forrst'] = strip_tags( $new_instance['forrst'] );
        $instance['github'] = strip_tags( $new_instance['github'] );
        $instance['googleplus'] = strip_tags( $new_instance['googleplus'] );
        $instance['lastfm'] = strip_tags( $new_instance['lastfm'] );
        $instance['picassa'] = strip_tags( $new_instance['picassa'] );
        $instance['pinterest'] = strip_tags( $new_instance['pinterest'] );
        $instance['reddit'] = strip_tags( $new_instance['reddit'] );
        $instance['rss'] = strip_tags( $new_instance['rss'] );
        $instance['skype'] = strip_tags( $new_instance['skype'] );
        $instance['soundcloud'] = strip_tags( $new_instance['soundcloud'] );
        $instance['tumblr'] = strip_tags( $new_instance['tumblr'] );
        $instance['twitter'] = strip_tags( $new_instance['twitter'] );
        $instance['vimeo'] = strip_tags($new_instance['vimeo']);
 
        return $instance;
    }
 
//Show the widget

    function widget($args, $instance) {
        extract($args);
 
        echo $before_widget;
     
        $icon_size = empty( $instance['icon_size'] ) ? '' : $instance['icon_size'];        
        $icon_color = empty( $instance['icon_color'] ) ? '' : $instance['icon_color'];   
        $icon_color_hover = empty( $instance['icon_color_hover'] ) ? '' : $instance['icon_color_hover'];       
        $amazon = empty( $instance['amazon'] ) ? '' : $instance['amazon'];
        $blogger = empty( $instance['blogger'] ) ? '' : $instance['blogger'];
        $delicious = empty( $instance['delicious'] ) ? '' : $instance['delicious']; 
        $deviantart = empty( $instance['deviantart'] ) ? '' : $instance['deviantart'];
        $dribbble = empty( $instance['dribbble'] ) ? '' : $instance['dribbble'];
        $facebook = empty( $instance['facebook'] ) ? '' : $instance['facebook'];
        $flickr = empty( $instance['flickr'] ) ? '' : $instance['flickr'];
        $forrst = empty( $instance['forrst'] ) ? '' : $instance['forrst']; 
        $github = empty( $instance['github'] ) ? '' : $instance['github'];
        $googleplus = empty( $instance['googleplus'] ) ? '' : $instance['googleplus'];
        $lastfm = empty( $instance['lastfm'] ) ? '' : $instance['lastfm']; 
        $picassa = empty( $instance['picassa'] ) ? '' : $instance['picassa'];
        $pinterest = empty( $instance['pinterest'] ) ? '' : $instance['pinterest']; 
        $reddit = empty( $instance['reddit'] ) ? '' : $instance['reddit'];
        $rss = empty( $instance['rss'] ) ? '' : $instance['rss'];
        $skype = empty( $instance['skype'] ) ? '' : $instance['skype']; 
        $soundcloud = empty( $instance['soundcloud'] ) ? '' : $instance['soundcloud'];
        $tumblr = empty( $instance['tumblr'] ) ? '' : $instance['tumblr']; 
        $twitter = empty( $instance['twitter'] ) ? '' : $instance['twitter'];
        $vimeo = empty( $instance['vimeo'] ) ? '' : $instance['vimeo'];	

		//Echo styles for icon colors.
		echo '<style>';
		echo '.ttrustSocial a {color:'.$icon_color.' !important;}';
		echo '.ttrustSocial a:hover {color:'.$icon_color_hover.' !important}';
		echo '</style>';
	
        
        echo '<ul class="clearfix '.strtolower($icon_size).'">'; 
        if (!empty($delicious)) {
        	echo '<li><li><a href="' . $delicious . '" target="_blank"><span class="icon-delicious"></span></a>';
        } else {
	        echo '';
        }
        if (!empty($deviantart)) {
        	echo '<li><a href="' . $deviantart . '" target="_blank"><span class="icon-deviantart"></span></a>';
        } else {
	        echo '';
        } 
        if (!empty($dribbble)) {
			echo '<li><a href="' . $dribbble . '" target="_blank"><span class="icon-dribbble"></span></a>';
		} else {
			echo '';
		}
		if (!empty($facebook)) {
			echo '<li><a href="' . $facebook . '" target="_blank"><span class="icon-facebook"></span></a>';
		} else {
			echo '';
		}
		if (!empty($flickr)) {
			echo '<li><a href="' . $flickr . '" target="_blank"><span class="icon-flickr"></span></a>';
		} else {
			echo '';
		}
		if (!empty($forrst)) {
			echo '<li><a href="' . $forrst . '" target="_blank"><span class="icon-forrst"></span></a>';
		} else {
			echo '';
		}
		if (!empty($github)) {
			echo '<li><a href="' . $github . '" target="_blank"><span class="icon-github"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($googleplus)) {
			echo '<li><a href="' . $googleplus . '" target="_blank"><span class="icon-google-plus"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($lastfm)) {
			echo '<li><a href="' . $lastfm . '" target="_blank"><span class="icon-lastfm"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($picassa)) {
			echo '<li><a href="' . $picassa . '" target="_blank"><span class="icon-picassa"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($pinterest)) {
			echo '<li><a href="' . $pinterest . '" target="_blank"><span class="icon-pinterest1"></span></a>'; 
		} else {
			echo '';
		}
		
		if (!empty($reddit)) {
			echo '<li><a href="' . $reddit . '" target="_blank"><span class="icon-reddit"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($rss)) {
			echo '<li><a href="' . $rss . '" target="_blank"><span class="icon-feed"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($skype)) {
			echo '<li><a href="' . $skype . '" target="_blank"><span class="icon-skype"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($soundcloud)) {
			echo '<li><a href="' . $soundcloud . '" target="_blank"><span class="icon-soundcloud"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($tumblr)) {
			echo '<li><a href="' . $tumblr . '" target="_blank"><span class="icon-tumblr"></span></a>'; 
		} else {
			echo '';
		}		
		if (!empty($twitter)) {
			echo '<li><a href="' . $twitter . '" target="_blank"><span class="icon-twitter"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($vimeo)) {
			echo '<li><a href="' . $vimeo . '" target="_blank"><span class="icon-vimeo"></span></a>'; 
		} else {
			echo '';
		}
		if (!empty($wordpress)) {
			echo '<li><a href="' . $wordpress . '" target="_blank"><span class="icon-wordpress"></span></a>'; 
		} else {
			echo '';
		}

		
		echo '</ul>'; 
		echo $after_widget;     
   }
}
?>