/**
  * if this callback of the hook that mean you not link specific menu to wp_nav_menu
  * @hook filter 'wp_nav_menu_args'
  * @param $args
  */
 public function _modify_nav_menu_args($args)
 {
     //get current menu name
     $menu = self::get_menu_name($args);
     /**
      * get menu skin
      * first entry for through out menu filters
      */
     $skin = HW_NavMenu_Metabox_settings::get_menu_setting('skin', $menu);
     $enable_skin = HW_NavMenu_Metabox_settings::get_menu_setting('enable_skin', $menu);
     $enable_filter_menu = HW_NavMenu_Metabox_settings::get_menu_setting('enable_filter_menu', $menu);
     //add other menu setting to menu args
     $addition_menu_args = array('show_searchbox', 'remove_ul_wrap', 'only_anchor_tag_nav_menu', 'show_home_menu', 'allow_tags_nav_menu', 'show_icon');
     foreach ($addition_menu_args as $option) {
         $args[$option] = HW_NavMenu_Metabox_settings::get_menu_setting($option, $menu);
     }
     if ($enable_filter_menu && $enable_skin && $skin) {
         //parse SKIN object
         $this->skin = APF_hw_skin_Selector_hwskin::resume_hwskin_instance($skin);
         //parse into HW_SKIN object & saved as property
         $this->skin->file = $this->skin->instance->get_skin_file($this->skin->hash_skin);
         $options_config = $this->skin->instance->get_file_skin_options($this->skin->hash_skin);
         //theme options configuration
         $theme_setting = $this->skin->instance->get_file_skin_setting();
         //theme setting file
         //register twig loader
         if (class_exists('HW_Twig_Template')) {
             //Twig_Autoloader::register();
             //$loader = new Twig_Loader_Filesystem($this->skin->instance->get_file_skin_resource('tpl'));
             $this->twig = HW_Twig_Template::create($this->skin->instance->get_file_skin_resource('tpl'));
             #$this->twig = new Twig_Environment($loader);
             $args['twig'] = $this->twig->get();
             //reference twig object
         }
         if (file_exists($this->skin->file)) {
             $theme = array();
             $theme['styles'] = array();
             //init
             $theme['scripts'] = array();
             $theme['filters'] = array();
             //allow filters
             //keep this info (ex: menu) with filter that bind to callback to compare from current filter args
             $theme['menu'] = $menu;
             $user_options = array();
             //skin options
             if (file_exists($theme_setting)) {
                 include $theme_setting;
             }
             //theme setting
             if (file_exists($options_config)) {
                 include $options_config;
             }
             //options file
             if (isset($theme_options)) {
                 //$theme_options variable already exists in skin options
                 //$skin_options_config = hwskin_parse_theme_options($theme_options);
                 //get addition skin options value
                 $skin_options = isset($skin['skin_options']) ? $skin['skin_options'] : array();
                 if (empty($skin_options)) {
                     $skin_options = array();
                 }
                 //please go menu setting page & press on save button
                 $exclude_options = array('menu');
                 foreach ($exclude_options as $opt) {
                     if (isset($skin_options[$opt])) {
                         unset($skin_options[$opt]);
                     }
                 }
                 $user_options = HW_SKIN::get_skin_options($skin_options, $theme['args'], $theme_options);
                 $args = array_merge($args, $user_options);
                 //sync skin options with $args
                 //hope $args share to all remain menu filters in order to render final output menu to user
                 /*foreach($skin_options as $arg => $value){
                       $field_setting = $skin_options_config[$arg];
                       if(!isset($args[$arg])) $args[$arg] = '';   //set menu args from skin
                       //append if exists setting
                       if(isset($field_setting['method']) && $field_setting['method'] == 'append' && !empty($value)){
                           if(!in_array($value, preg_split('#[\s]+#',$args[$arg]))){
                               $args[$arg] .= (!empty($args[$arg])? ' ':'').trim($value);
                           }
                       }
                       //override setting if not exists
                       if(isset($field_setting['method']) && $field_setting['method'] == 'override' && !empty($value)){
                           $args[$arg] = $value;
                       }
                   }*/
             }
             //make sure have no ouput at here
             HW_SKIN::include_skin_file($this->skin->file);
             //extract wp_nav_menu_args from skin file
             /*if(isset($theme['args']) && is_array($theme['args'])){
                   //$args = array_merge($args, $theme['args']);
                   foreach($theme['args'] as $arg => $val){
                       if(isset($args[$arg])) $args[$arg] .= (!empty($args[$arg])? ' ':'').$val;     //append
                       else $args[$arg] = $val;    //create if not exists
                   }
               }*/
             $this->skin->instance->do_filters($theme['filters'], array($theme, $user_options));
             //do filters & actions that defined in skin
             //$this->skin->instance->enqueue_files_from_skin(null/*$theme['styles']*/, $theme['scripts']);    //put stuff from skin (note: css enqueue before)
             //new way for enqueue stuff from skin
             HW_SKIN::enqueue_skin_assets(array('instance' => $this->skin->instance, 'hash_skin' => $this->skin->hash_skin, 'skin_file' => $this->skin->file, 'theme_settings' => $theme, 'theme_options' => $args));
             //languages selector on the website
             $show_langs_switcher = HW_NavMenu_Metabox_settings::get_menu_setting('show_langs_switcher', $menu);
             //show search form in nav menu
             if ($show_langs_switcher) {
                 //get langs switcher output
                 $args['langs_switcher'] = hw_get_qtrans_switcher();
             }
             #$args = array_merge($args, $skin_options); //filtered values in above
             //if(isset($args['show_items_separator'])) ;
         }
         $args['walker'] = new HW_Nav_Menu_Walker();
     }
     $this->menu_args = (object) $args;
     //save current menu args
     /*if( 'primary' == $args['theme_location'] )
             {
                 $args['depth'] = -1;
                 $args['container_id'] = 'my_primary_menu';
             }
             if('menu1' == $args['menu']){    #maybe old wp version
                 $args['walker'] = new custom_walker();
             }
             //for custom menu widget
             if(isset($args['menu']) && isset($args['menu']->name) && $args['menu']->name == 'menu-header')
             {
     
             }*/
     return $args;
 }
 /**
  * load widget template
  * @param array $instance: widget instance (optional)	 
  * @param array $data: array of data need to be extract to current context
  */
 private function load_widget_template(&$instance = array(), $data = array())
 {
     //extract data
     if (isset($this->shared) && is_array($this->shared)) {
         extract($this->shared);
     } else {
         if (is_array($data)) {
             extract($data);
         }
     }
     //extract variables from array $args that get from 'widget' method
     if (isset($args)) {
         extract($args);
     }
     if (!is_array($instance) || !count($instance)) {
         $instance = $this->hw_parse_data();
         $instance = $instance['instance'];
     } else {
         $this->get_widget_instance($instance);
     }
     //by hoangweb.com
     if ($this->skin) {
         //load skin
         $file = $this->skin->get_skin_file(empty($instance['skin']) ? 'default' : $instance['skin']);
         if (file_exists($file)) {
             /**
              * pagination skin
              */
             $paginav = $this->skin->get_skin_instance('pagination')->get_skin_file(empty($instance['pagination_skin']) ? 'default' : $instance['pagination_skin']);
             //skin settings
             /*
             $paginav_skin_setting = isset($instance['skin_setting'])? $instance['skin_setting'] : '';
             
             $skin_setting_file = $this->skin->get_file_skin_setting(); //current skin setting
             $skin_options = $this->skin->get_file_skin_options();      //current skin options
             
             if(file_exists($skin_setting_file)) include ($skin_setting_file);
             if(file_exists($skin_options)) include ($skin_options);
             
             if(isset($theme) && isset($theme['options'])) $default_options = $theme['options'];
             if(isset($default_options) && isset($theme_options)) {
                 $paginav_skin_setting = HW_SKIN::merge_skin_options_values($paginav_skin_setting, $default_options, $theme_options);
             }
             */
             /**
              * scrollbar skin
              */
             $scrollbar = $this->skin->get_skin_instance('scrollbar')->get_skin_file(empty($instance['scrollbar_skin']) ? 'default' : $instance['scrollbar_skin']);
             //widget feature: grid_posts
             $grid_posts = HW_AWC::get_widget_feature($this, 'grid_posts');
             $awc_enable_grid_posts = false;
             //disable by default
             if ($grid_posts && HW_AWC::check_widget_feature($this, 'grid_posts')) {
                 $awc_enable_grid_posts = $grid_posts->is_active($instance);
                 if ($awc_enable_grid_posts) {
                     $awc_grid_posts_cols = $grid_posts->get_field_value('awc_grid_posts_cols');
                 }
             }
             /**
              * init some variables
              */
             $theme = array();
             //declare stylesheets file
             //content wrapper ID
             $hwtpl_wrapper_id = $this->get_holder_id($instance['widget_id']);
             $hwtpl_scrollbar_wrapper_class = '';
             //scrollbar content wrapper css class
             $hwtpl_pagination_class = '';
             //for pagination
             /**
              * load pagination component
              */
             if (file_exists($paginav)) {
                 include $paginav;
                 //valid
                 if (!isset($theme['scripts'])) {
                     $theme['scripts'] = array();
                 }
                 if (!isset($theme['styles'])) {
                     $theme['styles'] = array();
                 }
                 //migrate skin from pagination module
                 if ($instance['use_default_pagenav_skin'] && hw_is_active_module('pagination')) {
                     $theme = HWPageNavi_Core::render_pagination_skin();
                 } elseif (count($theme['styles']) || count($theme['scripts'])) {
                     $this->skin->get_skin_instance('pagination')->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
                     //enqueue stuff from skin
                     /*HW_SKIN::enqueue_skin_assets(array(
                           'instance' => $this->skin,
                           'hash_skin' => $instance['skin'],
                           'skin_file' => $file,
                           'skin_settings' => $theme,
                           'skin_options' => $skin_setting
                       ));*/
                 }
                 //parse template tags
                 $hwtpl_pagination_class = isset($theme['pagination_class']) ? $theme['pagination_class'] : '';
                 $this->share_data('pagination', $theme);
             }
             //_print($this->skin->get_active_skin()); //enqueue stuff from skin
             /**
              * load scrollbar component
              */
             if (isset($instance['enable_scrollbar']) && $instance['enable_scrollbar'] && file_exists($scrollbar)) {
                 //load skin resource
                 $scrollbar_options_config = $this->skin->get_skin_instance('scrollbar')->get_file_skin_options(empty($instance['scrollbar_skin']) ? 'default' : $instance['scrollbar_skin']);
                 //theme options configuration
                 $scrollbar_theme_setting = $this->skin->get_skin_instance('scrollbar')->get_file_skin_setting();
                 //load theme-setting.php
                 //theme options
                 $scrollbar_theme_options = isset($instance['scrollbar_skin_setting']) ? $instance['scrollbar_skin_setting'] : array();
                 //scrollbar skin options
                 //reset
                 $theme['styles'] = array();
                 //declare stylesheets file
                 $theme['scripts'] = array();
                 //declare js files
                 $theme['options'] = array();
                 if (!empty($scrollbar_options_config) && file_exists($scrollbar_options_config)) {
                     include $scrollbar_options_config;
                     //include define scrollbar theme options
                 }
                 if (!empty($scrollbar_theme_setting) && file_exists($scrollbar_theme_setting)) {
                     include $scrollbar_theme_setting;
                     //scrollbar theme setting
                 }
                 if (isset($theme_options) && isset($theme)) {
                     $default = isset($theme['options']) ? $theme['options'] : array();
                     $result = HW_SKIN::get_skin_options($scrollbar_theme_options, $default, $theme_options);
                     $scrollbar_theme_options = array_merge($scrollbar_theme_options, $result);
                 }
                 /*
                 //best way but use old way as above do
                 $scrollbar_skin_setting = isset($instance['scrollbar_skin_setting'])? $instance['scrollbar_skin_setting'] : '';
                 
                                    $scrollbarskin_setting_file = $this->skin->get_skin_instance('scrollbar')->get_file_skin_setting(); //current skin setting
                                    $scrollbar_skin_options = $this->skin->get_skin_instance('scrollbar')->get_file_skin_options();      //current skin options
                 
                                    if(file_exists($scrollbarskin_setting_file)) include ($scrollbarskin_setting_file);
                                    if(file_exists($scrollbar_skin_options)) include ($scrollbar_skin_options);
                 
                                    if(isset($theme) && isset($theme['options'])) $scrollbar_default_options = $theme['options'];
                                    if(isset($scrollbar_default_options) && isset($theme_options)) {
                 $scrollbar_skin_setting = HW_SKIN::merge_skin_options_values($scrollbar_skin_setting, $scrollbar_default_options, $theme_options);
                                    }
                 */
                 //parse template tags
                 $hwtpl_scrollbar_wrapper_class = isset($theme['scrollbar_css']) ? $theme['scrollbar_css'] : '';
                 include $scrollbar;
                 //valid
                 /*if(!isset($theme['scripts'])) $theme['scripts'] = array();
                                        if(!isset($theme['styles'])) $theme['styles'] = array();
                 
                                        if(count($theme['styles']) || count($theme['scripts'])) {
                                            $this->skin->get_skin_instance('scrollbar')->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
                                        }*/
                 //enqueue stuff from skin
                 HW_SKIN::enqueue_skin_assets(array('instance' => $this->skin->get_skin_instance('scrollbar'), 'hash_skin' => $instance['scrollbar_skin'], 'skin_file' => $scrollbar, 'skin_settings' => $theme, 'skin_options' => $scrollbar_theme_options));
                 $this->init_scrollbar_options($scrollbar_theme_options, $theme);
             }
             /**
              * load main skin
              */
             $options_config = $this->skin->get_file_skin_options();
             $skin_setting = $this->skin->get_file_skin_setting();
             if (file_exists($skin_setting)) {
                 include $skin_setting;
             }
             //theme options
             $skin_options = isset($instance['skin_setting']) ? $instance['skin_setting'] : array();
             $skin_options = HW_SKIN::merge_skin_options_values($skin_options, $skin_setting, $options_config);
             //params
             if (empty($instance['intermediate_image_sizes']) && !empty($instance['thumb_w']) && !empty($instance['thumb_h'])) {
                 $image_size = array($instance['thumb_w'], $instance['thumb_h']);
             } elseif (!empty($instance['intermediate_image_sizes'])) {
                 $image_size = $instance['intermediate_image_sizes'];
             } else {
                 $image_size = 'thumbnail';
             }
             //reset
             $theme['styles'] = array();
             //declare stylesheets file
             $theme['scripts'] = array();
             //declare js files
             $theme['options'] = array();
             //refresh theme options
             //widget features
             $wfeatures = $this->init_widget_features(array('theme' => $theme, 'skin_options' => $skin_options, 'instance' => $instance));
             //render skin template power by twig
             $data = array('hwtpl_scrollbar_wrapper_class', 'cat_posts', 'full_image_src', 'fancy_group', 'fancybox_g1', 'arrExlpodeFields', 'image_size', 'wfeatures', 'hwtpl_wrapper_id', 'args', 'instance', 'open_title_link', 'close_title_link');
             $data = compact($data);
             $data['context'] = $this;
             //reference to this object
             $content = $this->skin->render_skin_template($data, false);
             if ($content !== false) {
                 echo $content;
             }
             include $file;
             //valid
             /*if(!isset($theme['scripts'])) $theme['scripts'] = array();
                                if(!isset($theme['styles'])) $theme['styles'] = array();
             
                                if(count($theme['styles']) || count($theme['scripts'])) {
                                    $this->skin->enqueue_files_from_skin($theme['styles'], $theme['scripts']); //enqueue stuff from skin
                                }*/
             //enqueue stuff from skin
             HW_SKIN::enqueue_skin_assets(array('instance' => $this->skin, 'hash_skin' => $instance['skin'], 'skin_file' => $file, 'skin_settings' => $theme, 'skin_options' => $skin_options));
             //init scrolling
             //add_action('wp_footer',array(&$this, 'init_content_options'),1000);	//don't use wp hook to setup scroll
             $this->init_content_options(array('theme' => $theme, 'skin_options' => $skin_options, 'instance' => $instance));
         }
     } else {
         echo __('not found class HW_SKIN.');
     }
 }
 /**
  * merge skin option values
  * @param array $user_theme_options user skin options data
  * @param array $default  default option define at theme-setting.php
  * @param array $theme_options options file (options.php) in current skin folder
  */
 public static function merge_skin_options_values($user_theme_options, $default, $_theme_options)
 {
     //parse default skin options from skin setting file (theme-setting.php)
     if (is_string($default) && !empty($default) && file_exists($default)) {
         include $default;
         if (isset($theme) && is_array($theme) && isset($theme['options'])) {
             $default = $theme['options'];
         }
     }
     //include theme options (options.php)
     if (is_string($_theme_options) && file_exists($_theme_options)) {
         include $_theme_options;
     }
     //valid
     if (!is_array($default)) {
         $default = array();
     }
     if (isset($theme_options) && !is_array($theme_options)) {
         $theme_options = array();
     }
     //- note that: skin options value either set in options file or skin file or both. But get options from theme setting for default.
     //merge skin options with persistent options in skin theme setting file:
     if (isset($theme_options)) {
         //$default = isset($theme['options']) ? $theme['options'] : array();
         $result = HW_SKIN::get_skin_options($user_theme_options, $default, $theme_options);
         $user_theme_options = array_merge($user_theme_options, $result);
     }
     //valid data, here is example of removing unused key
     if (isset($user_theme_options['template_file'])) {
         unset($user_theme_options['template_file']);
     }
     return $user_theme_options;
 }