<?php
add_action( 'widgets_init', 'tabe_big_load_widgets' );

function tabe_big_load_widgets() {
	register_widget( 'tabe_big_load_widgets' );
}

class tabe_big_load_widgets extends WP_Widget {

public function __construct(){
		$widget_ops = array( 'classname' => 'tabe_big_load_widgets', 'description' => __('سایدبار اصلی ', 'example') );
		$control_ops = array( 'width' => 300, 'height' => 355, 'id_base' => 'tabe_big_load_widgets' );
		parent::__construct( 'tabe_big_load_widgets',''. __( 'News - تب اصلی مطالب' , 'wp'), $widget_ops, $control_ops );
	}

function widget( $args, $instance ) {
		extract( $args );
		global $post;
		global $more;
		$more = -1;
		$catid = ( isset( $instance['catid'] ) ) ? strip_tags( $instance['catid'] ) : 0;
		$catid2 = ( isset( $instance['catid2'] ) ) ? strip_tags( $instance['catid2'] ) : 0;
		$catid3 = ( isset( $instance['catid3'] ) ) ? strip_tags( $instance['catid3'] ) : 0;
		$catid4 = ( isset( $instance['catid4'] ) ) ? strip_tags( $instance['catid4'] ) : 0;
		$excludepost = $instance['excludepost'];
		$excludepost2 = $instance['excludepost2'];
		$excludepost3 = $instance['excludepost3'];
		$excludepost4 = $instance['excludepost4'];
		$title_word_1 = $instance['title_word_1'];
		$title_word_2 = $instance['title_word_2'];
		$title_word_3 = $instance['title_word_3'];
		$title_word_4 = $instance['title_word_4'];
		
		?>
			<div class="boxe <?php echo $do_border; ?>">
			<div class="cat-tabs-header">
			<ul>
			<li><a href="#<?php echo $catid; ?>"> <?php echo get_cat_name(''.$catid.'');?></a></li>
			<li><a href="#<?php echo $catid2; ?>"> <?php echo get_cat_name(''.$catid2.'');?></a></li>
			<li><a href="#<?php echo $catid3; ?>"> <?php echo get_cat_name(''.$catid3.'');?></a></li>
			<li><a href="#<?php echo $catid4; ?>"><?php echo get_cat_name(''.$catid4.'');?></a></li>
			</ul>
		    </div>
				<div class="cat-tabs-wrap cat-tabs-wrap1" id="<?php echo $catid; ?>">
							<?php 
							$check_1 = 1;
							$start_1 = 1;
							$end_1 = 6;
							$list_exclude_1 = explode(',', $excludepost);
							$query_param1 = new WP_Query( array (
									'category__in' => $catid,
									'post__not_in' => $list_exclude_1,
									'posts_per_page'=> 3,
								));
							while ($query_param1->have_posts()) : $query_param1->the_post();
							?>					
        <div class="post-item-excerpt clearfix">
        <div class="post-thumbnail medium">
		<?php if(has_post_thumbnail()){?>
                  <a class="attachment-medium size-medium wp-post-image" href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-135', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a>
                  <?php }else{ ?>
                  <img src="<?php bloginfo("template_url"); ?>/img/none.png">
                  <?php } ?>
<span class="boxe-1-left-date"><?php the_time('d M Y'); ?></span>
        </div>
        <div class="post-excerpt">
		  <?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?> <small class="subtitle text-muted"><i class="fa fa-stop" aria-hidden="true"></i> <?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></small> <?php } ?>
                <h3 class="post-title2">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h3>
            <div class="post-excerpt-summary">
                <p><?php if(get_meta('lead') != false) : echo get_meta('lead'); else : the_excerpt(); endif; ?></p>
            </div>
        </div>
    </div>	
					
							<?php $start_1++; endwhile; wp_reset_query(); ?>
					</div>	
				<div class="cat-tabs-wrap cat-tabs-wrap2" id="<?php echo $catid2; ?>">

							<?php 
							$check_1 = 1;
							$check_2 = 2;
							$check_3 = 3;
							$start_1 = 1; 
							$list_exclude_2 = explode(',', $excludepost2);
							$query_param2 = new WP_Query( array (
									'category__in' => $catid2,
									'post__not_in' => $list_exclude_2,
									'posts_per_page'=> 3,
								));
							
							while ($query_param2->have_posts()) : $query_param2->the_post();
							?>
        <div class="post-item-excerpt clearfix">
        <div class="post-thumbnail medium">
<?php if(has_post_thumbnail()){?>
                  <a class="attachment-medium size-medium wp-post-image" href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-135', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a>
                  <?php }else{ ?>
                  <img src="<?php bloginfo("template_url"); ?>/img/none.png">
                  <?php } ?><span class="boxe-1-left-date"><?php the_time('d M Y'); ?></span>
        </div>
        <div class="post-excerpt">
		  <?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?> <small class="subtitle text-muted"><i class="fa fa-stop" aria-hidden="true"></i> <?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></small> <?php } ?>
                <h3 class="post-title2">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h3>
            <div class="post-excerpt-summary">
                <p><?php if(get_meta('lead') != false) : echo get_meta('lead'); else : the_excerpt(); endif; ?></p>
            </div>
        </div>
    </div>	
							<?php $start_1++; endwhile; wp_reset_query(); ?>
					</div>
							
				<div class="cat-tabs-wrap cat-tabs-wrap3" id="<?php echo $catid3; ?>">

							<?php 
							$check_1 = 1;
							$start_1 = 1;
							$end_1 = 6;
							$list_exclude_3 = explode(',', $excludepost3);
							$query_param3 = new WP_Query( array (
									'category__in' => $catid3,
									'post__not_in' => $list_exclude_3,
									'posts_per_page'=> 3,
								));
							while ($query_param3->have_posts()) : $query_param3->the_post();
							?>
							
        <div class="post-item-excerpt clearfix">
        <div class="post-thumbnail medium">
          <?php if(has_post_thumbnail()){?>
                  <a class="attachment-medium size-medium wp-post-image" href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-135', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a>
                  <?php }else{ ?>
                  <img src="<?php bloginfo("template_url"); ?>/img/none.png">
                  <?php } ?><span class="boxe-1-left-date"><?php the_time('d M Y'); ?></span>
        </div>
        <div class="post-excerpt">
		  <?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?> <small class="subtitle text-muted"><i class="fa fa-stop" aria-hidden="true"></i> <?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></small> <?php } ?>
                <h3 class="post-title2">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h3>
            <div class="post-excerpt-summary">
                <p><?php if(get_meta('lead') != false) : echo get_meta('lead'); else : the_excerpt(); endif; ?></p>
            </div>
        </div>
    </div>	
					
							<?php $start_1++; endwhile; wp_reset_query(); ?>

					</div>
						

				
				<div class="cat-tabs-wrap cat-tabs-wrap4" id="<?php echo $catid4; ?>">

							<?php 
							$check_1 = 1;
							$check_2 = 2;
							$check_3 = 3;
							$start_1 = 1; 
							$list_exclude_4 = explode(',', $excludepost4);
							$query_param4 = new WP_Query( array (
									'category__in' => $catid4,
									'post__not_in' => $list_exclude_4,
									'posts_per_page'=> 3,
								));
							while ($query_param4->have_posts()) : $query_param4->the_post();
							?>
							
        <div class="post-item-excerpt clearfix">
        <div class="post-thumbnail medium">
           <?php if(has_post_thumbnail()){?>
                  <a class="attachment-medium size-medium wp-post-image" href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-135', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a>
                  <?php }else{ ?>
                  <img src="<?php bloginfo("template_url"); ?>/img/none.png">
                  <?php } ?><span class="boxe-1-left-date"><?php the_time('d M Y'); ?></span>
        </div>
        <div class="post-excerpt">
		  <?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?> <small class="subtitle text-muted"><i class="fa fa-stop" aria-hidden="true"></i> <?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></small> <?php } ?>
                <h3 class="post-title2">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h3>
            <div class="post-excerpt-summary">
                <p><?php if(get_meta('lead') != false) : echo get_meta('lead'); else : the_excerpt(); endif; ?></p>
            </div>
        </div>
    </div>	
					
							<?php $start_1++; endwhile; wp_reset_query(); ?>
								
					</div>
							
				</div>


		<?php
		}
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['catid'] = strip_tags($new_instance['catid']);
		$instance['catid2'] = strip_tags($new_instance['catid2']);
		$instance['catid3'] = strip_tags($new_instance['catid3']);
		$instance['catid4'] = strip_tags($new_instance['catid4']);
		$instance['excludepost'] = strip_tags($new_instance['excludepost']);
		$instance['excludepost2'] = strip_tags($new_instance['excludepost2']);
		$instance['excludepost3'] = strip_tags($new_instance['excludepost3']);
		$instance['excludepost4'] = strip_tags($new_instance['excludepost4']);
		$instance['title_word_1'] = strip_tags($new_instance['title_word_1']);
		$instance['title_word_2'] = strip_tags($new_instance['title_word_2']);
		$instance['title_word_3'] = strip_tags($new_instance['title_word_3']);
		$instance['title_word_4'] = strip_tags($new_instance['title_word_4']);
		return $instance;
		}

	function form( $instance ) {
		$catid = isset( $instance['catid'] ) ? strip_tags( $instance['catid'] )  : 0;
		$catid2 = isset( $instance['catid2'] ) ? strip_tags( $instance['catid2'] )  : 0;
		$catid3 = isset( $instance['catid3'] ) ? strip_tags( $instance['catid3'] )  : 0;
		$catid4 = isset( $instance['catid4'] ) ? strip_tags( $instance['catid4'] )  : 0;
		$categories = get_categories(); 
		$defaults = array(
			'title_word_1' => __('11', 'boxp8'),
			'title_word_2' => __('12', 'boxp8'),
			'title_word_3' => __('8', 'boxp8'),
			'title_word_4' => __('12', 'boxp8'),
			'title_module_widget_style' => __('module-border-1', 'boxp8'),
			//'custom_color' => __('', 'boxp8'),
			'excludepost' => __('', 'boxp8'),
			'excludepost2' => __('', 'boxp8'),
			'excludepost3' => __('', 'boxp8'),
			'excludepost4' => __('', 'boxp8'),
			'excludepost' => __('', 'boxp8'));
		
		$instance = wp_parse_args( (array) $instance, $defaults ); 
		?>
		
        <p><em style="color:#0073aa;"><?php echo 'توجه : '; ?></em></p>
		<p><em style="color:#0085ba;"><?php echo 'این ابزارک فقط یک مرتبه باید به کار گرفته شود.'; ?></em></p>
		
		<p>
		<label for="<?php echo $this->get_field_id('catid'); ?>"><?php _e('تب اول', 'catid'); ?></label>
		<br/>
		<select id="<?php echo $this->get_field_id('catid'); ?>" name="<?php echo $this->get_field_name('catid'); ?>">
		<?php 
				foreach ($categories as $cat) :
					$selected = ( $cat->cat_ID == esc_attr($catid) ) ? ' selected = "selected" ' : '';
					$option = '<option '.$selected .'value="' . $cat->cat_ID;
					$option = $option .'">';
					$option = $option .$cat->cat_name;
					$option = $option .'</option>';
					echo $option;
				endforeach;
		?>
		</select>
		</p>

		
		<p>
		<label for="<?php echo $this->get_field_id('catid2'); ?>"><?php _e('تب دوم', 'catid2'); ?></label>
		<br/>
		<select id="<?php echo $this->get_field_id('catid2'); ?>" name="<?php echo $this->get_field_name('catid2'); ?>">
		<?php 
				foreach ($categories as $cat) :
					$selected = ( $cat->cat_ID == esc_attr($catid2) ) ? ' selected = "selected" ' : '';
					$option = '<option '.$selected .'value="' . $cat->cat_ID;
					$option = $option .'">';
					$option = $option .$cat->cat_name;
					$option = $option .'</option>';
					echo $option;
				endforeach;
		?>
		</select>
		</p>

		
		<p>
		<label for="<?php echo $this->get_field_id('catid3'); ?>"><?php _e('تب سوم', 'catid3'); ?></label>
		<br/>
		<select id="<?php echo $this->get_field_id('catid3'); ?>" name="<?php echo $this->get_field_name('catid3'); ?>">
		<?php 
				foreach ($categories as $cat) :
					$selected = ( $cat->cat_ID == esc_attr($catid3) ) ? ' selected = "selected" ' : '';
					$option = '<option '.$selected .'value="' . $cat->cat_ID;
					$option = $option .'">';
					$option = $option .$cat->cat_name;
					$option = $option .'</option>';
					echo $option;
				endforeach;
		?>
		</select>
		</p>
		
		<p>
		<label for="<?php echo $this->get_field_id('catid4'); ?>"><?php _e('تب چهارم', 'catid4'); ?></label>
		<br/>
		<select id="<?php echo $this->get_field_id('catid4'); ?>" name="<?php echo $this->get_field_name('catid4'); ?>">
		<?php 
				foreach ($categories as $cat) :
					$selected = ( $cat->cat_ID == esc_attr($catid4) ) ? ' selected = "selected" ' : '';
					$option = '<option '.$selected .'value="' . $cat->cat_ID;
					$option = $option .'">';
					$option = $option .$cat->cat_name;
					$option = $option .'</option>';
					echo $option;
				endforeach;
		?>
		</select>
		</p>

		
		
		<?php
	}
}
?>