/**
 * Functions for handling WordPress import to make it compatable with WooCommerce
 *
 * WordPress import should work - however, it fails to import custom product attribute taxonomies.
 * This code grabs the file before it is imported and ensures the taxonomies are created.
 *
 * @author 		WooThemes
 * @category 	Admin
 * @package 	WooCommerce
 */
function woocommerce_import_start()
{
    global $wpdb;
    $id = (int) $_POST['import_id'];
    $file = get_attached_file($id);
    $parser = new WXR_Parser();
    $import_data = $parser->parse($file);
    if (isset($import_data['posts'])) {
        $posts = $import_data['posts'];
        if ($posts && sizeof($posts) > 0) {
            foreach ($posts as $post) {
                if ($post['post_type'] == 'product') {
                    if ($post['terms'] && sizeof($post['terms']) > 0) {
                        foreach ($post['terms'] as $term) {
                            $domain = $term['domain'];
                            if (strstr($domain, 'pa_')) {
                                // Make sure it exists!
                                if (!taxonomy_exists($domain)) {
                                    $nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
                                    $exists_in_db = $wpdb->get_var("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';");
                                    if (!$exists_in_db) {
                                        // Create the taxonomy
                                        $wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select'), array('%s', '%s'));
                                    }
                                    // Register the taxonomy now so that the import works!
                                    register_taxonomy($domain, array('product'), array('hierarchical' => true, 'labels' => array('name' => $nicename, 'singular_name' => $nicename, 'search_items' => __('Search', 'woothemes') . ' ' . $nicename, 'all_items' => __('All', 'woothemes') . ' ' . $nicename, 'parent_item' => __('Parent', 'woothemes') . ' ' . $nicename, 'parent_item_colon' => __('Parent', 'woothemes') . ' ' . $nicename . ':', 'edit_item' => __('Edit', 'woothemes') . ' ' . $nicename, 'update_item' => __('Update', 'woothemes') . ' ' . $nicename, 'add_new_item' => __('Add New', 'woothemes') . ' ' . $nicename, 'new_item_name' => __('New', 'woothemes') . ' ' . $nicename), 'show_ui' => false, 'query_var' => true, 'rewrite' => array('slug' => strtolower(sanitize_title($nicename)), 'with_front' => false, 'hierarchical' => true)));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 2
0
 public function importwxr()
 {
     $this->requireUserPermission('extensions');
     // \util::var_dump($this->config);
     $filename = __DIR__ . "/" . $this->config['file'];
     $file = realpath(__DIR__ . "/" . $this->config['file']);
     $output = "";
     $this->foundcategories = array();
     // No logging. saves memory..
     $this->app['db.config']->setSQLLogger(null);
     if (!empty($_GET['action'])) {
         $action = $_GET['action'];
     } else {
         $action = "start";
     }
     require_once "src/parsers.php";
     $parser = new \WXR_Parser();
     switch ($action) {
         case "start":
             if (empty($file) || !is_readable($file)) {
                 $output .= "<p>File {$filename} doesn't exist. Correct this in <code>app/extensions/ImportWXR/config.yml</code>, and refresh this page.</p>";
             } else {
                 $output .= sprintf("<p>File <code>%s</code> selected for import.</p>", $this->config['file']);
                 $output .= "<p><a class='btn btn-primary' href='?action=dryrun'><strong>Test a few records</strong></a></p>";
                 $output .= "<p>This mapping will be used:</p>";
                 $output .= \util::var_dump($this->config['mapping'], true);
             }
             break;
         case "confirm":
             $res = $parser->parse($file);
             foreach ($res['posts'] as $post) {
                 $output .= $this->importPost($post, false);
             }
             $output .= "<p><strong>Done!</strong></p>";
             if (!empty($this->foundcategories)) {
                 $output .= "<p>These categories were found, make sure you add them to your <code>taxonomy.yml</code></p>";
                 $output .= "<textarea style='width: 400px;'>" . json_encode($this->foundcategories) . "</textarea>";
             }
             break;
         case "dryrun":
             $counter = 1;
             $res = $parser->parse($file);
             foreach ($res['posts'] as $post) {
                 $output .= $this->importPost($post, true);
                 if ($counter++ >= 4) {
                     break;
                 }
             }
             $output .= sprintf("<p>Looking good? Then click below to import the Records: </p>");
             $output .= "<p><a class='btn btn-primary' href='?action=confirm'><strong>Confirm!</strong></a></p>";
     }
     unset($res);
     return $this->app['render']->render('base.twig', array('title' => "Import WXR (PivotX / Wordpress XML)", 'content' => $output));
 }
/**
 * When running the WP importer, ensure attributes exist.
 *
 * @access public
 * @return void
 */
function woocommerce_import_start()
{
    global $wpdb;
    if (!isset($_POST['import_id'])) {
        return;
    }
    if (!class_exists('WXR_Parser')) {
        return;
    }
    $id = (int) $_POST['import_id'];
    $file = get_attached_file($id);
    $parser = new WXR_Parser();
    $import_data = $parser->parse($file);
    if (isset($import_data['posts'])) {
        $posts = $import_data['posts'];
        if ($posts && sizeof($posts) > 0) {
            foreach ($posts as $post) {
                if ($post['post_type'] == 'product') {
                    if ($post['terms'] && sizeof($post['terms']) > 0) {
                        foreach ($post['terms'] as $term) {
                            $domain = $term['domain'];
                            if (strstr($domain, 'pa_')) {
                                // Make sure it exists!
                                if (!taxonomy_exists($domain)) {
                                    $nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
                                    $exists_in_db = $wpdb->get_var("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';");
                                    if (!$exists_in_db) {
                                        // Create the taxonomy
                                        $wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select'), array('%s', '%s'));
                                    }
                                    // Register the taxonomy now so that the import works!
                                    register_taxonomy($domain, array('product'), array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  * When running the WP importer, ensure attributes exist.
  *
  * WordPress import should work - however, it fails to import custom product attribute taxonomies.
  * This code grabs the file before it is imported and ensures the taxonomies are created.
  */
 public function post_importer_compatibility()
 {
     global $wpdb;
     if (empty($_POST['import_id']) || !class_exists('WXR_Parser')) {
         return;
     }
     $id = absint($_POST['import_id']);
     $file = get_attached_file($id);
     $parser = new WXR_Parser();
     $import_data = $parser->parse($file);
     if (isset($import_data['posts'])) {
         $posts = $import_data['posts'];
         if ($posts && sizeof($posts) > 0) {
             foreach ($posts as $post) {
                 if ('product' === $post['post_type']) {
                     if (!empty($post['terms'])) {
                         foreach ($post['terms'] as $term) {
                             if (strstr($term['domain'], 'pa_')) {
                                 if (!taxonomy_exists($term['domain'])) {
                                     $attribute_name = wc_sanitize_taxonomy_name(str_replace('pa_', '', $term['domain']));
                                     // Create the taxonomy
                                     if (!in_array($attribute_name, wc_get_attribute_taxonomies())) {
                                         $attribute = array('attribute_label' => $attribute_name, 'attribute_name' => $attribute_name, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order', 'attribute_public' => 0);
                                         $wpdb->insert($wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute);
                                         delete_transient('wc_attribute_taxonomies');
                                     }
                                     // Register the taxonomy now so that the import works!
                                     register_taxonomy($term['domain'], apply_filters('woocommerce_taxonomy_objects_' . $term['domain'], array('product')), apply_filters('woocommerce_taxonomy_args_' . $term['domain'], array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false)));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Parse a WXR file
  *
  * @param string $file Path to WXR file for parsing
  * @return array Information gathered from the WXR file
  */
 function parse($file)
 {
     $parser = new WXR_Parser();
     return $parser->parse($file);
 }
Esempio n. 6
0
/**
 * Support for Import/Export
 * 
 * WordPress import should work - however, it fails to import custom product attribute taxonomies.
 * This code grabs the file before it is imported and ensures the taxonomies are created.
 **/

function jigoshop_import_start() {
	
	global $wpdb;
	
	$id = (int) $_POST['import_id'];
	$file = get_attached_file( $id );

	$parser = new WXR_Parser();
	$import_data = $parser->parse( $file );

	if (isset($import_data['posts'])) :
		$posts = $import_data['posts'];
		
		if ($posts && sizeof($posts)>0) foreach ($posts as $post) :
			
			if ($post['post_type']=='product') :
				
				if ($post['terms'] && sizeof($post['terms'])>0) :
					
					foreach ($post['terms'] as $term) :
						
						$domain = $term['domain'];
						
						if (strstr($domain, 'pa_')) :
							
							// Make sure it exists!
							if (!taxonomy_exists( $domain )) :
								
								$nicename = ucfirst(str_replace('pa_', '', $domain));
								
								// Create the taxonomy
								$wpdb->insert( $wpdb->prefix . "jigoshop_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'text' ), array( '%s', '%s' ) );
								
								// Register the taxonomy now so that the import works!
								register_taxonomy( $domain,
							        array('product'),
							        array(
							            'hierarchical' => true,
							            'labels' => array(
							                    'name' => $nicename,
							                    'singular_name' => $nicename,
							                    'search_items' =>  __( 'Search ', 'jigoshop') . $nicename,
							                    'all_items' => __( 'All ', 'jigoshop') . $nicename,
							                    'parent_item' => __( 'Parent ', 'jigoshop') . $nicename,
							                    'parent_item_colon' => __( 'Parent ', 'jigoshop') . $nicename . ':',
							                    'edit_item' => __( 'Edit ', 'jigoshop') . $nicename,
							                    'update_item' => __( 'Update ', 'jigoshop') . $nicename,
							                    'add_new_item' => __( 'Add New ', 'jigoshop') . $nicename,
							                    'new_item_name' => __( 'New ', 'jigoshop') . $nicename
							            ),
							            'show_ui' => false,
							            'query_var' => true,
							            'rewrite' => array( 'slug' => strtolower(sanitize_title($nicename)), 'with_front' => false, 'hierarchical' => true ),
							        )
							    );
			
								update_option('jigowatt_update_rewrite_rules', '1');
								
							endif;
							
						endif;
						
					endforeach;
					
				endif;
				
			endif;
			
		endforeach;
		
	endif;

}
 /**
  * Parses XML File from Wordpress export. Handles name spacing and returns array
  * containing accessible post ID's.
  *
  * @param string $path // path to XML file
  *
  * @return Array
  */
 public function prepData($path)
 {
     $parser = new \WXR_Parser();
     return @$parser->parse($path);
 }
function cherry_plugin_parse_xml($file)
{
    $file_content = file_get_contents($file);
    $file_content = iconv('utf-8', 'utf-8//IGNORE', $file_content);
    $file_content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $file_content);
    if ($file_content != null) {
        $dom = new DOMDocument('1.0');
        $dom->loadXML($file_content);
        $xml = simplexml_import_dom($dom);
        $old_upload_url = $xml->xpath('/rss/channel/wp:base_site_url');
        $old_upload_url = $old_upload_url[0];
        $upload_dir = wp_upload_dir();
        $upload_dir = $upload_dir['url'];
        $cut_upload_dir = substr($upload_dir, strpos($upload_dir, 'wp-content/uploads'), strlen($upload_dir) - 1);
        $cut_date_upload_dir = '<![CDATA[' . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
        $cut_date_upload_dir_2 = "\"" . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
        $pattern = '/wp-content\\/uploads\\/\\d{4}\\/\\d{2}/i';
        $patternCDATA = '/<!\\[CDATA\\[\\d{4}\\/\\d{2}/i';
        $pattern_meta_value = '/("|\')\\d{4}\\/\\d{2}/i';
        $file_content = str_replace($old_upload_url, site_url(), $file_content);
        $file_content = preg_replace($patternCDATA, $cut_date_upload_dir, $file_content);
        $file_content = preg_replace($pattern_meta_value, $cut_date_upload_dir_2, $file_content);
        $file_content = preg_replace($pattern, $cut_upload_dir, $file_content);
        $parser = new WXR_Parser();
        $parser_array = $parser->parse($file_content, $file);
        $parser_array['site_settings'] = array('blogname' => implode($xml->xpath('/rss/channel/title')), 'blogdescription' => implode($xml->xpath('/rss/channel/description')));
        return $parser_array;
    } else {
        exit('error');
    }
}
 function parse($file)
 {
     $parser = new WXR_Parser();
     // TFUSE 2012.02.10
     $this->tfuse_import_options($file);
     return $parser->parse($file);
 }
Esempio n. 10
0
 /**
  * Import fields configuration from an exported WordPress View preset
  * @param  string $file path to file
  * @return array       Fields config array (unserialized)
  */
 function import_fields($file)
 {
     if (empty($file) || !file_exists($file)) {
         do_action('gravityview_log_error', '[import_fields] Importing Preset Fields. File not found. (File)', $file);
         return false;
     }
     if (!class_exists('WXR_Parser')) {
         include_once GRAVITYVIEW_DIR . 'includes/lib/xml-parsers/parsers.php';
     }
     $parser = new WXR_Parser();
     $presets = $parser->parse($file);
     if (is_wp_error($presets)) {
         do_action('gravityview_log_error', '[import_fields] Importing Preset Fields failed. Threw WP_Error.', $presets);
         return false;
     }
     if (empty($presets['posts'][0]['postmeta']) && !is_array($presets['posts'][0]['postmeta'])) {
         do_action('gravityview_log_error', '[import_fields] Importing Preset Fields failed. Meta not found in file.', $file);
         return false;
     }
     do_action('gravityview_log_debug', '[import_fields] postmeta', $presets['posts'][0]['postmeta']);
     $fields = $widgets = array();
     foreach ($presets['posts'][0]['postmeta'] as $meta) {
         switch ($meta['key']) {
             case '_gravityview_directory_fields':
                 $fields = maybe_unserialize($meta['value']);
                 break;
             case '_gravityview_directory_widgets':
                 $widgets = maybe_unserialize($meta['value']);
                 break;
         }
     }
     do_action('gravityview_log_debug', '[import_fields] Imported Preset (Fields)', $fields);
     do_action('gravityview_log_debug', '[import_fields] Imported Preset (Widgets)', $widgets);
     return array('fields' => $fields, 'widgets' => $widgets);
 }
 /**
  * Subcommand to create guest authors from an author list in a WXR file
  *
  * @subcommand create-guest-authors-from-wxr
  * @synopsis --file=<file>
  */
 public function create_guest_authors_from_wxr($args, $assoc_args)
 {
     global $coauthors_plus;
     $defaults = array('file' => '');
     $this->args = wp_parse_args($assoc_args, $defaults);
     if (empty($this->args['file']) || !is_readable($this->args['file'])) {
         WP_CLI::error('Please specify a valid WXR file with the --file arg.');
     }
     if (!class_exists('WXR_Parser')) {
         require_once WP_CONTENT_DIR . '/admin-plugins/wordpress-importer/parsers.php';
     }
     $parser = new WXR_Parser();
     $import_data = $parser->parse($this->args['file']);
     if (is_wp_error($import_data)) {
         WP_CLI::error('Failed to read WXR file.');
     }
     // Get author nodes
     $authors = $import_data['authors'];
     foreach ($authors as $author) {
         WP_CLI::line(sprintf('Processing author %s (%s)', $author['author_login'], $author['author_email']));
         $guest_author_data = array('display_name' => $author['author_display_name'], 'user_login' => $author['author_login'], 'user_email' => $author['author_email'], 'first_name' => $author['author_first_name'], 'last_name' => $author['author_last_name'], 'ID' => $author['author_id']);
         $guest_author_id = $this->create_guest_author($guest_author_data);
     }
     WP_CLI::line('All done!');
 }
 /**
  * Parse a WXR file
  *
  * @param string $file Path to WXR file for parsing
  * @return array Information gathered from the WXR file
  */
 function parse($file)
 {
     if (!class_exists('WXR_Parser')) {
         require_once dirname(__FILE__) . '/parsers.php';
     }
     $parser = new WXR_Parser();
     return $parser->parse($file);
 }
    /**
     * [demo_installer description]
     *
     * @since 2.2.0
     *
     * @return [type] [description]
     */
    public function demo_installer()
    {
        $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
        if ($action === '') {
            ?>
			<div class="wrap about-wrap uncode-wrap" style="padding: 30px;">
				<div id="import-area">
					<h2><?php 
            echo esc_html__('Import Demo', 'radium');
            ?>
</h2>
					<div style="margin-top: 20px; max-width: 80%;">
						<p><?php 
            echo esc_html__('Here you can import with one click all the content from our demo site, this is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. When you import the data following things will happen:', 'radium');
            ?>
</p>
						<ul style="padding-left: 0px; list-style-position: inside; list-style-type: disc;">
							<li><?php 
            echo esc_html__('No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'radium');
            ?>
</li>
							<li><?php 
            echo esc_html__('No WordPress settings will be modified.', 'radium');
            ?>
</li>
							<li><?php 
            echo esc_html__('Posts, pages, some images, some widgets and menus will get imported.', 'radium');
            ?>
</li>
							<li><?php 
            echo esc_html__('Images will be downloaded from our server.', 'radium');
            ?>
</li>
							<li><?php 
            echo esc_html__('Please click import only once and wait, it can take few minutes.', 'radium');
            ?>
</li>
						</ul>
					</div>

					<div style="background-color: #F5FAFD; margin:30px 0; padding: 10px 30px; color: #777; clear:both; line-height:16px; font-size: 12px;">
						<p><b><?php 
            echo esc_html__('Important:', 'radium');
            ?>
</b></p>
						<ul style="padding-left: 0px; list-style-position: inside; list-style-type: disc;">
							<li><?php 
            printf(wp_kses(__('Deactivate all the plugins except the one listed  %s under the section \'Plugins used in the Uncode demo site\' if you are planning to use them.', 'radium'), array('a' => array('href' => array()))), '<a href="http://www.undsgn.com/uncode/documentation/first-steps/#installation">' . esc_html__('here', 'radium') . '</a>');
            ?>
</li>
							<li><?php 
            printf(esc_html__('Make sure that of the server requirements in %s > Welcome page are fulfilled.', 'radium'), UNCODE_NAME);
            ?>
</li>
							<li><?php 
            echo esc_html__('It\'s always recommended to run the import on a clean installtion of WordPress.', 'radium');
            ?>
</li>
							<li><?php 
            echo esc_html__('Some of the images imported will not match the demo site since they are copyrighted material.', 'radium');
            ?>
</li>
							<li><?php 
            printf(wp_kses(__('In case of import failure, when coming from a clean WordPress installation, we recommend to reset if before try it again. We suggest to use %s plugin.', 'radium'), array('a' => array('href' => array()))), '<a href="https://wordpress.org/plugins/wordpress-reset/">' . esc_html__('WordPress Reset', 'radium') . '</a>');
            ?>
</li>
						</ul>
					</div>
					<?php 
            $open_file = wp_remote_fopen($this->content_demo);
            $response = (array) wp_remote_get($this->content_demo, array('timeout' => 600));
            if ($open_file) {
                if (isset($response['response']['code']) && $response['response']['code'] === 200) {
                    ?>
							<form class="js-one-click-import-form" style="text-align: center;">
								<input class="panel-save button-primary" type="submit" value="IMPORT ALL" style="height: 50px;width: 200px;font-size: 20px;" />
							</form>
							<?php 
                } else {
                    if (isset($response['response']['code']) && $response['response']['code'] === 404) {
                        ?>
								<div>
									<h4 class="error" style="width:80%;text-align:center;margin:auto;"><?php 
                        echo sprintf('File %s not found.', esc_url($this->content_demo));
                        ?>
</h4>
								</div>
							<?php 
                    } else {
                        ?>
								<div>
									<h4 class="error" style="width:80%;text-align:center;margin:auto;">The file <?php 
                        echo esc_url($this->content_demo);
                        ?>
 can't be read. Please change file permission to 777.</h4>
								</div>
							<?php 
                        die;
                    }
                }
            } else {
                ?>
							<div>
								<h4 class="error" style="width:80%;text-align:center;margin:auto;"><?php 
                print_r($response->errors['http_request_failed'][0]);
                ?>
</h4>
							</div>
							<?php 
                die;
            }
            // include WXR file parsers
            require_once dirname(__FILE__) . '/parsers.php';
            $parser = new WXR_Parser();
            $parsed_xml = $parser->parse($this->content_demo);
            $post_array = array();
            $page_array = array();
            $portfolio_array = array();
            $product_array = array();
            foreach ($parsed_xml['posts'] as $key => $value) {
                switch ($value['post_type']) {
                    case 'post':
                        $ids = array($value['post_id']);
                        foreach ($value['postmeta'] as $meta_key => $meta_value) {
                            if ($meta_value['key'] === '_uncode_blocks_list') {
                                $ids[] = $meta_value['value'];
                            }
                        }
                        $post_array[$value['post_title']] = array('ids' => $ids);
                        break;
                    case 'page':
                        $ids = array($value['post_id']);
                        foreach ($value['postmeta'] as $meta_key => $meta_value) {
                            if ($meta_value['key'] === '_uncode_blocks_list') {
                                $ids[] = $meta_value['value'];
                            }
                        }
                        $page_array[$value['post_title']] = array('ids' => $ids);
                        break;
                    case 'portfolio':
                        $ids = array($value['post_id']);
                        foreach ($value['postmeta'] as $meta_key => $meta_value) {
                            if ($meta_value['key'] === '_uncode_blocks_list') {
                                $ids[] = $meta_value['value'];
                            }
                        }
                        $portfolio_array[$value['post_title']] = array('ids' => $ids);
                        break;
                    case 'product':
                        $ids = array($value['post_id']);
                        foreach ($value['postmeta'] as $meta_key => $meta_value) {
                            if ($meta_value['key'] === '_uncode_blocks_list') {
                                $ids[] = $meta_value['value'];
                            }
                        }
                        $product_array[$value['post_title']] = array('ids' => $ids);
                        break;
                }
            }
            $is_woocommerce = class_exists('WooCommerce');
            ?>
					<br />
					<br />
					<hr />
					<br />
					<form class="js-one-click-import-form import-singles" style="text-align: center;">
						<div class="one-click-single-col" style="width:<?php 
            echo $is_woocommerce ? '25' : '33.3333';
            ?>
%;float:left;padding-right:10px;box-sizing:border-box;">
							<h3>Posts</h3>
							<select name="post[]" style="width:100%;height:200px;padding:10px;" multiple>
								<?php 
            ksort($post_array);
            foreach ($post_array as $key => $value) {
                echo '<option value="' . esc_attr(implode(',', $value['ids'])) . '">' . $key . '</option>';
            }
            ?>
							</select>
						</div>
						<div class="one-click-single-col" style="width:<?php 
            echo $is_woocommerce ? '25' : '33.3333';
            ?>
%;float:left;padding-right:10px;box-sizing:border-box;">
							<h3>Pages</h3>
							<select name="page[]" style="width:100%;height:200px;padding:10px;" multiple>
								<?php 
            ksort($page_array);
            foreach ($page_array as $key => $value) {
                echo '<option value="' . esc_attr(implode(',', $value['ids'])) . '">' . $key . '</option>';
            }
            ?>
							</select>
						</div>
						<div class="one-click-single-col" style="width:<?php 
            echo $is_woocommerce ? '25' : '33.3333';
            ?>
%;float:left;padding-right:10px;box-sizing:border-box;">
							<h3>Portfolios</h3>
							<select name="portfolio[]" style="width:100%;height:200px;padding:10px;" multiple>
								<?php 
            ksort($portfolio_array);
            foreach ($portfolio_array as $key => $value) {
                echo '<option value="' . esc_attr(implode(',', $value['ids'])) . '">' . $key . '</option>';
            }
            ?>
							</select>
						</div>
						<?php 
            if ($is_woocommerce) {
                ?>
						<div class="one-click-single-col" style="width:<?php 
                echo $is_woocommerce ? '25' : '33.3333';
                ?>
%;float:left;padding-right:10px;box-sizing:border-box;">
							<h3>Products</h3>
							<select name="product[]" style="width:100%;height:200px;padding:10px;" multiple>
								<?php 
                ksort($product_array);
                foreach ($product_array as $key => $value) {
                    echo '<option value="' . esc_attr(implode(',', $value['ids'])) . '">' . $key . '</option>';
                }
                ?>
							</select>
						</div>
						<?php 
            }
            ?>
						<div style="clear:both;">
							<br />
							<br />
							<input class="panel-save button-primary" type="submit" value="IMPORT SINGLES" style="height: 50px;width: 200px;font-size: 20px;" />
						</div>
						<br />
					</form>
				</div>
			</div>
		<?php 
        } else {
            if ('demo-data' == $action && check_admin_referer('radium-demo-code', 'demononce')) {
                $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : '';
                if ($ids === '' || (string) $ids === '-1') {
                    $this->set_demo_data($this->content_demo);
                    $this->set_demo_theme_options($this->theme_options_file);
                    //import before widgets incase we need more sidebars
                    $this->set_demo_menus();
                    $this->process_widget_import_file($this->widget_demo_url);
                    $homepage = get_page_by_title('Index');
                    if ($homepage) {
                        update_option('page_on_front', $homepage->ID);
                        update_option('show_on_front', 'page');
                    }
                } else {
                    $this->set_demo_data($this->content_demo, $ids);
                }
            }
        }
        ?>

			<script type="text/javascript">
				jQuery( function ( $ ) {
					'use strict';
					$('.js-one-click-import-form' ).on( 'submit', function (e) {
						e.preventDefault();
						$( this ).find( '.panel-save' ).attr( 'disabled', true );
						$( '#import-area' ).hide();
						$( '<div class="in-progress" style="text-align: center; padding: 100px;"><img src="<?php 
        echo get_template_directory_uri() . '/core/one-click-demo/importer/';
        ?>
loader-puff.svg"><p id="importing-text" style="font-weight: bold; font-size: 2em;"><?php 
        echo esc_html__('Import in progress…', 'radium');
        ?>
</p><p style="max-width: 80%; margin: 20px auto;"><b><?php 
        echo esc_html__('Don&#39;t close the browser or navigate away.', 'radium');
        ?>
</b><br><?php 
        echo esc_html__('Please be patient, the import procedure can take few minutes.', 'radium');
        ?>
</p></div>' ).insertAfter('#import-area');
						var data = {
							action: 'demo-data',
							dataType: "html",
							ids: $( this ).hasClass('import-singles') ? $( this ).serialize() : '-1',
							demononce: '<?php 
        echo wp_create_nonce('radium-demo-code');
        ?>
'
						};

						$.ajax({
							type : "post",
							dataType : "html",
							url : '<?php 
        echo admin_url("admin.php?page=one-click-demo");
        ?>
',
							data : data,
							success: function(response, textStatus, xhr) {
								var result = $(response).find('.uncode-wrap').html(),
									is_fine = $(response).find('#import-fine');
								if (!$(is_fine).length) {
									result = 'Unknown error: Check if some content it\'s been imported among your Media, in this case make sure that your server meet the requirements in the Welcome page. Otherwise contact our support or import manually the XML file.';
								}
								$('.uncode-wrap').html(result).css({
									 'text-align': 'center',
									 'padding': '100px'
								});
								$('.uncode-wrap .log-link').on('click', function() {
									$('#import-log').show();
								});
							},
							error: function (xhr, ajaxOptions, thrownError) {
								thrownError = 'Error: Please try increase the <a href="http://codex.wordpress.org/Common_WordPress_Errors#Maximum_execution_time_exceeded" target="_blank">PHP Time Limit value</a> and try again other few times';
								var result = '<b>' + thrownError + '</b>';
								$('.uncode-wrap').html(result).css({
									 'text-align': 'center',
									 'padding': '100px'
								});
							}
						});
						return false;
					});
				});
			</script>
		<?php 
    }
 public function post_importer_compatibility($file)
 {
     global $wpdb;
     if (!$this->wc_is_enabled() || !class_exists('WXR_Parser')) {
         return;
     }
     $parser = new WXR_Parser();
     $import_data = $parser->parse($file);
     if (isset($import_data['posts'])) {
         $posts = $import_data['posts'];
         if ($posts && sizeof($posts) > 0) {
             foreach ($posts as $post) {
                 if ($post['post_type'] == 'product') {
                     if ($post['terms'] && sizeof($post['terms']) > 0) {
                         foreach ($post['terms'] as $term) {
                             $domain = $term['domain'];
                             if (strstr($domain, 'pa_')) {
                                 // Make sure it exists!
                                 if (!taxonomy_exists($domain)) {
                                     $nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
                                     $exists_in_db = $wpdb->get_var($wpdb->prepare("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $nicename));
                                     // Create the taxonomy
                                     if (!$exists_in_db) {
                                         $wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order'), array('%s', '%s', '%s'));
                                     }
                                     // Register the taxonomy now so that the import works!
                                     register_taxonomy($domain, apply_filters('woocommerce_taxonomy_objects_' . $domain, array('product')), apply_filters('woocommerce_taxonomy_args_' . $domain, array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false)));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 15
0
 /**
  * Parse a WXR file
  *
  * @param string $file Path to WXR file for parsing
  * @return array Information gathered from the WXR file
  */
 function parse($file)
 {
     require dirname(__FILE__) . '/parsers.php';
     $parser = new WXR_Parser();
     return $parser->parse($file);
 }
Esempio n. 16
0
function om_import_menu_meta($processed_menu_items)
{
    if (empty($GLOBALS['omImportTool']['menu_add_meta'])) {
        return false;
    }
    $add_meta_list = $GLOBALS['omImportTool']['menu_add_meta'];
    if (!class_exists('WXR_Parser')) {
        require $GLOBALS['omImportTool']['path'] . 'includes/parsers.php';
    }
    $parser = new WXR_Parser();
    $import_data = $parser->parse($GLOBALS['omImportTool']['path'] . $GLOBALS['omImportTool']['wordpress_xml']);
    unset($parser);
    if (is_wp_error($import_data)) {
        return false;
    }
    foreach ($import_data['posts'] as $post) {
        if ('nav_menu_item' == $post['post_type']) {
            $post_id = $post['post_id'];
            if (isset($processed_menu_items[$post_id])) {
                foreach ($add_meta_list as $meta_name) {
                    foreach ($post['postmeta'] as $postmeta) {
                        if ($postmeta['key'] == $meta_name) {
                            update_post_meta($processed_menu_items[$post_id], $meta_name, $postmeta['value']);
                            break;
                        }
                    }
                }
            }
        }
    }
}