/**
  * filter args data
  * @param $args
  * @param $instance: widget instance
  * @return mixed
  */
 public function _hwlct_wp_list_categories_args($args, $instance)
 {
     $skin_setting = isset($instance['skin_settings']) ? $instance['skin_settings'] : '';
     //get current skin settings
     $skin_setting_file = $this->skin->get_file_skin_setting(empty($instance['skin']) ? 'default' : $instance['skin']);
     //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'];
     } else {
         $default_options = array();
     }
     if (isset($default_options) && isset($theme_options)) {
         $skin_setting = HW_SKIN::merge_skin_options_values($skin_setting, $default_options, $theme_options);
     }
     //but note you give space value to 'title_li' like that 'title_li'=' ', then you will get duplicate ul tag around li
     //if(!empty($skin_setting['remove_wrap']) )
     $args['title_li'] = '';
     //remind options
     $args['options'] = $skin_setting;
     //register twig loader
     if (class_exists('HW_Twig_Template')) {
         $this->twig = HW_Twig_Template::create($this->skin->get_file_skin_resource('tpl'));
         #$this->twig = new Twig_Environment($loader);
         $args['twig'] = $this->twig->get();
         //reference twig object
     }
     return $args;
 }
 /**
  * get qtranslate switcher
  */
 public static function get_qtrans_switcher()
 {
     $mqtrans_skin = hw_option('mqtrans_skin');
     //get mqtrans skin
     $other_service = hw_option('enable_googletranslate');
     //use google translate?
     if (isset($mqtrans_skin['hash_skin']) && isset($mqtrans_skin['hwskin_config'])) {
         $skin = APF_hw_skin_Selector_hwskin::resume_hwskin_instance($mqtrans_skin);
         //skin options
         //$skin_options = $mqtrans_skin['skin_options'];
         $html = '';
         //output
         $file = $skin->instance->get_skin_file($skin->hash_skin);
         //load footer template
         if (file_exists($file)) {
             HW_HOANGWEB::load_class('HW_String');
             HW_HOANGWEB::load_class('HW_Twig_Template');
             HW_HOANGWEB::load_class('HW_mqtranslate');
             //get theme setting file
             $setting = $skin->instance->get_file_skin_setting();
             //(new HW_SKIN);
             if (file_exists($setting)) {
                 include $setting;
             }
             //skin options
             $skin_options_file = $skin->instance->get_file_skin_options();
             //(new HW_SKIN)->enqueue_files_from_skin()
             $skin_options = isset($mqtrans_skin['skin_options']) ? $mqtrans_skin['skin_options'] : array();
             //user options
             $skin_options = HW_SKIN::merge_skin_options_values($skin_options, $setting, $skin_options_file);
             $data = array();
             //data send to twig template
             /*active google translate*/
             if ($other_service) {
                 $TranslateElement_opts = array('pageLanguage' => 'vi');
                 //layout
                 $layout = self::get_googletrans_layout_param(isset($skin_options['display_mode']) ? $skin_options['display_mode'] : '');
                 if ($layout) {
                     $TranslateElement_opts['layout'] = $layout;
                 }
                 //include languages
                 if (!empty($skin_options['specific_langs']) && is_array($skin_options['specific_langs'])) {
                     $TranslateElement_opts['includedLanguages'] = join($skin_options['specific_langs'], ',');
                 }
                 $data['google_translate_ID'] = !empty($skin_options['google_translate_ID']) ? $skin_options['google_translate_ID'] : HW_String::generateRandomString();
             } else {
                 //prepare data for template
                 if (class_exists('HW_mqtranslate')) {
                     // make sure use __autoload
                     $data = HW_mqtranslate::generateLanguageSelectCode();
                 }
             }
             //get templates folder from skin
             if (isset($theme) && isset($theme['templates_folder'])) {
                 $tpl = $theme['templates_folder'];
             } else {
                 $tpl = '';
             }
             if (class_exists('HW_Twig_Template')) {
                 $twig = HW_Twig_Template::create($skin->instance->get_file_skin_resource($tpl));
                 if (isset($data)) {
                     $twig->set_template_data($data);
                 }
                 //inject data to current twig for skin using
             }
             ob_start();
             //google translate
             if (isset($TranslateElement_opts)) {
                 $json = HW_SKIN_Option::build_json_options($TranslateElement_opts, null, 'layout');
                 echo '<script type="text/javascript">
                 function googleTranslateElementInit() {
                     new google.translate.TranslateElement(' . $json . ', "' . $data['google_translate_ID'] . '");
                 }
                 </script>
                 ';
             }
             $content = $skin->instance->render_skin_template(compact('wrapper', 'active_langs', 'text'), false);
             //data, return=false
             if ($content !== false) {
                 echo $content;
             }
             if ($skin->instance->allow_skin_file()) {
                 include $file;
             }
             $html = ob_get_contents();
             if ($html && ob_get_length()) {
                 ob_end_clean();
             }
         }
         //valid
         if (!isset($theme['styles'])) {
             $theme['styles'] = array();
         }
         if (!isset($theme['scripts'])) {
             $theme['scripts'] = array();
         }
         //put stuff from skin
         if (count($theme['styles']) || count($theme['scripts'])) {
             $skin->instance->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
         }
         return $html;
     }
 }
 /**
  * display socials icon
  * @param string $skin
  */
 public static function do_social_skin($skin = '')
 {
     //valid
     //if(empty($skin)) $skin = 'default';
     //get option
     $social = hw_option('social_skin');
     if (!isset($social['all_skins'])) {
         printf('<em>Vui lòng nhấn Save changes <a href="%s">ở đây</a> trước khi sử dụng.</em>', admin_url('admin.php?page=hoangweb-theme-options&tab=socials-options'));
         return;
     }
     $data_skins = unserialize(base64_decode($social['all_skins']));
     //get user skin
     if (empty($skin) && isset($social['hash_skin'])) {
         //default user selected skin
         $hash_skin = $social['hash_skin'];
     } elseif ($skin && isset($data_skins[$skin])) {
         //get any skin by name
         $hash_skin = $data_skins[$skin];
     }
     if (!isset($hash_skin)) {
         return;
     }
     //validate
     if ($hash_skin && isset($social['hwskin_config']) && class_exists('APF_hw_skin_Selector_hwskin')) {
         $skin = APF_hw_skin_Selector_hwskin::resume_hwskin_instance($social);
         $file = $skin->instance->get_skin_file($hash_skin);
         //(new HW_SKIN)->get_skin_url('');
         //get theme setting file
         $setting = $skin->instance->get_file_skin_setting();
         if (file_exists($setting)) {
             include $setting;
         }
         //$skin_url = $skin->instance->get_skin_url('');
         $skin_variables = $skin->instance->get_skin_variables();
         if (file_exists($file)) {
             HW_HOANGWEB::load_class('HW_Twig_Template');
             //get templates folder from skin
             if (isset($theme) && isset($theme['templates_folder'])) {
                 $tpl = $theme['templates_folder'];
             } else {
                 $tpl = '';
             }
             //prepare data for template
             $data = array('facebook_url' => hw_option('fb_url'), 'googleplus_url' => hw_option('gplus_url'), 'twitter_url' => hw_option('twitter_url'), 'youtube_url' => hw_option('youtube_url'), 'skin_variables' => $skin_variables, 'SKIN_URL' => $skin_variables['url']);
             $twig = HW_Twig_Template::create($skin->instance->get_file_skin_resource($tpl));
             $twig->set_template_data($data);
             //inject data to current twig for skin using
             $content = $skin->instance->render_skin_template($data, false);
             //data, return=false
             if ($content !== false) {
                 echo $content;
             }
             if ($skin->instance->allow_skin_file()) {
                 include $file;
             }
             //load footer skin configuration
         }
         //valid
         if (!isset($theme['styles'])) {
             $theme['styles'] = array();
         }
         if (!isset($theme['scripts'])) {
             $theme['scripts'] = array();
         }
         //put stuff from skin
         if (count($theme['styles']) || count($theme['scripts'])) {
             $skin->instance->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
         }
     }
 }
 /**
  * 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;
 }
 /**
  * skin data: contain 'hash_skin','hwskin_config'
  * @param $skin_data
  * @param $_callback: callbacks function
  * @param Array $params2callback: send this to callback
  * @param bool $echo decide to return or print out
  */
 public static function apply_skin_data($skin_data = array(), $_callback = null, $params2callback = array(), $echo = true)
 {
     ob_start();
     //current hash skin && skin config
     if (isset($skin_data['hash_skin'])) {
         $hash_skin = $skin_data['hash_skin'];
     }
     if (isset($skin_data['hwskin_config'])) {
         $skin_config = $skin_data['hwskin_config'];
     }
     //HW_SKIN object
     if (!empty($skin_data['instance']) && $skin_data['instance'] instanceof HW_SKIN) {
         $skin = $skin_data['instance'];
     }
     //skin options
     if (!empty($skin_data['skin_options'])) {
         $skin_options = $skin_data['skin_options'];
     } else {
         $skin_options = array();
     }
     if ((!empty($skin_config) || !empty($skin)) && isset($hash_skin)) {
         if (!isset($skin)) {
             $skin = self::resume_skin($skin_config);
         }
         //resume HW_SKIN with given config
         $file = $skin->get_skin_file($hash_skin);
         //main skin file
         //init twig template object
         $hw_tpl = $skin->create_skin_twig();
         $skin_info = $skin->get_skin_info($hash_skin);
         $tpl_file = HW_Twig_Template::twig_asset_exists($skin_info['skin_tpl_path'], $hw_tpl->get());
         if (file_exists($file) || $tpl_file) {
             $skin_data['skin_file'] = $file;
             //save skin file
             //parse callbacks
             if (isset($_callback['callback_before']) && is_callable($_callback['callback_before'])) {
                 $callback_before = $_callback['callback_before'];
             }
             if (isset($_callback['callback_after']) && is_callable($_callback['callback_after'])) {
                 $callback_after = $_callback['callback_after'];
             }
             if (is_callable($_callback)) {
                 //just one callback
                 $callback_after = $_callback;
             }
             //theme setting
             $theme_setting = $skin->get_file_skin_setting();
             if (file_exists($theme_setting)) {
                 include $theme_setting;
             }
             //theme options
             $skin_options_file = $skin->get_file_skin_options();
             $skin_options = HW_SKIN::merge_skin_options_values($skin_options, $theme_setting, $skin_options_file);
             //update data
             $skin_data['skin_options'] = $skin_options;
             if (isset($theme)) {
                 $skin_data['theme_settings'] = $theme;
             }
             if (isset($callback_before)) {
                 $var = 'cb_data_return_' . rand(5, 10);
                 ${$var} = call_user_func($callback_before, array_merge(get_defined_vars(), (array) $params2callback));
                 if (is_array(${$var})) {
                     extract(${$var});
                 }
                 unset(${$var});
             }
             //load both main skin file & twig template
             if ($skin->allow_skin_file() && file_exists($file)) {
                 if (is_array($params2callback)) {
                     extract($params2callback);
                 }
                 include $file;
                 //note add hook does't work if include statement inside a function with 2 level
                 #self::include_skin_file($file);
             }
             if ($skin->allow_skin_tpl() && $tpl_file) {
                 echo $hw_tpl->_render($skin_info['skin_tpl_path'], array_merge($params2callback, $skin_data));
             }
             //$wp_registered_sidebars[$sidebar]['skin'] = $skin;     //bring skin object into params
             if (isset($callback_after)) {
                 $var = 'cb_data_return_' . rand(5, 10);
                 ${$var} = call_user_func($callback_after, array_merge(get_defined_vars(), (array) $params2callback));
                 if (is_array(${$var})) {
                     extract(${$var});
                 }
                 unset(${$var});
             }
             /**
              * enqueue css & js -> depricated
              */
             /*if(!isset($theme['styles'])) $theme['styles'] = array();
                                 if(!isset($theme['scripts'])) $theme['scripts'] = array();
             
                                 if(count($theme['styles']) || count($theme['scripts'])) {
                                     $skin->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
                                 }*/
             self::enqueue_skin_assets($skin_data);
             if (!empty($theme['filters'])) {
                 $skin->do_filters($theme['filters'], array($theme, $skin_options));
             }
         }
     }
     $content = ob_get_contents();
     ob_clean();
     if ($echo) {
         echo $content;
     } else {
         return $content;
     }
 }