/**
 * return all terms taxonomies base post type
 * @param $post_type: post type name
 * @param $args: addition arguments
 */
function hwrp_get_all_terms_taxonomies($post_type, $args = array())
{
    if (!class_exists('HW_POST')) {
        HW_HOANGWEB::load_class('HW_POST');
    }
    return HW_POST::get_all_terms_taxonomies($post_type, $args);
}
 /**
  * main class constructor
  */
 public function __construct()
 {
     //list taxonomies
     $tax_data = HW_POST::hw_list_taxonomies(array('hw-ml-slider'));
     //array_unshift($tax_data, '--Select--');
     HW_UI_Component::empty_select_option($tax_data);
     $this->tax_data = $tax_data;
     //list templates for current theme
     $this->theme_templates_list = array('-1' => 'Mặc định');
     $templates = hw_list_active_theme_templates();
     foreach ($templates as $file) {
         $this->theme_templates_list[base64_encode($file['path'])] = $file['name'];
     }
     //add action filters
     $this->add_actions();
 }
 /**
  * create new contact form
  * @param $args
  * @param $assoc_args
  */
 public function create_form($args, $assoc_args)
 {
     $this->do_import();
     $form_slug = 'contact-form-1';
     $page = 'lien-he';
     $page = get_page_by_path($page);
     //get form
     $cf = HW_POST::get_post_by_name($form_slug, 'wpcf7_contact_form');
     if (is_wp_error($cf)) {
         WP_CLI::error('Not found contact form with name: ' . $form_slug);
         return;
     }
     $form_id = $cf->ID;
     //update contact page with contact form 7 inserting
     $contact_page = array('post_type' => 'page', 'post_content' => '[contact-form-7 id="' . $form_id . '"]');
     if (!is_wp_error($page)) {
         $contact_page['ID'] = $page->ID;
     }
     wp_update_post($contact_page);
     WP_CLI::success(' Create new contact form 7 successful.');
 }
 /**
  * load custom fields associate with post type
  */
 public function _hw_load_customfields_from_pt()
 {
     if (!wp_verify_nonce($_REQUEST['nonce'], "load_customfields_from_pt_nonce")) {
         exit("unauthorize");
     }
     global $wpdb, $wp_registered_widgets;
     $customfields = array();
     //all custom fields get from post type
     $sql = array();
     //prepare sql command
     $pt = explode(',', $_GET['pt']);
     /**
      * get widget object by id
      */
     $widget_id = $_GET['widget'];
     //get widget id
     $widget_obj = $wp_registered_widgets[$widget_id];
     $widget_obj = $widget_obj['callback'][0];
     //widget object instance
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         //$result = json_encode($result);
         $mt_keys = HW_POST::generate_posttypes_meta_keys($pt);
         $out = sprintf('<select name="%s" id="%s" multiple style="max-height:500px;width:200px">', esc_attr($widget_obj->get_field_name('more_meta_keys') . '[]'), esc_attr($widget_obj->get_field_id('more_meta_keys')));
         // Holds the HTML markup.
         $structure = array();
         foreach ($mt_keys as $key) {
             $structure[] = sprintf('<option value="%s" key="%s" >%s</option>', esc_attr($key), esc_attr($key), esc_html($key));
         }
         $out .= join("\n", $structure);
         $out .= '</select>';
         echo $out;
     } else {
         header("Location: " . $_SERVER["HTTP_REFERER"]);
     }
     die;
 }
    /**
     * Widget settings
     * @param $instance
     */
    function form($instance)
    {
        //$this->skin->saveCallbackJs4SkinChangeEvent('console.log(skin);');
        //$this->skin->saveCallbackJs4SkinChangeEvent('console.log("jkehrerdgb");');
        //for showing/hiding advanced options; wordpress moves this script to where it needs to go
        wp_enqueue_script('jquery');
        //create feature tog
        if (class_exists('HW_ButtonToggle_widget')) {
            $btn_tog = new HW_ButtonToggle_widget($this, $instance);
        }
        ?>

        <?php 
        $terms_data = array();
        // instance exist? if not set defaults
        if ($instance) {
            $title = $instance['title'];
            $this_taxonomy = $instance['taxonomy'];
            $orderby = $instance['orderby'];
            $ascdsc = $instance['ascdsc'];
            $exclude = $instance['exclude'];
            $childof = $instance['childof'];
            $showcount = isset($instance['count']) ? (bool) $instance['count'] : false;
            $hierarchical = isset($instance['hierarchical']) ? (bool) $instance['hierarchical'] : false;
            $dropdown = isset($instance['dropdown']) ? (bool) $instance['dropdown'] : false;
            $childof_current_term = isset($instance['childof_current_term']) ? (bool) $instance['childof_current_term'] : false;
            $show_subcat_by_parent = isset($instance['show_subcat_by_parent']) ? (bool) $instance['show_subcat_by_parent'] : false;
            $categories_by_current_post = isset($instance['categories_by_current_post']) ? (bool) $instance['categories_by_current_post'] : false;
            $hide_empty = isset($instance['hide_empty']) ? (bool) $instance['hide_empty'] : false;
            $depth = isset($instance['depth']) ? $instance['depth'] : 0;
            $use_skin = isset($instance['use_skin']) ? (bool) $instance['use_skin'] : false;
            $extend_skin_options = isset($instance['extend_skin_options']) ? (bool) $instance['extend_skin_options'] : false;
            $skin = isset($instance['skin']) ? $instance['skin'] : '';
            //saved active hash skin
            //total skin setting
            $skin_setting = isset($instance['skin_settings']) ? $instance['skin_settings'] : '';
            $skin_condition = isset($instance['skin_condition']) ? $instance['skin_condition'] : '';
            $show_option_none = isset($instance['show_option_none']) ? $instance['show_option_none'] : '';
            //get terms by select tax
            if (!empty($this_taxonomy)) {
                $terms_data = HW_POST::list_tax_terms($this_taxonomy);
            }
        } else {
            //These are our defaults
            $title = '';
            $orderby = 'count';
            $ascdsc = 'desc';
            $exclude = '';
            $childof = '';
            $this_taxonomy = 'category';
            //this will display the category taxonomy, which is used for normal, built-in posts
            $hierarchical = true;
            $showcount = true;
            $dropdown = false;
            $childof_current_term = false;
            $show_subcat_by_parent = false;
            $categories_by_current_post = false;
            $hide_empty = false;
            //default hide if empty
            $depth = 0;
            //unlimit nested level
            $use_skin = false;
            $skin = '';
            $skin_setting = '';
            $skin_condition = '';
            $extend_skin_options = false;
            $show_option_none = '';
        }
        // The widget form
        $terms_holder_id = 'holder-' . $this->get_field_id('terms');
        $exclude_terms_holder_id = 'holder-' . $this->get_field_id('exclude_terms');
        ?>
		
		
			<p>
				<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        echo __('Tiêu đề:');
        ?>
</label>
				<input id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" class="widefat" />
			</p>
			<p>
				<label for="<?php 
        echo $this->get_field_id('taxonomy');
        ?>
"><?php 
        echo __('Chọn Taxonomy:');
        ?>
</label>
				<select name="<?php 
        echo $this->get_field_name('taxonomy');
        ?>
" id="<?php 
        echo $this->get_field_id('taxonomy');
        ?>
" class="widefat" style="height: auto;" size="4" onchange="__hwlct_object.change_taxonomy(this, '#<?php 
        echo $terms_holder_id;
        ?>
', 'hwlct_change_taxonomy_cbs','<?php 
        //echo $link
        ?>
')">
			<?php 
        $args = array('public' => true, '_builtin' => false);
        $output = 'names';
        // or objects
        $operator = 'and';
        // 'and' or 'or'
        $taxonomies = get_taxonomies($args, $output, $operator);
        $taxonomies[] = 'category';
        $taxonomies[] = 'post_tag';
        $taxonomies[] = 'post_format';
        foreach ($taxonomies as $taxonomy) {
            ?>
				<option value="<?php 
            echo $taxonomy;
            ?>
" <?php 
            if ($taxonomy == $this_taxonomy) {
                echo 'selected="selected"';
            }
            ?>
><?php 
            echo $taxonomy;
            ?>
</option>
			<?php 
        }
        ?>
			</select>
			</p>
			<?php 
        if (class_exists('HW_SKIN')) {
            ?>
			    <p><?php 
            //echo $this->skin->get_skins_select_tag('skin');
            //$this->skin->get_skins_listview('skin1',$instance['skin1']);
            //$this->skin->get_skin_instance('t1')->get_skins_select_tag('skin2',null,array('class'=>'widefat'),HW_SKIN::DROPDOWN_DDSSLICK_THEME,HW_SKIN::SKIN_LINKS);
            ?>
</p>
            <p>
                <input type="checkbox" name="<?php 
            echo $this->get_field_name('use_skin');
            ?>
" id="<?php 
            echo $this->get_field_id('use_skin');
            ?>
" <?php 
            checked($use_skin);
            ?>
/>
                <label for="<?php 
            echo $this->get_field_id('use_skin');
            ?>
"><?php 
            _e('Kích hoạt Giao diện');
            ?>
</label>

            </p>
            <p>
                <input type="checkbox" name="<?php 
            echo $this->get_field_name('extend_skin_options');
            ?>
" id="<?php 
            echo $this->get_field_id('extend_skin_options');
            ?>
" <?php 
            selected($extend_skin_options ? 1 : 0);
            ?>
 />
                <label for="<?php 
            echo $this->get_field_id('extend_skin_options');
            ?>
"><?php 
            _e('Cho phép sử dụng skin options');
            ?>
</label>
                <br/>
                <span><em>Cho phép sử dụng skin options mặc dù không kích hoạt sử dụng giao diện riêng.</em></span>
            </p>
			<p>
			     <label for="<?php 
            echo $this->get_field_id('skin');
            ?>
"><strong><?php 
            _e('Giao diện');
            ?>
</strong></label>
				  <?php 
            echo $this->skin->get_skins_select_tag('skin', null, array('class' => 'widefat'), false);
            #$this->skin->addCallbackSkinChangeEvent('console.log(3);');
            ?>
                <!-- show skin options,skin condition field if exists -->
                <?php 
            echo $this->skin->get_skin_template_condition_selector('skin_condition', $skin_condition);
            echo $this->skin->prepare_skin_options_fields('skin_settings', $skin_setting, $skin);
            /*echo $this->skin->create_total_skin_selector('skin', array('hash_skin' => $skin, 'skin_settings' => $skin_setting), null,array(
                  'show_main_skin' =>0,
                  'show_condition_field'=>1,
                  'show_skin_options' => 1
              ));*/
            ?>
			</p>
			
			<?php 
        }
        ?>
			<?php 
        if (isset($btn_tog)) {
            $btn_tog->set_button_toggle_start_wrapper('Nâng cao...');
        }
        ?>
				
				<input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('count');
        ?>
" name="<?php 
        echo $this->get_field_name('count');
        ?>
"<?php 
        checked($showcount);
        ?>
 />
				<label for="<?php 
        echo $this->get_field_id('count');
        ?>
"><?php 
        _e('Hiển thị số lượng posts bên cạnh');
        ?>
</label><br />
				<input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('hierarchical');
        ?>
" name="<?php 
        echo $this->get_field_name('hierarchical');
        ?>
"<?php 
        checked($hierarchical);
        ?>
 />
				<label for="<?php 
        echo $this->get_field_id('hierarchical');
        ?>
"><?php 
        _e('Hiển thị đa tầng');
        ?>
</label><br/>

        <input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('dropdown');
        ?>
" name="<?php 
        echo $this->get_field_name('dropdown');
        ?>
"<?php 
        checked($dropdown);
        ?>
 />
        <label for="<?php 
        echo $this->get_field_id('dropdown');
        ?>
"><?php 
        _e('Hiển thị dạng Dropdown');
        ?>
</label><br/>

        <input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('hide_empty');
        ?>
" name="<?php 
        echo $this->get_field_name('hide_empty');
        ?>
" <?php 
        checked($hide_empty);
        ?>
 />
        <label for="<?php 
        echo $this->get_field_id('hide_empty');
        ?>
"><?php 
        _e('Ẩn mục không có posts');
        ?>
</label><br/>

        <input type="text" class="text" size="5" id="<?php 
        echo $this->get_field_id('depth');
        ?>
" name="<?php 
        echo $this->get_field_name('depth');
        ?>
" value="<?php 
        echo isset($instance['depth']) ? $instance['depth'] : '0';
        ?>
" />
        <label for="<?php 
        echo $this->get_field_id('depth');
        ?>
"><?php 
        _e('depth');
        ?>
</label><br/>
        <span><em>=1: Nếu chỉ muốn hiện tất cả những danh mục chính.</em></span><br/>
        <span><em>Yêu cầu: bật tùy chọn "Hiển thị đa tầng".</em></span>

				<p>
					<label for="<?php 
        echo $this->get_field_id('orderby');
        ?>
"><?php 
        echo __('Xắp xếp:');
        ?>
</label>
					<select name="<?php 
        echo $this->get_field_name('orderby');
        ?>
" id="<?php 
        echo $this->get_field_id('orderby');
        ?>
" class="widefat" >
						<option value="ID" <?php 
        if ($orderby == 'ID') {
            echo 'selected="selected"';
        }
        ?>
>ID</option>
						<option value="name" <?php 
        if ($orderby == 'name') {
            echo 'selected="selected"';
        }
        ?>
>Name</option>
						<option value="slug" <?php 
        if ($orderby == 'slug') {
            echo 'selected="selected"';
        }
        ?>
>Slug</option>
						<option value="count" <?php 
        if ($orderby == 'count') {
            echo 'selected="selected"';
        }
        ?>
>Count</option>
						<option value="term_group" <?php 
        if ($orderby == 'term_group') {
            echo 'selected="selected"';
        }
        ?>
>Term Group</option>
					</select>
				</p>
				<p>
					<label><input type="radio" name="<?php 
        echo $this->get_field_name('ascdsc');
        ?>
" value="asc" <?php 
        if ($ascdsc == 'asc') {
            echo 'checked';
        }
        ?>
/> Tăng dần</label><br/>
					<label><input type="radio" name="<?php 
        echo $this->get_field_name('ascdsc');
        ?>
" value="desc" <?php 
        if ($ascdsc == 'desc') {
            echo 'checked';
        }
        ?>
/> Giảm dần</label>
				</p>
				<p id="<?php 
        echo $exclude_terms_holder_id;
        ?>
">
					<label for="<?php 
        echo $this->get_field_id('exclude');
        ?>
">Loại trừ ID (danh sách IDs ngăn cách dấu phẩy)</label><br/>
					<select multiple class="widefat" name="<?php 
        echo $this->get_field_name('exclude');
        ?>
[]" >
                        <?php 
        if (!empty($terms_data)) {
            foreach ($terms_data as $id => $name) {
                $selected = in_array($id, $exclude) ? 'selected="selected"' : '';
                printf('<option %s value="%s">%s</option>', $selected, $id, $name);
            }
        }
        ?>
					</select>
				</p>
        <hr/>
				<p id="<?php 
        echo $terms_holder_id;
        ?>
">
					<label for="<?php 
        echo $this->get_field_id('childof');
        ?>
">Chỉ hiển thị sub-category của category mẹ (category id)</label><br/>
                    <?php 
        //echo $childof;
        ?>
					<select class="widefat" data-id="<?php 
        echo $this->number;
        ?>
" name="<?php 
        echo $this->get_field_name('childof');
        ?>
" id="<?php 
        echo $this->get_field_id('childof');
        ?>
">
                        <option value="">---- Chọn ----</option>
                        <?php 
        if (!empty($terms_data)) {
            foreach ($terms_data as $id => $name) {
                printf('<option %s value="%s">%s</option>', selected($id, $childof, false), $id, $name);
            }
        }
        ?>
					</select>

				</p>
                <p>
                    <input type="checkbox" name="<?php 
        echo $this->get_field_name('childof_current_term');
        ?>
" id="<?php 
        echo $this->get_field_id('childof_current_term');
        ?>
" <?php 
        checked($childof_current_term ? 1 : 0);
        ?>
/>
                    <label for="<?php 
        echo $this->get_field_id('childof_current_term');
        ?>
"><?php 
        _e('Lấy category mẹ hiện tại(category id)');
        ?>
</label><br/>
                    <span><em>Chỉ hiển thị sub-category của category hiện tại.</em></span>
                </p>
        <hr/>
                <p>
                    <input type="checkbox" name="<?php 
        echo $this->get_field_name('show_subcat_by_parent');
        ?>
" id="<?php 
        echo $this->get_field_id('show_subcat_by_parent');
        ?>
" <?php 
        checked($show_subcat_by_parent ? 1 : 0);
        ?>
/>
                    <label for="<?php 
        echo $this->get_field_id('show_subcat_by_parent');
        ?>
" style="text-decoration: line-through;"><?php 
        _e('Hiển thị sub-category khi vào trang mẹ');
        ?>
</label><br/>

                    <span><em>Hiển thị sub-category con của trang category mẹ nhưng vẫn dữ toàn bộ danh mục</em></span>
                </p>
        <hr/>
                <p>
                    <label for="<?php 
        echo $this->get_field_id('show_option_none');
        ?>
"><strong><?php 
        _e('Nội dung không có dữ liệu');
        ?>
</strong></label><br/>
                    <input type="text" name="<?php 
        echo $this->get_field_name('show_option_none');
        ?>
" id="<?php 
        echo $this->get_field_id('show_option_none');
        ?>
" value="<?php 
        echo $show_option_none;
        ?>
"/>

                </p>
            <p>
                <input type="checkbox" name="<?php 
        echo $this->get_field_name('categories_by_current_post');
        ?>
" id="<?php 
        echo $this->get_field_id('categories_by_current_post');
        ?>
" <?php 
        checked($categories_by_current_post ? 1 : 0);
        ?>
/>
                <label for="<?php 
        echo $this->get_field_id('categories_by_current_post');
        ?>
"><?php 
        _e('Hiển thị cho post hiện tại');
        ?>
</label><br/>
                <span><em>Hiển thị tất cả những taxonomies, taxonomies nào thuộc về post hiện tại.</em></span>
            </p>

			<script>
                /**
                 * hwlct_change_taxonomy_cbs callbacks
                 */
                if(typeof __hwlct_object.add_callback == 'function')
                __hwlct_object.add_callback('<?php 
        echo $this->number;
        ?>
', 'hwlct_change_taxonomy_cbs', {
                    before_ajax : function() {
                        var select_tag = jQuery('#<?php 
        echo $this->get_field_id('childof');
        ?>
:eq(0)'),
                            exclude_select_tag = jQuery('#<?php 
        echo $this->get_field_id('exclude');
        ?>
:eq(0)');

                        select_tag.html(' ').append(jQuery('<option>', {value:'',text : 'Loading..'}));
                        exclude_select_tag.html(' ').append(jQuery('<option>', {value:'',text : 'Loading..'}));
                    },
                    after_ajax : function(data) {
                        var select_tag = jQuery('#<?php 
        echo $this->get_field_id('childof');
        ?>
:eq(0)'),
                            exclude_select_tag = jQuery('#<?php 
        echo $this->get_field_id('exclude');
        ?>
:eq(0)');

                        jQuery(select_tag).add(exclude_select_tag).html(' ').append(jQuery('<option>', {
                            value: "",
                            text: "------Select------"  //.data[value]
                        }));

                        if(data.posts)
                            jQuery.each(data.terms, function(value, text) {
                                jQuery(select_tag).add(exclude_select_tag).append(jQuery('<option>', {
                                    value: value,
                                    text: text  //.data[value]
                                }));
                            });

                    }
                });
			</script>
			<?php 
        if (isset($btn_tog)) {
            $btn_tog->set_button_toggle_end_wrapper();
        }
        //close feature tog
    }
 public function setUp()
 {
     $sliders = self::get_all_mlsliders();
     //_print($this->__get('oForm')->getValue());
     $fields = array();
     //fields setting
     /*get all post type terms*/
     $select_posttype = hwml_get_option('source_posttype');
     if (!is_string($select_posttype)) {
         $select_posttype = 'post';
     }
     // default post type
     //prepare terms list for active post type
     $data = array();
     $terms = HW_POST::get_all_terms_taxonomies($select_posttype);
     //get all terms from post type
     foreach ($terms as $t) {
         $data[base64_encode($t->slug . '|' . $t->taxonomy)] = $t->name;
     }
     $this->addSettingFields(array('field_id' => 'slideshow_source', 'type' => 'select', 'title' => __('Chọn nguồn slides'), 'description' => 'Lấy dữ liệu cho slideshow.', 'label' => array('metaslider' => 'Slider', 'posttype' => 'Post Type & Taxonomies')), array('field_id' => 'current_post', 'type' => 'checkbox', 'title' => __('Post hiện tại'), 'description' => 'Lấy ảnh gán vào post hiện tại.'), array('field_id' => 'source_posttype', 'type' => 'select', 'title' => 'Chọn Post Types', 'label' => get_post_types(), 'description' => __('Lựa chọn post type & nhấn cập nhật/xuất bản để lọc danh mục.')), array('field_id' => 'only_attachments', 'type' => 'checkbox', 'title' => __('Lấy ảnh gán vào post'), 'description' => 'Lấy toàn bộ ảnh gán vào post.'));
     //if(count($this->data) > 0){   //warning: don't put any condition to add setting field , it will not work!
     $this->addSettingFields(array('field_id' => 'post_type_terms', 'type' => 'checkbox', 'title' => 'Danh mục của (' . $select_posttype . ')', 'description' => !count($data) ? ' Không có dữ liệu !' : 'Chọn danh mục của post type đã chọn.', 'label' => $data), array('field_id' => 'tax_query_relation', 'type' => 'select', 'title' => 'Mối quan hệ AND/OR cho danh mục', 'description' => '', 'label' => array('AND' => 'AND', 'OR' => 'OR')));
     //}
     $this->addSettingFields(array('field_id' => 'pick_slider', 'type' => 'select', 'title' => __('Chọn nguồn slider', 'hwslider'), 'description' => __('Chọn dữ liệu sliders. Thêm/Sửa slides <a target="_blank" href="' . self::get_edit_sliders_url() . '">tại đây</a>.', 'hwslider'), 'label' => $sliders), array('field_id' => 'show_title', 'type' => 'checkbox', 'title' => 'Hiển thị tiêu đề slide', 'description' => 'Hiển thị tiêu đề slide'), array('field_id' => 'slider_theme', 'type' => 'hw_skin', 'title' => __('Chọn slider theme', 'hwslider'), 'description' => __('Chọn theme riêng cho slider', 'hwslider'), 'enable_skin_condition' => true, 'external_skins_folder' => 'hw_mlslider_skins', 'skin_filename' => 'mlslider-skin.php', 'enable_external_callback' => false, 'skins_folder' => 'themes', 'apply_current_path' => HWML_PLUGIN_PATH, 'plugin_url' => HWML_PLUGIN_URL, 'group' => 'group-others', 'hwskin_field_output_callback' => array($this, '_hwskin_field_output')));
     //add dynamic apf fields
     if (count($fields) > 0) {
         foreach ($fields as $opt) {
             $this->addSettingField($opt);
         }
     }
     // content_{page slug}_{tab slug}
     //add_filter( 'content_hw_sidebar_widgets_settings', array( $this, 'replyToInsertContents' ) );
 }
	<ul class="smoothDivScroll"><!-- class="smoothDivScroll" ->for scrolling content option -->
		<?php 
if (!empty($cat_posts)) {
    while ($cat_posts->have_posts()) {
        $cat_posts->the_post();
        $classes = array();
        if (0 == $cat_posts->current_post || 0 == $cat_posts->current_post % 4) {
            $classes[] = 'first';
        }
        if (($cat_posts->current_post + 1) % 4 == 0) {
            $classes[] = 'lastcolumn';
        }
        //other way
        //HW_POST::get_item_class();
        if (isset($awc_enable_grid_posts) && $awc_enable_grid_posts && class_exists('HW_POST') && !empty($awc_grid_posts_cols)) {
            $classes = HW_POST::get_item_class($awc_grid_posts_cols, $classes);
        }
        //display post custom fields
        if (in_array('duration', $metaFields)) {
            $duration = get_post_meta(get_the_ID(), 'duration', true);
        }
        $classes = implode(' ', $classes);
        //feature image
        $full_image_src = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
        //for fancybox
        ?>
				<li <?php 
        post_class($classes);
        ?>
>
    $classes = array();
    if ($cat_posts->current_post == 0) {
        $classes[] = 'dongA';
    } else {
        $classes[] = 'dongAt';
    }
    if (0 == $cat_posts->current_post || 0 == $cat_posts->current_post % 4) {
        $classes[] = 'first';
    }
    if (($cat_posts->current_post + 1) % 4 == 0) {
        $classes[] = 'lastcolumn';
    }
    //other way
    //HW_POST::get_item_class();
    if ($awc_enable_grid_posts && class_exists('HW_POST')) {
        $classes = HW_POST::get_item_class($instance['awc_grid_posts_cols'], $classes);
    }
    //display post custom fields
    /*if(in_array('duration',$metaFields)){
          $duration = get_post_meta(get_the_ID(),'duration',true);
      }*/
    $classes = implode(' ', $classes);
    if ($cat_posts->current_post == 0) {
        ?>

                <div <?php 
        post_class($classes);
        ?>
>
                    <div class="itemhot_home"></div>
                    <a href="<?php 
/**
 * list terms taxonomy
 * @param $tax
 * @param $args
 * @param $field default get term id as select value
 * @return array
 */
function hwlct_list_tax_terms($tax, $args = array(), $field = 'id')
{
    HW_HOANGWEB::load_class('HW_POST');
    return HW_POST::list_tax_terms($tax, $args, $field);
}
if ($dropdown) {
    echo '<form action="' . get_bloginfo('url') . '" method="get">';
    wp_dropdown_categories($args);
    echo '<input type="submit" value="go &raquo;" />';
    echo '</form>';
} else {
    echo '<div id="lct-widget-' . $tax . '" class="hwlct-container hwlct-travel-box">';
    //wp_list_categories($args);
    HW_POST::reset_item_counter();
    //$data = get_categories($args);
    foreach ($terms_data as $i => $term) {
        $classes = array('item-box');
        if ($awc_enable_grid_posts && isset($awc_grid_posts_cols) && class_exists('HW_POST')) {
            $classes = HW_POST::get_item_class($awc_grid_posts_cols, $classes);
        }
        $classes_attribute = HW_POST::item_class($classes);
        $term_link = get_term_link($term);
        //term image custom field
        if (function_exists('get_field')) {
            $image = get_field('image', $term);
        } else {
            $image = '';
        }
        if (!$image) {
            $image = HW_SKIN::current()->get_skin_url('images/placeholder.png');
        }
        $quick_edit_link = esc_url(get_edit_term_link($term, $term->taxonomy));
        $skin->render_skin_template(array('classes_attribute' => $classes_attribute, 'term_link' => $term_link, 'image' => $image, 'quick_edit_link' => $quick_edit_link, 'term' => $term), true, false, 'loop.tpl');
        /*
        ?>
        <div  <?php echo $classes_attribute?> id="<?php echo $term->term_id?>">
    echo '<form action="' . get_bloginfo('url') . '" method="get">';
    wp_dropdown_categories($args);
    echo '<input type="submit" value="go &raquo;" /></form>';
} else {
    echo '<div id="lct-widget-' . $tax . '" class="hwlct-container hwlct-box1">';
    //wp_list_categories($args);
    HW_POST::reset_item_counter();
    $data = get_categories($args);
    foreach ($data as $term) {
        $classes = array('item-box');
        if ($awc_enable_grid_posts && isset($awc_grid_posts_cols) && class_exists('HW_POST')) {
            $classes = HW_POST::get_item_class($awc_grid_posts_cols, $classes);
        }
        ?>
        <div <?php 
        HW_POST::item_class($classes);
        ?>
 id="<?php 
        echo $term->term_id;
        ?>
">
            <div class="sub-category-item">
                <div class="picture">
                    <a href="<?php 
        echo get_term_link($term);
        ?>
" title="<?php 
        echo $term->name;
        ?>
">
                        <?php 
 /**
  * get related posts template by current post or specific post ID
  * @param $post_id: post ID or single post data
  */
 public function get_relatedposts_template_by_post($post_id = '')
 {
     if (!empty($post_id) && is_numeric($post_id)) {
         $post = get_post($post_id);
     }
     if (!isset($post)) {
         global $post;
         //get current post
     }
     if (empty($post)) {
         return;
     }
     //post not found (not single post page)
     //get post type
     $post_type = $post->post_type;
     $skins = hw_yarpp_get_option('hwrp_skins');
     if (!isset($skins[$post_type]) || !isset($skins[$post_type]['active'])) {
         return;
         //current post not support related posts skin
     }
     //get post terms
     if (!isset($skins[$post_type]['filter_terms']) || !$skins[$post_type]['filter_terms']) {
         //filter skin with terms
         $allow_terms = $skins[$post_type]['terms'];
         if (!HW_POST::check_post_terms($post, $allow_terms, false)) {
             return;
         }
         //not match requirement
         /*$terms = hwrp_get_all_post_terms($post, array('fields'=> 'slugs'));
           if(is_array($terms))
           foreach($terms as $slug){
               if( !in_array($slug,$allow_terms)) return;   //not match requirement
           }*/
     }
     //override template by checking detail term
     if (class_exists('APF_Related_templates')) {
         $result = APF_Related_templates::get_relatedposts_template_by_post($post);
         //from HW_HOANGWEB plugin
         if (!empty($result['template']['instance'])) {
             $skins[$post_type]['instance'] = $result['template']['instance'];
             //change active skin
             if (isset($result['template']['hash_skin'])) {
                 $skins[$post_type]['skin'] = $result['template']['hash_skin'];
             }
             $skins[$post_type]['options_data'] = $result;
             //detail related data
             //override
             if (isset($result['title'])) {
                 $skins[$post_type]['title'] = $result['title'];
             }
             //override skin
             if (isset($result['widget_config'])) {
                 $skins[$post_type]['widget_config'] = $result['widget_config'];
             }
             if (isset($result['sidebar'])) {
                 $skins[$post_type]['box_skin'] = $result['sidebar'];
             }
             if (isset($result['sidebar_widget_skin'])) {
                 $skins[$post_type]['box_widget_skin'] = $result['sidebar_widget_skin'];
             }
             return (object) $skins[$post_type];
         }
     }
     //get related posts skin for current post
     if (!isset($skins[$post_type]['instance']) && isset($skins[$post_type]['skin']) && !empty($skins[$post_type]['hwskin_config']) && class_exists('HW_SKIN')) {
         $skins[$post_type]['instance'] = HW_SKIN::resume_skin($skins[$post_type]['hwskin_config']);
         //resume hw_skin instance
         return (object) $skins[$post_type];
     }
 }
 /**
  * reset counter for listing terms taxonomy
  */
 public static function reset_item_counter()
 {
     self::$iCount = 0;
 }
</p>
<p><!-- more meta keys -->
    <label for="<?php 
echo $this->get_field_id("more_meta_keys");
?>
"><?php 
_e('Chọn meta keys');
?>
</label>
<div id="<?php 
echo $this->get_field_id('holder_meta_keys');
?>
">
    <?php 
if (isset($instance['more_meta_keys'])) {
    $mt_keys = HW_POST::generate_posttypes_meta_keys($instance['posttype']);
    $out = sprintf('<select name="%s" id="%s" multiple style="max-height:200px;width:200px">', esc_attr($this->get_field_name('more_meta_keys') . '[]'), esc_attr($this->get_field_id('more_meta_keys')));
    // Holds the HTML markup.
    $structure = array();
    foreach ($mt_keys as $key) {
        $selected = in_array($key, (array) $instance['more_meta_keys']);
        $structure[] = sprintf('<option value="%s" key="%s" ' . ($selected ? 'selected="selected"' : '') . '>%s</option>', esc_attr($key), esc_attr($key), esc_html($key));
    }
    $out .= join("\n", $structure);
    $out .= '</select>';
    echo $out;
}
?>

</div>
<a href="javascript:void(0)" onclick="__hwcpl_object.get_customfields_by_type(jQuery('#<?php 
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 private function _process_posts()
 {
     $this->posts = apply_filters('hw_import_posts', $this->posts);
     $_id_meta_key = '_hw_id';
     //hwArray::split_loop_segments(5, count($this->posts));
     foreach ($this->posts as $post) {
         $post = apply_filters('hw_import_post_data_raw', $post);
         if (!post_type_exists($post['post_type'])) {
             $this->logger->add_log(sprintf(__('Failed to import &#8220;%s&#8221;: Invalid post type %s', 'wordpress-importer'), esc_html($post['post_title']), esc_html($post['post_type'])));
             do_action('wp_import_post_exists', $post);
             continue;
         }
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->_process_menu_item($post);
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         $post_id = 0;
         //$post_exists = post_exists( $post['post_title'], '', $post['post_date'] );    //by wp
         $post_exists = HW_POST::post_exists($post['post_title'], $post['post_type']);
         if ($post_exists && get_post_type($post_exists) == $post['post_type'] && (!isset($post['hw_attributes']['update']) || !$post['hw_attributes']['update'])) {
             $this->logger->add_log(sprintf(__('%s &#8220;%s&#8221; đã tồn tại và không cho phép cập nhật.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title'])));
             $comment_post_ID = $post_id = $post_exists;
             $post['post_id'] = $post['ID'] = $post_id;
             //get _id meta value
             $_id = get_post_meta($post_id, $_id_meta_key, true);
             if ($_id) {
                 $post['_id'] = $_id;
             }
         } else {
             if ($post_exists) {
                 $comment_post_ID = $post_id = $post_exists;
                 //exists post
                 $this->logger->add_log(sprintf(__('Cập nhật vào post "%s" cho %s.', 'wordpress-importer'), esc_html($post['post_title']), $post_type_object->labels->singular_name));
             } else {
                 $this->logger->add_log(sprintf(__('Thêm mới post "%s" cho %s.', 'wordpress-importer'), esc_html($post['post_title']), $post_type_object->labels->singular_name));
             }
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     if (!empty($post['post_id'])) {
                         $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     }
                     //by hoang, because we not use import_id feature
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             //valid
             if ($post['post_content'] instanceof HWIE_Module_Import_Results) {
                 //import result in post content
                 $post['post_content']->init($this->parser->importer, $this->parser->_get_option('data', array()));
                 $post['post_content'] = $post['post_content']->parse_data()->value;
                 //HW_Logger::log_file($post['post_content']);
             }
             $postdata = array('post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             if (!empty($post['post_id'])) {
                 $postdata['import_id'] = $post['post_id'];
             }
             //import id,because we never  use import_id feature
             if (!empty($post_id)) {
                 $post['ID'] = $postdata['ID'] = $post_id;
                 //exists post ID
             }
             $original_post_ID = $post['post_id'];
             $postdata = apply_filters('hw_import_post_data_processed', $postdata, $post);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_wp_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 //fix
                 if (empty($postdata['upload_date'])) {
                     $postdata['upload_date'] = date('Y') . '/' . date('m');
                 }
                 if (trim($remote_url)) {
                     $comment_post_ID = $post_id = $this->_process_attachment($postdata, $remote_url);
                     #__print($post_id);
                     $post['ID'] = $post_id;
                     //save attachment id
                 }
             } else {
                 //by hoang
                 if ($post_exists && isset($post['hw_attributes']['update']) && $post['hw_attributes']['update']) {
                     $comment_post_ID = $post_id = wp_update_post($postdata, true);
                     //update exists post
                 } else {
                     $comment_post_ID = $post_id = wp_insert_post($postdata, true);
                 }
                 //add new post
                 $post['ID'] = $post_id;
                 //set post id
                 do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post);
             }
             if (empty($post_id)) {
                 continue;
             }
             //nothing
             if (is_wp_error($post_id)) {
                 $this->logger->add_log(sprintf(__('Failed to import %s &#8220;%s&#8221;', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title'])));
                 if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                     echo ': ' . $post_id->get_error_message();
                 }
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
         }
         //set postthumbnail
         if (!empty($post['hw_thumbnail_id'])) {
             $thumb_id = (int) $this->hw_processed_posts[$post['hw_thumbnail_id']]['ID'];
             //set_post_thumbnail((int)$post['ID'], $thumb_id);
             update_post_meta((int) $post['ID'], '_thumbnail_id', $thumb_id);
             #__print($this->hw_processed_posts);
         }
         // map pre-import ID to local ID
         /*if(isset($post['_id'])) $post_key = $post['_id'];   //<hw:attachment><hw:_id></hw:_id>...
           elseif(!empty($post['post_id'])) $post_key = intval($post['post_id']);
           elseif(!empty($post['hw_attributes']['name'])) {
               $post_key = $post['hw_attributes']['name'];
           }
           elseif($post['post_title']) $post_key = sanitize_title($post['post_title']);
           */
         $post_key = HW_WXR_Parser::get_import_id($post);
         //$this->hw_processed_posts[$post_key] = array('ID'=>$post['ID']);
         $this->tracker->add_import('post', $post_key, $post);
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         if (!isset($post['terms'])) {
             $post['terms'] = array();
         }
         $post['terms'] = apply_filters('hw_import_post_terms', $post['terms'], $post_id, $post);
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_wp_error($t)) {
                         $term_id = $t['term_id'];
                         do_action('wp_import_insert_term', $t, $term, $post_id, $post);
                     } else {
                         $this->logger->add_log(sprintf(__('Failed to import %s %s', 'wordpress-importer'), esc_html($taxonomy), esc_html($term['name'])));
                         if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                             $this->logger->add_log(': ' . $t->get_error_message());
                         }
                         #echo '<br />';
                         do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post);
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('hw_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('hw_import_post_meta', $post['postmeta'], $post_id, $post);
         if (!is_array($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         //save _id key as post meta, alway update this value
         if (!empty($post['_id'])) {
             $post['postmeta'][] = array('key' => $_id_meta_key, 'value' => $post['_id']);
         }
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('hw_import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         if ($meta['value'] instanceof HWIE_Module_Import_Results) {
                             $meta['value']->init($this->parser->importer, $this->parser->_get_option('data'));
                             $value = $meta['value']->parse_data()->value;
                             #__print($value);
                         } else {
                             $value = maybe_unserialize($meta['value']);
                         }
                     }
                     /*if($value instanceof DOMElement) {
                           $parse = new HWIE_Module_Import_Results($value);
                           $parse->init($this);
                           //$value = $parse->parse_import_thumbnail();
                           $value = $parse->parse_data()->value;
                           $this->logger->add_log('parse import thumbnail: '. $value);
                       }*/
                     //modify by hoang
                     add_post_meta($post_id, $key, $value);
                     if (isset($post['hw_attributes']['update']) && $post['hw_attributes']['update']) {
                         update_post_meta($post_id, $key, $value);
                     }
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key && is_numeric($value)) {
                         $this->featured_images[$post_id] = (int) $value;
                     }
                 }
             }
         }
     }
     unset($this->posts);
 }