<?php

//Contact Info
class SH_Contact_Info extends WP_Widget
{
	
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'SH_Contact_Info', /* Name */esc_html__('WowThemes Contact Info',SH_NAME), array( 'description' => esc_html__('Show contact info ', SH_NAME )) );
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		//$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo 	$before_widget;?>
      
            <div class="row">

						<?php if( $address = $instance['address']): ?>
						
							<div class="col-md-4">
								<div class="info-box">
									<span class="icon">
										<i class="fa fa-map-marker"></i>
									</span>
									<?php echo balanceTags($address); ?>
									
								</div>
							</div> <!-- / .col-md-4 -->
						
						<?php endif; ?>

						<?php if( $address = $instance['phone']): ?>

							<div class="col-md-4">
								<div class="info-box">
									<span class="icon">
										<i class="fa fa-phone"></i>
									</span>
									<?php echo balanceTags($address); ?>
									
								</div>
							</div> <!-- / .col-md-4 -->
						<?php endif; ?>
						

						<?php if( $address = $instance['timing']): ?>

							<div class="col-md-4">
								<div class="info-box">
									<span class="icon">
										<i class="fa fa-clock-o"></i>
									</span>
									<?php echo balanceTags($address); ?>
									
								</div>
							</div> <!-- / .col-md-4 -->
						
						<?php endif; ?>
					</div> <!-- / .row -->
		<?php
		
		echo 	$after_widget;
	}
	
	
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;

		$instance['address'] = $new_instance['address'];
		$instance['phone'] = $new_instance['phone'];
		$instance['timing'] = $new_instance['timing'];

		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance)
	{
		$address = ($instance) ? esc_attr($instance['address']) : 'Plaza on the River Club and Residence, London, Albert Embankment, London, United Kingdom';
		$phone = ($instance) ? esc_attr($instance['phone']) : '';
		$timing = ($instance) ? esc_attr($instance['timing']) : '';
		?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('address')); ?>"><?php esc_html_e('Address:', SH_NAME); ?></label>
            <textarea placeholder="Address" class="widefat" id="<?php echo esc_attr($this->get_field_id('address')); ?>" name="<?php echo esc_attr($this->get_field_name('address')); ?>"><?php echo balanceTags($address); ?></textarea>
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('phone')); ?>"><?php esc_html_e('Phone and Email:', SH_NAME); ?></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 esc_attr($phone); ?></textarea>
        </p>
         
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('timing')); ?>"><?php esc_html_e('Office Timings:', SH_NAME); ?></label>
            <textarea placeholder="Office Timings" class="widefat" id="<?php echo esc_attr($this->get_field_id('timing')); ?>" name="<?php echo esc_attr($this->get_field_name('timing')); ?>"><?php echo balanceTags($timing); ?></textarea>
        </p>     
		<?php 
	}
	
}

// twitter
class SH_Contact_Form extends WP_Widget
{
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'SH_Contact_Form', /* Name */esc_html__('WowThemes Contact Form',SH_NAME), array( 'description' => esc_html__('Show the contact form in widgetize sidebar', SH_NAME )) );
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo 	$before_widget;?>
        
		<?php if( $form_id = $instance['form_id'] )
		echo do_shortcode('[sh_form id='.$form_id.']'); ?>

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

		$instance['email'] = strip_tags($new_instance['email']);
		$instance['form_id'] = $new_instance['form_id'];
		//$instance['number'] = $new_instance['number'];

		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance)
	{
		$email = ($instance) ? esc_attr($instance['email']) : get_bloginfo('admin_email');
		$form_id = ($instance) ? esc_attr($instance['form_id']) : 1;
		//$number = ( $instance ) ? esc_attr($instance['number']) : '';?>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('email')); ?>"><?php esc_html_e('Reciever Email:', SH_NAME); ?></label>
            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('email')); ?>" name="<?php echo esc_attr($this->get_field_name('email')); ?>" type="text" value="<?php echo esc_attr($email); ?>" />
        </p>
        <p>
        	<?php $forms = sh_get_posts_array('sh_form' ); //printr($forms);?>
            <label for="<?php echo esc_attr($this->get_field_id('form_id')); ?>"><?php esc_html_e('Choose Form:', SH_NAME); ?></label>
            <select id="<?php echo esc_attr($this->get_field_id('form_id')); ?>" name="<?php echo esc_attr($this->get_field_name('form_id')); ?>" class="widefat">
            	<?php foreach($forms as $k => $fom): ?>
					<option value="<?php echo esc_attr($k); ?>" <?php selected($k, $form_id); ?>><?php echo balanceTags($fom); ?></option>
            	<?php endforeach; ?>	
            </select>
            
        </p>
                
		<?php 
	}
}

/// recent posts
class SH_Recent_Post_img extends WP_Widget
{
	/** constructor */
	function __construct()
	{
		parent::__construct( /* Base ID */'SH_Recent_Post_img', /* Name */esc_html__('DW Recent Posts with Images',SH_NAME), array( 'description' => esc_html__('Show the recent posts with images', SH_NAME )) );
	}
 

	/** @see WP_Widget::widget */
	function widget($args, $instance)
	{
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		
		echo 	$before_widget;
		
		echo balanceTags($before_title.$title.$after_title); 
		
		$query_string = 'posts_per_page='.$instance['number'];
		if( $instance['cat'] ) $query_string .= '&cat='.$instance['cat'];
		query_posts( $query_string ); 
	
		$this->posts();
		wp_reset_query(); 
		
		echo 	$after_widget;
	}
 
 
	/** @see WP_Widget::update */
	function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		
		$instance['title'] = $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__('Recent Posts', SH_NAME);
		$number = ( $instance ) ? esc_attr($instance['number']) : 4;
		$cat = ( $instance ) ? esc_attr($instance['cat']) : '';?>
			
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title: ', SH_NAME); ?></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:', SH_NAME); ?></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', SH_NAME); ?></label>
            <?php wp_dropdown_categories( array('show_option_all'=>esc_html__('All Categories', SH_NAME), 'selected'=>$cat, 'class'=>'widefat', 'name'=>$this->get_field_name('cat')) ); ?>
        </p>
        
		<?php 
	}
	
	function posts()
	{
		
		if( have_posts() ):?>
        
            <?php while( have_posts() ): the_post(); ?>
              
			        <div class="mini-post">
                        <div class="mini-post-cover">
                        	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('263x219'); ?></a>
                        </div>
                        <h4><a href="<?php the_permalink(); ?>" class="d-text-c-h"><?php the_title(); ?></a></h4>
                        <p><?php echo get_the_date(); ?></p>
					</div>
            
			    <?php endwhile; ?>
                
            
            
		<?php endif;
    }
}






