<?php
/**
 *  ffGetInTouch
 *
 *  @author freshface
 */

// private register this widget for framework
fEnv::addWidget('ffSocial');

class ffSocial extends frameworkWidget {
	/**
	 *  Defining the widget options
	 */

     protected $_widgetAdminTitle =       "Social Buttons - Custom Widget";
     protected $_widgetAdminDescription = "Social Buttons widget";
     protected $_widgetWrapperClasses =   "";
     protected $_widgetFormSize =         frameworkWidget::WIDGET_FORM_SIZE_WIDE;

     protected $socialIconTypes = array( 'twitter',
    	'facebook',
    	'linkedin',
    	'stumbleupon',
    	'tumblr',
    	'flickr',
    	'delicious', 
    	'rss',
    	'emailurl',
    	'youtube',
    	'vimeo',
    	'msn',
    	'skype',
    	'mobileme',
      'email' );

     protected $options = array(
        array(  'id' => 'title',
                'description' => 'Title',
                'type' => 'text',
                'default' => 'Social icons widget'),

        array(  'id' => 'social',
                'description' => 'Social Links',
                'type' => 'textarea',
                'default' => '',
                ),
     );

	/**
	 * Printing widget, called by wordpress
	 */
    protected function _widget($args, $instance) {
    	
        extract( $args );

        echo $before_widget;

        if( !empty( $instance['title'] ) ) {
            $instance['title'] = apply_filters('widget_title', $instance['title'] );
        }

  		echo $before_title . $instance['title'] . $after_title;
  		
        echo '<div id="widget_social">';
        $socialStuff = new ffSocialFeeder( $instance['social'] );
		if( !empty($socialStuff->items) ) {
	        foreach ($socialStuff->items as $socialItem) {
	        	if( !in_array( $socialItem->type, $this->socialIconTypes ) ) continue;
	        	
	        	echo '<a href="'.$socialItem->link.'"><img src="'.get_bloginfo('template_url').'/gfx/icons/social/small/'.$socialItem->type.'.png" alt="'.$socialItem->type.'" /></a>';
	        	//if( in_array( $this->socialIconTypes ))
	            //echo '<li class="' . $socialItem->type . '"><a href="' . $socialItem->link . '">' . $socialItem->title . '</a></li>';
	        }
		}
        echo '<div class="clear"></div></div>';
        echo $after_widget;
    }
}
