/** * Reimport */ public function update() { $id = $this->input->get('id'); $action_type = $this->input->get('type'); $this->data['item'] = $item = new PMXI_Import_Record(); if (!$id or $item->getById($id)->isEmpty()) { wp_redirect($this->baseUrl); die; } pmxi_session_unset(); $chunks = 0; if ($this->input->post('is_confirmed')) { check_admin_referer('update-import', '_wpnonce_update-import'); $uploads = wp_upload_dir(); if (empty(PMXI_Plugin::$session->data['pmxi_import']['chunk_number'])) { if (in_array($item->type, array('upload'))) { // if import type NOT URL if (preg_match('%\\W(zip)$%i', trim(basename($item->path)))) { include_once PMXI_Plugin::ROOT_DIR . '/libraries/pclzip.lib.php'; $archive = new PclZip(trim($item->path)); if (($v_result_list = $archive->extract(PCLZIP_OPT_PATH, $uploads['path'], PCLZIP_OPT_REPLACE_NEWER)) == 0) { $this->errors->add('form-validation', 'Failed to open uploaded ZIP archive : ' . $archive->errorInfo(true)); } else { $filePath = ''; if (!empty($v_result_list)) { foreach ($v_result_list as $unzipped_file) { if ($unzipped_file['status'] == 'ok' and preg_match('%\\W(xml|csv|txt|dat|psv)$%i', trim($unzipped_file['stored_filename']))) { $filePath = $unzipped_file['filename']; break; } } } if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } if (empty($filePath)) { $zip = zip_open(trim($item->path)); if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { $filePath = zip_entry_name($zip_entry); $fp = fopen($uploads['path'] . "/" . $filePath, "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp, "{$buf}"); zip_entry_close($zip_entry); fclose($fp); } break; } zip_close($zip); } else { $this->errors->add('form-validation', __('Failed to open uploaded ZIP archive. Can\'t extract files.', 'pmxi_plugin')); } } if (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($filePath))) { // If CSV file found in archieve if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($filePath, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : ''); // create chunks $filePath = $csv->xml_path; } } } elseif (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($item->path))) { // If CSV file uploaded if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($item->path, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : ''); $filePath = $csv->xml_path; } elseif (preg_match('%\\W(gz)$%i', trim($item->path))) { // If gz file uploaded $fileInfo = pmxi_gzfile_get_contents($item->path); if (!is_wp_error($fileInfo)) { $filePath = $fileInfo['localPath']; // detect CSV or XML if ($fileInfo['type'] == 'csv') { // it is CSV file include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($filePath, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : ''); // create chunks $filePath = $csv->xml_path; } } else { $this->errors->add('form-validation', $fileInfo->get_error_message()); } } else { // If XML file uploaded $filePath = $item->path; } } @set_time_limit(0); $local_paths = !empty($local_paths) ? $local_paths : array($filePath); foreach ($local_paths as $key => $path) { if (!empty($action_type) and $action_type == 'continue') { $chunks = $item->count; } else { $file = new PMXI_Chunk($path, array('element' => $item->root_element, 'encoding' => $item->options['encoding'])); while ($xml = $file->read()) { if (!empty($xml)) { PMXI_Import_Record::preprocessXml($xml); $xml = "<?xml version=\"1.0\" encoding=\"" . $item->options['encoding'] . "\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8'); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if ($elements = @$xpath->query($item->xpath) and !empty($elements) and !empty($elements->length)) { $chunks += $elements->length; } unset($dom, $xpath, $elements); } } unset($file); } !$key and $filePath = $path; } if (empty($chunks)) { $this->errors->add('form-validation', __('No matching elements found for Root element and XPath expression specified', 'pmxi_plugin')); } } if ($chunks) { // xml is valid if (!PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->data['pmxi_import']['chunk_number'])) { // compose data to look like result of wizard steps PMXI_Plugin::$session['pmxi_import'] = array('filePath' => $filePath, 'source' => array('name' => $item->name, 'type' => $item->type, 'path' => $item->path, 'root_element' => $item->root_element), 'feed_type' => $item->feed_type, 'update_previous' => $item->id, 'parent_import_id' => $item->parent_import_id, 'xpath' => $item->xpath, 'template' => $item->template, 'options' => $item->options, 'encoding' => !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8', 'is_csv' => !empty($item->options['delimiter']) ? $item->options['delimiter'] : PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'scheduled' => $item->scheduled, 'chunk_number' => 1, 'log' => '', 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'pointer' => 1, 'count' => isset($chunks) ? $chunks : 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'action' => (!empty($action_type) and $action_type == 'continue') ? 'continue' : 'update'); pmxi_session_commit(); } // deligate operation to other controller $controller = new PMXI_Admin_Import(); $controller->data['update_previous'] = $item; $controller->process(); return; } } $this->render(); }
/** * Step #1: Choose File */ public function index() { $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); 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(array('type' => 'upload', 'feed_type' => '', 'url' => 'http://', 'ftp' => array('url' => 'ftp://'), 'file' => '', 'reimport' => '', 'is_update_previous' => $id ? 1 : 0, 'update_previous' => $id, 'xpath' => '/', 'filepath' => '', 'root_element' => '')); if ($this->input->post('is_submitted_continue')) { if (!empty(PMXI_Plugin::$session->data['pmxi_import']['local_paths'])) { wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die; } } elseif ('upload' == $this->input->post('type')) { $uploads = wp_upload_dir(); if (empty($post['filepath'])) { $this->errors->add('form-validation', __('XML/CSV file must be specified', 'pmxi_plugin')); } elseif (!is_file($post['filepath'])) { $this->errors->add('form-validation', __('Uploaded file is empty', 'pmxi_plugin')); } elseif (!preg_match('%\\W(xml|gzip|zip|csv|gz)$%i', trim(basename($post['filepath'])))) { $this->errors->add('form-validation', __('Uploaded file must be XML, CSV or ZIP, GZIP', 'pmxi_plugin')); } elseif (preg_match('%\\W(zip)$%i', trim(basename($post['filepath'])))) { include_once PMXI_Plugin::ROOT_DIR . '/libraries/pclzip.lib.php'; $archive = new PclZip($post['filepath']); if (($v_result_list = $archive->extract(PCLZIP_OPT_PATH, $uploads['path'], PCLZIP_OPT_REPLACE_NEWER)) == 0) { $this->errors->add('form-validation', 'Failed to open uploaded ZIP archive : ' . $archive->errorInfo(true)); } else { $filePath = ''; if (!empty($v_result_list)) { foreach ($v_result_list as $unzipped_file) { if ($unzipped_file['status'] == 'ok' and preg_match('%\\W(xml|csv|txt|dat|psv)$%i', trim($unzipped_file['stored_filename']))) { $filePath = $unzipped_file['filename']; break; } } } if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } if (empty($filePath)) { $zip = zip_open(trim($post['filepath'])); if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { $filePath = zip_entry_name($zip_entry); $fp = fopen($uploads['path'] . "/" . $filePath, "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp, "{$buf}"); zip_entry_close($zip_entry); fclose($fp); } break; } zip_close($zip); } else { $this->errors->add('form-validation', __('Failed to open uploaded ZIP archive. Can\'t extract files.', 'pmxi_plugin')); } } // Detect if file is very large $source = array('name' => basename($post['filepath']), 'type' => 'upload', 'path' => $post['filepath']); if (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($filePath))) { // If CSV file found in archieve if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($filePath, true); // create chunks $filePath = $csv->xml_path; $post['root_element'] = 'node'; } } } elseif (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($post['filepath']))) { // If CSV file uploaded // Detect if file is very large if ($uploads['error']) { $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin')); } $filePath = $post['filepath']; $source = array('name' => basename($post['filepath']), 'type' => 'upload', 'path' => $filePath); include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($post['filepath'], true); $filePath = $csv->xml_path; $post['root_element'] = 'node'; } elseif (preg_match('%\\W(gz)$%i', trim($post['filepath']))) { // If gz file uploaded $fileInfo = pmxi_gzfile_get_contents($post['filepath']); if (!is_wp_error($fileInfo)) { $filePath = $fileInfo['localPath']; // Detect if file is very large $source = array('name' => basename($post['filepath']), 'type' => 'upload', 'path' => $post['filepath']); // detect CSV or XML if ($fileInfo['type'] == 'csv') { // it is CSV file include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser($filePath, true); // create chunks $filePath = $csv->xml_path; $post['root_element'] = 'node'; } } else { $this->errors->add('form-validation', $fileInfo->get_error_message()); } } else { // If XML file uploaded // Detect if file is very large $filePath = $post['filepath']; $source = array('name' => basename($post['filepath']), 'type' => 'upload', 'path' => $filePath); } } elseif ($this->input->post('is_submitted')) { $this->errors->add('form-validation', __('Upgrade to the paid edition of WP All Import to use this feature.', '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')) { $this->errors->add('form-validation', __('Class \'DOMDocument\' not found.', 'pmxi_plugin')); } if (!class_exists('XMLReader')) { $this->errors->add('form-validation', __('Class \'XMLReader\' not found.', '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 find root element for this feed. Please open the feed in your browser or a text editor and ensure it is a valid feed.', 'pmxi_plugin')); } } 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_session_unset(); PMXI_Plugin::$session['pmxi_import'] = array('filePath' => $filePath, 'parent_import_id' => $parent_import, 'xpath' => !empty($xpath) ? $xpath : '', 'feed_type' => $post['feed_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' => !empty($csv_paths) ? $csv_paths : array(PMXI_Plugin::$csv_path), 'action' => 'import', 'elements_cloud' => !empty($elements_cloud) ? $elements_cloud : array(), 'pointer' => 1); $update_previous = new PMXI_Import_Record(); if ($post['is_update_previous'] and !$update_previous->getById($post['update_previous'])->isEmpty()) { PMXI_Plugin::$session['pmxi_import']['update_previous'] = $update_previous->id; PMXI_Plugin::$session['pmxi_import']['xpath'] = $update_previous->xpath; PMXI_Plugin::$session['pmxi_import']['template'] = $update_previous->template; PMXI_Plugin::$session['pmxi_import']['options'] = $update_previous->options; } else { PMXI_Plugin::$session['pmxi_import']['update_previous'] = ''; } pmxi_session_commit(); $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@soflyy.com">support@soflyy.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 { $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@soflyy.com">support@soflyy.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); } $this->render(); }
public function file() { $wp_uploads = wp_upload_dir(); $uploads = $wp_uploads['basedir'] . '/wpallimport/files/'; if (empty($this->file)) { $this->errors->add('form-validation', __('Please specify a file to import.', 'pmxi_plugin')); } elseif (preg_match('%\\W(zip)$%i', trim($this->file))) { if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } echo '<span style="display:none">'; copy($uploads . $this->file, $this->uploadsPath . '/' . basename($this->file)); echo '</span>'; $zipfilePath = $this->uploadsPath . '/' . basename($this->file); include_once PMXI_Plugin::ROOT_DIR . '/libraries/pclzip.lib.php'; $archive = new PclZip($zipfilePath); if (($v_result_list = $archive->extract(PCLZIP_OPT_PATH, $this->uploadsPath, PCLZIP_OPT_REPLACE_NEWER)) == 0) { $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'pmxi_plugin')); } else { $filePath = ''; if (!empty($v_result_list)) { foreach ($v_result_list as $unzipped_file) { if ($unzipped_file['status'] == 'ok' and preg_match('%\\W(xml|csv|txt|dat|psv|json)$%i', trim($unzipped_file['stored_filename']))) { $filePath = $unzipped_file['filename']; break; } } } if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } if (empty($filePath)) { $zip = zip_open(trim($zipfilePath)); if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { $filePath = zip_entry_name($zip_entry); $fp = fopen($this->uploadsPath . "/" . $filePath, "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp, "{$buf}"); zip_entry_close($zip_entry); fclose($fp); } break; } zip_close($zip); } else { $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'pmxi_plugin')); } } // Detect if file is very large $source = array('name' => basename($this->file), 'type' => 'file', 'path' => $uploads . $this->file); if (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($filePath))) { // If CSV file found in archieve if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser(array('filename' => $filePath, 'targetDir' => $this->uploadsPath)); // create chunks //pmxi_remove_source($filePath, false); $filePath = $csv->xml_path; $this->is_csv = $csv->is_csv; $this->root_element = 'node'; } elseif (preg_match('%\\W(json)$%i', trim($filePath))) { $json_str = file_get_contents($filePath); $is_json = pmxi_isJson($json_str); if (is_wp_error($is_json)) { $this->errors->add('form-validation', $is_json->get_error_message(), 'pmxi_plugin'); } else { $xml_data = pmxi_json_to_xml(json_decode($json_str, true)); if (empty($xml_data)) { $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'pmxi_plugin')); } else { $jsontmpname = $this->uploadsPath . '/' . url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath)))); file_put_contents($jsontmpname, $xml_data); pmxi_remove_source($filePath); $filePath = $jsontmpname; } } } elseif (preg_match('%\\W(sql)$%i', trim($filePath))) { include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php'; $localSQLPath = $filePath; $sql = new PMXI_SQLParser($localSQLPath, $this->uploadsPath); $filePath = $sql->parse(); pmxi_remove_source($localSQLPath, false); } } if (file_exists($zipfilePath)) { pmxi_remove_source($zipfilePath, false); } } elseif (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($this->file))) { if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } // copy file in temporary folder // hide warning message echo '<span style="display:none">'; copy($uploads . $this->file, $this->uploadsPath . '/' . basename($this->file)); echo '</span>'; $filePath = $this->uploadsPath . '/' . basename($this->file); $source = array('name' => basename($this->file), 'type' => 'file', 'path' => $uploads . $this->file); // Detect if file is very large include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser(array('filename' => $filePath, 'targetDir' => $this->uploadsPath)); // create chunks //pmxi_remove_source($filePath, false); $filePath = $csv->xml_path; $this->is_csv = $csv->is_csv; $this->root_element = 'node'; } elseif (preg_match('%\\W(json)$%i', trim($this->file))) { if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } // copy file in temporary folder // hide warning message echo '<span style="display:none">'; copy($uploads . $this->file, $this->uploadsPath . '/' . basename($this->file)); echo '</span>'; $filePath = $this->uploadsPath . '/' . basename($this->file); $source = array('name' => basename($this->file), 'type' => 'file', 'path' => $uploads . $this->file); $json_str = file_get_contents($filePath); $is_json = pmxi_isJson($json_str); if (is_wp_error($is_json)) { $this->errors->add('form-validation', $is_json->get_error_message(), 'pmxi_plugin'); } else { $xml_data = pmxi_json_to_xml(json_decode($json_str, true)); if (empty($xml_data)) { $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'pmxi_plugin')); } else { $jsontmpname = $this->uploadsPath . '/' . url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath)))); file_put_contents($jsontmpname, $xml_data); pmxi_remove_source($filePath, false); $filePath = $jsontmpname; } } } elseif (preg_match('%\\W(sql)$%i', trim($this->file))) { if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } // copy file in temporary folder // hide warning message echo '<span style="display:none">'; copy($uploads . $this->file, $this->uploadsPath . '/' . basename($this->file)); echo '</span>'; $localSQLPath = $this->uploadsPath . '/' . basename($this->file); $source = array('name' => basename($this->file), 'type' => 'file', 'path' => $uploads . $this->file); include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php'; $sql = new PMXI_SQLParser($localSQLPath, $this->uploadsPath); $filePath = $sql->parse(); pmxi_remove_source($localSQLPath, false); } else { if ($this->uploadsPath === false) { $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'pmxi_plugin')); } // copy file in temporary folder // hide warning message echo '<span style="display:none">'; copy($uploads . $this->file, $this->uploadsPath . '/' . basename($this->file)); echo '</span>'; $source = array('name' => basename($this->file), 'type' => 'file', 'path' => $uploads . $this->file); $filePath = $this->uploadsPath . '/' . basename($this->file); if (preg_match('%\\W(gz)$%i', basename($this->file))) { $fileInfo = pmxi_gzfile_get_contents($filePath, 0, $this->uploadsPath); if (!is_wp_error($fileInfo)) { pmxi_remove_source($filePath, false); $filePath = $fileInfo['localPath']; } else { $this->errors->add('form-validation', $fileInfo->get_error_message()); } } if (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($this->file)) or !empty($fileInfo) and $fileInfo['type'] == 'csv') { include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $csv = new PMXI_CsvParser(array('filename' => $filePath, 'targetDir' => $this->uploadsPath)); // create chunks //pmxi_remove_source($filePath, false); $filePath = $csv->xml_path; $this->is_csv = $csv->is_csv; $this->root_element = 'node'; } } if ($this->errors->get_error_codes()) { return $this->errors; } return array('filePath' => $filePath, 'source' => $source, 'root_element' => $this->root_element, 'is_csv' => $this->is_csv); }