/** * @param $aField * @return string */ private function _getInputs($aField) { $_aOutput = array(); //ckeditor config $config = array('language' => 'vi', 'uiColor' => '#9AB8F3'); if (isset($aField['config']) && is_array($aField['config'])) { $config = array_merge($config, $aField['config']); } $_aAttributes = $aField['attributes']; //$description = isset( $aField['description'])? $aField['description'] : ''; //field description //$_aAttributes = $aAttributes+ $_aAttributes; $name = $_aAttributes['name']; $id = HW_Validation::valid_apf_slug($name); $value = isset($aField['attributes']['value']) ? $aField['attributes']['value'] : ''; $_aOutput[] = '<textarea id="' . $id . '" name="' . $name . '" class="" rows="6" >' . esc_attr($value) . '</textarea>'; $_aOutput[] = "<div class='admin-page-framework-input-label-container my_custom_field_type'>" . "<span class='admin-page-framework-input-label-string' style=''>" . "</span>" . PHP_EOL . "</div>"; $_aOutput[] = '<script type="text/javascript"> jQuery(function(){ CKEDITOR.config.extraPlugins = "hw_wp_media_button"; // Replace the <textarea id="editor1"> with a CKEditor // instance, using default configuration. CKEDITOR.replace( "' . $id . '" ,' . json_encode($config) . '); }); </script> '; return implode(PHP_EOL, $_aOutput); }
/** * class constructor */ public function __construct($option_group = null, $page_slug = '') { if ($page_slug) { $this->page_slug = $page_slug; } //apply screen option to this page //note option_group should be valid as variable name if ($option_group) { $this->option_group = HW_Validation::valid_apf_slug($option_group); //set screen option group self::$options_manager[$option_group] = $this; //add to array } add_filter('set-screen-option', [$this, 'set_screen'], 10, 3); add_action('admin_menu', [$this, 'plugin_menu']); add_filter('screen_settings', array($this, '_screen_settings'), 10, 2); /* //access option $screen = get_current_screen(); // retrieve the "per_page" option $screen_option = $screen->get_option('per_page', 'option'); // get the default value if none is set $per_page = $screen->get_option( 'per_page', 'default' ); */ }
/** * validation form fields * @param $values * @return mixed */ public function validation_tab_filter($values) { $locations = get_registered_nav_menus(); foreach ($values as $field => $menu) { foreach (array_keys($locations) as $location) { if ($this->real_field_name($field) == HW_Validation::valid_apf_slug($location)) { HW_NAVMENU::set_menu_location($location, $menu); break; } } } return $values; }
/** * 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; }
/** * export module data to wxr format (module data mean short data written for module) * @param $xml */ function export_wxr_data($xml = null) { if (empty($xml)) { $xml = $this->xml_data; } //set options foreach ($this->get_options_xml($xml) as $item) { $atts = $item->attributes(); $sidebar = (string) $atts['sidebar']; $type = (string) $atts['type']; $hw = $item->children($this->namespaces['hw']); if ($type == 'sidebar_setting') { $skins = $this->fetch_skins($hw->skin); $args = array('enable_override_sidebar' => '1', 'alphabe_widgets' => '1', 'bgcolor_title' => '', 'bgimg_title' => '', 'bgcolor_box' => '', 'bgimg_box' => ''); $args = array_merge($args, $skins); $this->options->add_option('HW_Sidebar_Settings', $args, array('prefix' => HW_Validation::valid_apf_slug($sidebar) . '_', 'method' => 'append')); } elseif ($type == 'sidebar_position') { $setting = array('sidebars_pos' => array('sidebars_position')); foreach ($hw->params->param as $param) { $sidebar = (string) $param->attributes()->name; $position = (string) $param; $setting['sidebars_pos']['sidebars_position'] = array($sidebar => array('position' => $position)); } $this->options->add_module_setting_page($setting); } } //posts foreach ($this->get_posts_xml() as $item) { $atts = $item->attributes(); $wp = $item->children($this->namespaces['wp']); $hw = $item->children($this->namespaces['hw']); //post meta $post_metas = $this->fetch_post_metas($hw->meta); $this->posts->addItem(array('title' => (string) $wp->title, 'description' => '', 'content' => '', 'excerpt' => '', 'post_type' => 'hw_mysidebar', 'post_metas' => $post_metas), HW_XML::attributesArray($item)); } //$this->add_export_widgets(); //add widget if that found in this module $this->do_import(); }
/** * render facebook comment box * @param $atts attributes */ function _hw_fb_comment_display($atts) { HW_HOANGWEB::load_class('HW_UI_Component'); $inst = HW_Module_Comments::get(); $options = $inst->get_tab('facebook')->get_values(); $atts = array(); $appId = isset($options['appId']) ? $options['appId'] : ''; $width = !empty($options['width']) ? HW_Validation::format_unit($options['width']) : '100%'; $num_posts = !empty($options['num_posts']) ? $options['num_posts'] : '5'; $colorscheme = !empty($options['colorscheme']) ? $options['colorscheme'] : 'light'; $order_by = !empty($options['order_by']) ? $options['order_by'] : 'social'; //order_by $show_count = !empty($options['show_count']) ? $options['show_count'] : 0; $comment_text = !empty($options['comment_text']) ? $options['comment_text'] : __('Bình luận'); echo '<div id="fb-root"></div>'; #echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>'; echo "\r\n<script>(function(d, s, id) {\r\n var js, fjs = d.getElementsByTagName(s)[0];\r\n if (d.getElementById(id)) return;\r\n js = d.createElement(s); js.id = id;\r\n js.src = '//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId={$appId}';\r\n fjs.parentNode.insertBefore(js, fjs);\r\n}(document, 'script', 'facebook-jssdk'));</script>"; //show count if ($show_count) { echo '<span class="fb-comments-count" data-href="' . get_permalink() . '"></span> ' . $comment_text; } if (isset($options['html5'])) { $atts['data-href'] = get_permalink(); $atts['data-width'] = $width; $atts['data-numposts'] = $num_posts; $atts['data-order-by'] = $order_by; $atts['data-colorscheme'] = $colorscheme; echo '<div class="fb-comments" ' . HW_UI_Component::generateAttributes($atts) . '></div>'; } else { $atts['href'] = get_permalink(); $atts['width'] = $width; $atts['num_posts'] = $num_posts; $atts['order_by'] = $order_by; $atts['width'] = $width; echo '<fb:comments ' . HW_UI_Component::generateAttributes($atts) . '></fb:comments>'; } }
/** * generate field id * @param string $field * @return mixed */ public function get_field_id($field = '') { return HW_Validation::valid_apf_slug($this->get_field_name($field)); }
/** * add settings for modules settings page * @param array $settings */ public function add_module_setting_page($settings = array()) { $this->add_option('HW_Module_Settings_page', $settings, array('prefix' => HW_Validation::valid_apf_slug($this->base->get_module()->option('module_name')) . '_', 'method' => 'append')); }
/** * generate object name * @param $name: name */ public static function generate_callback_name($name) { if (class_exists('HW_Validation')) { return HW_Validation::valid_objname($name); } else { $delimiter = '_'; return preg_replace('/[\\s,.\\[\\]\\/\\#\\*@$%^\\!~\\-\\+\\=]+/', $delimiter, $name); } }
/** * generate field id * @param $name * @return string */ private function get_field_id($name) { $widget = $this->widget_ref; //get current widget //valid name if (is_object($widget) && $widget instanceof WP_Widget) { //if whether object reference of widget instance $fname = $widget->get_field_id($name); //get field name if context is widget } else { $fname = $name; } //valid object name $fname = class_exists('HW_Validation') ? HW_Validation::valid_objname($fname) : $this->valid_objname($fname); return $fname; }
/** * 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.'); }
/** * extend from wordpress core * @param string $output * @param object $category * @param int $depth * @param array $args * @param int $id */ public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { if (!empty($args['mydata']['skin_setting'])) { $skin_setting = $args['mydata']['skin_setting']; } $this->current_cat = new HW_TimberTerm($category); /** This filter is documented in wp-includes/category-template.php */ $cat_name = apply_filters('list_cats', esc_attr($category->name), $category); //valid $options = (object) $args['options']; if (!isset($options->before)) { $options->before = ''; } if (!isset($options->submenu_before)) { $options->submenu_before = ''; } if (!isset($options->after)) { $options->after = ''; } if (!isset($options->submenu_after)) { $options->submenu_after = ''; } if (!isset($options->link_before)) { $options->link_before = ''; } if (!isset($options->submenu_link_before)) { $options->submenu_link_before = ''; } if (!isset($options->link_after)) { $options->link_after = ''; } if (!isset($options->submenu_link_after)) { $options->submenu_link_after = ''; } //whether current menu item has sub menu $item_has_sub = $this->item_has_sub($category); //separator if (!empty($options->ex_separator) && isset($options->show_items_separator)) { $output .= $options->ex_separator; } $data['args'] = hwArray::cloneArray($options); $data['indent'] = $indent = $depth ? str_repeat("\t", $depth) : ''; $data['item_has_sub'] = $item_has_sub; $id = apply_filters('hw_cat_item_id', 'cat-item-' . $category->term_id, $category, $args, $depth); $data['id'] = ' id="cat-' . esc_attr($category->term_id) . '"'; if ($item_has_sub && !empty($options->remove_link_parent)) { $data['remove_link_parent'] = true; } else { $data['remove_link_parent'] = false; } //item class //category item class $classes[] = 'cat-item cat-item-' . $category->term_id; if (!empty($args['current_category'])) { $_current_category = get_term($args['current_category'], $category->taxonomy); if ($category->term_id == $args['current_category']) { $classes[] = 'current-cat'; if (isset($skin_setting['current_item_class'])) { $classes[] = ' ' . $skin_setting['current_item_class']; } } elseif ($category->term_id == $_current_category->parent) { $classes[] = 'current-cat-parent'; } } if ($item_has_sub && !empty($options->menu_item_class_has_submenu)) { //cat item class has submenu $classes[] = $options->menu_item_class_has_submenu; } if ($depth > 0 && !empty($options->menu_item_class_submenu)) { //cat item class in submenu $classes[] = $options->menu_item_class_submenu; } $data['classes'] = $class_names = join(' ', apply_filters('cat_item_css_class', HW_Validation::valid_classes_attr(array_filter($classes)), $category, $args, $depth)); //custom fields $custom_item = get_post_custom($category->term_id); $data['field-01'] = isset($custom_item['menu-item-field-01'][0]) ? $custom_item['menu-item-field-01'][0] : ''; $data['field-02'] = isset($custom_item['menu-item-field-02'][0]) ? $custom_item['menu-item-field-02'][0] : ''; //cat item image if (isset($options->show_icon) && $options->show_icon) { $image_url = HW_ACF_Taxonomy::get_field_image($category); if ($image_url) { $image_img = '<img src="' . $image_url . '" class="hw-cat-item-icon"/>'; } else { $image_img = ''; } } $data['image_url'] = isset($image_url) ? $image_url : ''; $data['image_img'] = isset($image_img) ? $image_img : ''; /** * anchor attributes */ $atts = array(); $atts['href'] = esc_url(get_term_link($category)); $atts['class'] = array(); //anchor classes if ($item_has_sub && isset($options->anchor_class_has_submenu)) { //anchor class has submenu $atts['class'][] = $options->anchor_class_has_submenu; } if ($depth > 0 && !empty($options->anchor_class_submenu)) { //anchor class in submenu $atts['class'][] = $options->anchor_class_submenu; } $atts = apply_filters('hw_cat_link_attributes', $atts, $category, $args, $depth, $this); //validation $atts['class'] = HW_Validation::valid_classes_attr(array_filter($atts['class'])); $atts['class'] = join(' ', $atts['class']); if ($args['use_desc_for_title'] && !empty($category->description)) { $atts['title'] = esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))); } $attributes = HW_UI_Component::generateAttributes($atts); //addition attribute build for item link if ($depth == 0 && !empty($options->anchor_attrs)) { $attributes .= " {$options->anchor_attrs}"; } elseif ($depth != 0 && !empty($options->anchor_attrs_submenu)) { $attributes .= " {$options->anchor_attrs_submenu}"; } //attributes item link for submenu if ($item_has_sub && !empty($options->anchor_attrs_has_submenu)) { $attributes .= " {$options->anchor_attrs_has_submenu}"; } $data['attributes'] = $attributes; $data['title'] = apply_filters('the_title', $category->name, $category->term_id); $link = $options->before; $link .= '<a ' . $attributes . ' >'; $link .= $options->link_before . $cat_name . $options->link_after; $link .= '</a>'; $link .= $options->after; //feed image if (!empty($args['feed_image']) || !empty($args['feed'])) { $link .= ' '; if (empty($args['feed_image'])) { $link .= '('; } $link .= '<a href="' . esc_url(get_term_feed_link($category->term_id, $category->taxonomy, $args['feed_type'])) . '"'; if (empty($args['feed'])) { $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; } else { $alt = ' alt="' . $args['feed'] . '"'; $name = $args['feed']; $link .= empty($args['title']) ? '' : $args['title']; } $link .= '>'; if (empty($args['feed_image'])) { $link .= $name; } else { $link .= "<img src='" . $args['feed_image'] . "'{$alt}" . ' />'; } $link .= '</a>'; if (empty($args['feed_image'])) { $link .= ')'; } } if (!empty($args['show_count'])) { $link .= ' (' . number_format_i18n($category->count) . ')'; } //render cat item if (isset($args['twig']) && HW_NAVMENU::twig_asset_exists('start_el.twig', $args['twig'])) { $tpl = $args['twig']->loadTemplate('start_el.twig'); $data['term'] = $this->current_cat; $output .= $tpl->render($data); } else { if ('list' == $args['style']) { $output .= $indent . "\t<li"; //class attr $output .= ' class="' . $class_names . '"'; $output .= ">{$link}\n"; } else { $output .= "\t{$link}<br />\n"; } } }
/** * @hook wp_footer */ function print_footer() { if (is_product()) { $setting = self::get()->get_values(); $thumbnailsContainer = isset($setting['smallthumb_container']) ? $setting['smallthumb_container'] : '.product .thumbnails'; $productImages = isset($setting['productImages']) ? $setting['productImages'] : '.product .images > a'; $mouseEvent = isset($setting['mouseEvent']) ? $setting['mouseEvent'] : 'mouseover'; //css generator $css = array($thumbnailsContainer . ' img' => array('width' => get_option('woocommerce_thumbnail_image_width') . 'px'), '.cloud-zoom-big' => array()); if (!empty($setting['zoombig_width'])) { $css['.cloud-zoom-big']['width'] = HW_Validation::format_unit($setting['zoombig_width']) . ' !important'; } if (!empty($setting['zoombig_height'])) { $css['.cloud-zoom-big']['height'] = HW_Validation::format_unit($setting['zoombig_height']) . ' !important'; } echo HW_UI_Component::generateCSS($css); ?> <script type="text/javascript"> jQuery(document).ready(function($){ var $thumbnailsContainer, $thumbnails,$productImages, addCloudZoom; $('a.zoom').unbind('click.fb'); $thumbnailsContainer = $('<?php echo $thumbnailsContainer; ?> '); $thumbnails = $('a', $thumbnailsContainer); $productImages = $('<?php echo $productImages; ?> '); addCloudZoom = function(el){ el.addClass('cloud-zoom').CloudZoom(); } if($thumbnails.length){ <?php if ($mouseEvent == 'click') { echo '$thumbnails.unbind(\'click\');'; } ?> $thumbnails.bind('<?php echo $mouseEvent; ?> ',function(){ var $image = $(this).clone(false); $image.insertAfter($productImages); $productImages.remove(); $productImages = $image; $('.mousetrap').remove(); addCloudZoom($productImages); return false; }) } addCloudZoom($productImages); }); </script> <?php } }
/** * display help icon * @param $module * @param $aField */ private function generate_help_icon($module, $aField) { $module_label = isset($aField['module_info']['name']) ? $aField['module_info']['name'] : $module->module_name; $help = $aField['hw_help']; if (empty($help)) { return; } $help_file = HW_HELP::get_help_popup_file(array($help['class'], $help['file'])); $_aAttributes = $aField['attributes']; $name = $_aAttributes['name']; $id = HW_Validation::valid_apf_slug($name); $html = '<a href="#" id="' . $id . '" data-hw-module="' . $module->module_name . '" data-hw-help-file="' . urlencode(HW_Encryptor::encrypt($help_file)) . '" title="' . $module_label . '"><img src="' . plugins_url('help_icon.png', __FILE__) . '" class="module-help-icon hw-module-help"/>Trợ giúp</a>'; return $html; }
/** * @param $atts */ public function _gallery_shortcode($atts) { global $post; // If no attributes have been passed, the gallery should be pulled from the current post. $gallery_id = false; if (empty($atts)) { $gallery_id = $post->ID; $data = is_preview() ? $this->gallery->_get_gallery($gallery_id) : $this->gallery->get_gallery($gallery_id); } else { if (isset($atts['id'])) { $gallery_id = (int) $atts['id']; $data = is_preview() ? $this->gallery->_get_gallery($gallery_id) : $this->gallery->get_gallery($gallery_id); } else { if (isset($atts['slug'])) { $gallery_id = $atts['slug']; $data = is_preview() ? $this->gallery->_get_gallery_by_slug($gallery_id) : $this->gallery->get_gallery_by_slug($gallery_id); } else { // A custom attribute must have been passed. Allow it to be filtered to grab data from a custom source. $data = apply_filters('hw_envira_gallery_custom_gallery_data', false, $atts, $post); } } } // If there is no data to output or the gallery is inactive, do nothing. if (!$data || empty($data['gallery']) || isset($data['status']) && 'inactive' == $data['status'] && !is_preview()) { return; } // Get rid of any external plugins trying to jack up our stuff where a gallery is present. $this->plugin_humility(); // If this is a feed view, customize the output and return early. if (is_feed()) { return $this->do_feed_output($data); } $i = 1; $args = array(); $args['wrapper_id'] = sanitize_html_class($data['id']); $args['wrapper_class'] = $this->get_gallery_classes($data); $args['columns_class'] = $this->get_config('columns', $data); $galleries = array(); foreach ($data['gallery'] as $id => $item) { // Skip over images that are pending (ignore if in Preview mode). if (isset($item['status']) && 'pending' == $item['status'] && !is_preview()) { continue; } $gallery = array(); $image = $this->get_image_src($id, $item, $data); $gallery = array_merge($item); $gallery['index'] = $i; $gallery['id'] = $id; $gallery['item_classes'] = $this->get_gallery_item_classes($item, $i, $data); $gallery['margin_bottom'] = HW_Validation::format_unit($this->get_config('margin', $data)); $gallery['img_src'] = esc_url($image[0]); $gallery['img_width'] = esc_url($image[1]); $gallery['img_height'] = esc_url($image[2]); $thumb = wp_get_attachment_image_src($id, 'thumbnail'); $gallery['thumb_src'] = $thumb[0]; $gallery['thumb_width'] = $thumb[1]; $gallery['thumb_height'] = $thumb[2]; $gallery['placeholder'] = esc_url(plugins_url('assets/css/images/holder.gif', dirname(dirname(__FILE__)))); $galleries[$id] = $gallery; // Increment the iterator. $i++; } /*---start skin---*/ //$skin = $this->get_config( 'hw_skin', $data ); $skin = !empty($data['config']['hw_skin']) ? $data['config']['hw_skin'] : $this->get_config('hw_skin', array()); if (empty($skin['hash_skin'])) { return; } //get skin options $data['options'] = isset($skin['skin_options']) ? $skin['skin_options'] : array(); $data['json_options'] = HW_SKIN_Option::build_json_options($data['options']); //$this->skin->get_current(); //change sidebar params from skin return HW_SKIN::apply_skin_data($skin, array('callback_before' => array(__CLASS__, '_hw_skin_before_include_skin_file')), array('galleries' => $galleries, 'args' => $args, 'data' => $data), false); }
/** * export module data to wxr format (module data mean short data written for module) * @param $xml */ function export_wxr_data($xml = null) { if (empty($xml)) { $xml = $this->xml_data; } //register menu location #$xml->xpath('/rss/hw:'. $this->get_module()->option('module_name') . '/hw:nav_menu'); /*foreach($xml->xpath('/rss/hw:'. $this->get_module()->option('module_name')) as $lmenu) { }*/ //create nav menu item foreach ($this->get_posts_xml($xml) as $item) { $terms = array(); $atts = $item->attributes(); $hw = $item->children($this->namespaces['hw']); $wp = $item->children($this->namespaces['wp']); $post_type = (string) $wp->post_type; $post_meta = array(); $data = array('post_type' => $post_type); if ($post_type == 'post') { //post $data = array('title' => (string) $wp->title, 'content' => (string) $wp->content, 'excerpt' => (string) $wp->excerpt, 'post_type' => $post_type); } elseif ($post_type == 'nav_menu_item') { //nav menu item $data = array('title' => (string) $wp->title, 'description' => '', 'content' => '', 'excerpt' => '', 'post_type' => $post_type); $post_meta = array_merge(array('_menu_item_target' => '', '_menu_item_menu_item_parent' => '0', '_menu_item_url' => '', '_menu_item_xfn' => ''), $post_meta); if (isset($hw->assign_menu)) { $nicename = (string) $hw->assign_menu->menu->attributes()->name; $menu_name = (string) $hw->assign_menu->menu; if (!$menu_name) { $menu_name = $nicename; } $terms['nav_menu'] = array($nicename => $menu_name); //assign to menu if (isset($hw->assign_menu->item_import_result)) { $_item = $hw->assign_menu->item_import_result; $type = (string) $_item->attributes()->type; if (!empty($_item)) { if ($type == 'post') { $menu_item = $this->get_import_result($_item->import_post, 'post'); $post_meta['_menu_item_object'] = $menu_item['post_type']; $post_meta['_menu_item_object_id'] = $menu_item['ID']; $post_meta['_menu_item_type'] = 'post_type'; } elseif ($type == 'term') { $menu_item = $this->get_import_result($_item->import_term, 'term'); //HW_Logger::log_file($menu_item); $post_meta['_menu_item_object'] = $menu_item['taxonomy']; $post_meta['_menu_item_object_id'] = $menu_item['term_id']; $post_meta['_menu_item_type'] = 'taxonomy'; } } } $data['terms'] = $terms; } } if ($hw->meta) { //you can also use $this->fetch_post_metas_value($hw->meta); $post_meta = array_merge($post_meta, $this->fetch_post_metas_value($hw->meta)); $data['post_metas'] = $post_meta; } $this->posts->addItem($data, HW_XML::attributesArray($item)); } //set options if ($this->get_options_xml($xml)) { } foreach ($this->get_options_xml($xml) as $item) { $atts = $item->attributes(); $hw = $item->children($this->namespaces['hw']); $wp = $item->children($this->namespaces['wp']); $type = (string) $atts['type']; if ($type == 'menu_setting') { $option_name = isset($atts['name']) ? $atts['name'] : 'HW_NAVMENU_settings'; $menu = (string) $atts['menu']; //$params = $this->simplexml_parser->recursive_option_data($item->children())->option; $params = $this->simplexml_parser->recursive_option_data($hw->params->children())->option; $setting = array('enable_filter_menu' => '1'); $setting = array_merge($setting, $params); //parse skin $skins = $this->fetch_skins($hw->skin); if (isset($skins['skin'])) { //add to setting $setting['skin'] = $skins['skin']; } $this->options->add_option($option_name, $setting, array('prefix' => HW_Validation::valid_apf_slug($menu) . '_', 'method' => 'append')); } elseif ($type == 'module_setting') { $setting = array(); foreach ($hw->params[0]->children() as $param) { $menu = (string) $param->attributes()->name; $setting[$menu] = $this->get_hw_params_element($param, 'params', true); } $this->options->add_module_setting_page($setting); } } $this->add_export_widgets(); $this->do_import(); }
/** * return valid field name from string * @param $str * @return mixed */ public static function valid_apf_field_name($str) { HW_HOANGWEB::load_class('HW_Validation'); return HW_Validation::valid_apf_slug($str); }
/** * generate unique name to wrap js function in current widget * @return string */ private function generate_object_name() { if (!$this->valid_widget()) { return; } //return 'hw_toggle_'.preg_replace('/[@#\$%\^&\*\(\)\|\{\}+\=\-\~\!]+/','_',$this->generate_name('Expand')); return 'hw_toggle_' . HW_Validation::valid_objname($this->generate_name('Expand')); }
/** * custom dynamic sidebar for dynamic_sidebar() function * @param $name: sidebar id */ function hw_dynamic_sidebar($name) { $name = apply_filters('hw_dynamic_sidebar', $name); $dynamic_settings = HW_AWC_Frontend::get_active_sidebars_settings(); //_print($dynamic_settings); $pages_condition_and = array(); $pages_condition_or = array(); //match occurence condition $match_occurence = hw_get_setting('match_occurence', 'first_occurence'); //get cache result for first $detect_addition_sidebar = false; $data = get_transient('hw_dynamic_sidebar'); if (empty($data)) { $data = array(); } #see: other way in includes/layout-templates/theme.php/HW__Template_Condition foreach ($dynamic_settings as $id => $setting) { $result = $result_or = array(); //$and = APF_hw_condition_rules::parseQuery($setting['query_data_and']); //AND relation //$or = APF_hw_condition_rules::parseQuery($setting['query_data_or']); //OR relation if (!empty($setting['query_data_and'])) { $_result = HW_AWC_Frontend::check_sidebar_changing($setting['query_data_and'], 'AND'); list($k, $v) = each($_result); $result[] = array('template' => $k, 'result' => $v, 'setting' => $setting); //$result[$k] $pages_condition_and = array_merge($pages_condition_and, $result); //override page result for AND relation } if (!empty($setting['query_data_or'])) { $_result_or = HW_AWC_Frontend::check_sidebar_changing($setting['query_data_or'], 'OR'); list($k, $v) = each($_result_or); $result_or[] = array('template' => $k, 'result' => $v, 'setting' => $setting); $pages_condition_or = array_merge($pages_condition_or, $result_or); //override page result for OR relation } } foreach (array($pages_condition_and, $pages_condition_or) as $pages_condition) { if (isset($pages_condition) && is_array($pages_condition)) { //get sidebar alternate with AND relation $key = base64_encode(serialize($pages_condition)); if (!empty($data[$key])) { $name = $data[$key]; } else { foreach ($pages_condition as $temp => $meet_condition) { if ($meet_condition['result']) { $_name = HW_Validation::valid_objname($name); //get active sidebars $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true); if (is_active_sidebar($sidebar)) { //make sure sidebar not empty if ($match_occurence == 'first_occurence' && !$detect_addition_sidebar || $match_occurence == 'last_occurence') { $name = $sidebar; //rename sidebar $data[$key] = $name; //save redirect sidebar name $detect_addition_sidebar = true; //detect append } } } } } } } /* if(isset($pages_condition_and) && is_array($pages_condition_and)) { //get sidebar alternate with AND relation $and_key = base64_encode(serialize($pages_condition_and)); if(!empty($data[$and_key])) $name = $data[$and_key]; else{ foreach ($pages_condition_and as $temp => $meet_condition) { if($meet_condition['result']) { $_name = HW_Validation::valid_objname($name); //get active sidebars $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true); if(is_active_sidebar($sidebar)) { //make sure sidebar not empty $name = $sidebar; //rename sidebar $data[$and_key] = $name; //save redirect sidebar name $detect_addition_sidebar = true; //detect append } } } } } if(isset($pages_condition_or) && is_array($pages_condition_or)) { //get sidebar alternate with OR relation $or_key = base64_encode(serialize($pages_condition_or)); if(!empty($data[$or_key])) { $name = $data[$or_key]; } else { foreach ($pages_condition_or as $temp => $meet_condition) { if($meet_condition['result']) { $_name = HW_Validation::valid_objname($name); //get active sidebars $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true); if(is_active_sidebar($sidebar)){ //make sure sidebar not empty $name = $sidebar; //rename sidebar $data[$or_key] = $name; //save redirect sidebar name $detect_addition_sidebar = true; //detect append } } } } } */ //cache result to database if ($detect_addition_sidebar == true) { set_transient('hw_dynamic_sidebar', $data); } dynamic_sidebar($name); //load sidebar }
/** * valid tab slug * @param $name * @return mixed */ public static function valid_tab_slug($name) { #return preg_replace('#-@!#$%^&*()+/\.<>~#', '_', $name); return HW_Validation::valid_apf_slug($name); }
/** * return setting page for module * @param $name * @param $action */ public static function get_tab_setting_page($name, $action = '', $args = array()) { $_args = array('tab' => HW_Validation::valid_apf_slug($name), 'page' => urlencode(self::PAGE_SLUG), '_name' => urlencode($name), 'tab-nonce' => urlencode(wp_create_nonce('tab-nonce'))); if (is_array($args)) { $_args = array_merge($_args, $args); } return wp_nonce_url(add_query_arg($_args, admin_url('admin.php')), $action); }
/** * valid field id from their name or any give string * @param $str */ private static function generate_id($str) { return class_exists('HW_Validation') ? HW_Validation::valid_objname($str) : $str; }
/** * parse theme config using wrx format * @param $file */ public function parse($file) { $site = $menus = $assets = $libs = $modules = $plugins = $positions = $configuration = array(); $xml = HW_WXR_Parser_SimpleXML::read_simplexml_object($file); $namespaces = $xml->namespaces; $xml = $xml->xml; $xml_parser = new HW_WXR_Parser(); //::get_instance(); $simplexml_parser = $xml_parser->simplexml_parser; //site meta if (isset($xml->site)) { $hw = $xml->site->children($namespaces['hw']); if (isset($hw->name)) { $site['name'] = (string) $hw->name; } if (isset($hw->description)) { $site['description'] = (string) $hw->description; } if (isset($hw->logo)) { $site['logo'] = (string) $hw->logo; } if (isset($hw->banner)) { $site['banner'] = (string) $hw->banner; } if (isset($hw->phone)) { $site['phone'] = (string) $hw->phone; } if (isset($hw->email)) { $site['admin_email'] = (string) $hw->email; } if (isset($hw->address)) { $site['address'] = (string) $hw->address; } if (isset($hw->testimonials)) { $site['testimonials'] = (string) $hw->testimonials; } if (!empty($hw->footer_text)) { $site['footer'] = (string) $hw->footer_text; } } //configuration if (isset($xml->configuration)) { $hw = $xml->configuration->children($namespaces['hw']); $configuration['sample_data'] = (string) $hw->sample_data; $media = $hw->media->children('hw'); $configuration['media'] = array(); foreach ($media as $image) { foreach ($image as $size) { $atts = $size->attributes(); $configuration['media'][$size->getName()] = array('width' => (string) $atts->width, 'height' => (string) $atts->height, 'crop' => (string) $atts->crop); } } /*if(!empty($media->thumbnail)) $configuration['media']['thumbnail'] = (string) $media->thumbnail; if(!empty($media->medium)) $configuration['media']['medium'] = (string) $media->medium; if(!empty($media->large)) $configuration['media']['large'] = (string) $media->large;*/ $configuration['locale'] = (string) $hw->locale; } //fetch menus foreach ($xml->xpath('/theme/menus/hw:menu') as $menu) { $atts = $menu->attribute(); $menus[(string) $atts['slug']] = (string) $menu; } //fetch sidebars $sidebars = array(); #$simplexml_parser->grab_sidebars($xml->xpath('/theme')[0], $namespaces); foreach ($xml->xpath('/theme/sidebars/hw:sidebar') as $sidebar_widgets) { $atts = $sidebar_widgets->attributes(); $skin = (string) $atts['skin']; //sidebar skin $sidebar_name = (string) $atts['name']; if (!isset($sidebars[(string) $atts['name']])) { $sidebars[$sidebar_name] = array('skin' => $skin, 'widgets' => array(), 'params' => array()); } //get widgets in sidebar $hw = $sidebar_widgets->children($namespaces['hw']); foreach ($hw->widget as $widget) { $name = (string) $widget->attributes()->name; $sidebars[$sidebar_name]['widgets'][] = $name; } //sidebar params $sidebars[$sidebar_name]['params'] = array('name' => $sidebar_name); if (!empty($hw->params)) { $sidebars[$sidebar_name]['params'] = array_merge($sidebars[$sidebar_name]['params'], $simplexml_parser->recursive_option_data($hw->params[0]->children())->option); } } //fetch assets foreach ($xml->xpath('/theme/assets') as $items) { $atts = $items->attributes(); $page = isset($atts['page']) ? (string) $atts['page'] : '__all__'; //group by page if (!isset($assets[$page])) { $assets[$page] = array(); } foreach ($items as $item) { $atts = $item->attributes(); $file = array(); $file['type'] = !empty($atts['type']) ? (string) $atts['type'] : ''; //dependencies if (!empty($atts['depends'])) { $file['depends'] = explode(',', (string) $atts['depends']); } else { $file['depends'] = false; } //handle if (!empty($atts['handle'])) { $file['handle'] = (string) $atts['handle']; } if (!empty($atts['ver'])) { $file['ver'] = (string) $atts['ver']; } //version $file['name'] = (string) $item; $assets[$page][] = $file; } } //fetch libs foreach ($xml->xpath('/theme/libs/lib') as $item) { $atts = $item->attributes(); $lib = isset($atts['name']) ? (string) $atts['name'] : (string) $item; $libs[] = $lib; } //fetch modules $modules_list = $xml->xpath('/theme/modules'); if ($modules_list) { $only_list = (string) $modules_list[0]->attributes()->only_list; } else { $only_list = 0; } if (!$only_list) { $installed_modules = HW_TGM_Module_Activation::get_register_modules(array('active' => 1, 'core' => 1), 'or'); #HW_Logger::log_file($installed_modules); //get installed modules, refer to core modules foreach ($installed_modules as $slug => $module) { $modules[$slug] = array('name' => $slug, 'status' => 1, 'core' => !empty($module['force_activation']), 'active' => 1); } } foreach ($xml->xpath('/theme/modules/module') as $item) { $atts = $item->attributes(); $module['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item; $module['status'] = isset($atts['status']) ? (string) $atts['status'] : 1; //active module as default $modules[$module['name']] = $module; } //fetch wp plugins foreach ($xml->xpath('/theme/plugins/plugin') as $item) { $atts = $item->attributes(); $plugin['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item; $plugin['status'] = isset($atts['status']) ? (string) $atts['status'] : 1; //active plugin as default $plugins[$plugin['name']] = $plugin; } //positions foreach ($xml->xpath('/theme/positions/position') as $item) { $atts = $item->attributes(); //valid hook name $name = isset($atts['name']) ? (string) $atts['name'] : (string) $item; $name = strtolower(HW_Validation::valid_objname($name)); //display text $text = (string) $item; if (empty($text) && $name) { $text = $name; } $positions[] = array('name' => $name, 'text' => $text); } unset($xml); return array('assets' => $assets, 'libs' => $libs, 'modules' => $modules, 'plugins' => $plugins, 'positions' => $positions, 'sidebars' => $sidebars, 'menus' => $menus, 'site' => $site, 'configuration' => $configuration); }
/** * valid classes attribute value * @param array|string $classes * @return string */ private function valid_classes_attr($classes) { HW_HOANGWEB::load_class('HW_Validation'); return HW_Validation::valid_classes_attr($classes); }
/** * 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 }
/** * localize script * @extend from HW_Module class * @param $handle * @param $object_name * @param array $data */ public function localize_script($handle, $object_name, $data = array()) { //validation if (!is_array($data)) { $data = array(); } #$module = $this->get_module_name(); //$handle = 'hw-module-'.$module.'-'. md5(self::get_file_name($file)); wp_localize_script($handle, HW_Validation::valid_objname($object_name), $data); }
/** * display slideshow images */ public function display_small_images() { extract($this->get_params()); //get all images $images = $this->get_images(); $setting = $this->get_params(); $out = '<div id="hw-product-slideShow" class="hw-ImageCarouselBox" style="margin: 10px auto 0;">'; //slideshow small images $out .= '<div class="' . $smallthumb_container_class . ' listImages">'; if (is_array($images) && count($images)) { $out .= '<ul class="' . $smallthumb_class . '">'; foreach ($images as $img) { $thumb_small = wp_get_attachment_image_src($img->ID, 'thumbnail'); //_print($thumb_small);//array('90','90') $thumb = wp_get_attachment_image_src($img->ID, 'medium'); $out .= sprintf("<li class='%s'><a href='%s' class='cloud-zoom-gallery %s' title='%s' rel='useZoom: \"{$this->cloudzoom_id}\", smallImage: \"%s\"'><img src='%s' class='%s' alt='%s' /></a></li>", $smallthumb_item_class, $img->guid, $smallthumb_anchor_class, $img->post_title, $thumb[0], $thumb_small[0], $smallthumb_img_class, $img->post_title); } $out .= '</ul>'; } $out .= '</div>'; $out .= '</div>'; $out .= "<script>jQuery(function(){jQuery('#" . $this->cloudzoom_id . "').CloudZoom();});</script>"; //css $css = array('.cloud-zoom-big' => array()); if (!empty($setting['zoombig_width'])) { $css['.cloud-zoom-big']['width'] = HW_Validation::format_unit($setting['zoombig_width']) . ' !important'; } if (!empty($setting['zoombig_height'])) { $css['.cloud-zoom-big']['height'] = HW_Validation::format_unit($setting['zoombig_height']) . ' !important'; } $out .= $this->generateCSS($css); echo $out; }