/**
 * support product module with pagination from woocommerce
 */
function hwoo_filter_pagination_output($html)
{
    if (class_exists('HWPageNavi_Core', false)) {
        HWPageNavi_Core::render_pagination_skin($html);
    }
    return $html;
}
 /**
  * scb init
  */
 public function _hw_pagenavi_plugin_init()
 {
     //if(is_admin()){   //no, i will also use on website, don;t limit in admin screen
     //we use same wp-pagenavi options name called 'pagenavi_options'
     $options = new scbOptions('pagenavi_options', __FILE__, array('hw_skin' => '', 'hw_skin_config' => '', 'hw_skin_condition' => ''));
     // OK
     HWPageNavi_Core::init($options);
     require_once dirname(__FILE__) . '/includes/admin.php';
     // using require() can cause activation errors
     new HWPageNavi_Options_Page(__FILE__, $options);
     //}
 }
 /**
  * render current pagenavi skin
  * @param $html
  */
 public static function render_pagination_skin($html = '')
 {
     //get hoangweb scb options
     $options = HWPageNavi_Core::getOptions()->get();
     //$options = PageNavi_Core::$options->get();    //other way
     if (isset($options['hw_skin']['hwskin_config']) && isset($options['hw_skin']['hash_skin'])) {
         #$skin = HW_SKIN::resume_skin($options['hw_skin']['hwskin_config']);
         $skin = HW_SKIN::resume_hwskin_instance($options['hw_skin']);
         if (!empty($skin)) {
             $file = $skin->instance->get_skin_file($options['hw_skin']['hash_skin']);
             if (file_exists($file)) {
                 $theme_setting = $skin->instance->get_file_skin_setting();
                 //extract theme setting from skin
                 //load theme setting
                 if (file_exists($theme_setting)) {
                     include $theme_setting;
                 }
                 //custom wp_pagenavi output by skin
                 $html = hw_paginav_output($file, $html);
                 //valid theme setting
                 /*if(!isset($theme['styles']) || !is_array($theme['styles'])) $theme['styles'] = array();
                                     if(!isset($theme['scripts']) || !is_array($theme['scripts'])) $theme['scripts'] = array();
                 
                                     if(count($theme['styles']) || count($theme['scripts'])) {
                                         //put css within head tag
                                         $skin->instance->enqueue_files_from_skin($theme['styles'], $theme['scripts']);
                                     }*/
                 $skin_assets = array('skin_file' => $file);
                 if (isset($theme)) {
                     $skin_assets['theme_settings'] = $theme;
                 }
                 HW_SKIN::enqueue_skin_assets(array_merge($skin_assets, (array) $skin));
                 return isset($theme) && is_array($theme) ? $theme : array();
             }
         }
     }
 }
 /**
  * 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.');
     }
 }
 /**
  * render scb hw_skin field type
  * @param $value
  * @param $field
  */
 public function pagination_skin_scb_field($value, $field)
 {
     if (!$this->skin) {
         return;
     }
     //get hoangweb scb options
     $options = HWPageNavi_Core::getOptions()->get();
     //get hw_skin config
     if (empty($options['hw_skin_config'])) {
         $hwskin_config = $this->skin->get_config(true);
     } else {
         $hwskin_config = $options['hw_skin_config'];
     }
     //skin condition
     $skin_condition = isset($options['hw_skin_condition']) ? $options['hw_skin_condition'] : '';
     #$out = $this->skin->get_skins_select_tag('hw_skin',$value,array('name' => "hw_skin[hash_skin]",'class'=>'hw-skin-selector'),false);
     //get skin config
     #$out .= '<input type="hidden" name="hw_skin_config" id="hw_skin_config" value="'.$hwskin_config.'"/>';
     $out = $this->skin->create_total_skin_selector('hw_skin', $value, array(), array('show_main_skin' => 1, 'show_config_field' => 1, 'show_condition_field' => 1, 'show_skin_options' => 1));
     $out .= '<em>' . $field->desc . '</em>';
     return $out;
 }