/**
  * 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();
         $option = (string) $atts['name'];
         $hw = $item->children($this->namespaces['hw']);
         //admin page setting
         if ($option == 'download_attachments_general') {
             $setting = array('capabilities' => array('manage_download_attachments'), 'deactivation_delete' => '', 'backend_columns' => array('id' => '1', 'author' => '1', 'title' => '1', 'type' => '1', 'size' => '1', 'date' => '1', 'downloads' => '1'), 'backend_content' => array('caption' => '1', 'description' => '1'), 'attachment_link' => 'modal', 'library' => 'all', 'downloads_in_media_library' => '1', 'use_css_style' => '0', 'pretty_urls' => "", 'download_link' => 'download');
             $data = $this->simplexml_parser->recursive_option_data($item->children())->option;
             if (!empty($data)) {
                 $setting = array_merge($setting, $data);
             }
             $this->options->add_option($option, $setting);
         }
         //module tab setting
         if ($option == 'HW_Module_Settings_page') {
             $setting = array('content_before' => (string) $hw->content_before, 'content_after' => (string) $hw->content_after);
             $skin_name = (string) $hw->skin->attributes()->name;
             $skin = $hw->skin->children($this->namespaces['skin']);
             //skin
             $pskin = new HWIE_Skin_Params($skin_name, (string) $skin->instance);
             $pskin->add_hash_skin('hash_skin', array('skin' => (string) $skin->skin_name, 'source' => (string) $skin->source));
             $pskin->add_skin_config();
             $setting[$skin_name] = $pskin->get_skin(0);
             //other params
             if (!empty($hw->params)) {
                 $other = $this->simplexml_parser->recursive_option_data($hw->params[0]->children())->option;
                 $setting = array_merge($setting, $other);
             }
             $this->options->add_module_setting_page($setting);
         }
     }
     $this->do_import();
 }
Пример #2
0
 /**
  * fetch skins
  * @param $skins
  * @param string $fhash_skin
  * @param string $fconfig_name
  * @param array $extra
  * @param bool $compac_skin
  */
 public function fetch_skins($skins, $fhash_skin = 'hash_skin', $fconfig_name = 'hwskin_config', $extra = array(), $compac_skin = true)
 {
     $result = array();
     if (!empty($skins)) {
         foreach ($skins as $skin) {
             $name = (string) $skin->attributes()->name;
             $_skin = $skin->children($this->namespaces['skin']);
             $skin_type = !empty($_skin->skin_type) ? (string) $_skin->skin_type : 'file';
             //skin
             $pskin = new HWIE_Skin_Params($name ? $name : 'skin', (string) $_skin->instance);
             //skins data for current module
             $pskin->skins_data = HWIE_Param::dom_to_simplexml($this->skins->documentElement, 'SimpleXMLElement', 'params');
             $pskin->add_hash_skin($fhash_skin, array('skin' => (string) $_skin->skin_name, 'file' => (string) $_skin->file, 'source' => (string) $_skin->source, 'group' => (string) $_skin->group, 'skin_type' => $skin_type));
             #$pskin->add_skin_config();
             $pskin->add_skin_config($fconfig_name, array('group' => (string) $_skin->group));
             $extra_params = array('hwskin_condition' => "", 'skin_options' => array('enqueue_css_position' => 'footer', 'enqueue_js_position' => 'footer'));
             if ($skin_type == 'link') {
                 $pskin->add_skin_file('url', array('file' => (string) $_skin->file));
             }
             if (!empty($_skin->params)) {
                 $skin_params = $this->simplexml_parser->recursive_option_data($_skin->params->children())->option;
                 if (!empty($skin_params)) {
                     $extra_params = array_merge($extra_params, $skin_params);
                 }
             }
             if (is_array($extra) && count($extra)) {
                 $extra_params = array_merge($extra_params, $extra);
             }
             $pskin->extra_params($extra_params);
             $result[$name] = $compac_skin ? $pskin->get_skin(false) : $pskin;
             #$pskin->parse_skin_values();
         }
     }
     return $result;
 }
 /**
  * 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',
           ));
       }*/
 }
    /**
     * export module data to wxr format (module data mean short data written for module)
     * @param $xml
     */
    public function export_wxr_data($xml = null)
    {
        #$this->test();return;
        if (empty($xml)) {
            $xml = $this->xml_data;
        }
        $module = $this->get_module()->option('module_name');
        foreach ($this->get_posts_xml($xml) as $item) {
            $item_atts = (array) $item->attributes();
            //get xml element attributes
            $wp = $item->children($this->namespaces['wp']);
            $hw = $item->children($this->namespaces['hw']);
            $title = (string) $wp->title;
            $form = $hw->form_html->children($this->namespaces['hw']);
            $form_html = (string) $form->html;
            if (!empty($hw->mail)) {
                //$mail = self::array_to_xml_params($hw->mail, false);
                $mail = dom_import_simplexml($hw->mail);
            } else {
                $mail = array();
            }
            //form skin
            $atts = $hw->skin->attributes();
            $skin = $hw->skin->children($this->namespaces['skin']);
            $skin_name = $atts['name'] ? $atts['name'] : 'skin';
            /*$skin_instance = !empty($skin->instance)? (string) $skin->instance : 'hw-wpcf7';
                        $skin_source = !empty($skin->source)? (string) $skin->source : 'plugin';
            
                        $pskin = new HWIE_Skin_Params(($atts['name']? $atts['name'] : 'skin'), $skin_instance);
                        $pskin->add_hash_skin('hash_skin', array(
                            'skin' => (string)$skin->skin_name,
                            'source' => $skin_source
                        ));
                        $pskin->add_skin_config();
            
                        $params = array(
                            'hwskin_condition' => '',
                            'skin_options' => array(
                                'enqueue_css_position' => 'head',
                                'enqueue_js_position' => 'footer'
                            )
                        );
                        if(!empty($skin->params)) {
                            $skin_params = $this->simplexml_parser->recursive_option_data($skin->params)->option;
                            if(!empty($skin_params)) $params = array_merge($params, $skin_params);
                        }
                        $pskin->extra_params($params);
                        */
            $skins = $this->fetch_skins($skin, 'hash_skin', 'hwskin_config', 0, false);
            //google form id
            if (isset($hw->google_formID)) {
                $gform_id = (string) $hw->google_formID;
            } else {
                $gform_id = '1GzynAtb3hiv6E0mFE0KhxMwARSYGdGSY8oJ5ImGM7m4';
            }
            $this->posts->addItem(array('title' => $title, 'description' => '', 'content' => '', 'excerpt' => '', 'post_type' => 'wpcf7_contact_form', 'post_metas' => array('_wpcf7-form' => $form_html, '_form' => $form_html, '_mail' => $mail, '_mail_2' => array('active' => '0', 'subject' => '', 'sender' => '', 'body' => '', 'recipient' => '', 'additional_headers' => ''), '_messages' => array('mail_sent_ok' => '', 'mail_sent_ng' => '', 'validation_error' => '', 'spam' => '', 'accept_terms' => '', 'invalid_required' => '', 'invalid_too_long' => '', 'invalid_too_short' => ''), '_additional_settings' => 'on_sent_ok: ""
on_submit: ""', '_locale' => 'vi', '_hw_wpcf7_use_skin' => 'on', '_hw_wpcf7_skin' => $skins[$skin_name]->get_hash_skin(), '_hw_wpcf7skin_setting' => $skins[$skin_name]->get_skin(), '_hw_custom_css' => '', '_hw_form_template' => 'basic-contact-form', '_hw_gformID' => $gform_id, '_enable_email_by_gapp' => 'on', '_hook_url' => '', '_hwcf_data_hook' => 'google_form', '_hw_sent_ok_redirect_page' => '-1', '_hw_on_sent_ok_js_event' => '', '_hw_on_submit_js_event' => '', '_hw_default_gform' => '', '_hw_form_class_attr' => (string) $form->form_class, '_hw_form_id_attr' => (string) $form->form_id, '_hw_form_name_attr' => (string) $form->form_name, '_hw_form_enctype_attr' => (string) $form->form_enctype)), $item_atts['@attributes']);
            /*$ele=new HWIE_Param('params:skin_encoded', array('instance'=> $module, 'name' => 'hash_skin'));
              $ele->add_child('skin:skin', 'skin1');
              $ele->add_child('skin:skin_type', 'file');*/
        }
        //set options
        foreach ($this->get_options_xml($xml) as $item) {
            $atts = $item->attributes();
            $name = !empty($atts['name']) ? (string) $atts['name'] : 'loadingImg';
            $hw = $item->children($this->namespaces['hw']);
            $skin = $hw->skin->children($this->namespaces['skin']);
            $skin_instance = !empty($skin->instance) ? (string) $skin->instance : 'hwcf7_images';
            $skin_source = !empty($skin->source) ? (string) $skin->source : 'plugin';
            $group = (string) $skin->group;
            //wpcf7 loading
            $skin_image = new HWIE_Skin_Params($name, $skin_instance);
            $skin_image->add_hash_skin('hash_skin', array('skin' => (string) $skin->skin_name, 'source' => $skin_source, 'skin_type' => (string) $skin->skin_type, 'group' => $group));
            $skin_image->add_skin_config('hwskin_config', array('group' => $group));
            $skin_image->add_skin_file('url', array('file' => (string) $skin->file));
            break;
        }
        if (isset($skin_image)) {
            $this->options->add_option('HW_Wpcf_settings', array('general' => array('enable_wpcf7_css' => '1', 'enable_wpcf7_js' => '1', 'exclude_pages' => array('__all__'), 'loadingImg' => $skin_image->get_skin(false)), 'webhook' => array('webhook_url' => '')));
        }
        //start import
        $this->do_import();
    }