本文整理汇总了PHP中PMXI_Import_Record类的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Import_Record类的具体用法?PHP PMXI_Import_Record怎么用?PHP PMXI_Import_Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PMXI_Import_Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Step #1: Choose File
*/
public function index($post_type = 'post')
{
$default = PMAI_Plugin::get_default_import_options();
$this->data['id'] = $id = $this->input->get('id');
$this->data['import'] = $import = new PMXI_Import_Record();
if (!$id or $import->getById($id)->isEmpty()) {
// specified import is not found
$post = $this->input->post((isset(PMXI_Plugin::$session->options) ? PMXI_Plugin::$session->options : array()) + $default);
} else {
$post = $this->input->post($this->data['import']->options + $default);
}
$this->data['is_loaded_template'] = !empty(PMXI_Plugin::$session->is_loaded_template) ? PMXI_Plugin::$session->is_loaded_template : false;
$load_options = $this->input->post('load_template');
if ($load_options) {
// init form with template selected
$template = new PMXI_Template_Record();
if (!$template->getById($this->data['is_loaded_template'])->isEmpty()) {
$post = (!empty($template->options) ? $template->options : array()) + $default;
}
} elseif ($load_options == -1) {
$post = $default;
}
$this->data['post_type'] = $post_type;
$this->data['post'] =& $post;
$this->render();
}
示例2: pmwi_pmxi_after_xml_import
function pmwi_pmxi_after_xml_import($import_id)
{
$import = new PMXI_Import_Record();
$import->getById($import_id);
if (!$import->isEmpty() and in_array($import->options['custom_type'], array('product', 'product_variation')) and $import->options['is_keep_former_posts'] == 'no' and ($import->options['update_all_data'] == 'yes' or $import->options['is_update_categories'])) {
$product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false);
$product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false);
}
}
示例3: validateXml
/**
* Validate XML to be valid for import
* @param string $xml
* @param WP_Error[optional] $errors
* @return bool Validation status
*/
public static function validateXml(&$xml, $errors = NULL)
{
if (FALSE === $xml or '' == $xml) {
$errors and $errors->add('form-validation', __('WP All Import can\'t read your file.<br/><br/>Probably, you are trying to import an invalid XML feed. Try opening the XML feed in a web browser (Google Chrome is recommended for opening XML files) to see if there is an error message.<br/>Alternatively, run the feed through a validator: http://validator.w3.org/<br/>99% of the time, the reason for this error is because your XML feed isn\'t valid.<br/>If you are 100% sure you are importing a valid XML feed, please contact WP All Import support.', 'wp_all_import_plugin'));
} else {
PMXI_Import_Record::preprocessXml($xml);
if (function_exists('simplexml_load_string')) {
libxml_use_internal_errors(true);
libxml_clear_errors();
$_x = @simplexml_load_string($xml);
$xml_errors = libxml_get_errors();
libxml_clear_errors();
if ($xml_errors) {
$error_msg = '<strong>' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul>';
foreach ($xml_errors as $error) {
$error_msg .= '<li>';
$error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . $error->line . ', ';
$error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', ';
$error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': ';
$error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
$error_msg .= '</li>';
}
$error_msg .= '</ul>';
$errors and $errors->add('form-validation', $error_msg);
} else {
return true;
}
} else {
$errors and $errors->add('form-validation', __('Required PHP components are missing.', 'wp_all_import_plugin'));
$errors and $errors->add('form-validation', __('WP All Import requires the SimpleXML PHP module to be installed. This is a standard feature of PHP, and is 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 SimpleXML PHP module.', 'wp_all_import_plugin'));
}
}
return false;
}
示例4: validateXml
/**
* Validate XML to be valid for import
* @param string $xml
* @param WP_Error[optional] $errors
* @return bool Validation status
*/
public static function validateXml(&$xml, $errors = NULL)
{
if (FALSE === $xml or '' == $xml) {
$errors and $errors->add('form-validation', __('XML file does not exist, not accessible or empty', 'pmxi_plugin'));
} else {
PMXI_Import_Record::preprocessXml($xml);
if (function_exists('simplexml_load_string')) {
libxml_use_internal_errors(true);
libxml_clear_errors();
$_x = @simplexml_load_string($xml);
$xml_errors = libxml_get_errors();
libxml_clear_errors();
if ($xml_errors) {
$error_msg = '<strong>' . __('Invalid XML', 'pmxi_plugin') . '</strong><ul>';
foreach ($xml_errors as $error) {
$error_msg .= '<li>';
$error_msg .= __('Line', 'pmxi_plugin') . ' ' . $error->line . ', ';
$error_msg .= __('Column', 'pmxi_plugin') . ' ' . $error->column . ', ';
$error_msg .= __('Code', 'pmxi_plugin') . ' ' . $error->code . ': ';
$error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
$error_msg .= '</li>';
}
$error_msg .= '</ul>';
$errors and $errors->add('form-validation', $error_msg);
} else {
return true;
}
} else {
$errors and $errors->add('form-validation', __('simplexml module is disabled on your server', 'pmxi_plugin'));
}
}
return false;
}
示例5: pmxi_wp_ajax_delete_import
function pmxi_wp_ajax_delete_import()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can('manage_options')) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
$input = new PMXI_Input();
$post = $input->post(array('data' => ''));
$get = $input->get(array('iteration' => 1));
$params = array();
parse_str($post['data'], $params);
$response = array('result' => false, 'msg' => '', 'redirect' => add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'wp_all_import_plugin')), $params['base_url']));
if (!empty($params['import_ids'])) {
foreach ($params['import_ids'] as $key => $id) {
$import = new PMXI_Import_Record();
$import->getById($id);
if (!$import->isEmpty()) {
if ((int) $get['iteration'] === 1) {
$import->set(array('deleted' => 0))->update();
}
$is_all_records_deleted = $import->deletePostsAjax(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
$response['result'] = empty($params['import_ids'][$key + 1]) ? $is_all_records_deleted : false;
$response['msg'] = sprintf(__('Import #%d - %d records deleted', 'wp_all_import_plugin'), $import->id, $import->deleted);
if ($is_all_records_deleted === true) {
$import->delete(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
}
}
}
}
exit(json_encode($response));
}
示例6: merge
public function merge()
{
/* Merge nested XML/CSV files */
if (!empty($this->nested_files)) {
$tmp_files = array();
foreach ($this->nested_files as $key => $nfile) {
$nested_fileURL = array_shift(XmlImportParser::factory($this->xml, $this->xpath, $nfile, $tmp_file)->parse());
$tmp_files[] = $tmp_file;
if (!empty($nested_fileURL)) {
$errors = new WP_Error();
$uploader = new PMXI_Upload($nested_fileURL, $errors);
$upload_result = $uploader->url();
if ($upload_result instanceof WP_Error) {
$errors = $upload_result;
} else {
$source = $upload_result['source'];
$filePath = $upload_result['filePath'];
if (!empty($upload_result['root_element'])) {
$root_element = $upload_result['root_element'];
} else {
$root_element = '';
}
$feed_type = $upload_result['feed_type'];
}
unset($uploader);
$nested_xml = file_get_contents($filePath);
if (!empty($nested_xml)) {
PMXI_Import_Record::preprocessXml($nested_xml);
if (PMXI_Import_Record::validateXml($nested_xml) === true) {
$nestedDom = new DOMDocument('1.0', 'UTF-8');
$nestedold = libxml_use_internal_errors(true);
$nestedDom->loadXML($nested_xml);
libxml_use_internal_errors($nestedold);
$second = $nestedDom->documentElement;
if ($second->hasChildNodes()) {
foreach ($second->childNodes as $node) {
$importNode = $this->dom->importNode($node, true);
$this->dom->documentElement->appendChild($importNode);
}
$this->xml = $this->elements ? $this->dom->saveXML($this->elements->item(0)) : $this->dom->saveXML();
}
unset($nestedDom);
}
}
}
}
foreach ($tmp_files as $tmp_file) {
// remove all temporary files created
@unlink($tmp_file);
}
}
}
示例7: pmxi_wp_ajax_nested_xpath
function pmxi_wp_ajax_nested_xpath()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can(PMXI_Plugin::$capabilities)) {
exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
extract($_POST);
$result = array();
if (@file_exists($filePath)) {
$file = new PMXI_Chunk($filePath, array('element' => $root_element, 'encoding' => 'UTF-8'));
$tagno = 0;
$loop = 0;
$count = 0;
$xml_tree = '';
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
if ('' != $customXpath) {
$dom = new DOMDocument('1.0', 'UTF-8');
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = $xpath->query($customXpath) and $elements->length) {
$loop++;
$count += $elements->length;
if (!$tagno or $loop == $tagno) {
ob_start();
PMXI_Render::render_xml_element($elements->item(0), true);
$xml_tree = ob_get_clean();
$tagno = 1;
}
}
} else {
exit(json_encode(array('success' => false, 'msg' => __('XPath is required', 'wp_all_import_plugin'))));
die;
}
}
}
unset($file);
} else {
exit(json_encode(array('success' => false, 'msg' => 'File path is required', 'wp_all_import_plugin')));
die;
}
exit(json_encode(array('success' => true, 'xml_tree' => $xml_tree, 'count' => $count ? sprintf("<p class='green pmxi_counter'>" . __('Elements found', 'pmxi_pligun') . " <strong>%s</strong></p>", $count) : "<p class='red pmxi_counter'>" . __('Elements not found', 'pmxi_pligun') . "</p>")));
die;
}
示例8: __construct
/**
* 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']);
}
示例9: delete
/**
* @see parent::delete()
*/
public function delete()
{
$this->deletePosts();
if (!empty($this->options['import_id']) and wp_all_export_is_compatible()) {
$import = new PMXI_Import_Record();
$import->getById($this->options['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$import->delete();
}
}
$export_file_path = wp_all_export_get_absolute_path($this->options['filepath']);
if (@file_exists($export_file_path)) {
wp_all_export_remove_source($export_file_path);
}
if (!empty($this->attch_id)) {
wp_delete_attachment($this->attch_id, true);
}
$wp_uploads = wp_upload_dir();
$file_for_remote_access = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . md5(PMXE_Plugin::getInstance()->getOption('cron_job_key') . $this->id) . '.' . $this->options['export_to'];
if (@file_exists($file_for_remote_access)) {
@unlink($file_for_remote_access);
}
return parent::delete();
}
示例10: filter
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
PMXI_Import_Record::preprocessXml($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
示例11: pmxi_wp_ajax_parse_nested_file
/**
*
* Ajax action that will parse nested XML/CSV files
*
*/
function pmxi_wp_ajax_parse_nested_file()
{
extract($_POST);
$result = array();
$wp_uploads = wp_upload_dir();
if (!empty($_POST['nested_type'])) {
$root_element = '';
$feed_type = '';
$errors = new WP_Error();
switch ($_POST['nested_type']) {
case 'upload':
$uploader = new PMXI_Upload($_POST['nested_filepath'], $errors);
$upload_result = $uploader->upload();
if ($upload_result instanceof WP_Error) {
$errors = $upload_result;
} else {
$source = $upload_result['source'];
$filePath = $upload_result['filePath'];
if (!empty($upload_result['root_element'])) {
$root_element = $upload_result['root_element'];
}
}
break;
case 'url':
$uploader = new PMXI_Upload($_POST['nested_url'], $errors);
$upload_result = $uploader->url();
if ($upload_result instanceof WP_Error) {
$errors = $upload_result;
} else {
$source = $upload_result['source'];
$filePath = $upload_result['filePath'];
if (!empty($upload_result['root_element'])) {
$root_element = $upload_result['root_element'];
}
$feed_type = $upload_result['feed_type'];
}
break;
case 'file':
$uploader = new PMXI_Upload($_POST['nested_file'], $errors);
$upload_result = $uploader->file();
if ($upload_result instanceof WP_Error) {
$errors = $upload_result;
} else {
$source = $upload_result['source'];
$filePath = $upload_result['filePath'];
if (!empty($upload_result['root_element'])) {
$root_element = $upload_result['root_element'];
}
}
break;
}
}
if ($errors->get_error_codes()) {
$msgs = $errors->get_error_messages();
ob_start();
?>
<?php
foreach ($msgs as $msg) {
?>
<div class="error"><p><?php
echo $msg;
?>
</p></div>
<?php
}
?>
<?php
exit(json_encode(array('success' => false, 'errors' => ob_get_clean())));
die;
} else {
$xml_tree = '';
if (@file_exists($filePath)) {
$file = new PMXI_Chunk($filePath, array('element' => $root_element));
if (!empty($file->options['element'])) {
$customXpath = "/" . $file->options['element'];
$elements_cloud = $file->cloud;
}
$root_element = $file->options['element'];
$file = new PMXI_Chunk($filePath, array('element' => $root_element, 'encoding' => 'UTF-8'));
$tagno = 0;
$loop = 0;
$count = 0;
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
if ('' != $customXpath) {
$dom = new DOMDocument('1.0', 'UTF-8');
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = $xpath->query($customXpath) and $elements->length) {
$loop++;
$count += $elements->length;
//.........这里部分代码省略.........
示例12: pmxe_wp_ajax_wpallexport
//.........这里部分代码省略.........
if (in_array('product', $exportOptions['cpt'])) {
$templateOptions['_virtual'] = 1;
$templateOptions['_downloadable'] = 1;
$templateOptions['put_variation_image_to_gallery'] = 1;
$templateOptions['disable_auto_sku_generation'] = 1;
}
if (XmlExportEngine::$is_user_export) {
$templateOptions['is_update_first_name'] = 0;
$templateOptions['is_update_last_name'] = 0;
$templateOptions['is_update_role'] = 0;
$templateOptions['is_update_nickname'] = 0;
$templateOptions['is_update_description'] = 0;
$templateOptions['is_update_login'] = 0;
$templateOptions['is_update_password'] = 0;
$templateOptions['is_update_nicename'] = 0;
$templateOptions['is_update_email'] = 0;
$templateOptions['is_update_registered'] = 0;
$templateOptions['is_update_display_name'] = 0;
$templateOptions['is_update_url'] = 0;
}
if ('xml' == $exportOptions['export_to']) {
wp_all_export_prepare_template_xml($exportOptions, $templateOptions);
} else {
wp_all_export_prepare_template_csv($exportOptions, $templateOptions);
}
//$template = new PMXI_Template_Record();
$tpl_options = $templateOptions;
if ('csv' == $exportOptions['export_to']) {
$tpl_options['delimiter'] = $exportOptions['delimiter'];
}
$tpl_options['update_all_data'] = 'yes';
$tpl_options['is_update_status'] = 1;
$tpl_options['is_update_title'] = 1;
$tpl_options['is_update_author'] = 1;
$tpl_options['is_update_slug'] = 1;
$tpl_options['is_update_content'] = 1;
$tpl_options['is_update_excerpt'] = 1;
$tpl_options['is_update_dates'] = 1;
$tpl_options['is_update_menu_order'] = 1;
$tpl_options['is_update_parent'] = 1;
$tpl_options['is_update_attachments'] = 1;
$tpl_options['is_update_acf'] = 1;
$tpl_options['update_acf_logic'] = 'full_update';
$tpl_options['acf_list'] = '';
$tpl_options['is_update_product_type'] = 1;
$tpl_options['is_update_attributes'] = 1;
$tpl_options['update_attributes_logic'] = 'full_update';
$tpl_options['attributes_list'] = '';
$tpl_options['is_update_images'] = 1;
$tpl_options['is_update_custom_fields'] = 1;
$tpl_options['update_custom_fields_logic'] = 'full_update';
$tpl_options['custom_fields_list'] = '';
$tpl_options['is_update_categories'] = 1;
$tpl_options['update_categories_logic'] = 'full_update';
$tpl_options['taxonomies_list'] = '';
$tpl_data = array('name' => $exportOptions['template_name'], 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $tpl_options);
$exportOptions['tpl_data'] = $tpl_data;
$export->set(array('options' => $exportOptions))->save();
// if ( ! empty($exportOptions['template_name'])) { // save template in database
// $template->getByName($exportOptions['template_name'])->set($tpl_data)->save();
// }
}
// associate exported posts with new import
if (wp_all_export_is_compatible() and $exportOptions['is_generate_import']) {
$options = $templateOptions + PMXI_Plugin::get_default_import_options();
$import = new PMXI_Import_Record();
$import->getById($exportOptions['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$xmlPath = PMXE_Plugin::$session->file;
$root_element = '';
$historyPath = PMXE_Plugin::$session->file;
if ('csv' == $exportOptions['export_to']) {
$options['delimiter'] = $exportOptions['delimiter'];
include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
$path_info = pathinfo($xmlPath);
$path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
$security_folder = array_pop($path_parts);
$target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
$csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target));
if (!in_array($xmlPath, $exportOptions['attachment_list'])) {
$exportOptions['attachment_list'][] = $csv->xml_path;
}
$historyPath = $csv->xml_path;
$root_element = 'node';
} else {
$root_element = 'post';
}
$import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1, 'count' => PMXE_Plugin::$session->count))->save();
$history_file = new PMXI_File_Record();
$history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $historyPath, 'registered_on' => date('Y-m-d H:i:s')))->save();
$exportOptions['import_id'] = $import->id;
$export->set(array('options' => $exportOptions))->save();
}
}
}
$export->set(array('executing' => 0, 'canceled' => 0))->save();
do_action('pmxe_after_export', $export->id);
wp_send_json(array('exported' => $export->exported, 'percentage' => 100, 'done' => true, 'records_per_request' => $exportOptions['records_per_iteration'], 'file' => PMXE_Plugin::$session->file));
}
}
示例13: upload
//.........这里部分代码省略.........
exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 101, "message" => __("Failed to open input stream.", "wp_all_import_plugin")), "id" => "id")));
}
fclose($in);
fclose($out);
} else {
delete_transient(self::$upload_transient);
exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => __("Failed to open output stream.", "wp_all_import_plugin")), "id" => "id")));
}
}
$post_type = false;
// Check if file has been uploaded
if (!$chunks || $chunk == $chunks - 1) {
// Strip the temp .part suffix off
rename("{$filePath}.part", $filePath);
chmod($filePath, 0755);
delete_transient(self::$upload_transient);
$errors = new WP_Error();
$uploader = new PMXI_Upload($filePath, $errors, rtrim(str_replace(basename($filePath), '', $filePath), '/'));
$upload_result = $uploader->upload();
if ($upload_result instanceof WP_Error) {
$errors = $upload_result;
$msgs = $errors->get_error_messages();
ob_start();
?>
<?php
foreach ($msgs as $msg) {
?>
<div class="error inline"><p><?php
echo $msg;
?>
</p></div>
<?php
}
?>
<?php
$response = ob_get_clean();
exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => $response), "id" => "id")));
} else {
// validate XML
$file = new PMXI_Chunk($upload_result['filePath'], array('element' => $upload_result['root_element']));
$is_valid = true;
if (!empty($file->options['element'])) {
$defaultXpath = "/" . $file->options['element'];
} else {
$is_valid = false;
}
if ($is_valid) {
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);
$xpath = new DOMXPath($dom);
if ($elements = $xpath->query($defaultXpath) and $elements->length) {
break;
}
}
/*else {
$is_valid = false;
break;
}*/
}
if (empty($xml)) {
$is_valid = false;
}
}
unset($file);
if (!preg_match('%\\W(xml)$%i', trim($upload_result['source']['path']))) {
@unlink($upload_result['filePath']);
}
if (!$is_valid) {
ob_start();
?>
<div class="error inline"><p><?php
_e('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');
?>
</p></div>
<?php
$response = ob_get_clean();
exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => $response), "id" => "id")));
} else {
$wp_uploads = wp_upload_dir();
$uploads = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
if (!file_exists($uploads . basename($filePath))) {
@copy($filePath, $uploads . basename($filePath));
}
}
if (!empty($upload_result['post_type'])) {
$post_type = $upload_result['post_type'];
}
}
}
// Return JSON-RPC response
exit(json_encode(array("jsonrpc" => "2.0", "error" => null, "result" => null, "id" => "id", "name" => $filePath, "post_type" => $post_type)));
}
示例14: filter
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
PMXI_Import_Record::preprocessXml($bucket->data);
$is_remove_colons_from_rss = apply_filters('wp_all_import_remove_colons_from_rss', true);
if ($is_remove_colons_from_rss) {
$bucket->data = $this->replace_colons($bucket->data);
}
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
示例15: link_template_to_import
public static function link_template_to_import(&$export, $file_path, $foundPosts)
{
$exportOptions = $export->options;
// associate exported posts with new import
if (wp_all_export_is_compatible()) {
$options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
$import = new PMXI_Import_Record();
$import->getById($exportOptions['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$xmlPath = $file_path;
$root_element = '';
$historyPath = $file_path;
if ('csv' == $exportOptions['export_to']) {
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
$options['delimiter'] = $exportOptions['delimiter'];
include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
$path_info = pathinfo($xmlPath);
$path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
$security_folder = array_pop($path_parts);
$wp_uploads = wp_upload_dir();
$target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
$csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target));
if (!in_array($xmlPath, $exportOptions['attachment_list'])) {
$exportOptions['attachment_list'][] = $csv->xml_path;
}
$historyPath = $csv->xml_path;
$root_element = 'node';
} else {
$root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
}
$import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1, 'count' => $foundPosts))->save();
$history_file = new PMXI_File_Record();
$history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $historyPath, 'registered_on' => date('Y-m-d H:i:s')))->save();
$exportOptions['import_id'] = $import->id;
$export->set(array('options' => $exportOptions))->save();
}
}
}