/**
  * buid condition select tag
  * @param $value
  * @param array $atts
  * @return string
  */
 public static function get_conditions_select_tag($value, $atts = array())
 {
     HW_HOANGWEB::load_class('HW_UI_Component');
     $options = array();
     $dynamic_settings = self::get_active_conditions_settings();
     foreach ($dynamic_settings as $id => $item) {
         $options[$id] = $item['title'];
     }
     if (class_exists('HW_Conditions_Manager', false)) {
         $guide_link = '(<a href="' . HW_Conditions_Manager::admin_condition_mananger_link() . '" target="_blank">Thêm điều kiện</a>)';
     } else {
         $guide_link = '';
     }
     return HW_UI_Component::build_select_tag($options, $value, $atts, true) . $guide_link;
 }
 /**
  * load option grid posts
  * @param WP_Widget $t: widget object
  * @param array $instance: widget data
  */
 function do_widget_feature($t, $instance = array())
 {
     $this->widget_instance = $instance;
     //maybe update widget instance
     //$wf_name = $this->get_widget_feature_name('');
     //list registered sidebars
     $sidebars = hwawc_get_active_sidebars_select();
     $sidebar_skins = HW_AWC_Sidebar_Settings::available_widget_skins(true);
     //sidebar skins
     //saved widget configs by specifying group
     $widgetconfig_groups = AWC_WidgetFeature_saveconfig::get_widgets_settings_select(' WHERE _group="' . self::WIDGET_CONFIG_GROUP . '"');
     //HW_UI_Component::build_select_tag($sidebars, '', '');
     echo '<div class="form-wf-shortcode-params" id="' . $this->get_field_id('wfshortcode_container') . '"><fieldset><legend>Tạo shortcode widget</legend>';
     echo '<input type="hidden" class="widget_class" name="' . $this->get_field_name('widget_class') . '" id="' . $this->get_field_id('widget_class') . '" value="' . get_class($t) . '"/>';
     echo '<input type="hidden" class="widget_instance" name="' . $this->get_field_name('widget_instance') . '" id=" ' . $this->get_field_id('widget_instance') . ' " value="' . base64_encode(serialize($instance)) . '"/>';
     //apply widget to sidebar
     echo '<p><label for="' . $this->get_field_id('sidebar') . '">Chọn Sidebar</label><br/>';
     echo '<select class="hw-select sidebar" name="' . $this->get_field_name('sidebar') . '" id="' . $this->get_field_id('sidebar') . '">';
     foreach ($sidebars as $id => $name) {
         $selected = selected($this->get_field_value('sidebar'), $id, false);
         printf('<option value="%s" %s>%s</option>', $id, $selected, $name);
     }
     echo '</select></p>';
     //choose sidebar skin
     echo '<p><label for="' . $this->get_field_id('sidebar_skin') . '">Chọn giao diện Sidebar</label><br/>';
     echo HW_UI_Component::build_select_tag($sidebar_skins, null, array('name' => $this->get_field_name('sidebar_skin'), 'id' => $this->get_field_id('sidebar_skin'), 'class' => 'sidebar_skin'));
     echo '</select></p>';
     //widget config group
     echo '<p><label for="' . $this->get_field_id('config_group') . '">Chọn widget config</label><br/>';
     echo '<select class="config_group" name=" ' . $this->get_field_name('config_group') . ' " id="' . $this->get_field_id('config_group') . '">';
     foreach ($widgetconfig_groups as $id => $text) {
         $selected = selected($this->get_field_value('config_group'), $id, false);
         printf('<option value="%s" %s>%s</option>', $id, $selected, $text);
     }
     echo '</select>';
     echo '<a href="javascript:void(0)" onclick="__awc_feature_shortcode_params.refresh_saved_widgetsconfig(this,\'' . $this->get_field_id('config_group') . '\')">Refresh</a>';
     //you also should be active saveconfig feature
     if (!HW_AWC_WidgetFeatures::check_widget_feature($t, 'saveconfig')) {
         echo '<div>Bạn cũng cần kích hoạt feature "<a href="' . admin_url('options-general.php?page=' . HW_HOANGWEB_Settings::HW_SETTINGS_PAGE) . '" target="_blank">saveconfig</a>" cho widget này.</div>';
     }
     echo '</p>';
     echo '<a href="javascript:void(0)" onclick="__awc_feature_shortcode_params.generate_shortcode(this,jQuery(\'#' . $this->get_field_id('wfshortcode_container') . '\'))" class="button">Tạo shortcode</a>';
     echo '<div></div>';
     echo '<p><em>Hướng dẫn</em>: Sử dụng tính năng "Lưu cài đặt" ở tại widget này để lưu cấu hình của widget (chọn nhóm "Shortcode Widget")</p>';
     echo '</fieldset></div>';
 }
        /**
         * load options fixed widget feature
         * @param WP_Widget $t: widget object
         * @param array $instance: widget data
         */
        function do_widget_feature($t, $instance = array())
        {
            $this->widget_instance = $instance;
            //maybe update widget instance
            $enable_fixed = $this->get_field_value('awc_enable_fixed_widget');
            $lib = $this->get_field_value('awc_fixedobj_lib');
            echo '<div class="awc-widget-feature-fixed_widget"><fieldset><legend>Fixed widget</legend>';
            if (class_exists('HW_NHP_Main_Settings', false)) {
                echo '<p><a href="' . HW_NHP_Main_Settings::get_setting_page_url() . '" target="_blank">Kích hoạt & cấu hình fixed widget</a></p>';
            }
            echo '<div ><input type="checkbox" name="' . $this->get_field_name('awc_enable_fixed_widget') . '" id="' . $this->get_field_id('awc_enable_fixed_widget') . '" ' . esc_attr($enable_fixed ? 'checked="checked"' : '') . '/>';
            echo '<label for="' . $this->get_field_id('awc_enable_fixed_widget') . '"><strong>Kích hoạt fixed widget</strong></label></div>';
            //grids column
            echo '<label for="' . $this->get_field_id('awc_fixedobj_lib') . '"><strong>Chọn thư viện</strong></label>';
            $fixed_libs = array('sticky' => 'Sticky', 'sticky-kit' => 'Sticky Kit');
            echo HW_UI_Component::build_select_tag($fixed_libs, $lib, array('name' => $this->get_field_name('awc_fixedobj_lib'), 'id' => $this->get_field_id('awc_fixedobj_lib')));
            #echo '<div><label for="'.$t->get_field_id('awc_grid_fancybox').'"><strong>Số cột posts grid:</strong></label>';
            #echo '<input size="5" type="text" name="'.$t->get_field_name('awc_grid_fancybox').'" id="'.$t->get_field_id('awc_grid_fancybox').'" value="'.$instance['awc_grid_fancybox'].'"/></div>';
            /*echo '<div>
                        <span>Cài đặt options</span><br/>
            
                    </div>';*/
            if ($lib == 'sticky-kit') {
                if (file_exists(plugin_dir_path(__FILE__) . '/options-sticky-kit.php')) {
                    include plugin_dir_path(__FILE__) . '/options-sticky-kit.php';
                }
            } elseif (file_exists(plugin_dir_path(__FILE__) . '/options.php')) {
                include plugin_dir_path(__FILE__) . '/options.php';
            }
            //build theme options
            if (isset($theme_options)) {
                echo '<div id="' . $this->get_field_id('fixed_widget-settings') . '" class="">';
                echo $this->build_options($theme_options);
                echo '</div>';
            }
            echo '<script>
        jQuery(function($) {

        });
        </script>
        ';
            echo '</fieldset></div>';
        }
        /**
         * load option widget title link
         * @param WP_Widget $t: widget object
         * @param array $instance: widget data
         */
        function do_widget_feature($t, $instance = array())
        {
            HW_HOANGWEB::load_class('HW_UI_Component');
            $this->widget_instance = $instance;
            $title = self::get_widget_title($t, $instance);
            $link = $this->get_field_value('link_widget_title');
            //link targets
            $link_targets = array('_blank' => '_blank', '_self' => '_self', '_parent' => '_parent', '_top' => '_top');
            ?>
        <fieldset><legend>Liên kết tiêu đề</legend>
            <!-- hidden fields -->
            <input type="hidden" name="<?php 
            echo $this->get_field_name('title');
            ?>
" id="<?php 
            echo $this->get_field_id('title');
            ?>
" value="<?php 
            echo $title;
            ?>
"/>
            <input type="hidden" name="<?php 
            echo $this->get_field_name('widget_name');
            ?>
" id="<?php 
            echo $this->get_field_id('widget_name');
            ?>
" value="<?php 
            echo $t->id_base;
            ?>
"/>

            <p><em>Chú ý: Đặt tiêu đề widget và nhấn lưu widget một lần nữa sau khi chọn liên kết.</em></p>
        <p>
            <label for="<?php 
            echo $this->get_field_id('link_widget_title');
            ?>
"><strong>Trỏ Liên kết vào tiêu đề</strong></label>
            <input type="text" class="hwawc-hidden" name="<?php 
            echo $this->get_field_name('link_widget_title');
            ?>
" id="<?php 
            echo $this->get_field_id('link_widget_title');
            ?>
" value="<?php 
            echo $link;
            ?>
"/>
        <div>
            <button class="button" id="<?php 
            echo $this->get_field_id('insert-link-btn');
            ?>
">Chọn liên kết</button>
                <span class="link">
                    <?php 
            if ($link) {
                ?>
                        <a href="<?php 
                echo $link;
                ?>
" target="_blank">Mở liên kết</a>
                    <?php 
            }
            ?>
                </span>
        </div>
            <div>
                <label for="<?php 
            $this->get_field_id('target_attr');
            ?>
"><strong>Target</strong></label>
                <?php 
            echo HW_UI_Component::build_select_tag($link_targets, $this->get_field_value('target_attr'), array('name' => $this->get_field_name('target_attr'), 'id' => $this->get_field_id('target_attr')));
            ?>
            </div>

        <script>
            var wpLinkL10n = {"title":"Insert\/edit link","update":"Update","save":"Add Link","noTitle":"(no title)","noMatchesFound":"No matches found."};
            jQuery('#<?php 
            echo $this->get_field_id('insert-link-btn');
            ?>
').on('click', function(event) {
                event.preventDefault();

                hw_awc_open_link_dialog(function(url){console.log(url);
                    jQuery('#<?php 
            echo $this->get_field_id('link_widget_title');
            ?>
').val(url).attr('value',url);

                },'<?php 
            echo $this->get_field_id('link_widget_title');
            ?>
',jQuery(this).next());

                return false;
            });
        </script>
        </p>
        </fieldset>
    <?php 
        }
 /**
  * box sidebar
  */
 echo '<td>';
 echo HW_UI_Component::build_select_tag($sidebars, $current_box, array('name' => $aSkin_field_name . '[box_skin]', 'id' => $post_type . '_box_skin'));
 echo '</td>';
 /**
  * sidebar skins
  */
 echo '<td>';
 $sidebar_skins_data = array();
 $sidebar_skins = HW_AWC_Sidebar_Settings::available_widget_skins();
 foreach ($sidebar_skins as $theme_name => $opt) {
     $sidebar_skins_data[$theme_name] = $opt['title'];
 }
 echo HW_UI_Component::build_select_tag($sidebar_skins_data, $current_box_skin, array('name' => $aSkin_field_name . '[box_widget_skin]', 'id' => $post_type . '_box_widget_skin'));
 echo '</td>';
 /**
  * title
  */
 echo '<td><input type="text" name="' . $aSkin_field_name . '[title]" value="' . (isset($skins[$post_type]['title']) ? $skins[$post_type]['title'] : '') . '"/></td>';
 /**
  * get taxonomies terms assign to post type
  */
 echo '<td>';
 //echo '';
 foreach ($terms as $t) {
     $skin_for_term_field = $aSkin_field_name . '[terms][]';
     $skin_for_term_field_id = 'hwrp_skins_' . $post_type . '_term_' . $t->slug;
     $term_in_list = isset($skins[$post_type]['terms']) && in_array($t->slug, $skins[$post_type]['terms']) ? 'checked="checked"' : '';
     //check term already skin