Export WordPress data to XML/CSV - Version 1.1.5

Version Description

  • improvement: removed autoload=true from wp_options
  • improvement: WPML options in separate section
  • bug fix: allow underscores in main xml tags
  • bug fix: prevent uploading import template into wpae
  • bug fix: ID column in CSV
  • bug fix: ACF repeater headers
Download this release

Release Info

Developer soflyy
Plugin Icon 128x128 Export WordPress data to XML/CSV
Version 1.1.5
Comparing to
See all releases

Code changes from version 1.1.4 to 1.1.5

Files changed (52) hide show
  1. actions/admin_notices.php +2 -2
  2. actions/pmxe_after_export.php +224 -36
  3. actions/pmxe_before_export.php +40 -0
  4. actions/wp_ajax_wpae_available_rules.php +1 -1
  5. actions/wp_ajax_wpae_filtering_count.php +160 -55
  6. actions/wp_ajax_wpae_preview.php +59 -39
  7. actions/wp_ajax_wpallexport.php +316 -277
  8. actions/wp_loaded.php +0 -1
  9. classes/XMLWriter.php +5 -0
  10. config/options.php +2 -0
  11. controllers/admin/export.php +179 -143
  12. controllers/admin/manage.php +34 -13
  13. controllers/admin/settings.php +108 -7
  14. controllers/controller.php +23 -15
  15. controllers/controller/admin.php +5 -5
  16. dist/app.min.js +2 -2
  17. helpers/pmxe_filter.php +2 -2
  18. helpers/pmxe_functions.php +2 -2
  19. helpers/pmxe_render_xml_element.php +5 -5
  20. helpers/pmxe_render_xml_text.php +5 -4
  21. helpers/wp_all_export_generate_export_file.php +27 -28
  22. helpers/wp_all_export_get_cpt_name.php +2 -2
  23. helpers/wp_all_export_get_export_format.php +1 -1
  24. helpers/wp_all_export_posts_where.php +3 -3
  25. helpers/wp_all_export_reverse_rules_html.php +1 -1
  26. i18n/languages/wp_all_export_plugin-de_DE.mo +0 -0
  27. i18n/languages/wp_all_export_plugin-de_DE.po +2 -2
  28. i18n/languages/wp_all_export_plugin-es_ES.mo +0 -0
  29. i18n/languages/wp_all_export_plugin-es_ES.po +1269 -1247
  30. i18n/languages/wp_all_export_plugin-fr_FR.mo +0 -0
  31. i18n/languages/wp_all_export_plugin-fr_FR.po +1192 -839
  32. i18n/languages/wp_all_export_plugin-ja.mo +0 -0
  33. i18n/languages/wp_all_export_plugin-ja.po +537 -1035
  34. i18n/languages/wp_all_export_plugin-lv.mo +0 -0
  35. i18n/languages/wp_all_export_plugin-lv.po +1504 -701
  36. i18n/languages/wp_all_export_plugin-pt_BR.mo +0 -0
  37. i18n/languages/wp_all_export_plugin-pt_BR.po +2 -2
  38. i18n/languages/wp_all_export_plugin-ru_RU.mo +0 -0
  39. i18n/languages/wp_all_export_plugin-ru_RU.po +1273 -1243
  40. i18n/languages/wp_all_export_plugin.mo +0 -0
  41. i18n/languages/wp_all_export_plugin.pot +460 -686
  42. libraries/WpaeString.php +0 -1
  43. libraries/WpaeXmlProcessor.php +17 -11
  44. libraries/XmlCsvExport.php +28 -9
  45. libraries/XmlExportACF.php +141 -9
  46. libraries/XmlExportCpt.php +13 -3
  47. libraries/XmlExportEngine.php +17 -7
  48. libraries/XmlExportWooCommerce.php +145 -47
  49. libraries/XmlExportWooCommerceOrder.php +47 -16
  50. models/export/record.php +5 -3
  51. readme.txt +17 -9
  52. src/App/Controller/CategoriesController.php +1 -0
actions/admin_notices.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  function pmxe_admin_notices() {
4
-
5
  // notify user if history folder is not writable
6
  $uploads = wp_upload_dir();
7
 
@@ -9,7 +9,7 @@ function pmxe_admin_notices() {
9
  $messages = $input->get('pmxe_nt', array());
10
  if ($messages) {
11
  is_array($messages) or $messages = array($messages);
12
- foreach ($messages as $type => $m) {
13
  in_array((string)$type, array('updated', 'error')) or $type = 'updated';
14
  ?>
15
  <div class="<?php echo $type ?>"><p><?php echo $m ?></p></div>
1
  <?php
2
 
3
  function pmxe_admin_notices() {
4
+
5
  // notify user if history folder is not writable
6
  $uploads = wp_upload_dir();
7
 
9
  $messages = $input->get('pmxe_nt', array());
10
  if ($messages) {
11
  is_array($messages) or $messages = array($messages);
12
+ foreach ($messages as $type => $m) {
13
  in_array((string)$type, array('updated', 'error')) or $type = 'updated';
14
  ?>
15
  <div class="<?php echo $type ?>"><p><?php echo $m ?></p></div>
actions/pmxe_after_export.php CHANGED
@@ -1,16 +1,23 @@
1
  <?php
2
 
3
  function pmxe_pmxe_after_export($export_id, $export)
4
- {
5
  if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
6
  {
7
  PMXE_Plugin::$session->set('file', '');
8
- PMXE_Plugin::$session->save_data();
9
  }
10
 
11
  if ( ! $export->isEmpty())
12
- {
13
- $splitSize = $export->options['split_large_exports_count'];
 
 
 
 
 
 
 
14
 
15
  $exportOptions = $export->options;
16
  // remove previously genereted chunks
@@ -19,27 +26,32 @@ function pmxe_pmxe_after_export($export_id, $export)
19
  foreach ($exportOptions['split_files_list'] as $file) {
20
  @unlink($file);
21
  }
22
- }
23
 
24
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
25
 
26
  if ( ! $is_secure_import)
27
  {
28
- $filepath = get_attached_file($export->attch_id);
29
  }
30
  else
31
  {
32
  $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
33
- }
34
 
 
35
  $is_export_csv_headers = apply_filters('wp_all_export_is_csv_headers_enabled', true, $export->id);
36
 
37
- if ( isset($export->options['include_header_row'])) {
38
  $is_export_csv_headers = $export->options['include_header_row'];
39
  }
40
 
 
 
 
 
41
  // Remove headers row from CSV file
42
- if ( empty($is_export_csv_headers) && @file_exists($filepath) && $export->options['export_to'] == 'csv' && $export->options['export_to_sheet'] == 'csv' ){
43
 
44
  $tmp_file = str_replace(basename($filepath), 'iteration_' . basename($filepath), $filepath);
45
  copy($filepath, $tmp_file);
@@ -87,45 +99,67 @@ function pmxe_pmxe_after_export($export_id, $export)
87
  {
88
  case 'xml':
89
 
90
- $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $export->options['main_xml_tag'], $export->id);
91
- $record_xml_tag = apply_filters('wp_all_export_record_xml_tag', $export->options['record_xml_tag'], $export->id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  $records_count = 0;
94
  $chunk_records_count = 0;
95
  $fileCount = 1;
96
 
97
- $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$main_xml_tag.">";
98
 
99
  $file = new PMXE_Chunk($filepath, array('element' => $record_xml_tag, 'encoding' => 'UTF-8'));
100
  // loop through the file until all lines are read
101
  while ($xml = $file->read()) {
102
 
103
  if ( ! empty($xml) )
104
- {
105
- $chunk = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
106
-
107
- $dom = new DOMDocument('1.0', "UTF-8");
108
- $old = libxml_use_internal_errors(true);
109
- $dom->loadXML($chunk); // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
110
- libxml_use_internal_errors($old);
111
- $xpath = new DOMXPath($dom);
112
-
113
  $records_count++;
114
  $chunk_records_count++;
115
  $feed .= $xml;
116
  }
117
 
118
  if ( $chunk_records_count == $splitSize or $records_count == $export->exported ){
119
- $feed .= "</".$main_xml_tag.">";
120
  $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath);
121
  file_put_contents($outputFile, $feed);
122
  if ( ! in_array($outputFile, $exportOptions['split_files_list']))
123
  $exportOptions['split_files_list'][] = $outputFile;
124
  $chunk_records_count = 0;
125
- $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$main_xml_tag.">";
126
  }
 
127
 
128
- }
129
  break;
130
  case 'csv':
131
  $in = fopen($filepath, 'r');
@@ -155,7 +189,35 @@ function pmxe_pmxe_after_export($export_id, $export)
155
  $rowCount++;
156
  }
157
  fclose($in);
158
- fclose($out);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  break;
161
 
@@ -166,7 +228,69 @@ function pmxe_pmxe_after_export($export_id, $export)
166
 
167
  $export->set(array('options' => $exportOptions))->save();
168
  }
169
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  // make a temporary copy of current file
172
  if ( empty($export->parent_id) and @file_exists($filepath) and @copy($filepath, str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath)))
@@ -175,19 +299,83 @@ function pmxe_pmxe_after_export($export_id, $export)
175
  $exportOptions['current_filepath'] = str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath);
176
  $export->set(array('options' => $exportOptions))->save();
177
  }
 
 
178
 
179
- // genereta export bundle
180
- $export->generate_bundle();
181
 
182
- if ( ! empty($export->parent_id) )
183
- {
184
- $parent_export = new PMXE_Export_Record();
185
- $parent_export->getById($export->parent_id);
186
- if ( ! $parent_export->isEmpty() )
187
- {
188
- $parent_export->generate_bundle(true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  }
190
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  // clean session
193
  if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
1
  <?php
2
 
3
  function pmxe_pmxe_after_export($export_id, $export)
4
+ {
5
  if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
6
  {
7
  PMXE_Plugin::$session->set('file', '');
8
+ PMXE_Plugin::$session->save_data();
9
  }
10
 
11
  if ( ! $export->isEmpty())
12
+ {
13
+
14
+ $export->set(
15
+ array(
16
+ 'registered_on' => date('Y-m-d H:i:s'),
17
+ )
18
+ )->save();
19
+
20
+ $splitSize = $export->options['split_large_exports_count'];
21
 
22
  $exportOptions = $export->options;
23
  // remove previously genereted chunks
26
  foreach ($exportOptions['split_files_list'] as $file) {
27
  @unlink($file);
28
  }
29
+ }
30
 
31
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
32
 
33
  if ( ! $is_secure_import)
34
  {
35
+ $filepath = get_attached_file($export->attch_id);
36
  }
37
  else
38
  {
39
  $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
40
+ }
41
 
42
+ //TODO: Look into what is happening with this variable and what it is used for
43
  $is_export_csv_headers = apply_filters('wp_all_export_is_csv_headers_enabled', true, $export->id);
44
 
45
+ if ( isset($export->options['include_header_row']) ) {
46
  $is_export_csv_headers = $export->options['include_header_row'];
47
  }
48
 
49
+ $removeHeaders = false;
50
+
51
+ $removeHeaders = apply_filters('wp_all_export_remove_csv_headers', $removeHeaders, $export->id);
52
+
53
  // Remove headers row from CSV file
54
+ if ( (empty($is_export_csv_headers) && @file_exists($filepath) && $export->options['export_to'] == 'csv' && $export->options['export_to_sheet'] == 'csv') || $removeHeaders){
55
 
56
  $tmp_file = str_replace(basename($filepath), 'iteration_' . basename($filepath), $filepath);
57
  copy($filepath, $tmp_file);
99
  {
100
  case 'xml':
101
 
102
+ require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
103
+
104
+ switch ( $export->options['xml_template_type'])
105
+ {
106
+ case 'XmlGoogleMerchants':
107
+ case 'custom':
108
+ // Determine XML root element
109
+ // $main_xml_tag = false;
110
+ // preg_match_all("%<[\w]+[\s|>]{1}%", $export->options['custom_xml_template_header'], $matches);
111
+ // if ( ! empty($matches[0]) ){
112
+ // $main_xml_tag = preg_replace("%[\s|<|>]%","",array_shift($matches[0]));
113
+ // }
114
+ // Determine XML recond element
115
+ $record_xml_tag = false;
116
+ preg_match_all("%<[\w]+[\s|>]{1}%", $export->options['custom_xml_template_loop'], $matches);
117
+ if ( ! empty($matches[0]) ){
118
+ $record_xml_tag = preg_replace("%[\s|<|>]%","",array_shift($matches[0]));
119
+ }
120
+
121
+ $xml_header = PMXE_XMLWriter::preprocess_xml($export->options['custom_xml_template_header']);
122
+ $xml_footer = PMXE_XMLWriter::preprocess_xml($export->options['custom_xml_template_footer']);
123
+
124
+ break;
125
+
126
+ default:
127
+ $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $export->options['main_xml_tag'], $export->id);
128
+ $record_xml_tag = apply_filters('wp_all_export_record_xml_tag', $export->options['record_xml_tag'], $export->id);
129
+ $xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$main_xml_tag.">";
130
+ $xml_footer = "</".$main_xml_tag.">";
131
+ break;
132
+
133
+ }
134
 
135
  $records_count = 0;
136
  $chunk_records_count = 0;
137
  $fileCount = 1;
138
 
139
+ $feed = $xml_header;
140
 
141
  $file = new PMXE_Chunk($filepath, array('element' => $record_xml_tag, 'encoding' => 'UTF-8'));
142
  // loop through the file until all lines are read
143
  while ($xml = $file->read()) {
144
 
145
  if ( ! empty($xml) )
146
+ {
 
 
 
 
 
 
 
 
147
  $records_count++;
148
  $chunk_records_count++;
149
  $feed .= $xml;
150
  }
151
 
152
  if ( $chunk_records_count == $splitSize or $records_count == $export->exported ){
153
+ $feed .= $xml_footer;
154
  $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath);
155
  file_put_contents($outputFile, $feed);
156
  if ( ! in_array($outputFile, $exportOptions['split_files_list']))
157
  $exportOptions['split_files_list'][] = $outputFile;
158
  $chunk_records_count = 0;
159
+ $feed = $xml_header;
160
  }
161
+ }
162
 
 
163
  break;
164
  case 'csv':
165
  $in = fopen($filepath, 'r');
189
  $rowCount++;
190
  }
191
  fclose($in);
192
+ fclose($out);
193
+
194
+ // convert splitted files into XLS format
195
+ if ( ! empty($exportOptions['split_files_list']) && ! empty($export->options['export_to_sheet']) and $export->options['export_to_sheet'] != 'csv' )
196
+ {
197
+ require_once PMXE_Plugin::ROOT_DIR . '/classes/PHPExcel/IOFactory.php';
198
+
199
+ foreach ($exportOptions['split_files_list'] as $key => $file)
200
+ {
201
+ $objReader = PHPExcel_IOFactory::createReader('CSV');
202
+ // If the files uses a delimiter other than a comma (e.g. a tab), then tell the reader
203
+ $objReader->setDelimiter($export->options['delimiter']);
204
+ // If the files uses an encoding other than UTF-8 or ASCII, then tell the reader
205
+ $objPHPExcel = $objReader->load($file);
206
+ switch ($export->options['export_to_sheet']){
207
+ case 'xls':
208
+ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
209
+ $objWriter->save(str_replace(".csv", ".xls", $file));
210
+ $exportOptions['split_files_list'][$key] = str_replace(".csv", ".xls", $file);
211
+ break;
212
+ case 'xlsx':
213
+ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
214
+ $objWriter->save(str_replace(".csv", ".xlsx", $file));
215
+ $exportOptions['split_files_list'][$key] = str_replace(".csv", ".xlsx", $file);
216
+ break;
217
+ }
218
+ @unlink($file);
219
+ }
220
+ }
221
 
222
  break;
223
 
228
 
229
  $export->set(array('options' => $exportOptions))->save();
230
  }
231
+ }
232
+
233
+ // convert CSV to XLS
234
+ if ( @file_exists($filepath) and $export->options['export_to'] == 'csv' && ! empty($export->options['export_to_sheet']) and $export->options['export_to_sheet'] != 'csv')
235
+ {
236
+
237
+ require_once PMXE_Plugin::ROOT_DIR . '/classes/PHPExcel/IOFactory.php';
238
+
239
+ $objReader = PHPExcel_IOFactory::createReader('CSV');
240
+ // If the files uses a delimiter other than a comma (e.g. a tab), then tell the reader
241
+ $objReader->setDelimiter($export->options['delimiter']);
242
+ // If the files uses an encoding other than UTF-8 or ASCII, then tell the reader
243
+
244
+ $objPHPExcel = $objReader->load($filepath);
245
+
246
+ switch ($export->options['export_to_sheet']) {
247
+ case 'xls':
248
+ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
249
+ $objWriter->save(str_replace(".csv", ".xls", $filepath));
250
+ @unlink($filepath);
251
+ $filepath = str_replace(".csv", ".xls", $filepath);
252
+ break;
253
+ case 'xlsx':
254
+ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
255
+ $objWriter->save(str_replace(".csv", ".xlsx", $filepath));
256
+ @unlink($filepath);
257
+ $filepath = str_replace(".csv", ".xlsx", $filepath);
258
+ break;
259
+ }
260
+
261
+ $exportOptions = $export->options;
262
+ $exportOptions['filepath'] = wp_all_export_get_relative_path($filepath);
263
+ $export->set(array('options' => $exportOptions))->save();
264
+
265
+ $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
266
+
267
+ if ( ! $is_secure_import ){
268
+ $wp_uploads = wp_upload_dir();
269
+ $wp_filetype = wp_check_filetype(basename($filepath), null );
270
+ $attachment_data = array(
271
+ 'guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path( $filepath ),
272
+ 'post_mime_type' => $wp_filetype['type'],
273
+ 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filepath)),
274
+ 'post_content' => '',
275
+ 'post_status' => 'inherit'
276
+ );
277
+ if ( ! empty($export->attch_id) )
278
+ {
279
+ $attach_id = $export->attch_id;
280
+ $attachment = get_post($attach_id);
281
+ if ($attachment)
282
+ {
283
+ update_attached_file( $attach_id, $filepath );
284
+ wp_update_attachment_metadata( $attach_id, $attachment_data );
285
+ }
286
+ else
287
+ {
288
+ $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
289
+ }
290
+ }
291
+ }
292
+
293
+ }
294
 
295
  // make a temporary copy of current file
296
  if ( empty($export->parent_id) and @file_exists($filepath) and @copy($filepath, str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath)))
299
  $exportOptions['current_filepath'] = str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath);
300
  $export->set(array('options' => $exportOptions))->save();
301
  }
302
+
303
+ $generateBundle = apply_filters('wp_all_export_generate_bundle', true);
304
 
305
+ if($generateBundle) {
 
306
 
307
+ // genereta export bundle
308
+ $export->generate_bundle();
309
+
310
+ if ( ! empty($export->parent_id) )
311
+ {
312
+ $parent_export = new PMXE_Export_Record();
313
+ $parent_export->getById($export->parent_id);
314
+ if ( ! $parent_export->isEmpty() )
315
+ {
316
+ $parent_export->generate_bundle(true);
317
+ }
318
+ }
319
+ }
320
+
321
+
322
+ // send exported data to zapier.com
323
+ $subscriptions = get_option('zapier_subscribe', array());
324
+ if ( ! empty($subscriptions) and empty($export->parent_id))
325
+ {
326
+
327
+ $wp_uploads = wp_upload_dir();
328
+
329
+ $fileurl = str_replace($wp_uploads['basedir'], $wp_uploads['baseurl'], $filepath);
330
+
331
+ $response = array(
332
+ 'website_url' => home_url(),
333
+ 'export_id' => $export->id,
334
+ 'export_name' => $export->friendly_name,
335
+ 'file_name' => basename($filepath),
336
+ 'file_type' => wp_all_export_get_export_format($export->options),
337
+ 'post_types_exported' => empty($export->options['cpt']) ? $export->options['wp_query'] : implode($export->options['cpt'], ','),
338
+ 'export_created_date' => $export->registered_on,
339
+ 'export_last_run_date' => date('Y-m-d H:i:s'),
340
+ 'export_trigger_type' => empty($_GET['export_key']) ? 'manual' : 'cron',
341
+ 'records_exported' => $export->exported,
342
+ 'export_file' => ''
343
+ );
344
+
345
+ if (file_exists($filepath))
346
+ {
347
+ $response['export_file_url'] = $fileurl;
348
+ $response['status'] = 200;
349
+ $response['message'] = 'OK';
350
+ }
351
+ else
352
+ {
353
+ $response['export_file_url'] = '';
354
+ $response['status'] = 300;
355
+ $response['message'] = 'File doesn\'t exist';
356
  }
357
+
358
+ $response = apply_filters('wp_all_export_zapier_response', $response);
359
+
360
+ foreach ($subscriptions as $zapier)
361
+ {
362
+ if (empty($zapier['target_url'])) continue;
363
+
364
+ wp_remote_post( $zapier['target_url'], array(
365
+ 'method' => 'POST',
366
+ 'timeout' => 45,
367
+ 'redirection' => 5,
368
+ 'httpversion' => '1.0',
369
+ 'blocking' => true,
370
+ 'headers' => array(
371
+ 'Content-Type' => 'application/json'
372
+ ),
373
+ 'body' => "[".json_encode($response)."]",
374
+ 'cookies' => array()
375
+ )
376
+ );
377
+ }
378
+ }
379
 
380
  // clean session
381
  if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
actions/pmxe_before_export.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function pmxe_pmxe_before_export($export_id)
4
+ {
5
+ $export = new PMXE_Export_Record();
6
+ $export->getById($export_id);
7
+
8
+ if ( ! $export->isEmpty() )
9
+ {
10
+ if ( ! $export->options['export_only_new_stuff'] )
11
+ {
12
+ $postList = new PMXE_Post_List();
13
+ $missingPosts = $postList->getBy(array('export_id' => $export_id, 'iteration !=' => --$export->iteration));
14
+ $missing_ids = array();
15
+ if ( ! $missingPosts->isEmpty() ):
16
+
17
+ foreach ($missingPosts as $missingPost)
18
+ {
19
+ $missing_ids[] = $missingPost['post_id'];
20
+ }
21
+
22
+ endif;
23
+
24
+ if ( ! empty($missing_ids))
25
+ {
26
+ global $wpdb;
27
+ // Delete records form pmxe_posts
28
+ $sql = "DELETE FROM " . PMXE_Plugin::getInstance()->getTablePrefix() . "posts WHERE post_id IN (" . implode(',', $missing_ids) . ") AND export_id = %d";
29
+ $wpdb->query(
30
+ $wpdb->prepare($sql, $export->id)
31
+ );
32
+ }
33
+ }
34
+
35
+ if ( empty($export->parent_id) )
36
+ {
37
+ delete_option( 'wp_all_export_queue_' . $export->id );
38
+ }
39
+ }
40
+ }
actions/wp_ajax_wpae_available_rules.php CHANGED
@@ -32,7 +32,7 @@ function pmxe_wp_ajax_wpae_available_rules(){
32
 
33
  <?php
34
  }
35
- elseif( in_array($post['selected'], array('post_date', 'user_registered', 'comment_date', 'cf__completed_date')) )
36
  {
37
  ?>
38
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
32
 
33
  <?php
34
  }
35
+ elseif( in_array($post['selected'], array('post_date', 'post_modified', 'user_registered', 'comment_date', 'cf__completed_date')) )
36
  {
37
  ?>
38
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
actions/wp_ajax_wpae_filtering_count.php CHANGED
@@ -32,18 +32,25 @@ function pmxe_wp_ajax_wpae_filtering_count(){
32
  }
33
 
34
  $export = new PMXE_Export_Record();
35
- $export->getById($export_id);
36
  if ( ! $export->isEmpty() )
37
  {
38
- XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
 
39
  XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
40
- if (!empty($post['wpml_lang'])) XmlExportEngine::$exportOptions['wpml_lang'] = $post['wpml_lang'];
 
 
 
 
41
  }
42
  else{
43
- XmlExportEngine::$exportOptions['wpml_lang'] = empty($post['wpml_lang']) ? 'all' : $post['wpml_lang'];
 
44
  }
45
 
46
  if (class_exists('SitePress') && !empty(XmlExportEngine::$exportOptions['wpml_lang'])){
 
47
  do_action( 'wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang'] );
48
  }
49
 
@@ -51,17 +58,17 @@ function pmxe_wp_ajax_wpae_filtering_count(){
51
  XmlExportEngine::$is_comment_export = ( 'comments' == $post['cpt'] ) ? true : false;
52
  XmlExportEngine::$is_taxonomy_export = ( 'taxonomies' == $post['cpt'] ) ? true : false;
53
  XmlExportEngine::$post_types = array($post['cpt']);
54
- XmlExportEngine::$exportOptions['export_variations'] = empty($post['export_variations']) ? XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION : $post['export_variations'];
55
 
56
- $filters = new XmlExportFiltering($filter_args);
 
 
57
 
58
- $filters->parseQuery();
59
-
60
  PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
61
  PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
62
  PMXE_Plugin::$session->save_data();
63
 
64
- $found_records = 0;
65
  $total_records = 0;
66
 
67
  $cpt = array($post['cpt']);
@@ -75,37 +82,59 @@ function pmxe_wp_ajax_wpae_filtering_count(){
75
  // get total users
76
  $totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
77
  if ( ! empty($totalQuery->results)){
78
- $found_records = $total_records = $totalQuery->get_total();
79
- }
 
 
 
 
 
 
 
 
 
 
80
  }
81
  elseif(XmlExportEngine::$is_comment_export)
82
- {
83
  // get total comments
84
  $totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));');
85
- $found_records = $total_records = $totalQuery->get_comments();
 
 
 
 
 
 
 
 
86
  }
87
  else
88
  {
89
  remove_all_actions('parse_query');
90
  remove_all_actions('pre_get_posts');
91
  remove_all_filters('posts_clauses');
 
 
 
 
 
 
 
 
92
 
93
  ob_start();
94
  // get custom post type records depends on filters
95
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
96
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
97
 
98
- // get total custom post type records
99
- $totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
100
- if ( ! empty($totalQuery->found_posts)){
101
- $found_records = $total_records = $totalQuery->found_posts;
102
  }
103
-
104
- wp_reset_postdata();
105
-
106
  remove_filter('posts_join', 'wp_all_export_posts_join');
107
  remove_filter('posts_where', 'wp_all_export_posts_where');
108
- ob_get_clean();
109
  }
110
  }
111
  else
@@ -115,8 +144,18 @@ function pmxe_wp_ajax_wpae_filtering_count(){
115
  // get total users
116
  $totalQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
117
  if ( ! empty($totalQuery->results)){
118
- $found_records = $total_records = $totalQuery->get_total();
119
- }
 
 
 
 
 
 
 
 
 
 
120
  }
121
  elseif( 'comments' == $post['cpt'] )
122
  {
@@ -126,25 +165,55 @@ function pmxe_wp_ajax_wpae_filtering_count(){
126
  if ( version_compare($wp_version, '4.2.0', '>=') )
127
  {
128
  $totalQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
129
- $found_records = $total_records = $totalQuery->get_comments();
130
  }
131
  else
132
  {
133
- $found_records = $total_records = get_comments( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
134
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
136
  elseif( 'taxonomies' == $post['cpt'] )
137
  {
138
  global $wp_version;
139
 
140
  if ( version_compare($wp_version, '4.6.0', '>=') ) {
 
 
 
 
 
 
 
 
 
 
 
 
141
  $exportQuery = new WP_Term_Query(array(
142
  'taxonomy' => $post['taxonomy_to_export'],
143
  'orderby' => 'name',
144
  'order' => 'ASC',
145
  'hide_empty' => FALSE
146
  ));
147
- $found_records = $found_records = count($exportQuery->get_terms());
 
 
148
  }
149
  else{
150
  ?>
@@ -155,19 +224,21 @@ function pmxe_wp_ajax_wpae_filtering_count(){
155
  <?php
156
  exit(json_encode(array('html' => ob_get_clean(), 'found_records' => 0, 'hasVariations' => $hasVariations))); die;
157
  }
 
158
  }
159
  else
160
  {
161
  remove_all_actions('parse_query');
162
- remove_all_actions('pre_get_posts');
163
- remove_all_filters('posts_clauses');
164
 
165
  $cpt = ($is_products_export) ? array('product', 'product_variation') : array($post['cpt']);
166
 
167
  // get total custom post type records
168
  $totalQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
169
- if ( ! empty($totalQuery->found_posts)){
170
- $total_records = $totalQuery->found_posts;
 
171
  }
172
 
173
  wp_reset_postdata();
@@ -175,40 +246,57 @@ function pmxe_wp_ajax_wpae_filtering_count(){
175
  ob_start();
176
  // get custom post type records depends on filters
177
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
 
 
178
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
179
 
180
- $exportQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
181
- if ( ! empty($exportQuery->found_posts))
182
- {
183
- $found_records = $exportQuery->found_posts;
184
- }
185
 
186
  if($is_products_export) {
187
- foreach($exportQuery->posts as $product) {
188
- if($product->post_type = 'product_variation') {
189
- $hasVariations = true;
190
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
192
  }
193
 
194
- remove_filter('posts_join', 'wp_all_export_posts_join');
195
  remove_filter('posts_where', 'wp_all_export_posts_where');
 
 
 
 
196
  ob_end_clean();
 
197
  }
198
- }
199
 
200
  PMXE_Plugin::$session->set('exportQuery', $exportQuery);
201
  PMXE_Plugin::$session->save_data();
202
-
203
  if ( $post['is_confirm_screen'] )
204
  {
205
  ?>
206
 
207
- <?php if ($found_records > 0) :?>
208
  <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?></h3>
209
- <h4><?php printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name($cpt, $found_records, $post)); ?></h4>
210
  <?php else: ?>
211
- <?php if (! $export->isEmpty() and $export->options['export_only_new_stuff']): ?>
212
  <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
213
  <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
214
  <?php elseif ($total_records > 0): ?>
@@ -226,11 +314,11 @@ function pmxe_wp_ajax_wpae_filtering_count(){
226
  {
227
  ?>
228
 
229
- <?php if ($found_records > 0) :?>
230
- <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records, $post); ?></strong> will be exported</h3>
231
- <h4><?php _e("Choose data to include in the export file.", "wp_all_export_plugin"); ?></h4>
232
  <?php else: ?>
233
- <?php if (! $export->isEmpty() and $export->options['export_only_new_stuff']): ?>
234
  <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
235
  <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
236
  <?php elseif ($total_records > 0): ?>
@@ -242,14 +330,14 @@ function pmxe_wp_ajax_wpae_filtering_count(){
242
  <?php endif; ?>
243
  <?php endif; ?>
244
 
245
- <?php
246
  }
247
  else
248
  {
249
  ?>
250
  <div class="founded_records">
251
- <?php if ($found_records > 0) :?>
252
- <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records, $post); ?></strong> will be exported</h3>
253
  <h4><?php _e("Continue to configure and run your export.", "wp_all_export_plugin"); ?></h4>
254
  <?php elseif ($total_records > 0): ?>
255
  <h4 style="line-height:60px;"><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
@@ -257,9 +345,26 @@ function pmxe_wp_ajax_wpae_filtering_count(){
257
  <h4 style="line-height:60px;"><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
258
  <?php endif; ?>
259
  </div>
260
- <?php
261
  }
262
 
263
- exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records, 'hasVariations' => $hasVariations))); die;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
 
265
  }
32
  }
33
 
34
  $export = new PMXE_Export_Record();
35
+ $export->getById($export_id);
36
  if ( ! $export->isEmpty() )
37
  {
38
+ XmlExportEngine::$exportRecord = $export;
39
+ XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
40
  XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
41
+ XmlExportEngine::$exportOptions['export_only_modified_stuff'] = $post['export_only_modified_stuff'];
42
+ if ( ! empty($post['wpml_lang']) ){
43
+ XmlExportEngine::$exportOptions['wpml_lang'] = $post['wpml_lang'];
44
+ $export->set(array('options' => XmlExportEngine::$exportOptions))->save();
45
+ }
46
  }
47
  else{
48
+ $sessionLang = empty(PMXE_Plugin::$session->wpml_lang) ? 'all' : PMXE_Plugin::$session->wpml_lang;
49
+ XmlExportEngine::$exportOptions['wpml_lang'] = empty($post['wpml_lang']) ? $sessionLang : $post['wpml_lang'];
50
  }
51
 
52
  if (class_exists('SitePress') && !empty(XmlExportEngine::$exportOptions['wpml_lang'])){
53
+ PMXE_Plugin::$session->set('wpml_lang', XmlExportEngine::$exportOptions['wpml_lang']);
54
  do_action( 'wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang'] );
55
  }
56
 
58
  XmlExportEngine::$is_comment_export = ( 'comments' == $post['cpt'] ) ? true : false;
59
  XmlExportEngine::$is_taxonomy_export = ( 'taxonomies' == $post['cpt'] ) ? true : false;
60
  XmlExportEngine::$post_types = array($post['cpt']);
61
+ XmlExportEngine::$exportOptions['export_variations'] = empty($post['export_variations']) ? XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION : $post['export_variations'];
62
 
63
+ $filters = \Wpae\Pro\Filtering\FilteringFactory::getFilterEngine();
64
+ $filters->init($filter_args);
65
+ $filters->parse();
66
 
 
 
67
  PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
68
  PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
69
  PMXE_Plugin::$session->save_data();
70
 
71
+ $foundRecords = 0;
72
  $total_records = 0;
73
 
74
  $cpt = array($post['cpt']);
82
  // get total users
83
  $totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
84
  if ( ! empty($totalQuery->results)){
85
+ $total_records = $totalQuery->get_total();
86
+ }
87
+
88
+ ob_start();
89
+ // get users depends on filters
90
+ add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
91
+ $exportQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
92
+ if ( ! empty($exportQuery->results)){
93
+ $foundRecords = $exportQuery->get_total();
94
+ }
95
+ remove_action('pre_user_query', 'wp_all_export_pre_user_query');
96
+ ob_get_clean();
97
  }
98
  elseif(XmlExportEngine::$is_comment_export)
99
+ {
100
  // get total comments
101
  $totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));');
102
+ $total_records = $totalQuery->get_comments();
103
+
104
+ ob_start();
105
+ // get comments depends on filters
106
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
107
+ $exportQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . '));');
108
+ $foundRecords = $exportQuery->get_comments();
109
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
110
+ ob_get_clean();
111
  }
112
  else
113
  {
114
  remove_all_actions('parse_query');
115
  remove_all_actions('pre_get_posts');
116
  remove_all_filters('posts_clauses');
117
+
118
+ // get total custom post type records
119
+ $totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
120
+ if ( ! empty($totalQuery->found_posts)){
121
+ $total_records = $totalQuery->found_posts;
122
+ }
123
+
124
+ wp_reset_postdata();
125
 
126
  ob_start();
127
  // get custom post type records depends on filters
128
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
129
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
130
 
131
+ $exportQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
132
+ if ( ! empty($exportQuery->found_posts)){
133
+ $foundRecords = $exportQuery->found_posts;
 
134
  }
 
 
 
135
  remove_filter('posts_join', 'wp_all_export_posts_join');
136
  remove_filter('posts_where', 'wp_all_export_posts_where');
137
+ ob_get_clean();
138
  }
139
  }
140
  else
144
  // get total users
145
  $totalQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
146
  if ( ! empty($totalQuery->results)){
147
+ $total_records = $totalQuery->get_total();
148
+ }
149
+
150
+ ob_start();
151
+ // get users depends on filters
152
+ add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
153
+ $exportQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
154
+ if ( ! empty($exportQuery->results)){
155
+ $foundRecords = $exportQuery->get_total();
156
+ }
157
+ remove_action('pre_user_query', 'wp_all_export_pre_user_query');
158
+ ob_get_clean();
159
  }
160
  elseif( 'comments' == $post['cpt'] )
161
  {
165
  if ( version_compare($wp_version, '4.2.0', '>=') )
166
  {
167
  $totalQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
168
+ $total_records = $totalQuery->get_comments();
169
  }
170
  else
171
  {
172
+ $total_records = get_comments( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
173
+ }
174
+
175
+ ob_start();
176
+ // get comments depends on filters
177
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
178
+
179
+ if ( version_compare($wp_version, '4.2.0', '>=') )
180
+ {
181
+ $exportQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC'));
182
+ $foundRecords = count($exportQuery->get_comments());
183
+ }
184
+ else
185
+ {
186
+ $foundRecords = count(get_comments( array( 'orderby' => 'comment_ID', 'order' => 'ASC')));
187
+ }
188
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
189
+ ob_get_clean();
190
  }
191
  elseif( 'taxonomies' == $post['cpt'] )
192
  {
193
  global $wp_version;
194
 
195
  if ( version_compare($wp_version, '4.6.0', '>=') ) {
196
+ $totalQuery = new WP_Term_Query(array(
197
+ 'taxonomy' => $post['taxonomy_to_export'],
198
+ 'orderby' => 'name',
199
+ 'order' => 'ASC',
200
+ 'number' => 10,
201
+ 'hide_empty' => FALSE
202
+ ));
203
+ $total_records = count($totalQuery->get_terms());
204
+
205
+ ob_start();
206
+ // get comments depends on filters
207
+ add_filter('terms_clauses', 'wp_all_export_terms_clauses', 10, 3);
208
  $exportQuery = new WP_Term_Query(array(
209
  'taxonomy' => $post['taxonomy_to_export'],
210
  'orderby' => 'name',
211
  'order' => 'ASC',
212
  'hide_empty' => FALSE
213
  ));
214
+ $foundRecords = count($exportQuery->get_terms());
215
+ remove_filter('terms_clauses', 'wp_all_export_terms_clauses');
216
+ ob_get_clean();
217
  }
218
  else{
219
  ?>
224
  <?php
225
  exit(json_encode(array('html' => ob_get_clean(), 'found_records' => 0, 'hasVariations' => $hasVariations))); die;
226
  }
227
+
228
  }
229
  else
230
  {
231
  remove_all_actions('parse_query');
232
+ remove_all_actions('pre_get_posts');
233
+ remove_all_filters('posts_clauses');
234
 
235
  $cpt = ($is_products_export) ? array('product', 'product_variation') : array($post['cpt']);
236
 
237
  // get total custom post type records
238
  $totalQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
239
+
240
+ if ( ! empty($totalQuery->found_posts)){
241
+ $total_records = $totalQuery->found_posts;
242
  }
243
 
244
  wp_reset_postdata();
246
  ob_start();
247
  // get custom post type records depends on filters
248
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
249
+ add_filter('posts_where', 'wp_all_export_numbering_where', 15, 1);
250
+
251
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
252
 
 
 
 
 
 
253
 
254
  if($is_products_export) {
255
+
256
+ add_filter('posts_where', 'wp_all_export_numbering_where', 15, 1);
257
+
258
+ $productsQuery = new WP_Query( array( 'post_type' => array('product', 'product_variation'), 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
259
+ $variationsQuery = new WP_Query( array( 'post_type' => 'product_variation', 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
260
+
261
+ $foundProducts = $productsQuery->found_posts;
262
+
263
+ $foundVariations = $variationsQuery->found_posts;
264
+
265
+ $foundRecords = $foundProducts;
266
+ $hasVariations = !!$foundVariations;
267
+
268
+ remove_filter('posts_where', 'wp_all_export_numbering_where');
269
+
270
+ } else {
271
+ $exportQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
272
+ if ( ! empty($exportQuery->found_posts))
273
+ {
274
+ $foundRecords = $exportQuery->found_posts;
275
  }
276
  }
277
 
 
278
  remove_filter('posts_where', 'wp_all_export_posts_where');
279
+ remove_filter('posts_where', 'wp_all_export_numbering_where');
280
+
281
+ remove_filter('posts_join', 'wp_all_export_posts_join');
282
+
283
  ob_end_clean();
284
+
285
  }
286
+ }
287
 
288
  PMXE_Plugin::$session->set('exportQuery', $exportQuery);
289
  PMXE_Plugin::$session->save_data();
290
+
291
  if ( $post['is_confirm_screen'] )
292
  {
293
  ?>
294
 
295
+ <?php if ($foundRecords > 0) :?>
296
  <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?></h3>
297
+ <h4><?php printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $foundRecords, wp_all_export_get_cpt_name($cpt, $foundRecords, $post)); ?></h4>
298
  <?php else: ?>
299
+ <?php if (! $export->isEmpty() and ($export->options['export_only_new_stuff'] or $export->options['export_only_modified_stuff'])): ?>
300
  <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
301
  <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
302
  <?php elseif ($total_records > 0): ?>
314
  {
315
  ?>
316
 
317
+ <?php if ($foundRecords > 0) :?>
318
+ <h3><span class="matches_count"><?php echo $foundRecords; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $foundRecords, $post); ?></strong> will be exported</h3>
319
+ <h4><?php _e("Drag &amp; drop data to include in the export file.", "wp_all_export_plugin"); ?></h4>
320
  <?php else: ?>
321
+ <?php if (! $export->isEmpty() and ($export->options['export_only_new_stuff'] or $export->options['export_only_modified_stuff'])): ?>
322
  <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
323
  <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
324
  <?php elseif ($total_records > 0): ?>
330
  <?php endif; ?>
331
  <?php endif; ?>
332
 
333
+ <?php
334
  }
335
  else
336
  {
337
  ?>
338
  <div class="founded_records">
339
+ <?php if ($foundRecords > 0) :?>
340
+ <h3><span class="matches_count"><?php echo $foundRecords; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $foundRecords, $post); ?></strong> will be exported</h3>
341
  <h4><?php _e("Continue to configure and run your export.", "wp_all_export_plugin"); ?></h4>
342
  <?php elseif ($total_records > 0): ?>
343
  <h4 style="line-height:60px;"><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
345
  <h4 style="line-height:60px;"><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt, 2, $post)); ?></h4>
346
  <?php endif; ?>
347
  </div>
348
+ <?php
349
  }
350
 
351
+ exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $foundRecords, 'hasVariations' => $hasVariations))); die;
352
+
353
+ }
354
+
355
+ function wp_all_export_numbering_where($where)
356
+ {
357
+ global $wpdb;
358
+
359
+ $excludeVariationsSql = " AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o
360
+ LEFT OUTER JOIN $wpdb->posts r ON o.post_parent = r.ID WHERE ((r.post_status = 'trash' OR r.ID IS NULL) AND o.post_type = 'product_variation'))";
361
+
362
+ $groupSql = "GROUP BY $wpdb->posts.ID";
363
+ if(strpos($where, $groupSql) !== false ){
364
+ $where = str_replace($groupSql, $excludeVariationsSql." ".$groupSql, $where);
365
+ } else {
366
+ $where = $where.$excludeVariationsSql;
367
+ }
368
 
369
+ return $where;
370
  }
actions/wp_ajax_wpae_preview.php CHANGED
@@ -19,12 +19,20 @@ function pmxe_wp_ajax_wpae_preview(){
19
  ob_start();
20
 
21
  $values = array();
22
-
23
- parse_str($_POST['data'], $values);
24
 
25
- $export_id = (isset($_GET['id'])) ? stripcslashes($_GET['id']) : 0;
26
 
27
- $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
 
 
 
 
 
 
 
 
 
 
28
 
29
  $exportOptions['custom_xml_template'] = (isset($_POST['custom_xml'])) ? stripcslashes($_POST['custom_xml']) : '';
30
  $exportOptions['custom_xml_template'] = str_replace('<ID>','<id>', $exportOptions['custom_xml_template'] );
@@ -38,11 +46,11 @@ function pmxe_wp_ajax_wpae_preview(){
38
 
39
  $engine = new XmlExportEngine($exportOptions, $errors);
40
 
41
- XmlExportEngine::$exportOptions = $exportOptions;
42
- XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
43
- XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
44
  XmlExportEngine::$is_taxonomy_export = $exportOptions['is_taxonomy_export'];
45
- XmlExportEngine::$exportID = $export_id;
46
 
47
  if ( class_exists('SitePress') && ! empty(XmlExportEngine::$exportOptions['wpml_lang'])){
48
  do_action( 'wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang'] );
@@ -57,7 +65,7 @@ function pmxe_wp_ajax_wpae_preview(){
57
 
58
  if ( ! empty(XmlExportEngine::$exportOptions['custom_xml_template'])){
59
 
60
- $engine->init_additional_data();
61
 
62
  $engine->init_available_data();
63
 
@@ -106,8 +114,8 @@ function pmxe_wp_ajax_wpae_preview(){
106
  exit( json_encode(array('html' => ob_get_clean())) );
107
  }
108
 
109
- if ( 'advanced' == $exportOptions['export_type'] )
110
- {
111
  if ( XmlExportEngine::$is_user_export ) {
112
  $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
113
  }
@@ -115,26 +123,36 @@ function pmxe_wp_ajax_wpae_preview(){
115
  $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
116
  }
117
  else {
 
 
 
 
118
  $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));');
119
- }
120
  }
121
  else
122
  {
123
  XmlExportEngine::$post_types = $exportOptions['cpt'];
124
 
125
  if ( in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt']))
126
- {
127
  add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
128
  $exportQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
129
  remove_action('pre_user_query', 'wp_all_export_pre_user_query');
130
  }
 
 
 
 
 
 
131
  elseif( in_array('comments', $exportOptions['cpt']))
132
- {
133
  add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
134
-
135
- global $wp_version;
136
 
137
- if ( version_compare($wp_version, '4.2.0', '>=') )
 
 
138
  {
139
  $exportQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10 ));
140
  }
@@ -145,18 +163,19 @@ function pmxe_wp_ajax_wpae_preview(){
145
  remove_action('comments_clauses', 'wp_all_export_comments_clauses');
146
  }
147
  else
148
- {
149
  remove_all_actions('parse_query');
150
  remove_all_actions('pre_get_posts');
151
- remove_all_filters('posts_clauses');
152
-
153
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
154
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
155
- $exportQuery = new WP_Query( array( 'post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 10 ));
 
156
  remove_filter('posts_where', 'wp_all_export_posts_where');
157
- remove_filter('posts_join', 'wp_all_export_posts_join');
158
  }
159
- }
160
 
161
  XmlExportEngine::$exportQuery = $exportQuery;
162
 
@@ -169,7 +188,7 @@ function pmxe_wp_ajax_wpae_preview(){
169
  <p class="wpallexport-preview-title"><?php echo sprintf("Preview first 10 %s", wp_all_export_get_cpt_name($exportOptions['cpt'], 10, $exportOptions)); ?></p>
170
 
171
  <div class="wpallexport-preview-content">
172
-
173
  <?php
174
 
175
  if(!$custom_xml_valid) {
@@ -187,22 +206,23 @@ function pmxe_wp_ajax_wpae_preview(){
187
  exit( json_encode(array('html' => ob_get_clean())) );
188
  }
189
 
190
- $wp_uploads = wp_upload_dir();
191
-
192
  $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
193
- if ( @file_exists($functions) )
194
  require_once $functions;
 
195
 
196
  switch ($exportOptions['export_to']) {
197
 
198
- case 'xml':
199
 
200
  $dom = new DOMDocument('1.0', $exportOptions['encoding']);
201
  libxml_use_internal_errors(true);
202
  try{
203
  $xml = XmlCsvExport::export_xml(true);
204
  } catch (WpaeMethodNotFoundException $e) {
205
-
206
  // Find the line where the function is
207
  $errorMessage = '';
208
  $functionName = $e->getMessage();
@@ -359,15 +379,15 @@ function pmxe_wp_ajax_wpae_preview(){
359
  }
360
  }
361
  }
362
-
363
  break;
364
 
365
  case 'csv':
366
- ?>
367
  <small>
368
- <?php
369
-
370
- $csv = XmlCsvExport::export_csv( true );
371
 
372
  if (!empty($csv)){
373
  $csv_rows = array_filter(explode("\n", $csv));
@@ -375,8 +395,8 @@ function pmxe_wp_ajax_wpae_preview(){
375
  ?>
376
  <table class="pmxe_preview" cellpadding="0" cellspacing="0">
377
  <?php
378
- foreach ($csv_rows as $rkey => $row) {
379
- $cells = str_getcsv($row, $exportOptions['delimiter']);
380
  if ($cells){
381
  ?>
382
  <tr>
@@ -393,18 +413,18 @@ function pmxe_wp_ajax_wpae_preview(){
393
  ?>
394
  </tr>
395
  <?php
396
- }
397
  }
398
  ?>
399
  </table>
400
  <?php
401
- }
402
  }
403
  else{
404
  _e('Data not found.', 'wp_all_export_plugin');
405
  }
406
  ?>
407
- </small>
408
  <?php
409
  break;
410
 
19
  ob_start();
20
 
21
  $values = array();
 
 
22
 
23
+ parse_str($_POST['data'], $values);
24
 
25
+
26
+ if(is_array($values['cc_options'])) {
27
+
28
+ foreach ($values['cc_options'] as &$value) {
29
+ $value = stripslashes($value);
30
+ }
31
+ }
32
+
33
+ $export_id = (isset($_GET['id'])) ? stripcslashes($_GET['id']) : 0;
34
+
35
+ $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
36
 
37
  $exportOptions['custom_xml_template'] = (isset($_POST['custom_xml'])) ? stripcslashes($_POST['custom_xml']) : '';
38
  $exportOptions['custom_xml_template'] = str_replace('<ID>','<id>', $exportOptions['custom_xml_template'] );
46
 
47
  $engine = new XmlExportEngine($exportOptions, $errors);
48
 
49
+ XmlExportEngine::$exportOptions = $exportOptions;
50
+ XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
51
+ XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
52
  XmlExportEngine::$is_taxonomy_export = $exportOptions['is_taxonomy_export'];
53
+ XmlExportEngine::$exportID = $export_id;
54
 
55
  if ( class_exists('SitePress') && ! empty(XmlExportEngine::$exportOptions['wpml_lang'])){
56
  do_action( 'wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang'] );
65
 
66
  if ( ! empty(XmlExportEngine::$exportOptions['custom_xml_template'])){
67
 
68
+ $engine->init_additional_data();
69
 
70
  $engine->init_available_data();
71
 
114
  exit( json_encode(array('html' => ob_get_clean())) );
115
  }
116
 
117
+ if ( 'advanced' == $exportOptions['export_type'] )
118
+ {
119
  if ( XmlExportEngine::$is_user_export ) {
120
  $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
121
  }
123
  $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
124
  }
125
  else {
126
+ remove_all_actions('parse_query');
127
+ remove_all_actions('pre_get_posts');
128
+ remove_all_filters('posts_clauses');
129
+
130
  $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));');
131
+ }
132
  }
133
  else
134
  {
135
  XmlExportEngine::$post_types = $exportOptions['cpt'];
136
 
137
  if ( in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt']))
138
+ {
139
  add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
140
  $exportQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
141
  remove_action('pre_user_query', 'wp_all_export_pre_user_query');
142
  }
143
+ elseif ( in_array('taxonomies', $exportOptions['cpt']))
144
+ {
145
+ add_filter('terms_clauses', 'wp_all_export_terms_clauses', 10, 3);
146
+ $exportQuery = new WP_Term_Query( array( 'taxonomy' => $exportOptions['taxonomy_to_export'], 'orderby' => 'term_id', 'order' => 'ASC', 'number' => 10, 'hide_empty' => false ));
147
+ remove_filter('terms_clauses', 'wp_all_export_terms_clauses');
148
+ }
149
  elseif( in_array('comments', $exportOptions['cpt']))
150
+ {
151
  add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
 
 
152
 
153
+ global $wp_version;
154
+
155
+ if ( version_compare($wp_version, '4.2.0', '>=') )
156
  {
157
  $exportQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10 ));
158
  }
163
  remove_action('comments_clauses', 'wp_all_export_comments_clauses');
164
  }
165
  else
166
+ {
167
  remove_all_actions('parse_query');
168
  remove_all_actions('pre_get_posts');
169
+ remove_all_filters('posts_clauses');
170
+
171
  add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
172
  add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
173
+ $exportQuery = new WP_Query( array( 'post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 10 ));
174
+
175
  remove_filter('posts_where', 'wp_all_export_posts_where');
176
+ remove_filter('posts_join', 'wp_all_export_posts_join');
177
  }
178
+ }
179
 
180
  XmlExportEngine::$exportQuery = $exportQuery;
181
 
188
  <p class="wpallexport-preview-title"><?php echo sprintf("Preview first 10 %s", wp_all_export_get_cpt_name($exportOptions['cpt'], 10, $exportOptions)); ?></p>
189
 
190
  <div class="wpallexport-preview-content">
191
+
192
  <?php
193
 
194
  if(!$custom_xml_valid) {
206
  exit( json_encode(array('html' => ob_get_clean())) );
207
  }
208
 
209
+ $wp_uploads = wp_upload_dir();
210
+
211
  $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
212
+ if ( @file_exists($functions) ) {
213
  require_once $functions;
214
+ }
215
 
216
  switch ($exportOptions['export_to']) {
217
 
218
+ case 'xml':
219
 
220
  $dom = new DOMDocument('1.0', $exportOptions['encoding']);
221
  libxml_use_internal_errors(true);
222
  try{
223
  $xml = XmlCsvExport::export_xml(true);
224
  } catch (WpaeMethodNotFoundException $e) {
225
+
226
  // Find the line where the function is
227
  $errorMessage = '';
228
  $functionName = $e->getMessage();
379
  }
380
  }
381
  }
382
+
383
  break;
384
 
385
  case 'csv':
386
+ ?>
387
  <small>
388
+ <?php
389
+
390
+ $csv = XmlCsvExport::export_csv( true );
391
 
392
  if (!empty($csv)){
393
  $csv_rows = array_filter(explode("\n", $csv));
395
  ?>
396
  <table class="pmxe_preview" cellpadding="0" cellspacing="0">
397
  <?php
398
+ foreach ($csv_rows as $rkey => $row) {
399
+ $cells = str_getcsv($row, $exportOptions['delimiter']);
400
  if ($cells){
401
  ?>
402
  <tr>
413
  ?>
414
  </tr>
415
  <?php
416
+ }
417
  }
418
  ?>
419
  </table>
420
  <?php
421
+ }
422
  }
423
  else{
424
  _e('Data not found.', 'wp_all_export_plugin');
425
  }
426
  ?>
427
+ </small>
428
  <?php
429
  break;
430
 
actions/wp_ajax_wpallexport.php CHANGED
@@ -1,284 +1,323 @@
1
  <?php
2
  /**
3
- * AJAX action export processing
4
- */
5
- function pmxe_wp_ajax_wpallexport(){
6
-
7
- if ( ! check_ajax_referer( 'wp_all_export_secure', 'security', false )){
8
- exit( __('Security check', 'wp_all_export_plugin') );
9
- }
10
-
11
- if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
12
- exit( __('Security check', 'wp_all_export_plugin') );
13
- }
14
-
15
- $input = new PMXE_Input();
16
- $export_id = $input->get('id', 0);
17
- if (empty($export_id))
18
- {
19
- $export_id = ( ! empty(PMXE_Plugin::$session->update_previous)) ? PMXE_Plugin::$session->update_previous : 0;
20
- }
21
-
22
- $wp_uploads = wp_upload_dir();
23
-
24
- $export = new PMXE_Export_Record();
25
-
26
- $export->getById($export_id);
27
-
28
- if ( $export->isEmpty() ){
29
- exit( __('Export is not defined.', 'wp_all_export_plugin') );
30
- }
31
-
32
- $exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
33
-
34
- wp_reset_postdata();
35
-
36
- XmlExportEngine::$exportOptions = $exportOptions;
37
- XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
38
- XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
39
- XmlExportEngine::$exportID = $export_id;
40
- XmlExportEngine::$exportRecord = $export;
41
-
42
- if ( class_exists('SitePress') && ! empty(XmlExportEngine::$exportOptions['wpml_lang'])){
43
- do_action( 'wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang'] );
44
- }
45
-
46
- $errors = new WP_Error();
47
- $engine = new XmlExportEngine($exportOptions, $errors);
48
-
49
- $posts_per_page = $exportOptions['records_per_iteration'];
50
-
51
- if ('advanced' == $exportOptions['export_type'])
52
- {
53
- if (XmlExportEngine::$is_user_export)
54
- {
55
- exit( json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin'))) );
56
- }
57
- elseif(XmlExportEngine::$is_comment_export)
58
- {
59
- exit( json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin'))) );
60
- }
61
- else
62
- {
63
- remove_all_actions('parse_query');
64
- remove_all_actions('pre_get_posts');
65
- remove_all_filters('posts_clauses');
66
-
67
- add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
68
- add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
69
- $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
70
- remove_filter('posts_where', 'wp_all_export_posts_where');
71
- remove_filter('posts_join', 'wp_all_export_posts_join');
72
- }
73
- }
74
- else
75
- {
76
- XmlExportEngine::$post_types = $exportOptions['cpt'];
77
-
78
- // $is_products_export = ($exportOptions['cpt'] == 'product' and class_exists('WooCommerce'));
79
-
80
- if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt']))
81
- {
82
- exit( json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin'))) );
83
- }
84
- elseif(in_array('comments', $exportOptions['cpt']))
85
- {
86
- exit( json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin'))) );
87
- }
88
- else
89
- {
90
- remove_all_actions('parse_query');
91
- remove_all_actions('pre_get_posts');
92
- remove_all_filters('posts_clauses');
93
-
94
- add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
95
- add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
96
- $exportQuery = new WP_Query( array( 'post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page ));
97
- remove_filter('posts_where', 'wp_all_export_posts_where');
98
- remove_filter('posts_join', 'wp_all_export_posts_join');
99
- }
100
- }
101
-
102
- XmlExportEngine::$exportQuery = $exportQuery;
 
 
 
 
 
 
 
 
 
 
103
 
104
  $engine->init_additional_data();
105
 
106
- // get total founded records
107
- if (XmlExportEngine::$is_comment_export)
108
- {
109
-
110
- }
111
- else
112
- {
113
- $foundPosts = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->found_posts : $exportQuery->get_total();
114
- $postCount = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->post_count : count($exportQuery->get_results());
115
- }
116
- // [ \get total founded records ]
117
-
118
- if ( ! $export->exported )
119
- {
120
- $attachment_list = $export->options['attachment_list'];
121
- if ( ! empty($attachment_list))
122
- {
123
- foreach ($attachment_list as $attachment) {
124
- if ( ! is_numeric($attachment))
125
- {
126
- @unlink($attachment);
127
- }
128
- }
129
- }
130
- $exportOptions['attachment_list'] = array();
131
- $export->set(array(
132
- 'options' => $exportOptions
133
- ))->save();
134
-
135
- $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
136
-
137
- if ( $is_secure_import and ! empty($exportOptions['filepath'])){
138
-
139
- $exportOptions['filepath'] = '';
140
-
141
- }
142
-
143
- PMXE_Plugin::$session->set('count', $foundPosts);
144
- PMXE_Plugin::$session->save_data();
145
- }
146
-
147
- // if posts still exists then export them
148
- if ( $postCount )
149
- {
150
- XmlCsvExport::export();
151
-
152
- $export->set(array(
153
- 'exported' => $export->exported + $postCount,
154
- 'last_activity' => date('Y-m-d H:i:s')
155
- ))->save();
156
-
157
- }
158
-
159
- if ($posts_per_page != -1 and $postCount)
160
- {
161
- wp_send_json(array(
162
- 'export_id' => $export->id,
163
- 'queue_export' => false,
164
- 'exported' => $export->exported,
165
- 'percentage' => ceil(($export->exported/$foundPosts) * 100),
166
- 'done' => false,
167
- 'records_per_request' => $exportOptions['records_per_iteration']
168
- ));
169
- }
170
- else
171
- {
172
-
173
- if ( file_exists(PMXE_Plugin::$session->file)){
174
-
175
- if ($exportOptions['export_to'] == 'xml')
176
- {
177
-
178
- $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], $export->id);
179
-
180
- file_put_contents(PMXE_Plugin::$session->file, '</'.$main_xml_tag.'>', FILE_APPEND);
181
-
182
- $xml_footer = apply_filters('wp_all_export_xml_footer', '', $export->id);
183
-
184
- if ( ! empty($xml_footer) ) file_put_contents(PMXE_Plugin::$session->file, $xml_footer, FILE_APPEND);
185
- }
186
-
187
- $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
188
-
189
- if ( ! $is_secure_import ){
190
-
191
- if ( ! $export->isEmpty() ){
192
-
193
- $wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null );
194
- $attachment_data = array(
195
- 'guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path( PMXE_Plugin::$session->file ),
196
- 'post_mime_type' => $wp_filetype['type'],
197
- 'post_title' => preg_replace('/\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)),
198
- 'post_content' => '',
199
- 'post_status' => 'inherit'
200
- );
201
-
202
- if ( empty($export->attch_id) )
203
- {
204
- $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
205
- }
206
- elseif($export->options['creata_a_new_export_file'] )
207
- {
208
- $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
209
- }
210
- else
211
- {
212
- $attach_id = $export->attch_id;
213
- $attachment = get_post($attach_id);
214
- if ($attachment)
215
- {
216
- update_attached_file( $attach_id, PMXE_Plugin::$session->file );
217
- wp_update_attachment_metadata( $attach_id, $attachment_data );
218
- }
219
- else
220
- {
221
- $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
222
- }
223
- }
224
-
225
- if ( ! in_array($attach_id, $exportOptions['attachment_list'])) $exportOptions['attachment_list'][] = $attach_id;
226
-
227
- $export->set(array(
228
- 'attch_id' => $attach_id,
229
- 'options' => $exportOptions
230
- ))->save();
231
- }
232
-
233
- }
234
- else
235
- {
236
- $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file);
237
-
238
- if ( ! $export->isEmpty() ){
239
- $export->set(array(
240
- 'options' => $exportOptions
241
- ))->save();
242
- }
243
-
244
- }
245
-
246
- PMXE_Wpallimport::generateImportTemplate( $export, PMXE_Plugin::$session->file, PMXE_Plugin::$session->count );
247
-
248
- }
249
-
250
- $export->set(array(
251
- 'executing' => 0,
252
- 'canceled' => 0,
253
- 'iteration' => ++$export->iteration
254
- ))->save();
255
-
256
- do_action('pmxe_after_export', $export->id, $export);
257
-
258
- $queue_exports = empty($export->parent_id) ? array() : get_option( 'wp_all_export_queue_' . $export->parent_id );
259
-
260
- if ( ! empty($queue_exports) and ! empty($export->parent_id))
261
- {
262
- array_shift($queue_exports);
263
- }
264
-
265
- if ( empty($queue_exports) )
266
- {
267
- delete_option( 'wp_all_export_queue_' . ( empty($export->parent_id) ? $export->id : $export->parent_id ) );
268
- }
269
- else
270
- {
271
- update_option( 'wp_all_export_queue_' . ( empty($export->parent_id) ? $export->id : $export->parent_id ), $queue_exports );
272
- }
273
-
274
- wp_send_json(array(
275
- 'export_id' => $export->id,
276
- 'queue_export' => empty($queue_exports) ? false : $queue_exports[0],
277
- 'exported' => $export->exported,
278
- 'percentage' => 100,
279
- 'done' => true,
280
- 'records_per_request' => $exportOptions['records_per_iteration']
281
- ));
282
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  }
284
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * AJAX action export processing
4
+ */
5
+ function pmxe_wp_ajax_wpallexport()
6
+ {
7
+
8
+ if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
9
+ exit(__('Security check', 'wp_all_export_plugin'));
10
+ }
11
+
12
+ if (!current_user_can(PMXE_Plugin::$capabilities)) {
13
+ exit(__('Security check', 'wp_all_export_plugin'));
14
+ }
15
+
16
+ $input = new PMXE_Input();
17
+ $export_id = $input->get('id', 0);
18
+ if (empty($export_id)) {
19
+ $export_id = (!empty(PMXE_Plugin::$session->update_previous)) ? PMXE_Plugin::$session->update_previous : 0;
20
+ }
21
+
22
+ $wp_uploads = wp_upload_dir();
23
+
24
+ $export = new PMXE_Export_Record();
25
+
26
+ $export->getById($export_id);
27
+
28
+ if ($export->isEmpty()) {
29
+ exit(__('Export is not defined.', 'wp_all_export_plugin'));
30
+ }
31
+
32
+ $exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
33
+
34
+ wp_reset_postdata();
35
+
36
+ XmlExportEngine::$exportOptions = $exportOptions;
37
+ XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
38
+ XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
39
+ XmlExportEngine::$is_taxonomy_export = empty($exportOptions['is_taxonomy_export']) ? false : $exportOptions['is_taxonomy_export'];
40
+ XmlExportEngine::$exportID = $export_id;
41
+ XmlExportEngine::$exportRecord = $export;
42
+
43
+ if (class_exists('SitePress') && !empty(XmlExportEngine::$exportOptions['wpml_lang'])) {
44
+ do_action('wpml_switch_language', XmlExportEngine::$exportOptions['wpml_lang']);
45
+ }
46
+
47
+ $errors = new WP_Error();
48
+ $engine = new XmlExportEngine($exportOptions, $errors);
49
+
50
+ $posts_per_page = $exportOptions['records_per_iteration'];
51
+
52
+ if ($exportOptions['export_type'] == 'advanced') {
53
+ if (XmlExportEngine::$is_user_export) {
54
+ add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
55
+ $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'number\' => ' . $posts_per_page . ' ));');
56
+ remove_action('pre_user_query', 'wp_all_export_pre_user_query');
57
+ } elseif (XmlExportEngine::$is_comment_export) {
58
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
59
+ $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'number\' => ' . $posts_per_page . ' ));');
60
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
61
+ } else {
62
+ remove_all_actions('parse_query');
63
+ remove_all_actions('pre_get_posts');
64
+ remove_all_filters('posts_clauses');
65
+
66
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
67
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
68
+ $code = 'return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));';
69
+ $exportQuery = eval($code);
70
+
71
+ remove_filter('posts_where', 'wp_all_export_posts_where');
72
+ remove_filter('posts_join', 'wp_all_export_posts_join');
73
+ }
74
+ } else {
75
+ XmlExportEngine::$post_types = $exportOptions['cpt'];
76
+
77
+ // $is_products_export = ($exportOptions['cpt'] == 'product' and class_exists('WooCommerce'));
78
+
79
+ if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt'])) {
80
+ add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
81
+ $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => $posts_per_page, 'offset' => $export->exported));
82
+ remove_action('pre_user_query', 'wp_all_export_pre_user_query');
83
+ } elseif (in_array('taxonomies', $exportOptions['cpt'])) {
84
+ add_filter('terms_clauses', 'wp_all_export_terms_clauses', 10, 3);
85
+ $exportQuery = new WP_Term_Query(array('taxonomy' => $exportOptions['taxonomy_to_export'], 'orderby' => 'term_id', 'order' => 'ASC', 'number' => $posts_per_page, 'offset' => $export->exported, 'hide_empty' => false));
86
+ $postCount = count($exportQuery->get_terms());
87
+ remove_filter('terms_clauses', 'wp_all_export_terms_clauses');
88
+ } elseif (in_array('comments', $exportOptions['cpt'])) {
89
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
90
+
91
+ global $wp_version;
92
+
93
+ if (version_compare($wp_version, '4.2.0', '>=')) {
94
+ $exportQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => $posts_per_page, 'offset' => $export->exported));
95
+ } else {
96
+ $exportQuery = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => $posts_per_page, 'offset' => $export->exported));
97
+ }
98
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
99
+ } else {
100
+ remove_all_actions('parse_query');
101
+ remove_all_actions('pre_get_posts');
102
+ remove_all_filters('posts_clauses');
103
+
104
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
105
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
106
+ $exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page));
107
+ remove_filter('posts_where', 'wp_all_export_posts_where');
108
+ remove_filter('posts_join', 'wp_all_export_posts_join');
109
+ }
110
+ }
111
+
112
+ XmlExportEngine::$exportQuery = $exportQuery;
113
 
114
  $engine->init_additional_data();
115
 
116
+ // get total founded records
117
+ if (XmlExportEngine::$is_comment_export) {
118
+ global $wp_version;
119
+
120
+ if (version_compare($wp_version, '4.2.0', '>=')) {
121
+ $postCount = count($exportQuery->get_comments());
122
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
123
+ $result = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
124
+ $foundPosts = $result->get_comments();
125
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
126
+ } else {
127
+ $postCount = count($exportQuery);
128
+ add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
129
+ $foundPosts = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
130
+ remove_action('comments_clauses', 'wp_all_export_comments_clauses');
131
+ }
132
+ } elseif (XmlExportEngine::$is_taxonomy_export) {
133
+ add_filter('terms_clauses', 'wp_all_export_terms_clauses', 10, 3);
134
+ $result = new WP_Term_Query(array('taxonomy' => $exportOptions['taxonomy_to_export'], 'orderby' => 'term_id', 'order' => 'ASC', 'hide_empty' => false));
135
+ $foundPosts = count($result->get_terms());
136
+ remove_filter('terms_clauses', 'wp_all_export_terms_clauses');
137
+ } else {
138
+
139
+ if(XmlExportEngine::$is_user_export) {
140
+ $foundPosts = $exportQuery->get_total();
141
+ $postCount = count($exportQuery->get_results());
142
+ } else {
143
+ $foundPosts = $exportQuery->found_posts;
144
+ $postCount = $exportQuery->post_count;
145
+ }
146
+ }
147
+ // [ \get total founded records ]
148
+
149
+ if (!$export->exported) {
150
+ $attachment_list = $export->options['attachment_list'];
151
+ if (!empty($attachment_list)) {
152
+ foreach ($attachment_list as $attachment) {
153
+ if (!is_numeric($attachment)) {
154
+ @unlink($attachment);
155
+ }
156
+ }
157
+ }
158
+ $exportOptions['attachment_list'] = array();
159
+ $export->set(array(
160
+ 'options' => $exportOptions
161
+ ))->save();
162
+
163
+ $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
164
+
165
+ if ($is_secure_import and !empty($exportOptions['filepath'])) {
166
+
167
+ $exportOptions['filepath'] = '';
168
+ }
169
+
170
+ PMXE_Plugin::$session->set('count', $foundPosts);
171
+ PMXE_Plugin::$session->save_data();
172
+ }
173
+
174
+ $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
175
+ if (@file_exists($functions))
176
+ require_once $functions;
177
+
178
+ // Export posts
179
+ XmlCsvExport::export();
180
+
181
+ $export->set(array(
182
+ 'exported' => $export->exported + $postCount,
183
+ 'last_activity' => date('Y-m-d H:i:s')
184
+ ))->save();
185
+
186
+
187
+ if ($posts_per_page != -1 && $postCount && !isAdvancedSingleItemExport($postCount, $foundPosts)) {
188
+
189
+ $percentage = ceil(($export->exported / $foundPosts) * 100);
190
+
191
+ wp_send_json(array(
192
+ 'export_id' => $export->id,
193
+ 'queue_export' => false,
194
+ 'exported' => $export->exported,
195
+ 'percentage' => $percentage,
196
+ 'done' => false,
197
+ 'posts' => $postCount,
198
+ 'code' => $code,
199
+ 'records_per_request' => $exportOptions['records_per_iteration']
200
+ ));
201
+ } else {
202
+ if (file_exists(PMXE_Plugin::$session->file)) {
203
+
204
+ if ($exportOptions['export_to'] == 'xml') {
205
+ switch (XmlExportEngine::$exportOptions['xml_template_type']) {
206
+ case 'custom':
207
+ require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
208
+ file_put_contents(PMXE_Plugin::$session->file, PMXE_XMLWriter::preprocess_xml(XmlExportEngine::$exportOptions['custom_xml_template_footer']), FILE_APPEND);
209
+ break;
210
+ default:
211
+
212
+ break;
213
+ }
214
+
215
+ if (!in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
216
+ $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], $export->id);
217
+
218
+ file_put_contents(PMXE_Plugin::$session->file, '</' . $main_xml_tag . '>', FILE_APPEND);
219
+
220
+ $xml_footer = apply_filters('wp_all_export_xml_footer', '', $export->id);
221
+
222
+ if (!empty($xml_footer)) file_put_contents(PMXE_Plugin::$session->file, $xml_footer, FILE_APPEND);
223
+ }
224
+ }
225
+
226
+ $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
227
+
228
+ if (!$is_secure_import) {
229
+
230
+ if (!$export->isEmpty()) {
231
+
232
+ $wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null);
233
+ $attachment_data = array(
234
+ 'guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file),
235
+ 'post_mime_type' => $wp_filetype['type'],
236
+ 'post_title' => preg_replace('/\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)),
237
+ 'post_content' => '',
238
+ 'post_status' => 'inherit'
239
+ );
240
+
241
+ if (empty($export->attch_id)) {
242
+ $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
243
+ } elseif ($export->options['creata_a_new_export_file']) {
244
+ $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
245
+ } else {
246
+ $attach_id = $export->attch_id;
247
+ $attachment = get_post($attach_id);
248
+ if ($attachment) {
249
+ update_attached_file($attach_id, PMXE_Plugin::$session->file);
250
+ wp_update_attachment_metadata($attach_id, $attachment_data);
251
+ } else {
252
+ $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
253
+ }
254
+ }
255
+
256
+ if (!in_array($attach_id, $exportOptions['attachment_list'])) $exportOptions['attachment_list'][] = $attach_id;
257
+
258
+ $export->set(array(
259
+ 'attch_id' => $attach_id,
260
+ 'options' => $exportOptions
261
+ ))->save();
262
+ }
263
+
264
+ } else {
265
+ $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file);
266
+
267
+ if (!$export->isEmpty()) {
268
+ $export->set(array(
269
+ 'options' => $exportOptions
270
+ ))->save();
271
+ }
272
+
273
+ }
274
+
275
+ PMXE_Wpallimport::generateImportTemplate($export, PMXE_Plugin::$session->file, PMXE_Plugin::$session->count);
276
+
277
+ }
278
+
279
+ $export->set(array(
280
+ 'executing' => 0,
281
+ 'canceled' => 0,
282
+ 'iteration' => ++$export->iteration
283
+ ))->save();
284
+
285
+ do_action('pmxe_after_export', $export->id, $export);
286
+
287
+ $queue_exports = empty($export->parent_id) ? array() : get_option('wp_all_export_queue_' . $export->parent_id);
288
+
289
+ // update child exports with correct WHERE & JOIN filters
290
+ if (!empty($export->options['cpt']) and class_exists('WooCommerce') and in_array('shop_order', $export->options['cpt']) and empty($export->parent_id)) {
291
+ $queue_exports = XmlExportWooCommerceOrder::prepare_child_exports($export);
292
+ }
293
+
294
+ if (!empty($queue_exports) and !empty($export->parent_id)) {
295
+ array_shift($queue_exports);
296
+ }
297
+
298
+ if (empty($queue_exports)) {
299
+ delete_option('wp_all_export_queue_' . (empty($export->parent_id) ? $export->id : $export->parent_id));
300
+ } else {
301
+ update_option('wp_all_export_queue_' . (empty($export->parent_id) ? $export->id : $export->parent_id), $queue_exports);
302
+ }
303
+
304
+ wp_send_json(array(
305
+ 'export_id' => $export->id,
306
+ 'queue_export' => empty($queue_exports) ? false : $queue_exports[0],
307
+ 'exported' => $export->exported,
308
+ 'percentage' => 100,
309
+ 'done' => true,
310
+ 'records_per_request' => $exportOptions['records_per_iteration']
311
+ ));
312
+ }
313
  }
314
 
315
+ /**
316
+ * @param $postCount
317
+ * @param $foundPosts
318
+ * @return bool
319
+ */
320
+ function isAdvancedSingleItemExport($postCount, $foundPosts)
321
+ {
322
+ return ($postCount == 1 && $foundPosts == 1);
323
+ }
actions/wp_loaded.php CHANGED
@@ -4,5 +4,4 @@ function pmxe_wp_loaded() {
4
 
5
  @ini_set("max_input_time", PMXE_Plugin::getInstance()->getOption('max_input_time'));
6
  @ini_set("max_execution_time", PMXE_Plugin::getInstance()->getOption('max_execution_time'));
7
-
8
  }
4
 
5
  @ini_set("max_input_time", PMXE_Plugin::getInstance()->getOption('max_input_time'));
6
  @ini_set("max_execution_time", PMXE_Plugin::getInstance()->getOption('max_execution_time'));
 
7
  }
classes/XMLWriter.php CHANGED
@@ -177,6 +177,11 @@ class PMXE_XMLWriter extends XMLWriter
177
  $originalValue = $v;
178
 
179
  if (is_array($v)) {
 
 
 
 
 
180
  $delimiter = uniqid();
181
  $node_tpl = preg_replace('%\[(.*)\{'.$key.'\}([^\[]*)\]%', "[$1explode('" . $delimiter . "', '" . implode($delimiter, $v) . "')$2]", $node_tpl);
182
  $v = "[explode('" . $delimiter . "', '" . implode($delimiter, $v) . "')]";
177
  $originalValue = $v;
178
 
179
  if (is_array($v)) {
180
+ foreach($v as &$val) {
181
+ $val = str_replace("\"","**DOUBLEQUOT**",$val);
182
+ $val = str_replace("'","**SINGLEQUOT**",$val);
183
+ }
184
+
185
  $delimiter = uniqid();
186
  $node_tpl = preg_replace('%\[(.*)\{'.$key.'\}([^\[]*)\]%', "[$1explode('" . $delimiter . "', '" . implode($delimiter, $v) . "')$2]", $node_tpl);
187
  $v = "[explode('" . $delimiter . "', '" . implode($delimiter, $v) . "')]";
config/options.php CHANGED
@@ -12,6 +12,8 @@ $config = array(
12
  "max_input_time" => -1,
13
  "max_execution_time" => -1,
14
  "secure" => 1,
 
 
15
  "zapier_api_key" => wp_all_export_rand_char(32),
16
  "zapier_invitation_url" => "",
17
  "zapier_invitation_url_received" => ""
12
  "max_input_time" => -1,
13
  "max_execution_time" => -1,
14
  "secure" => 1,
15
+ "license" => "",
16
+ "license_status" => "",
17
  "zapier_api_key" => wp_all_export_rand_char(32),
18
  "zapier_invitation_url" => "",
19
  "zapier_invitation_url_received" => ""
controllers/admin/export.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
  /**
3
  * Export configuration wizard
4
- *
5
  * @author Max Tsiplyakov <makstsiplyakov@gmail.com>
6
  */
7
 
8
  class PMXE_Admin_Export extends PMXE_Controller_Admin {
9
-
10
  protected $isWizard = true; // indicates whether controller is in wizard mode (otherwise it called to be delegated an edit action)
11
 
12
- protected function init() {
13
 
14
- parent::init();
15
 
16
  if ('PMXE_Admin_Manage' == PMXE_Plugin::getInstance()->getAdminCurrentScreen()->base) { // prereqisites are not checked when flow control is deligated
17
  $id = $this->input->get('id');
18
- $this->data['export'] = $export = new PMXE_Export_Record();
19
  if ( ! $id or $export->getById($id)->isEmpty()) { // specified import is not found
20
  wp_redirect(add_query_arg('page', 'pmxe-admin-manage', admin_url('admin.php'))); die();
21
  }
22
- $this->isWizard = false;
23
  $export->fix_template_options();
24
- } else {
25
  $action = PMXE_Plugin::getInstance()->getAdminCurrentScreen()->action;
26
- $this->_step_ready($action);
27
  }
28
 
29
  // preserve id parameter as part of baseUrl
30
- $id = $this->input->get('id') and $this->baseUrl = add_query_arg('id', $id, $this->baseUrl);
31
 
32
  }
33
 
@@ -38,18 +38,18 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
38
  public function get($var)
39
  {
40
  return $this->{$var};
41
- }
42
 
43
  /**
44
  * Checks whether corresponding step of wizard is complete
45
  * @param string $action
46
  * @return bool
47
  */
48
- protected function _step_ready($action) {
49
 
50
  // step #1: xml selction - has no prerequisites
51
  if ('index' == $action) return true;
52
-
53
  if ('element' == $action) return true;
54
 
55
  $this->data['update_previous'] = $update_previous = new PMXE_Export_Record();
@@ -68,18 +68,18 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
68
  }
69
 
70
  if ('process' == $action) return true;
71
-
72
  }
73
-
74
  /**
75
  * Step #1: Choose CPT
76
  */
77
- public function index() {
78
 
79
  $action = $this->input->get('action');
80
 
81
  $DefaultOptions = array(
82
- 'cpt' => '',
83
  'export_to' => 'xml',
84
  'export_type' => 'specific',
85
  'wp_query' => '',
@@ -93,26 +93,24 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
93
 
94
  if ( ! in_array($action, array('index')))
95
  {
96
- PMXE_Plugin::$session->clean_session();
97
  $this->data['preload'] = false;
98
- }
99
  else
100
  {
101
- $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $DefaultOptions;
102
  $this->data['preload'] = true;
103
  }
104
 
105
- $wp_uploads = wp_upload_dir();
106
-
107
  $this->data['post'] = $post = $this->input->post($DefaultOptions);
108
 
109
- if ( is_array($this->data['post']['cpt']) ) $this->data['post']['cpt'] = $this->data['post']['cpt'][0];
110
 
111
  // Delete history
112
  $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH);
113
- if ( ! empty($history_files) ){
114
  foreach ($history_files as $filePath) {
115
- @file_exists($filePath) and @unlink($filePath);
116
  }
117
  }
118
 
@@ -124,55 +122,54 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
124
  {
125
  $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Export requires XMLReader, and XMLWriter PHP modules to be installed.<br/>These are standard features of PHP, and are necessary for WP All Export to write the files you are trying to export.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp_all_export_plugin'));
126
  }
127
-
128
  if ($this->input->post('is_submitted'))
129
- {
130
 
131
  PMXE_Plugin::$session->set('export_type', $post['export_type']);
132
  PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']);
133
  PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']);
134
- PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']);
135
  PMXE_Plugin::$session->set('taxonomy_to_export', $post['taxonomy_to_export']);
136
  PMXE_Plugin::$session->set('created_at_version', $post['created_at_version']);
137
 
138
- if ( ! empty($post['auto_generate']) )
139
  {
140
  $auto_generate = XmlCsvExport::auto_genetate_export_fields($post, $this->errors);
141
-
142
- foreach ($auto_generate as $key => $value)
143
  {
144
- PMXE_Plugin::$session->set($key, $value);
145
- }
146
 
147
- PMXE_Plugin::$session->save_data();
148
- }
149
  else
150
  {
151
- $engine = new XmlExportEngine($post, $this->errors);
152
  $engine->init_additional_data();
153
- }
154
-
155
- }
156
 
157
- if ($this->input->post('is_submitted') and ! $this->errors->get_error_codes()) {
158
 
159
  check_admin_referer('choose-cpt', '_wpnonce_choose-cpt');
160
 
161
- PMXE_Plugin::$session->save_data();
162
-
163
  if ( ! empty($post['auto_generate']) )
164
- {
165
  wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die();
166
- }
167
  else
168
  {
169
- wp_redirect(add_query_arg('action', 'template', $this->baseUrl)); die();
170
- }
171
 
172
  }
173
-
174
  $this->render();
175
- }
176
 
177
  /**
178
  * Step #2: Export Template
@@ -187,7 +184,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
187
  if ($this->isWizard) {
188
  // New export
189
  $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default;
190
- $post = $this->input->post($DefaultOptions);
191
  }
192
  else{
193
  // Edit export
@@ -199,38 +196,38 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
199
  if (empty($this->data['export']->options['export_variations_title'])){
200
  $DefaultOptions['export_variations_title'] = XmlExportEngine::VARIATION_USE_DEFAULT_TITLE;
201
  }
202
- $post = $this->input->post($DefaultOptions);
203
  $post['scheduled'] = $this->data['export']->scheduled;
204
 
205
  foreach ($post as $key => $value) {
206
  PMXE_Plugin::$session->set($key, $value);
207
  }
208
  $this->data['dismiss_warnings'] = get_option('wpae_dismiss_warnings_' . $this->data['export']->id, 0);
209
- }
210
 
211
- $max_input_vars = @ini_get('max_input_vars');
212
 
213
- if(ctype_digit($max_input_vars) && count($_POST, COUNT_RECURSIVE) >= $max_input_vars)
214
  {
215
- $this->errors->add('form-validation', sprintf(__('You\'ve reached your max_input_vars limit of %d. Please contact your web host to increase it.', 'wp_all_export_plugin'), $max_input_vars));
216
  }
217
 
218
- PMXE_Plugin::$session->save_data();
219
 
220
- $this->data['post'] =& $post;
 
 
221
 
222
- PMXE_Plugin::$session->set('is_loaded_template', '');
223
-
224
  $this->data['engine'] = null;
225
 
226
  XmlExportEngine::$exportQuery = PMXE_Plugin::$session->get('exportQuery');
227
 
228
  if (($load_template = $this->input->post('load_template'))) { // init form with template selected
229
- if ( ! $template->getById($load_template)->isEmpty()) {
230
  $template_options = $template->options;
231
  unset($template_options['cpt']);
232
- unset($template_options['export_to']);
233
- unset($template_options['export_type']);
234
  unset($template_options['wp_query']);
235
  unset($template_options['filter_rules_hierarhy']);
236
  unset($template_options['product_matching_mode']);
@@ -244,7 +241,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
244
 
245
  if ( empty($post['cc_type'][0]) && ! in_array($post['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){
246
  $this->errors->add('form-validation', __('You haven\'t selected any columns for export.', 'wp_all_export_plugin'));
247
- }
248
 
249
  if ( 'csv' == $post['export_to'] and '' == $post['delimiter'] ){
250
  $this->errors->add('form-validation', __('CSV delimiter must be specified.', 'wp_all_export_plugin'));
@@ -252,42 +249,72 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin {
252
 
253
  if ( 'xml' == $post['export_to'] && ! in_array($post['xml_template_type'], array('custom', 'XmlGoogleMerchants')) )
254
  {
255
- $post['main_xml_tag'] = preg_replace('/[^a-z0-9]/i', '', $post['main_xml_tag']);
256
  if ( empty($post['main_xml_tag']) ){
257
  $this->errors->add('form-validation', __('Main XML Tag is required.', 'wp_all_export_plugin'));
258
- }
259
 
260
- $post['record_xml_tag'] = preg_replace('/[^a-z0-9]/i', '', $post['record_xml_tag']);
261
  if ( empty($post['record_xml_tag']) ){
262
  $this->errors->add('form-validation', __('Single Record XML Tag is required.', 'wp_all_export_plugin'));
263
- }
264
 
265
- if ($post['main_xml_tag'] == $post['record_xml_tag']){
266
  $this->errors->add('form-validation', __('Main XML Tag equals to Single Record XML Tag.', 'wp_all_export_plugin'));
267
  }
268
  }
269
 
270
- if ( ! $this->errors->get_error_codes()) {