/** * @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; }
/** * 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(); }
/** * get real field name * @param $name * @return mixed */ public function real_field_name($name) { $prefix = HW_Validation::valid_apf_slug($this->feature_name); return preg_replace('#^' . $prefix . '_#', '', trim($name)); }
/** * 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); }
/** * 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 field id * @param string $field * @return mixed */ public function get_field_id($field = '') { return HW_Validation::valid_apf_slug($this->get_field_name($field)); }
/** * 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; }
/** * 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); }