/**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * @param $data
  */
 public function add_export($data)
 {
     HW_XML::mergeDom(array($data), $this->export_widgets);
 }
 /**
  * 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',
           ));
       }*/
 }
 /**
  * define new skin
  * @param $name skin name
  * @param array $args skin params
  */
 public function add_skin($name, $args = array())
 {
     if ($this->get($name)) {
         return;
     }
     //already exists
     $skin = $this->createElement('hw:skin');
     $skin->setAttribute('name', $name);
     $allow_keys = array('default_skin_path', 'default_skin', 'skin_type', 'skin_name', 'other_folder', 'group', 'enable_external_callback', 'list', 'properties', 'options');
     //get apply skin
     if (!empty($args['apply_plugin'])) {
         $apply_plugin = $args['apply_plugin'];
     } else {
         $apply_plugin = $this->base->get_module()->option('module_name');
     }
     $item = $this->createElement('skin:apply_plugin', $this->cdata($apply_plugin));
     $skin->appendChild($item);
     if (is_array($args)) {
         foreach ($args as $key => $value) {
             if (!in_array($key, $allow_keys)) {
                 continue;
             }
             if (is_string($value)) {
                 $item = $this->createElement('skin:' . $key, $this->cdata($value));
             } elseif (is_array($value)) {
                 $item = $this->createElement('skin:' . $key);
                 $aParams = HW_XML::array_to_xml_params($value, 'param', 'params');
                 $item->appendChild($this->importNode(dom_import_simplexml($aParams), true));
             }
             $skin->appendChild($item);
         }
     }
     $this->add($name, $skin);
     $this->skins->appendChild($skin);
 }
 /**
  * @param $string
  * @param $tag
  * @Param $xml_object return xml in object without string
  * @return mixed|string
  */
 function get_tag($string, $tag, $xml_object = false)
 {
     preg_match("|<{$tag}.*?>(.*?)</{$tag}>|is", $string, $return);
     if (isset($return[1])) {
         if (substr($return[1], 0, 9) == '<![CDATA[') {
             if (strpos($return[1], ']]]]><![CDATA[>') !== false) {
                 preg_match_all('|<!\\[CDATA\\[(.*?)\\]\\]>|s', $return[1], $matches);
                 $return = '';
                 foreach ($matches[1] as $match) {
                     $return .= $match;
                 }
             } else {
                 $return = preg_replace('|^<!\\[CDATA\\[(.*)\\]\\]>$|s', '$1', $return[1]);
             }
         } else {
             $return = $return[1];
         }
     } else {
         $return = '';
     }
     if ($xml_object && trim($return) && HW_XML::string_is_xml_format($return)) {
         return HWIE_Param::string2xml_withNS($return);
     }
     return $return;
 }