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

	function tabs_posts() {
		$widget_ops = array( 'classname' => 'tabs-posts' );
		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'tabs-posts-widget' );
		$this->WP_Widget( 'tabs-posts-widget', 'tabs widget', $widget_ops, $control_ops );
	}

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

		$title = apply_filters('widget_title', $instance['cat_posts_title'] );
		$no_of_posts = $instance['no_of_posts'];
		$cats_id = $instance['cats_id'];
		$thumb = $instance['thumb'];
         /*
		echo $before_widget;
			echo $before_title;
			echo $title ;*/ ?>
		<?php/* echo $after_title; */?>

 <div class="tabs_widget">
      <ul class="tabs_nav">
         <li class="active"><a href="#tab1">الأكثر شعبية</a></li>
         <li><a href="#tab2">أحدث التعليقات</a></li>
      </ul>            <div class="clear"></div>
      <div class="tabs_content">
         <div class="tab_container" id="tab1">
            <ul class="posts_widget">

<?php
global $post;                                  //, 'category' => 1
$args = array( 'numberposts' => 4, 'offset'=> 0 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :	setup_postdata($post); ?>
<li>
<div class="thumb"> <a href="<?php the_permalink(); ?>">
<img width="60" height="60" src="<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<?php echo $image[0]; ?>
<?php endif; ?>" class="attachment-small wp-post-image" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<span class="posts_widget_overlay"></span></a></div>
<p><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></p>
</li>
<?php endforeach; ?>
</ul>
         </div>
         <!--//tab1-->

         <div class="tab_container" id="tab2">
            <ul class="posts_widget">
      <?php $comments = get_comments('status=approve&number=5'); ?>

<?php foreach ($comments as $comment) { ?>
    <li>
    <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"
           rel="external nofollow" title="<?php echo $title; ?>">
    <?php
        $title = get_the_title($comment->comment_post_ID);

        echo '<div class="thumb">' .get_avatar( $comment, '53' ) .'</a></div>';

        echo '<span class="recommauth">' . ($comment->comment_author) . '</span>';
        ?> : <?php
        echo wp_html_excerpt( $comment->comment_content, 72 ); ?>
        </a>

    </li>
<?php }  ?>

</ul>
         </div>
         <!--//tab2-->



      </div>
      </div>
   <!--//widget-->





	<?php
	   //	echo $after_widget;
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['cat_posts_title'] = strip_tags( $new_instance['cat_posts_title'] );
		$instance['no_of_posts'] = strip_tags( $new_instance['no_of_posts'] );
		
		$instance['cats_id'] = implode(',' , $new_instance['cats_id']  );

		$instance['thumb'] = strip_tags( $new_instance['thumb'] );
		return $instance;
	}

	function form( $instance ) {
		$defaults = array( 'cat_posts_title' =>__( 'Category Posts' , 'tie') , 'cats_id' => '1'  );
		$instance = wp_parse_args( (array) $instance, $defaults );
		
		$categories_obj = get_categories();
		$categories = array();

		foreach ($categories_obj as $pn_cat) {
			$categories[$pn_cat->cat_ID] = $pn_cat->cat_name;
		}
		?>



	<?php
	}
}
?>