' . __('Invalid XML', 'wp_all_import_plugin') . '
';
foreach($custom_xml_template_errors as $error) {
$error_msg .= '- ';
$error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . ($error->line + $line_difference) . ', ';
$error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', ';
$error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': ';
$error_msg .= '' . trim(esc_html($error->message)) . '';
$error_msg .= '
';
}
$error_msg .= '
';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
}
switch ($exportOptions['export_to']) {
case 'xml':
$dom = new DOMDocument('1.0', $exportOptions['encoding']);
libxml_use_internal_errors(true);
try{
$xml = XmlCsvExport::export_xml(true);
} catch (WpaeMethodNotFoundException $e) {
// Find the line where the function is
$errorMessage = '';
$functionName = $e->getMessage();
$txtParts = explode("\n",$originalXmlTemplate);
for ($i=0, $length = count($txtParts);$i<$length;$i++)
{
$tmp = strstr($txtParts[$i], $functionName);
if ($tmp) {
$errorMessage .= 'Error parsing XML feed: Call to undefined function
"'.$functionName.'" on Line '.($i+1);
}
}
$error_msg = '
'.__($errorMessage, 'wp_all_import_plugin').'';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
} catch (WpaeInvalidStringException $e) {
// Find the line where the function is
$errorMessage = '';
$functionName = $e->getMessage();
$txtParts = explode("\n",$originalXmlTemplate);
for ($i=0, $length = count($txtParts);$i<$length;$i++)
{
$tmp = strstr($txtParts[$i], $functionName);
if ($tmp) {
$errorMessage .= 'Error parsing XML feed: Unterminated string on line '.($i+1);
}
}
$error_msg = '
'.__($errorMessage, 'wp_all_import_plugin').'';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
} catch (WpaeTooMuchRecursionException $e) {
$errorMessage = __('There was a problem parsing the custom XML template');
$error_msg = '
'.__($errorMessage, 'wp_all_import_plugin').'';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
}
$xml_errors = false;
$main_xml_tag = '';
switch ( XmlExportEngine::$exportOptions['xml_template_type'] ){
case 'custom':
case 'XmlGoogleMerchants':
require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
$preview_xml = "" . "\n
\n" . $xml . "\n";
$preview_xml = str_replace('', 'CDATACLOSE', $preview_xml);
$preview_xml = str_replace('&', '&', $preview_xml);
$preview_xml = str_replace('&', '&', $preview_xml);
$xml = PMXE_XMLWriter::preprocess_xml( XmlExportEngine::$exportOptions['custom_xml_template_header'] ) . "\n" . $xml . "\n" . PMXE_XMLWriter::preprocess_xml( XmlExportEngine::$exportOptions['custom_xml_template_footer'] );
$xml = str_replace('', 'CDATACLOSE', $xml);
$xml = str_replace('&', '&', $xml);
$xml = str_replace('&', '&', $xml);
// Determine XML root element
preg_match_all("%<[\w]+[\s|>]{1}%", XmlExportEngine::$exportOptions['custom_xml_template_header'], $matches);
if ( ! empty($matches[0]) ){
$main_xml_tag = preg_replace("%[\s|<|>]%","",array_shift($matches[0]));
}
libxml_clear_errors();
$dom->loadXML($xml);
$xml_errors = libxml_get_errors();
libxml_clear_errors();
if (! $xml_errors ){
$xpath = new DOMXPath($dom);
if (($elements = @$xpath->query('/' . $main_xml_tag)) and $elements->length){
pmxe_render_xml_element($elements->item( 0 ), true);
}
else{
$xml_errors = true;
}
}
break;
default:
libxml_clear_errors();
$dom->loadXML($xml);
$xml_errors = libxml_get_errors();
libxml_clear_errors();
$xpath = new DOMXPath($dom);
// Determine XML root element
$main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], XmlExportEngine::$exportID);
$elements = @$xpath->query('/' . $main_xml_tag);
if ($elements->length){
pmxe_render_xml_element($elements->item( 0 ), true);
$xml_errors = false;
}
else{
$error_msg = '
' . __('Can\'t preview the document.', 'wp_all_import_plugin') . '';
$error_msg .= '- ';
$error_msg .= __('You can continue export or try to use <data> tag as root element.', 'wp_all_import_plugin');
$error_msg .= '
';
$error_msg .= '
';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
}
break;
}
if ( $xml_errors ){
$preview_dom = new DOMDocument('1.0', $exportOptions['encoding']);
libxml_clear_errors();
$preview_dom->loadXML($preview_xml);
$preview_xml_errors = libxml_get_errors();
libxml_clear_errors();
if ($preview_xml_errors){
$error_msg = '
' . __('Invalid XML', 'wp_all_import_plugin') . '';
foreach($preview_xml_errors as $error) {
$error_msg .= '- ';
$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 .= '' . trim(esc_html($error->message)) . '';
$error_msg .= '
';
}
$error_msg .= '
';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
}
else{
$xpath = new DOMXPath($preview_dom);
if (($elements = @$xpath->query('/Preview')) and $elements->length){
pmxe_render_xml_element($elements->item( 0 ), true);
}
else{
$error_msg = '
' . __('Can\'t preview the document. Root element is not detected.', 'wp_all_import_plugin') . '';
$error_msg .= '- ';
$error_msg .= __('You can continue export or try to use <data> tag as root element.', 'wp_all_import_plugin');
$error_msg .= '
';
$error_msg .= '
';
echo $error_msg;
exit( json_encode(array('html' => ob_get_clean())) );
}
}
}
break;
case 'csv':
?>
$row) {
$cells = str_getcsv($row, $exportOptions['delimiter']);
if ($cells){
?>
$value) {
?>
|