PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 3.2.2
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v3.2.2
4.1.1 3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / actions / wp_ajax_parse_nested_file.php
wp-all-import / actions Last commit date
admin_head.php 11 years ago admin_init.php 11 years ago admin_menu.php 11 years ago admin_notices.php 11 years ago delete_post.php 11 years ago plugins_loaded.php 11 years ago wp.php 11 years ago wp_ajax_auto_detect_cf.php 11 years ago wp_ajax_auto_detect_sf.php 11 years ago wp_ajax_import_failed.php 11 years ago wp_ajax_nested_merge.php 11 years ago wp_ajax_nested_xpath.php 11 years ago wp_ajax_parse_nested_file.php 11 years ago wp_ajax_test_images.php 11 years ago wp_ajax_unmerge_file.php 11 years ago wp_loaded.php 11 years ago
wp_ajax_parse_nested_file.php
155 lines
1 <?php
2 /**
3 *
4 * Ajax action that will parse nested XML/CSV files
5 *
6 */
7 function pmxi_wp_ajax_parse_nested_file(){
8
9 extract($_POST);
10
11 $result = array();
12
13 $wp_uploads = wp_upload_dir();
14
15 if ( ! empty($_POST['nested_type']) ){
16
17 $root_element = '';
18 $feed_type = '';
19 $errors = new WP_Error();
20
21 switch ($_POST['nested_type']){
22
23 case 'upload':
24
25 $uploader = new PMXI_Upload($_POST['nested_filepath'], $errors);
26 $upload_result = $uploader->upload();
27
28 if ($upload_result instanceof WP_Error){
29 $errors = $upload_result;
30 }
31 else{
32 $source = $upload_result['source'];
33 $filePath = $upload_result['filePath'];
34 if ( ! empty($upload_result['root_element']))
35 $root_element = $upload_result['root_element'];
36 }
37
38 break;
39
40 case 'url':
41
42 $uploader = new PMXI_Upload($_POST['nested_url'], $errors);
43 $upload_result = $uploader->url();
44
45 if ($upload_result instanceof WP_Error){
46 $errors = $upload_result;
47 }
48 else{
49 $source = $upload_result['source'];
50 $filePath = $upload_result['filePath'];
51 if ( ! empty($upload_result['root_element']))
52 $root_element = $upload_result['root_element'];
53 $feed_type = $upload_result['feed_type'];
54 }
55
56 break;
57
58 case 'file':
59
60 $uploader = new PMXI_Upload($_POST['nested_file'], $errors);
61 $upload_result = $uploader->file();
62
63 if ($upload_result instanceof WP_Error){
64 $errors = $upload_result;
65 }
66 else{
67 $source = $upload_result['source'];
68 $filePath = $upload_result['filePath'];
69 if ( ! empty($upload_result['root_element']))
70 $root_element = $upload_result['root_element'];
71 }
72
73 break;
74 }
75 }
76
77 if ( $errors->get_error_codes() )
78 {
79 $msgs = $errors->get_error_messages();
80 ob_start();
81 ?>
82 <?php foreach ($msgs as $msg): ?>
83 <div class="error"><p><?php echo $msg ?></p></div>
84 <?php endforeach ?>
85 <?php
86 exit(json_encode(array(
87 'success' => false,
88 'errors' => ob_get_clean()
89 ))); die;
90 }
91 else
92 {
93
94 $xml_tree = '';
95
96 if ( @file_exists($filePath) ){
97
98 $file = new PMXI_Chunk($filePath, array('element' => $root_element));
99
100 if ( ! empty($file->options['element']) ) {
101 $customXpath = "/".$file->options['element'];
102 $elements_cloud = $file->cloud;
103 }
104
105 $root_element = $file->options['element'];
106
107 $file = new PMXI_Chunk($filePath, array('element' => $root_element, 'encoding' => 'UTF-8'));
108
109 $tagno = 0;
110 $loop = 0;
111 $count = 0;
112
113 while ($xml = $file->read()) {
114
115 if ( ! empty($xml) )
116 {
117 PMXI_Import_Record::preprocessXml($xml);
118 $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
119
120 if ( '' != $customXpath){
121 $dom = new DOMDocument('1.0', 'UTF-8');
122 $old = libxml_use_internal_errors(true);
123 $dom->loadXML($xml);
124 libxml_use_internal_errors($old);
125 $xpath = new DOMXPath($dom);
126 if (($elements = $xpath->query($customXpath)) and $elements->length){
127 $loop++;
128 $count += $elements->length;
129 if ( ! $tagno or $loop == $tagno ){
130 ob_start();
131 PMXI_Render::render_xml_element($elements->item(0), true);
132 $xml_tree = ob_get_clean();
133 $tagno = 1;
134 }
135 }
136 }
137 else break;
138 }
139 }
140 unset($file);
141 }
142
143 exit(json_encode(array(
144 'success' => true,
145 'source' => $source,
146 'realpath' => $source['path'],
147 'filePath' => $filePath,
148 'root_element' => $root_element,
149 'xml_tree' => $xml_tree,
150 'xpath' => $customXpath,
151 '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>")
152 ))); die;
153 }
154
155 }