<?php

// CLOUDFW - Posts Widget

class Cloudfw_Post extends WP_Widget {

	function Cloudfw_Post() {
		$widget_ops = array('classname' => 'widget_cloudfw_posts', 'description' => __( 'CloudFW - Recent And Popular Posts Widget' ) );
		$this->WP_Widget('cloudfw_posts', __('CloudFW - Posts'), $widget_ops);
		$this->alt_option_name = 'cloudfw_posts_entries';

		add_action( 'save_post', 	array(&$this, 'flush_widget_cache') );
		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
	}

	function widget($args, $instance) {
		$cache = wp_cache_get('cloudfw_posts', 'widget');

		if ( !is_array($cache) )
			$cache = array();

		if ( isset($cache[$args['widget_id']]) ) {
			echo $cache[$args['widget_id']];
			return;
		}

		ob_start();
		extract($args);
		$case = $instance['case'];
		
			if ($case == "recent" || $case == "") {
				$default_title = __('Recent Posts');
			}elseif ($case == "popular") {
				$default_title = __('Popular Posts');
			}

		$title = apply_filters('widget_title', empty($instance['title']) ? $default_title : $instance['title'], $instance, $this->id_base);
		if ( !$number = (int) $instance['number'] )
			$number = 10;
		else if ( $number < 1 )
			$number = 1;
		else if ( $number > 15 )
			$number = 15;

		
			
			if ($case == "recent" || $case == "") {
					$r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
			}elseif ($case == "popular") {
					$r = new WP_Query(array('orderby' => 'comment_count', 'showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
			}
		
		
		if ($r->have_posts()) :
?>
		<?php echo $before_widget; ?>
		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
		<ul>
		<?php  while ($r->have_posts()) : $r->the_post();
		
		$post_title = esc_attr(get_the_title() ? __translate( get_the_title() ) : get_the_ID());
		
		$shortened_post_title = (strlen($post_title)>20) ? mb_substr($post_title,0,20).'..' : $post_title ;
		
		?>
		<li>
        <span class="cloudfw_post_wrap">
        <span class="cloudfw_posts_thumbnail">
        	<?php if (has_post_thumbnail()): 
				
				$image_url = wp_get_attachment_image_src(get_post_thumbnail_id(),'thumbnail', true);
				echo '<a href="'.__url( get_permalink(FALSE) ).'"><img src="'.cloudfw_thumbnail(array('src'=> $image_url[0],'w'=> 60,'h'=> 60, 'r' => '1:1')).'" alt="',esc_attr(get_the_title() ? __translate( get_the_title() ) : get_the_ID()),'" /></a>';
			
			else:
				echo '<span class="cloudfw_posts_no_thumbnail"></span>'; // no thumbnail
				
			endif;
			
			?>
          </span>  
           <span class="cloudfw_posts_titles">      
                <a class="cloudfw_posts_title<?php if(strlen($post_title)>20) echo ' tooltip';?>" href="<?php the_permalink() ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $shortened_post_title; ?></a>
                <span class="cloudfw_posts_comment"><?php comments_popup_link( __( '0 Comment', 'cloudfw' ), __( '1 Comment', 'cloudfw' ), __( '% Comments', 'cloudfw' ) ); ?></span>
        	</span>
            <span class="cf"></span>
        </span>
        </li>
		<?php endwhile; ?>
		</ul><div class="clear"></div>
		<?php echo $after_widget; ?>
<?php
		wp_reset_postdata();

		endif;

		$cache[$args['widget_id']] = ob_get_flush();
		wp_cache_set('cloudfw_posts', $cache, 'widget');
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['number'] = (int) $new_instance['number'];
		$instance['case'] = strip_tags($new_instance['case']);
		$this->flush_widget_cache();

		$alloptions = wp_cache_get( 'alloptions', 'options' );
		if ( isset($alloptions['cloudfw_posts_entries']) )
			delete_option('cloudfw_posts_entries');

		return $instance;
	}

	function flush_widget_cache() {
		wp_cache_delete('cloudfw_posts', 'widget');
	}

	function form( $instance ) {
		$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
		if ( !isset($instance['number']) || !$number = (int) $instance['number'] )
			$number = 5;
		$case = isset($instance['case']) ? esc_attr($instance['case']) : 'recent';
?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','cloudfw'); ?></label>
		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>

		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:','cloudfw'); ?></label>
		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>

        <p><label for="<?php echo $this->get_field_id('case'); ?>"><?php _e('Show:','cloudfw'); ?></label>
      
        <select id="<?php echo $this->get_field_id('case'); ?>" name="<?php echo $this->get_field_name('case'); ?>">
        	<option <?php if ($case == 'recent')  echo ' selected="selected"';  ?> value="recent"><?php _e('Recent Posts','cloudfw'); ?></option>
        	<option <?php if ($case == 'popular') echo ' selected="selected"';  ?> value="popular"><?php _e('Popular Posts','cloudfw'); ?></option>
        </select></p>
                
<?php
	}
}
register_widget('Cloudfw_Post');
// # / CLOUDFW - Recent Posts



// CLOUDFW - Twitter Widget

class Cloudfw_Twitter extends WP_Widget {
	function Cloudfw_Twitter() {
		$widget_ops = array('classname' => 'widget_cloudfw_twitter', 'description' => '' );
		$this->WP_Widget('cloudfw_twitter', 'CloudFW - Twitter', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		
		
		if ( !$count = (int) $instance['count'] )
			$count = 5;
		else if ( $count < 1 )
			$count = 1;
		else if ( $count > 15 )
			$count = 15;
			

		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);

		if ( !empty( $title ) ) { 
		
		echo $before_title . $title . $after_title; 
		
		};
		
		$id = 'twitter_widget_'.cloudfw_randomizer(5);
		
		echo '<ul id="'.$id.'">';
		
		$username = $instance['username'];
		
		if (empty($username)):
		
		
		echo '<li>'.__('Plase Enter Your Twitter Username To Show Its Tweets Here','cloudfw').'</li>';
		
		else:
						

		echo '<li class="twitter-loading"></li>';

		echo '<script type="text/javascript">
				$(document).ready(function(){
					$("#'.$id.'").tweet({
						username: "'.$username.'",
						join_text: false,
						count: '.$count.',
						type: "widget",
						loading_text: " ",
						avatar_size: 32
					});
				});
			</script>';
			
		endif;
		
		echo '</ul>'.$after_widget;
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['username'] = strip_tags($new_instance['username']);
		$instance['count'] = strip_tags($new_instance['count']);

		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'username'=> '', 'count'=>5 ) );
		$title = strip_tags($instance['title']);
		$username = strip_tags($instance['username']);
		$count = strip_tags($instance['count']);
?>

<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','cloudfw'); ?>:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>

<p><label for="<?php echo $this->get_field_id('username'); ?>"><?php _e('Twitter Username','cloudfw'); ?>:
<input class="widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>" type="text" value="<?php echo esc_attr($username); ?>" /></label>
</p>
<p><label for="<?php echo $this->get_field_id('count'); ?>">Number Of Tweets Showed:
<input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo esc_attr($count); ?>" /></label>
</p>
<?php
	}
}
register_widget('Cloudfw_Twitter');


// CLOUDFW - SubPages Widget

class Cloudfw_SubPages extends WP_Widget {
	function Cloudfw_SubPages() {
		$widget_ops = array('classname' => 'widget_subposts', 'description' => '' );
		$this->WP_Widget('cloudfw_subposts', 'CloudFW - Sub Pages', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);

		$get_pid = $instance['pid'];
		if (empty($get_pid)) {
		  if (is_page()) {
			  	
				global $post;
				$parent_id = $post->post_parent;
				
				if ($parent_id):
				
					//$def_title = '<a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>';
					$pid = $parent_id;
					
				else:
				
					$def_title = __translate( get_the_title() );
					$pid = get_the_ID();
				
				endif;
		  
		  } 
		} else {
		  $pid = $get_pid;
		}
		
		if (empty($pid)) return false;
		
		$subpages = $instance['subpages'];

		if ($subpages == 1)	$subpages = 0;	else $subpages = 1;
		
		$args = array(
			'child_of'		=> $pid,
			'depth'			=> $subpages,
			'exclude '		=> NULL,
			'title_li'		=> 0,
			'sort_column'	=> 'menu_order',
			'echo'			=> 0,					 
			
			);
		
		$out = wp_list_pages($args);

		if (!empty($out)):
		
			echo $before_widget;
			$title = empty($instance['title']) ? $def_title : apply_filters('widget_title', $instance['title']);
	
			if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
			
			echo '<ul class="'._isso($subpages, 'subpages_off', 'subpages_on').'">';
			
				echo $out;
				
			echo '</ul>';
			echo $after_widget;
			
		endif;
		
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['pid'] = strip_tags($new_instance['pid']);
		$instance['subpages'] = strip_tags($new_instance['subpages']);

		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'pid'=> NULL, 'subpages'=> 1 ) );
		$title = strip_tags($instance['title']);
		$pid = strip_tags($instance['pid']);
		$subpages = strip_tags($instance['subpages']);
?>

<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','cloudfw'); ?>:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>

<p><label for="<?php echo $this->get_field_id('pid'); ?>"><?php _e('Custom Parent Page','cloudfw'); ?>: 

<p><em><?php _e('If any page is selected for custom parent page, it will be current page','cloudfw'); ?></em></p>

<?php
     $pages =  wp_dropdown_pages(array('echo' => 0, 'selected' => $pid, 'name' => $this->get_field_name('pid'), 'sort_column'=> 'menu_order, post_title'));
	 
	 
	 $pages = str_replace('id="'.$this->get_field_name('pid').'">', 'id="'.$this->get_field_name('pid').'" style="width:100%;"><option value="" class="level-0"></option>',$pages);
	 
	 echo $pages;
?>
</p>
<br/><br/>
<p><label for="<?php echo $this->get_field_id('subpages'); ?>"><?php _e('Show Subpages','cloudfw'); ?>:</label><br />
    <input type="radio" id="<?php echo $this->get_field_id('subpages'); ?>" name="<?php echo $this->get_field_name('subpages'); ?>" value="1" <?php if ($instance['subpages'] == 1) { echo "checked='checked'"; } ?>><?php _e('Yes','cloudfw'); ?>
    <input type="radio" id="<?php echo $this->get_field_id('subpages'); ?>" name="<?php echo $this->get_field_name('subpages'); ?>" value="0" <?php if ($instance['subpages'] == 0) { echo "checked='checked'"; } ?>><?php _e('No','cloudfw'); ?>
</p><?php
	}
}
register_widget('Cloudfw_SubPages');


$social_widgets_services = array(
	'email'			=>		'Your Email URL',
	'facebook'		=>		'Facebook URL',
	'twitter'		=>		'Twitter URL',
	'friendfeed'	=>		'FriendFeed URL',
	'youtube'		=>		'Youtube URL',
	'vimeo'			=>		'Vimeo URL',
	'digg'			=>		'Digg URL',
	'tumblr'		=>		'Thumblr URL',
	'technorati'	=>		'Technorati URL',
	'stumbleupon'	=>		'Stumbleupon URL',
	'linkedin'		=>		'LinkedIn URL',
	'yahoo-buzz'	=>		'Yahoo Buzz URL',
	'skype'			=>		'Skype URL',
	'google'		=>		'Google Account URL',
	'google-talk'	=>		'Google Talk URL',
	'messenger'		=>		'Messenger URL',
	'yahoo-messenger'=>		'Yahoo Messenger URL',
	'formspring'	=>		'Formspring URL',
	'dribbble'		=>		'Dribble URL',
	'myspace'		=>		'Myspace URL',
	'flickr'		=>		'FlickR URL',
	'orkut'			=>		'Orkut URL',
	'reddit'		=>		'Reddit URL',
	);

// CLOUDFW - Social Services Widget

class Cloudfw_Social_Services extends WP_Widget {
	function Cloudfw_Social_Services() {
		$widget_ops = array('classname' => 'widget_cloudfw_social', 'description' => '' );
		$this->WP_Widget('cloudfw_social', 'CloudFW Social Services', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);

		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
			
			if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
			$social_services_icons_dir = TMP_ADMIN_SRC. "/social_icon";
			
		switch($instance['size']){
			case '16': $sizes = '-16x16.png'; break;
			case '24': default: $sizes = '-24x24.png'; break;
			case '32': $sizes = '-32x32.png'; break;
			}

			
	global $social_widgets_services;
	foreach ((array)$social_widgets_services as $service_id => $service_title)
			{
			if (!empty($instance['widget_social_'.$service_id]))echo '<a href="'.$instance['widget_social_'.$service_id].'"><img src="'.$social_services_icons_dir.'/'.$service_id.$sizes.'" alt="" /></a> ';
			}
	

		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
		global $social_widgets_services;
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['size'] = strip_tags($new_instance['size']);

	foreach ($social_widgets_services as $service_id => $service_title)
			{
			$instance['widget_social_'.$service_id] = strip_tags($new_instance['widget_social_'.$service_id]);
			}


		return $instance;
	}

	function form($instance) {
		global $social_widgets_services;
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'size' => '24' ) );
		$title = strip_tags($instance['title']);
		$size = strip_tags($instance['size']);

foreach ($social_widgets_services as $service_id => $service_title):
		
		${widget_social_.$service_id} = strip_tags($instance['widget_social_'.$service_id]);

endforeach;?>

<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','cloudfw'); ?>:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>

    <p><label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Icon Size','cloudfw');?>:</label>
  
    <select id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>">
        <option <?php if ($size == '16')  echo ' selected="selected"';  ?> value="16">16x16</option>
        <option <?php if ($size == '24') echo ' selected="selected"';  ?> value="24">24x24</option>
        <option <?php if ($size == '32') echo ' selected="selected"';  ?> value="32">32x32</option>
    </select>px</p>
                


<?php 	foreach ($social_widgets_services as $service_id => $service_title):?>

<p><label for="<?php echo $this->get_field_id('widget_social_'.$service_id); ?>"><?php echo $service_title; ?>:
<input class="widefat" id="<?php echo $this->get_field_id('widget_social_'.$service_id); ?>" name="<?php echo $this->get_field_name('widget_social_'.$service_id); ?>" type="text" value="<?php echo esc_attr(${widget_social_.$service_id}); ?>" /></label></p>

<?php 	endforeach; ?>

<?php
	}
}
register_widget('Cloudfw_Social_Services');





$social_widgets_services_header = array(
	'rss'			=>		'RSS URL',
	'facebook'		=>		'Facebook URL',
	'twitter'		=>		'Twitter URL',
	'flickr'		=>		'FlickR URL',
	'daviantart'	=>		'Daviantart URL',
	'youtube'		=>		'Youtube URL',
	'vimeo'			=>		'Vimeo URL',
	'digg'			=>		'Digg URL',
	'forrst'		=>		'Forrst URL',
	'technorati'	=>		'Technorati URL',
	'stumbleupon'	=>		'Stumbleupon URL',
	'delicious'		=>		'Delicious URL',
	'myspace'		=>		'Myspace URL',
	'lastfm'		=>		'LastFM URL',
	);


class Cloudfw_Social_Services_Header extends WP_Widget {
	function Cloudfw_Social_Services_Header() {
		$widget_ops = array('classname' => 'widget_cloudfw_social_header', 'description' => '' );
		$this->WP_Widget('cloudfw_social_header', 'CloudFW Social Services For Header', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);


		$default_opacity = $instance['default_opacity'];
		$hover_opacity = $instance['hover_opacity'];

		$default_opacity = is_numeric($default_opacity) && !($default_opacity > 1) && !($default_opacity <= 0) ? $default_opacity : 1;
		$hover_opacity = is_numeric($hover_opacity) && !($hover_opacity > 1) && !($hover_opacity <= 0) ? $hover_opacity : 1;

		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		
		$color = $instance['color'];
		if (empty($color)) $color = 'light';
			
			if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
			$social_services_icons_dir = TMP_URL. "/lib/icons/MonotoneIcons/".apply_filters('clodfw_social_widget_color', $color, $widget_id);

			
	global $social_widgets_services_header;
	foreach ((array)$social_widgets_services_header as $service_id => $service_title)
		{
		if (!empty($instance['widget_social_'.$service_id]))echo '<span><a href="'.$instance['widget_social_'.$service_id].'"><img src="'.$social_services_icons_dir.'/'.$service_id.'.png" alt="" /></a></span> ';
		}
	

		echo $after_widget;
		?>

		<script>

		jQuery(document).ready(function() {

			if (!jQuery.browser.msie  && !(parseInt(jQuery.browser.version) == 7)) {

			    jQuery('#<?php echo $widget_id; ?> a').fadeTo(1000, <?php echo $default_opacity; ?>).hover(function () {
			        jQuery(this).stop(true).fadeTo(200, <?php echo $hover_opacity; ?>);
			    }, function () {
			        jQuery(this).stop(true).fadeTo(200, <?php echo $default_opacity; ?>);
			    });
			}
		});


		</script>

		<?php
	}

	function update($new_instance, $old_instance) {
		global $social_widgets_services_header;
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['color'] = strip_tags($new_instance['color']);
		$instance['default_opacity'] = strip_tags($new_instance['default_opacity']);
		$instance['hover_opacity'] = strip_tags($new_instance['hover_opacity']);

		foreach ($social_widgets_services_header as $service_id => $service_title)
			$instance['widget_social_'.$service_id] = strip_tags($new_instance['widget_social_'.$service_id]);

		return $instance;
	}

	function form($instance) {
		global $social_widgets_services_header;
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'default_opacity' => .4, 'hover_opacity' => 1 ) );
		$title = strip_tags($instance['title']);
		$color = strip_tags($instance['color']);
		$default_opacity = strip_tags($instance['default_opacity']);
		$hover_opacity = strip_tags($instance['hover_opacity']);

foreach ($social_widgets_services_header as $service_id => $service_title):
		
		${widget_social_.$service_id} = strip_tags($instance['widget_social_'.$service_id]);

endforeach;?>

<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','cloudfw'); ?>:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>


<p><label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Color Scheme','cloudfw');?>:</label>
  
    <select id="<?php echo $this->get_field_id('color'); ?>" name="<?php echo $this->get_field_name('color'); ?>">
        <option <?php if ($color == 'light-double')  echo ' selected="selected"';  ?> value="light-double">Light 100%</option>
        <option <?php if ($color == 'light')  echo ' selected="selected"';  ?> value="light">Light 50%</option>
        <option <?php if ($color == 'dark') echo ' selected="selected"';  ?> value="dark">Dark</option>
        <option <?php if ($color == 'blue') echo ' selected="selected"';  ?> value="blue">Dark Blue</option>
    </select>
</p>

<p><label  id="<?php echo $this->get_field_id('default_opacity'); ?>"><?php _e('Opacity Level','cloudfw'); ?>:
<input class="" id="<?php echo $this->get_field_id('default_opacity'); ?>" name="<?php echo $this->get_field_name('default_opacity'); ?>" type="text" value="<?php echo esc_attr($default_opacity); ?>" /></label></p>

<p><label  id="<?php echo $this->get_field_id('hover_opacity'); ?>"><?php _e('Opacity Level When Hovered','cloudfw'); ?>:
<input class="" id="<?php echo $this->get_field_id('hover_opacity'); ?>" name="<?php echo $this->get_field_name('hover_opacity'); ?>" type="text" value="<?php echo esc_attr($hover_opacity); ?>" /></label></p>


<?php foreach ($social_widgets_services_header as $service_id => $service_title):?>

<p><label for="<?php echo $this->get_field_id('widget_social_'.$service_id); ?>"><?php echo $service_title; ?>:
<input class="widefat" id="<?php echo $this->get_field_id('widget_social_'.$service_id); ?>" name="<?php echo $this->get_field_name('widget_social_'.$service_id); ?>" type="text" value="<?php echo esc_attr(${widget_social_.$service_id}); ?>" /></label></p>

<?php 	endforeach; ?>

<?php
	}
}
register_widget('Cloudfw_Social_Services_Header');


// CLOUDFW - Search Widget

class Cloudfw_Search extends WP_Widget {
	function Cloudfw_Search() {
		$widget_ops = array('classname' => 'widget_cloudfw_search', 'description' => 'Special Search Form For Header' );
		$this->WP_Widget('cloudfw_search', 'CloudFW - Search Form For Header', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);


		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);

		if ( !empty( $title ) ) { 
		
		echo $before_title . $title . $after_title; 
		
		};

		echo ' <form action="'.home_url().'" id="searchform" method="get">
                      <div id="search-module">
                            
                                <span id="search-module-icon"></span><input type="text" name="s" id="search-input" />
                                
                        </div><!-- /#search-module -->
                    </form>
		';

		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);

		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
		$title = strip_tags($instance['title']);
?>

<label for="<?php echo $this->get_field_id('title'); ?>">Title:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>

<?php
	}
}
register_widget('Cloudfw_Search');


// CLOUDFW - Registration

class Cloudfw_Registration extends WP_Widget {
	function Cloudfw_Registration() {
		$widget_ops = array('classname' => 'widget_cloudfw_registration', 'description' => 'Registration Module For Header' );
		$this->WP_Widget('widget_cloudfw_registration', 'CloudFW - Registration Module', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);

		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);

		if ( !empty( $title ) ) { 
		
		echo $before_title . $title . $after_title; 
		
		};
		
		if (!(current_user_can('read'))){ 
		// Not Logged In
		?>
		
		<ul id="menu-login-menu" class="menu widget_nav_menu">
        	<li class="cloudfw-login"><a href="#/login"><?php _e('Login','cloudfw'); ?></a></li>
            <?php if (get_option('users_can_register')) {?><li class="cloudfw-register"><a href="#/register"><?php _e('Register','cloudfw'); ?></a></li><?php } // if users_can_register ?>
        </ul>
        
		<?php }else{ 
		// Logged In
		
		global $current_user;
		get_currentuserinfo();
		
		?>
    	
        <?php //print_r($current_user->user_email);?>
        <div id="user-profile">
        
        <div class="user-profile-avatar">
        <a href="#/profile"><?php echo get_avatar( $current_user->user_email, 40 ); ?></a>
        </div>
        
		<ul id="menu-profile" class="menu widget_nav_menu">
        	<li class="cloudfw-profile"><a href="#/profile"><?php echo $current_user->user_login; ?></a></li>
        	<li><a href="<?php echo wp_logout_url(__url(get_permalink())); ?>"><?php _e('Logout','cloudfw');?></a></li>
        </ul>
        
        <div class="cf"></div>
        
        </div>
        
        
		
		<?php
		}
		
		
		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);

		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
		$title = strip_tags($instance['title']);
?>

<label for="<?php echo $this->get_field_id('title'); ?>">Title:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>

<?php
	}
}
register_widget('Cloudfw_Registration');?>