Export WordPress data to XML/CSV - Version 1.0.5

Version Description

  • fixed misaligned columns on exporting product attributes
  • fixed export nested repeaters field in CSV format
  • fixed live records counting for advanced export mode
  • fixed Events Calendar conflict
  • added new filters 'wp_all_export_add_before_node', 'wp_all_export_add_after_node'
  • added possibility export repeater rows one per line
  • exclude orphaned variations from exprt file
  • changed UI for export media data ( images & attachments )
Download this release

Release Info

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

Code changes from version 1.0.4 to 1.0.5

Files changed (65) hide show
  1. actions/admin_menu.php +7 -7
  2. actions/pmxe_after_export.php +49 -19
  3. actions/pmxe_exported_post.php +19 -8
  4. actions/wp_ajax_export_available_rules.php +28 -8
  5. actions/wp_ajax_export_filtering.php +39 -106
  6. actions/wp_ajax_export_filtering_count.php +132 -48
  7. actions/wp_ajax_export_preview.php +61 -17
  8. actions/wp_ajax_generate_zapier_api_key.php +1 -1
  9. actions/wp_ajax_wpallexport.php +113 -289
  10. classes/handler.php +43 -74
  11. classes/wpallimport.php +476 -0
  12. controllers/admin/export.php +97 -155
  13. controllers/admin/manage.php +48 -69
  14. controllers/controller.php +1 -1
  15. filters/wpallexport_custom_types.php +47 -3
  16. helpers/pmxe_export_acf_field_csv.php +0 -446
  17. helpers/pmxe_export_acf_field_xml.php +0 -354
  18. helpers/pmxe_export_csv.php +0 -641
  19. helpers/pmxe_export_xml.php +0 -513
  20. helpers/pmxe_functions.php +48 -1
  21. helpers/wp_all_export_generate_export_file.php +3 -3
  22. helpers/wp_all_export_get_cpt_name.php +25 -11
  23. helpers/wp_all_export_get_export_format.php +6 -0
  24. helpers/wp_all_export_posts_join.php +21 -0
  25. helpers/wp_all_export_posts_where.php +18 -0
  26. helpers/wp_all_export_reverse_rules_html.php +7 -4
  27. helpers/wp_all_export_write_article.php +29 -0
  28. i18n/languages/wp_all_export_plugin-de_DE.mo +0 -0
  29. i18n/languages/wp_all_export_plugin-de_DE.po +449 -357
  30. i18n/languages/wp_all_export_plugin-es_ES.mo +0 -0
  31. i18n/languages/wp_all_export_plugin-es_ES.po +980 -643
  32. i18n/languages/wp_all_export_plugin-ru_RU.mo +0 -0
  33. i18n/languages/wp_all_export_plugin-ru_RU.po +1460 -676
  34. libraries/XmlCsvExport.php +717 -0
  35. libraries/XmlExportACF.php +1050 -34
  36. libraries/XmlExportComment.php +234 -0
  37. libraries/XmlExportCpt.php +596 -0
  38. libraries/XmlExportEngine.php +563 -184
  39. libraries/XmlExportFiltering.php +106 -0
  40. libraries/XmlExportMediaGallery.php +336 -0
  41. libraries/XmlExportUser.php +203 -100
  42. libraries/XmlExportWooCommerce.php +603 -190
  43. libraries/XmlExportWooCommerceCoupon.php +198 -0
  44. libraries/XmlExportWooCommerceOrder.php +725 -109
  45. libraries/XmlGoogleMerchants.php +59 -0
  46. models/export/record.php +243 -2
  47. readme.txt +12 -2
  48. schema.php +2 -0
  49. static/css/admin.css +266 -98
  50. static/js/admin.js +823 -545
  51. views/admin/export/blocks/filters.php +132 -0
  52. views/admin/export/index.php +25 -17
  53. views/admin/export/options.php +52 -151
  54. views/admin/export/options/settings.php +108 -55
  55. views/admin/export/process.php +110 -46
  56. views/admin/export/template.php +174 -119
  57. views/admin/export/template/add_new_field.php +27 -0
  58. views/admin/export/template/advanced_field_options.php +92 -0
  59. views/admin/export/template/new_field_cpt.php +0 -151
  60. views/admin/export/template/new_field_shop_order.php +0 -98
  61. views/admin/export/template/new_field_user.php +0 -122
  62. views/admin/manage/index.php +21 -18
  63. views/admin/manage/scheduling.php +8 -4
  64. views/admin/manage/update.php +25 -130
  65. wp-all-export.php +29 -8
actions/admin_menu.php CHANGED
@@ -6,16 +6,16 @@
6
  function pmxe_admin_menu() {
7
  global $menu, $submenu;
8
 
9
- if (current_user_can('manage_options')) { // admin management options
10
 
11
- add_menu_page(__('WP All Export', 'wp_all_export_plugin'), __('All Export', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-home', array(PMXE_Plugin::getInstance(), 'adminDispatcher'), PMXE_Plugin::ROOT_URL . '/static/img/xmlicon.png');
12
  // workaround to rename 1st option to `Home`
13
  $submenu['pmxe-admin-home'] = array();
14
- add_submenu_page('pmxe-admin-home', __('Export to XML', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('New Export', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-export', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
15
- add_submenu_page('pmxe-admin-home', __('Manage Exports', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Manage Exports', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-manage', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
16
- add_submenu_page('pmxe-admin-home', __('Settings', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Settings', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-settings', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
17
- // add_submenu_page('pmxe-admin-home', __('Feedback', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Feedback', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-feedback', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
18
- add_submenu_page('pmxe-admin-home', __('Support', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Support', 'wp_all_export_plugin'), 'manage_options', 'pmxe-admin-help', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
19
 
20
  }
21
  }
6
  function pmxe_admin_menu() {
7
  global $menu, $submenu;
8
 
9
+ if (current_user_can(PMXE_Plugin::$capabilities)) { // admin management options
10
 
11
+ add_menu_page(__('WP All Export', 'wp_all_export_plugin'), __('All Export', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-home', array(PMXE_Plugin::getInstance(), 'adminDispatcher'), PMXE_Plugin::ROOT_URL . '/static/img/xmlicon.png');
12
  // workaround to rename 1st option to `Home`
13
  $submenu['pmxe-admin-home'] = array();
14
+ add_submenu_page('pmxe-admin-home', __('Export to XML', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('New Export', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-export', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
15
+ add_submenu_page('pmxe-admin-home', __('Manage Exports', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Manage Exports', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-manage', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
16
+ add_submenu_page('pmxe-admin-home', __('Settings', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Settings', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-settings', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
17
+ // add_submenu_page('pmxe-admin-home', __('Feedback', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Feedback', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-feedback', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
18
+ add_submenu_page('pmxe-admin-home', __('Support', 'wp_all_export_plugin') . ' ‹ ' . __('WP All Export', 'wp_all_export_plugin'), __('Support', 'wp_all_export_plugin'), PMXE_Plugin::$capabilities, 'pmxe-admin-help', array(PMXE_Plugin::getInstance(), 'adminDispatcher'));
19
 
20
  }
21
  }
actions/pmxe_after_export.php CHANGED
@@ -1,17 +1,16 @@
1
  <?php
2
 
3
- function pmxe_pmxe_after_export($export_id)
4
- {
5
- $export = new PMXE_Export_Record();
6
- $export->getById($export_id);
7
-
8
- $splitSize = $export->options['split_large_exports_count'];
9
-
 
10
  if ( ! $export->isEmpty())
11
- {
12
- $export->set(array(
13
- 'iteration' => $export->options['creata_a_new_export_file'] ? $export->iteration + 1 : 0
14
- ))->update();
15
 
16
  $exportOptions = $export->options;
17
  // remove previously genereted chunks
@@ -31,7 +30,7 @@ function pmxe_pmxe_after_export($export_id)
31
  else
32
  {
33
  $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
34
- }
35
 
36
  // Split large exports into chunks
37
  if ( $export->options['split_large_exports'] and $splitSize < $export->exported )
@@ -46,13 +45,16 @@ function pmxe_pmxe_after_export($export_id)
46
  {
47
  case 'xml':
48
 
 
 
 
49
  $records_count = 0;
50
  $chunk_records_count = 0;
51
  $fileCount = 1;
52
 
53
- $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$export->options['main_xml_tag'].">";
54
 
55
- $file = new PMXE_Chunk($filepath, array('element' => $export->options['record_xml_tag'], 'encoding' => 'UTF-8'));
56
  // loop through the file until all lines are read
57
  while ($xml = $file->read()) {
58
 
@@ -72,16 +74,16 @@ function pmxe_pmxe_after_export($export_id)
72
  }
73
 
74
  if ( $chunk_records_count == $splitSize or $records_count == $export->exported ){
75
- $feed .= "</".$export->options['main_xml_tag'].">";
76
  $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath);
77
  file_put_contents($outputFile, $feed);
78
  if ( ! in_array($outputFile, $exportOptions['split_files_list']))
79
  $exportOptions['split_files_list'][] = $outputFile;
80
  $chunk_records_count = 0;
81
- $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$export->options['main_xml_tag'].">";
82
  }
83
 
84
- }
85
  break;
86
  case 'csv':
87
  $in = fopen($filepath, 'r');
@@ -110,8 +112,9 @@ function pmxe_pmxe_after_export($export_id)
110
  }
111
  $rowCount++;
112
  }
 
 
113
 
114
- fclose($out);
115
  break;
116
 
117
  default:
@@ -121,6 +124,33 @@ function pmxe_pmxe_after_export($export_id)
121
 
122
  $export->set(array('options' => $exportOptions))->save();
123
  }
124
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
126
  }
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
30
  else
31
  {
32
  $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
33
+ }
34
 
35
  // Split large exports into chunks
36
  if ( $export->options['split_large_exports'] and $splitSize < $export->exported )
45
  {
46
  case 'xml':
47
 
48
+ $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $export->options['main_xml_tag'], $export->id);
49
+ $record_xml_tag = apply_filters('wp_all_export_record_xml_tag', $export->options['record_xml_tag'], $export->id);
50
+
51
  $records_count = 0;
52
  $chunk_records_count = 0;
53
  $fileCount = 1;
54
 
55
+ $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$main_xml_tag.">";
56
 
57
+ $file = new PMXE_Chunk($filepath, array('element' => $record_xml_tag, 'encoding' => 'UTF-8'));
58
  // loop through the file until all lines are read
59
  while ($xml = $file->read()) {
60
 
74
  }
75
 
76
  if ( $chunk_records_count == $splitSize or $records_count == $export->exported ){
77
+ $feed .= "</".$main_xml_tag.">";
78
  $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath);
79
  file_put_contents($outputFile, $feed);
80
  if ( ! in_array($outputFile, $exportOptions['split_files_list']))
81
  $exportOptions['split_files_list'][] = $outputFile;
82
  $chunk_records_count = 0;
83
+ $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<".$main_xml_tag.">";
84
  }
85
 
86
+ }
87
  break;
88
  case 'csv':
89
  $in = fopen($filepath, 'r');
112
  }
113
  $rowCount++;
114
  }
115
+ fclose($in);
116
+ fclose($out);
117
 
 
118
  break;
119
 
120
  default:
124
 
125
  $export->set(array('options' => $exportOptions))->save();
126
  }
127
+ }
128
+
129
+ // make a temporary copy of current file
130
+ if ( empty($export->parent_id) and @file_exists($filepath) and @copy($filepath, str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath)))
131
+ {
132
+ $exportOptions = $export->options;
133
+ $exportOptions['current_filepath'] = str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath);
134
+ $export->set(array('options' => $exportOptions))->save();
135
+ }
136
+
137
+ // genereta export bundle
138
+ $export->generate_bundle();
139
+
140
+ if ( ! empty($export->parent_id) )
141
+ {
142
+ $parent_export = new PMXE_Export_Record();
143
+ $parent_export->getById($export->parent_id);
144
+ if ( ! $parent_export->isEmpty() )
145
+ {
146
+ $parent_export->generate_bundle(true);
147
+ }
148
+ }
149
+
150
+ // clean session
151
+ if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
152
+ {
153
+ PMXE_Plugin::$session->clean_session( $export->id );
154
+ }
155
  }
156
  }
actions/pmxe_exported_post.php CHANGED
@@ -1,15 +1,26 @@
1
  <?php
2
- function pmxe_pmxe_exported_post( $pid ){
3
-
 
 
 
 
4
  $postRecord = new PMXE_Post_Record();
5
  $postRecord->getBy(array(
6
  'post_id' => $pid,
7
- 'export_id' => XmlExportEngine::$exportID
8
  ));
9
 
10
- $postRecord->isEmpty() and $postRecord->set(array(
11
- 'post_id' => $pid,
12
- 'export_id' => XmlExportEngine::$exportID
13
- ))->insert();
14
-
 
 
 
 
 
 
 
15
  }
1
  <?php
2
+
3
+ function pmxe_pmxe_exported_post( $pid, $exportRecord )
4
+ {
5
+ // do not associate exported record with child export
6
+ if ( ! empty($exportRecord->parent_id) ) return;
7
+
8
  $postRecord = new PMXE_Post_Record();
9
  $postRecord->getBy(array(
10
  'post_id' => $pid,
11
+ 'export_id' => XmlExportEngine::$exportID
12
  ));
13
 
14
+ if ($postRecord->isEmpty())
15
+ {
16
+ $postRecord->set(array(
17
+ 'post_id' => $pid,
18
+ 'export_id' => XmlExportEngine::$exportID,
19
+ 'iteration' => $exportRecord->iteration
20
+ ))->insert();
21
+ }
22
+ else
23
+ {
24
+ $postRecord->set(array('iteration' => $exportRecord->iteration))->update();
25
+ }
26
  }
actions/wp_ajax_export_available_rules.php CHANGED
@@ -6,7 +6,7 @@ function pmxe_wp_ajax_export_available_rules(){
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
- if ( ! current_user_can('manage_options') ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
@@ -24,15 +24,15 @@ function pmxe_wp_ajax_export_available_rules(){
24
  ?>
25
 
26
  <!-- Taxonomies -->
27
- <option value="in">IN</option>
28
- <option value="not_in">NOT IN</option>
29
 
30
  <!-- Custom Fields -->
31
  <!--option value="between">BETWEEN</option-->
32
 
33
  <?php
34
  }
35
- elseif($post['selected'] === 'post_date')
36
  {
37
  ?>
38
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
@@ -48,18 +48,38 @@ function pmxe_wp_ajax_export_available_rules(){
48
  <option value="is_not_empty"><?php _e('is not empty', 'wp_all_export_plugin'); ?></option>
49
  <?php
50
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  else
52
  {
53
  ?>
54
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
55
- <option value="not_equals"><?php _e('not equals', 'wp_all_export_plugin'); ?></option>
56
  <option value="greater"><?php _e('greater than', 'wp_all_export_plugin');?></option>
57
- <option value="equals_or_greater"><?php _e('equals or greater than', 'wp_all_export_plugin'); ?></option>
58
  <option value="less"><?php _e('less than', 'wp_all_export_plugin'); ?></option>
59
- <option value="equals_or_less"><?php _e('equals or less than', 'wp_all_export_plugin'); ?></option>
60
 
61
  <option value="contains"><?php _e('contains', 'wp_all_export_plugin'); ?></option>
62
- <option value="not_contains"><?php _e('not contains', 'wp_all_export_plugin'); ?></option>
63
  <option value="is_empty"><?php _e('is empty', 'wp_all_export_plugin'); ?></option>
64
  <option value="is_not_empty"><?php _e('is not empty', 'wp_all_export_plugin'); ?></option>
65
  <?php
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
+ if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
24
  ?>
25
 
26
  <!-- Taxonomies -->
27
+ <option value="in"><?php echo __('In', 'wp_all_export_plugin') . ' ' . ucwords(str_replace(array("tx_", "_"), array("", " "), $post['selected'])); ?></option>
28
+ <option value="not_in"><?php echo __('Not In', 'wp_all_export_plugin') . ' ' . ucwords(str_replace(array("tx_", "_"), array("", " "), $post['selected'])); ?></option>
29
 
30
  <!-- Custom Fields -->
31
  <!--option value="between">BETWEEN</option-->
32
 
33
  <?php
34
  }
35
+ elseif( in_array($post['selected'], array('post_date', 'user_registered', 'comment_date')) )
36
  {
37
  ?>
38
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
48
  <option value="is_not_empty"><?php _e('is not empty', 'wp_all_export_plugin'); ?></option>
49
  <?php
50
  }
51
+ elseif( in_array($post['selected'], array('wp_capabilities')))
52
+ {
53
+ ?>
54
+ <option value="contains"><?php _e('contains', 'wp_all_export_plugin'); ?></option>
55
+ <option value="not_contains"><?php _e("doesn't contain", 'wp_all_export_plugin'); ?></option>
56
+ <?php
57
+ }
58
+ elseif ( in_array($post['selected'], array('user_login', 'user_nicename', 'user_role', 'user_email', 'display_name', 'first_name', 'last_name', 'nickname', 'description',
59
+ 'post_status', 'post_title', 'post_content', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_agent',
60
+ 'comment_type', 'comment_content') ) )
61
+ {
62
+ ?>
63
+ <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
64
+ <option value="not_equals"><?php _e("doesn't equal", 'wp_all_export_plugin'); ?></option>
65
+ <option value="contains"><?php _e('contains', 'wp_all_export_plugin'); ?></option>
66
+ <option value="not_contains"><?php _e("doesn't contain", 'wp_all_export_plugin'); ?></option>
67
+ <option value="is_empty"><?php _e('is empty', 'wp_all_export_plugin'); ?></option>
68
+ <option value="is_not_empty"><?php _e('is not empty', 'wp_all_export_plugin'); ?></option>
69
+ <?php
70
+ }
71
  else
72
  {
73
  ?>
74
  <option value="equals"><?php _e('equals', 'wp_all_export_plugin'); ?></option>
75
+ <option value="not_equals"><?php _e("doesn't equal", 'wp_all_export_plugin'); ?></option>
76
  <option value="greater"><?php _e('greater than', 'wp_all_export_plugin');?></option>
77
+ <option value="equals_or_greater"><?php _e('equal to or greater than', 'wp_all_export_plugin'); ?></option>
78
  <option value="less"><?php _e('less than', 'wp_all_export_plugin'); ?></option>
79
+ <option value="equals_or_less"><?php _e('equal to or less than', 'wp_all_export_plugin'); ?></option>
80
 
81
  <option value="contains"><?php _e('contains', 'wp_all_export_plugin'); ?></option>
82
+ <option value="not_contains"><?php _e("doesn't contain", 'wp_all_export_plugin'); ?></option>
83
  <option value="is_empty"><?php _e('is empty', 'wp_all_export_plugin'); ?></option>
84
  <option value="is_not_empty"><?php _e('is not empty', 'wp_all_export_plugin'); ?></option>
85
  <?php
actions/wp_ajax_export_filtering.php CHANGED
@@ -6,10 +6,15 @@ function pmxe_wp_ajax_export_filtering(){
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
- if ( ! current_user_can('manage_options') ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
 
 
 
 
 
13
  ob_start();
14
 
15
  $errors = new WP_Error();
@@ -18,7 +23,7 @@ function pmxe_wp_ajax_export_filtering(){
18
 
19
  $post = $input->post('data', array());
20
 
21
- if ( ! empty($post['cpt'])):
22
 
23
  $engine = new XmlExportEngine($post, $errors);
24
 
@@ -30,116 +35,44 @@ function pmxe_wp_ajax_export_filtering(){
30
  <h3><?php _e('Add Filtering Options', 'wp_all_export_plugin'); ?></h3>
31
  </div>
32
  <div class="wpallexport-collapsed-content">
33
- <div class="wpallexport-free-edition-notice" style="padding: 20px; margin-bottom: 10px;">
34
- <a class="upgrade_link" target="_blank" href="http://www.wpallimport.com/upgrade-to-wp-all-export-pro/?utm_source=wordpress.org&amp;utm_medium=filter-rules&amp;utm_campaign=free+wp+all+export+plugin"><?php _e('Upgrade to the professional edition of WP All Export to add filtering rules.','wp_all_export_plugin');?></a>
35
- <p><?php _e('If you already own it, remove the free edition and install the professional edition.', 'wp_all_export_plugin'); ?></p>
36
- </div>
37
- <div class="wp_all_export_rule_inputs">
38
- <table>
39
- <tr>
40
- <th><?php _e('Element', 'wp_all_export_plugin'); ?></th>
41
- <th><?php _e('Rule', 'wp_all_export_plugin'); ?></th>
42
- <th><?php _e('Value', 'wp_all_export_plugin'); ?></th>
43
- <th>&nbsp;</th>
44
- </tr>
45
- <tr>
46
- <td style="width: 25%;">
47
- <select id="wp_all_export_xml_element">
48
- <option value=""><?php _e('Select Element', 'wp_all_export_plugin'); ?></option>
49
- <?php echo $engine->render_filters(); ?>
50
- </select>
51
- </td>
52
- <td style="width: 25%;" id="wp_all_export_available_rules">
53
- <select id="wp_all_export_rule">
54
- <option value=""><?php _e('Select Rule', 'wp_all_export_plugin'); ?></option>
55
- </select>
56
- </td>
57
- <td style="width: 25%;">
58
- <input id="wp_all_export_value" type="text" placeholder="value" value="" disabled="disabled"/>
59
- </td>
60
- <td style="width: 15%;">
61
- <a id="wp_all_export_add_rule" href="javascript:void(0);"><?php _e('Add Rule', 'wp_all_export_plugin');?></a>
62
- </td>
63
- </tr>
64
- </table>
65
- </div>
66
- <div id="wpallexport-filters" style="padding:0;">
67
- <div class="wpallexport-content-section" style="padding:0; border: none;">
68
- <fieldset id="wp_all_export_filtering_rules">
69
- <?php
70
- $filter_rules = PMXE_Plugin::$session->get('filter_rules_hierarhy');
71
- $filter_rules_hierarhy = json_decode($filter_rules);
72
- ?>
73
- <p style="margin:20px 0 5px; text-align:center; <?php if (!empty($filter_rules_hierarhy)):?> display:none;<?php endif; ?>"><?php _e('No filtering options. Add filtering options to only export records matching some specified criteria.', 'wp_all_export_plugin');?></p>
74
- <ol class="wp_all_export_filtering_rules">
75
- <?php
76
- if ( ! empty($filter_rules_hierarhy) and is_array($filter_rules_hierarhy) ):
77
- $rulenumber = 0;
78
- foreach ($filter_rules_hierarhy as $rule) {
79
-
80
- if ( is_null($rule->parent_id) )
81
- {
82
- $rulenumber++;
83
- ?>
84
- <li id="item_<?php echo $rulenumber;?>" class="dragging">
85
- <div class="drag-element">
86
- <input type="hidden" value="<?php echo $rule->element; ?>" class="wp_all_export_xml_element" name="wp_all_export_xml_element[<?php echo $rulenumber; ?>]"/>
87
- <input type="hidden" value="<?php echo $rule->title; ?>" class="wp_all_export_xml_element_title" name="wp_all_export_xml_element_title[<?php echo $rulenumber; ?>]"/>
88
- <input type="hidden" value="<?php echo $rule->condition; ?>" class="wp_all_export_rule" name="wp_all_export_rule[<?php echo $rulenumber; ?>]"/>
89
- <input type="hidden" value="<?php echo $rule->value; ?>" class="wp_all_export_value" name="wp_all_export_value[<?php echo $rulenumber; ?>]"/>
90
- <span class="rule_element"><?php echo $rule->title; ?></span>
91
- <span class="rule_as_is"><?php echo $rule->condition; ?></span>
92
- <span class="rule_condition_value"><?php echo $rule->value; ?></span>
93
- <span class="condition" <?php if ($rulenumber == count($filter_rules_hierarhy)):?>style="display:none;"<?php endif; ?>>
94
- <label for="rule_and_<?php echo $rulenumber; ?>">AND</label>
95
- <input id="rule_and_<?php echo $rulenumber; ?>" type="radio" value="and" name="rule[<?php echo $rulenumber; ?>]" <?php if ($rule->clause == 'AND'): ?>checked="checked"<?php endif; ?> class="rule_condition"/>
96
- <label for="rule_or_<?php echo $rulenumber; ?>">OR</label>
97
- <input id="rule_or_<?php echo $rulenumber; ?>" type="radio" value="or" name="rule[<?php echo $rulenumber; ?>]" <?php if ($rule->clause == 'OR'): ?>checked="checked"<?php endif; ?> class="rule_condition"/>
98
- </span>
99
- </div>
100
- <a href="javascript:void(0);" class="icon-item remove-ico"></a>
101
- <?php echo wp_all_export_reverse_rules_html($filter_rules_hierarhy, $rule, $rulenumber); ?>
102
- </li>
103
- <?php
104
- }
105
- }
106
- endif;
107
- ?>
108
- </ol>
109
- <div class="clear"></div>
110
- <div class="ajax-console" id="filtering_result">
111
-
112
- </div>
113
- <!--a href="javascript:void(0);" id="wp_all_export_apply_filters" <?php if (empty($filter_rules_hierarhy)):?>style="display:none;"<?php endif; ?>><?php _e('Apply Filters To Export Data', 'wp_all_export_plugin');?></a-->
114
- <div class="wp_all_export_filter_preloader"></div>
115
- </fieldset>
116
-
117
- <?php if ( "product" == $post["cpt"] and class_exists('WooCommerce')) : ?>
118
-
119
- <div class="input wp_all_export_product_matching_mode" <?php if (empty($filter_rules_hierarhy)): ?>style="display:none;"<?php endif; ?>>
120
- <?php $product_matching_mode = PMXE_Plugin::$session->get('product_matching_mode'); ?>
121
- <label><?php _e("Variable product matching rules: ", "wp_all_export_plugin"); ?></label>
122
- <select name="product_matching_mode">
123
- <option value="strict" <?php echo ( $product_matching_mode == 'strict' ) ? 'selected="selected"' : ''; ?>><?php _e("Strict", "wp_all_export_plugin"); ?></option>
124
- <option value="permissive" <?php echo ( $product_matching_mode == 'permissive' ) ? 'selected="selected"' : ''; ?>><?php _e("Permissive", "wp_all_export_plugin"); ?></option>
125
- <option value="parent" <?php echo ( $product_matching_mode == 'parent' ) ? 'selected="selected"' : ''; ?>><?php _e("Parent", "wp_all_export_plugin"); ?></option>
126
- </select>
127
- <a href="#help" class="wpallexport-help" style="position: relative; top: 0px;" title="<?php _e('Strict matching requires all variations to pass in order for the product to be exported. Permissive matching allows the product to be exported if any of the variations pass. Parent matching applies filters to parent products only.', 'wp_all_export_plugin'); ?>">?</a>
128
- </div>
129
-
130
- <?php endif; ?>
131
-
132
-
133
-
134
- </div>
135
- </div>
136
  </div>
137
  </div>
138
 
139
  <?php
140
 
141
  endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- exit(json_encode(array('html' => ob_get_clean()))); die;
144
 
145
  }
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
+ if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
13
+ $response = array(
14
+ 'html' => '',
15
+ 'btns' => ''
16
+ );
17
+
18
  ob_start();
19
 
20
  $errors = new WP_Error();
23
 
24
  $post = $input->post('data', array());
25
 
26
+ if ( ! empty($post['cpt'])):
27
 
28
  $engine = new XmlExportEngine($post, $errors);
29
 
35
  <h3><?php _e('Add Filtering Options', 'wp_all_export_plugin'); ?></h3>
36
  </div>
37
  <div class="wpallexport-collapsed-content">
38
+ <?php include_once PMXE_ROOT_DIR . '/views/admin/export/blocks/filters.php'; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  </div>
40
  </div>
41
 
42
  <?php
43
 
44
  endif;
45
+
46
+ $response['html'] = ob_get_clean();
47
+
48
+ if ( XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export )
49
+ {
50
+ $response['btns'] = '';
51
+ exit(json_encode($response)); die;
52
+ }
53
+
54
+ ob_start();
55
+
56
+ if ( XmlExportEngine::$is_auto_generate_enabled ):
57
+ ?>
58
+ <span class="wp_all_export_btn_with_note">
59
+ <a href="javascript:void(0);" class="back rad3 auto-generate-template" style="float:none; background: #425f9a; padding: 0 50px; margin-right: 10px; color: #fff; font-weight: normal;"><?php printf(__('Migrate %s', 'wp_all_export_plugin'), wp_all_export_get_cpt_name(array($post['cpt']), 2)); ?></a>
60
+ <span class="auto-generate-template">&nbsp;</span>
61
+ </span>
62
+ <span class="wp_all_export_btn_with_note">
63
+ <input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php _e('Customize Export File', 'wp_all_export_plugin') ?>"/>
64
+ <span class="auto-generate-template">&nbsp;</span>
65
+ </span>
66
+ <?php
67
+ else:
68
+ ?>
69
+ <span class="wp_all_export_btn_with_note">
70
+ <input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php _e('Customize Export File', 'wp_all_export_plugin') ?>"/>
71
+ </span>
72
+ <?php
73
+ endif;
74
+ $response['btns'] = ob_get_clean();
75
 
76
+ exit(json_encode($response)); die;
77
 
78
  }
actions/wp_ajax_export_filtering_count.php CHANGED
@@ -6,7 +6,7 @@ function pmxe_wp_ajax_export_filtering_count(){
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
- if ( ! current_user_can('manage_options') ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
@@ -14,11 +14,11 @@ function pmxe_wp_ajax_export_filtering_count(){
14
 
15
  $input = new PMXE_Input();
16
 
17
- $post = $input->post('data', array());
18
 
19
  $filter_args = array(
20
- 'filter_rules_hierarhy' => $post['filter_rules_hierarhy'],
21
- 'product_matching_mode' => $post['product_matching_mode']
22
  );
23
 
24
  $input = new PMXE_Input();
@@ -30,12 +30,14 @@ function pmxe_wp_ajax_export_filtering_count(){
30
 
31
  $export = new PMXE_Export_Record();
32
  $export->getById($export_id);
33
- if ( ! $export->isEmpty() ){
 
34
  XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
35
  XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
36
  }
37
 
38
- XmlExportEngine::$is_user_export = ( 'users' == $post['cpt'] ) ? true : false;
 
39
  XmlExportEngine::$post_types = array($post['cpt']);
40
 
41
  $filters = new XmlExportFiltering($filter_args);
@@ -49,62 +51,139 @@ function pmxe_wp_ajax_export_filtering_count(){
49
  $found_records = 0;
50
  $total_records = 0;
51
 
52
- if ( 'users' == $post['cpt'] )
 
 
 
 
53
  {
54
- // get total users
55
- $totalQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
56
- if ( ! empty($totalQuery->results)){
57
- $total_records = $totalQuery->get_total();
 
 
 
58
  }
59
-
60
- // get users depends on filters
61
- add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
62
- $exportQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
63
- if ( ! empty($exportQuery->results)){
64
- $found_records = $exportQuery->get_total();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  }
66
- remove_action('pre_user_query', 'wp_all_export_pre_user_query');
67
  }
68
  else
69
- {
70
- $cpt = ($post['cpt'] == 'product') ? array('product', 'product_variation') : $post['cpt'];
71
-
72
- // get total custom post type records
73
- $totalQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
74
- if ( ! empty($totalQuery->found_posts)){
75
- $total_records = $totalQuery->found_posts;
 
76
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- // get custom post type records depends on filters
79
- add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
80
- add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
81
 
82
- $exportQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
83
- if ( ! empty($exportQuery->found_posts)){
84
- $found_records = $exportQuery->found_posts;
85
- }
86
 
87
- remove_filter('posts_join', 'wp_all_export_posts_join');
88
- remove_filter('posts_where', 'wp_all_export_posts_where');
89
- }
 
 
90
 
 
 
 
 
 
 
 
 
91
  if ( $post['is_confirm_screen'] )
92
  {
93
  ?>
94
 
95
  <?php if ($found_records > 0) :?>
96
- <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?></h3>
97
- <h4><?php printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name(array($post['cpt']), $found_records)); ?></h4>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  <?php else: ?>
99
  <?php if (! $export->isEmpty() and $export->options['export_only_new_stuff']): ?>
100
- <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
101
- <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?></h4>
102
  <?php elseif ($total_records > 0): ?>
103
- <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
104
- <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?></h4>
105
  <?php else: ?>
106
- <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
107
- <h4><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?></h4>
108
  <?php endif; ?>
109
  <?php endif; ?>
110
 
@@ -114,13 +193,18 @@ function pmxe_wp_ajax_export_filtering_count(){
114
  {
115
  ?>
116
  <div class="founded_records">
117
- <?php if ($found_records > 0) :?>
118
- <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name(array($post['cpt']), $found_records); ?></strong> will be exported</h3>
119
- <h4><?php _e("Continue to Step 2 to choose data to include in the export file.", "wp_all_export_plugin"); ?></h4>
 
 
 
 
 
120
  <?php elseif ($total_records > 0): ?>
121
- <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(array($post['cpt']))); ?></h4>
122
  <?php else: ?>
123
- <h4 style="line-height:60px;"><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?></h4>
124
  <?php endif; ?>
125
  </div>
126
  <?php
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
+ if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
14
 
15
  $input = new PMXE_Input();
16
 
17
+ $post = $input->post('data', array());
18
 
19
  $filter_args = array(
20
+ 'filter_rules_hierarhy' => empty($post['filter_rules_hierarhy']) ? array() : $post['filter_rules_hierarhy'],
21
+ 'product_matching_mode' => empty($post['product_matching_mode']) ? 'strict' : $post['product_matching_mode']
22
  );
23
 
24
  $input = new PMXE_Input();
30
 
31
  $export = new PMXE_Export_Record();
32
  $export->getById($export_id);
33
+ if ( ! $export->isEmpty() )
34
+ {
35
  XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
36
  XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
37
  }
38
 
39
+ XmlExportEngine::$is_user_export = ( 'users' == $post['cpt'] or 'shop_customer' == $post['cpt'] ) ? true : false;
40
+ XmlExportEngine::$is_comment_export = ( 'comments' == $post['cpt'] ) ? true : false;
41
  XmlExportEngine::$post_types = array($post['cpt']);
42
 
43
  $filters = new XmlExportFiltering($filter_args);
51
  $found_records = 0;
52
  $total_records = 0;
53
 
54
+ $cpt = array($post['cpt']);
55
+
56
+ $is_products_export = ($post['cpt'] == 'product' and class_exists('WooCommerce'));
57
+
58
+ if ($post['export_type'] == 'advanced')
59
  {
60
+ if (XmlExportEngine::$is_user_export)
61
+ {
62
+ // get total users
63
+ $totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
64
+ if ( ! empty($totalQuery->results)){
65
+ $found_records = $total_records = $totalQuery->get_total();
66
+ }
67
  }
68
+ elseif(XmlExportEngine::$is_comment_export)
69
+ {
70
+ // get total comments
71
+ $totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));');
72
+ $found_records = $total_records = $totalQuery->get_comments();
73
+ }
74
+ else
75
+ {
76
+ remove_all_actions('parse_query');
77
+ remove_all_actions('pre_get_posts');
78
+
79
+ ob_start();
80
+ // get custom post type records depends on filters
81
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
82
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
83
+
84
+ // get total custom post type records
85
+ $totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
86
+ if ( ! empty($totalQuery->found_posts)){
87
+ $found_records = $total_records = $totalQuery->found_posts;
88
+ }
89
+
90
+ wp_reset_postdata();
91
+
92
+ remove_filter('posts_join', 'wp_all_export_posts_join');
93
+ remove_filter('posts_where', 'wp_all_export_posts_where');
94
+ ob_get_clean();
95
  }
 
96
  }
97
  else
98
+ {
99
+ if ( 'users' == $post['cpt'] or 'shop_customer' == $post['cpt'] )
100
+ {
101
+ // get total users
102
+ $totalQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
103
+ if ( ! empty($totalQuery->results)){
104
+ $found_records = $total_records = $totalQuery->get_total();
105
+ }
106
  }
107
+ elseif( 'comments' == $post['cpt'] )
108
+ {
109
+ // get total comments
110
+ global $wp_version;
111
+
112
+ if ( version_compare($wp_version, '4.2.0', '>=') )
113
+ {
114
+ $totalQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
115
+ $found_records = $total_records = $totalQuery->get_comments();
116
+ }
117
+ else
118
+ {
119
+ $found_records = $total_records = get_comments( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
120
+ }
121
+ }
122
+ else
123
+ {
124
+ remove_all_actions('parse_query');
125
+ remove_all_actions('pre_get_posts');
126
 
127
+ $cpt = ($is_products_export) ? array('product', 'product_variation') : array($post['cpt']);
 
 
128
 
129
+ ob_start();
130
+ // get custom post type records depends on filters
131
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
132
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
133
 
134
+ // get total custom post type records
135
+ $totalQuery = new WP_Query( array( 'post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10 ));
136
+ if ( ! empty($totalQuery->found_posts)){
137
+ $found_records = $total_records = $totalQuery->found_posts;
138
+ }
139
 
140
+ wp_reset_postdata();
141
+
142
+ remove_filter('posts_join', 'wp_all_export_posts_join');
143
+ remove_filter('posts_where', 'wp_all_export_posts_where');
144
+ ob_end_clean();
145
+ }
146
+ }
147
+
148
  if ( $post['is_confirm_screen'] )
149
  {
150
  ?>
151
 
152
  <?php if ($found_records > 0) :?>
153
+ <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?></h3>
154
+ <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)); ?></h4>
155
+ <?php else: ?>
156
+ <?php if (! $export->isEmpty() and $export->options['export_only_new_stuff']): ?>
157
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
158
+ <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
159
+ <?php elseif ($total_records > 0): ?>
160
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
161
+ <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
162
+ <?php else: ?>
163
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
164
+ <h4><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
165
+ <?php endif; ?>
166
+ <?php endif; ?>
167
+
168
+ <?php
169
+ }
170
+ elseif( $post['is_template_screen'] )
171
+ {
172
+ ?>
173
+
174
+ <?php if ($found_records > 0) :?>
175
+ <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?></strong> will be exported</h3>
176
+ <h4><?php _e("Choose data to include in the export file.", "wp_all_export_plugin"); ?></h4>
177
  <?php else: ?>
178
  <?php if (! $export->isEmpty() and $export->options['export_only_new_stuff']): ?>
179
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
180
+ <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
181
  <?php elseif ($total_records > 0): ?>
182
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
183
+ <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
184
  <?php else: ?>
185
+ <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?></h3>
186
+ <h4><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?></h4>
187
  <?php endif; ?>
188
  <?php endif; ?>
189
 
193
  {
194
  ?>
195
  <div class="founded_records">
196
+ <?php if ($found_records > 0) :?>
197
+ <?php if (XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export): ?>
198
+ <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?></strong> can be exported</h3>
199
+ <h4><?php printf(__('Upgrade to the professional edition of WP All Export to export %s.', 'wp_all_export_plugin'), wp_all_export_get_cpt_name($cpt)); ?></h4>
200
+ <?php else:?>
201
+ <h3><span class="matches_count"><?php echo $found_records; ?></span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?></strong> will be exported</h3>
202
+ <h4><?php _e("Continue to configure and run your export.", "wp_all_export_plugin"); ?></h4>
203
+ <?php endif; ?>
204
  <?php elseif ($total_records > 0): ?>
205
+ <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)); ?></h4>
206
  <?php else: ?>
207
+ <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)); ?></h4>
208
  <?php endif; ?>
209
  </div>
210
  <?php
actions/wp_ajax_export_preview.php CHANGED
@@ -8,7 +8,7 @@ function pmxe_wp_ajax_export_preview(){
8
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
9
  }
10
 
11
- if ( ! current_user_can('manage_options') ){
12
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
13
  }
14
 
@@ -18,16 +18,28 @@ function pmxe_wp_ajax_export_preview(){
18
 
19
  parse_str($_POST['data'], $values);
20
 
 
 
21
  $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
22
 
23
- XmlExportEngine::$exportOptions = $exportOptions;
24
- XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
 
 
 
 
 
 
25
 
26
  if ( 'advanced' == $exportOptions['export_type'] )
27
  {
28
  if ( XmlExportEngine::$is_user_export )
29
  {
30
- exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
 
 
 
 
31
  }
32
  else
33
  {
@@ -38,13 +50,33 @@ function pmxe_wp_ajax_export_preview(){
38
  {
39
  XmlExportEngine::$post_types = $exportOptions['cpt'];
40
 
41
- if ( ! in_array('users', $exportOptions['cpt']))
42
- {
43
- $exportQuery = new WP_Query( array( 'post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 10 ));
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
  else
46
- {
47
- exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
 
 
 
 
 
 
 
48
  }
49
  }
50
 
@@ -57,28 +89,40 @@ function pmxe_wp_ajax_export_preview(){
57
  <div class="wpallexport-preview-content">
58
 
59
  <?php
 
 
 
 
 
60
 
61
  switch ($exportOptions['export_to']) {
62
 
63
  case 'xml':
64
 
65
  $dom = new DOMDocument('1.0', $exportOptions['encoding']);
66
- $old = libxml_use_internal_errors(true);
67
- $xml = pmxe_export_xml($exportQuery, $exportOptions, true);
 
 
68
  $dom->loadXML($xml);
69
  libxml_use_internal_errors($old);
70
  $xpath = new DOMXPath($dom);
71
- if (($elements = @$xpath->query('/' . $exportOptions['main_xml_tag'])) and $elements->length){
 
 
 
72
  pmxe_render_xml_element($elements->item( 0 ), true);
73
- }
74
 
75
  break;
76
 
77
  case 'csv':
78
  ?>
79
  <small>
80
- <?php
81
- $csv = pmxe_export_csv($exportQuery, $exportOptions, true);
 
 
82
  if (!empty($csv)){
83
  $csv_rows = array_filter(explode("\n", $csv));
84
  if ($csv_rows){
@@ -111,7 +155,7 @@ function pmxe_wp_ajax_export_preview(){
111
  }
112
  }
113
  else{
114
- _e('Data not found.', 'pmxe_plugin');
115
  }
116
  ?>
117
  </small>
@@ -120,7 +164,7 @@ function pmxe_wp_ajax_export_preview(){
120
 
121
  default:
122
 
123
- _e('This format is not supported.', 'pmxe_plugin');
124
 
125
  break;
126
  }
8
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
9
  }
10
 
11
+ if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
12
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
13
  }
14
 
18
 
19
  parse_str($_POST['data'], $values);
20
 
21
+ $export_id = (isset($_GET['id'])) ? stripcslashes($_GET['id']) : 0;
22
+
23
  $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
24
 
25
+ $errors = new WP_Error();
26
+
27
+ $engine = new XmlExportEngine($exportOptions, $errors);
28
+
29
+ XmlExportEngine::$exportOptions = $exportOptions;
30
+ XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
31
+ XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
32
+ XmlExportEngine::$exportID = $export_id;
33
 
34
  if ( 'advanced' == $exportOptions['export_type'] )
35
  {
36
  if ( XmlExportEngine::$is_user_export )
37
  {
38
+ $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
39
+ }
40
+ elseif ( XmlExportEngine::$is_comment_export )
41
+ {
42
+ $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
43
  }
44
  else
45
  {
50
  {
51
  XmlExportEngine::$post_types = $exportOptions['cpt'];
52
 
53
+ if ( in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt']))
54
+ {
55
+ $exportQuery = new WP_User_Query( array( 'orderby' => 'ID', 'order' => 'ASC', 'number' => 10 ));
56
+ }
57
+ elseif( in_array('comments', $exportOptions['cpt']))
58
+ {
59
+ global $wp_version;
60
+
61
+ if ( version_compare($wp_version, '4.2.0', '>=') )
62
+ {
63
+ $exportQuery = new WP_Comment_Query( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10 ));
64
+ }
65
+ else
66
+ {
67
+ $exportQuery = get_comments( array( 'orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10 ));
68
+ }
69
  }
70
  else
71
+ {
72
+ remove_all_actions('parse_query');
73
+ remove_all_actions('pre_get_posts');
74
+
75
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
76
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
77
+ $exportQuery = new WP_Query( array( 'post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 10 ));
78
+ remove_filter('posts_where', 'wp_all_export_posts_where');
79
+ remove_filter('posts_join', 'wp_all_export_posts_join');
80
  }
81
  }
82
 
89
  <div class="wpallexport-preview-content">
90
 
91
  <?php
92
+ $wp_uploads = wp_upload_dir();
93
+
94
+ $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
95
+ if ( @file_exists($functions) )
96
+ require_once $functions;
97
 
98
  switch ($exportOptions['export_to']) {
99
 
100
  case 'xml':
101
 
102
  $dom = new DOMDocument('1.0', $exportOptions['encoding']);
103
+ $old = libxml_use_internal_errors(true);
104
+
105
+ $xml = XmlCsvExport::export_xml( true );
106
+
107
  $dom->loadXML($xml);
108
  libxml_use_internal_errors($old);
109
  $xpath = new DOMXPath($dom);
110
+
111
+ $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], XmlExportEngine::$exportID);
112
+
113
+ if (($elements = @$xpath->query('/' . $main_xml_tag)) and $elements->length){
114
  pmxe_render_xml_element($elements->item( 0 ), true);
115
+ }
116
 
117
  break;
118
 
119
  case 'csv':
120
  ?>
121
  <small>
122
+ <?php
123
+
124
+ $csv = XmlCsvExport::export_csv( true );
125
+
126
  if (!empty($csv)){
127
  $csv_rows = array_filter(explode("\n", $csv));
128
  if ($csv_rows){
155
  }
156
  }
157
  else{
158
+ _e('Data not found.', 'wp_all_export_plugin');
159
  }
160
  ?>
161
  </small>
164
 
165
  default:
166
 
167
+ _e('This format is not supported.', 'wp_all_export_plugin');
168
 
169
  break;
170
  }
actions/wp_ajax_generate_zapier_api_key.php CHANGED
@@ -6,7 +6,7 @@ function pmxe_wp_ajax_generate_zapier_api_key(){
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
- if ( ! current_user_can('manage_options') ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
6
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
7
  }
8
 
9
+ if ( ! current_user_can( PMXE_Plugin::$capabilities ) ){
10
  exit( json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))) );
11
  }
12
 
actions/wp_ajax_wpallexport.php CHANGED
@@ -8,7 +8,7 @@ function pmxe_wp_ajax_wpallexport(){
8
  exit( __('Security check', 'wp_all_export_plugin') );
9
  }
10
 
11
- if ( ! current_user_can('manage_options') ){
12
  exit( __('Security check', 'wp_all_export_plugin') );
13
  }
14
 
@@ -28,47 +28,84 @@ function pmxe_wp_ajax_wpallexport(){
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::$exportID = $export_id;
 
 
 
 
 
39
 
40
- $posts_per_page = $exportOptions['records_per_iteration'];
41
 
42
  if ('advanced' == $exportOptions['export_type'])
43
- {
44
  if (XmlExportEngine::$is_user_export)
45
  {
46
  exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
47
  }
 
 
 
 
48
  else
49
- {
50
- $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
 
 
 
 
 
 
 
51
  }
52
  }
53
  else
54
  {
55
  XmlExportEngine::$post_types = $exportOptions['cpt'];
56
 
57
- if ( ! in_array('users', $exportOptions['cpt']))
58
- {
59
- $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 ));
 
 
 
 
 
 
60
  }
61
  else
62
  {
63
- exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
 
 
 
 
 
 
 
64
  }
65
- }
66
 
67
  XmlExportEngine::$exportQuery = $exportQuery;
68
 
69
- $foundPosts = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->found_posts : $exportQuery->get_total();
70
-
71
- $postCount = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->post_count : count($exportQuery->get_results());
 
 
 
 
 
 
 
 
72
 
73
  if ( ! $export->exported )
74
  {
@@ -89,12 +126,7 @@ function pmxe_wp_ajax_wpallexport(){
89
 
90
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
91
 
92
- if ( $is_secure_import and ! empty($exportOptions['filepath'])){
93
-
94
- // if 'Create a new file each time export is run' disabled remove all previously generated source files
95
- // if ( ! $exportOptions['creata_a_new_export_file'] or ! $export->iteration ){
96
- // wp_all_export_remove_source(wp_all_export_get_absolute_path($exportOptions['filepath']));
97
- // }
98
 
99
  $exportOptions['filepath'] = '';
100
 
@@ -102,60 +134,47 @@ function pmxe_wp_ajax_wpallexport(){
102
 
103
  PMXE_Plugin::$session->set('count', $foundPosts);
104
  PMXE_Plugin::$session->save_data();
105
- }
106
 
107
  // if posts still exists then export them
108
  if ( $postCount )
109
- {
110
- switch ( $exportOptions['export_to'] ) {
111
-
112
- case 'xml':
113
-
114
- pmxe_export_xml($exportQuery, $exportOptions);
115
-
116
- break;
117
-
118
- case 'csv':
119
-
120
- pmxe_export_csv($exportQuery, $exportOptions);
121
-
122
- break;
123
-
124
- default:
125
- # code...
126
- break;
127
- }
128
-
129
- wp_reset_postdata();
130
-
131
- }
132
-
133
- if ($postCount){
134
 
135
  $export->set(array(
136
- 'exported' => $export->exported + $postCount
 
137
  ))->save();
138
-
139
- }
140
 
141
- if ($posts_per_page != -1 and $postCount){
142
 
 
 
143
  wp_send_json(array(
144
- 'exported' => $export->exported,
145
- 'percentage' => ceil(($export->exported/$foundPosts) * 100),
146
- 'done' => false,
 
 
147
  'records_per_request' => $exportOptions['records_per_iteration']
148
- ));
149
-
150
  }
151
  else
152
- {
153
-
154
- wp_reset_postdata();
155
 
156
  if ( file_exists(PMXE_Plugin::$session->file)){
157
 
158
- if ($exportOptions['export_to'] == 'xml') file_put_contents(PMXE_Plugin::$session->file, '</'.$exportOptions['main_xml_tag'].'>', FILE_APPEND);
 
 
 
 
 
 
 
 
 
 
159
 
160
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
161
 
@@ -176,7 +195,7 @@ function pmxe_wp_ajax_wpallexport(){
176
  {
177
  $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
178
  }
179
- elseif($export->options['creata_a_new_export_file'])
180
  {
181
  $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
182
  }
@@ -204,8 +223,8 @@ function pmxe_wp_ajax_wpallexport(){
204
  }
205
 
206
  }
207
- else{
208
-
209
  $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file);
210
 
211
  if ( ! $export->isEmpty() ){
@@ -214,239 +233,44 @@ function pmxe_wp_ajax_wpallexport(){
214
  ))->save();
215
  }
216
 
217
- }
218
-
219
- // Generate templa for WP All Import
220
- if ($exportOptions['is_generate_templates']){
221
-
222
- $custom_type = (empty($exportOptions['cpt'])) ? 'post' : $exportOptions['cpt'][0];
223
-
224
- $templateOptions = array(
225
- 'type' => ( ! empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post',
226
- 'wizard_type' => 'new',
227
- 'deligate' => 'wpallexport',
228
- 'custom_type' => (XmlExportEngine::$is_user_export) ? 'import_users' : $custom_type,
229
- 'status' => 'xpath',
230
- 'is_multiple_page_parent' => 'no',
231
- 'unique_key' => '',
232
- 'acf' => array(),
233
- 'fields' => array(),
234
- 'is_multiple_field_value' => array(),
235
- 'multiple_value' => array(),
236
- 'fields_delimiter' => array(),
237
-
238
- 'update_all_data' => 'no',
239
- 'is_update_status' => 0,
240
- 'is_update_title' => 0,
241
- 'is_update_author' => 0,
242
- 'is_update_slug' => 0,
243
- 'is_update_content' => 0,
244
- 'is_update_excerpt' => 0,
245
- 'is_update_dates' => 0,
246
- 'is_update_menu_order' => 0,
247
- 'is_update_parent' => 0,
248
- 'is_update_attachments' => 0,
249
- 'is_update_acf' => 0,
250
- 'update_acf_logic' => 'only',
251
- 'acf_list' => '',
252
- 'is_update_product_type' => 1,
253
- 'is_update_attributes' => 0,
254
- 'update_attributes_logic' => 'only',
255
- 'attributes_list' => '',
256
- 'is_update_images' => 0,
257
- 'is_update_custom_fields' => 0,
258
- 'update_custom_fields_logic' => 'only',
259
- 'custom_fields_list' => '',
260
- 'is_update_categories' => 0,
261
- 'update_categories_logic' => 'only',
262
- 'taxonomies_list' => '',
263
- 'export_id' => $export->id
264
- );
265
-
266
- if ( in_array('product', $exportOptions['cpt']) )
267
- {
268
- $templateOptions['_virtual'] = 1;
269
- $templateOptions['_downloadable'] = 1;
270
- $templateOptions['put_variation_image_to_gallery'] = 1;
271
- $templateOptions['disable_auto_sku_generation'] = 1;
272
- }
273
-
274
- if ( XmlExportEngine::$is_user_export )
275
- {
276
- $templateOptions['is_update_first_name'] = 0;
277
- $templateOptions['is_update_last_name'] = 0;
278
- $templateOptions['is_update_role'] = 0;
279
- $templateOptions['is_update_nickname'] = 0;
280
- $templateOptions['is_update_description'] = 0;
281
- $templateOptions['is_update_login'] = 0;
282
- $templateOptions['is_update_password'] = 0;
283
- $templateOptions['is_update_nicename'] = 0;
284
- $templateOptions['is_update_email'] = 0;
285
- $templateOptions['is_update_registered'] = 0;
286
- $templateOptions['is_update_display_name'] = 0;
287
- $templateOptions['is_update_url'] = 0;
288
- }
289
-
290
- if ( 'xml' == $exportOptions['export_to'] )
291
- {
292
- wp_all_export_prepare_template_xml($exportOptions, $templateOptions);
293
- }
294
- else
295
- {
296
- wp_all_export_prepare_template_csv($exportOptions, $templateOptions);
297
- }
298
-
299
- //$template = new PMXI_Template_Record();
300
-
301
- $tpl_options = $templateOptions;
302
-
303
- if ( 'csv' == $exportOptions['export_to'] )
304
- {
305
- $tpl_options['delimiter'] = $exportOptions['delimiter'];
306
- }
307
-
308
- $tpl_options['update_all_data'] = 'yes';
309
- $tpl_options['is_update_status'] = 1;
310
- $tpl_options['is_update_title'] = 1;
311
- $tpl_options['is_update_author'] = 1;
312
- $tpl_options['is_update_slug'] = 1;
313
- $tpl_options['is_update_content'] = 1;
314
- $tpl_options['is_update_excerpt'] = 1;
315
- $tpl_options['is_update_dates'] = 1;
316
- $tpl_options['is_update_menu_order'] = 1;
317
- $tpl_options['is_update_parent'] = 1;
318
- $tpl_options['is_update_attachments'] = 1;
319
- $tpl_options['is_update_acf'] = 1;
320
- $tpl_options['update_acf_logic'] = 'full_update';
321
- $tpl_options['acf_list'] = '';
322
- $tpl_options['is_update_product_type'] = 1;
323
- $tpl_options['is_update_attributes'] = 1;
324
- $tpl_options['update_attributes_logic'] = 'full_update';
325
- $tpl_options['attributes_list'] = '';
326
- $tpl_options['is_update_images'] = 1;
327
- $tpl_options['is_update_custom_fields'] = 1;
328
- $tpl_options['update_custom_fields_logic'] = 'full_update';
329
- $tpl_options['custom_fields_list'] = '';
330
- $tpl_options['is_update_categories'] = 1;
331
- $tpl_options['update_categories_logic'] = 'full_update';
332
- $tpl_options['taxonomies_list'] = '';
333
-
334
- $tpl_data = array(
335
- 'name' => $exportOptions['template_name'],
336
- 'is_keep_linebreaks' => 0,
337
- 'is_leave_html' => 0,
338
- 'fix_characters' => 0,
339
- 'options' => $tpl_options,
340
- );
341
-
342
- $exportOptions['tpl_data'] = $tpl_data;
343
-
344
- $export->set(array(
345
- 'options' => $exportOptions
346
- ))->save();
347
-
348
- // if ( ! empty($exportOptions['template_name'])) { // save template in database
349
- // $template->getByName($exportOptions['template_name'])->set($tpl_data)->save();
350
- // }
351
-
352
- }
353
-
354
- // associate exported posts with new import
355
- if ( wp_all_export_is_compatible() and $exportOptions['is_generate_import']){
356
-
357
- $options = $templateOptions + PMXI_Plugin::get_default_import_options();
358
-
359
- $import = new PMXI_Import_Record();
360
 
361
- $import->getById($exportOptions['import_id']);
362
-
363
- if ( ! $import->isEmpty() and $import->parent_import_id == 99999 ){
364
-
365
- $xmlPath = PMXE_Plugin::$session->file;
366
-
367
- $root_element = '';
368
-
369
- $historyPath = PMXE_Plugin::$session->file;
370
-
371
- if ( 'csv' == $exportOptions['export_to'] )
372
- {
373
- $options['delimiter'] = $exportOptions['delimiter'];
374
-
375
- include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php' );
376
-
377
- $path_info = pathinfo($xmlPath);
378
-
379
- $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
380
-
381
- $security_folder = array_pop($path_parts);
382
-
383
- $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
384
 
385
- $csv = new PMXI_CsvParser( array( 'filename' => $xmlPath, 'targetDir' => $target ) );
386
-
387
- if ( ! in_array($xmlPath, $exportOptions['attachment_list']) )
388
- {
389
- $exportOptions['attachment_list'][] = $csv->xml_path;
390
- }
391
-
392
- $historyPath = $csv->xml_path;
393
 
394
- $root_element = 'node';
395
 
396
- }
397
- else
398
- {
399
- $root_element = 'post';
400
- }
401
 
402
- $import->set(array(
403
- 'xpath' => '/' . $root_element,
404
- 'type' => 'upload',
405
- 'options' => $options,
406
- 'root_element' => $root_element,
407
- 'path' => $xmlPath,
408
- 'name' => basename($xmlPath),
409
- 'imported' => 0,
410
- 'created' => 0,
411
- 'updated' => 0,
412
- 'skipped' => 0,
413
- 'deleted' => 0,
414
- 'iteration' => 1,
415
- 'count' => PMXE_Plugin::$session->count
416
- ))->save();
417
-
418
- $history_file = new PMXI_File_Record();
419
- $history_file->set(array(
420
- 'name' => $import->name,
421
- 'import_id' => $import->id,
422
- 'path' => $historyPath,
423
- 'registered_on' => date('Y-m-d H:i:s')
424
- ))->save();
425
-
426
- $exportOptions['import_id'] = $import->id;
427
-
428
- $export->set(array(
429
- 'options' => $exportOptions
430
- ))->save();
431
- }
432
- }
433
  }
434
 
435
- $export->set(array(
436
- 'executing' => 0,
437
- 'canceled' => 0
438
- ))->save();
439
-
440
- do_action('pmxe_after_export', $export->id);
 
 
441
 
442
  wp_send_json(array(
443
- 'exported' => $export->exported,
444
- 'percentage' => 100,
445
- 'done' => true,
446
- 'records_per_request' => $exportOptions['records_per_iteration'],
447
- 'file' => PMXE_Plugin::$session->file
 
448
  ));
449
-
450
  }
 
451
 
452
- }
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
 
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
+ $errors = new WP_Error();
43
+ $engine = new XmlExportEngine($exportOptions, $errors);
44
 
45
+ $posts_per_page = $exportOptions['records_per_iteration'];
46
 
47
  if ('advanced' == $exportOptions['export_type'])
48
+ {
49
  if (XmlExportEngine::$is_user_export)
50
  {
51
  exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
52
  }
53
+ elseif(XmlExportEngine::$is_comment_export)
54
+ {
55
+ exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export comments.', 'wp_all_export_plugin'))) );
56
+ }
57
  else
58
+ {
59
+ remove_all_actions('parse_query');
60
+ remove_all_actions('pre_get_posts');
61
+
62
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
63
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
64
+ $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
65
+ remove_filter('posts_where', 'wp_all_export_posts_where');
66
+ remove_filter('posts_join', 'wp_all_export_posts_join');
67
  }
68
  }
69
  else
70
  {
71
  XmlExportEngine::$post_types = $exportOptions['cpt'];
72
 
73
+ // $is_products_export = ($exportOptions['cpt'] == 'product' and class_exists('WooCommerce'));
74
+
75
+ if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt']))
76
+ {
77
+ exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))) );
78
+ }
79
+ elseif(in_array('comments', $exportOptions['cpt']))
80
+ {
81
+ exit( json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export comments.', 'wp_all_export_plugin'))) );
82
  }
83
  else
84
  {
85
+ remove_all_actions('parse_query');
86
+ remove_all_actions('pre_get_posts');
87
+
88
+ add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
89
+ add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
90
+ $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 ));
91
+ remove_filter('posts_where', 'wp_all_export_posts_where');
92
+ remove_filter('posts_join', 'wp_all_export_posts_join');
93
  }
94
+ }
95
 
96
  XmlExportEngine::$exportQuery = $exportQuery;
97
 
98
+ // get total founded records
99
+ if (XmlExportEngine::$is_comment_export)
100
+ {
101
+
102
+ }
103
+ else
104
+ {
105
+ $foundPosts = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->found_posts : $exportQuery->get_total();
106
+ $postCount = ( ! XmlExportEngine::$is_user_export ) ? $exportQuery->post_count : count($exportQuery->get_results());
107
+ }
108
+ // [ \get total founded records ]
109
 
110
  if ( ! $export->exported )
111
  {
126
 
127
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
128
 
129
+ if ( $is_secure_import and ! empty($exportOptions['filepath'])){
 
 
 
 
 
130
 
131
  $exportOptions['filepath'] = '';
132
 
134
 
135
  PMXE_Plugin::$session->set('count', $foundPosts);
136
  PMXE_Plugin::$session->save_data();
137
+ }
138
 
139
  // if posts still exists then export them
140
  if ( $postCount )
141
+ {
142
+ XmlCsvExport::export();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  $export->set(array(
145
+ 'exported' => $export->exported + $postCount,
146
+ 'last_activity' => date('Y-m-d H:i:s')
147
  ))->save();
 
 
148
 
149
+ }
150
 
151
+ if ($posts_per_page != -1 and $postCount)
152
+ {
153
  wp_send_json(array(
154
+ 'export_id' => $export->id,
155
+ 'queue_export' => false,
156
+ 'exported' => $export->exported,
157
+ 'percentage' => ceil(($export->exported/$foundPosts) * 100),
158
+ 'done' => false,
159
  'records_per_request' => $exportOptions['records_per_iteration']
160
+ ));
 
161
  }
162
  else
163
+ {
 
 
164
 
165
  if ( file_exists(PMXE_Plugin::$session->file)){
166
 
167
+ if ($exportOptions['export_to'] == 'xml')
168
+ {
169
+
170
+ $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], $export->id);
171
+
172
+ file_put_contents(PMXE_Plugin::$session->file, '</'.$main_xml_tag.'>', FILE_APPEND);
173
+
174
+ $xml_footer = apply_filters('wp_all_export_xml_footer', '', $export->id);
175
+
176
+ if ( ! empty($xml_footer) ) file_put_contents(PMXE_Plugin::$session->file, $xml_footer, FILE_APPEND);
177
+ }
178
 
179
  $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
180
 
195
  {
196
  $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
197
  }
198
+ elseif($export->options['creata_a_new_export_file'] and ( ! XmlExportWooCommerceOrder::$is_active || $export->options['export_type'] != 'specific') )
199
  {
200
  $attach_id = wp_insert_attachment( $attachment_data, PMXE_Plugin::$session->file );
201
  }
223
  }
224
 
225
  }
226
+ else
227
+ {
228
  $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file);
229
 
230
  if ( ! $export->isEmpty() ){
233
  ))->save();
234
  }
235
 
236
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ PMXE_Wpallimport::generateImportTemplate( $export, PMXE_Plugin::$session->file, PMXE_Plugin::$session->count );
239
+
240
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
+ $export->set(array(
243
+ 'executing' => 0,
244
+ 'canceled' => 0,
245
+ 'iteration' => ++$export->iteration
246
+ ))->save();
 
 
 
247
 
248
+ do_action('pmxe_after_export', $export->id, $export);
249
 
250
+ $queue_exports = empty($export->parent_id) ? array() : get_option( 'wp_all_export_queue_' . $export->parent_id );
 
 
 
 
251
 
252
+ if ( ! empty($queue_exports) and ! empty($export->parent_id))
253
+ {
254
+ array_shift($queue_exports);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  }
256
 
257
+ if ( empty($queue_exports) )
258
+ {
259
+ delete_option( 'wp_all_export_queue_' . ( empty($export->parent_id) ? $export->id : $export->parent_id ) );
260
+ }
261
+ else
262
+ {
263
+ update_option( 'wp_all_export_queue_' . ( empty($export->parent_id) ? $export->id : $export->parent_id ), $queue_exports );
264
+ }
265
 
266
  wp_send_json(array(
267
+ 'export_id' => $export->id,
268
+ 'queue_export' => empty($queue_exports) ? false : $queue_exports[0],
269
+ 'exported' => $export->exported,
270
+ 'percentage' => 100,
271
+ 'done' => true,
272
+ 'records_per_request' => $exportOptions['records_per_iteration']
273
  ));
 
274
  }
275
+ }
276
 
 
classes/handler.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
- class PMXE_Handler extends PMXE_Session {
4
-
5
  /** cookie name */
6
  private $_cookie;
7
 
@@ -20,7 +20,8 @@ class PMXE_Handler extends PMXE_Session {
20
  * @access public
21
  * @return void
22
  */
23
- public function __construct() {
 
24
 
25
  $this->set_session_expiration();
26
 
@@ -34,7 +35,8 @@ class PMXE_Handler extends PMXE_Session {
34
  * Return true if the current user has an active session, i.e. a cookie to retrieve values
35
  * @return boolean
36
  */
37
- public function has_session() {
 
38
  return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
39
  }
40
 
@@ -44,18 +46,18 @@ class PMXE_Handler extends PMXE_Session {
44
  * @access public
45
  * @return void
46
  */
47
- public function set_session_expiration() {
 
48
  $this->_session_expiring = time() + intval( apply_filters( 'wpallexport_session_expiring', 60 * 60 * 47 ) ); // 47 Hours
49
  $this->_session_expiration = time() + intval( apply_filters( 'wpallexport_session_expiration', 60 * 60 * 48 ) ); // 48 Hours
50
  }
51
 
52
- public function generate_import_id() {
53
-
54
  $input = new PMXE_Input();
55
  $import_id = $input->get('id', 'new');
56
 
57
  return $import_id;
58
-
59
  }
60
 
61
  /**
@@ -64,8 +66,13 @@ class PMXE_Handler extends PMXE_Session {
64
  * @access public
65
  * @return array
66
  */
67
- public function get_session_data() {
68
- return (array) get_option( '_wpallexport_session_' . $this->_import_id . '_', array() );
 
 
 
 
 
69
  }
70
 
71
  /**
@@ -74,7 +81,8 @@ class PMXE_Handler extends PMXE_Session {
74
  * @access public
75
  * @return array
76
  */
77
- public function get_clear_session_data() {
 
78
  $this->_data = $this->get_session_data();
79
  $clear_data = array();
80
  foreach ($this->_data as $key => $value) {
@@ -91,75 +99,36 @@ class PMXE_Handler extends PMXE_Session {
91
  * @access public
92
  * @return void
93
  */
94
- public function save_data() {
 
95
  // Dirty if something changed - prevents saving nothing new
96
- if ( $this->_dirty && $this->has_session() ) {
97
-
98
  $session_option = '_wpallexport_session_' . $this->_import_id . '_';
99
- $session_expiry_option = '_wpallexport_session_expires_' . $this->_import_id . '_';
100
-
101
- wp_cache_delete( 'notoptions', 'options' );
102
- wp_cache_delete( $session_option, 'options' );
103
- wp_cache_delete( $session_expiry_option, 'options' );
104
-
105
- if ( false === get_option( $session_option ) ) {
106
- add_option( $session_option, $this->_data, '', 'no' );
107
- add_option( $session_expiry_option, $this->_session_expiration, '', 'no' );
108
- } else {
109
- update_option( $session_option, $this->_data );
110
- }
111
- }
112
- }
113
-
114
- public function convertData( $import_id ){
115
 
116
- $this->_import_id = 'new';
117
 
118
- $this->_data = $this->get_session_data();
119
-
120
- $this->set_session_expiration();
121
-
122
- $this->_import_id = $import_id;
123
-
124
- $this->clean_session();
125
-
126
- $this->_dirty = true;
127
-
128
- $this->save_data();
129
- }
130
-
131
- public function clean_session( $import_id = 'new' ){
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  global $wpdb;
134
-
135
- $now = time();
136
- $expired_sessions = array();
137
- $wpallimport_session_expires = $wpdb->get_results( $wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE %s", "_wpallexport_session_expires_" . $import_id . "_%") );
138
-
139
- $expired_sessions[] = "_wpallexport_session_{$import_id}_"; // Session key
140
-
141
- foreach ( $wpallimport_session_expires as $wpallimport_session_expire ) {
142
- //if ( $now > intval( $wpallimport_session_expire->option_value ) ) {
143
- //$session_id = substr( $wpallimport_session_expire->option_name, 29 );
144
- $expired_sessions[] = $wpallimport_session_expire->option_name; // Expires key
145
- //$expired_sessions[] = "_wpallimport_session_$session_id"; // Session key
146
- //}
147
- }
148
-
149
- if ( ! empty( $expired_sessions ) ) {
150
- wp_cache_delete( 'notoptions', 'options' );
151
- foreach ($expired_sessions as $expired) {
152
- wp_cache_delete( $expired, 'options' );
153
- delete_option($expired);
154
- }
155
- $expired_sessions_chunked = array_chunk( $expired_sessions, 100 );
156
-
157
- foreach ( $expired_sessions_chunked as $chunk ) {
158
- $option_names = implode( "','", $chunk );
159
- $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
160
- }
161
- }
162
 
 
 
163
  }
164
-
165
  }
1
  <?php
2
 
3
+ class PMXE_Handler extends PMXE_Session
4
+ {
5
  /** cookie name */
6
  private $_cookie;
7
 
20
  * @access public
21
  * @return void
22
  */
23
+ public function __construct()
24
+ {
25
 
26
  $this->set_session_expiration();
27
 
35
  * Return true if the current user has an active session, i.e. a cookie to retrieve values
36
  * @return boolean
37
  */
38
+ public function has_session()
39
+ {
40
  return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
41
  }
42
 
46
  * @access public
47
  * @return void
48
  */
49
+ public function set_session_expiration()
50
+ {
51
  $this->_session_expiring = time() + intval( apply_filters( 'wpallexport_session_expiring', 60 * 60 * 47 ) ); // 47 Hours
52
  $this->_session_expiration = time() + intval( apply_filters( 'wpallexport_session_expiration', 60 * 60 * 48 ) ); // 48 Hours
53
  }
54
 
55
+ public function generate_import_id()
56
+ {
57
  $input = new PMXE_Input();
58
  $import_id = $input->get('id', 'new');
59
 
60
  return $import_id;
 
61
  }
62
 
63
  /**
66
  * @access public
67
  * @return array
68
  */
69
+ public function get_session_data()
70
+ {
71
+ global $wpdb;
72
+
73
+ $session = $wpdb->get_row( $wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name = %s", '_wpallexport_session_' . $this->_import_id . '_'), ARRAY_A );
74
+
75
+ return empty($session) ? array() : maybe_unserialize($session['option_value']);
76
  }
77
 
78
  /**
81
  * @access public
82
  * @return array
83
  */
84
+ public function get_clear_session_data()
85
+ {
86
  $this->_data = $this->get_session_data();
87
  $clear_data = array();
88
  foreach ($this->_data as $key => $value) {
99
  * @access public
100
  * @return void
101
  */
102
+ public function save_data()
103
+ {
104
  // Dirty if something changed - prevents saving nothing new
105
+ if ( $this->_dirty && $this->has_session() )
106
+ {
107
  $session_option = '_wpallexport_session_' . $this->_import_id . '_';
108
+ $session_expiry_option = '_wpallexport_session_expires_' . $this->_import_id . '_';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ global $wpdb;
111
 
112
+ $session = $wpdb->get_row( $wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name = %s", $session_option), ARRAY_A );
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
+ if ( empty($session) )
115
+ {
116
+ $wpdb->query($wpdb->prepare("INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no')", $session_option, serialize($this->_data)));
117
+ $wpdb->query($wpdb->prepare("INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no')", $session_expiry_option, $this->_session_expiration));
118
+ // add_option( $session_option, $this->_data, '', 'no' );
119
+ // add_option( $session_expiry_option, $this->_session_expiration, '', 'no' );
120
+ } else {
121
+ // update_option( $session_option, $this->_data );
122
+ $wpdb->query($wpdb->prepare("UPDATE `$wpdb->options` SET `option_value` = %s WHERE `option_name` = %s", serialize($this->_data), $session_option));
123
+ }
124
+ }
125
+ }
126
+
127
+ public function clean_session( $import_id = 'new' )
128
+ {
129
  global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
+ $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", '_wpallexport_session_' . $import_id . '_') );
132
+ $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", '_wpallexport_session_expires_' . $import_id . '_') );
133
  }
 
134
  }
classes/wpallimport.php ADDED
@@ -0,0 +1,476 @@