<?php

	/*
		Plugin Name: Testimonial Widget
		Plugin URI: http://serifly.com
		Description: Displays a clients testimonial.
		Author: Serifly
		Version: 1.0
		Author URI: http://serifly.com
	*/

	class serifly_widget_testimonial extends WP_WIDGET
	{
		function serifly_widget_testimonial()
		{
			$widget_ops = array('classname' => 'testimonialWidget', 'description' => 'Displays a clients testimonial. Change the values in the theme options panel.' );
			$this->WP_Widget('serifly_widget_testimonial', 'Customer Review', $widget_ops);
		}
		
		function form($instance)
		{
			$instance = wp_parse_args((array)$instance, array('title' => 'Customer Review', 'author' => '', 'text' => ''));
			$title = $instance['title'];
			$author = $instance['author'];
			$text = $instance['text'];
			
			// HTML Starts
			?>
						
			<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'serifly'); ?>: <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('author'); ?>"><?php _e('Author', 'serifly'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('author'); ?>" name="<?php echo $this->get_field_name('author'); ?>" type="text" value="<?php echo esc_attr($author); ?>" /></label></p>
			<p><label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text', 'serifly'); ?>: <textarea class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo esc_attr($text); ?></textarea></label></p>
			
			<?php
			// HTML Ends			
		}
		
		function update($new_instance, $old_instance)
		{
			$instance = $old_instance;
			$instance['title'] = $new_instance['title'];
			$instance['author'] = $new_instance['author'];
			$instance['text'] = $new_instance['text'];
			return $instance;
		}
		
		function widget($args, $instance)
		{
			extract($args, EXTR_SKIP);
		 
		    echo $before_widget;
		    $title = empty($instance['title']) ? ' ' : apply_filters('serifly_widget_testimonial', $instance['title']);
		    $author = empty($instance['author']) ? ' ' : apply_filters('serifly_widget_testimonial', $instance['author']);
		    $text = empty($instance['text']) ? ' ' : apply_filters('serifly_widget_testimonial', $instance['text']);
		 
		    if (!empty($title))
		    {
		    	echo $before_title . $title . $after_title;;
		 	}
		 
		 	// HTML Starts
		 	?>
		 	
			<div class="testimonialBox">
				<p>&ldquo;<?php echo $text; ?>&rdquo;</p>
				<div class="author">
					<?php echo $author; ?>
				</div>
			</div>
		 	
		 	<?php
		 	// HTML Ends
		 
		    echo $after_widget;
		}
	}
	
	add_action('widgets_init', create_function('', 'return register_widget("serifly_widget_testimonial");'));

?>