<?php
	/*
* Khởi tạo widget item
*/

add_action( 'widgets_init', 'create_LT2Theme_widget' );
function create_LT2Theme_widget() {
	register_widget('Service_Widget');
	register_widget('Counter_Widget');
	register_widget('CompanyPartner_Widget');
	register_widget('Testimonials_Widget');
	register_widget('Contact_Widget');
	register_widget('Certificate_Widget');
	// register_widget('FooterMenu_Widget');
}
/**
* Tạo class Service_Widget
*/
class Service_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/

	function __construct() {
		parent::__construct (
			'services_widget', // id của widget
			'ThaThuCo Dịch Vụ', // tên của widget
			array(
				'description' => 'Hiển thị danh sách dịch vụ nổi bật trên trang chủ.' // mô tả
			)
		);
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'category' => '',
			'order' => 'latest'
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$category = esc_attr( $instance['category'] );
		$number_posts = esc_attr( $instance['number_posts'] );
		$order = esc_attr( $instance['order'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';?>
		<p>
			<label for="">Chọn chuyên mục:</label><br>
		<?php
		wp_dropdown_categories( array( 'show_option_all' =>'Tất cả','name' => $this->get_field_name( 'category' ), 'selected' => $category, 'hide_empty' => 0 ) );
		echo '</p><p>Số cột hiển thị<br/>';
		?>
		</p>
		<p>
			<label for="">Sắp xếp:</label>
			<select name="<?php echo $this->get_field_name('order') ?>" >
				<option value="latest" <?php echo selected($order, "latest") ?>>Mới nhất</option>
				<option value="updated" <?php echo selected($order, "updated") ?>>Sửa mới nhất</option>
			</select>
		</p>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = $new_instance['category'];
		$instance['order'] = $new_instance['order'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		global $ththeme_option;
		$title = apply_filters( 'widget_title', $instance['title'] );
		$category = $instance['category'];
		$order = $instance['order'];
		if($order ==  'updated') {
			$services = new WP_Query( array('post_type' => 'post', 'cat' => $category, 'posts_per_page' => 3, 'orderby' => 'modified', 'order' => 'DESC'  ) ); 
		} else {
			$services = new WP_Query( array('post_type' => 'post', 'cat' => $category, 'posts_per_page' => 3, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
		}
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="margin: 0px 0px 0px 0px;padding: 115px 0px 120px 0px;" id="gdlr-core-wrapper-3">';
		if($ththeme_option['home-service-background']['url'])
		echo '<div class="gdlr-core-pbf-background-wrap">
                        <div class="gdlr-core-pbf-background gdlr-core-parallax gdlr-core-js" style="background-image: url('.$ththeme_option['home-service-background']['url'].') ;background-size: cover ;background-position: center ;" data-parallax-speed="0.2"></div>
                    </div>';
		if($title){
			echo "<div class='section__title'>";
			echo $before_title.$title.$after_title;
			echo '</div>';
		} ?>
		<?php $n = 0; ?>
		<?php if($services->have_posts()): ?>
		<div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
            <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-container">
				<?php
				while ( $services->have_posts() ) : $services->the_post();
					$n++;
					if($n == 1){
						$first = 'gdlr-core-column-first';
					} else $first = '';
				?>
				<div class="gdlr-core-pbf-column gdlr-core-column-20 <?php echo $first; ?>" data-skin="Homepage Column Service">
					<div class="gdlr-core-pbf-column-content-margin gdlr-core-js " style="padding: 0px 10px 0px 10px;">
						<div class="gdlr-core-pbf-column-content clearfix gdlr-core-js " data-gdlr-animation="fadeInUp" data-gdlr-animation-duration="600ms" data-gdlr-animation-offset="0.8">
							<div class="gdlr-core-pbf-element">
								<div class="gdlr-core-column-service-item gdlr-core-item-pdb  gdlr-core-center-align gdlr-core-no-caption gdlr-core-item-pdlr" style="padding-bottom: 30px;">
									<div class="gdlr-core-column-service-media gdlr-core-media-image" style=";margin-left: auto ;margin-right: auto ;"><?php the_post_thumbnail(array( 600, 400, 'bfi_thumb' => true )); ?></div>
									<div class="gdlr-core-column-service-content-wrapper">
										<div class="gdlr-core-column-service-title-wrap">
										<h3 class="gdlr-core-column-service-title gdlr-core-skin-title" style="font-size: 23px ;font-weight: 700 ;text-transform: none ;"><?php the_title(); ?></h3></div>
										<div class="gdlr-core-column-service-content" style="font-size: 16px ;text-transform: none ;">
											<p><?php echo wp_trim_words(get_the_excerpt(), 26, '...'); ?></p> <a class="gdlr-core-column-service-read-more gdlr-core-info-font" href="<?php the_permalink(); ?>" target="_self" style="font-style: normal ;">Xem thêm<i class="fa fa-long-arrow-right"></i></a>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php
				endwhile;
				?>
            </div>
        </div>
		<?php endif; ?>
		</div>
    <?php
		echo $after_widget;
	}

}

class Counter_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		parent::__construct (
			'counter_widget', // id của widget
			'ThaThuCo Counter', // tên của widget
			array(
				'description' => 'Hiển thị thống kê các dự án, đối tác, khách hàng, kinh nghiệm...' // mô tả
			)
		);
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => ''
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';?>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		global $ththeme_option;
		$title = apply_filters( 'widget_title', $instance['title'] );
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="padding: 0px 0px 0px 0px;">
            	<div class="gdlr-core-pbf-background-wrap" style="background-color: #0a0a0a ;"></div>
                    <div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                        <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-pbf-wrapper-full-no-space">
                            <div class="gdlr-core-pbf-element">
                                <div class="gdlr-core-tab-feature-item gdlr-core-js gdlr-core-item-pdb  gdlr-core-item-pdlr" style="padding-bottom: 0px ;" id="gdlr-core-tab-feature-1">';
		if($title){
			echo "<div class='section__title'>";
			echo $before_title.$title.$after_title;
			echo '</div>';
		} ?>
		<?php if($ththeme_option['counter-col1-title']): ?>
		<div class="gdlr-core-tab-feature-title-item-wrap clearfix">
			<div class="gdlr-core-tab-feature-title-wrap gdlr-core-tab-feature-size-4 gdlr-core-active gdlr-core-js" data-tab-id="1" data-sync-height="gdlr-core-tab-feature-1-title">
				<div class="gdlr-core-tab-feature-title-background  gdlr-core-with-active" style="background-image: url(<?php echo $ththeme_option['counter-col1-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-active" style="background-image: url(<?php echo $ththeme_option['counter-col1-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay-active"></div>
				<?php if($ththeme_option['counter-col1-image']['url']): ?>
				<div class="gdlr-core-tab-feature-title-image" style="max-width: 56px ;margin-left: auto ;margin-right: auto ;"><img src="<?php echo $ththeme_option['counter-col1-image']['url'] ?>" alt="" width="110" height="108" title="tab-1-icon-n"></div>
				<?php endif; ?>
				<h3 class="gdlr-core-tab-feature-title"><?php echo $ththeme_option['counter-col1-title']; ?></h3>
				<div class="gdlr-core-tab-feature-caption"><?php echo $ththeme_option['counter-col1-number'] ?></div>
			</div>
			<?php if($ththeme_option['counter-col2-title']): ?>
			<div class="gdlr-core-tab-feature-title-wrap gdlr-core-tab-feature-size-4  gdlr-core-js" data-tab-id="1" data-sync-height="gdlr-core-tab-feature-1-title">
				<div class="gdlr-core-tab-feature-title-background  gdlr-core-with-active" style="background-image: url(<?php echo $ththeme_option['counter-col2-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-active" style="background-image: url(<?php echo $ththeme_option['counter-col2-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay-active"></div>
				<?php if($ththeme_option['counter-col2-image']['url']): ?>
				<div class="gdlr-core-tab-feature-title-image" style="max-width: 56px ;margin-left: auto ;margin-right: auto ;"><img src="<?php echo $ththeme_option['counter-col2-image']['url'] ?>" alt="" width="110" height="108" title="tab-1-icon-n"></div>
				<?php endif; ?>
				<h3 class="gdlr-core-tab-feature-title"><?php echo $ththeme_option['counter-col2-title']; ?></h3>
				<div class="gdlr-core-tab-feature-caption"><?php echo $ththeme_option['counter-col2-number'] ?></div>
			</div>
			<?php endif; ?>
			<?php if($ththeme_option['counter-col3-title']): ?>
			<div class="gdlr-core-tab-feature-title-wrap gdlr-core-tab-feature-size-4  gdlr-core-js" data-tab-id="1" data-sync-height="gdlr-core-tab-feature-1-title">
				<div class="gdlr-core-tab-feature-title-background  gdlr-core-with-active" style="background-image: url(<?php echo $ththeme_option['counter-col3-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-active" style="background-image: url(<?php echo $ththeme_option['counter-col3-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay-active"></div>
				<?php if($ththeme_option['counter-col3-image']['url']): ?>
				<div class="gdlr-core-tab-feature-title-image" style="max-width: 56px ;margin-left: auto ;margin-right: auto ;"><img src="<?php echo $ththeme_option['counter-col3-image']['url'] ?>" alt="" width="110" height="108" title="tab-1-icon-n"></div>
				<?php endif; ?>
				<h3 class="gdlr-core-tab-feature-title"><?php echo $ththeme_option['counter-col3-title']; ?></h3>
				<div class="gdlr-core-tab-feature-caption"><?php echo $ththeme_option['counter-col3-number'] ?></div>
			</div>
			<?php endif; ?>
			<?php if($ththeme_option['counter-col4-title']): ?>
			<div class="gdlr-core-tab-feature-title-wrap gdlr-core-tab-feature-size-4  gdlr-core-js" data-tab-id="1" data-sync-height="gdlr-core-tab-feature-1-title">
				<div class="gdlr-core-tab-feature-title-background  gdlr-core-with-active" style="background-image: url(<?php echo $ththeme_option['counter-col4-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-active" style="background-image: url(<?php echo $ththeme_option['counter-col2-bg']['url'] ?>) ;"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay"></div>
				<div class="gdlr-core-tab-feature-title-background-overlay-active"></div>
				<?php if($ththeme_option['counter-col4-image']['url']): ?>
				<div class="gdlr-core-tab-feature-title-image" style="max-width: 56px ;margin-left: auto ;margin-right: auto ;"><img src="<?php echo $ththeme_option['counter-col4-image']['url'] ?>" alt="" width="110" height="108" title="tab-1-icon-n"></div>
				<?php endif; ?>
				<h3 class="gdlr-core-tab-feature-title"><?php echo $ththeme_option['counter-col4-title']; ?></h3>
				<div class="gdlr-core-tab-feature-caption"><?php echo $ththeme_option['counter-col4-number'] ?></div>
			</div>
			<?php endif; ?>
		</div>
		<?php endif; ?>
    <?php
    	echo "</div></div></div></div></div>";
		echo $after_widget;
	}

}

class Testimonials_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		add_action('admin_enqueue_scripts', array($this, 'scripts'));
		parent::__construct (
			'testimonials_widget', // id của widget
			'ThaThuCo Khách Hàng', // tên của widget
			array(
				'description' => 'Hiển thị danh sách trượt các cảm nhận của khách hàng nói về Thanh Huyền.' // mô tả
			)
		);
	}

	public function scripts()
	{
	   wp_enqueue_script( 'media-upload' );
	   wp_enqueue_media();
	   wp_enqueue_script('adminJS', get_template_directory_uri() . '/js/admin.js', array('jquery'));
	}

	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'bg_image' => '',
			'description' => '',
			'number_posts' => 4,
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$bg_image = esc_attr( $instance['bg_image'] );
		$description = esc_attr( $instance['description'] );
		$number_posts = esc_attr( $instance['number_posts'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';?>
		<p>
			<label for="">Mô tả:</label>
			<textarea class="widefat" name="<?php echo $this->get_field_name('description') ?>" rows="3"><?php echo $description; ?></textarea>
		</p>
		<p>
	      	<label for="<?php echo $this->get_field_id( 'bg_image' ); ?>"><?php _e( 'Ảnh Background:' ); ?></label>
	      	<input class="widefat" id="<?php echo $this->get_field_id( 'bg_image' ); ?>" name="<?php echo $this->get_field_name( 'bg_image' ); ?>" type="text" value="<?php echo esc_url( $bg_image ); ?>" /><br>
	      	<button class="upload_image_button button button-primary">Upload Image</button>
	   	</p>
		<?php
		echo '<p>Chọn số cảm nhận sẽ hiển thị<br/>';
		echo '<select name="'.$this->get_field_name('number_posts').'">';
		echo '<option value="">Tất Cả</option>';
		for ($i=2; $i < 9; $i++) {
			echo '<option value="'.$i.'" '.selected($number_posts,$i).' >'.$i.'</option>';
		}
		echo '</select>';
		?>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['bg_image'] = $new_instance['bg_image'];
		$instance['description'] = $new_instance['description'];
		$instance['number_posts'] = $new_instance['number_posts'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$bg_image = $instance['bg_image'];
		$description = $instance['description'];
		$number_posts = $instance['number_posts'] ? $instance['number_posts'] : 4;
		$testimonials = new WP_Query( array('post_type' => 'ththeme_testimonials', 'posts_per_page' => $number_posts, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="padding: 110px 0px 60px 0px;" id="gdlr-core-wrapper-10">';
		if($bg_image)
			echo '<div class="gdlr-core-pbf-background-wrap">
                        <div class="gdlr-core-pbf-background gdlr-core-parallax gdlr-core-js" style="background-image: url('.$bg_image.') ;background-size: cover ;background-position: center ;" data-parallax-speed="0.2"></div>
                    </div>';
        echo '<div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-container">';
		if($title){
			if($description){
				$class = 'description';
			} else $class = '';
			echo "<div class='section__title $class'>";
			echo $before_title.$title.$after_title;
			echo '<span class="underline"></span></div>';
		}
		if($description){
			echo '<div class="gdlr-core-pbf-element description">
                    <div class="gdlr-core-text-box-item gdlr-core-item-pdlr gdlr-core-item-pdb gdlr-core-center-align" style="padding-bottom: 45px ;">
                        <div class="gdlr-core-text-box-item-content" style="font-size: 17px ;text-transform: none ;color: #c3d9ff ;">
                            <p>'.$description.'</p>
                        </div>
                    </div>
                </div>';
		}
		?>
		<?php if($testimonials->have_posts()): ?>
		<div class="gdlr-core-pbf-element">
            <div class="gdlr-core-testimonial-item gdlr-core-item-pdb clearfix  gdlr-core-testimonial-style-left gdlr-core-item-pdlr">
                <div class="gdlr-core-flexslider flexslider gdlr-core-js-2  gdlr-core-bullet-style-cylinder" data-type="carousel" data-column="2" data-move="1" data-nav="bullet" data-nav-parent="gdlr-core-testimonial-item" data-disable-autoslide="1">
                    <ul class="slides">
				<?php
				while ( $testimonials->have_posts() ) : $testimonials->the_post();
				?>
					<li class="gdlr-core-item-mglr">
                        <div class="gdlr-core-testimonial clearfix">
                            <div class="gdlr-core-testimonial-frame clearfix gdlr-core-skin-e-background">
                                <div class="gdlr-core-testimonial-quote gdlr-core-quote-font" style="color: #e53d34 ;">&#8220;</div>
                                <div class="gdlr-core-testimonial-content-wrap">
                                    <div class="gdlr-core-testimonial-content gdlr-core-info-font gdlr-core-skin-content" style="font-size: 18px ;">
                                        <p><?php echo get_the_excerpt(); ?></p>
                                    </div>
                                    <div class="gdlr-core-testimonial-author-wrap clearfix">
                                        <div class="gdlr-core-testimonial-author-image gdlr-core-media-image"><?php the_post_thumbnail(array( 150, 150, 'bfi_thumb' => true )); ?></div>
                                        <div class="gdlr-core-testimonial-author-content">
                                            <div class="gdlr-core-testimonial-title gdlr-core-title-font gdlr-core-skin-title" style="color: #143369 ;font-size: 18px ;"><?php the_title(); ?></div>
                                            <div class="gdlr-core-testimonial-position gdlr-core-info-font gdlr-core-skin-caption" style="color: #143369 ;font-size: 16px ;"><?php echo get_post_meta(get_the_ID(), 'job_position', true); ?></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </li>
				<?php
				endwhile;
				?>
					</ul>
              	</div>
            </div>
        </div>
		<?php endif; ?>
	</div></div></div>
    <?php
		echo $after_widget;
	}

}

class CompanyPartner_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		add_action('admin_enqueue_scripts', array($this, 'scripts'));
		parent::__construct (
			'ththeme_partner_widget', // id của widget
			'ThaThuCo Đối Tác', // tên của widget
			array(
				'description' => 'Hiển thị logo đối tác trên trang chủ.' // mô tả
			)
		);
	}

	public function scripts()
	{
	   wp_enqueue_script( 'media-upload' );
	   wp_enqueue_media();
	   wp_enqueue_script('adminJS', get_template_directory_uri() . '/js/admin.js', array('jquery'));
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'number_posts' => 5,
			'bg_image' => ''
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$bg_image = ! empty( $instance['bg_image'] ) ? $instance['bg_image'] : '';
		$number_posts = esc_attr( $instance['number_posts'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';
		?>
		<p>
	      	<label for="<?php echo $this->get_field_id( 'bg_image' ); ?>"><?php _e( 'Ảnh Background:' ); ?></label>
	      	<input class="widefat" id="<?php echo $this->get_field_id( 'bg_image' ); ?>" name="<?php echo $this->get_field_name( 'bg_image' ); ?>" type="text" value="<?php echo esc_url( $bg_image ); ?>" /><br>
	      	<button class="upload_image_button button button-primary">Upload Image</button>
	   	</p>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['bg_image'] = ( ! empty( $new_instance['bg_image'] ) ) ? $new_instance['bg_image'] : '';
		$instance['number_posts'] = $new_instance['number_posts'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$bg_image = ! empty( $instance['bg_image'] ) ? $instance['bg_image'] : '';
		$number_posts = $instance['number_posts'] ? $instance['number_posts'] : 100;
		$parners = new WP_Query( array('post_type' => 'ththeme_partner', 'posts_per_page' => $number_posts, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="padding: 100px 0px 90px 0px;" id="gdlr-core-wrapper-8">';
		if($bg_image)
			echo '<div class="gdlr-core-pbf-background-wrap">
                        <div class="gdlr-core-pbf-background gdlr-core-parallax gdlr-core-js" style="background-image: url('.$bg_image.') ;background-size: cover ;background-position: center ;" data-parallax-speed="0.1"></div>
                    </div>';
        if($title){
			echo "<div class='section__title'>";
			echo $before_title.$title.$after_title;
			echo '<span class="underline"></span></div>';
		}

        if($parners->have_posts()): ?>
        	<div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-container-custom" style="max-width: 1380px ;">
                    <div class="gdlr-core-pbf-element">
                        <div class="gdlr-core-gallery-item gdlr-core-item-pdb clearfix  gdlr-core-gallery-item-style-grid">
                            <div class="gdlr-core-gallery-item-holder gdlr-core-js-2 clearfix" data-layout="fitrows">
		<?php
			$n = 0;
			while ( $parners->have_posts() ) : $parners->the_post();
				$n++;
				if($n == 1){
					$first = 'gdlr-core-column-first';
				} else $first = '';
				?>
				<div class="gdlr-core-item-list gdlr-core-gallery-column  gdlr-core-column-12  <?php echo $first; ?> gdlr-core-item-pdlr gdlr-core-item-mgb">
                    <div class="gdlr-core-gallery-list gdlr-core-media-image"><img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"></div>
                </div>
            <?php endwhile;
			?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php
		endif;
		echo $after_widget;
	}

}

class Certificate_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		parent::__construct (
			'ththeme_certificate_widget', // id của widget
			'ThaThuCo Giải Thưởng', // tên của widget
			array(
				'description' => 'Hiển thị danh sách ảnh các giải thường, bằng khen trên trang chủ.' // mô tả
			)
		);
	}

	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'number_posts' => 8,
			'background_color' => '#FFFFFF',
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$background_color = ! empty( $instance['background_color'] ) ? $instance['background_color'] : '#FFFFFF';
		$number_posts = esc_attr( $instance['number_posts'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';
		?>
		<p>
			<label for="">Màu nền khối:</label>
			<input type="color" name="<?php echo $this->get_field_name('background_color') ?>" value="<?php echo $background_color; ?>" />
		</p>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['background_color'] = $new_instance['background_color'];
		$instance['number_posts'] = $new_instance['number_posts'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$background_color = ! empty( $instance['background_color'] ) ? $instance['background_color'] : '#FFFFFF';
		$number_posts = $instance['number_posts'] ? $instance['number_posts'] : 100;
		$certificates = new WP_Query( array('post_type' => 'ththeme_certificate', 'posts_per_page' => $number_posts, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="padding: 60px 20px 60px 20px;" id="gdlr-core-wrapper-8">';
		if($background_color)
			echo '<div class="gdlr-core-pbf-background-wrap">
                        <div class="gdlr-core-pbf-background gdlr-core-parallax gdlr-core-js" style="background-color:'.$background_color.';"></div>
                    </div>';
        if($title){
			echo "<div class='section__title'>";
			echo $before_title.$title.$after_title;
			echo '<span class="underline"></span></div>';
		}

        if($certificates->have_posts()): ?>
        	<div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-container-custom" style="max-width: 1380px ;">
                    <div class="gdlr-core-pbf-element">
                        <div class="gdlr-core-gallery-item gdlr-core-item-pdb clearfix  gdlr-core-gallery-item-style-grid">
                            <div class="gdlr-core-gallery-item-holder gdlr-core-js-2 clearfix" data-layout="fitrows">
		<?php
			$n = 0;
			while ( $certificates->have_posts() ) : $certificates->the_post();
				$n++;
				if($n == 1){
					$first = 'gdlr-core-column-first';
				} else $first = '';
				?>
				<div class="gdlr-core-item-list gdlr-core-gallery-column  gdlr-core-column-15  <?php echo $first; ?> gdlr-core-item-pdlr gdlr-core-item-mgb">
                    <div class="gdlr-core-gallery-list gdlr-core-media-image">
                    	<a class="gdlr-core-lightgallery gdlr-core-js " href="<?php the_post_thumbnail_url(); ?>" data-lightbox-group="gdlr-core-img-group-1"><img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"><span class="gdlr-core-image-overlay "><i class="gdlr-core-image-overlay-icon gdlr-core-size-22 fa fa-search"></i></span></a>
                    </div>
                </div>
            <?php endwhile;
			?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php
		endif;
		echo $after_widget;
	}

}

class Contact_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		parent::__construct (
			'ththeme_contact_widget', // id của widget
			'ThaThuCo Contact', // tên của widget
			array(
				'description' => 'Hiển thị bản đồ công ty và các thông tiên liên hệ khác trên trang chủ.' // mô tả
			)
		);
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'embed_map' => '',
			'contact_info' => '',
			'contact_form' => ''
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$embed_map = esc_attr( $instance['embed_map'] );
		$contact_info = esc_attr( $instance['contact_info'] );
		$contact_form = esc_attr( $instance['contact_form'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';
		echo '<p><label for="">Google map:</label> <textarea class="widefat" name="'.$this->get_field_name('embed_map').'" rows="6">'.$embed_map.'</textarea></p>';
		echo '<p><label for="">Contact info:</label> <textarea class="widefat" name="'.$this->get_field_name('contact_info').'" rows="6">'.$contact_info.'</textarea></p>';
		// echo '<p><label for="">Contact form:</label> <input class="widefat" type="text" name="'.$this->get_field_name('contact_form').'" value="'.$contact_form.'" /></p>';
		?>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['embed_map'] = $new_instance['embed_map'];
		$instance['contact_info'] = $new_instance['contact_info'];
		$instance['contact_form'] = $new_instance['contact_form'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$embed_map = $instance['embed_map'];
		$contact_info = $instance['contact_info'];
		$contact_form = $instance['contact_form'];
		echo $before_widget;
		echo '<div class="gdlr-core-pbf-wrapper " style="padding: 0px 0px 0px 0px;">
				<div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                    <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-container">';
        echo '<div class="gdlr-core-pbf-column gdlr-core-column-30 gdlr-core-column-first">
                <div class="gdlr-core-pbf-column-content-margin gdlr-core-js ">
                    <div class="gdlr-core-pbf-column-content clearfix gdlr-core-js ">'.$embed_map.'</div>
                </div>
            </div>';
        echo '<div class="gdlr-core-pbf-column gdlr-core-column-30" data-skin="Re Button 2" id="gdlr-core-column-4">
                <div class="gdlr-core-pbf-column-content-margin gdlr-core-js  gdlr-core-column-extend-right" style="margin: -40px 0px 0px 0px;padding: 90px 25px 65px 60px;">
                    <div class="gdlr-core-pbf-background-wrap" style="background-color: #181e2a ;border-radius: 3px 0px 0px 0px;-moz-border-radius: 3px 0px 0px 0px;-webkit-border-radius: 3px 0px 0px 0px;"></div>
                    <div class="gdlr-core-pbf-column-content clearfix gdlr-core-js " data-gdlr-animation="fadeInRight" data-gdlr-animation-duration="600ms" data-gdlr-animation-offset="0.8">';
		if($title){
			echo '<div class="gdlr-core-pbf-element">
                    <div class="gdlr-core-title-item gdlr-core-item-pdb clearfix  gdlr-core-left-align gdlr-core-title-item-caption-top gdlr-core-item-pdlr" style="padding-bottom: 25px ;">
                        <div class="gdlr-core-title-item-left-image gdlr-core-media-image" style="margin: -2px 25px 0px 0px;"><img src="'.get_site_url().'/wp-content/themes/THtheme/images/unnamed.png" alt="contact" style="width:30px;" title="icon-box"></div>
                        <div class="gdlr-core-title-item-left-image-wrap">
                            <div class="gdlr-core-title-item-title-wrap ">
                                <h3 class="gdlr-core-title-item-title gdlr-core-skin-title " style="font-size: 22px ;font-weight: 700 ;letter-spacing: 0px ;text-transform: none ;color: #ffffff ;">'.$title.'<span class="gdlr-core-title-item-title-divider gdlr-core-skin-divider"></span></h3></div>
                        </div>
                    </div>
                </div>';
        }
        echo '<div class="gdlr-core-pbf-element">
                <div class="gdlr-core-text-box-item gdlr-core-item-pdlr gdlr-core-item-pdb gdlr-core-left-align" style="padding-bottom: 10px ;">
                    <div class="gdlr-core-text-box-item-content" style="font-size: 19px ;text-transform: none ;color: #c7d8ff ;">'.
                        $contact_info
                    .'</div>
                </div>
            </div>';
        ?>		
        					</div>
				        </div>
				    </div>
				</div>
			</div>
		</div>
    <?php
		echo $after_widget;
	}

}

class RecentNews_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		parent::__construct (
			'dwn_news_widget', // id của widget
			'DWN Tin Tức', // tên của widget
			array(
				'description' => 'Hiển thị danh sách tin tức từ các chuyên mục theo lựa chọn.' // mô tả
			)
		);
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'title_color' => '',
			'background_color' => '#FFFFFF',
			'description' => '',
			'category' => '',
			'columns' => 3,
			'number_posts' => 3,
			'order' => 'latest'
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$title_color = esc_attr( $instance['title_color'] );
		$background_color = esc_attr( $instance['background_color'] );
		$description = esc_attr( $instance['description'] );
		$category = esc_attr( $instance['category'] );
		$columns = esc_attr( $instance['columns'] );
		$number_posts = esc_attr( $instance['number_posts'] );
		$order = esc_attr( $instance['order'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';?>
		<p>
			<label for="">Tiêu đề màu trắng:</label>
			<input class="widefat" type="checkbox" name="<?php echo $this->get_field_name('title_color') ?>" <?php checked($title_color, 'on' ) ?> />
		</p>
		<p>
			<label for="">Màu nền khối:</label>
			<input type="color" name="<?php echo $this->get_field_name('background_color') ?>" value="<?php echo $background_color; ?>" />
		</p>
		<p>
			<label for="">Mô tả:</label>
			<textarea class="widefat" name="<?php echo $this->get_field_name('description') ?>" rows="3"><?php echo $description; ?></textarea>
		</p>
		<p>
			<label for="">Chọn chuyên mục:</label><br>
		<?php
		wp_dropdown_categories( array( 'show_option_all' =>'Tất cả','name' => $this->get_field_name( 'category' ), 'selected' => $category, 'hide_empty' => 0 ) );
		echo '</p><p>Số cột hiển thị<br/>';
		echo '<select name="'.$this->get_field_name('columns').'">';
		for ($i=2; $i < 5; $i++) {
			echo '<option value="'.$i.'" '.selected($columns,$i).' >'.$i.'</option>';
		}
		echo '</select>';
		?>
		<?php
		echo '<p>Chọn số tin sẽ hiển thị<br/>';
		echo '<select name="'.$this->get_field_name('number_posts').'">';
		echo '<option value="">Tất Cả</option>';
		for ($i=2; $i < 9; $i++) {
			echo '<option value="'.$i.'" '.selected($number_posts,$i).' >'.$i.'</option>';
		}
		echo '</select>';?>
		<p>
			<label for="">Sắp xếp:</label>
			<select name="<?php echo $this->get_field_name('order') ?>" >
				<option value="latest" <?php echo selected($order, "latest") ?>>Mới nhất</option>
				<option value="viewest" <?php echo selected($order, "viewest") ?>>Xem nhiều nhất</option>
			</select>
		</p>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['title_color'] = $new_instance['title_color'];
		$instance['background_color'] = $new_instance['background_color'];
		$instance['description'] = $new_instance['description'];
		$instance['category'] = $new_instance['category'];
		$instance['columns'] = $new_instance['columns'];
		$instance['number_posts'] = $new_instance['number_posts'];
		$instance['order'] = $new_instance['order'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$title_color = $instance['title_color'] ? 'light' : '';
		$background_color = $instance['background_color'];
		$description = $instance['description'];
		$columns = $instance['columns'];
		$number_posts = $instance['number_posts'] ? $instance['number_posts'] : 100;
		$order = $instance['order'];
		$category = $instance['category'];
		if($background_color != '#FFFFFF')
			$after_widget = str_replace('class="widget-background"', 'class="widget-background" style="background-color: '.$background_color.';"', $after_widget);
		if($columns == 4){
			$class = 'col-sm-3';
		} elseif($columns == 3){
			$class = 'col-sm-4';
		} else $class = 'col-sm-6';
		if($order ==  'viewest'){
			$news = new WP_Query( array('post_type' => 'post', 'cat' => $category, 'posts_per_page' => $number_posts, 'meta_key' => 'wpb_post_views_count', 'orderby' => array('meta_value_num' => 'DESC','publish_date' => 'DESC')  ) ); 
		} else {
			$news = new WP_Query( array('post_type' => 'post', 'cat' => $category, 'posts_per_page' => $number_posts, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
		}
		echo $before_widget;
		if($title){
			echo "<div class='section__title $title_color'>";
			echo $before_title.$title.$after_title;
			echo '</div><div class="pt-3"></div>';
		} ?>
		<?php if($news->have_posts()): ?>
		<div class="row">
			<?php
			while ( $news->have_posts() ) : $news->the_post(); ?>
			<div class="col-md-4">
				<div class="card card-news">
					<div class="card-img">
						<a href="<?php the_permalink(); ?>">
							<?php the_post_thumbnail(array( 600, 360, 'bfi_thumb' => true )); ?>
						</a>
					</div>
					<div class="card-body">
						<h5 class="card-title">
						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
						</h5>
						<div class="text-icon-note"><i class="zmdi zmdi-time"></i><span><?php echo get_the_time('d-m-Y') ?></span></div>
						<p class="card-text"><?php echo wp_trim_words( get_the_excerpt(), 20, '...' ); ?></p>
					</div>
				</div>
			</div>
			<?php endwhile;
			?>
        </div>
		<?php endif; ?>
    <?php
		echo $after_widget;
	}

}

class FooterMenu_Widget extends WP_Widget {
/**
* Thiết lập widget: đặt tên, base ID
*/
	function __construct() {
		parent::__construct (
			'dwn_footer_menu_widget', // id của widget
			'DWN Footer Menu', // tên của widget
			array(
				'description' => 'Hiển thị danh sách liên kết trong footer menu.' // mô tả
			)
		);
	}
	/**
	* Tạo form option cho widget
	*/
	function form( $instance ) {
		parent::form( $instance );
		//Biến tạo các giá trị mặc định trong form
		$default = array(
			'title' => '',
			'menu_id' => 'footer-menu1',
		);
		//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
		$instance = wp_parse_args( (array) $instance, $default);
		//Tạo biến riêng cho giá trị mặc định trong mảng $default
		$title = esc_attr( $instance['title'] );
		$menu_id = esc_attr( $instance['menu_id'] );
		echo '<p><label for="">Title:</label> <input class="widefat" type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" /></p>';?>
		<p>
			<label for="">Chọn Menu Hiển Thị:</label>
			<select name="<?php echo $this->get_field_name('menu_id') ?>" >
				<option value="footer-menu-1" <?php echo selected($menu_id, "footer-menu-1") ?>>Footer menu 1</option>
				<option value="footer-menu-2" <?php echo selected($menu_id, "footer-menu-2") ?>>Footer menu 2</option>
			</select>
		</p>
	<?php
	}
		
	/**
	* save widget form
	*/
		
	function update( $new_instance, $old_instance ) {
		parent::update( $new_instance, $old_instance );
		
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['menu_id'] = $new_instance['menu_id'];
		return $instance;
	}

	/**
	* Show widget
	*/
		
	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters( 'widget_title', $instance['title'] );
		$menu_id = $instance['menu_id'];
		echo $before_widget;
		echo $before_title.$title.$after_title;
		echo '<ul id="main-nav_footer1" class="list-arrow-down">';
		foreach (wp_get_nav_menu_items($menu_id) as $item) {
			$link = $item->url;
        	$title = $item->title;
			if( $item->menu_item_parent == 0 ) 
            echo '<li class="menu-item" id="menu-item-'.$item->ID.'"><a href="' . $link . '">' . $title . '</a></li>';
		};
		echo '</ul>';
		echo $after_widget;
	}

}
?>