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;
}
Example #2
0
<a href="#next" class="next_element">&nbsp;</a><?php 
    } else {
        ?>
<span class="next_element">&nbsp;</span><?php 
    }
    ?>
				</div>
			</div>
			<div class="clear"></div>
			<div class="wpallimport-xml resetable"> 
				<?php 
    if (!empty($elements->length)) {
        if (PMXI_Plugin::$session->options['delimiter']) {
            PMXI_Render::render_csv_element($elements->item(0), true);
        } else {
            PMXI_Render::render_xml_element($elements->item($elements->length > 1 ? $tagno : 0), true);
        }
    }
    ?>
			
			</div>			
		<?php 
} else {
    ?>
			<div class="error inline below-h2" style="padding:10px; margin-top:45px;">
				<?php 
    printf(__('History file not found. Probably you are using wrong encoding.', 'wp_all_import_plugin'));
    ?>
			
			</div>
		<?php 
Example #3
0
 /**
  * Helper to evaluate xpath and return matching elements as direct paths for javascript side to highlight them
  */
 public function evaluate_variations()
 {
     if (!PMXI_Plugin::getInstance()->getAdminCurrentScreen()->is_ajax) {
         // call is only valid when send with ajax
         wp_redirect(add_query_arg('action', 'element', $this->baseUrl));
         die;
     }
     $post = $this->input->post(array('xpath' => '', 'show_element' => 1, 'root_element' => !empty(PMXI_Plugin::$session->source['root_element']) ? PMXI_Plugin::$session->source['root_element'] : '', 'tagno' => 0, 'parent_tagno' => 1));
     $wp_uploads = wp_upload_dir();
     $this->get_xml($post['parent_tagno'], true);
     $xpath = new DOMXPath($this->data['dom']);
     $this->data['tagno'] = max(intval($this->input->getpost('tagno', 1)), 0);
     if ('' == $post['xpath']) {
         $this->errors->add('form-validation', __('Your XPath is empty.<br/><br/>Please enter an XPath expression, or click "get default XPath" to get the default XPath.', 'wp_all_import_plugin'));
     } else {
         $post['xpath'] = '/' . (!empty($this->data['update_previous']->root_element) ? $this->data['update_previous']->root_element : PMXI_Plugin::$session->source['root_element']) . '/' . ltrim(trim(str_replace("[*]", "", $post['xpath']), '{}'), '/');
         // in default mode
         $this->data['variation_elements'] = $elements = @$xpath->query($post['xpath']);
         // prevent parsing warning to be displayed
         $this->data['variation_list_count'] = $elements->length;
         if (FALSE === $elements) {
             $this->errors->add('form-validation', __('Your XPath is not valid.<br/><br/>Click "get default XPath" to get the default XPath.', 'wp_all_import_plugin'));
         } elseif (!$elements->length) {
             $this->errors->add('form-validation', __('No matching variations found for XPath specified', 'wp_all_import_plugin'));
         } else {
             foreach ($elements as $el) {
                 if (!$el instanceof DOMElement) {
                     $this->errors->add('form-validation', __('XPath must match only elements', 'wp_all_import_plugin'));
                     break;
                 }
             }
         }
     }
     ob_start();
     if (!$this->errors->get_error_codes()) {
         $paths = array();
         $this->data['paths'] =& $paths;
         if (PMXI_Plugin::getInstance()->getOption('highlight_limit') and $elements->length <= PMXI_Plugin::getInstance()->getOption('highlight_limit')) {
             foreach ($elements as $el) {
                 if (!$el instanceof DOMElement) {
                     continue;
                 }
                 $p = PMXI_Render::get_xml_path($el, $xpath) and $paths[] = $p;
             }
         }
         $this->render();
     } else {
         $this->error();
     }
     exit(json_encode(array('html' => ob_get_clean())));
 }
/**
*
*	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;
                            if (!$tagno or $loop == $tagno) {
                                ob_start();
                                PMXI_Render::render_xml_element($elements->item(0), true);
                                $xml_tree = ob_get_clean();
                                $tagno = 1;
                            }
                        }
                    } else {
                        break;
                    }
                }
            }
            unset($file);
        }
        exit(json_encode(array('success' => true, 'source' => $source, 'realpath' => $source['path'], 'filePath' => $filePath, 'root_element' => $root_element, 'xml_tree' => $xml_tree, 'xpath' => $customXpath, 'count' => $count ? sprintf("<p class='green pmxi_counter'>" . __('Elements founded', 'pmxi_pligun') . " <strong>%s</strong></p>", $count) : "<p class='red pmxi_counter'>" . __('Elements not found', 'pmxi_pligun') . "</p>")));
        die;
    }
}
Example #5
0
	<?php 
}
?>
</div>
<div id="current_xml">
	<?php 
if ($is_csv) {
    ?>
		<?php 
    PMXI_Render::render_csv_element($elements->item(0), false, '//');
    ?>
	<?php 
} else {
    ?>
		<?php 
    PMXI_Render::render_xml_element($elements->item(0), false, '//');
    ?>
	<?php 
}
?>
</div>
<script type="text/javascript">
(function($){	
	var paths = <?php 
echo json_encode($paths);
?>
;
	var $xml = $('.wpallimport-xml');
	$('.wpallimport-console').fadeIn();
	$xml.html($('#current_xml').html()).css({'visibility':'visible'});
	for (var i = 0; i < paths.length; i++) {
Example #6
0
</th>
								<th><?php 
_e('Value', 'wp_all_import_plugin');
?>
</th>
								<th>&nbsp;</th>
							</tr>
							<tr>
								<td style="width:25%;">
									<select id="pmxi_xml_element">
										<option value=""><?php 
_e('Select Element', 'wp_all_import_plugin');
?>
</option>
										<?php 
PMXI_Render::render_xml_elements_for_filtring($elements->item(0));
?>
									</select>
								</td>
								<td style="width:25%;">
									<select id="pmxi_rule">
										<option value=""><?php 
_e('Select Rule', 'wp_all_import_plugin');
?>
</option>
										<option value="equals"><?php 
_e('equals', 'wp_all_import_plugin');
?>
</option>
										<option value="not_equals"><?php 
_e('not equals', 'wp_all_import_plugin');
    ?>
				<?php 
    if ($tagno < $variation_list_count - 1) {
        ?>
<a href="#variation_next" class="next_element">&nbsp;</a><?php 
    } else {
        ?>
<span class="next_element">&nbsp;</span><?php 
    }
    ?>
			</div>
		</div>
		<div class="clear"></div>
		<div class="xml resetable"> <?php 
    if (!empty($variation_list_count)) {
        PMXI_Render::render_xml_element($variation_elements->item($tagno), true);
    }
    ?>
</div>	
	</div>
</div>
<?php 
}
?>
<script type="text/javascript">
(function($){	
	var paths = <?php 
echo json_encode($paths);
?>
;
	var $xml = $('#variations_xml');	
	<?php 
}
?>
</div>
<div id="current_xml">	
	<?php 
if ($is_csv) {
    ?>
		<?php 
    PMXI_Render::render_csv_element($elements->item(0), false, '//');
    ?>
	<?php 
} else {
    ?>
		<?php 
    PMXI_Render::render_xml_element($elements->item($elements->length > 1 ? $show_element : 0), false, '//');
    ?>
	<?php 
}
?>
</div>
<script type="text/javascript">
(function($){	
	var paths = <?php 
echo json_encode($paths);
?>
;
	var $xml = $('.wpallimport-xml');
	$('.wpallimport-console').fadeIn();
	$xml.html($('#current_xml').html()).css({'visibility':'visible'});
	for (var i = 0; i < paths.length; i++) {
Example #9
0
<a href="#next" class="next_element">&nbsp;</a><?php 
    } else {
        ?>
<span class="next_element">&nbsp;</span><?php 
    }
    ?>
				</div>
			</div>
			<div class="clear"></div>
			<div class="wpallimport-xml resetable"> 
				<?php 
    if (!empty($elements->length)) {
        if (PMXI_Plugin::$session->options['delimiter']) {
            PMXI_Render::render_csv_element($elements->item(0), true);
        } else {
            PMXI_Render::render_xml_element($elements->item(0), true);
        }
    }
    ?>
			
			</div>			
		<?php 
} else {
    ?>
			<div class="error inline below-h2" style="padding:10px; margin-top:45px;">
				<?php 
    printf(__('History file not found. Probably you are using wrong encoding.', 'pmxi_plugin'));
    ?>
			
			</div>
		<?php