/** * ajax handle callback * @hook wp_ajax_{hw_help_popup} */ function hw_ajax_hw_help_popup() { if (!wp_verify_nonce($_REQUEST['nonce'], "hw-module-help-nonce")) { exit("No naughty business please"); } if (!isset($_REQUEST['file'])) { return; } HW_HOANGWEB::load_class('HW_WP'); //enqueue syntax highlighter library if (class_exists('HW_Libraries', false)) { HW_Libraries::enqueue_jquery_libs('syntaxhighlighter_3.0.83'); HW_Libraries::get('syntaxhighlighter_3.0.83')->enqueue_scripts('shBrushJScript.js', 'shBrushXml.js', 'shBrushPhp.js'); } $file = HW_Encryptor::decrypt(urldecode($_REQUEST['file'])); if (file_exists($file)) { echo file_get_contents($file); } HW_WP::hw_clean_wp_head(); //wp_head(); wp_footer(); //init SyntaxHighlighter echo ' <script type="text/javascript"> //SyntaxHighlighter if(typeof SyntaxHighlighter != "undefined") SyntaxHighlighter.all(); </script> '; die; }
/** * export module data to wxr format (module data mean short data written for module) * @param $xml */ function export_wxr_data($xml = null) { foreach ($this->get_posts_xml($xml) as $item) { $atts = $item->attributes(); //get xml element attributes $hw = $item->children($this->namespaces['hw']); $wp = $item->children($this->namespaces['wp']); $title = (string) $wp->title; //get skins $skins = $this->fetch_skins($hw->skin, 'hash_skin', 'hwskin_config', 0, false); //source path $source = (string) $hw->source; #if(!file_exists($source)) $source = get_stylesheet_directory().'/' .$source; $settings = $this->recursive_option_data($hw->settings->children())->option; if (isset($skins['theme'])) { $settings['theme'] = $skins['theme']->get_hash_skin_code(); } $this->run_cli('add_slider', array('title' => $title, 'source' => 'upload', 'num' => '3', 'from_path' => 'theme', 'source_path' => $source, 'settings' => HW_Encryptor::encode64($settings))); } $this->add_export_widgets(); $this->do_import(); }
/** * @param $data * @param bool $str_output */ protected static function build_special_params($str = array(), $str_output = false) { $dom = new DOMDocument(self::XML_VERSION, self::XML_ENCODING); if (HW_Encryptor::is_serialize_base64($str)) { $data = unserialize(base64_decode($str)); if (is_array($data)) { #$data = unserialize($data);# //belong to skin config if (is_array($data) && isset($data['skin_name']) && isset($data['default_skin_path']) && isset($data['apply_current_path']) && isset($data['plugin_url'])) { $what_skin = rtrim($data['skin_name'], '.php'); //get skin information $pskin = new HWIE_Skin_Params('skin', $what_skin); $pskin->add_skin_config('hwskin_config', array('group' => !empty($data['group']) ? $data['group'] : '')); /*$skin_instance = $dom->createElement('params:skin_instance'); $skin_instance->setAttribute('name', 'hwskin_config'); $skin_instance->setAttribute('instance', $what_skin); if(!empty($data['group'])) { $skin_instance->appendChild($dom->createElement('skin:group', $data['group'])); } $dom->appendChild($skin_instance);*/ $dom->appendChild($dom->importNode($pskin->get_skinconfig(0), true)); } } elseif (is_string($data) && count(explode('|', $data)) >= 8) { $skin = explode('|', $data); if (in_array(end($skin), array('theme', 'plugin', 'wp_content'))) { $what_skin = rtrim($skin[6], '.php'); //create skin instance $pskin = new HWIE_Skin_Params('skin', $what_skin); $pskin->add_hash_skin('hash_skin', array('skin' => trim($skin[1], '\\/'), 'skin_type' => $skin[3], 'source' => end($skin))); /*$hash_skin = $dom->createElement('params:skin_encoded'); $hash_skin->setAttribute('name', 'hash_skin'); $hash_skin->setAttribute('instance', $what_skin); //skin ns $hash_skin->appendChild($dom->createElement('skin:skin', trim($skin[1], '\/'))); //skin_type ns $hash_skin->appendChild($dom->createElement('skin:skin_type', $skin[3])); $dom->appendChild($hash_skin) ;*/ $dom->appendChild($dom->importNode($pskin->get_hash_skin(0), true)); } } return $str_output ? HW_XML::output_dom_to_string($dom, true) : $dom->documentElement; } return false; }
/** * generate help link with popup content * @param $file path of file help not link * @param $text anchor text link * @param $title dialog title */ public static function generate_help_popup($file, $text = '', $title = '') { //get help file path $file = self::get_help_popup_file($file); //valid if (!is_string($file)) { return '<em>Không tìm thấy file help.</em>'; } if (empty($text)) { $text = __('Hướng dẫn'); } //valid if (empty($title)) { $title = $text; } $ajax_url = HW_HOANGWEB_AJAX; //HW_HELP_AJAX $ajax_url .= '?action=hw_help_popup&include_head=1&include_footer=1&file=' . urlencode(HW_Encryptor::encrypt($file)); if (is_multisite()) { $ajax_url .= '&blog=' . get_current_blog_id(); } return sprintf('<a href="%s" class="hw-help-link-popup" title="%s">%s</a>', $ajax_url, $title, $text); }
/** * 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.'); }
/** * 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; }
/** * get import item result * @param $field * @param string $name * @return string */ public function get_results($field = '', $type = '', $name = '') { global $wpdb; static $result = array(); $sql = 'select * from ' . self::TRACKING_SQL_TABLE; if ($type) { $sql .= ' where _type="' . $type . '"'; } #HW_Logger::log_file($sql); if (empty($result[$sql])) { //$data = !HW_Cache::_get_transient('hw_importer_results'); //alway be get new data //if(!$data) { $data = $wpdb->get_results($sql, ARRAY_A); foreach ($data as $id => $row) { if (HW_Encryptor::is_serialize_base64($row['value'])) { //for type not is string $row['value'] = HW_Encryptor::decode64($row['value']); //unserialize($row['value']); } $data[$row['name']] = $field && isset($row[$field]) ? $row[$field] : $row; unset($data[$id]); } $result[$sql] = $data; //HW_Cache::_set_transient('hw_importer_results', $data); //} } return $name ? isset($result[$sql][$name]) ? $result[$sql][$name] : '' : $result[$sql]; }
/** * config data * @param $values * @param $fieldname */ public static function config($values, $fieldname) { if (!isset($values[$fieldname])) { return; } //valid form data self::valid_form_data(); if (!empty($values[$fieldname]['config'])) { $configuration = HW_Encryptor::decrypt($values[$fieldname]['config']); } else { $configuration = array(); } return (object) $configuration; }