/**
  * main class constructor
  */
 public function __construct()
 {
     if (function_exists('hwawc_get_all_widgets')) {
         $this->registered_widgets = hwawc_get_all_widgets();
     }
     if (class_exists('HW_AWC_WidgetFeatures')) {
         $this->registered_features = HW_AWC_WidgetFeatures::get_all_features();
     } else {
         $this->msgs[] = 'Không tìm thấy HW Any Widget class plugin.';
     }
 }
 /**
  * setup form fields
  */
 public function setUp()
 {
     $this->setRootMenuPage('(H) Widgets', HW_HOANGWEB_URL . '/images/ie-gear-icon.png');
     // Add the sub menus and the pages/ addSubMenuItems
     $this->addSubMenuItem(array('title' => 'Tính năng Widgets', 'page_slug' => self::PAGE_SLUG));
     //define tabs, for main tab
     $this->addInPageTabs(self::PAGE_SLUG, array('tab_slug' => 'general', 'title' => __('Tổng quan')));
     $register_features = HW_AWC_WidgetFeatures::get_all_features();
     foreach (HW_AWC_WidgetFeatures::get_features_data() as $name => $widgets) {
         foreach ($widgets as $id => $widget) {
             $feature = $widget['class'];
             //widget feature object
             if ($feature && $feature->_get_option('enable_tab_settings')) {
                 $this->addInPageTab(array('tab_slug' => $name, 'title' => $register_features[$name]));
                 // load + page slug + tab slug
                 add_action('load_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, '_replyToAddFormElements'));
                 //triggered before rendering the page.
                 add_action('do_before_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, 'do_before_tab_hook'));
                 // triggered in the middle of rendering the page.
                 add_action('do_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, 'do_tab_hook'));
                 //triggered after rendering the page
                 add_action('do_after_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, 'do_after_tab_hook'));
                 //receives the output of the middle part of the page including form input fields.
                 add_filter('content_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, 'content_tab_filter'));
                 //receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.
                 add_filter('validation_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($feature, '_validation_tab_filter'));
             }
             break;
             //use same setting  tab for all of widget that own this feature
         }
     }
     //get all features
     /*foreach(HW_AWC_WidgetFeatures::get_all_features() as $feature => $item){
     
             }*/
     $this->setInPageTabTag('h3');
     // sets the tag used for in-page tabs
 }
 /**
  * register widget fields feature
  * @param $widget: widget instance
  * @param $feature: give feature name by hoangweb
  */
 public static function register_widget_feature($widget, $feature)
 {
     if (!isset(self::$widgets_fields[$feature])) {
         self::$widgets_fields[$feature] = array();
     }
     $register_features = HW_AWC_WidgetFeatures::get_all_features();
     //get all register features
     //load widget feature from enternal
     $class = self::get_feature_class_byName($feature);
     //'AWC_WidgetFeature_' . $feature;
     if (class_exists($class)) {
         $class = new $class($widget, array());
         $class->feature_name = $feature;
         //widget feature identifier
         $class->feature_url = HW_AWC_WidgetFeatures_URL . '/' . $feature;
         $class->feature_path = HW_AWC_WidgetFeatures_PATH . '/' . $feature;
         $class->option('feature_alias', $register_features[$feature]);
         //set static options
         $class->_static_option('feature_name', $class->feature_name);
         $class->_static_option('feature_url', $class->feature_url);
         $class->_static_option('feature_path', $class->feature_path);
         $class->feature_loaded();
         //add widget feature to manager
         HW_Widget_Features_Setting::add_widget_feature($feature, $class);
         self::_setup_actions($class);
     }
     //prevent to duplicate widgets in one feature ($widget->id_base)
     self::$widgets_fields[$feature][$widget->id_base . '-' . $widget->number] = array('widget' => $widget, 'class' => $class);
 }
 /**
  * custom widget callback
  */
 public function _hw_custom_widget_callback_function()
 {
     global $wp_registered_widgets;
     $original_callback_params = func_get_args();
     $widget_id = $original_callback_params[0]['widget_id'];
     $widget_obj = $wp_registered_widgets[$widget_id];
     $original_callback = $widget_obj['original_callback'];
     $wp_registered_widgets[$widget_id]['callback'] = $original_callback;
     //widget object
     $widget = $widget_obj['original_callback'][0];
     $widget_opt = get_option($widget_obj['original_callback'][0]->option_name);
     $widget_num = $widget_obj['params'][0]['number'];
     $instance = $widget_opt[$widget_num];
     //get current widget instance
     $widget_id_base = $wp_registered_widgets[$widget_id]['callback'][0]->id_base;
     //do widget features
     #$features = array('fixed_widget');
     /*$feature = HW_AWC::get_widget_feature($widget, 'fancybox');
       if($feature && HW_AWC::check_widget_feature($widget, 'fancybox') && $feature->is_active($instance) ) {
           if(method_exists($feature, 'do_widget_feature_frontend')) {
               $feature->do_widget_feature_frontend($widget, $instance);
           }
       }*/
     $all_features = HW_AWC_WidgetFeatures::get_all_features();
     $widgets_fields = HW_AWC_WidgetFeatures::get_features_data();
     foreach ($all_features as $name => $text) {
         if (isset($widgets_fields[$name]) && is_array($widgets_fields[$name])) {
             foreach ($widgets_fields[$name] as $widg) {
                 if ($widget == $widg['widget'] || $widg['widget']->id_base == $widget->id_base && $widg['widget']->number == $widget->number) {
                     $feature = $widg['class'];
                     $active = true;
                     if (method_exists($feature, 'is_active')) {
                         //check active widget feature
                         $active = $feature->is_active($instance);
                     }
                     if ($active && method_exists($feature, 'do_widget_feature_frontend')) {
                         $feature->do_widget_feature_frontend($widget, $instance);
                     }
                 }
             }
         }
     }
     if (is_callable($original_callback)) {
         ob_start();
         call_user_func_array($original_callback, $original_callback_params);
         $widget_output = ob_get_clean();
         echo apply_filters('hw_widget_output', $widget_output, $widget_id_base, $widget_id);
     }
 }