/** * 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; } //add posts 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']); $post_type = (string) $wp->post_type; $title = (string) $wp->title; //post/page.. if ((string) $atts->type != 'gallery' || $post_type != 'hw-gallery') { /*if(isset($hw->content) && ($hw->content->xpath('hw:params'))) { //$content = $this->get_result_content($hw->content[0]->params->children()); //is deprecated //$content = $this->get_import_result($hw->content[0]->params->children()); //$content = $this->recursive_option_data($hw->content->xpath('hw:params')); $content = $hw->content->xpath('hw:params'); foreach($hw->content->xpath('hw:params') as $content){break;}; } else $content = (string) $hw->content; */ $content = $this->get_hw_params_element($hw->content, 'hw:params', true); $this->posts->addItem(array('title' => $title, 'description' => '', 'content' => $content, 'post_type' => (string) $wp->post_type)); continue; } //skin data $skin = $hw->skin->children($this->namespaces['skin']); $skin_name = $hw->skin->attributes()->name ? (string) $hw->skin->attributes()->name : 'skin'; $skin_instance = (string) $skin->instance; //skin $pskin = new HWIE_Skin_Params($skin_name, $skin_instance); $pskin->add_hash_skin('hash_skin', array('skin' => (string) $skin->skin_name, 'source' => (string) $skin->source)); //other skin params $params = array('hwskin_condition' => '', 'skin_options' => array('enqueue_css_position' => 'footer', 'enqueue_js_position' => 'footer')); $pskin->add_skin_config(); if (!empty($skin->params)) { $skin_options = $this->simplexml_parser->recursive_option_data($skin->params[0]->children())->option; if (!empty($skin_options)) { $params = array_merge($params, $skin_options); } } $pskin->extra_params($params); //gallery data $galleries = array(); if (!empty($hw->data) && !empty($hw->data->item)) { foreach ($hw->data->item as $item) { //$this->simplexml_parser->recursive_option_data($item->children())->option; $gallery = HW_XML::xml2array($item->children()); if (!isset($gallery['src'])) { continue; } $gallery['status'] = !isset($gallery['status']) || $gallery['status'] ? 'active' : ''; if (!isset($gallery['link'])) { $gallery['link'] = $gallery['src']; } if (!isset($gallery['alt'])) { $gallery['alt'] = ''; } if (!isset($gallery['thumb'])) { $gallery['thumb'] = ''; } $galleries[] = $gallery; } } $post_name = $this->posts->addItem(array('title' => $title, 'description' => '', 'content' => '', 'excerpt' => '', 'post_type' => 'hw-gallery', 'post_metas' => array('_eg_gallery_data' => array('title' => $title, 'config' => array('columns' => '1', 'gutter' => '10', 'margin' => '10', 'crop' => '0', 'crop_width' => '960', 'crop_height' => '300', 'lightbox_enabled' => '1', 'title_display' => 'float', 'classes' => array(), 'title' => $title, 'slug' => '', 'rtl' => '0', 'hw_skin' => $pskin->get_skin(0)), 'gallery' => $galleries), '_eg_in_gallery' => array(), '_edit_last' => '1')), HW_XML::attributesArray($item)); } $this->add_export_widgets(); //import widgets if exists $this->do_import(); //start import data $posts = $this->importer->get_import_results('posts'); /*if(!empty($post_name) && isset($posts[$post_name])) { //don't need $gallery_id = $posts[$post_name]['ID']; //create page to display gallery wp_insert_post(array( 'post_type' => 'page', 'import_id' => 0, 'post_title' => 'Gallery', 'post_content' => '[hw-gallery id="'.$gallery_id.'"]', 'post_status' => 'publish', )); }*/ }
/** * @param $xml * @param array $namespaces * @return array */ public function build_skin_data(SimpleXMLElement $xml, $namespaces = null) { if (empty($namespaces)) { $namespaces = $this->namespaces; } #$node=dom_import_simplexml($xml);//dom_import_simplexml() #$n = $xml->getNameSpaces(false);_print($node->localName.','.$node->textContent); #$xml->getDocNamespaces(0); #if(empty($n)) return; HW_HOANGWEB::load_class('HW_File_Directory'); if (empty($namespaces)) { $namespaces = $this->valid_namespaces($xml); } $skin_tag = $xml->xpath('params:skin_encoded'); $data = array(); if (!empty($skin_tag) || count($xml->xpath('params:skin_instance'))) { $params = $xml->children($namespaces['params']); $hash_skin = array(); $skin_config = array(); $apply_plugin = ''; $skin_name = ''; $skin_data = array(); $screenshot = ''; $screenshot_ext = 'jpg'; /*if(isset($skin->apply_plugin)) { //apply skin $apply_plugin = (string) $skin->apply_plugin ; } else*/ if (isset($skin_data['apply_plugin'])) { $apply_plugin = $skin_data['apply_plugin']; } else { $apply_plugin = ''; //leave empty for hw-hoangweb plugin } //for skin link if (!empty($params->skin_file) && HW_XML::count_childs($params->skin_file)) { $atts = $params->skin_file->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'url'; //skin_config //get skin data if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } $skin = $params->skin_file->children($namespaces['skin']); $hash_skin['type'] = ''; //get source if (isset($skin->source)) { $hash_skin['source'] = (string) $skin->source; } else { $hash_skin['source'] = 'plugin'; } $file_link = (string) $skin->file; $skin_file_name = isset($atts['name']) ? (string) $atts['name'] : 'url'; //get group if (isset($skin->group)) { $group = (string) $skin->group; } elseif (isset($skin_config['group'])) { $group = $skin_config['group']; } elseif (isset($skin_data['group'])) { $group = $skin_data['group']; } //$hash_skin = HW_SKIN::valid_holder_path($apply_plugin, $hash_skin); /*$file_url = HW_File_Directory::generate_url(HW_HOANGWEB_PLUGINS_URL,$apply_plugin, $skin_config['default_skin_path'], $group, $file_link ); //$hash_skin['screenshot_url'] = $hash_skin['file_url'] = $file_url; */ $hash_skin['file'] = $hash_skin['name'] = $file_link; //$data[isset($atts['name'])? (string) $atts['name']: 'url'] = $file_url ; } //parse hash_skin value if (isset($params->skin_encoded) && HW_XML::count_childs($params->skin_encoded)) { $atts = $params->skin_encoded->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'hash_skin'; //default hash_skin field-> not allow to update if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } #$params->skin_encoded->xpath('skin:skins_path'); $skin = $params->skin_encoded->children($namespaces['skin']); if (isset($skin->apply_plugin)) { //apply skin $apply_plugin = (string) $skin->apply_plugin; } elseif (isset($skin_data['apply_plugin'])) { $apply_plugin = $skin_data['apply_plugin']; } else { $apply_plugin = ''; //leave empty for hw-hoangweb plugin } //get source if (isset($skin->source)) { $hash_skin['source'] = (string) $skin->source; } else { $hash_skin['source'] = 'plugin'; } //skin name /*if(isset($skin->skin_name)) { $skin_name = (string) $skin->skin_name; } else*/ if (isset($skin_data['skin_name'])) { $skin_name = $skin_data['skin_name']; } //$hash = array('skins_path', ''); $hash_skin['holder'] = $apply_plugin; if ($apply_plugin) { $hash_skin = HW_SKIN::valid_holder_path($apply_plugin, $hash_skin); } else { //refer to hw-hoangweb plugin if (!file_exists($hash_skin['holder'])) { $hash_skin['holder'] = ''; #HW_HOANGWEB_PATH. DIRECTORY_SEPARATOR; $hash_skin['holder_url'] = ''; //HW_HOANGWEB_URL ; } } if (isset($skin->screenshot)) { //screenshot $screenshot = (string) $skin->screenshot; } /*elseif(isset($skin_data['screenshot'])) { $screenshot = $skin_data['screenshot']; }*/ if (isset($skin->skin_type)) { //skin type $hash_skin['type'] = (string) $skin->skin_type; } elseif (isset($skin_data['skin_type'])) { $hash_skin['type'] = $skin_data['skin_type']; } //group if (isset($skin->group)) { $hash_skin['group'] = (string) $skin->group; } elseif (isset($skin_data['group'])) { $hash_skin['group'] = $skin_data['group']; } else { $hash_skin['group'] = ''; } if (isset($skin->default_folder)) { //skins path $hash_skin['default_folder'] = (string) $skin->default_folder; } elseif (isset($skin_data['default_skin_path'])) { $hash_skin['default_folder'] = $skin_data['default_skin_path']; } //skin_folder if ($hash_skin['type'] == 'file') { $hash_skin['skin_folder'] = $hash_skin['default_folder'] . '/' . $hash_skin['group']; } else { $hash_skin['skin_folder'] = $hash_skin['default_folder']; } if ($hash_skin['type'] === 'link') { //path $hash_skin['path'] = rtrim($hash_skin['group'], '\\/') . '/'; } else { if (isset($skin->skin)) { //skin folder $hash_skin['path'] = (string) $skin->skin; } elseif (isset($skin_data['default_skin'])) { $hash_skin['path'] = $skin_data['default_skin']; } } $hash_skin['path'] = rtrim($hash_skin['path'], '\\/') . '/'; //valid $full_holder = HW_SKIN::get_skin_realpath(array('path' => $hash_skin['holder']), $hash_skin['source'])->path; $skin_path = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['group'], $hash_skin['path']); //screenshot mimetype /*if(isset($skin->screenshot_mimetype)) { //no, we auto find screenshot mimetype $screenshot_ext = (string) $skin->screenshot_mimetype; }*/ $screenshot_ext = file_exists($skin_path . '/screenshot.png') ? 'png' : 'jpg'; //skin name if ($hash_skin['type'] == 'file' && $skin_name) { $hash_skin['filename'] = $skin_name; } #else $hash_skin['file'] = $skin_name; //for skin link, do it above if (isset($skin->title) && !isset($hash_skin['name'])) { //title $hash_skin['name'] = (string) $skin->title; } else { if (isset($hash_skin['holder']) && isset($hash_skin['default_folder']) && !isset($hash_skin['name'])) { if (isset($skin_data['template_header'])) { $header = $skin_data['template_header']; } else { $header = array('name' => 'HW Template', 'description' => 'Description', 'author' => 'Author', 'uri' => 'Author URI'); } if ($hash_skin['type'] == 'file') { $skin_file = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['group'], $hash_skin['path']) . '/' . $skin_name; } else { $skin_file = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['path']) . '/' . $skin_name; } $temp_header = HW_SKIN::get_template_data($skin_file, 0, $header); $hash_skin['name'] = $temp_header['name']; } } $hash_skin['skin_url'] = HW_File_Directory::generate_url($hash_skin['holder_url'], $hash_skin['skin_folder'], $hash_skin['path']); if (isset($skin_file_name) && isset($file_link)) { $hash_skin['file_url'] = HW_File_Directory::generate_url($hash_skin['skin_url'], $file_link); $data[$skin_file_name] = $hash_skin['screenshot_url'] = $hash_skin['file_url']; } /*if($screenshot && !isset($hash_skin['screenshot_url'])) { //skin screenshot $hash_skin['screenshot_url'] = $screenshot; if(!HW_Validation::hw_valid_url($hash_skin['screenshot_url'])) { $hash_skin['screenshot_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL, $hash_skin['screenshot_url']); } } else*/ if (!isset($hash_skin['screenshot_url'])) { $hash_skin['screenshot_url'] = HW_File_Directory::generate_url($hash_skin['skin_url'], 'screenshot.' . ltrim($screenshot_ext, '.')); //default jpg mimetype } //valid hash skin value if (count($hash_skin) < 7) { return; } //$hash_skin = hwArray::sortArrayByArray($hash_skin, array('skins_path','skin_folder','skin_url','skin_type','title','screenshot','skin_name')); if (isset($hash_skin['type']) && $hash_skin['type'] == 'file') { $hash_skin_value = HW_SKIN::generate_skin_path($hash_skin); } else { $hash_skin_value = HW_SKIN::generate_skin_file($hash_skin); } #__print(($hash_skin));exit; $data[isset($atts['name']) ? (string) $atts['name'] : 'hash_skin'] = $hash_skin_value; } //parse skin config if (isset($params->skin_instance)) { $atts = $params->skin_instance->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'skin_config'; //skin_config if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } $skin = $params->skin_instance->children($namespaces['skin']); //get default values if (isset($skin->apply_plugin) && !$apply_plugin) { //apply_plugin $apply_plugin = (string) $skin->apply_skin; } elseif (isset($skin_data['apply_plugin']) && !$apply_plugin) { $apply_plugin = $skin_data['apply_plugin']; } if (isset($skin->skin_name) && !$skin_name) { //skin_name $skin_name = (string) $skin->skin_name; } elseif (isset($skin_data['skin_name']) && !$skin_name) { $skin_name = $skin_data['skin_name']; } //grab /*if(isset($skin->apply_current_path)) { //apply_current_path $skin_config['apply_current_path'] = (string) $skin->apply_current_path; if(!file_exists($skin_config['apply_current_path'])) { $skin_config['apply_current_path'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS, $skin_config['apply_current_path']); } } if(isset($skin->plugin_url)) { //plugin_url $skin_config['plugin_url'] = (string) $skin->plugin_url; if(!HW_Validation::hw_valid_url($skin_config['plugin_url'])) { $skin_config['plugin_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL , $skin_config['plugin_url']); } }*/ if (isset($skin->other_folder)) { //other_folder $skin_config['other_folder'] = (string) $skin->other_folder; } elseif (isset($skin_data['other_folder'])) { $skin_config['other_folder'] = $skin_data['other_folder']; } if ($skin_name) { //skin_name $skin_config['skin_name'] = $skin_name; } if (isset($skin->default_skin_path)) { //default_skin_path $skin_config['default_skin_path'] = (string) $skin->default_skin_path; } elseif (isset($skin_data['default_skin_path'])) { $skin_config['default_skin_path'] = $skin_data['default_skin_path']; } if (isset($skin->group)) { //group $skin_config['group'] = (string) $skin->group; } elseif (isset($skin_data['group'])) { $skin_config['group'] = $skin_data['group']; } if (isset($skin->enable_external_callback)) { //enable_external_callback $skin_config['enable_external_callback'] = (string) $skin->enable_external_callback; } elseif (isset($skin_data['enable_external_callback'])) { $skin_config['enable_external_callback'] = $skin_data['enable_external_callback']; } //allow skin names if (isset($skin->allows_skin_names)) { $skin_config['allows_skin_names'] = HW_XML::xml2array($skin->allows_skin_names->children(), 'param', 'params'); } elseif (isset($skin_data['allows_skin_names'])) { $skin_config['allows_skin_names'] = $skin_data['allows_skin_names']; } //properties if (isset($skin->properties)) { $skin_config['properties'] = HW_XML::xml2array($skin->properties->children(), 'param', 'params'); } elseif (isset($skin_data['properties'])) { $skin_config['properties'] = $skin_data['properties']; } //options if (isset($skin->options)) { $skin_config['options'] = HW_XML::xml2array($skin->properties->children(), 'param', 'params'); } elseif (isset($skin_data['options'])) { $skin_config['options'] = $skin_data['options']; } if ($apply_plugin && !isset($skin_config['apply_current_path'])) { //$skin_config["apply_current_path"] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS,$apply_plugin); $skin_config["apply_current_path"] = $apply_plugin; } if ($apply_plugin && !isset($skin_config['plugin_url'])) { //$skin_config['plugin_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL, $apply_plugin); $skin_config['plugin_url'] = $apply_plugin; } //other params $other_config_params = HW_XML::xml2array($params->skin_instance->children(), 'param', 'params'); //fix if (!isset($other_config_params['allows_skin_names'])) { $other_config_params['allows_skin_names'] = array(); } elseif (isset($skin_data['allows_skin_names'])) { $other_config_params['allows_skin_names'] = $skin_data['allows_skin_names']; } if (isset($skin_config['skin_name']) && !in_array($skin_config['skin_name'], $other_config_params['allows_skin_names'])) { $other_config_params['allows_skin_names'][] = $skin_config['skin_name']; } if (!empty($other_config_params)) { $skin_config = array_merge($skin_config, $other_config_params); } $data[isset($atts['name']) ? (string) $atts['name'] : 'skin_config'] = HW_SKIN::generate_skin_config($skin_config); } //other params $data = array_merge($data, HW_XML::xml2array($xml)); /*$atts = $xml->attributes(); //get attributes if(isset($atts['name'])) { $data = array((string)$atts['name'] => $data); }*/ return count($data) ? $data : null; } }