/**
     * extra fields to any widget
     * @param object $t: widget class object
     * @param $return
     * @param array $instance: widget instance
     */
    public function _hw_awc_in_widget_form($t, $return, $instance)
    {
        /*begin custom sidebar format*/
        static $sw_list;
        if (!$sw_list) {
            $sw_list = get_option('sidebars_widgets');
        }
        //get all widgets
        global $wp_registered_sidebars;
        foreach ($sw_list as $sidebar => $widgets) {
            //get sidebar where widget nested on it
            if (is_array($widgets) && in_array($t->id, $widgets)) {
                //make sure you ignore the key 'array_version'
                $found_sidebar = true;
                break;
            }
        }
        if ($sidebar == 'array_version' || !isset($found_sidebar) || !isset($wp_registered_sidebars[$sidebar])) {
            echo '<div style="background:#fafafa;border:1px solid #dadada;padding:5px;"><p>Nhấn nút Lưu để hiển thị công cụ tùy chỉnh widget này hoặc nếu không thấy thì xóa widget và thêm lại.</p></div>';
            return;
        }
        //first check
        if (isset($wp_registered_sidebars[$sidebar]['old_id'])) {
            $old_sidebar = $wp_registered_sidebars[$sidebar]['old_id'];
        } else {
            $old_sidebar = $sidebar;
        }
        if (!HW_AWC_Sidebar_Settings::check_valid_sidebar_name($old_sidebar)) {
            echo "<div class='hwawc-message'>Do Sidebar cũ có ID ({$old_sidebar}) không hợp lệ, nên tạo mới sidebar với tên: ({$sidebar})";
            echo '<br/>Hiển thị sidebar:<code>dynamic_sidebar("' . $sidebar . '")</code>';
            echo '</div>';
            // return;  //fixed from callback '_hw_awc_init'
        }
        $params = $wp_registered_sidebars[$sidebar];
        //get sidebar param where widget nested on it
        //create feature tog
        if (class_exists('HW_ButtonToggle_widget')) {
            $btn_tog = new HW_ButtonToggle_widget($t, $instance);
        }
        //instance HW_SKIN for widget box title
        $skin = new HW_SKIN($t, HW_AWC_PATH, 'hw_awc_skins', 'hwawc-skin.php', 'skins');
        $skin->plugin_url = HW_AWC_URL;
        $skin->external_callback = false;
        $skin->init();
        //seem no longer use
        ?>
        <?php 
        if (isset($btn_tog)) {
            $btn_tog->set_button_toggle_start_wrapper('Tùy chỉnh widget');
        }
        ?>
        <div style="background:#fafafa;border:1px solid #dadada;padding:5px;">
            <!-- show widget ID on each widget in admin. -->
            <p>
            <div id="<?php 
        echo $t->get_field_id('show_widget_id');
        ?>
" style="padding:5px;background:pink;border:1px solid red;" name="<?php 
        echo $t->get_field_name('show_widget_id');
        ?>
" >
                ID: <strong><?php 
        echo $t->id;
        ?>
</strong><br/>
                <?php 
        if (is_plugin_active('amr-shortcode-any-widget/amr-shortcode-any-widget.php')) {
            echo 'Hiển thị nội dung widget này bởi shortcode:<br/>';
            echo '<code>[do_widget id=' . $t->id . ']</code>';
            echo '<a href="' . HW_AWC_URL . '/docs/amr-shortcode-any-widget.html' . '" target="_blank">Hướng dẫn</a>';
        } else {
            echo hw_install_plugin_link('amr-shortcode-any-widget', 'Nhúng widget này bằng shortcode');
        }
        //display widget content with feature "shortcode_params"
        if (!HW_AWC_WidgetFeatures::check_widget_feature($t, 'shortcode_params') && class_exists('HW_HOANGWEB_Settings')) {
            echo '<p>Kích hoạt feature "<a target="_blank" href="' . admin_url('options-general.php?page=' . HW_HOANGWEB_Settings::HW_SETTINGS_PAGE) . '">Tạo shortcode widget</a>" để hiển thị nội dung của widget này.</p>';
        }
        ?>
            </div>
            </p>
            <!-- widget features -->
            <?php 
        $this->load_widget_features($t, $instance);
        ?>
            <p>

            </p>
            <hr/>
            <!-- sidebar custom after_title & before_title -->
            <?php 
        if (isset($params['before_title'])) {
            ?>

                <p>
                    <label for="<?php 
            echo $t->get_field_id('awc_clear_widget_title');
            ?>
"><strong><?php 
            _e('Xóa tiêu đề widget');
            ?>
</strong></label><br/>
                    <input type="checkbox" name="<?php 
            echo $t->get_field_name('awc_clear_widget_title');
            ?>
" id="<?php 
            echo $t->get_field_id('awc_clear_widget_title');
            ?>
" <?php 
            checked(isset($instance['awc_clear_widget_title']) && $instance['awc_clear_widget_title'] ? 1 : 0);
            ?>
/><?php 
            _e('Xóa before_title & after_title');
            ?>
                    <br/>
                    <span style="font-size:12px">Nếu xóa tiêu đề (xóa before_title & after_title) thì check vào đây. <i>(Tùy chọn này sẽ xóa thẻ HTML có trong before_title & after_title và cả before_widget,after_widget nếu cần thiết để có thể hiển thị tốt widget mà không có title.)</i></span>
                    <br/>

                </p><hr/>

                <p>
                    <label><strong><?php 
            _e('Sửa before_title');
            ?>
</strong></label><br/>
                    <em>Hiện tại: (<font color="blue"><?php 
            echo htmlentities($params['before_title']);
            ?>
</font>)</em><br/>
                    <em><?php 
            if (!preg_match('#%\\d\\$s#', $params['before_title'])) {
                echo '<font color="red">Cảnh báo: before_title chưa sẵn sàng.</font>';
            }
            ?>
</em><br/>
                    <input <?php 
            ?>
 type="text" name="<?php 
            echo $t->get_field_name('format_before_title');
            ?>
" id="<?php 
            echo $t->get_field_id('format_before_title');
            ?>
" value="<?php 
            echo isset($instance['format_before_title']) ? $instance['format_before_title'] : '';
            ?>
"><br/>
                    <span style="font-size:12px"><i>(mỗi ID or chuỗi class ngăn cách bởi '|')</i></span>
                    <br/>
                    <span><em>ie: before_title=>"<?php 
            echo htmlentities('<h2 id="%1$s" class="%2$s" style="%3$s">');
            ?>
"</em></span>
                </p><hr/>
            <?php 
        }
        ?>
            <p>
                <label><strong><?php 
        _e('Sửa after_title');
        ?>
</strong></label><br/>
                <em>Hiện tại: (<font color="blue"><?php 
        echo htmlentities($params['after_title']);
        ?>
</font>)</em><br/>
                <em><?php 
        if (!preg_match('#%\\d\\$s#', $params['after_title'])) {
            echo '<font color="red">Cảnh báo: after_title chưa sẵn sàng.</font>';
        }
        ?>
</em><br/>
                <input <?php 
        ?>
 type="text" name="<?php 
        echo $t->get_field_name('format_after_title');
        ?>
" id="<?php 
        echo $t->get_field_id('format_after_title');
        ?>
" value="<?php 
        echo isset($instance['format_after_title']) ? $instance['format_after_title'] : '';
        ?>
"><br/>
                <span style="font-size:12px"><i>(mỗi ID or chuỗi class ngăn cách bởi '|')</i></span>
                <br/>
                <span><em>ie: after_title=>"<?php 
        echo htmlentities('</h2><div id="%1$s" class="%2$s" style="%3$s">');
        ?>
"</em></span>
            </p><hr/>
            <p>
                <label><strong><?php 
        _e('Sửa before_widget');
        ?>
</strong></label><br/>
                <em>Thêm class theo thứ tự bằng cách chèn tag (*1,*2,..) vào tham số before_widget: <br/>(Hiện tại:<font color="blue"><?php 
        echo htmlentities($params['before_widget']);
        ?>
</font>)</em><br/>
                <em><?php 
        if (!preg_match('#\\*\\d+#', $params['before_widget'])) {
            echo '<font color="red">Cảnh báo: before_widget chưa sẵn sàng.</font>';
        }
        ?>
</em>
                <input type="text" name="<?php 
        echo $t->get_field_name('preclasses_before_widget');
        ?>
" id="<?php 
        echo $t->get_field_id('preclasses_before_widget');
        ?>
" value="<?php 
        echo isset($instance['preclasses_before_widget']) ? $instance['preclasses_before_widget'] : '';
        ?>
"><br/>
                <span style="font-size:12px"><i>(mỗi chuỗi class tương ứng với *1|*2.. ngăn cách bởi '|'. VD: class1 class2|class3 class4 class5)</i></span>
            </p>
            <hr/>
            <p>
                <label for="<?php 
        echo $t->get_field_id('widget_skin');
        ?>
"><strong><?php 
        _e('Giao diện widget');
        ?>
</strong></label>
            <div>
                <select name="<?php 
        echo $t->get_field_name('widget_skin');
        ?>
" id="<?php 
        echo $t->get_field_id('widget_skin');
        ?>
">
                    <?php 
        foreach (HW_AWC_Sidebar_Settings::available_widget_skins() as $name => $field) {
            ?>
                        <option <?php 
            selected(isset($instance['widget_skin']) && $name == $instance['widget_skin'] ? 1 : 0);
            ?>
 value="<?php 
            echo $name;
            ?>
"><?php 
            echo isset($field['title']) ? $field['title'] : $name;
            ?>
</option>
                    <?php 
        }
        ?>
                </select><br/>
                <span>Quản lý skins, nhấn <a target="_blank" href="<?php 
        echo HW_AWC_Sidebar_Settings::get_edit_sidebar_setting_page_link($sidebar);
        ?>
">vào đây</a>.</span>
            </div>
            </p>
            <p>
                <strong>Mầu sắc</strong><br/>
                <em>Lưu ý: TH nếu xóa mầu và khi load lại trang cần xóa lại vì mầu khởi đầu là #FFFFFF.<br/> Nếu không xuất hiện hộp chọn mầu thì tự điền mã mầu và lưu lại để khởi tạo lại trình chọn mã mầu.</em>
            </p>
            <p>
                <input type="text" size="5" class="color {hash:true}" name="<?php 
        echo $t->get_field_name('bgcolor_widget');
        ?>
" id="<?php 
        echo $t->get_field_id('bgcolor_widget');
        ?>
" value="<?php 
        echo isset($instance['bgcolor_widget']) ? $instance['bgcolor_widget'] : '';
        ?>
"/>
                <label for="<?php 
        echo $t->get_field_id('bgcolor_widget');
        ?>
">Mầu nền widget</label>
                <a class="clear-jscolor button" href="javascript:void(0)">Xóa</a>
            </p>
            <p>
                <input type="text" size="5" class="color {hash:true}" name="<?php 
        echo $t->get_field_name('bgcolor_title');
        ?>
" id="<?php 
        echo $t->get_field_id('bgcolor_title');
        ?>
" value="<?php 
        echo isset($instance['bgcolor_title']) ? $instance['bgcolor_title'] : '';
        ?>
"/>
                <label for="<?php 
        echo $t->get_field_id('bgcolor_title');
        ?>
">Mầu nền tiêu đề</label>
                <a class="clear-jscolor button" href="javascript:void(0)" onclick="">Xóa</a>
            </p>
            <p>
                <input type="text" size="5" class="color {hash:true}" name="<?php 
        echo $t->get_field_name('bgcolor_box');
        ?>
" id="<?php 
        echo $t->get_field_id('bgcolor_box');
        ?>
" value="<?php 
        echo isset($instance['bgcolor_box']) ? $instance['bgcolor_box'] : '';
        ?>
"/>
                <label for="<?php 
        echo $t->get_field_id('bgcolor_box');
        ?>
">Mầu nền nội dung</label>
                <a class="clear-jscolor button" href="javascript:void(0)">Xóa</a>
            </p>

            <!-- bg title -->
            <p>
                <label><strong><?php 
        _e('Ảnh nền cho tiêu đề widget');
        ?>
</strong></label>
            <div>
                <?php 
        if (strpos($params['before_title'], '{css_title}') === false) {
            echo '<font color="red">Warning: không tìm thấy {css_title} tag trong tham số <em>before_title</em>. Để sử dụng trường này bạn cần thêm tag này vào tham số <em>before_title</em> cho sidebar hiện tại.</font>';
        }
        ?>
                <?php 
        if (isset($instance['bgimg_title'])) {
            ?>
                    <img class="user-preview-image" style="max-width:100%;" src="<?php 
            echo $instance['bgimg_title'];
            ?>
"><!-- display image -->
                <?php 
        }
        ?>
                <input type="hidden" name="<?php 
        echo $t->get_field_name('bgimg_title');
        ?>
" id="<?php 
        echo $t->get_field_id('bgimg_title');
        ?>
" value="<?php 
        echo isset($instance['bgimg_title']) ? $instance['bgimg_title'] : '';
        ?>
" class="regular-text" /><!-- show image url -->
                <input type='button' class="button-primary" value="Upload" id="<?php 
        echo $t->get_field_id('hw_awc_uploadimage');
        ?>
"/><br /><!-- upload button -->
                <script type="text/javascript">
                    jQuery(function( $ ) {
                        if(typeof hw_awc_btn_upload_image == 'function') {
                            hw_awc_btn_upload_image($( '#<?php 
        echo $t->get_field_id('hw_awc_uploadimage');
        ?>
' ), $( '#<?php 
        echo $t->get_field_id('bgimg_title');
        ?>
' ));
                        }

                    });
                </script>
                <p>

                    <input type="checkbox" name="<?php 
        echo $t->get_field_name('bgimg_title_css');
        ?>
" id="<?php 
        echo $t->get_field_id('bgimg_title_css');
        ?>
" onlick="this.value = this.checked" <?php 
        checked(isset($instance['bgimg_title_css']) ? 1 : 0);
        ?>
/>
                    <label for="<?php 
        echo $t->get_field_id('bgimg_title_css');
        ?>
"><?php 
        _e('Hiển thị ảnh nền cho tiêu đề widget');
        ?>
</label>
                </p>
            </div>
            </p>
            <!-- bg box -->
            <p>
                <label for="<?php 
        echo $t->get_field_id('hw_awc_upload_bgimg_box');
        ?>
"><strong><?php 
        _e('Ảnh nền cho nội dung widget');
        ?>
</strong></label><br/>
                <?php 
        if (strpos($params['after_title'], '{css_box}') === false && strpos($params['before_widget'], '{css_box}') === false) {
            echo '<div><font color="red">Warning: không tìm thấy {css_box} tag trong tham số <em>after_title</em> hoặc <em>before_widget</em>. Để sử dụng trường này bạn cần thêm tag này cho sidebar hiện tại.</font></div>';
        }
        ?>
                <?php 
        if (isset($instance['bgimg_box'])) {
            ?>
                    <img class="user-preview-image" style="max-width:100%;" src="<?php 
            echo $instance['bgimg_box'];
            ?>
"><!-- display image -->
                <?php 
        }
        ?>
                <input type="hidden" name="<?php 
        echo $t->get_field_name('bgimg_box');
        ?>
" id="<?php 
        echo $t->get_field_id('bgimg_box');
        ?>
"
                       value="<?php 
        echo isset($instance['bgimg_box']) ? $instance['bgimg_box'] : '';
        ?>
" class="regular-text" /><!-- show image url -->
                <input type='button' class="button-primary" value="Upload" id="<?php 
        echo $t->get_field_id('hw_awc_upload_bgimg_box');
        ?>
"/><br /><!-- upload button -->
            </p>
            <script type="text/javascript">
                jQuery(function( $ ) {
                    if(typeof hw_awc_btn_upload_image == 'function') {
                        hw_awc_btn_upload_image($( '#<?php 
        echo $t->get_field_id('hw_awc_upload_bgimg_box');
        ?>
' ),$('#<?php 
        echo $t->get_field_id('bgimg_box');
        ?>
'));
                    }

                });
                jQuery(function($){
                    //empty color input
                    var empty_color_input = function(obj){
                        $(obj).attr('value','').css({background:'#fff'});
                        $(obj).empty();
                        //remove color from input
                        //HW_AWC.jscolor_set(obj,'');//wrong it will reset to white color
                    };
                    //init jscolor when ajax response for all input field has 'color' class
                    $('input.color').each(function(i,obj){
                        var color = $(obj).val(),
                            clear_btn = $($(obj).next().next());

                        $(obj).data('clear_btn', clear_btn);
                        //bind clear color button
                        if(!$(obj).data('clear_color_btn')){
                            $(obj).data({
                                clear_color_btn:function(){
                                    empty_color_input(obj);
                                    //remove color from input
                                    //HW_AWC.jscolor_set(obj,'');//wrong it will reset to white color
                                }
                            });
                        }
                        clear_btn.bind('click',$(obj).data('clear_color_btn'));
                        //update color
                        if(color && $(obj).attr('value')){
                            HW_AWC.jscolor_set(obj,color);  //resume color in input tag
                        }
                        else {
                            setTimeout(function(){
                                empty_color_input(obj); //clear default white color
                                $(obj).data('clear_btn').trigger('click');
                            },1000);
                        }

                    });
                });

            </script>
        </div>
        <?php 
        if (isset($btn_tog)) {
            $btn_tog->set_button_toggle_end_wrapper();
        }
        //close feature tog
    }