<?php
///----Blog widgets---

/// Recent Posts 
class BUILDARK_Recent_Post extends WP_Widget
{
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'BUILDARK_Recent_Post', /* Name */esc_html__( 'BUILDARK Services','buildark' ), array( 'description' => esc_html__( 'Show the services', 'buildark' )) );
	}
 

	/** @see WP_Widget::widget */
	function widget( $args, $instance )
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post( $before_widget ); ?>
		
        <!-- Recent Posts -->
        <div class="links-widget">
            <?php echo wp_kses_post($before_title.$title.$after_title); ?>
            
			<ul class="links">
			
				<?php
				$query_string = array( 'post_type' => 'bunch_services', 'showposts' => $instance['number'] );
				if( $instance['cat'] ) $query_string .= '&services_category='.$instance['cat'];
				

				$this->posts($query_string);
				?>
           
			</ul>
            
        </div>
        
		<?php echo wp_kses_post($after_widget);
	}
 
 
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['number'] = $new_instance['number'];
		$instance['cat'] = $new_instance['cat'];
		
		return $instance;
	}

	/** @see WP_Widget::form */
	function form( $instance )
	{
		$title = ( $instance ) ? esc_attr($instance['title']) : esc_html__( 'Services', 'buildark' );
		$number = ( $instance ) ? esc_attr($instance['number']) : 6;
		$cat = ( $instance ) ? esc_attr($instance['cat']) : '';?>
			
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e('No. of Posts:', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" />
        </p>
       
    	<p>
            <label for="<?php echo esc_attr($this->get_field_id('cat')); ?>"><?php esc_html_e('Category', 'buildark'); ?></label>
            <?php wp_dropdown_categories( array( 'taxonomy' => 'services_category', 'show_option_all'=>esc_html__('All Categories', 'buildark'), 'selected'=>$cat, 'class'=>'widefat', 'name'=>$this->get_field_name('cat')) ); ?>
        </p>
            
		<?php 
	}
	
	function posts($query_string)
	{
		
		$query = new WP_Query($query_string) ;
		if( $query->have_posts() ):?>
        
           	<!-- Title -->
				<?php while( $query->have_posts() ): $query->the_post(); ?>
                	
                	<li><a href="<?php echo esc_url(get_permalink(get_the_id()));?>"><?php the_title(); ?></a></li>
                	
                <?php endwhile; ?>
            
        <?php endif;
		wp_reset_postdata();
    }
}

///----footer widgets---
//About Us
class BUILDARK_About_us extends WP_Widget
{
	
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'BUILDARK_About_us', /* Name */esc_html__('BUILDARK About Us','buildark'), array( 'description' => esc_html__( 'Show the information about company', 'buildark' )) );
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post($before_widget);?>
      		
			<!--Footer Column-->
           
           <div class="logo-widget">
				<div class="footer-logo"><figure><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url( $instance['logo_url'] ); ?>" alt="<?php esc_attr_e('image', 'buildark');?>"></a></figure></div>
				<div class="widget-content">
					<div class="text"><?php echo wp_kses_post($instance['content']); ?></div>
					<a href="<?php echo esc_url( $instance['logo_url'] ); ?>" class="theme-btn btn-style-one"><?php esc_html_e( 'Get a Free Quote', 'buildark' );  ?></a>
				</div>
			</div>

            
		<?php
		
		echo wp_kses_post($after_widget);
	}
	
	
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;

		$instance['logo_url'] = strip_tags($new_instance['logo_url']);
		$instance['content'] = $new_instance['content'];
		$instance['quote_url'] = $new_instance['quote_url'];

		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance)
	{
		$logo_url = ($instance) ? esc_attr($instance['logo_url']) : '';
		$content = ($instance) ? esc_attr($instance['content']) : '';
		$quote_url = ($instance) ? esc_attr($instance['quote_url']) : '';
?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('logo_url')); ?>"><?php esc_html_e('Footer Logo Url: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('logo_url')); ?>" name="<?php echo esc_attr($this->get_field_name('logo_url')); ?>" type="text" value="<?php echo esc_attr($logo_url); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('content')); ?>"><?php esc_html_e('Content:', 'buildark'); ?></label>
            <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('content')); ?>" name="<?php echo esc_attr($this->get_field_name('content')); ?>" ><?php echo wp_kses_post($content); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('quote_url')); ?>"><?php esc_html_e('Quote Url: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('quote_url')); ?>" name="<?php echo esc_attr($this->get_field_name('quote_url')); ?>" type="text" value="<?php echo esc_attr( $quote_url ); ?>" />
        </p>
		<?php 
	}
	
}


//Contact Us
class BUILDARK_Contact_us extends WP_Widget
{
	
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'BUILDARK_Contact_us', /* Name */esc_html__('BUILDARK Contact Us','buildark'), array( 'description' => esc_html__( 'Show the contact info of company', 'buildark' )) );
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post($before_widget);?>
      		
			<!--Footer Column-->
          
          <div class="contact-widget">
				<?php echo wp_kses_post($before_title.$title.$after_title); ?>
				<ul class="list-style-one">
					<li><span class="icon flaticon-maps-and-flags"></span><?php echo wp_kses_post( $instance['address'] ); ?></li>
					<li><span class="icon flaticon-phone-call"></span><?php echo wp_kses_post( $instance['phone'] ); ?></li>
					<li><span class="icon flaticon-clock-1"></span><?php echo wp_kses_post( $instance['timings'] ); ?></li>
				</ul>
				<a class="contact-email" href="<?php echo esc_url( $instance['contact_url'] ); ?>"><?php esc_html_e( 'Send us an email and we’ll get in touch shortly', 'buildark' ); ?></a>
			</div>

            
		<?php
		
		echo wp_kses_post($after_widget);
	}
	
	
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;

		$instance['title'] = strip_tags($new_instance['title']);
		$instance['address'] = $new_instance['address'];
		$instance['phone'] = $new_instance['phone'];
		$instance['timings'] = $new_instance['timings'];
		$instance['contact_url'] = $new_instance['contact_url'];
		

		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance)
	{
		$title = ($instance) ? esc_attr($instance['title']) : 'Contact Us';
		$address = ($instance) ? esc_attr($instance['address']) : '';
		$phone = ($instance) ? esc_attr($instance['phone']) : '';
		$timings = ($instance) ? esc_attr($instance['timings']) : '';
		$contact_url = ($instance) ? esc_attr($instance['contact_url']) : '';
?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title Url: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('address')); ?>"><?php esc_html_e('Address:', 'buildark'); ?></label>
            <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('address')); ?>" name="<?php echo esc_attr($this->get_field_name('address')); ?>" ><?php echo wp_kses_post($address); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('phone')); ?>"><?php esc_html_e('Phone:', 'buildark'); ?></label>
            <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('phone')); ?>" name="<?php echo esc_attr($this->get_field_name('phone')); ?>" ><?php echo wp_kses_post($phone); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('timings')); ?>"><?php esc_html_e('Timings:', 'buildark'); ?></label>
            <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('timings')); ?>" name="<?php echo esc_attr($this->get_field_name('timings')); ?>" ><?php echo wp_kses_post($timings); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('contact_url')); ?>"><?php esc_html_e('Contact Url: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('contact_url')); ?>" name="<?php echo esc_attr($this->get_field_name('contact_url')); ?>" type="text" value="<?php echo esc_attr( $contact_url ); ?>" />
        </p>
		<?php 
	}
	
}


class Bunch_servies extends WP_Widget
{
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'Bunch_servies', /* Name */esc_html__('BuilderHub Services Detail Sidebar','buildark'), array( 'description' => esc_html__( 'Show the Services Sidebar', 'buildark' ) ) );
	}
 
	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		
		echo wp_kses_post($before_widget); ?>
		
        <!--Services Category-->
        <div class="sidebar-widget sidebar-category">
           <aside class="sidebar default-sidebar">	
              <a class="view-all" href="<?php echo esc_url( $instance['link'] ); ?>"><?php echo wp_kses_post( $instance['title'] ); ?> <span class="icon fa fa-gear"></span></a>
              
				<?php 
					$args = array('post_type' => 'bunch_services', 'showposts'=>$instance['number']);
					if( $instance['cat'] ) $args['tax_query'] = array(array('taxonomy' => 'services_category','field' => 'id','terms' => (array)$instance['cat']));
					 
					$this->posts($args);
				?>
			</aside>
        </div>
		
        <?php echo wp_kses_post($after_widget);
	}
 
 
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['link'] = strip_tags($new_instance['link']);
		$instance['number'] = $new_instance['number'];
		$instance['cat'] = $new_instance['cat'];
		
		return $instance;
	}
	/** @see WP_Widget::form */
	function form($instance)
	{
		$title = ( $instance ) ? esc_attr($instance['title']) : 'View All Services';
		$link = ( $instance ) ? esc_attr($instance['link']) : '#';
		$number = ( $instance ) ? esc_attr($instance['number']) : 6;
		$cat = ( $instance ) ? esc_attr($instance['cat']) : '';?>
		
       	<p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('link')); ?>"><?php esc_html_e('Link: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('link')); ?>" name="<?php echo esc_attr($this->get_field_name('link')); ?>" type="text" value="<?php echo esc_attr( $link ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e('Number of posts: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('cat')); ?>"><?php esc_html_e('Category', 'buildark'); ?></label>
            <?php wp_dropdown_categories( array('show_option_all'=>esc_html__('All Categories', 'buildark'), 'selected'=>$cat, 'taxonomy' => 'services_category', 'class'=>'widefat', 'name'=>$this->get_field_name('cat')) ); ?>
        </p>
            
		<?php 
	}
	
	function posts($args)
	{
		
		$query = new WP_Query($args);
		if( $query->have_posts() ):?>
        
           	<!-- Title -->
            <ul class="list">
				<?php $count = 0; while( $query->have_posts() ): $query->the_post(); 
                    global $post;
					$services_meta = _WSH()->get_meta();
					$read_more_link = buildark_set( $services_meta, 'ext_url' );
                ?>
                <li <?php if ( 0 === $count ) : ?>class="current"<?php endif; ?>><a href="<?php echo esc_url( $read_more_link ); ?>"><?php the_title(); ?></a></li>
                <?php $count++; endwhile; ?>
            </ul>   
             
        <?php endif;
		wp_reset_postdata();
    }
}

/// Our Brochures
class Bunch_Brochures extends WP_Widget
{
	
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'Bunch_Brochures', /* Name */esc_html__( 'BuilderHub Our Brochures','buildark' ), array( 'description' => esc_html__( 'Show the info Our Brochures', 'buildark' ) ) );
	}
	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post($before_widget);?>
     		
     		<div class="sidebar-widget sidebar-brochure">
				<a class="brochure" href="<?php echo esc_url($instance['pdf']); ?>"><span class="icon flaticon-pdf"></span> <?php esc_html_e('Our Document.PDF', 'buildark'); ?></a>
				<a class="brochure" href="<?php echo esc_url($instance['word']); ?>"><span class="icon flaticon-word"></span> <?php esc_html_e('Our Document.DOC', 'buildark'); ?></a>
			</div>
            
		<?php
		
		echo wp_kses_post($after_widget);
	}
	
	
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		
		$instance['pdf'] = $new_instance['pdf'];
		$instance['word'] = $new_instance['word'];
		return $instance;
	}
	/** @see WP_Widget::form */
	function form($instance)
	{
		$pdf = ($instance) ? esc_attr($instance['pdf']) : '';
		$word = ( $instance ) ? esc_attr($instance['word']) : '';?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('pdf')); ?>"><?php esc_html_e('PDF Link Here:', 'buildark'); ?></label>
            <input placeholder="<?php esc_attr_e('#', 'buildark');?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('pdf')); ?>" name="<?php echo esc_attr($this->get_field_name('pdf')); ?>" type="text" value="<?php echo esc_attr($pdf); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('word')); ?>"><?php esc_html_e('WORD Link Here:', 'buildark'); ?></label>
            <input placeholder="<?php esc_attr_e('#', 'buildark');?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('word')); ?>" name="<?php echo esc_attr($this->get_field_name('word')); ?>" type="text" value="<?php echo esc_attr($word); ?>" />
        </p>
                
		<?php 
	}
	
}

//Contact Us
class Bunch_Get_intouch_us extends WP_Widget
{
	
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'Bunch_Get_intouch_us', /* Name */esc_html__( 'BuilderHub Get Touch With Us','buildark' ), array( 'description' => esc_html__( 'Show the Get Touch With Us', 'buildark' ) ) );
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post($before_widget);?>
     		
     		<!--Locate Widget-->
			<div class="locate-widget">
				<div class="inner-box">
					<h3><?php echo wp_kses_post($instance['title']); ?></h3>
					<div class="text"><?php echo wp_kses_post($instance['content']); ?></div>
					<a href="<?php echo esc_url( $instance['ext_title'] ); ?>" class="locate-link"><?php esc_html_e( 'Locate Us', 'buildark' ); ?> &nbsp;<span class="fa fa-angle-right"></span></a>
					<span class="large-icon"><span class="icon flaticon-message"></span></span>
				</div>
			</div>
            
		<?php
		
		echo wp_kses_post($after_widget);
	}
	
	
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;

		$instance['title'] = strip_tags($new_instance['title']);
		$instance['content'] = $new_instance['content'];
		$instance['ext_link'] = $new_instance['ext_link'];

		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance)
	{
		$title = ($instance) ? esc_attr($instance['title']) : 'Get Touch With Us';
		$content = ($instance) ? esc_attr($instance['content']) : '';
		$ext_link = ( $instance ) ? esc_attr($instance['ext_link']) : ''; ?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'buildark'); ?></label>
            <input placeholder="<?php esc_attr_e('Our team ready to help you, please contact!', 'buildark');?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('content')); ?>"><?php esc_html_e('Content:', 'buildark'); ?></label>
            <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('content')); ?>" name="<?php echo esc_attr($this->get_field_name('content')); ?>" ><?php echo wp_kses_post($content); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('ext_link')); ?>"><?php esc_html_e('External Link:', 'buildark'); ?></label>
            <input placeholder="<?php esc_attr_e('#', 'buildark');?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('ext_link')); ?>" name="<?php echo esc_attr($this->get_field_name('ext_link')); ?>" type="text" value="<?php echo esc_attr($ext_link); ?>" />
        </p>
                
                
		<?php 
	}
	
}

/// Recent Posts 
class BUILDARK_Popular_News extends WP_Widget
{
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'BUILDARK_Popular_News', /* Name */esc_html__( 'BUILDARK Poplar News','buildark' ), array( 'description' => esc_html__( 'Show the Popular News', 'buildark' )) );
	}
 

	/** @see WP_Widget::widget */
	function widget( $args, $instance )
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo wp_kses_post( $before_widget ); ?>
		
        <!-- Recent Posts -->
        <div class="sidebar-widget-two popular-posts-two">
            <?php echo wp_kses_post($before_title.$title.$after_title); ?>
            
			<?php 
			    $query_string = 'posts_per_page='.$instance['number'];
				if( $instance['cat'] ) $query_string .= '&cat='.$instance['cat'];
				query_posts( $query_string ); 
				$this->posts();
				wp_reset_postdata();
            ?>
            
        </div>
        
		<?php echo wp_kses_post($after_widget);
	}
 
 
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['number'] = $new_instance['number'];
		$instance['cat'] = $new_instance['cat'];
		
		return $instance;
	}

	/** @see WP_Widget::form */
	function form( $instance )
	{
		$title = ( $instance ) ? esc_attr($instance['title']) : esc_html__( 'Popular News', 'buildark' );
		$number = ( $instance ) ? esc_attr($instance['number']) : 3;
		$cat = ( $instance ) ? esc_attr($instance['cat']) : '';?>
			
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title: ', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e('No. of Posts:', 'buildark'); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" />
        </p>
       
    	<p>
            <label for="<?php echo esc_attr($this->get_field_id('cat')); ?>"><?php esc_html_e('Category', 'buildark'); ?></label>
            <?php wp_dropdown_categories( array( 'taxonomy' => 'category', 'show_option_all'=>esc_html__('All Categories', 'buildark'), 'selected'=>$cat, 'class'=>'widefat', 'name'=>$this->get_field_name('cat')) ); ?>
        </p>
            
		<?php 
	}
	
	function posts($query_string)
	{
		
		$query = new WP_Query($query_string);
		if( $query->have_posts() ):?>
        
           	<!-- Title -->
			<?php while( $query->have_posts() ): $query->the_post(); ?>
            
                <article class="post">
                    <figure class="post-thumb">
                    	<a href="<?php echo esc_url(get_permalink(get_the_id()));?>">
							<?php the_post_thumbnail( 'buildark_75x75', array( 'class' => 'img-responsive' ) );  ?>
                        </a>
                    </figure>
                    <div class="text"><a href="<?php echo esc_url(get_permalink(get_the_id()));?>"><?php the_title(); ?></a></div>
                    <div class="post-info"><?php echo get_the_date(  ); ?></div>
                </article>

                	
            <?php endwhile; ?>
            
        <?php endif;
		wp_reset_postdata();
    }
}