/** * @param array $tab_info * @param array $options */ public function __construct($tab_info = array(), $options = array()) { parent::__construct($tab_info, $options); //valid if (!is_array($options)) { $options = array(); } if (!is_array($tab_info)) { $tab_info = array(); } if (empty($tab_container)) { $tab_container = HW_String::generateRandomString(); } $default_options = array('animate' => false, 'animationSpeed' => '1000', 'updateHash' => false); //easytabs options $this->set_options(array_merge($default_options, $options)); //params $params = array('container_id' => 'hw-tabs-container', 'container_class' => $tab_container, 'tabs_menu_class' => 'tabs_menu_class', 'current_tab_class' => '', 'tab_content_class' => ''); if (class_exists('HW_Module_Tabs') && HW_Module_Tabs::is_active()) { $setting = HW_Module_Tabs::get(); $params['container_id'] = $setting->get_field_value('container_id', 'hw-tabs-container'); $params['tabs_menu_class'] = $setting->get_field_value('tabs_menu_class'); $params['current_tab_class'] = $setting->get_field_value('current_tab_class'); $params['tab_content_class'] = $setting->get_field_value('tab_content_class'); } $this->set_params($tab_info, $params); /*$this->info['container_id'] = $tab_container; $this->info['tabs_menu_class'] = $tab_container;*/ }
/** * render map * @param $atts */ public function render_googlemap($atts = array()) { HW_HOANGWEB::load_class('HW_String'); $module = $this->_option('module'); $id = HW_String::generateRandomString(); //options $width = HW_Validation::format_unit(isset($atts['width']) ? $atts['width'] : ($module ? $module->get_field_value('width') : '')); $height = HW_Validation::format_unit(isset($atts['height']) ? $atts['height'] : ($module ? $module->get_field_value('height') : '')); $show_searchbox = isset($atts['show_searchbox']) ? (int) $atts['show_searchbox'] : ($module ? $module->get_field_value('show_searchbox') : ''); if (!empty($atts['location'])) { $location = $atts['location']; if (is_array($location)) { $location = json_encode($location); } } elseif (!empty($atts['address'])) { $location = '"' . $atts['address'] . '"'; } else { $location = '""'; } #$atts['location'] = isset($atts['location'])? HW_Gmap::getLocationFromAddress($atts['location']) : array(); #$location_json = json_encode($atts['location']); $input_box_id = 'pac-input-' . $id; //input box search location $map_canvas_id = 'map-canvas-' . $id; //map canvas $out = '<div class="hw-module-map-container">'; if ($show_searchbox) { $out .= '<input id="' . $input_box_id . '" class="controls hw-pac-input" type="text" placeholder="Tìm kiếm">'; } $out .= '<div id="' . $map_canvas_id . '" class="hw-map-canvas"></div>'; $out .= ' <style> .hw-map-canvas{ ' . ($width ? "width:{$width};" : '') . ' ' . ($height ? "height:{$height};" : '') . ' } </style> <script> jQuery(function($){ google.maps.event.addDomListener(window, "load", function(){ __hw_module_map.map_initialize("#' . $map_canvas_id . '","#' . $input_box_id . '",' . $location . '); }); }); </script> '; $out .= '</div>'; return $out; }
/** * construct method * @param $args * @param $options */ public function __construct($args = array(), $options = array()) { parent::__construct($args, $options); //load cloudzoom lib HW_Libraries::enqueue_jquery_libs('cloudzoom'); $this->cloudzoom_id = HW_String::generateRandomString(); //valid if (!is_array($args)) { $args = array(); } //params $default_params = array('images_from_current_post' => '0', 'zoombig_width' => '300px', 'zoombig_height' => '', 'container_id' => 'cloudzoom-container', 'container_class' => '', 'thumb_anchor_class' => 'cloudzoom-thumb-anchor-class', 'thumb_img_class' => 'cloudzoom-thumb-img-class', 'smallthumb_container_class' => 'cloudzoom-smallthumb-container', 'smallthumb_class' => 'cloudzoom-smallthumb-class', 'smallthumb_item_class' => 'cloudzoom-smallthumb-item-class', 'smallthumb_anchor_class' => 'cloudzoom-smallthumb-anchor-class', 'smallthumb_img_class' => 'cloudzoom-smallthumb-img-class'); if (class_exists('HW_Module_Cloudzoom') && HW_Module_Cloudzoom::is_active()) { $setting = HW_Module_Cloudzoom::get(); $params['images_from_current_post'] = $setting->get_field_value('images_from_current_post'); $params['zoombig_width'] = $setting->get_field_value('zoombig_width'); $params['zoombig_height'] = $setting->get_field_value('zoombig_height'); $params['container_id'] = $setting->get_field_value('container_id'); $params['container_class'] = $setting->get_field_value('container_class'); $params['thumb_anchor_class'] = $setting->get_field_value('thumb_anchor_class'); $params['thumb_img_class'] = $setting->get_field_value('thumb_img_class'); $params['smallthumb_container_class'] = $setting->get_field_value('smallthumb_container_class'); $params['smallthumb_class'] = $setting->get_field_value('smallthumb_class'); $params['smallthumb_item_class'] = $setting->get_field_value('smallthumb_item_class'); $params['smallthumb_anchor_class'] = $setting->get_field_value('smallthumb_anchor_class'); $params['smallthumb_img_class'] = $setting->get_field_value('smallthumb_img_class'); } $this->set_params($default_params); if (is_array($args)) { $this->set_params($args); } //cloud options if (is_array($options)) { $this->set_options($options); } }
/** * implement widget features * @param array $args */ public function init_widget_features($args = array()) { extract($args); if (!isset($instance)) { $instance = $this->get_widget_instance(); } $features = array(); //widget feature fancybox $fancybox = HW_AWC::get_widget_feature($this, 'fancybox'); if ($fancybox && HW_AWC::check_widget_feature($this, 'fancybox') && $fancybox->is_active($instance) && isset($skin_options)) { $features['fancybox'] = array('object' => $fancybox, 'data' => array()); if (!empty($skin_options['fancybox_images_group'])) { $fancybox_group = $skin_options['fancybox_images_group']; $fancybox_group_rel = base64_encode($fancybox_group); } else { $fancybox_group = HW_String::generateRandomString(); $fancybox_group_rel = HW_String::generateRandomString(); } $fancybox->run('.' . preg_replace('#^[\\s\\.]#', '', $fancybox_group)); $features['fancybox']['data'] = (object) array('fancybox_group' => $fancybox_group, 'fancybox_group_rel' => $fancybox_group_rel); } return $features; }
/** * return all widgets links data or for specific widget * @param string $title: get widget link field by title (optional) * @return mixed|void */ public static function get_all_widget_links($title = '') { static $widget_links; if (!$widget_links) { $widget_links = get_option('hwawc_widget_title_links', array()); } if ($title) { $san_title = sanitize_title(strtolower(HW_String::vn_str_filter($title))); return isset($widget_links[$san_title]) ? $widget_links[$san_title] : ''; } return $widget_links; }
/** * 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; } }
/** * get params * extend from HW_XML::xml2array * @param $dom start from this dom * @return SimpleXMLElement[] */ public function extract_params($dom = null) { #if(empty($this->xml)) return; $data = array(); //if(!is_object($dom) && isset($this->xml->params)) $dom = $this->xml->params; #if(!is_object($dom) && isset($this->xml->params)) $dom = $this->xml->params; //validation #if(!is_object($dom) || !$dom instanceof SimpleXMLElement) return ; /*if(!empty($dom)) { foreach ($dom->children() as $param) { $value = (string) $param['value']; //valid field type if(isset($param['type'])) { if($param['type'] == 'bool') $value = ($value!=='false')? true : false; } $data[(string)$param['name']] = $value; } } return $data;*/ $arr = array(); foreach ($dom as $element) { $tag = $element->getName(); if ($tag !== 'param' && $tag !== 'params') { continue; } $atts = $element->attributes(); $key = isset($atts['name']) ? (string) $atts['name'] : ''; $val = isset($atts['value']) ? (string) $atts['value'] : HW_String::truncate_empty_lines((string) $element); if (isset($atts['type']) && $atts['type'] == 'bool') { $val = $val ? true : false; } $e = get_object_vars($element); if (!empty($e)) { $val = count($element->children()) && $tag == 'params' ? $this->extract_params($element) : $val; if ($key !== '') { $arr[$key] = $val; } else { $arr[] = $val; } } else { if ($key !== '') { $arr[$key] = trim($element); } else { $arr[] = trim($element); } } } return $arr; }
/** * add new slider tab * @param $args * @param $assoc_args */ public function add_slider($args, $assoc_args) { //load necessary classes HW_HOANGWEB::load_class('HW_WP_Attachment'); //list( $name ) = $args; #params $title = $this->get_cmd_arg($assoc_args, 'title', HW_String::generateRandomString(10)); $slide_image_width = $this->get_cmd_arg($assoc_args, 'width', '730'); $slide_image_height = $this->get_cmd_arg($assoc_args, 'height', '280'); //source $source = $this->get_cmd_arg($assoc_args, 'source', 'upload'); $from = $this->get_cmd_arg($assoc_args, 'from_path', 'theme'); $source_path = $this->get_cmd_arg($assoc_args, 'source_path'); if ($from == 'theme') { $source_path = get_stylesheet_directory() . '/' . $source_path; } elseif ($from == 'plugin') { $source_path = HWML_PLUGIN_PATH . '/' . $source_path; } //number of slides $num = $this->get_cmd_arg($assoc_args, 'num', 3); if (!is_numeric($num)) { $num = 3; } //settings $slider_settings = $this->get_cmd_arg($assoc_args, 'settings', array()); if (is_string($slider_settings)) { $slider_settings = HW_Encryptor::decode64($slider_settings); } $attach_ids = array(); #get attachments ids if ($source == 'upload') { $count = 1; if ($handle = opendir($source_path)) { while (false !== ($entry = readdir($handle))) { if ($count > $num) { break; } //exceed max number of files allow to upload if ($entry != "." && $entry != ".." && HW_Validation::valid_image_ext($entry)) { #echo "$entry\n"; $attach_ids[] = HW_WP_Attachment::upload_attachment($source_path . DIRECTORY_SEPARATOR . $entry); $count++; } } closedir($handle); } } else { global $wpdb; $res = $wpdb->get_results("SELECT * from {$wpdb->posts} where post_type='attachment' and post_mime_type like '%image%' order by rand() limit {$num}"); foreach ($res as $row) { $attach_ids[] = $row->ID; } } /** * add slider tab */ $mlslider_post = array('post_content' => '', 'post_title' => wp_strip_all_tags($title), 'post_name' => sanitize_title($title), 'post_status' => 'publish', 'post_type' => 'hw-ml-slider', 'post_author' => '1', 'ping_status' => 'open', 'post_parent' => '0', 'post_excerpt' => '', 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => date('Y-m-d H:i:s'), 'comment_status' => 'open'); $slider_id = wp_insert_post($mlslider_post); /** * add metaslider setting for created above */ $settings_params = $this->get_params('metaslider_settings'); $settings = array('type' => 'flex', 'random' => 'false', 'cssClass' => '', 'printCss' => 'true', 'printJs' => 'true', 'width' => $slide_image_width, 'height' => $slide_image_height, 'spw' => 7, 'sph' => 5, 'delay' => '3000', 'sDelay' => 30, 'opacity' => 0.8, 'titleSpeed' => 500, 'effect' => 'fade', 'navigation' => 'true', 'links' => 'true', 'hoverPause' => 'true', 'theme' => '', 'direction' => 'horizontal', 'reverse' => 'false', 'animationSpeed' => '600', 'prevText' => '<', 'nextText' => '>', 'slices' => 15, 'center' => 'false', 'smartCrop' => 'true', 'carouselMode' => 'false', 'carouselMargin' => '5', 'easing' => 'linear', 'autoPlay' => 'true', 'fullWidth' => 'false', 'noConflict' => 'true', 'hw_mlcontainer_id' => 'false', 'smoothHeight' => 'false'); if (is_array($slider_settings) && count($slider_settings)) { $settings = array_merge($settings, $slider_settings); } $this->hwml_add_or_update_or_delete_meta($slider_id, 'settings', array_merge($settings, $settings_params)); /** * add images to slider */ foreach ($attach_ids as $slide_id) { //$slide_id = $row->ID; if ($this->hwml_slide_exists_in_slideshow($slider_id, $slide_id)) { continue; } $this->hwml_tag_slide_to_slider($slider_id, $slide_id); $this->hwml_add_or_update_or_delete_meta($slide_id, 'type', 'image'); $this->hwml_add_or_update_or_delete_meta($slide_id, 'crop_position', 'center-center'); //for crop tab, set crop position for current image $this->hwml_add_or_update_or_delete_meta($slide_id, 'title', 'demo-title-' . $slide_id); //for seo tab $this->hwml_add_or_update_or_delete_meta($slide_id, 'url', 'url-here-' . $slide_id); update_post_meta($slide_id, '_wp_attachment_image_alt', 'alt demo ' . $slide_id); //for seo tab $this->hwml_add_or_update_or_delete_meta($slide_id, 'new_window', 'true'); //$row->guid; } // Free up memory //$this->stop_the_insanity(); //WP_CLI::success( ' add slider successful.' ); $this->result(' add slider successful.'); }
/** * convert xml to array * @param SimpleXMLElement $xml * @param $singular_tag * @param $plural_tag * @return array */ public static function xml2array($xml, $singular_tag = 'param', $plural_tag = 'params') { $arr = array(); if ($xml instanceof SimpleXMLElement) { foreach ($xml as $element) { $tag = $element->getName(); if ($tag !== $singular_tag && $tag !== $plural_tag) { continue; } $atts = $element->attributes(); $key = isset($atts['name']) ? (string) $atts['name'] : ''; $val = isset($atts['value']) ? (string) $atts['value'] : HW_String::truncate_empty_lines((string) $element); if (isset($atts['type']) && $atts['type'] == 'bool') { $val = $val ? true : false; } $e = get_object_vars($element); if (!empty($e)) { $val = count($element->children()) && $tag == $plural_tag ? self::xml2array($element) : $val; if ($key !== '') { $arr[$key] = $val; } else { $arr[] = $val; } } else { if ($key !== '') { $arr[$key] = trim($element); } else { $arr[] = trim($element); } } } } return $arr; }
/** * validation form fields * @param $values * @return mixed */ public function validation_tab_filter($_values) { HW_HOANGWEB::load_class('HW_String'); /*foreach(array('xxx') as $option) { if(isset($values[$option])) $values[$option] = $values[$option]? true:false; }*/ $values = $this->pure_fields_result($_values); $values = $values['sidebars']; if (!empty($values['sidebar_id'])) { $id = $values['sidebar_id']; } else { $id = strtolower(HW_Validation::valid_objname(HW_String::vn_str_filter($values['sidebar_name']))); } $sidebar = array('id' => $id, 'name' => $values['sidebar_name'], 'description' => isset($values['sidebar_desc']) ? $values['sidebar_desc'] : '', 'before_widget' => $values['before_widget'], 'before_title' => $values['before_title'], 'after_title' => $values['after_title'], 'after_widget' => $values['after_widget']); if (!empty($sidebar['id'])) { hwawc_register_sidebar($sidebar); } return $_values; //un-save }
/** * do import for posts * @param $post * @return array */ public function process_post($post) { $post_id = $this->get_tag($post, 'wp:post_id'); $post_title = $this->get_tag($post, 'title'); $post_date = $this->get_tag($post, 'wp:post_date'); $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); $comment_status = $this->get_tag($post, 'wp:comment_status'); $ping_status = $this->get_tag($post, 'wp:ping_status'); $status = $this->get_tag($post, 'wp:status'); $post_name = $this->get_tag($post, 'wp:post_name'); $post_parent = $this->get_tag($post, 'wp:post_parent'); $menu_order = $this->get_tag($post, 'wp:menu_order'); $post_type = $this->get_tag($post, 'wp:post_type'); $post_password = $this->get_tag($post, 'wp:post_password'); $is_sticky = $this->get_tag($post, 'wp:is_sticky'); $guid = $this->get_tag($post, 'guid'); $post_author = $this->get_tag($post, 'dc:creator'); $post_excerpt = $this->get_tag($post, 'excerpt:encoded'); $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt); $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); $post_content = $this->get_tag($post, 'content:encoded'); $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); $post_content = $this->parser->pre_shortcode_tags($post_content); $postdata = compact('post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password', 'is_sticky'); $attachment_url = $this->get_tag($post, 'wp:attachment_url'); if ($attachment_url) { $postdata['attachment_url'] = $attachment_url; } //hw attachment preg_match_all('|<hw:attachment>(.+?)</hw:attachment>|is', $post, $attachments); $attachments = $attachments[1]; if ($attachments) { foreach ($attachments as $p) { $hw_attachment_url = $this->get_tag($p, 'hw:url'); if ($hw_attachment_url) { if (!HW_URL::valid_url($hw_attachment_url)) { $postdata['attachment_url'] = $this->parser->data('import_path') . $hw_attachment_url; } else { $postdata['attachment_url'] = $hw_attachment_url; } //found new attachment in post if ($post_type !== 'attachment') { $_postdata = hwArray::cloneArray($postdata); $_postdata['post_content'] = HW_String::limit($_postdata['post_content'], 50); $_postdata['post_excerpt'] = HW_String::limit($_postdata['post_excerpt'], 50); $_postdata['post_type'] = 'attachment'; $_postdata['_id'] = $this->get_tag($p, 'hw:_id'); $_postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail'); if ($_postdata['thumbnail']) { $_postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id'); } $this->posts[] = $_postdata; } /*else { $postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail'); if($postdata['thumbnail']) $postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id'); }*/ } } } preg_match_all('|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER); foreach ($terms as $t) { $post_terms[] = array('slug' => $t[2], 'domain' => $t[1], 'name' => str_replace(array('<![CDATA[', ']]>'), '', $t[3])); } if (!empty($post_terms)) { $postdata['terms'] = $post_terms; } preg_match_all('|<wp:comment>(.+?)</wp:comment>|is', $post, $comments); $comments = $comments[1]; if ($comments) { foreach ($comments as $comment) { preg_match_all('|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta); $commentmeta = $commentmeta[1]; $c_meta = array(); foreach ($commentmeta as $m) { $c_meta[] = array('key' => $this->get_tag($m, 'wp:meta_key'), 'value' => $this->get_tag($m, 'wp:meta_value')); } $post_comments[] = array('comment_id' => $this->get_tag($comment, 'wp:comment_id'), 'comment_author' => $this->get_tag($comment, 'wp:comment_author'), 'comment_author_email' => $this->get_tag($comment, 'wp:comment_author_email'), 'comment_author_IP' => $this->get_tag($comment, 'wp:comment_author_IP'), 'comment_author_url' => $this->get_tag($comment, 'wp:comment_author_url'), 'comment_date' => $this->get_tag($comment, 'wp:comment_date'), 'comment_date_gmt' => $this->get_tag($comment, 'wp:comment_date_gmt'), 'comment_content' => $this->get_tag($comment, 'wp:comment_content'), 'comment_approved' => $this->get_tag($comment, 'wp:comment_approved'), 'comment_type' => $this->get_tag($comment, 'wp:comment_type'), 'comment_parent' => $this->get_tag($comment, 'wp:comment_parent'), 'comment_user_id' => $this->get_tag($comment, 'wp:comment_user_id'), 'commentmeta' => $c_meta); } } if (!empty($post_comments)) { $postdata['comments'] = $post_comments; } preg_match_all('|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta); $postmeta = $postmeta[1]; if ($postmeta) { foreach ($postmeta as $p) { $post_postmeta[] = array('key' => $this->get_tag($p, 'wp:meta_key'), 'value' => $this->get_tag($p, 'wp:meta_value', true)); } } if (!empty($post_postmeta)) { $postdata['postmeta'] = $post_postmeta; } return $postdata; }
/** * 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; }
/** * add break line */ public function addBreakLine() { $this->addField(array('field_id' => uniqid(HW_String::generateRandomString(5)), 'type' => 'hw_html', 'show_title_column' => false, 'description' => '<hr/>')); }