/** * data load initialize * * @param mixed $filename please look at the load() method * * @access public * @see load() * @return void */ public function __construct($filename = null, $large_import = false, $xpath = '', $delimiter = '', $encoding = '', $xml_path = '') { PMXI_Plugin::$csv_path = $filename; $this->large_import = $large_import; $this->xpath = !empty($xpath) ? $xpath : (!empty($_POST['xpath']) ? $_POST['xpath'] : '/node'); $this->delimiter = $delimiter; if ('' != $encoding) { $this->csv_encoding = $encoding; $this->auto_encoding = false; } if ('' != $xml_path) { $this->xml_path = $xml_path; } @ini_set("display_errors", 0); @ini_set('auto_detect_line_endings', true); $file_params = self::analyse_file($filename, 1); $this->set_settings(array('delimiter' => $file_params['delimiter']['value'], 'eol' => $file_params['line_ending']['value'])); unset($file_params); //stream_filter_register('msaccessxml', 'MSAccessXmlFilter'); $this->load($filename); }
/** * data load initialize * * @param mixed $filename please look at the load() method * * @access public * @see load() * @return void */ public function __construct($options = array('filename' => null, 'xpath' => '', 'delimiter' => '', 'encoding' => '', 'xml_path' => '', 'targetDir' => false)) { PMXI_Plugin::$csv_path = $options['filename']; $this->xpath = !empty($options['xpath']) ? $options['xpath'] : (!empty($_POST['xpath']) ? $_POST['xpath'] : '/node'); if (!empty($options['delimiter'])) { $this->delimiter = $options['delimiter']; } else { $input = new PMXI_Input(); $id = $input->get('id', 0); if (!$id) { $id = $input->get('import_id', 0); } if ($id) { $import = new PMXI_Import_Record(); $import->getbyId($id); if (!$import->isEmpty()) { $this->delimiter = $import->options['delimiter']; } } } if (!empty($options['encoding'])) { $this->csv_encoding = $options['encoding']; $this->auto_encoding = false; } if (!empty($options['xml_path'])) { $this->xml_path = $options['xml_path']; } @ini_set("display_errors", 0); @ini_set('auto_detect_line_endings', true); $file_params = self::analyse_file($options['filename'], 1); $this->set_settings(array('delimiter' => $file_params['delimiter']['value'], 'eol' => $file_params['line_ending']['value'])); unset($file_params); $wp_uploads = wp_upload_dir(); $this->targetDir = empty($options['targetDir']) ? wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $options['targetDir']; $this->load($options['filename']); }
/** * Step #1: Choose File */ public function index() { PMXI_Plugin::$session->clean_session(); $this->data['reimported_import'] = $import = new PMXI_Import_Record(); $this->data['id'] = $id = $this->input->get('id'); $this->data['parent_import'] = $parent_import = $this->input->get('parent_import', 0); $parent_import_record = new PMXI_Import_Record(); $default = array('type' => 'upload', 'wizard_type' => 'new', 'custom_type' => 'post', 'show_hidden_cpt' => 0, 'feed_type' => '', 'url' => '', 'ftp' => array('url' => 'ftp://'), 'file' => '', 'reimport' => '', 'is_update_previous' => $id ? 1 : 0, 'update_previous' => $id, 'xpath' => '/', 'filepath' => '', 'root_element' => '', 'downloaded' => '', 'auto_generate' => 0, 'template' => false); if ($parent_import and !$parent_import_record->getById($parent_import)->isEmpty()) { $default['custom_type'] = $parent_import_record->options['custom_type']; } if ($id) { // update requested but corresponding import is not found if ($import->getById($id)->isEmpty()) { if (!empty($_GET['deligate']) and $_GET['deligate'] == 'wpallexport') { wp_redirect(add_query_arg('pmxi_nt', array('error' => urlencode(__('The import associated with this export has been deleted.', 'wp_all_import_plugin')), 'updated' => urlencode(__('Please re-run your export by clicking Run Export on the All Export -> Manage Exports page. Then try your import again.', 'wp_all_import_plugin'))), remove_query_arg('id', $this->baseUrl))); die; } else { wp_redirect(add_query_arg('pmxi_nt', array('error' => urlencode(__('This import has been deleted.', 'wp_all_import_plugin'))), remove_query_arg('id', $this->baseUrl))); die; } } else { $default['custom_type'] = $import->options['custom_type']; } } $this->data['post'] = $post = $this->input->post($default); if (!class_exists('DOMDocument') or !class_exists('XMLReader')) { $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Import requires DOMDocument, XMLReader, and XMLWriter PHP modules to be installed.<br/>These are standard features of PHP, and are necessary for WP All Import to read the files you are trying to import.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp_all_import_plugin')); } if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) { check_admin_referer('choose-file', '_wpnonce_choose-file'); if ('upload' == $this->input->post('type')) { $uploader = new PMXI_Upload($post['filepath'], $this->errors, rtrim(str_replace(basename($post['filepath']), '', $post['filepath']), '/')); $upload_result = $uploader->upload(); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; $post['template'] = $upload_result['template']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } } } elseif ('url' == $this->input->post('type')) { if (!empty($post['downloaded'])) { $downloaded = json_decode($post['downloaded'], true); $source = $downloaded['source']; $filePath = $downloaded['filePath']; $post['template'] = $downloaded['template']; PMXI_Plugin::$csv_path = $downloaded['csv_path']; PMXI_Plugin::$is_csv = $downloaded['is_csv']; if (!empty($downloaded['root_element'])) { $post['root_element'] = $downloaded['root_element']; } $post['feed_type'] = $downloaded['feed_type']; } else { $uploader = new PMXI_Upload($post['url'], $this->errors); $upload_result = $uploader->url($post['feed_type']); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; $post['template'] = $upload_result['template']; PMXI_Plugin::$csv_path = $upload_result['csv_path']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } $post['feed_type'] = $upload_result['feed_type']; } } } elseif ('file' == $this->input->post('type')) { $uploader = new PMXI_Upload($post['file'], $this->errors); $upload_result = $uploader->file(); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; $post['template'] = $upload_result['template']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } } } if ($this->input->post('is_submitted') and '' == $this->input->post('custom_type')) { $this->errors->add('form-validation', __('Select an item type to import the data', 'wp_all_import_plugin')); } if ($post['is_update_previous'] and empty($post['update_previous'])) { $this->errors->add('form-validation', __('Previous import for update must be selected to proceed with a new one', 'wp_all_import_plugin')); } $this->data['detection_feed_extension'] = false; $elements_cloud = array(); @set_time_limit(0); $table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports'; $deligate = $this->input->get('deligate', false); $redirect_to_template = false; $importRecord = new PMXI_Import_Record(); switch ($deligate) { case 'wpallexport': global $wpdb; $import_id = $this->input->get('id', 0); $importRecord->clear(); $importRecord->getById($import_id); if (!$importRecord->isEmpty() and !empty($importRecord->options['unique_key'])) { $importRecord->set(array('path' => wp_all_import_get_relative_path($filePath), 'parent_import_id' => 0))->save(); $post['is_update_previous'] = 1; $post['update_previous'] = $importRecord->id; //$chunks = $importRecord->count; $redirect_to_template = true; } if ($importRecord->isEmpty()) { $this->errors->add('form-validation', __('File is no longer in the correct format', 'wp_all_import_plugin')); } elseif (empty($importRecord->options['unique_key'])) { $this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin')); } elseif ($importRecord->options['custom_type'] == 'import_users' && !class_exists('PMUI_Plugin')) { $this->errors->add('form-validation', __('The import template you are using requires User Import Add-On.<br/><a href="http://www.wpallimport.com/add-ons/user-import/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin" target="_blank">Purchase the User Import Add-On</a>', 'wp_all_import_plugin')); } break; default: # code... break; } $local_paths = !empty($local_paths) ? $local_paths : array($filePath); foreach ($local_paths as $key => $path) { if (@file_exists($path)) { $file = new PMXI_Chunk($path, array('element' => $post['root_element'], 'get_cloud' => true)); if (!empty($file->options['element'])) { $xpath = "/" . $file->options['element']; $elements_cloud = $file->cloud; if (!empty($elements_cloud) and class_exists('PMXE_Plugin') and !$importRecord->isEmpty()) { $is_file_valid = apply_filters('wp_all_import_is_exported_file_valid', true, $importRecord->options['export_id'], $elements_cloud); if (!$is_file_valid) { $this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin')); } } if (($redirect_to_template or $post['auto_generate']) and !$this->errors->get_error_codes()) { // loop through the file until all lines are read while ($xml = $file->read()) { if (!empty($xml)) { PMXI_Import_Record::preprocessXml($xml); $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', 'UTF-8'); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $dxpath = new DOMXPath($dom); if ($elements = @$dxpath->query($xpath) and $elements->length) { $chunks += $elements->length; unset($dom, $dxpath, $elements); } } } //unset($file); } break; } } else { $this->errors->add('form-validation', __('Unable to download feed resource.', 'wp_all_import_plugin')); } } if (!$this->errors->get_error_codes()) { // xml is valid $source['root_element'] = $file->options['element']; $source['first_import'] = date("Y-m-d H:i:s"); PMXI_Plugin::$session->clean_session(); $session_data = array('filePath' => $filePath, 'parent_import_id' => $parent_import, 'xpath' => !empty($xpath) ? $xpath : '', 'feed_type' => $post['feed_type'], 'wizard_type' => $post['wizard_type'], 'custom_type' => $post['custom_type'], 'source' => $source, 'encoding' => 'UTF-8', 'is_csv' => PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'processing' => 0, 'queue_chunk_number' => 0, 'count' => isset($chunks) ? $chunks : 0, 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'csv_paths' => array(PMXI_Plugin::$csv_path), 'action' => 'import', 'elements_cloud' => !empty($elements_cloud) ? $elements_cloud : array(), 'pointer' => 1, 'deligate' => $deligate); // apply options from WP All Export bundle if (!empty($post['template'])) { $templates = json_decode($post['template'], true); $template_options = maybe_unserialize($templates[0]['options']); $template_options['type'] = $post['custom_type'] == 'page' ? 'page' : 'post'; $template_options['custom_type'] = $post['custom_type']; $template_options['wizard_type'] = $post['wizard_type']; if ($post['wizard_type'] == 'new') { $template_options['create_new_records'] = 1; } $this->data['post'] = $template_options; PMXI_Plugin::$session->set('options', $template_options); } foreach ($session_data as $key => $value) { PMXI_Plugin::$session->set($key, $value); } $update_previous = new PMXI_Import_Record(); if ($post['is_update_previous'] and !$update_previous->getById($post['update_previous'])->isEmpty()) { PMXI_Plugin::$session->set('update_previous', $update_previous->id); PMXI_Plugin::$session->set('xpath', $update_previous->xpath); PMXI_Plugin::$session->set('options', $update_previous->options); } else { PMXI_Plugin::$session->set('update_previous', ''); } PMXI_Plugin::$session->save_data(); $xml = $this->get_xml(); if (empty($xml)) { $this->errors->add('form-validation', __('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin')); } elseif ($redirect_to_template) { wp_redirect(add_query_arg('action', 'template', $this->baseUrl)); die; } elseif ($post['auto_generate']) { wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die; } else { wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die; } } else { if ('url' == $this->input->post('type') and !empty($this->errors)) { $this->errors->add('form-validation', __('WP All Import unable to detect file type.<br/><br/>WP All Import not able to determine what type of file you are importing. Make sure your file extension is correct for the file type you are importing.<br/> Please choose the correct file type from the dropdown below, or try adding &type=xml or &type=csv to the end of the URL, for example http://example.com/export-products.php?&type=xml', 'wp_all_import_plugin')); $this->data['detection_feed_extension'] = true; } else { $this->errors->add('form-validation', __('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin')); } } do_action("pmxi_get_file", $filePath); } if ($this->input->post('is_submitted') and $this->errors->get_error_codes()) { PMXI_Plugin::$session->clean_session(); } $this->render(); }
/** * Step #1: Choose File */ public function index() { PMXI_Plugin::$session->clean_session(); $this->data['reimported_import'] = $import = new PMXI_Import_Record(); $this->data['id'] = $id = $this->input->get('id'); $this->data['parent_import'] = $parent_import = $this->input->get('parent_import', 0); $parent_import_record = new PMXI_Import_Record(); $default = array('type' => 'upload', 'wizard_type' => 'new', 'custom_type' => 'post', 'show_hidden_cpt' => 0, 'feed_type' => '', 'url' => '', 'ftp' => array('url' => 'ftp://'), 'file' => '', 'reimport' => '', 'is_update_previous' => $id ? 1 : 0, 'update_previous' => $id, 'xpath' => '/', 'filepath' => '', 'root_element' => '', 'downloaded' => ''); if ($parent_import and !$parent_import_record->getById($parent_import)->isEmpty()) { $default['custom_type'] = $parent_import_record->options['custom_type']; } if ($id and $import->getById($id)->isEmpty()) { // update requested but corresponding import is not found wp_redirect(remove_query_arg('id', $this->baseUrl)); die; } $this->data['post'] = $post = $this->input->post($default); if ($this->input->post('is_submitted_continue')) { if (!empty(PMXI_Plugin::$session->local_paths)) { wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die; } } elseif ('upload' == $this->input->post('type')) { $uploader = new PMXI_Upload($post['filepath'], $this->errors, rtrim(str_replace(basename($post['filepath']), '', $post['filepath']), '/')); $upload_result = $uploader->upload(); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } } } elseif ('url' == $this->input->post('type')) { if (!empty($post['downloaded'])) { $downloaded = json_decode($post['downloaded'], true); $source = $downloaded['source']; $filePath = $downloaded['filePath']; PMXI_Plugin::$csv_path = $downloaded['csv_path']; PMXI_Plugin::$is_csv = $downloaded['is_csv']; if (!empty($downloaded['root_element'])) { $post['root_element'] = $downloaded['root_element']; } $post['feed_type'] = $downloaded['feed_type']; } else { $uploader = new PMXI_Upload($post['url'], $this->errors); $upload_result = $uploader->url($post['feed_type']); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; PMXI_Plugin::$csv_path = $upload_result['csv_path']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } $post['feed_type'] = $upload_result['feed_type']; } } } elseif ('file' == $this->input->post('type')) { $uploader = new PMXI_Upload($post['file'], $this->errors); $upload_result = $uploader->file(); if ($upload_result instanceof WP_Error) { $this->errors = $upload_result; } else { $source = $upload_result['source']; $filePath = $upload_result['filePath']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if (!empty($upload_result['root_element'])) { $post['root_element'] = $upload_result['root_element']; } } } if ($this->input->post('is_submitted') and '' == $this->input->post('custom_type')) { $this->errors->add('form-validation', __('Select an item type to import the data', 'pmxi_plugin')); } if ($post['is_update_previous'] and empty($post['update_previous'])) { $this->errors->add('form-validation', __('Previous import for update must be selected to proceed with a new one', 'pmxi_plugin')); } $this->data['detection_feed_extension'] = false; if (!class_exists('DOMDocument') or !class_exists('XMLReader')) { $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Import requires DOMDocument and XMLReader PHP classes to be installed.<br/>These are standard features of PHP, and are necessary for WP All Import to read the files you are trying to import.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument and XMLReader PHP classes.', 'pmxi_plugin')); } if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) { check_admin_referer('choose-file', '_wpnonce_choose-file'); $elements_cloud = array(); @set_time_limit(0); $local_paths = !empty($local_paths) ? $local_paths : array($filePath); foreach ($local_paths as $key => $path) { if (@file_exists($path)) { $file = new PMXI_Chunk($path, array('element' => $post['root_element'])); if (!empty($file->options['element'])) { $xpath = "/" . $file->options['element']; $elements_cloud = $file->cloud; break; } } else { $this->errors->add('form-validation', __('Unable to download feed resource.', 'pmxi_plugin')); } } if (!$this->errors->get_error_codes()) { // xml is valid $source['root_element'] = $file->options['element']; $source['first_import'] = date("Y-m-d H:i:s"); PMXI_Plugin::$session->clean_session(); $session_data = array('filePath' => $filePath, 'parent_import_id' => $parent_import, 'xpath' => !empty($xpath) ? $xpath : '', 'feed_type' => $post['feed_type'], 'wizard_type' => $post['wizard_type'], 'custom_type' => $post['custom_type'], 'source' => $source, 'encoding' => 'UTF-8', 'is_csv' => PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'processing' => 0, 'queue_chunk_number' => 0, 'count' => isset($chunks) ? $chunks : 0, 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'csv_paths' => array(PMXI_Plugin::$csv_path), 'action' => 'import', 'elements_cloud' => !empty($elements_cloud) ? $elements_cloud : array(), 'pointer' => 1); foreach ($session_data as $key => $value) { PMXI_Plugin::$session->set($key, $value); } $update_previous = new PMXI_Import_Record(); if ($post['is_update_previous'] and !$update_previous->getById($post['update_previous'])->isEmpty()) { PMXI_Plugin::$session->set('update_previous', $update_previous->id); PMXI_Plugin::$session->set('xpath', $update_previous->xpath); PMXI_Plugin::$session->set('template', $update_previous->template); PMXI_Plugin::$session->set('options', $update_previous->options); } else { PMXI_Plugin::$session->set('update_previous', ''); } PMXI_Plugin::$session->save_data(); $xml = $this->get_xml(); if (empty($xml)) { $this->errors->add('form-validation', __('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'pmxi_plugin')); } else { wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die; } } else { if ('url' == $this->input->post('type') and !empty($this->errors)) { $this->errors->add('form-validation', __('WP All Import unable to detect file type.<br/><br/>WP All Import not able to determine what type of file you are importing. Make sure your file extension is correct for the file type you are importing.<br/> Please choose the correct file type from the dropdown below, or try adding &type=xml or &type=csv to the end of the URL, for example http://example.com/export-products.php?&type=xml', 'pmxi_plugin')); $this->data['detection_feed_extension'] = true; } else { $this->errors->add('form-validation', __('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'pmxi_plugin')); } } do_action("pmxi_get_file", $filePath); } if ($this->input->post('is_submitted') and $this->errors->get_error_codes()) { PMXI_Plugin::$session->clean_session(); } $this->render(); }