/** * This is the Widget * @param $args * @param $instance */ public function widget($args, $instance) { global $post; extract($args); // Widget options $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); // Title $this_taxonomy = $instance['taxonomy']; // Taxonomy to show $hierarchical = !empty($instance['hierarchical']) ? '1' : '0'; $showcount = !empty($instance['count']) ? '1' : '0'; $hide_empty = !empty($instance['hide_empty']) ? '1' : '0'; $depth = !empty($instance['depth']) ? $instance['depth'] : 0; //skin $use_skin = !empty($instance['use_skin']) ? 1 : 0; $use_skin_options = !empty($instance['extend_skin_options']) ? 1 : 0; $skin = isset($instance['skin']) ? $instance['skin'] : ''; //saved active hash skin //skin settings $skin_setting = isset($instance['skin_settings']) ? $instance['skin_settings'] : ''; if ($skin) { $skin_setting_file = $this->skin->get_file_skin_setting($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']; } if (isset($default_options) && isset($theme_options)) { $skin_setting = HW_SKIN::merge_skin_options_values($skin_setting, $default_options, $theme_options); } } //widget feature field: 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'); } } $show_option_none = !empty($instance['show_option_none']) ? $instance['show_option_none'] : ''; if (array_key_exists('orderby', $instance)) { $orderby = $instance['orderby']; } else { $orderby = 'count'; } if (array_key_exists('ascdsc', $instance)) { $ascdsc = $instance['ascdsc']; } else { $ascdsc = 'desc'; } if (array_key_exists('exclude', $instance)) { $exclude = join(',', (array) $instance['exclude']); } else { $exclude = ''; } if (array_key_exists('dropdown', $instance)) { $dropdown = $instance['dropdown']; } else { $dropdown = false; } #child of arg if (array_key_exists('childof', $instance)) { $childof = $instance['childof']; } else { $childof = ''; } //get current category/taxonomy if (isset($instance['childof_current_term']) && $instance['childof_current_term'] && (is_category() || is_tax())) { $obj = get_queried_object(); //get current page data $childof = $obj->term_id; //get current term in template } $show_subcat_by_parent = isset($instance['show_subcat_by_parent']) ? (bool) $instance['show_subcat_by_parent'] : false; $categories_by_current_post = isset($instance['categories_by_current_post']) ? (bool) $instance['categories_by_current_post'] : false; $args['skin'] = $skin; $args['skin_setting'] = $skin_setting; $data = array('show_subcat_by_parent' => $show_subcat_by_parent, 'categories_by_current_post' => $categories_by_current_post, 'skin' => $skin, 'skin_setting' => $skin_setting); // Output $tax = $this_taxonomy; if ($dropdown) { $taxonomy_object = get_taxonomy($tax); $args = array('show_option_all' => false, 'show_option_none' => '', 'orderby' => $orderby, 'order' => $ascdsc, 'show_count' => $showcount, 'hide_empty' => $hide_empty, 'child_of' => $childof, 'exclude' => $exclude, 'echo' => 0, 'hierarchical' => $hierarchical, 'name' => $taxonomy_object->query_var, 'id' => 'hwlct-widget-' . $tax, 'depth' => $depth, 'taxonomy' => $tax, 'hide_if_empty' => (bool) $hide_empty, 'walker' => new hwlctwidget_Taxonomy_Dropdown_Walker(), 'mydata' => $data); } else { $args = array('show_option_all' => false, 'orderby' => $orderby, 'order' => $ascdsc, 'style' => 'list', 'show_count' => $showcount, 'hide_empty' => $hide_empty, 'use_desc_for_title' => 1, 'child_of' => $childof, 'exclude' => $exclude, 'hierarchical' => $hierarchical, 'title_li' => '', 'show_option_none' => apply_filters('hwlct_show_option_none', $show_option_none), 'number' => null, 'echo' => 0, 'depth' => $depth, 'taxonomy' => $tax, 'mydata' => $data); $args['walker'] = new hwlctwidget_Taxonomy_Walker($args); } $args = apply_filters('hwlct_wp_list_categories_args', $args, $instance); //filter args if ($use_skin && $this->skin) { //load skin $skin = $this->skin; //$file = $this->skin->get_skin_instance('x')->get_skin_link(empty($instance['skin1'])? 'default':$instance['skin1']); $file = $this->skin->get_skin_file(empty($instance['skin']) ? 'default' : $instance['skin']); if (file_exists($file)) { HW_POST::reset_item_counter(); $terms_data = get_categories($args); //get terms data foreach ($terms_data as $id => &$term) { //wrap with timber $term = new HW_TimberTerm($term->term_id, $term->taxonomy); //class $classes = array('item-box'); if ($awc_enable_grid_posts && isset($awc_grid_posts_cols) && class_exists('HW_POST')) { $classes = HW_POST::get_item_class($awc_grid_posts_cols, $classes); } if (class_exists('HW_POST')) { $term->add_class(HW_POST::item_class($classes, false)); } //term image custom field /*if(function_exists('get_field')) $image = get_field('image',$term); else $image = ''; if(!$image) $image = HW_SKIN::current()->get_skin_url('images/placeholder.png');*/ } //skin template $content = $this->skin->render_skin_template(compact('terms_data', 'tax'), false); if ($content !== false) { echo $content; } //init theme setting $theme['styles'] = array(); //declare stylesheets file $theme['scripts'] = array(); //declare js files if ($this->skin->allow_skin_file()) { include $file; } //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)); } } else { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } if ($dropdown) { echo '<form action="' . get_bloginfo('url') . '" method="get">'; echo apply_filters('hwlct_wp_dropdown_categories', wp_dropdown_categories($args), $args, $instance); echo '<input type="submit" value="go »" /></form>'; } else { echo apply_filters('hwlct_wp_list_categories', wp_list_categories($args), $args, $instance); } echo $after_widget; } if ($use_skin && !class_exists('HW_SKIN')) { echo 'HW_SKIN class không tìm thấy.'; } //notice }
/** * 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 theme option field * @param $aField */ public function renderOptionField($field, $_name, $_id, $values = null, $wrapper = true, $repeat = true) { if (!isset($field['type'])) { $field['type'] = 'text'; } //default set checkbox option //valid field type if (!in_array($field['type'], self::allow_field_types())) { return; } if (!isset($field['name'])) { $field['name'] = ''; //valid field name //return ; //allow type='string' } /*if(!isset($field['id'])) { //set field id attr -> never use $field['id'] = $field['name']; }*/ //filter field setting before render field form $field = apply_filters('renderOptionField', $field); $tag = ''; $name = $_name . '[' . $field['name'] . ']'; //field name $id = $_id . '_' . $field['name']; //field id $title = isset($field['title']) ? $field['title'] : $field['name']; $desc = isset($field['description']) ? $field['description'] : ''; //field value if (!empty($values) && isset($values[$field['name']])) { $value = esc_attr($values[$field['name']]); } else { $value = isset($field['value']) ? esc_attr($field['value']) : ''; //default field value } $field_atts = array('id' => $id, 'name' => $name, 'value' => $value, 'title' => $title, 'desc' => $desc); if ($wrapper) { $tag .= '<p style="margin-bottom:14px;">'; } //check field avaiable it'belong to widget feature if (isset($field['awc_widget_feature']) && is_object($this->widget_ref) && !HW_AWC::check_widget_feature($this->widget_ref, $field['awc_widget_feature'])) { $tag .= '<span>Field (<em>' . $name . '</em>) yêu cầu kích hoạt feature "' . $field['awc_widget_feature'] . '" cho widget này.</span>'; } else { self::build_option_field($field, $field_atts, $tag, array(&$this, 'renderOptionField_callback')); } if ($wrapper) { $tag .= '</p>'; } //repeat the field if ($repeat == true && isset($field['repeat'])) { //repeat current field if (isset($field['repeat']) && is_numeric($field['repeat'])) { for ($i = 1; $i < $field['repeat']; $i++) { //- first repeat field $save_id = $field['name']; $field['name'] .= '_' . $i; $field['title'] = $field['name']; //sync for title $tag .= $this->renderOptionField($field, $_name, $_id, $values, false, false); $field['name'] = $save_id; } } } return $tag; }