/** * get related posts template by current post or specific post ID * @param $post_id: post ID or single post data */ public function get_relatedposts_template_by_post($post_id = '') { if (!empty($post_id) && is_numeric($post_id)) { $post = get_post($post_id); } if (!isset($post)) { global $post; //get current post } if (empty($post)) { return; } //post not found (not single post page) //get post type $post_type = $post->post_type; $skins = hw_yarpp_get_option('hwrp_skins'); if (!isset($skins[$post_type]) || !isset($skins[$post_type]['active'])) { return; //current post not support related posts skin } //get post terms if (!isset($skins[$post_type]['filter_terms']) || !$skins[$post_type]['filter_terms']) { //filter skin with terms $allow_terms = $skins[$post_type]['terms']; if (!HW_POST::check_post_terms($post, $allow_terms, false)) { return; } //not match requirement /*$terms = hwrp_get_all_post_terms($post, array('fields'=> 'slugs')); if(is_array($terms)) foreach($terms as $slug){ if( !in_array($slug,$allow_terms)) return; //not match requirement }*/ } //override template by checking detail term if (class_exists('APF_Related_templates')) { $result = APF_Related_templates::get_relatedposts_template_by_post($post); //from HW_HOANGWEB plugin if (!empty($result['template']['instance'])) { $skins[$post_type]['instance'] = $result['template']['instance']; //change active skin if (isset($result['template']['hash_skin'])) { $skins[$post_type]['skin'] = $result['template']['hash_skin']; } $skins[$post_type]['options_data'] = $result; //detail related data //override if (isset($result['title'])) { $skins[$post_type]['title'] = $result['title']; } //override skin if (isset($result['widget_config'])) { $skins[$post_type]['widget_config'] = $result['widget_config']; } if (isset($result['sidebar'])) { $skins[$post_type]['box_skin'] = $result['sidebar']; } if (isset($result['sidebar_widget_skin'])) { $skins[$post_type]['box_widget_skin'] = $result['sidebar_widget_skin']; } return (object) $skins[$post_type]; } } //get related posts skin for current post if (!isset($skins[$post_type]['instance']) && isset($skins[$post_type]['skin']) && !empty($skins[$post_type]['hwskin_config']) && class_exists('HW_SKIN')) { $skins[$post_type]['instance'] = HW_SKIN::resume_skin($skins[$post_type]['hwskin_config']); //resume hw_skin instance return (object) $skins[$post_type]; } }
/** * get template for current context */ public static function get_current_context_template() { global $post; $taxonomies_template = hw_get_setting(array('my_taxonomy_settings', 'taxonomies_template'), array()); //taxonomy template foreach ($taxonomies_template as $item) { if (!isset($item['enable']) || strtolower($item['enable']) == 'off' || !$item['enable']) { continue; } //taxonomy template if ((is_tax() || is_category()) && (!empty($item['term']) && (is_tax($item['taxonomy'], $item['term']) || is_category($item['term'])) || (empty($item['term']) || $item['term'] == -1))) { $item['found'] = 'taxonomy'; $item['template'] = base64_decode($item['template']); //get real path /*if(file_exists($item['template'])) { $template = $item['template']; } else*/ if (file_exists(locate_template($item['template']))) { $item['template'] = locate_template($item['template']); } //return $item; break; } //single template if (is_single() && (!empty($item['term']) && in_category($item['term'], $post) || $item['term'] == -1)) { $item['found'] = 'single'; $item['single_template'] = base64_decode($item['single_template']); //decode path /*if(file_exists($item['single_template'])) { return $item['single_template']; } else*/ if (file_exists(locate_template($item['single_template']))) { $item['single_template'] = locate_template($item['single_template']); } //return $item; break; } } if (isset($item['found'])) { if (isset($item['loop_template']) && isset($item['loop_template']['hwskin_config'])) { //parse loop template $item['skin'] = HW_SKIN::resume_skin($item['loop_template']['hwskin_config']); } return $item; } }
/** * check you theme exists function bind to this hook 'dynamic_sidebar_params' before use this. * @param array $params: sidebar widgets params */ public function _hw_awc_widget_change_params($params) { global $wp_registered_widgets; global $wp_registered_sidebars; $this_id = $params[0]['id']; // Get the id for the current sidebar we're processing $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[$widget_id]; $widget_opt = get_option($widget_obj['callback'][0]->option_name); $widget_num = $widget_obj['params'][0]['number']; $arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { // Check if the current sidebar has no widgets return $params; // No widgets in this sidebar... bail early. } if (!is_active_sidebar($this_id)) { return $params; } //this sidebar should be actived $current_widget = $widget_opt[$widget_num]; //get current widget //check if this sidebar have any modified from user setting $enable_override_sidebar = HW_AWC_Sidebar_Settings::get_sidebar_setting('enable_override_sidebar', $this_id); //parse settings if (isset($current_widget['bgcolor_widget'])) { $color_widget = self::valid_hex_color($current_widget['bgcolor_widget']); } //callback if (!is_admin()) { $wp_registered_widgets[$widget_id]['original_callback'] = $wp_registered_widgets[$widget_id]['callback']; $wp_registered_widgets[$widget_id]['callback'] = array($this, '_hw_custom_widget_callback_function'); } /** * apply skin for specific widget */ if ($enable_override_sidebar && isset($current_widget['widget_skin'])) { //get widget skin $skin_data = HW_AWC_Sidebar_Settings::get_sidebar_setting($current_widget['widget_skin'], $this_id); if (isset($skin_data['hash_skin'])) { $hash_skin = $skin_data['hash_skin']; } if (isset($skin_data['hwskin_config'])) { $skin_config = $skin_data['hwskin_config']; } if (isset($skin_config) && $skin_config && isset($hash_skin)) { $skin = HW_SKIN::resume_skin($skin_config); //resume HW_SKIN with given config if (method_exists($skin, 'get_skin_file')) { $file = $skin->get_skin_file($hash_skin); } if (isset($file) && file_exists($file)) { $theme = array(); //valid include $file; //don't use include_one or require_once, and don't create function in skin file because will cause duplicate function $wp_registered_sidebars[$this_id]['skin'] = $skin; //bring skin object into params /** * override sidebar param */ if (isset($theme['params']) && is_array($theme['params'])) { $params[0] = array_merge($params[0], $theme['params']); } /** * this snipet from WP Core (wp-includes/widgets.php) - since version 4.0 * Substitute HTML id and class attributes into before_widget */ $classname_ = self::format_widget_sidebar_params($widget_id); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_); /** * 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']); }*/ } } } $params[0] = self::format_sidebar_params($this_id, $params[0], $current_widget); //$params[0] = array_merge($params[0], $new_params); /*clear widget title*/ if (isset($current_widget['awc_clear_widget_title']) && $current_widget['awc_clear_widget_title']) { //clear before_title & after_title $params[0]['before_title'] = ''; $params[0]['after_title'] = ''; //valid HTML combine from before_widget + after_widget $tidyconfig = array('indent' => false, 'show-body-only' => true, 'clean' => false, 'output-xhtml' => true, 'input-xml' => true); $sign_str = '_______'; $html = $params[0]['before_widget'] . $sign_str . $params[0]['after_widget']; $html = HW_String::tidy_cleaning($html, $tidyconfig, 'body'); //hwawc_tidy_cleaning($html,$tidyconfig,'body'); $t = explode($sign_str, $html); if (count($t) == 2) { $params[0]['before_widget'] = $t[0]; //get new before widget $params[0]['after_widget'] = $t[1]; //get new after_widget param } } /** * show widgets with order number */ if ($enable_override_sidebar && HW_AWC_Sidebar_Settings::get_sidebar_setting('alphabe_widgets', $this_id)) { global $hwawc_widget_num; // Global a counter array if (!$hwawc_widget_num) { // If the counter array doesn't exist, create it $hwawc_widget_num = array(); } if (isset($hwawc_widget_num[$this_id])) { // See if the counter array has an entry for this sidebar $hwawc_widget_num[$this_id]++; } else { // If not, create it starting with 1 $hwawc_widget_num[$this_id] = 1; } $class_id = 'widget-' . $hwawc_widget_num[$this_id]; $class = 'class="'; // Add a widget number class for additional styling options //if(!$this->exists_class($class_id, $params[0]['before_widget'])) { $class .= $class_id . ' '; //} if ($hwawc_widget_num[$this_id] == 1) { // If this is the first widget //if(!$this->exists_class('widget-first', $params[0]['before_widget'])) $class .= 'widget-first '; } elseif ($hwawc_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { // If this is the last widget //if(!$this->exists_class('widget-last', $params[0]['before_widget'])) $class .= 'widget-last '; } $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); // Insert our new classes into "before widget" } //finally if ($enable_override_sidebar) { //mark modify before_widget class by adding new class for this plugin to prevent conflict other css in your theme $params[0]['before_widget'] = str_replace('class="', 'class="hw-awc-override ', $params[0]['before_widget']); } return $params; }
/** * resume hw_skin instance from this field type value * moving from `APF_hw_skin_Selector_hwskin` class * @param $apf_hwskin_aValue */ public static function resume_hwskin_instance($apf_hwskin_aValue = array()) { if (!is_array($apf_hwskin_aValue)) { return; } //an array of 2 keys: 'hash_skin', 'hwskin_config' created by this field type $return = array(); //skin metadata $return = array_merge($return, $apf_hwskin_aValue); if (isset($apf_hwskin_aValue['hash_skin'])) { $hash_skin = $apf_hwskin_aValue['hash_skin']; $return['hash_skin'] = $hash_skin; } if (isset($apf_hwskin_aValue['hwskin_config'])) { $skin_config = $apf_hwskin_aValue['hwskin_config']; } if (isset($skin_config) && $skin_config) { $skin = HW_SKIN::resume_skin($skin_config); $return['instance'] = $skin; //$return['skins_data'] = $skin->get_skin_data($hash_skin); //$return['hash_skin'] = $hash_skin; $return['skin_config'] = $skin_config; //i know it nerver in use later } return (object) $return; }