<?php
add_action( 'widgets_init', 'comments_avatar_widget' );
function comments_avatar_widget() {
	register_widget( 'comments_avatar' );
}
class comments_avatar extends WP_Widget {	

	public function __construct(){
		$widget_ops = array( 'classname' => 'comments_avatar_widget','description' => 'آخرین دیدگاهها با اسلایدر'  );
		$control_ops = array( 'id_base' => 'comments_avatar_widget' );
		parent::__construct( 'comments_avatar_widget',( 'Jam - آخرین دیدگاهها'), $widget_ops, $control_ops );
	}
	
	function widget( $args, $instance ) {
		extract( $args );

		$title = apply_filters('widget_title', $instance['title'] );
		$no_of_comments = $instance['no_of_comments'];
		$avatar_size = $instance['avatar_size'];	
		if ( $title ) 
			 ?>
		
		<div class="slider_comments clearfix">
        <div class="polist">
		<?php tie_most_commented( $no_of_comments , $avatar_size); ?>
		</div>
        </div>
	<?php 
		
	}

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

	function form( $instance ) {
		$defaults = array( 'title' =>__( 'دیدگاههای اخیر' , 'tie'), 'no_of_comments' => '3' , 'avatar_size' => '80' );
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
		<p>
			<label for="<?php echo $this->get_field_id( 'no_of_comments' ); ?>">تعداد دیدگاه :  </label>
			<input id="<?php echo $this->get_field_id( 'no_of_comments' ); ?>" name="<?php echo $this->get_field_name( 'no_of_comments' ); ?>" value="<?php echo $instance['no_of_comments']; ?>" type="text" size="3" />
		</p>


	<?php
	}
}
?>