Ultimate CSV Importer - Version 3.6.78

Version Description

Download this release

Release Info

Developer smackcoders
Plugin Icon 128x128 Ultimate CSV Importer
Version 3.6.78
Comparing to
See all releases

Code changes from version 3.6.77 to 3.6.78

Readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://www.smackcoders.com/donate.html
4
  Tags: batch, csv, excel, import, spreadsheet, autoblog, Autoblogger, csvimporter, data, dataimport, importer, wpcsvimporter, wpimporter, acf, auto blog, csv import, csv to post, data import, Easy CSV Importer, eci, import plugin, admin, user, users, Advanced CSV Import, Advanced CSV Importer, affiliate, amazon, author, automatic, blog, bulk, bulk edit, bulk editor, categories, comments, content, csv file, csv format, csv importer, custom post, e-commerce, free, images, language, manage, media, meta, multisite, News, page, photos, pictures, plugin, Post, seo, shop, shortcode, tags, Taxonomy, text, title, video, eshop, woocommerce, wordpress, xml, youtube, export
5
  Requires at least: 3.9
6
  Tested up to: 4.1.1
7
- Stable tag: 3.6.77
8
- Version: 3.6.77
9
  Author: smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
 
@@ -32,7 +32,7 @@ Wordpress Ultimate CSV Importer Pro V4.0 is available as live demo for users to
32
  * Mapping template feature with edit option.
33
  * Auto mapping and specific column update in Update feature.
34
 
35
- ** Now stable version 3.6.77 available to download with minor fix on featured image naming issue. Visit [www.wpultimatecsvimporter.com](http://www.wpultimatecsvimporter.com) for more news and future plans.
36
 
37
  WP Ultimate CSV Importer Plugin proven much effective advanced CSV File Importer With Ultimate User Friendly Features. It is much easy now even for newbies to import any csv file as any wordpress post type and associated fields by simple mapping feature. Now import any CSV file as thousands of post, page and custom post types. This is admin side free plugin helps you in bulk edit, create and import posts type for your blog or site.
38
 
@@ -195,6 +195,9 @@ This will solve your issue or get support from hosting if you dint have sufficie
195
 
196
  == Changelog ==
197
 
 
 
 
198
  = 3.6.77 =
199
  * Added: WordPress 4.1.1 compatibility checked.
200
  * Improved: Inline image import feature. Added recursive method to assign the image.
@@ -426,6 +429,9 @@ This will solve your issue or get support from hosting if you dint have sufficie
426
 
427
  == Upgrade Notice ==
428
 
 
 
 
429
  = 3.6.77 =
430
  * Upgrade now for WordPress 4.1.1 compatibility and minor bug fixes.
431
 
4
  Tags: batch, csv, excel, import, spreadsheet, autoblog, Autoblogger, csvimporter, data, dataimport, importer, wpcsvimporter, wpimporter, acf, auto blog, csv import, csv to post, data import, Easy CSV Importer, eci, import plugin, admin, user, users, Advanced CSV Import, Advanced CSV Importer, affiliate, amazon, author, automatic, blog, bulk, bulk edit, bulk editor, categories, comments, content, csv file, csv format, csv importer, custom post, e-commerce, free, images, language, manage, media, meta, multisite, News, page, photos, pictures, plugin, Post, seo, shop, shortcode, tags, Taxonomy, text, title, video, eshop, woocommerce, wordpress, xml, youtube, export
5
  Requires at least: 3.9
6
  Tested up to: 4.1.1
7
+ Stable tag: 3.6.78
8
+ Version: 3.6.78
9
  Author: smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
 
32
  * Mapping template feature with edit option.
33
  * Auto mapping and specific column update in Update feature.
34
 
35
+ ** Now stable version 3.6.78 available to download with hot security fix. Visit [www.wpultimatecsvimporter.com](http://www.wpultimatecsvimporter.com) for more news and future plans.
36
 
37
  WP Ultimate CSV Importer Plugin proven much effective advanced CSV File Importer With Ultimate User Friendly Features. It is much easy now even for newbies to import any csv file as any wordpress post type and associated fields by simple mapping feature. Now import any CSV file as thousands of post, page and custom post types. This is admin side free plugin helps you in bulk edit, create and import posts type for your blog or site.
38
 
195
 
196
  == Changelog ==
197
 
198
+ = 3.6.78 =
199
+ * Added: Hot security fix in readfile.php. ( Thanks - James Golovich )
200
+
201
  = 3.6.77 =
202
  * Added: WordPress 4.1.1 compatibility checked.
203
  * Improved: Inline image import feature. Added recursive method to assign the image.
429
 
430
  == Upgrade Notice ==
431
 
432
+ = 3.6.78 =
433
+ * Upgrade now for security fix.
434
+
435
  = 3.6.77 =
436
  * Upgrade now for WordPress 4.1.1 compatibility and minor bug fixes.
437
 
images/Importicon_24.png CHANGED
File without changes
images/csv_importer_dashboard_v3.5.png ADDED
Binary file
images/facebook.png CHANGED
File without changes
images/googleplus.png CHANGED
File without changes
images/icon.png CHANGED
File without changes
images/linkedin.png CHANGED
File without changes
images/twitter.png CHANGED
File without changes
includes/WPImporter_includes_helper.php CHANGED
@@ -299,6 +299,20 @@ class WPImporter_includes_helper {
299
  return $csv->data;
300
  }
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
 
303
  /**
304
  * Manage duplicates
299
  return $csv->data;
300
  }
301
 
302
+ function csv_file_readdata($file, $obj)
303
+ {
304
+ $file = $obj->getUploadDirectory().'/'.$file;
305
+ require_once(WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY.'includes/Importer.php');
306
+ $csv = new ImporterLib();
307
+ $csv->delim($file);
308
+ foreach($csv->data as $hkey => $hval) {
309
+ foreach($hval as $hk => $hv) {
310
+ $this->headers[] = $hk;
311
+ }
312
+ break;
313
+ }
314
+ return $csv->data;
315
+ }
316
 
317
  /**
318
  * Manage duplicates
index.php CHANGED
@@ -2,7 +2,7 @@
2
  /******************************
3
  * Plugin Name: WP Ultimate CSV Importer
4
  * Description: A plugin that helps to import the data's from a CSV file.
5
- * Version: 3.6.77
6
  * Author: smackcoders.com
7
  * Plugin URI: http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html
8
  * Author URI: http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html
@@ -75,7 +75,7 @@ define('WP_CONST_ULTIMATE_CSV_IMP_URL', 'http://www.smackcoders.com/wp-ultimate-
75
  define('WP_CONST_ULTIMATE_CSV_IMP_NAME', 'WP Ultimate CSV Importer');
76
  define('WP_CONST_ULTIMATE_CSV_IMP_SLUG', 'wp-ultimate-csv-importer');
77
  define('WP_CONST_ULTIMATE_CSV_IMP_SETTINGS', 'WP Ultimate CSV Importer');
78
- define('WP_CONST_ULTIMATE_CSV_IMP_VERSION', '3.6.77');
79
  define('WP_CONST_ULTIMATE_CSV_IMP_DIR', WP_PLUGIN_URL . '/' . WP_CONST_ULTIMATE_CSV_IMP_SLUG . '/');
80
  define('WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY', plugin_dir_path(__FILE__));
81
  define('WP_CSVIMP_PLUGIN_BASE', WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY);
2
  /******************************
3
  * Plugin Name: WP Ultimate CSV Importer
4
  * Description: A plugin that helps to import the data's from a CSV file.
5
+ * Version: 3.6.78
6
  * Author: smackcoders.com
7
  * Plugin URI: http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html
8
  * Author URI: http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html
75
  define('WP_CONST_ULTIMATE_CSV_IMP_NAME', 'WP Ultimate CSV Importer');
76
  define('WP_CONST_ULTIMATE_CSV_IMP_SLUG', 'wp-ultimate-csv-importer');
77
  define('WP_CONST_ULTIMATE_CSV_IMP_SETTINGS', 'WP Ultimate CSV Importer');
78
+ define('WP_CONST_ULTIMATE_CSV_IMP_VERSION', '3.6.78');
79
  define('WP_CONST_ULTIMATE_CSV_IMP_DIR', WP_PLUGIN_URL . '/' . WP_CONST_ULTIMATE_CSV_IMP_SLUG . '/');
80
  define('WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY', plugin_dir_path(__FILE__));
81
  define('WP_CSVIMP_PLUGIN_BASE', WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY);
js/ultimate-importer-free.js CHANGED
@@ -26,19 +26,20 @@ jQuery( document ).ready(function() {
26
  var select_delimeter = jQuery('#select_delim').val();
27
  var select_delim = jQuery('#select_delim').val();
28
  var get_log = jQuery('#log').val();
 
29
  if (!jQuery.trim(jQuery('#log').html()).length) {
30
  if(checkmodule != 'dashboard')
31
  document.getElementById('log').innerHTML = '<p style="margin:15px;color:red;">NO LOGS YET NOW.</p>';
32
  }
33
 
34
- if (checkfile != '') {
35
  uploadedFile = checkfile;
36
- }
37
  if (select_delimeter != '') {
38
  select_delim = select_delimeter;
39
  }
40
  if(uploadedFile != '' && select_delim != '') {
41
- var doaction = 'record_no=1&file_name=' + uploadedFile + '&selected_delimeter=' + select_delim;
42
  var tmpLoc = jQuery('#tmpLoc').val();
43
  if(tmpLoc != '' && tmpLoc != null) {
44
  jQuery.ajax({
@@ -72,16 +73,17 @@ function gotoelement(id) {
72
  var no_of_records = document.getElementById('totRecords').value;
73
  var uploadedFile = document.getElementById('uploadedFile').value;
74
  var delim = document.getElementById('select_delimeter').value;
 
75
  if (id == 'prev_record') {
76
  gotoElement = parseInt(gotoElement) - 1;
77
  }
78
  if (id == 'next_record') {
79
  gotoElement = parseInt(gotoElement) + 1;
80
  }
81
- if (gotoElement <= 0) {
82
  gotoElement = 0;
83
  }
84
- if (gotoElement >= no_of_records) {
85
  gotoElement = parseInt(no_of_records) - 1;
86
  }
87
  if (id == 'apply_element') {
@@ -101,7 +103,7 @@ function gotoelement(id) {
101
  return false;
102
  }
103
  }
104
- var doaction = 'record_no=' + gotoElement + '&file_name=' + uploadedFile + '&delim='+ delim;
105
  var tmpLoc = document.getElementById('tmpLoc').value;
106
  jQuery.ajax({
107
  url: tmpLoc + 'templates/readfile.php',
@@ -111,10 +113,12 @@ function gotoelement(id) {
111
  success: function (response) {
112
  var totalLength = response.length;
113
  for (var i = 0; i < totalLength; i++) {
114
- if ((response[i].length) > 32) {
115
- document.getElementById('elementVal_' + i).innerHTML = response[i].substring(0, 28) + '...';
116
- } else {
117
- document.getElementById('elementVal_' + i).innerHTML = response[i];
 
 
118
  }
119
  }
120
  var displayRecCount = gotoElement + 1;
26
  var select_delimeter = jQuery('#select_delim').val();
27
  var select_delim = jQuery('#select_delim').val();
28
  var get_log = jQuery('#log').val();
29
+ var checkmodule = jQuery('#checkmodule').val();
30
  if (!jQuery.trim(jQuery('#log').html()).length) {
31
  if(checkmodule != 'dashboard')
32
  document.getElementById('log').innerHTML = '<p style="margin:15px;color:red;">NO LOGS YET NOW.</p>';
33
  }
34
 
35
+ /* if (checkfile != '') {
36
  uploadedFile = checkfile;
37
+ } */
38
  if (select_delimeter != '') {
39
  select_delim = select_delimeter;
40
  }
41
  if(uploadedFile != '' && select_delim != '') {
42
+ var doaction = 'record_no=1&file_name=' + uploadedFile + '&selected_delimeter=' + select_delim + '&checkmodule=' + checkmodule;
43
  var tmpLoc = jQuery('#tmpLoc').val();
44
  if(tmpLoc != '' && tmpLoc != null) {
45
  jQuery.ajax({
73
  var no_of_records = document.getElementById('totRecords').value;
74
  var uploadedFile = document.getElementById('uploadedFile').value;
75
  var delim = document.getElementById('select_delimeter').value;
76
+ var checkmodule = jQuery('#checkmodule').val();
77
  if (id == 'prev_record') {
78
  gotoElement = parseInt(gotoElement) - 1;
79
  }
80
  if (id == 'next_record') {
81
  gotoElement = parseInt(gotoElement) + 1;
82
  }
83
+ if (parseInt(gotoElement) <= 0) {
84
  gotoElement = 0;
85
  }
86
+ if (parseInt(gotoElement) >= parseInt(no_of_records)) {
87
  gotoElement = parseInt(no_of_records) - 1;
88
  }
89
  if (id == 'apply_element') {
103
  return false;
104
  }
105
  }
106
+ var doaction = 'record_no=' + gotoElement + '&file_name=' + uploadedFile + '&delim='+ delim + '&checkmodule=' + checkmodule;
107
  var tmpLoc = document.getElementById('tmpLoc').value;
108
  jQuery.ajax({
109
  url: tmpLoc + 'templates/readfile.php',
113
  success: function (response) {
114
  var totalLength = response.length;
115
  for (var i = 0; i < totalLength; i++) {
116
+ if (response[i] == null) {
117
+ document.getElementById('elementVal_' + i).innerHTML = response[i];
118
+ } else if ((response[i].length) >= 32) {
119
+ document.getElementById('elementVal_' + i).innerHTML = response[i].substring(0, 28) + '...';
120
+ } else {
121
+ document.getElementById('elementVal_' + i).innerHTML = response[i];
122
  }
123
  }
124
  var displayRecCount = gotoElement + 1;
js/ultimate-importer-pro.js ADDED
@@ -0,0 +1,770 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready(function() {
2
+ jQuery('.dropdown-toggle').dropdown('toggle');
3
+ var checkmodule = document.getElementById('checkmodule').value;
4
+ if(checkmodule != 'dashboard' && checkmodule != 'filemanager') {
5
+ var get_log = document.getElementById('log').innerHTML;
6
+ if (!jQuery.trim(jQuery('#log').html()).length) {
7
+ document.getElementById('log').innerHTML = '<p style="margin:15px;color:red;">NO LOGS YET NOW.</p>';
8
+ }
9
+
10
+ pieStats();
11
+ lineStats();
12
+
13
+
14
+ }
15
+ if(checkmodule=='custompost')
16
+ {
17
+ var step = document.getElementById('stepstatus').value;
18
+ if(step == 'mapping_settings') {
19
+ var cust_post_list_count = document.getElementById('cust_post_list_count').value;
20
+ if(cust_post_list_count=='0')
21
+ document.getElementById('cust_post_empty').style.display='';
22
+ }
23
+ }
24
+ var checkfile = document.getElementById('checkfile').value;
25
+ var uploadedFile = document.getElementById('uploadedFile').value;
26
+ var select_delimeter=document.getElementById('select_delim').value;
27
+ var select_delim=document.getElementById('select_delim').value;
28
+ var get_log = document.getElementById('log').innerHTML;
29
+ if (!jQuery.trim(jQuery('#log').html()).length) {
30
+ document.getElementById('log').innerHTML = '<p style="margin:15px;color:red;">NO LOGS YET NOW.</p>';
31
+ }
32
+ if(checkfile != ''){
33
+ uploadedFile = checkfile;
34
+ }
35
+ if(select_delimeter!='')
36
+ {
37
+ select_delim=select_delimeter;
38
+ }
39
+ var doaction = 'record_no=1&file_name='+uploadedFile+'&selected_delimeter='+select_delim;
40
+ var tmpLoc = document.getElementById('tmpLoc').value;
41
+ jQuery.ajax({
42
+ url: tmpLoc+'templates/readfile.php',
43
+ type: 'post',
44
+ data: doaction,
45
+ dataType: 'json',
46
+ success: function(response){
47
+ var totalLength = response.length;
48
+ var setHeight = (parseInt(totalLength)*30)+250;
49
+ //document.getElementById('sec-two').style.height = setHeight+'px';
50
+ }
51
+ });
52
+ });
53
+ function goto_mapping(id){
54
+ if(id == 'importfile'){
55
+ var currentURL = document.URL;
56
+ var go_to_url = currentURL.replace("uploadfile","mapping_settings");
57
+ window.location.assign(go_to_url);
58
+ document.getElementById('sec-one').style.display='none';
59
+ document.getElementById('sec-two').style.display='';
60
+ }
61
+ }
62
+
63
+ function gotoelement(id) {
64
+ var gotoElement = document.getElementById('current_record').value;
65
+ var no_of_records = document.getElementById('totRecords').value;
66
+ var uploadedFile = document.getElementById('uploadedFile').value;
67
+ var delim = document.getElementById('select_delimeter').value;
68
+ if (id == 'prev_record') {
69
+ gotoElement = parseInt(gotoElement) - 1;
70
+ }
71
+ if (id == 'next_record') {
72
+ gotoElement = parseInt(gotoElement) + 1;
73
+ }
74
+ if (gotoElement <= 0) {
75
+ gotoElement = 0;
76
+ }
77
+ if (gotoElement >= no_of_records) {
78
+ gotoElement = parseInt(no_of_records) - 1;
79
+ }
80
+ if (id == 'apply_element') {
81
+ gotoElement = parseInt(document.getElementById('goto_element').value);
82
+ if (isNaN(gotoElement)) {
83
+ showMapMessages('error', ' Please provide valid record number.');
84
+ }
85
+ if (gotoElement <= 0) {
86
+ gotoElement = 0;
87
+ showMapMessages('error', ' Please provide valid record number.');
88
+ } else {
89
+ gotoElement = gotoElement - 1;
90
+ }
91
+ if (gotoElement >= no_of_records) {
92
+ gotoElement = parseInt(no_of_records) - 1;
93
+ showMapMessages('error', 'CSV file have only ' + no_of_records + ' records.');
94
+ return false;
95
+ }
96
+ }
97
+ var doaction = 'record_no=' + gotoElement + '&file_name=' + uploadedFile + '&delim='+ delim;
98
+ var tmpLoc = document.getElementById('tmpLoc').value;
99
+ jQuery.ajax({
100
+ url: tmpLoc + 'templates/readfile.php',
101
+ type: 'post',
102
+ data: doaction,
103
+ dataType: 'json',
104
+ success: function (response) {
105
+ var totalLength = response.length;
106
+ for (var i = 0; i < totalLength; i++) {
107
+ if ((response[i].length) > 32) {
108
+ document.getElementById('elementVal_' + i).innerHTML = response[i].substring(0, 28) + '...';
109
+ } else {
110
+ document.getElementById('elementVal_' + i).innerHTML = response[i];
111
+ }
112
+ }
113
+ var displayRecCount = gotoElement + 1;
114
+ document.getElementById('preview_of_row').innerHTML = "Showing preview of row #" + displayRecCount;
115
+ document.getElementById('current_record').value = gotoElement;
116
+ }
117
+ });
118
+ }
119
+
120
+ function showtemplatediv_wpuci(checked, div)
121
+ {
122
+ if(checked)
123
+ jQuery('#'+div).show();
124
+ else
125
+ jQuery('#'+div).hide();
126
+ }
127
+
128
+ function showtemplatediv_edit(checked, value)
129
+ {
130
+ if(value == 'saveas')
131
+ jQuery('#showtemplate_edit_div').show();
132
+ else
133
+ jQuery('#showtemplate_edit_div').hide();
134
+ }
135
+
136
+
137
+ function selectpoststatus()
138
+ {
139
+ var ps = document.getElementById("importallwithps");
140
+ var selectedpsindex = ps.options[ps.selectedIndex].value;
141
+ if(selectedpsindex == 3){
142
+ document.getElementById('globalpassword_label').style.display = "block";
143
+ document.getElementById('globalpassword_text').style.display = "block";
144
+ }
145
+ else{
146
+ document.getElementById('globalpassword_label').style.display = "none";
147
+ document.getElementById('globalpassword_text').style.display = "none";
148
+ }
149
+ var totdropdown= document.getElementById('h2').value;
150
+ var total = parseInt(totdropdown);
151
+ if(selectedpsindex=='0')
152
+ {
153
+
154
+ for(var i=0;i < total;i++)
155
+ {
156
+
157
+ dropdown = document.getElementById("mapping"+i);
158
+ var option=document.createElement('option');
159
+ option.text="post_status";
160
+ dropdown.add(option);
161
+
162
+ }
163
+
164
+ }
165
+ else {
166
+ for(var i=0;i < total;i++)
167
+ {
168
+
169
+ dropdown = document.getElementById("mapping"+i);
170
+
171
+ var totarr = dropdown.options.length;
172
+
173
+ for(var j=0;j<totarr;j++)
174
+ {
175
+
176
+ if(dropdown.options[j].value=='post_status')
177
+ {
178
+
179
+ dropdown.options.remove(j);
180
+ totarr--;
181
+ }
182
+ }
183
+
184
+ }
185
+ }
186
+ }
187
+
188
+
189
+
190
+ // Function for add customfield
191
+
192
+ function addcustomfield(myval, selected_id) {
193
+ var a = document.getElementById('h1').value;
194
+ var importer = document.getElementById('selectedImporter').value;
195
+ var aa = document.getElementById('h2').value;
196
+ var selected_dropdown = document.getElementById('mapping' + selected_id);
197
+ var selected_value = selected_dropdown.value;
198
+ var prevoptionindex = document.getElementById('prevoptionindex').value;
199
+ var prevoptionvalue = document.getElementById('prevoptionvalue').value;
200
+ var mappedID = 'mapping' + selected_id;
201
+ var add_prev_option = false;
202
+ if(mappedID == prevoptionindex){
203
+ add_prev_option = true;
204
+ }
205
+ for (var i = 0; i < aa; i++) {
206
+ var b = document.getElementById('mapping' + i).value;
207
+ var id = 'mapping' + i;
208
+ if(add_prev_option){
209
+ if(i != selected_id){
210
+ jQuery('#'+id).append( new Option(prevoptionvalue,prevoptionvalue) );
211
+ }
212
+ }
213
+ if(i != selected_id){
214
+ var x=document.getElementById('mapping' + i);
215
+ jQuery('#'+id+' option[value="'+selected_value+'"]').remove();
216
+ }
217
+ if (b == 'add_custom' + i) {
218
+ document.getElementById('textbox' + i).style.display = "";
219
+ document.getElementById('customspan' + i).style.display = "";
220
+ }
221
+ else {
222
+ document.getElementById('textbox' + i).style.display = "none";
223
+ document.getElementById('customspan' + i).style.display = "none";
224
+ }
225
+ }
226
+ document.getElementById('prevoptionindex').value = 'mapping' + selected_id;
227
+ var customField = selected_value.indexOf("add_custom");
228
+ if(selected_value != '-- Select --' && customField != 0){
229
+ document.getElementById('prevoptionvalue').value = selected_value;
230
+ }
231
+ }
232
+
233
+
234
+ function clearMapping()
235
+ {
236
+ var total_mfields = document.getElementById('h2').value;
237
+ var mfields_arr = document.getElementById('mapping_fields_array').value;
238
+ var n=mfields_arr.split(",");
239
+ var options = '<option id="select">-- Select --</option>';
240
+ for(var i=0;i<n.length;i++){
241
+ options +="<option value='"+n[i]+"'>"+n[i]+"</option>";
242
+ }
243
+ for(var j=0;j<total_mfields;j++){
244
+ document.getElementById('mapping'+j).innerHTML = options;
245
+ document.getElementById('mapping'+j).innerHTML += "<option value='add_custom"+j+"'>Add Custom Field</option>";
246
+ document.getElementById('textbox'+j).style.display = 'none';
247
+ document.getElementById('customspan'+j).style.display = 'none';
248
+ }
249
+ }
250
+
251
+ function clearmapping()
252
+ {
253
+ var total_mfields = document.getElementById('h2').value;
254
+ var mfields_arr = document.getElementById('mapping_fields_array').value;
255
+ var n=mfields_arr.split(",");
256
+ var options = "<option id='select'>-- Select --</option>";
257
+ for(var i=0;i<n.length;i++){
258
+ options +="<option value='"+n[i]+"'>"+n[i]+"</option>";
259
+ }
260
+ for(var j=0;j<total_mfields;j++){
261
+ document.getElementById('mapping'+j).innerHTML = options;
262
+ //document.getElementById('mapping'+j).innerHTML += "<option value='add_custom"+j+"'>Add Custom Field</option>";
263
+ document.getElementById('textbox'+j).style.display = 'none';
264
+ document.getElementById('customspan'+j).style.display = 'none';
265
+ }
266
+ }
267
+
268
+ function shownotification(msg, alerts)
269
+ {
270
+ var newclass;
271
+ var divid = "notification_wp_csv";
272
+
273
+ if(alerts == 'success')
274
+ newclass = "alert alert-success";
275
+ else if(alerts == 'danger')
276
+ newclass = "alert alert-danger";
277
+ else if(alerts == 'warning')
278
+ newclass = "alert alert-warning";
279
+ else
280
+ newclass = "alert alert-info";
281
+
282
+ jQuery('#'+divid).removeClass()
283
+ jQuery('#'+divid).html(msg);
284
+ jQuery('#'+divid).addClass(newclass);
285
+ // Scroll
286
+ jQuery('html,body').animate({
287
+ scrollTop: jQuery("#"+divid).offset().top},
288
+ 'slow');
289
+ }
290
+
291
+ function import_csv()
292
+ {
293
+ // code added by goku to check whether templatename
294
+ var mapping_checked = jQuery('#mapping_templatename_checked').is(':checked');
295
+ var mapping_tempname = jQuery('#mapping_templatename').val();
296
+ var mapping_checked_radio = jQuery('input[name=tempaction]:radio:checked').val();
297
+ if(mapping_checked || mapping_checked_radio == 'saveas')
298
+ {
299
+ if(mapping_checked_radio == 'saveas')
300
+ mapping_tempname = jQuery('#mapping_templatename_edit').val();
301
+
302
+ if(jQuery.trim(mapping_tempname) == '')
303
+ {
304
+ alert('Template name is empty');
305
+ return false;
306
+ }
307
+ else
308
+ {
309
+ // check templatename already exists
310
+ jQuery.ajax({
311
+ type: 'POST',
312
+ url: ajaxurl,
313
+ async: false,
314
+ data: {
315
+ 'action' : 'checktemplatename',
316
+ 'templatename' : mapping_tempname,
317
+ },
318
+ success:function(data)
319
+ {
320
+ if(data != 0)
321
+ {
322
+ jQuery('#mapping_templatename').val('');
323
+ }
324
+ },
325
+ error: function(errorThrown){
326
+ console.log(errorThrown);
327
+ }
328
+ });
329
+ }
330
+ }
331
+ var mapping_tempname = jQuery('#mapping_templatename').val();
332
+ if(mapping_checked_radio == 'saveas')
333
+ //mapping_tempname = jQuery('#mapping_templatename_edit').val();
334
+
335
+ if(mapping_tempname == '' && (mapping_checked || mapping_templatename_edit == 'saveas'))
336
+ {
337
+ alert('Template Name already exists');return false;
338
+ }
339
+ // code ends here on checking templatename
340
+
341
+ var importer = document.getElementById('selectedImporter').value;
342
+ var header_count = document.getElementById('h2').value;
343
+ var array = new Array();
344
+ var val1, val2, val3, val4, val5, val6, val7, error_msg, chk_status_in_csv, post_status_msg;
345
+ val1 = val2 = val3 = val4 = val5 = val6 = val7 = post_status_msg = post_type = 'Off';
346
+ for (var i = 0; i < header_count; i++) {
347
+ var e = document.getElementById("mapping" + i);
348
+ var value = e.options[e.selectedIndex].value;
349
+ array[i] = value;
350
+ }
351
+ //alert(array.length);
352
+ if (importer == 'post' || importer == 'page' || importer == 'custompost') {
353
+ if(importer == 'custompost') {
354
+ var getSelectedIndex = document.getElementById('custompostlist');
355
+ var SelectedIndex = getSelectedIndex.value;
356
+ //var t=getSelectedIndex.options[getSelectedIndex.selectedIndex];
357
+ if( SelectedIndex != 'select')
358
+ post_type='On';
359
+ //alert(t+'---'+SelectedIndex);
360
+ }
361
+
362
+ chk_status_in_csv = document.getElementById('importallwithps').value;
363
+ if (chk_status_in_csv != 0)
364
+ post_status_msg = 'On';
365
+
366
+ for (var j = 0; j < array.length; j++) {
367
+ if (array[j] == 'post_title') {
368
+ val1 = 'On';
369
+ }
370
+ if (array[j] == 'post_content') {
371
+ val2 = 'On';
372
+ }
373
+ if (post_status_msg == 'Off') {
374
+ if (array[j] == 'post_status')
375
+ post_status_msg = 'On';
376
+ }
377
+ }
378
+ if (importer != 'custompost' && val1 == 'On' && val2 == 'On' && post_status_msg == 'On') {
379
+ return true;
380
+ }
381
+ else if (importer == 'custompost' && val1 == 'On' && val2 == 'On' && post_status_msg == 'On' && post_type=='On') {
382
+ return true;
383
+ }
384
+ else {
385
+ error_msg = '';
386
+ if (val1 == 'Off')
387
+ error_msg += " post_title,";
388
+ if (val2 == 'Off')
389
+ error_msg += " post_content,";
390
+ if(importer == 'custompost') {
391
+ if (SelectedIndex == 'select')
392
+ error_msg += " post_type,";
393
+ }
394
+ if (post_status_msg == 'Off')
395
+ error_msg += " post_status";
396
+ showMapMessages('error', 'Error: ' + error_msg + ' - Mandatory fields. Please map the fields to proceed.');
397
+ return false;
398
+ }
399
+ }
400
+
401
+ // validation starts
402
+ else if(importer == 'comments'){
403
+ //var getSelectedIndex1 = document.getElementById('selectPosts');
404
+ //var SelectedIndex1 = getSelectedIndex1.options[getSelectedIndex1.selectedIndex].text;
405
+ for(var j=0;j<array.length;j++){
406
+ if(array[j] == 'comment_author'){
407
+ val1 = 'On';
408
+ }
409
+ if(array[j] == 'comment_author_email'){
410
+ val2 = 'On';
411
+ }
412
+ if(array[j] == 'comment_content'){
413
+ val3 = 'On';
414
+ }
415
+ if(array[j] == 'comment_post_ID'){
416
+ val4 = 'On';
417
+ }
418
+
419
+
420
+ }
421
+ if(val1 == 'On' && val2 == 'On' && val3 == 'On' && val4 == 'On') {
422
+ return true;
423
+ }
424
+ else{
425
+ showMapMessages('error',' "Post Id", "Comment Author", "Comment Author Email" and "Comment Content" should be mapped.');
426
+ return false;
427
+ }
428
+
429
+
430
+ showMapMessages('error',header_count);return false;
431
+ }
432
+ else if(importer == 'users'){
433
+ //var getSelectedIndex = document.getElementById('userrole');
434
+ //var SelectedIndex = getSelectedIndex.options[getSelectedIndex.selectedIndex].text;
435
+ for(var j=0;j<array.length;j++){
436
+ if(array[j] == 'user_login'){
437
+ val1 = 'On';
438
+ }
439
+ if(array[j] == 'user_email'){
440
+ val2 = 'On';
441
+ }
442
+ if(array[j] == 'role'){
443
+ val3 = 'On';
444
+ }
445
+ }
446
+ if(val1 == 'On' && val2 == 'On' && val3 == 'On') {
447
+ return true;
448
+ }
449
+ else{
450
+ showMapMessages('error','"role", "user_login" and "user_email" should be mapped.');
451
+ return false;
452
+ }
453
+ }
454
+ // validation ends
455
+ }
456
+
457
+
458
+ function showMapMessages(alerttype, msg) {
459
+ jQuery("#showMsg").addClass("maperror");
460
+ document.getElementById('showMsg').innerHTML = msg;
461
+ document.getElementById('showMsg').className += ' ' + alerttype;
462
+ document.getElementById('showMsg').style.display = '';
463
+ jQuery("#showMsg").fadeOut(10000);
464
+ }
465
+
466
+ function importRecordsbySettings(siteurl)
467
+ {
468
+ var importlimit = document.getElementById('importlimit').value;
469
+ var get_requested_count = importlimit;
470
+ var tot_no_of_records = document.getElementById('checktotal').value;
471
+ var importas = document.getElementById('selectedImporter').value;
472
+ var uploadedFile = document.getElementById('checkfile').value;
473
+ // var no_of_columns = document.getElementById('h2').value;
474
+ var step = document.getElementById('stepstatus').value;
475
+ var mappingArr = document.getElementById('mappingArr').value;
476
+ var dupContent = document.getElementById('duplicatecontent').checked;
477
+ var dupTitle = document.getElementById('duplicatetitle').checked;
478
+ var currentlimit = document.getElementById('currentlimit').value;
479
+ var tmpCnt = document.getElementById('tmpcount').value;
480
+ var no_of_tot_records = document.getElementById('tot_records').value;
481
+ var get_log = document.getElementById('log').innerHTML;
482
+ document.getElementById('reportLog').style.display = '';
483
+ document.getElementById('terminatenow').style.display = '';
484
+ if(get_requested_count != '') {
485
+ //return true;
486
+ } else {
487
+ document.getElementById('showMsg').style.display = "";
488
+ document.getElementById('showMsg').innerHTML = '<p id="warning-msg" class="alert alert-warning">Fill all mandatory fields.</p>'; jQuery("#showMsg").fadeOut(10000);
489
+ return false;
490
+ }
491
+ if(parseInt(get_requested_count) <= parseInt(no_of_tot_records)) {
492
+ document.getElementById('server_request_warning').style.display = 'none';
493
+ } else {
494
+ document.getElementById('server_request_warning').style.display = '';
495
+ return false;
496
+ }
497
+ if(get_log == '<p style="margin:15px;color:red;">NO LOGS YET NOW.</p>'){
498
+ document.getElementById('log').innerHTML = '<p style="margin:15px;color:red;">Your Import Is In Progress...</p>';
499
+ document.getElementById('startbutton').disabled = true;
500
+ }
501
+ document.getElementById('ajaxloader').style.display="";
502
+ var tempCount = parseInt(tmpCnt);
503
+ var totalCount = parseInt(tot_no_of_records);
504
+ if(tempCount>totalCount){
505
+ document.getElementById('ajaxloader').style.display="none";
506
+ document.getElementById('startbutton').style.display="none";
507
+ document.getElementById('importagain').style.display="";
508
+ document.getElementById('terminatenow').style.display = "none";
509
+ return false;
510
+ }
511
+
512
+ var postdata = new Array();
513
+ postdata = {'dupContent':dupContent,'dupTitle':dupTitle,'importlimit':importlimit,'limit':currentlimit,'totRecords':tot_no_of_records,'selectedImporter':importas,'uploadedFile':uploadedFile,'tmpcount':tmpCnt,}
514
+
515
+ var tmpLoc = document.getElementById('tmpLoc').value;
516
+ jQuery.ajax({
517
+ type: 'POST',
518
+ url: ajaxurl,
519
+ data: {
520
+ 'action' : 'importByRequest',
521
+ 'postdata' : postdata,
522
+ 'siteurl' : siteurl,
523
+ },
524
+ success:function(data) {
525
+ if(parseInt(tmpCnt) == parseInt(tot_no_of_records)){
526
+ document.getElementById('terminatenow').style.display = "none";
527
+ }
528
+ if(parseInt(tmpCnt) < parseInt(tot_no_of_records)){
529
+ var terminate_action = document.getElementById('terminateaction').value;
530
+ if(terminate_action == 'continue'){
531
+ currentlimit = parseInt(currentlimit)+parseInt(importlimit);
532
+ document.getElementById('currentlimit').value = currentlimit;
533
+ console.log('impLmt: '+importlimit+'totRecds: '+tot_no_of_records);
534
+ document.getElementById('tmpcount').value = parseInt(tmpCnt)+parseInt(importlimit);
535
+ setTimeout(function(){importRecordsbySettings()},0);
536
+ } else {
537
+ document.getElementById('log').innerHTML += "Import process has been terminated.</br>";
538
+ return false;
539
+ }
540
+ }else{
541
+ document.getElementById('ajaxloader').style.display="none";
542
+ document.getElementById('startbutton').style.display="none";
543
+ document.getElementById('importagain').style.display="";
544
+ return false;
545
+ }
546
+ document.getElementById('log').innerHTML += data+'<br/>';
547
+
548
+ },
549
+ error: function(errorThrown){
550
+ console.log(errorThrown);
551
+ }
552
+ });
553
+ }
554
+
555
+ // Terminate import process
556
+ function terminateProcess(){
557
+ document.getElementById('terminateaction').value = 'terminate';
558
+ }
559
+
560
+
561
+ // Enable/Disable WP-e-Commerce Custom Fields
562
+ function enablewpcustomfield(val){
563
+ if(val == 'wpcustomfields'){
564
+ document.getElementById('wpcustomfieldstr').style.display = '';
565
+ }
566
+ else{
567
+ document.getElementById('wpcustomfields').checked = false;
568
+ document.getElementById('wpcustomfieldstr').style.display = 'none';
569
+ }
570
+ }
571
+
572
+ function saveSettings(){ //alert('dd');
573
+ //document.getElementById('ShowMsg').style.display = '';
574
+ jQuery(document).ready( function() {
575
+ jQuery('#ShowMsg').delay(2000).fadeOut();
576
+ });
577
+ }
578
+
579
+ function Reload(){
580
+ window.location.reload();
581
+ }
582
+
583
+ function check_if_avail(val){
584
+ var proModule = new Array();
585
+ proModule[0] = 'categories';
586
+ proModule[1] = 'customtaxonomy';
587
+ proModule[2] = 'eshop';
588
+ proModule[3] = 'marketpress';
589
+ proModule[4] = 'woocommerce';
590
+ proModule[5] = 'wpcommerce';
591
+ proModule[6] = 'cctm';
592
+ proModule[7] = 'types';
593
+ proModule[8] = 'acf';
594
+ proModule[9] = 'Customerreviews';
595
+ proModule[10] = 'WP-Members';
596
+ proModule[11] = 'yoastseo';
597
+ proModule[12] = 'caticonenable';
598
+ proModule[13] = 'custompostuitype';
599
+ proModule[14] = 'wpcustomfields';
600
+ proModule[15] = 'recommerce';
601
+ proModule[16] = 'automapping';
602
+ proModule[17] = 'utfsupport';
603
+
604
+
605
+ var warning_name = new Array();
606
+ warning_name['categories'] = 'Categories/Tags';
607
+ warning_name['customtaxonomy'] = 'Custom Taxonomy';
608
+ warning_name['eshop'] = 'Eshop';
609
+ warning_name['marketpress'] = 'Market Press Lite';
610
+ warning_name['woocommerce'] = 'WooCommerce';
611
+ warning_name['wpcommerce'] = 'WP e-Commerce';
612
+ warning_name['cctm'] = 'CCTM';
613
+ warning_name['types'] = 'Types';
614
+ warning_name['acf'] = 'ACF';
615
+ warning_name['Customerreviews'] = 'Customer Reviews';
616
+ warning_name['WP-Members'] = 'WP-Members';
617
+ warning_name['aioseo'] = 'All-in-SEO';
618
+ warning_name['yoastseo'] = 'Yoast SEO';
619
+ warning_name['caticonenable'] = 'Category Icons';
620
+ warning_name['custompostuitype'] = 'Custom Post Type UI';
621
+ warning_name['automapping'] = 'Auto Mapping';
622
+ warning_name['utfsupport'] = 'UTF Support';
623
+
624
+ var result = inArray(val, proModule);
625
+ if(result == true){
626
+
627
+ if(val == 'eshop' || val == 'wpcustomfields' || val == 'wpcommerce' || val == 'woocommerce' || val == 'marketpress'){
628
+ if(val == 'wpcommerce' || val == 'wpcustomfields') {
629
+ document.getElementById('wpcustomfieldstr').style.display = '';
630
+ } else {
631
+ document.getElementById('wpcustomfieldstr').style.display = '';
632
+ }
633
+ // document.getElementById('wpcustomfieldstr').style.display = 'none';
634
+ document.getElementById('nonerecommerce').checked = true;
635
+ }
636
+ if(val == 'cctm' || val == 'acf'){
637
+ document.getElementById('nonercustompost').checked = true;
638
+ }
639
+ if(val == 'aioseo' || val == 'yoastseo'){
640
+ document.getElementById('nonerseooption').checked = true;
641
+ }
642
+ if(val == 'caticonenable'){
643
+ document.getElementById('caticondisable').checked = true;
644
+ }
645
+ document.getElementById(val).checked = false;
646
+ document.getElementById('ShowMsg').style.display = "";
647
+ document.getElementById('warning-msg').innerHTML = warning_name[val]+' feature is available only for PRO!.';
648
+ jQuery('#ShowMsg').delay(7000).fadeOut();
649
+ }
650
+ }
651
+
652
+ function inArray(needle, haystack) {
653
+ var length = haystack.length;
654
+ for(var i = 0; i < length; i++) {
655
+ if(typeof haystack[i] == 'object') {
656
+ if(arrayCompare(haystack[i], needle)) {
657
+ return true;
658
+ }
659
+ } else {
660
+ if(haystack[i] == needle) {
661
+ return true;
662
+ }
663
+ }
664
+ }
665
+ return false;
666
+ }
667
+
668
+ function import_again(){
669
+ var get_current_url = document.getElementById('current_url').value;
670
+ window.location.assign(get_current_url);
671
+ }
672
+ function sendemail2smackers(){
673
+ // var useremail = document.getElementById('usermailid').value;
674
+ var message_content = document.getElementById('message').value;
675
+ var firstname = document.getElementById('firstname').value;
676
+ var lastname = document.getElementById('lastname').value;
677
+ if(message_content != '' && firstname != '' && lastname != '')
678
+ return true;
679
+ else
680
+ document.getElementById('showMsg').style.display = '';
681
+ document.getElementById('showMsg').innerHTML = '<p id="warning-msg" class="alert alert-warning">Fill all mandatory fields.</p>';
682
+ jQuery("#showMsg").fadeOut(10000);
683
+ return false;
684
+ }
685
+
686
+
687
+ function check_allnumeric(inputtxt)
688
+ {
689
+ var numbers = /^[0-9]+$/;
690
+ if(inputtxt.match(numbers))
691
+ {
692
+ return true;
693
+ }
694
+ else
695
+ {
696
+ if(inputtxt == '')
697
+ alert('Fill all mandatory fields.');
698
+ else
699
+ alert('Please enter numeric characters only');
700
+ return false;
701
+ }
702
+ }
703
+
704
+ function gotoback() {
705
+ var currentURL = document.getElementById('current_url').value;
706
+ var set_assigned_step = currentURL.replace("uploadfile","mapping_settings");
707
+ // window.location.assign(set_assigned_step);
708
+ }
709
+ function export_module(){
710
+ var get_selected_module = document.getElementsByName('export');
711
+ // alert(get_selected_module);
712
+ for (var i = 0, length = get_selected_module.length; i < length; i++) {
713
+ if (get_selected_module[i].checked) {
714
+ // do whatever you want with the checked radio
715
+ //alert(get_selected_module[i].value);
716
+ // only one radio can be logically checked, don't check the rest
717
+ //break;
718
+ return true;
719
+ }
720
+ }
721
+ showMapMessages('error', 'Please choose one module to export the records!');
722
+ return false;
723
+ }
724
+ function export_check(value) {
725
+ if( value == 'woocommerce' || value == 'wpcommerce' || value == 'marketpress' || value == 'users' || value == 'category' || value == 'tags' || value == 'customtaxonomy') {
726
+ document.getElementById(value).checked = false;
727
+ document.getElementById('ShowMsg').style.display = "";
728
+ value = value.toUpperCase();
729
+ document.getElementById('warning-msg').innerHTML = value+' Feature is available only for PRO!.';
730
+ jQuery('#ShowMsg').delay(7000).fadeOut();
731
+ }
732
+ }
733
+ function choose_import_method(id) {
734
+ if(id == 'uploadfilefromcomputer') {
735
+ document.getElementById('boxmethod1').style.border = "1px solid #ccc";
736
+ document.getElementById('method1').style.display = '';
737
+ document.getElementById('method1').style.height = '40px';
738
+ }
739
+ }
740
+ function choose_import_mode(id) {
741
+ if(id == 'importNow') {
742
+ document.getElementById('importrightaway').style.display='';
743
+ document.getElementById('reportLog').style.display='';
744
+ document.getElementById('schedule').style.display='none';
745
+ }
746
+ if(id == 'scheduleNow') {
747
+ document.getElementById('schedule').style.display='';
748
+ document.getElementById('importrightaway').style.display='none';
749
+ document.getElementById('reportLog').style.display='none';
750
+ }
751
+ }
752
+ function selectModules(id) {
753
+ var param = id ;
754
+ if(param == 'checkallModules') {
755
+ document.getElementById('post').checked = true;
756
+ document.getElementById('page').checked = true;
757
+ document.getElementById('users').checked = true;
758
+ document.getElementById('comments').checked = true;
759
+ document.getElementById('custompost').checked = true;
760
+ }
761
+ else if(param == 'uncheckallModules') {
762
+
763
+ document.getElementById('post').checked = false;
764
+ document.getElementById('page').checked = false;
765
+ document.getElementById('users').checked = false;
766
+ document.getElementById('comments').checked = false;
767
+ document.getElementById('custompost').checked = false;
768
+ }
769
+ }
770
+
lib/jquery-plugins/index.php ADDED
File without changes
modules/export/templates/export_old.php ADDED
@@ -0,0 +1,1400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /******************************************************************************************
3
+ * Copyright (C) Smackcoders 2014 - All Rights Reserved
4
+ * Unauthorized copying of this file, via any medium is strictly prohibited
5
+ * Proprietary and confidential
6
+ * You can contact Smackcoders at email address info@smackcoders.com.
7
+ *******************************************************************************************/
8
+
9
+ require_once('../../../../../../wp-load.php');
10
+ $ExportObj = new WPCSVProExportData();
11
+ #print('<pre>'); print_r($_POST); //die;
12
+ $ExportObj->executeIndex($_POST);
13
+ class WPCSVProExportData {
14
+ public function __construct() {
15
+
16
+ }
17
+
18
+ /**
19
+ * The actions index method
20
+ * @param array $request
21
+ * @return array
22
+ */
23
+ public function executeIndex($request) {
24
+ #print('<pre>'); print_r($request); print('</pre>'); die;
25
+ if($request['export'] == 'category') {
26
+ $this->WPImpExportCategories($request);
27
+ }
28
+ else if($request['export'] == 'tags') {
29
+ $this->WPImpExportTags($request);
30
+ }
31
+ else if($request['export'] == 'customtaxonomy') {
32
+ $this->WPImpExportTaxonomies($request);
33
+ }
34
+ else if($request['export'] == 'customerreviews') {
35
+ $this->WPImpExportCustomerReviews($request);
36
+ }
37
+ else if($request['export'] == 'comments') {
38
+ $this->WPImpExportComments($request);
39
+ }
40
+ else if($request['export'] == 'users') {
41
+ $this->WPImpExportUsers($request);
42
+ }
43
+ else {
44
+ $this->WPImpPROExportData($request);#die;
45
+ }
46
+ }
47
+
48
+ /**
49
+ *
50
+ */
51
+ public function generateCSVHeaders($exporttype){
52
+ global $wpdb;
53
+ $post_type = $exporttype;
54
+ $unwantedHeader = array('_eshop_product', '_wp_attached_file', '_wp_page_template', '_wp_attachment_metadata', '_encloseme');
55
+ if($exporttype == 'woocommerce' || $exporttype == 'marketpress')
56
+ $post_type = 'product';
57
+ if($exporttype == 'wpcommerce')
58
+ $post_type = 'wpsc-product';
59
+ if($exporttype == 'eshop')
60
+ $post_type = 'post';
61
+ if($exporttype == 'custompost') {
62
+ $post_type = $_POST['export_post_type'];
63
+ }
64
+ $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$post_type'";
65
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') and meta_key NOT LIKE 'field_%' and meta_key NOT LIKE '_wp_types%'";
66
+ $result_header_query1 = $wpdb->get_results($header_query1);
67
+ $result_header_query2 = $wpdb->get_results($header_query2);
68
+
69
+ foreach ($result_header_query1 as $rhq1_key) {
70
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
71
+ if (!in_array($rhq1_headkey, $Header))
72
+ $Header[] = $rhq1_headkey;
73
+ }
74
+ }
75
+ foreach($this->getACFvalues() as $acfKey => $acfVal) {
76
+ $unwantedHeader[] = '_' . $acfKey;
77
+ }
78
+ foreach($this->getACFvalues() as $acfKey => $acfVal) {
79
+ if(!in_array($acfKey, $unwantedHeader)) {
80
+ $Header[] = $acfKey;
81
+ $unwantedHeader[] = $acfKey;
82
+ }
83
+ }
84
+ foreach($this->getTypesFields() as $typeKey => $typeVal) {
85
+ if(!in_array($typeKey, $unwantedHeader)) {
86
+ $Header[] = $typeVal;
87
+ $unwantedHeader[] = $typeKey;
88
+ }
89
+ }
90
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
91
+ $Header[] = $aioseoval;
92
+ $unwantedHeader[] = $aioseokey;
93
+ }
94
+ foreach($this->getYoastSEOfields() as $yoastseokey => $yoastseoval) {
95
+ $Header[] = $yoastseoval;
96
+ $unwantedHeader[] = $yoastseokey;
97
+ }
98
+ foreach ($result_header_query2 as $rhq2_headkey) {
99
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
100
+ if(!in_array($rhq2_headkey->meta_key, $unwantedHeader)) {
101
+ $Header[] = $rhq2_headkey->meta_key;
102
+ }
103
+ }
104
+ }
105
+
106
+ #print('<pre>'); print_r($Header); die;
107
+ if($exporttype == 'woocommerce' || $exporttype == 'marketpress' || $exporttype == 'wpcommerce' || $exporttype == 'eshop') {
108
+ if($exporttype == 'woocommerce') {
109
+ foreach($this->WoocommerceMetaHeaders() as $woo_hkey => $woo_hval) {
110
+ if(in_array($woo_hval, $Header))
111
+ $ProHeader[] = $woo_hkey;
112
+ else
113
+ $ProHeader[] = $woo_hkey;
114
+ }
115
+ }
116
+ else if($exporttype == 'marketpress') {
117
+ foreach($this->MarketPressHeaders() as $mp_hkey => $mp_hval) {
118
+ if(in_array($mp_hval, $Header))
119
+ $ProHeader[] = $mp_hkey;
120
+ else
121
+ $ProHeader[] = $mp_hkey;
122
+ }
123
+ }
124
+ else if($exporttype == 'wpcommerce') {
125
+ foreach($this->WpeCommerceHeaders() as $wpcom_hkey => $wpcom_hval) {
126
+ if(in_array($wpcom_hval, $Header))
127
+ $ProHeader[] = $wpcom_hkey;
128
+ else
129
+ $ProHeader[] = $wpcom_hkey;
130
+ }
131
+ }
132
+ else if($exporttype == 'eshop') {
133
+ foreach($this->EshopHeaders() as $eshop_hkey => $eshop_hval) {
134
+ if(in_array($eshop_hval, $Header))
135
+ $ProHeader[] = $eshop_hkey;
136
+ else
137
+ $ProHeader[] = $eshop_hkey;
138
+ }
139
+ }
140
+ foreach($this->getACFvalues() as $acfKey => $acfVal) {
141
+ if(!in_array($acfKey, $unwantedHeader)) {
142
+ $ProHeader[] = $acfKey;
143
+ }
144
+ }
145
+ foreach($this->getTypesFields() as $typeKey => $typeVal) {
146
+ if(!in_array($typeKey, $unwantedHeader)) {
147
+ $ProHeader[] = $typeVal;
148
+ }
149
+ }
150
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
151
+ $ProHeader[] = $aioseoval;
152
+ }
153
+ foreach($this->getYoastSEOfields() as $yoastseokey => $yoastseoval) {
154
+ $ProHeader[] = $yoastseoval;
155
+ }
156
+ $ProHeader[] = 'featured_image';
157
+ return $ProHeader;
158
+ }
159
+ $Header[] = 'featured_image';
160
+ return $Header;
161
+ }
162
+
163
+ /**
164
+ *
165
+ */
166
+ public function get_all_record_ids($exporttype, $request) {
167
+ global $wpdb;
168
+ $post_type = $exporttype;
169
+ $get_post_ids = "select DISTINCT ID from $wpdb->posts p join $wpdb->postmeta pm on pm.post_id = p.ID";
170
+ if($post_type == 'woocommerce' || $post_type == 'marketpress')
171
+ $post_type = 'product';
172
+ if($post_type == 'wpcommerce')
173
+ $post_type = 'wpsc-product';
174
+ if($post_type == 'eshop')
175
+ $post_type = 'post';
176
+ if($post_type == 'custompost')
177
+ $post_type = $_POST['export_post_type'];
178
+
179
+ $get_post_ids .= " where p.post_type = '$post_type'";
180
+ if(isset($request['getdatawithspecificstatus'])) {
181
+ if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'All') {
182
+ $get_post_ids .= " and p.post_status in ('publish','draft','future','private','pending')";
183
+ } else if(isset($request['postwithstatus']) && ($request['postwithstatus'] == 'Publish' || $request['postwithstatus'] == 'Sticky')) {
184
+ $get_post_ids .= " and p.post_status in ('publish')";
185
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Draft') {
186
+ $get_post_ids .= " and p.post_status in ('draft')";
187
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Scheduled') {
188
+ $get_post_ids .= " and p.post_status in ('future')";
189
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Private') {
190
+ $get_post_ids .= " and p.post_status in ('private')";
191
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Pending') {
192
+ $get_post_ids .= " and p.post_status in ('pending')";
193
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Protected') {
194
+ $get_post_ids .= " and p.post_status in ('publish') and post_password != ''";
195
+ }
196
+ } else {
197
+ $get_post_ids .= " and p.post_status in ('publish','draft','future','private','pending')";
198
+ }
199
+ if(isset($request['getdataforspecificperiod'])) {
200
+ $get_post_ids .= " and p.post_date >= '" . $request['postdatefrom'] . "' and p.post_date <= '" . $request['postdateto'] . "'";
201
+ }
202
+ if($exporttype == 'eshop')
203
+ $get_post_ids .= " and pm.meta_key = 'sku'";
204
+ if($post_type == 'woocommerce')
205
+ $get_post_ids .= " and pm.meta_key = '_sku'";
206
+ if($post_type == 'marketpress')
207
+ $get_post_ids .= " and pm.meta_key = 'mp_sku'";
208
+ if($post_type == 'wpcommerce')
209
+ $get_post_ids .= " and pm.meta_key = '_wpsc_sku'";
210
+
211
+ /* if($exporttype == 'woocommerce') {
212
+ $post_type = 'product';
213
+ $get_post_ids = "select DISTINCT ID from $wpdb->posts p join $wpdb->postmeta pm on pm.post_id = p.ID where post_type = '$post_type' and post_status in ('publish','draft','future','private','pending') and pm.meta_key = '_sku'";
214
+ } */
215
+ if(isset($request['getdatabyspecificauthors'])) {
216
+ if(isset($request['postauthor']) && $request['postauthor'] != 0) {
217
+ $get_post_ids .= " and p.post_author = {$request['postauthor']}";
218
+ }
219
+ }
220
+ #print_r($get_post_ids); die;
221
+ $result = $wpdb->get_col($get_post_ids);
222
+ if(isset($request['getdatawithspecificstatus'])) {
223
+ if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Sticky') {
224
+ $get_sticky_posts = get_option('sticky_posts');
225
+ foreach($get_sticky_posts as $sticky_post_id) {
226
+ if(in_array($sticky_post_id, $result))
227
+ $sticky_posts[] = $sticky_post_id;
228
+ }
229
+ return $sticky_posts;
230
+ }
231
+ }
232
+ #print_r($get_sticky_posts);
233
+ #print_r($result);die;
234
+ return $result;
235
+ }
236
+
237
+ /**
238
+ *
239
+ */
240
+ public function getPostDatas($postID) {
241
+ global $wpdb;
242
+ $query1 = "SELECT wp.* FROM $wpdb->posts wp where ID=$postID";
243
+ $result_query1 = $wpdb->get_results($query1);
244
+ if (!empty($result_query1)) {
245
+ foreach ($result_query1 as $posts) {
246
+ foreach ($posts as $post_key => $post_value) {
247
+ if ($post_key == 'post_status') {
248
+ if (is_sticky($postID)) {
249
+ $PostData[$post_key] = 'Sticky';
250
+ $post_status = 'Sticky';
251
+ } else {
252
+ $PostData[$post_key] = $post_value;
253
+ $post_status = $post_value;
254
+ }
255
+ } else {
256
+ $PostData[$post_key] = $post_value;
257
+ }
258
+ if ($post_key == 'post_password') {
259
+ if ($post_value) {
260
+ $PostData['post_status'] = "{" . $post_value . "}";
261
+ } else {
262
+ $PostData['post_status'] = $post_status;
263
+ }
264
+ }
265
+ if ($post_key == 'comment_status') {
266
+ if ($post_value == 'closed') {
267
+ $PostData['comment_status'] = 0;
268
+ }
269
+ if ($post_value == 'open') {
270
+ $PostData['comment_status'] = 1;
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+ return $PostData;
277
+ }
278
+
279
+ /**
280
+ *
281
+ */
282
+ public function getPostMetaDatas($postID) {
283
+ global $wpdb;
284
+ $query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
285
+ #print($query2); print('<br>');
286
+ $result = $wpdb->get_results($query2);
287
+ return $result;
288
+ }
289
+
290
+ /**
291
+ *
292
+ */
293
+ public function getTypesFields() {
294
+ $wptypesfields = get_option('wpcf-fields');
295
+ #print('<pre>'); print_r($wptypesfields);
296
+ foreach($wptypesfields as $typeFkey){
297
+ $typesfields[$typeFkey['meta_key']] = $typeFkey['name'];
298
+ }
299
+ #print_r($typesfields);
300
+ return $typesfields;
301
+ }
302
+
303
+ /**
304
+ *
305
+ */
306
+ public function getACFvalues($getspecificfieldtype = null) {
307
+ global $wpdb;
308
+ // Code for ACF fields
309
+ $get_acf_fields = $wpdb->get_col ( "SELECT meta_value FROM $wpdb->postmeta
310
+ GROUP BY meta_key
311
+ HAVING meta_key LIKE 'field_%'
312
+ ORDER BY meta_key" );
313
+
314
+ foreach ( $get_acf_fields as $acf_value ){
315
+ $get_acf_field = unserialize($acf_value);
316
+ $acf_fields[$get_acf_field['name']] = "CF: ".$get_acf_field['name'];
317
+ $acf_fields_slug[$get_acf_field['name']] = "_".$get_acf_field['name'];
318
+
319
+ if($get_acf_field['type'] == 'checkbox'){
320
+ $checkbox_option_fields[] = $get_acf_field['name'];
321
+ }
322
+ } // Code ends here
323
+ if($getspecificfieldtype == 'checkbox')
324
+ return $checkbox_option_fields;
325
+ else
326
+ return $acf_fields;
327
+ }
328
+
329
+
330
+ /**
331
+ *
332
+ */
333
+ public function getAIOSEOfields() {
334
+ $aioseofields = array('_aioseop_keywords' => 'seo_keywords',
335
+ '_aioseop_description' => 'seo_description',
336
+ '_aioseop_title' => 'seo_title',
337
+ '_aioseop_noindex' => 'seo_noindex',
338
+ '_aioseop_nofollow' => 'seo_nofollow',
339
+ '_aioseop_disable' => 'seo_disable',
340
+ '_aioseop_disable_analytics' => 'seo_disable_analytics',
341
+ '_aioseop_noodp' => 'seo_noodp',
342
+ '_aioseop_noydir' => 'seo_noydir',);
343
+ return $aioseofields;
344
+ }
345
+
346
+ /**
347
+ *
348
+ */
349
+ public function getYoastSEOfields () {
350
+ $yoastseofields = array('_yoast_wpseo_focuskw' => 'focus_keyword',
351
+ '_yoast_wpseo_title' => 'title',
352
+ '_yoast_wpseo_metadesc' => 'meta_desc',
353
+ '_yoast_wpseo_meta-robots-noindex' => 'meta-robots-noindex',
354
+ '_yoast_wpseo_meta-robots-nofollow' => 'meta-robots-nofollow',
355
+ '_yoast_wpseo_meta-robots-adv' => 'meta-robots-adv',
356
+ '_yoast_wpseo_sitemap-include' => 'sitemap-include',
357
+ '_yoast_wpseo_sitemap-prio' => 'sitemap-prio',
358
+ '_yoast_wpseo_canonical' => 'canonical',
359
+ '_yoast_wpseo_redirect' => 'redirect',
360
+ '_yoast_wpseo_opengraph-description' => 'opengraph-description',
361
+ '_yoast_wpseo_google-plus-description' => 'google-plus-description',
362
+ );
363
+ return $yoastseofields;
364
+ }
365
+
366
+ /**
367
+ *
368
+ */
369
+ public function getAllTerms($postID, $type) {
370
+ // Tags & Categories
371
+ if($type == 'woocommerce' || $type == 'marketpress') {
372
+ $exporttype = 'product';
373
+ $postTags = $postCategory = '';
374
+ $taxonomies = get_object_taxonomies($exporttype);
375
+ $get_tags = get_the_terms( $postID, 'product_tag' );
376
+ if($get_tags){
377
+ foreach($get_tags as $tags){
378
+ $postTags .= $tags->name.',';
379
+ }
380
+ }
381
+ $postTags = substr($postTags,0,-1);
382
+ $TermsData['product_tag'] = $postTags;
383
+ foreach ($taxonomies as $taxonomy) {
384
+ if($taxonomy == 'product_cat' || $taxonomy == 'product_category'){
385
+ $get_categotries =wp_get_post_terms( $postID, $taxonomy );
386
+ if($get_categotries){
387
+ foreach($get_categotries as $category){
388
+ $postCategory .= $category->name.'|';
389
+ }
390
+ }
391
+ $postCategory = substr($postCategory, 0 , -1);
392
+ $TermsData['product_category'] = $postCategory;
393
+ }
394
+ }
395
+ } else if($type == 'wpcommerce') {
396
+ $exporttype = 'wpsc-product';
397
+ $postTags = $postCategory = '';
398
+ $taxonomies = get_object_taxonomies($exporttype);
399
+ $get_tags = get_the_terms( $postID, 'product_tag' );
400
+ if($get_tags){
401
+ foreach($get_tags as $tags){
402
+ $postTags .= $tags->name.',';
403
+ }
404
+ }
405
+ $postTags = substr($postTags,0,-1);
406
+ $TermsData['product_tag'] = $postTags;
407
+ foreach ($taxonomies as $taxonomy) {
408
+ if($taxonomy == 'wpsc_product_category'){
409
+ $get_categotries =wp_get_post_terms( $postID, $taxonomy );
410
+ if($get_categotries){
411
+ foreach($get_categotries as $category){
412
+ $postCategory .= $category->name.'|';
413
+ }
414
+ }
415
+ $postCategory = substr($postCategory, 0 , -1);
416
+ $TermsData['product_category'] = $postCategory;
417
+ }
418
+ }
419
+ } else {
420
+ $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
421
+ $postTags = $postCategory = '';
422
+ foreach ($get_tags as $tags) {
423
+ $postTags .= $tags . ',';
424
+ }
425
+ $postTags = substr($postTags, 0, -1);
426
+ $TermsData['post_tag'] = $postTags;
427
+ $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
428
+ foreach ($get_categotries as $category) {
429
+ $postCategory .= $category . '|';
430
+ }
431
+ $postCategory = substr($postCategory, 0, -1);
432
+ $TermsData['post_category'] = $postCategory;
433
+ }
434
+ #print('<pre>'); print_r($TermsData); die;
435
+ return $TermsData;
436
+ }
437
+
438
+ /**
439
+ *
440
+ */
441
+ public function MarketPressHeaders() {
442
+ $marketpressHeaders = array('product_title' => 'post_title', 'product_content' => 'post_content', 'product_excerpt' => 'post_excerpt', 'product_publish_date' => 'post_date', 'product_slug' => 'post_name', 'product_status' => 'post_status', 'product_parent' => 'post_parent', 'comment_status' => 'open', 'ping_status' => 'open', 'variation' => 'mp_var_name', 'SKU' => 'mp_sku', 'regular_price' => 'mp_price', 'is_sale' => 'mp_is_sale', 'sale_price' => 'mp_sale_price', 'track_inventory' => 'mp_track_inventory', 'inventory' => 'mp_inventory', 'track_limit' => 'mp_track_limit', 'limit_per_order' => 'mp_limit', 'product_link' => 'mp_product_link', 'is_special_tax' => 'mp_is_special_tax', 'special_tax' => 'mp_special_tax', 'sales_count' => 'mp_sales_count', 'extra_shipping_cost' => 'mp_shipping', 'file_url' => 'mp_file', 'product_category' => 'post_category', 'product_tag' => 'post_tag', 'featured_image' => 'featured_image',);
443
+ return $marketpressHeaders;
444
+ }
445
+
446
+ /**
447
+ *
448
+ */
449
+ public function WpeCommerceHeaders() {
450
+ $wpecommerceHeaders = array('post_date' => 'post_date', 'post_content' => 'post_content', 'post_title' => 'post_title', 'post_excerpt' => 'post_excerpt', 'post_name' => 'post_name', 'stock' => '_wpsc_stock', 'price' => '_wpsc_price', 'sale_price' => '_wpsc_special_price', 'SKU' => '_wpsc_sku', 'product_tags' => 'product_tag', 'product_category' => null, 'featured_image' => 'featured_image', 'custom_meta' => null, 'wpsc_is_donation' => '_wpsc_is_donation', 'notify_when_none_left' => 'notify_when_none_left', 'unpublish_when_none_left' => 'unpublish_when_none_left', 'taxable_amount' => 'wpec_taxes_taxable_amount', 'is_taxable' => 'wpec_taxes_taxable', 'external_link' => 'external_link', 'external_link_text' => 'external_link_text', 'external_link_target' => 'external_link_target', 'no_shipping' => 'no_shipping', 'weight' => 'weight', 'weight_unit' => 'weight_unit', 'height' => 'height', 'height_unit' => 'height_unit', 'width' => 'width', 'width_unit' => 'width_unit', 'length' => 'length', 'length_unit' => 'length_unit', 'dimension_unit' => null, 'shipping' => 'shipping', 'merchant_notes' => 'merchant_notes', 'enable_comments' => 'enable_comments', 'quantity_limited' => 'quantity_limited', 'special' => 'special', 'display_weight_as' => 'display_weight_as', 'state' => 'state', 'quantity' => 'quantity', 'table_price' => 'table_price', 'google_prohibited' => 'google_prohibited',);
451
+ return $wpecommerceHeaders;
452
+ }
453
+
454
+ /**
455
+ *
456
+ */
457
+ public function WoocommerceMetaHeaders() {
458
+ $woocomHeaders = array('product_publish_date' => 'post_date', 'product_content' => 'post_content', 'product_name' => 'post_title', 'product_short_description' => 'post_excerpt', 'product_slug' => 'post_name', 'post_parent' => 0, 'product_category' => 'post_category', 'product_tag' => 'post_tag', 'post_type' => null, 'product_type' => '_product_type', 'product_shipping_class' => '_product_shipping_class', 'product_status' => 'post_status', 'visibility' => '_visibility', 'tax_status' => '_tax_status', 'product_attribute_name' => '_product_attribute_name', 'product_attribute_value' => '_product_attribute_value', 'product_attribute_visible' => '_product_attribute_visible', 'product_attribute_variation' => '_product_attribute_variation', 'featured_image' => null, 'product_attribute_taxonomy' => '_product_attribute_taxonomy', 'tax_class' => '_tax_class', 'file_paths' => '_file_paths', 'comment_count' => null, 'menu_order' => 0, 'comment_status'=> null, 'edit_last' => null, 'edit_lock' => null, 'thumbnail_id' => null, 'visibility' => '_visibility', 'stock_status' => '_stock_status', 'stock_qty' => '_stock', 'total_sales' => null, 'downloadable' => 'downloadable', 'downloadable_files' => '_downloadable_files', 'virtual' => '_virtual', 'regular_price' => '_regular_price', 'sale_price' => '_sale_price', 'purchase_note' => null, 'featured_product' => '_featured', 'weight' => null, 'length' => null, 'width' => null, 'height' => null, 'sku' => '_sku', 'upsell_ids' => '_upsell_ids', 'crosssell_ids' => '_crosssell_ids', 'sale_price_dates_from' => '_sale_price_dates_from', 'sale_price_dates_to' => '_sale_price_dates_to', 'price' => null,'sold_individually' => '_price', 'manage_stock' => '_manage_stock', 'backorders' => '_backorders', 'product_image_gallery' => '__product_image_gallery', 'product_url' => '_product_url', 'button_text' => '_button_text', 'downloadable_files' => null, 'download_limit' => '_download_limit', 'download_expiry' => '_download_expiry', 'download_type'=> null, 'min_variation_price' => null, 'max_variation_price'=> null, 'min_price_variation_id' => null, 'max_price_variation_id' => null, 'min_variation_regular_price' => null, 'max_variation_regular_price' => null, 'min_regular_price_variation_id' => null, 'max_regular_price_variation_id' => null, 'min_variation_sale_price' => null, 'max_variation_sale_price' => null, 'min_sale_price_variation_id' => null, 'max_sale_price_variation_id' => null, 'default_attributes' => null,);
459
+ return $woocomHeaders;
460
+ }
461
+
462
+ /**
463
+ *
464
+ */
465
+ public function EshopHeaders() {
466
+ $eshopHeaders = array('post_title' => 'post_title', 'post_content' => 'post_content', 'post_excerpt' => 'post_excerpt', 'post_date' => 'post_date', 'post_name' => 'post_name', 'post_status' => 'post_status', 'post_author' => 'post_author', 'post_parent' => 0, 'comment_status' => 'open', 'ping_status' => 'open', 'SKU' => 'sku', 'products_option' => 'products_option', 'sale_price' => 'sale_price', 'regular_price' => 'regular_price', 'description' => 'description', 'shiprate' => 'shiprate', 'optset' => null, 'featured_product' => 'featured', 'product_in_sale' => '_eshop_sale', 'stock_available' => '_eshop_stock', 'cart_option' => 'cart_radio', 'category' => 'post_category', 'tags' => 'post_tag', 'featured_image' => null,);
467
+ return $eshopHeaders;
468
+ }
469
+
470
+ /**
471
+ * @param $request
472
+ * @return array
473
+ */
474
+ public function WPImpPROExportData($request) {
475
+ #print('<pre>'); print_r($this->getACFvalues()); die;
476
+ global $wpdb;
477
+ $export_delimiter = ',';
478
+ $exporttype = $_POST['export'];
479
+ $wpcsvsettings=get_option('wpcsvprosettings');
480
+ if(isset($wpcsvsettings['export_delimiter'])){
481
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
482
+ }
483
+ if($_POST['export_filename'])
484
+ $csv_file_name =$_POST['export_filename'].'.csv';
485
+ else
486
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
487
+ $wptypesfields = get_option('wpcf-fields');
488
+ #print('<pre>'); print_r($wptypesfields); die;
489
+ #print('<pre>'); print_r($_POST); print('</pre>');
490
+ //if($exporttype=='post' || $exporttype=='page' || $exporttype=='custompost') {
491
+ if($exporttype == 'custompost') {
492
+ $exporttype = $_POST['export_post_type'];
493
+ }
494
+ $Header = $this->generateCSVHeaders($exporttype);
495
+ $result = $this->get_all_record_ids($exporttype, $request);
496
+ #print('<pre>'); print_r($Header); print_r($result); print('</pre>'); die;
497
+ $fieldsCount = count($result);
498
+ if ($result) {
499
+ foreach ($result as $postID) {
500
+ $pId = $pId . ',' . $postID;
501
+ $PostData[$postID] = $this->getPostDatas($postID);
502
+ #print('<pre>'); print_r($PostData); #die;
503
+ $result_query2 = $this->getPostMetaDatas($postID);
504
+ #print('<pre>'); print_r($result_query2); print('</pre>'); #die;
505
+
506
+ $possible_values = array('s:', 'a:', ':{');
507
+ if (!empty($result_query2)) {
508
+ foreach ($result_query2 as $postmeta) {
509
+ $typesFserialized = 0;
510
+ $isFound = explode('wpcf-',$postmeta->meta_key);
511
+ if(count($isFound) == 2){
512
+ foreach($wptypesfields as $typesKey => $typesVal){
513
+ if($postmeta->meta_key == 'wpcf-'.$typesKey){
514
+ foreach($possible_values as $posval){
515
+ if(strpos($postmeta->meta_value,$posval)){
516
+ $typesFserialized = 1;
517
+ } else {
518
+ $typesFserialized = 0;
519
+ }
520
+ }
521
+ if($typesFserialized == 1){
522
+ $getMetaData = get_post_meta($postID, $postmeta->meta_key);
523
+ if(!is_array($getMetaData[0])){
524
+ $get_all_values = unserialize($getMetaData[0]);
525
+ $get_values = $get_all_values[0];
526
+ } else {
527
+ $get_values = $getMetaData[0];
528
+ }
529
+ $typesFVal = null;
530
+ if($typesVal['type'] == 'checkboxes'){
531
+ foreach($get_values as $authorKey => $authorVal) {
532
+ foreach($typesVal['data']['options'] as $doKey => $doVal){
533
+ if($doKey == $authorKey)
534
+ $typesFVal .= $doVal['title'].',';
535
+ }
536
+ }
537
+ $typesFVal = substr($typesFVal, 0, -1);
538
+ } elseif($typesVal['type'] == 'skype') {
539
+ $typesFVal = $get_values['skypename'];
540
+ }
541
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $typesFVal;
542
+ } else {
543
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
544
+ }
545
+ }
546
+ }
547
+ } else {
548
+ // ACF checkbox fields
549
+ $acfserialized = 0;
550
+ if(array_key_exists($postmeta->meta_key, $this->getACFvalues())) {
551
+ foreach($possible_values as $posval){
552
+ if(strpos($postmeta->meta_value,$posval)){
553
+ $acfserialized = 1;
554
+ } else {
555
+ $acfserialized = 0;
556
+ }
557
+ }
558
+ if($acfserialized == 0) {
559
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
560
+ } else {
561
+ $acf_checkboxes = $this->getACFvalues('checkbox');
562
+ if(in_array($postmeta->meta_key, $acf_checkboxes)) {
563
+ $get_all_values = unserialize($postmeta->meta_value);
564
+ foreach($get_all_values as $optKey => $optVal) {
565
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $optVal . ',';
566
+ }
567
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
568
+ }
569
+ }
570
+ }
571
+ // ACF checkbox fields ends here
572
+ // WooCommerce product meta datas
573
+ else if ($postmeta->meta_key == '_product_attributes') {
574
+ #print_r($postmeta->meta_value); #die;
575
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
576
+ $product_attribute_name = $product_attribute_value = $product_attribute_visible = $product_attribute_variation = '';
577
+ $PostMetaData[$postmeta->post_id]['_product_attribute_name'] = '';
578
+ $PostMetaData[$postmeta->post_id]['_product_attribute_value'] = '';
579
+ $PostMetaData[$postmeta->post_id]['_product_attribute_visible'] = '';
580
+ $PostMetaData[$postmeta->post_id]['_product_attribute_variation'] = '';
581
+ $eshop_products_unser1 = unserialize($postmeta->meta_value);
582
+ $check_attr_count1 = count($eshop_products_unser1);
583
+ if($check_attr_count1 == 1){
584
+ $eshop_products_unser2 = unserialize($eshop_products_unser1);
585
+ $check_attr_count2 = count($eshop_products_unser2);
586
+ }
587
+ if($check_attr_count1 < $check_attr_count2){
588
+ $unserialized_attributes = $eshop_products_unser2;
589
+ }else{
590
+ $unserialized_attributes = $eshop_products_unser1;
591
+ }
592
+
593
+ foreach ($unserialized_attributes as $key) {
594
+ foreach($key as $attr_header => $attr_value){
595
+ if($attr_header == 'name')
596
+ $product_attribute_name .= $attr_value.'|';
597
+ if($attr_header == 'value')
598
+ $product_attribute_value .= $attr_value.'|';
599
+ if($attr_header == 'is_visible')
600
+ $product_attribute_visible .= $attr_value.'|';
601
+ if($attr_header == 'is_variation'){
602
+ if(isset($attr_value))
603
+ $product_attribute_variation .= $attr_value.'|';
604
+ }
605
+ }
606
+ }
607
+ $PostMetaData[$postmeta->post_id]['_product_attribute_name'] = substr($product_attribute_name, 0, -1);
608
+ $PostMetaData[$postmeta->post_id]['_product_attribute_value'] = substr($product_attribute_value, 0, -1);
609
+ $PostMetaData[$postmeta->post_id]['_product_attribute_visible'] = substr($product_attribute_visible, 0, -1);
610
+ $PostMetaData[$postmeta->post_id]['_product_attribute_variation'] = substr($product_attribute_variation, 0, -1);
611
+ #print('<pre>'); print_r($PostMetaData); die;
612
+ }
613
+ else if ($postmeta->meta_key == '_upsell_ids') {
614
+ $upsellids = array();
615
+ $crosssellids = array();
616
+ #print('<pre>'); print('VALUE for _upsell_ids: '); print_r($postmeta->meta_value); #print_r($PostMetaData); print('</pre>'); #die;
617
+ if($postmeta->meta_value != '' && $postmeta->meta_value != null) {
618
+ $upsellids = unserialize($postmeta->meta_value);
619
+ if(is_array($upsellids)){
620
+ foreach($upsellids as $upsellID){
621
+ $upsell_ids .= $upsellID.',';
622
+ }
623
+ $PostMetaData[$postmeta->post_id]['_upsell_ids'] = substr($upsell_ids, 0, -1);
624
+ }else{
625
+ $PostMetaData[$postmeta->post_id]['_upsell_ids'] = '';
626
+ }
627
+ #print('<pre>'); print('VALUE for _upsell_ids: '); print_r($postmeta->meta_value); print_r($PostMetaData);
628
+ }
629
+ }
630
+ #print('<pre>'); print('VALUE for _upsell_ids: '); print_r($postmeta->meta_value); print_r($PostMetaData); print('</pre>'); #die;
631
+ else if ($postmeta->meta_key == '_crosssell_ids') {
632
+ if($postmeta->meta_value != '' && $postmeta->meta_value != null) {
633
+ $crosssellids = unserialize($postmeta->meta_value);
634
+ if(is_array($crosssellids)){
635
+ foreach($crosssellids as $crosssellID){
636
+ $crosssell_ids .= $crosssellID.',';
637
+ }
638
+ $PostMetaData[$postmeta->post_id]['_crosssell_ids'] = substr($crosssell_ids, 0, -1);
639
+ }else{
640
+ $PostMetaData[$postmeta->post_id]['_crosssell_ids'] = '';
641
+ }
642
+ }
643
+ }
644
+ else if ($postmeta->meta_key == '_downloadable_files') {
645
+ if($postmeta->meta_value != '' && $postmeta->meta_value != null) {
646
+ $downloadable_files = unserialize($postmeta->meta_value);
647
+ if(is_array($downloadable_files)){
648
+ foreach($downloadable_files as $dkey => $dval){
649
+ $downloadable_key = $dkey;
650
+ foreach($dval as $down_key => $down_val) {
651
+ $downloadable_value .= $down_val . ',';
652
+ }
653
+ }
654
+ $downloadable_all .= $downloadable_key . ',' . $downloadable_value;
655
+ $PostMetaData[$postmeta->post_id]['_downloadable_files'] = substr($downloadable_all ,0, -1);
656
+ }else{
657
+ $PostMetaData[$postmeta->post_id]['_downloadable_files'] = '';
658
+ }
659
+ }
660
+ }
661
+ else if ($postmeta->meta_key == '_thumbnail_id') {
662
+ $attachment_file = '';
663
+ $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
664
+ $attachment = $wpdb->get_results($get_attachement);
665
+ $attachment_file = $attachment[0]->guid;
666
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
667
+ $postmeta->meta_key = 'featured_image';
668
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
669
+ }
670
+ else if ($postmeta->meta_key == '_visibility') {
671
+ if($postmeta->meta_value == 'visible')
672
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
673
+ if($postmeta->meta_value == 'catalog')
674
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
675
+ if($postmeta->meta_value == 'search')
676
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
677
+ if($postmeta->meta_value == 'hidden')
678
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 4;
679
+ }
680
+ else if ($postmeta->meta_key == '_stock_status') {
681
+ /*if($postmeta->meta_value == 'instock')
682
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
683
+ if($postmeta->meta_value == 'outofstock')
684
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;*/
685
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
686
+ }
687
+ else if ($postmeta->meta_key == '_tax_status') {
688
+ if($postmeta->meta_value == 'taxable')
689
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
690
+ if($postmeta->meta_value == 'shipping')
691
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
692
+ if($postmeta->meta_value == 'none')
693
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
694
+ }
695
+ else if ($postmeta->meta_key == '_tax_class') {
696
+ if($postmeta->meta_value == '')
697
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
698
+ if($postmeta->meta_value == 'reduced-rate')
699
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
700
+ if($postmeta->meta_value == 'zero-rate')
701
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
702
+ }
703
+ else if ($postmeta->meta_key == '_backorders') {
704
+ if($postmeta->meta_value == 'no')
705
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
706
+ if($postmeta->meta_value == 'notify')
707
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
708
+ if($postmeta->meta_value == 'yes')
709
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
710
+ }
711
+ else if ($postmeta->meta_key == '_featured') {
712
+ if($postmeta->meta_value == 'no')
713
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 1;
714
+ if($postmeta->meta_value == 'yes')
715
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 2;
716
+ if($postmeta->meta_value == 'zero-rate')
717
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 3;
718
+ }
719
+ else if ($postmeta->meta_key == '_product_type') {
720
+ if($postmeta->meta_value == 'simple')
721
+ $PostMetaData[$postmeta->post_id]['product_type'] = 1;
722
+ if($postmeta->meta_value == 'grouped')
723
+ $PostMetaData[$postmeta->post_id]['product_type'] = 2;
724
+ if($postmeta->meta_value == 'variable')
725
+ $PostMetaData[$postmeta->post_id]['product_type'] = 4;
726
+ }
727
+ /* else if($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
728
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
729
+ } */
730
+ #$eshop_products = $postmeta->meta_value;
731
+ else if ($postmeta->meta_key == 'products') {
732
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
733
+ $eshop_products = unserialize($eshop_products);
734
+ foreach ($eshop_products as $key) {
735
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key['option'] . '|' . $key['price'] . '|' . $key['saleprice'] . ',';
736
+ }
737
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
738
+ } // WooCommerce product meta datas end here
739
+ // MarketPress product meta datas starts here
740
+ else if ($postmeta->meta_key == 'mp_var_name') {
741
+ $mp_variations = null;
742
+ $all_variations = unserialize($postmeta->meta_value);
743
+ foreach($all_variations as $variation_name) {
744
+ $mp_variations .= $variation_name . ',';
745
+ }
746
+ $mp_variations = substr($mp_variations, 0, -1);
747
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_variations;
748
+ }
749
+ else if ($postmeta->meta_key == 'mp_sale_price') {
750
+ $mp_sale_prices = null;
751
+ $all_sale_prices = unserialize($postmeta->meta_value);
752
+ foreach($all_sale_prices as $mp_sale_price_value) {
753
+ $mp_sale_prices .= $mp_sale_price_value . ',';
754
+ }
755
+ $mp_sale_prices = substr($mp_sale_prices, 0, -1);
756
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_sale_prices;
757
+ }
758
+ else if ($postmeta->meta_key == 'mp_price') {
759
+ $mp_prod_prices = null;
760
+ $all_mp_prod_prices = unserialize($postmeta->meta_value);
761
+ foreach($all_mp_prod_prices as $mp_prod_price_value) {
762
+ $mp_prod_prices .= $mp_prod_price_value . ',';
763
+ }
764
+ $mp_prod_prices = substr($mp_prod_prices, 0, -1);
765
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_prod_prices;
766
+ }
767
+ else if ($postmeta->meta_key == 'mp_sku') {
768
+ $mp_sku = null;
769
+ $all_mp_prod_sku = unserialize($postmeta->meta_value);
770
+ foreach($all_mp_prod_sku as $mp_prod_sku) {
771
+ $mp_sku .= $mp_prod_sku. ',';
772
+ }
773
+ $mp_sku = substr($mp_sku, 0, -1);
774
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_sku;
775
+ }
776
+ else if ($postmeta->meta_key == 'mp_shipping') {
777
+ $mp_prod_shipping_value = unserialize($postmeta->meta_value);
778
+ $mp_shipping_value = $mp_prod_shipping_value['extra_cost'];
779
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_shipping_value;
780
+ }
781
+ else if ($postmeta->meta_key == 'mp_inventory') {
782
+ $mp_inventory_value = null;
783
+ $mp_prod_inventory_values = unserialize($postmeta->meta_value);
784
+ foreach($mp_prod_inventory_values as $inventory_values) {
785
+ $mp_inventory_value .= $inventory_values. ',';
786
+ }
787
+ $mp_inventory_value = substr($mp_inventory_value, 0, -1);
788
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $mp_inventory_value;
789
+ } // MarketPress product meta datas ends here
790
+ // WP e-Commerce product meta datas starts here
791
+ else if ($postmeta->meta_key == '_wpsc_product_metadata') {
792
+ $wpecomm_product_metadata = unserialize($postmeta->meta_value);
793
+ #print('<pre>'); print_r($wpecomm_product_metadata); die;
794
+ foreach($wpecomm_product_metadata as $prod_md_key => $prod_md_val) {
795
+ if($prod_md_key == 'dimensions') { #die('summa');
796
+ foreach($prod_md_val as $prod_dimen_key => $prod_dimen_val) {
797
+ $PostMetaData[$postmeta->post_id][$prod_dimen_key] = $prod_dimen_val;
798
+ }
799
+ }
800
+ else if($prod_md_key == 'shipping') {
801
+ $shipping = null;
802
+ foreach($prod_md_val as $prod_ship_key => $prod_ship_val) {
803
+ $shipping .= $prod_ship_val . ',';
804
+ }
805
+ $shipping = substr($shipping, 0, -1);
806
+ $PostMetaData[$postmeta->post_id][$prod_md_key] = $shipping;
807
+ }
808
+ else if($prod_md_key == 'table_rate_price') {
809
+ foreach($prod_md_val as $table_rate_key => $table_rate_val) {
810
+ if($table_rate_key == 'quantity') {
811
+ $trq_val = null;
812
+ foreach($table_rate_val as $trq) {
813
+ $trq_val .= $trq . '|';
814
+ }
815
+ $trq_val = substr($trq_val, 0, -1);
816
+ $PostMetaData[$postmeta->post_id][$table_rate_key] = $trq_val;
817
+ } else if($table_rate_key == 'table_price') {
818
+ $tbl_price_amt = null;
819
+ foreach($table_rate_val as $tbl_price) {
820
+ $tbl_price_amt .= $tbl_price . '|';
821
+ }
822
+ $tbl_price_amt = substr($tbl_price_amt, 0, -1);
823
+ $PostMetaData[$postmeta->post_id][$table_rate_key] = $tbl_price_amt;
824
+ } else {
825
+ $PostMetaData[$postmeta->post_id][$table_rate_key] = $table_rate_val;
826
+ }
827
+ }
828
+ }
829
+ else {
830
+ $PostMetaData[$postmeta->post_id][$prod_md_key] = $prod_md_val;
831
+ }
832
+ }
833
+ }
834
+ // Wp e-Commerce product meta datas ends here
835
+ // Eshop product meta datas starts here
836
+ else if ($postmeta->meta_key == 'featured') {
837
+ $isFeatured = strtolower($postmeta->meta_value);
838
+ $PostMetaData[$postmeta->post_id]['featured_product'] = $isFeatured;
839
+ }
840
+ else if ($postmeta->meta_key == 'sale') {
841
+ $is_prod_sale = strtolower($postmeta->meta_value);
842
+ $PostMetaData[$postmeta->post_id]['product_in_sale'] = $is_prod_sale;
843
+ }
844
+ else if ($postmeta->meta_key == '_eshop_stock') {
845
+ if($postmeta->meta_value == 1) {
846
+ $stock_available = 'yes';
847
+ } else {
848
+ $stock_available = 'no';
849
+ }
850
+ $PostMetaData[$postmeta->post_id]['stock_available'] = $stock_available;
851
+ }
852
+ else if ($postmeta->meta_key == 'cart_radio') {
853
+ $PostMetaData[$postmeta->post_id]['cart_option'] = $postmeta->meta_value;
854
+ }
855
+ else if ($postmeta->meta_key == 'shiprate') {
856
+ $PostMetaData[$postmeta->post_id]['shiprate'] = $postmeta->meta_value;
857
+ }
858
+ else if ($postmeta->meta_key == '_eshop_product') {
859
+ $product_attr_details = unserialize($postmeta->meta_value);
860
+ $prod_option = $sale_price = $reg_price = null;
861
+ #print('<pre>');print_r($product_attr_details); #die;
862
+ foreach($product_attr_details as $prod_att_det_Key => $prod_att_det_Val) {
863
+ if($prod_att_det_Key == 'sku') {
864
+ $PostMetaData[$postmeta->post_id]['sku'] = $prod_att_det_Val;
865
+ }
866
+ else if($prod_att_det_Key == 'products') {
867
+ foreach($prod_att_det_Val as $all_prod_options) {
868
+ $prod_option .= $all_prod_options['option'] . ',';
869
+ $sale_price .= $all_prod_options['saleprice'] . ',';
870
+ $reg_price .= $all_prod_options['price'] . ',';
871
+ }
872
+ $prod_option = substr($prod_option, 0, -1);
873
+ $sale_price = substr($sale_price, 0, -1);
874
+ $reg_price = substr($reg_price, 0, -1);
875
+ $PostMetaData[$postmeta->post_id]['products_option'] = $prod_option;
876
+ $PostMetaData[$postmeta->post_id]['sale_price'] = $sale_price;
877
+ $PostMetaData[$postmeta->post_id]['regular_price'] = $reg_price;
878
+ }
879
+ }
880
+ #$PostMetaData[$postmeta->post_id]['cart_option'] = $postmeta->meta_value;
881
+ }
882
+ // Eshop product meta datas ends here
883
+ else if ($postmeta->meta_key == '_thumbnail_id') {
884
+ $attachment_file = '';
885
+ $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
886
+ $attachment = $wpdb->get_results($get_attachement);
887
+ $attachment_file = $attachment[0]->guid;
888
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
889
+ $postmeta->meta_key = 'featured_image';
890
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
891
+ }
892
+ else if(is_array($checkbox_option_fields) && in_array($postmeta->meta_key,$checkbox_option_fields)){
893
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
894
+ $eshop_products = unserialize($eshop_products); //print_r($eshop_products);
895
+ foreach ($eshop_products as $key) {
896
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key . ',';
897
+ }
898
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
899
+ }
900
+ else {
901
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
902
+ }
903
+ }
904
+ }
905
+ }
906
+ # print('PostMetaData: '); print('<pre>'); print_r($Header); print_r($PostMetaData); #die;
907
+ $TermsData[$postID] = $this->getAllTerms($postID,$exporttype);
908
+ /*
909
+ // Tags & Categories
910
+ $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
911
+ $postTags = $postCategory = '';
912
+ foreach ($get_tags as $tags) {
913
+ $postTags .= $tags . ',';
914
+ }
915
+ $postTags = substr($postTags, 0, -1);
916
+ $TermsData[$postID]['post_tag'] = $postTags;
917
+ $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
918
+ foreach ($get_categotries as $category) {
919
+ $postCategory .= $category . '|';
920
+ }
921
+ $postCategory = substr($postCategory, 0, -1);
922
+ $TermsData[$postID]['post_category'] = $postCategory;
923
+ */
924
+ }
925
+
926
+ #$ExportData = array();
927
+ // Merge all arrays
928
+ #echo '<pre>'; print_r($TermsData); die;
929
+ // echo '<pre>'; print_r($PostData); die('sds');
930
+ foreach ($PostData as $pd_key => $pd_val) {
931
+ if (array_key_exists($pd_key, $PostMetaData)) {
932
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
933
+ // echo '<pre>'; print_r($ExportData); die('exist');
934
+ } else {
935
+ $ExportData[$pd_key] = $PostData[$pd_key];
936
+ }
937
+ if (array_key_exists($pd_key, $TermsData)) {
938
+ if (empty($ExportData[$pd_key]))
939
+ $ExportData[$pd_key] = array();
940
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
941
+ }
942
+ }
943
+ }
944
+ #print('<pre>'); print_r($Header); die;
945
+ #print('<pre>'); print_r($ExportData); die;
946
+ if($exporttype == 'woocommerce') {
947
+ foreach($Header as $hkey) {
948
+ foreach($ExportData as $edkey => $edval) {
949
+ /*if(array_key_exists($hkey, $this->getACFvalues())) {
950
+ $ExportData[$edkey][$hkey] = $edval[$hkey];
951
+ unset($ExportData[$edkey]['_'.$hkey]);
952
+ }
953
+ else if(in_array($hkey, $this->getAIOSEOfields())) {
954
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
955
+ $ExportData[$edkey][$aioseoval] = $edval[$aioseokey];
956
+ unset($ExportData[$edkey][$hkey]);
957
+ }
958
+ }
959
+ else if(array_key_exists('_'.$hkey, $edval)) {
960
+ $ExportData[$edkey][$hkey] = $edval['_'.$hkey];
961
+ unset($ExportData[$edkey]['_'.$hkey]);
962
+ } */
963
+ foreach($this->WoocommerceMetaHeaders() as $woohkey => $woohval) {
964
+ if(array_key_exists($woohval, $ExportData[$edkey])) {
965
+ $ExportData[$edkey][$woohkey] = $edval[$woohval];
966
+ unset($ExportData[$edkey][$woohval]);
967
+ }
968
+ }
969
+ }
970
+ }
971
+ }
972
+ # MarketPressHeaders
973
+ if($exporttype == 'marketpress') {
974
+ foreach($Header as $hkey) {
975
+ foreach($ExportData as $edkey => $edval) {
976
+ foreach($this->MarketPressHeaders() as $mphkey => $mphval) {
977
+ if(array_key_exists($mphval, $ExportData[$edkey])) {
978
+ $ExportData[$edkey][$mphkey] = $edval[$mphval];
979
+ // unset($ExportData[$edkey][$mphval]);
980
+ }
981
+ }
982
+ }
983
+ }
984
+ }
985
+ if($exporttype == 'wpcommerce') {
986
+ foreach($Header as $hkey) {
987
+ foreach($ExportData as $edkey => $edval) {
988
+ foreach($this->WpeCommerceHeaders() as $wpcomhkey => $wpcomhval) {
989
+ if(array_key_exists($wpcomhval, $ExportData[$edkey])) {
990
+ $ExportData[$edkey][$wpcomhkey] = $edval[$wpcomhval];
991
+ // unset($ExportData[$edkey][$wpcomhval]);
992
+ }
993
+ }
994
+ }
995
+ }
996
+ }
997
+ if($exporttype == 'eshop') {
998
+ foreach($Header as $hkey) {
999
+ foreach($ExportData as $edkey => $edval) {
1000
+ foreach($this->EshopHeaders() as $eshophkey => $eshophval) {
1001
+ if(array_key_exists($eshophval, $ExportData[$edkey])) {
1002
+ $ExportData[$edkey][$eshophkey] = $edval[$eshophval];
1003
+ // unset($ExportData[$edkey][$wpcomhval]);
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+ }
1009
+ #print('<pre>'); print_r($Header); print('</pre>'); #die;
1010
+ # print('<pre>'); print_r($ExportData); die;
1011
+ foreach ($Header as $header_key) {
1012
+ if (is_array($ExportData)) {
1013
+ foreach ($ExportData as $ED_key => $ED_val) {
1014
+ if (in_array($header_key, $this->getAIOSEOfields())) { #die($header_key);
1015
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
1016
+ $CSVContent[$ED_key][$aioseoval] = $ED_val[$aioseokey];
1017
+ #unset($CSVContent[$ED_key][$header_key]);
1018
+ }
1019
+ } else if (in_array($header_key, $this->getYoastSEOfields())) {
1020
+ foreach($this->getYoastSEOfields() as $yoastseokey => $yoastseoval) {
1021
+ $CSVContent[$ED_key][$yoastseoval] = $ED_val[$yoastseokey];
1022
+ #unset($CSVContent[$ED_key][$header_key]);
1023
+ }
1024
+ } else if (in_array($header_key, $this->getTypesFields())) {
1025
+ foreach($this->getTypesFields() as $typesFkey => $typesFval) {
1026
+ $CSVContent[$ED_key][$typesFval] = $ED_val[$typesFkey];
1027
+ #unset($CSVContent[$ED_key][$header_key]);
1028
+ }
1029
+ } else if (array_key_exists($header_key, $ED_val)) {
1030
+ $CSVContent[$ED_key][$header_key] = $ED_val[$header_key];
1031
+ } else {
1032
+ $CSVContent[$ED_key][$header_key] = null;
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ #print(count($CSVContent[22]));print('<br>' . count($Header));
1038
+ #print('<pre>'); print_r($CSVContent) ;print('</pre>'); die;
1039
+ $csv = new WPImpCSVParserLib();
1040
+ $csv->output ($csv_file_name, $CSVContent, $Header, $export_delimiter);
1041
+ }
1042
+
1043
+ /**
1044
+ *
1045
+ */
1046
+ public function WPImpExportCategories($request) {
1047
+ global $wpdb;
1048
+ $export_delimiter = ',';
1049
+ $exporttype = $request['export'];
1050
+ $wpcsvsettings=get_option('wpcsvprosettings');
1051
+ if(isset($wpcsvsettings['export_delimiter'])){
1052
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1053
+ }
1054
+ if($_POST['export_filename'])
1055
+ $csv_file_name =$_POST['export_filename'].'.csv';
1056
+ else
1057
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1058
+
1059
+ $Header[] = 'name';
1060
+ $Header[] = 'slug';
1061
+ $Header[] = 'description';
1062
+ $get_all_categories = get_categories('hide_empty=0');
1063
+ $fieldsCount = count($get_all_categories);
1064
+ foreach( $get_all_categories as $cateKey => $cateValue ) {
1065
+ $categID = $cateValue->term_id;
1066
+ $categName = $cateValue->cat_name;
1067
+ $categSlug = $cateValue->slug;
1068
+ $categDesc = $cateValue->category_description;
1069
+ $categParent = $cateValue->parent;
1070
+ if($categParent == 0) {
1071
+ $TERM_DATA[$categID]['name'] = $categName;
1072
+ } else {
1073
+ $categParentName = get_cat_name( $categParent );
1074
+ $TERM_DATA[$categID]['name'] = $categParentName . '|' . $categName;
1075
+ }
1076
+ $TERM_DATA[$categID]['slug'] = $categSlug;
1077
+ $TERM_DATA[$categID]['description'] = $categDesc;
1078
+ }
1079
+ $csv = new WPImpCSVParserLib();
1080
+ $csv->output ($csv_file_name, $TERM_DATA, $Header, $export_delimiter);
1081
+ }
1082
+
1083
+ /**
1084
+ *
1085
+ */
1086
+ public function WPImpExportTags($request) {
1087
+ global $wpdb;
1088
+ $export_delimiter = ',';
1089
+ $exporttype = $request['export'];
1090
+ $wpcsvsettings=get_option('wpcsvprosettings');
1091
+ if(isset($wpcsvsettings['export_delimiter'])){
1092
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1093
+ }
1094
+ if($_POST['export_filename'])
1095
+ $csv_file_name =$_POST['export_filename'].'.csv';
1096
+ else
1097
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1098
+
1099
+ $Header[] = 'name';
1100
+ $Header[] = 'slug';
1101
+ $Header[] = 'description';
1102
+ $get_all_tags = get_tags('hide_empty=0');
1103
+ $fieldsCount = count($get_all_tags);
1104
+ foreach( $get_all_tags as $tagKey => $tagValue ) {
1105
+ $tagID = $tagValue->term_id;
1106
+ $tagName = $tagValue->name;
1107
+ $tagSlug = $tagValue->slug;
1108
+ $tagDesc = $tagValue->description;
1109
+ $TERM_DATA[$tagID]['name'] = $tagName;
1110
+ $TERM_DATA[$tagID]['slug'] = $tagSlug;
1111
+ $TERM_DATA[$tagID]['description'] = $tagDesc;
1112
+ }
1113
+ $csv = new WPImpCSVParserLib();
1114
+ $csv->output ($csv_file_name, $TERM_DATA, $Header, $export_delimiter);
1115
+ }
1116
+
1117
+ /**
1118
+ *
1119
+ */
1120
+ public function WPImpExportTaxonomies($request) {
1121
+ global $wpdb;
1122
+ $export_delimiter = ',';
1123
+ $exporttype = $request['export'];
1124
+ $wpcsvsettings=get_option('wpcsvprosettings');
1125
+ if(isset($wpcsvsettings['export_delimiter'])){
1126
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1127
+ }
1128
+ if($_POST['export_filename'])
1129
+ $csv_file_name =$_POST['export_filename'].'.csv';
1130
+ else
1131
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1132
+
1133
+ $taxonomy_name = $_POST['export_taxo_type'];
1134
+ $taxonomies = get_terms( $taxonomy_name, 'orderby=count&hide_empty=0' );
1135
+ $Header[] = 'name';
1136
+ $Header[] = 'slug';
1137
+ $Header[] = 'description';
1138
+ $fieldsCount = count($taxonomies);
1139
+ foreach( $taxonomies as $taxoKey => $taxoValue ) {
1140
+ $taxoID = $taxoValue->term_id;
1141
+ $taxoName = $taxoValue->name;
1142
+ $taxoSlug = $taxoValue->slug;
1143
+ $taxoDesc = $taxoValue->description;
1144
+ $taxoParent = $taxoValue->parent;
1145
+ if($taxoParent == 0) {
1146
+ $TERM_DATA[$taxoID]['name'] = $taxoName;
1147
+ } else {
1148
+ $taxoParentName = get_term( $taxoParent, $taxonomy_name );
1149
+ $TERM_DATA[$taxoID]['name'] = $taxoParentName->name . '|' . $taxoName;
1150
+ }
1151
+ $TERM_DATA[$taxoID]['slug'] = $taxoSlug;
1152
+ $TERM_DATA[$taxoID]['description'] = $taxoDesc;
1153
+ }
1154
+ $csv = new WPImpCSVParserLib();
1155
+ $csv->output ($csv_file_name, $TERM_DATA, $Header, $export_delimiter);
1156
+ }
1157
+
1158
+ /**
1159
+ *
1160
+ */
1161
+ public function WPImpExportCustomerReviews($request) {
1162
+ global $wpdb;
1163
+ $export_delimiter = ',';
1164
+ $exporttype = $request['export'];
1165
+ $wpcsvsettings=get_option('wpcsvprosettings');
1166
+ if(isset($wpcsvsettings['export_delimiter'])){
1167
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1168
+ }
1169
+ if($_POST['export_filename'])
1170
+ $csv_file_name =$_POST['export_filename'].'.csv';
1171
+ else
1172
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1173
+
1174
+ $header_query1 = "SELECT * FROM wp_wpcreviews";
1175
+ $header_query2 = "SELECT id FROM wp_wpcreviews";
1176
+
1177
+ $result_header_query1 = $wpdb->get_results($header_query1);
1178
+ foreach($result_header_query1 as $rhq1_key){
1179
+ foreach($rhq1_key as $rhq1_headkey => $rhq1_headval){
1180
+ if(!in_array($rhq1_headkey,$Header))
1181
+ $Header[] = $rhq1_headkey;
1182
+ }
1183
+ }
1184
+
1185
+ $result = $wpdb->get_results($header_query1);
1186
+ $result1 = $wpdb->get_results($header_query2);
1187
+ $fieldsCount = count($result);
1188
+ if ($result) {
1189
+ $i =0;
1190
+ foreach ($result as $postID) {
1191
+ foreach ($postID as $Key => $Val){
1192
+ $postData[$i][$Key] = $Val;
1193
+ }
1194
+ $i++;
1195
+ }
1196
+ $ExportData = $postData;
1197
+ $j=0;
1198
+ foreach($Header as $key)
1199
+ {
1200
+ $key=$j;
1201
+ $header[] = $key;
1202
+ $j++;
1203
+ }
1204
+
1205
+ $csv = new WPImpCSVParserLib();
1206
+ $csv->output ($csv_file_name, $ExportData, $Header, $export_delimiter);
1207
+ }
1208
+ }
1209
+
1210
+ /**
1211
+ *
1212
+ */
1213
+ public function WPImpExportComments($request) {
1214
+ global $wpdb;
1215
+ $export_delimiter = ',';
1216
+ $exporttype = $request['export'];
1217
+ $wpcsvsettings=get_option('wpcsvprosettings');
1218
+ if(isset($wpcsvsettings['export_delimiter'])){
1219
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1220
+ }
1221
+ if($_POST['export_filename'])
1222
+ $csv_file_name =$_POST['export_filename'].'.csv';
1223
+ else
1224
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1225
+
1226
+ $commentQuery = "SELECT * FROM $wpdb->comments " . $orderBy;
1227
+ $comments = $wpdb->get_results( $commentQuery);
1228
+ $mappedHeader = false;
1229
+ $i = 0;
1230
+ foreach($comments as $comment){
1231
+ foreach($comment as $key => $value){
1232
+ if(!$mappedHeader){
1233
+ $Header[] = $key; // ."$export_delimiter";
1234
+ }
1235
+ $ExportData[$i][$key] = $value; //'"'.$value.'"'."$export_delimiter";
1236
+ }
1237
+ $mappedHeader = true;
1238
+ $i++;
1239
+ }
1240
+ #print('<pre>'); print_r($header); print_r($singleCommentContent);die;
1241
+ $csv = new WPImpCSVParserLib();
1242
+ $csv->output ($csv_file_name, $ExportData, $Header, $export_delimiter);
1243
+ }
1244
+
1245
+ /**
1246
+ *
1247
+ */
1248
+ public function WPImpExportUsers($request) {
1249
+ global $wpdb;
1250
+ $export_delimiter = ',';
1251
+ $exporttype = $request['export'];
1252
+ $wpcsvsettings=get_option('wpcsvprosettings');
1253
+ if(isset($wpcsvsettings['export_delimiter'])){
1254
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
1255
+ }
1256
+ if($_POST['export_filename'])
1257
+ $csv_file_name =$_POST['export_filename'].'.csv';
1258
+ else
1259
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
1260
+
1261
+ $uId = '';
1262
+ $header_query1 = "SELECT *FROM $wpdb->users";
1263
+ $header_query2 = "SELECT user_id, meta_key, meta_value FROM $wpdb->users wp JOIN $wpdb->usermeta wpm ON wpm.user_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last')";
1264
+ $result_header_query1 = $wpdb->get_results($header_query1);
1265
+ $result_header_query2 = $wpdb->get_results($header_query2);
1266
+ /* print('<pre>'); print_r($result_header_query1);
1267
+ print_r($result_header_query2);die; */
1268
+ foreach ($result_header_query1 as $rhq1_key) {
1269
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
1270
+ if (!in_array($rhq1_headkey, $Header))
1271
+ $Header[] = $rhq1_headkey;
1272
+ }
1273
+ }
1274
+ foreach ($result_header_query2 as $rhq2_headkey) {
1275
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
1276
+ if($rhq2_headkey->meta_key == 'mp_shipping_info' )
1277
+ {
1278
+ $mp_ship_header= unserialize($rhq2_headkey->meta_value);
1279
+ foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "msi: ".$mp_ship_key; }
1280
+ }
1281
+ if($rhq2_headkey->meta_key == 'mp_billing_info' )
1282
+ {
1283
+ $mp_ship_header= unserialize($rhq2_headkey->meta_value);
1284
+ foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "mbi: ".$mp_ship_key; }
1285
+ }
1286
+
1287
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file' && $rhq2_headkey->meta_key != 'mp_shipping_info' && $rhq2_headkey->meta_key != 'mp_billing_info' )
1288
+ $Header[] = $rhq2_headkey->meta_key;
1289
+ }
1290
+ }
1291
+ #echo '<pre>'; print_r($Header); die('dsd');
1292
+ $get_user_ids = "select DISTINCT ID from $wpdb->users u join $wpdb->usermeta um on um.user_id = u.ID";
1293
+
1294
+ $result = $wpdb->get_col($get_user_ids);
1295
+ $fieldsCount = count($result);
1296
+ if ($result) {
1297
+ foreach ($result as $userID) {
1298
+ $uId = $uId . ',' . $userID;
1299
+ $query1 = "SELECT *FROM $wpdb->users where ID in ($userID);";
1300
+ $result_query1 = $wpdb->get_results($query1);
1301
+ if (!empty($result_query1)) {
1302
+ foreach ($result_query1 as $users) {
1303
+ foreach ($users as $user_key => $user_value) {
1304
+ $UserData[$userID][$user_key] = $user_value;
1305
+ }
1306
+ }
1307
+ }
1308
+ // echo '<pre>'; print_r($UserData); die ('dfdf');
1309
+ $query2 = "SELECT user_id, meta_key, meta_value FROM $wpdb->users wp JOIN $wpdb->usermeta wpm ON wpm.user_id = wp.ID where ID=$userID";
1310
+ $possible_values = array('s:', 'a:', ':{');
1311
+ $result_query2 = $wpdb->get_results($query2);
1312
+ if (!empty($result_query2)) {
1313
+ foreach ($result_query2 as $usermeta) {
1314
+ // echo '<pre>'; print_r($usermeta);
1315
+
1316
+ foreach($possible_values as $posval){
1317
+ if(strpos($usermeta->meta_value,$posval)){
1318
+ if($usermeta->meta_key == 'mp_shipping_info' || $usermeta->meta_key == 'mp_billing_info')
1319
+ $typesFserialized = 1;
1320
+ } else {
1321
+ $typesFserialized = 0;
1322
+ }
1323
+ }
1324
+ if($typesFserialized == 1)
1325
+ {
1326
+ if($usermeta->meta_key == 'mp_shipping_info')
1327
+ {
1328
+ $UserID = $usermeta->user_id;
1329
+ $mp_ship_data = unserialize($usermeta->meta_value);
1330
+ foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
1331
+ {
1332
+ $mp_ship_tempkey = "msi: ".$mp_ship_key;
1333
+ $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
1334
+ }
1335
+ }
1336
+
1337
+ if($usermeta->meta_key == 'mp_billing_info')
1338
+ {
1339
+ $UserID = $usermeta->user_id;
1340
+ $mp_ship_data = unserialize($usermeta->meta_value);
1341
+ foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
1342
+ {
1343
+ $mp_ship_tempkey = "mbi: ".$mp_ship_key;
1344
+ $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
1345
+ }
1346
+ }
1347
+
1348
+ if($usermeta->meta_key != 'wp_capabilities' && $usermeta->meta_key !='mp_shipping_info' && $usermeta->meta_key != 'mp_billing_info') {
1349
+ $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
1350
+ } else {
1351
+ if($usermeta->meta_key == 'wp_capabilities') {
1352
+ $getUserRole = unserialize($usermeta->meta_value);
1353
+ // echo '<pre>'; print_r($getUserRole); die('ddf');
1354
+ foreach($getUserRole as $urKey => $urVal) {
1355
+ $getUserRole = get_role($urKey);
1356
+ }
1357
+ $rolelevel = 0;
1358
+ $isfound = array();
1359
+ foreach($getUserRole->capabilities as $roleKey => $roleVal){
1360
+ $isfound = explode('level_', $roleKey);
1361
+ if(is_array($isfound) && count($isfound) == 2){
1362
+ $rolelevel = $rolelevel + 1;
1363
+ }
1364
+ } $rolelevel = $rolelevel - 1;
1365
+ #$UserData[$userID][$usermeta->meta_key] = $rolelevel;
1366
+ }
1367
+ }
1368
+ } else {
1369
+ foreach($possible_values as $posval){
1370
+ if(strpos($usermeta->meta_value,$posval)){
1371
+ $UserData[$userID][$usermeta->meta_key] = null;
1372
+ } else {
1373
+ $ifSerialized = 0;
1374
+ $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
1375
+ }
1376
+ }
1377
+
1378
+ }
1379
+ } #echo '<pre>'; print_r($UserData); die('dd');
1380
+ }
1381
+ }
1382
+ }
1383
+ $UserHeader = array();
1384
+ foreach ($Header as $header_key) {
1385
+ foreach ($UserData as $UD_key => $UD_val) {
1386
+ if(array_key_exists($header_key, $UD_val)) {
1387
+ $CSVContent[$UD_key][$header_key] = $UD_val[$header_key];
1388
+ if(!in_array($header_key, $UserHeader))
1389
+ $UserHeader[] = $header_key;
1390
+ }
1391
+ else {
1392
+ $CSVContent[$UD_key][$header_key] = null;
1393
+ }
1394
+ }
1395
+ }
1396
+
1397
+ $csv = new WPImpCSVParserLib();
1398
+ $csv->output ($csv_file_name, $CSVContent, $UserHeader, $export_delimiter);
1399
+ }
1400
+ }
modules/old_export/actions/actions.php ADDED
@@ -0,0 +1,1428 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /******************************************************************************************
3
+ * Copyright (C) Smackcoders 2014 - All Rights Reserved
4
+ * Unauthorized copying of this file, via any medium is strictly prohibited
5
+ * Proprietary and confidential
6
+ * You can contact Smackcoders at email address info@smackcoders.com.
7
+ *******************************************************************************************/
8
+
9
+ class ExportActions extends SkinnyActions {
10
+ public function __construct() {
11
+
12
+ }
13
+
14
+ /**
15
+ * The actions index method
16
+ * @param array $request
17
+ * @return array
18
+ */
19
+ public function executeIndex($request) {
20
+ // return an array of name value pairs to send data to the template
21
+ $data = array();
22
+ if (!empty($request['POST'])) {
23
+ $type = $request['POST']['export'];
24
+ $filename = $request['POST']['export_filename'];
25
+ if (!empty($type) && !empty($filename)) {
26
+ $helper = new ultimatecsv_include_helper();
27
+ $helper->generateanddownloadcsv($type, $filename);
28
+ }
29
+ }
30
+ return $data;
31
+ }
32
+
33
+ /**
34
+ * @param $request
35
+ * @return array
36
+ */
37
+ public function executeExport($request) {
38
+ #TODO: Update phpdoc
39
+ $data = array();
40
+ #TODO: $data = array() not used in this function / overwritten immediately
41
+ ob_start();
42
+ global $wpdb;
43
+ $Header = $PostData = $PostMetaData = $TermsData = $ExportData = array();
44
+ $exporttype = $request['POST']['export'];
45
+ $export_filename = $request['POST']['export_filename'];
46
+ if ($export_filename) {
47
+ $csv_file_name = $export_filename . '.csv';
48
+ } else {
49
+ $csv_file_name = 'exportas_' . $exporttype . '_' . date("Y-m-d") . '.csv';
50
+ }
51
+ #TODO: $csv_file_name not used in this function / overwritten immediately
52
+
53
+ if ($exporttype == 'post' || $exporttype == 'page') {
54
+ $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$exporttype'";
55
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') and meta_key NOT LIKE 'field_%'";
56
+ $result_header_query1 = $wpdb->get_results($header_query1);
57
+ $result_header_query2 = $wpdb->get_results($header_query2);
58
+
59
+ foreach ($result_header_query1 as $rhq1_key) {
60
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
61
+ if (!in_array($rhq1_headkey, $Header)) {
62
+ $Header[] = $rhq1_headkey;
63
+ }
64
+ }
65
+ }
66
+
67
+ foreach ($result_header_query2 as $rhq2_headkey) {
68
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
69
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file') {
70
+ $Header[] = $rhq2_headkey->meta_key;
71
+ }
72
+ }
73
+ }
74
+
75
+ $Header[] = 'post_tag';
76
+ $Header[] = 'featured_image';
77
+ $Header[] = 'post_category';
78
+ // Code for ACF fields
79
+ $limit = ( int )apply_filters('postmeta_form_limit', 30);
80
+ $get_acf_fields = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta
81
+ GROUP BY meta_key
82
+ HAVING meta_key LIKE 'field_%'
83
+ ORDER BY meta_key
84
+ LIMIT $limit");
85
+
86
+ foreach ($get_acf_fields as $acf_value) {
87
+ $get_acf_field = unserialize($acf_value);
88
+ $acf_fields[$get_acf_field['name']] = "CF: " . $get_acf_field['name'];
89
+ $acf_fields_slug[$get_acf_field['name']] = "_" . $get_acf_field['name'];
90
+ if (in_array("_" . $get_acf_field['name'], $Header)) {
91
+ $Header = array_diff($Header, $acf_fields_slug);
92
+ }
93
+ if ($get_acf_field['type'] == 'checkbox') {
94
+ $checkbox_option_fields[] = $get_acf_field['name'];
95
+ }
96
+ } // Code ends here
97
+ $get_post_ids = "select DISTINCT ID from $wpdb->posts where post_type = '$exporttype' and post_status in ('publish','draft','future','private','pending')";
98
+
99
+ $result = $wpdb->get_col($get_post_ids);
100
+ $fieldsCount = count($result);
101
+ if ($result) {
102
+ foreach ($result as $postID) {
103
+ $pId = $pId . ',' . $postID;
104
+ $query1 = "SELECT wp.* FROM $wpdb->posts wp where ID=$postID";
105
+ $result_query1 = $wpdb->get_results($query1);
106
+ if (!empty($result_query1)) {
107
+ foreach ($result_query1 as $posts) {
108
+ foreach ($posts as $post_key => $post_value) {
109
+ if ($post_key == 'post_status') {
110
+ if (is_sticky($postID)) {
111
+ $PostData[$postID][$post_key] = 'Sticky';
112
+ $post_status = 'Sticky';
113
+ } else {
114
+ $PostData[$postID][$post_key] = $post_value;
115
+ $post_status = $post_value;
116
+ }
117
+ } else {
118
+ $PostData[$postID][$post_key] = $post_value;
119
+ }
120
+ if ($post_key == 'post_password') {
121
+ if ($post_value) {
122
+ $PostData[$postID]['post_status'] = "{" . $post_value . "}";
123
+ } else {
124
+ $PostData[$postID]['post_status'] = $post_status;
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ $query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
131
+ $result_query2 = $wpdb->get_results($query2);
132
+ if (!empty($result_query2)) {
133
+ foreach ($result_query2 as $postmeta) {
134
+ if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
135
+ if (is_array($acf_fields_slug) && !in_array($postmeta->meta_key, $acf_fields_slug)) {
136
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
137
+ }
138
+ }
139
+ $eshop_products = $postmeta->meta_value;
140
+ if ($postmeta->meta_key == 'products') {
141
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
142
+ $eshop_products = unserialize($eshop_products);
143
+ foreach ($eshop_products as $key) {
144
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key['option'] . '|' . $key['price'] . '|' . $key['saleprice'] . ',';
145
+ }
146
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
147
+ }
148
+ if ($postmeta->meta_key == '_thumbnail_id') {
149
+ $attachment_file = '';
150
+ $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
151
+ $attachment = $wpdb->get_results($get_attachement);
152
+ $attachment_file = $attachment[0]->guid;
153
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
154
+ $postmeta->meta_key = 'featured_image';
155
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
156
+ }
157
+ if (is_array($checkbox_option_fields) && in_array($postmeta->meta_key, $checkbox_option_fields)) {
158
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
159
+ $eshop_products = unserialize($eshop_products); //print_r($eshop_products);
160
+ foreach ($eshop_products as $key) {
161
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key . ',';
162
+ }
163
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
164
+ }
165
+ }
166
+
167
+ }
168
+ // Tags & Categories
169
+ $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
170
+ $postTags = $postCategory = '';
171
+ foreach ($get_tags as $tags) {
172
+ $postTags .= $tags . ',';
173
+ }
174
+ $postTags = substr($postTags, 0, -1);
175
+ $TermsData[$postID]['post_tag'] = $postTags;
176
+ $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
177
+ foreach ($get_categotries as $category) {
178
+ $postCategory .= $category . '|';
179
+ }
180
+ $postCategory = substr($postCategory, 0, -1);
181
+ $TermsData[$postID]['post_category'] = $postCategory;
182
+ }
183
+ $ExportData = array();
184
+ // Merge all arrays
185
+ foreach ($PostData as $pd_key => $pd_val) {
186
+ if (array_key_exists($pd_key, $PostMetaData)) {
187
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
188
+ } else {
189
+ $ExportData[$pd_key] = $PostData[$pd_key];
190
+ }
191
+ if (array_key_exists($pd_key, $TermsData)) {
192
+ if (empty($ExportData[$pd_key])) {
193
+ $ExportData[$pd_key] = array();
194
+ }
195
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
196
+ }
197
+ }
198
+
199
+ foreach ($Header as $header_key) {
200
+ foreach ($ExportData as $ED_key) {
201
+ if (array_key_exists($header_key, $ED_key)) {
202
+ $CSVContent[$header_key][] = $ED_key[$header_key];
203
+ } else {
204
+ $CSVContent[$header_key][] = '';
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ # GENERATE AS CSV
211
+ $CSVDATA = array();
212
+ for ($j = 0; $j < $fieldsCount; $j++) {
213
+ foreach ($Header as $value) {
214
+ $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '",';
215
+ }
216
+ }
217
+ $CSV_FILE_CONTENT = array();
218
+ foreach ($Header as $csv_header) {
219
+ if ($csv_header == '_eshop_stock') {
220
+ $csv_header = 'stock_available';
221
+ }
222
+ if ($csv_header == 'cart_radio') {
223
+ $csv_header = 'cart_option';
224
+ }
225
+ if ($csv_header == 'sale') {
226
+ $csv_header = 'product_in_sale';
227
+ }
228
+ if ($csv_header == 'featured') {
229
+ $csv_header = 'featured_product';
230
+ }
231
+ if ($csv_header == 'sku' || $csv_header == '_wpsc_sku') {
232
+ $csv_header = 'SKU';
233
+ }
234
+ if ($csv_header == '_aioseop_keywords') {
235
+ $csv_header = 'seo_keywords';
236
+ }
237
+ if ($csv_header == '_aioseop_description') {
238
+ $csv_header = 'seo_description';
239
+ }
240
+ if ($csv_header == '_aioseop_title') {
241
+ $csv_header = 'seo_title';
242
+ }
243
+ if ($csv_header == '_aioseop_noindex') {
244
+ $csv_header = 'seo_noindex';
245
+ }
246
+ if ($csv_header == '_aioseop_nofollow') {
247
+ $csv_header = 'seo_nofollow';
248
+ }
249
+ if ($csv_header == '_aioseop_disable') {
250
+ $csv_header = 'seo_disable';
251
+ }
252
+ if ($csv_header == '_aioseop_disable_analytics') {
253
+ $csv_header = 'seo_disable_analytics';
254
+ }
255
+ if ($csv_header == '_yoast_wpseo_focuskw') {
256
+ $csv_header = 'focus_keyword';
257
+ }
258
+ if ($csv_header == '_yoast_wpseo_title') {
259
+ $csv_header = 'title';
260
+ }
261
+ if ($csv_header == '_yoast_wpseo_metadesc') {
262
+ $csv_header = 'meta_desc';
263
+ }
264
+ if ($csv_header == '_yoast_wpseo_meta-robots-noindex') {
265
+ $csv_header = 'meta-robots-noindex';
266
+ }
267
+ if ($csv_header == '_yoast_wpseo_meta-robots-nofollow') {
268
+ $csv_header = 'meta-robots-nofollow';
269
+ }
270
+ if ($csv_header == '_yoast_wpseo_meta-robots-adv') {
271
+ $csv_header = 'meta-robots-adv';
272
+ }
273
+ if ($csv_header == '_yoast_wpseo_sitemap-include') {
274
+ $csv_header = 'sitemap-include';
275
+ }
276
+ if ($csv_header == '_yoast_wpseo_sitemap-prio') {
277
+ $csv_header = 'sitemap-prio';
278
+ }
279
+ if ($csv_header == '_yoast_wpseo_canonical') {
280
+ $csv_header = 'canonical';
281
+ }
282
+ if ($csv_header == '_yoast_wpseo_redirect') {
283
+ $csv_header = 'redirect';
284
+ }
285
+ if ($csv_header == '_yoast_wpseo_opengraph-description') {
286
+ $csv_header = 'opengraph-description';
287
+ }
288
+ if ($csv_header == '_yoast_wpseo_google-plus-description') {
289
+ $csv_header = 'google-plus-description';
290
+ }
291
+ if (array_key_exists($csv_header, $acf_fields)) {
292
+ $csv_header = $acf_fields[$csv_header];
293
+ }
294
+
295
+ $CSV_FILE_CONTENT .= $csv_header . ",";
296
+ }
297
+
298
+ $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
299
+ $CSV_FILE_CONTENT .= "\n";
300
+ if ($CSVDATA) {
301
+ foreach ($CSVDATA as $csv_content) {
302
+ $csv_content = substr($csv_content, 0, -1);
303
+ $CSV_FILE_CONTENT .= $csv_content . "\n";
304
+ }
305
+ }
306
+ } elseif ($exporttype == 'customerreviews') {
307
+ $header_query1 = "SELECT * FROM wp_wpcreviews";
308
+ #TODO: Remove * from the SQL
309
+
310
+ $result_header_query1 = $wpdb->get_results($header_query1);
311
+ foreach ($result_header_query1 as $rhq1_key) {
312
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
313
+ if (!in_array($rhq1_headkey, $Header)) {
314
+ $Header[] = $rhq1_headkey;
315
+ }
316
+ }
317
+ }
318
+
319
+ $Header[] = 'date_time';
320
+ $Header[] = 'reviewer_name';
321
+ $Header[] = 'reviewer_email';
322
+ $Header[] = 'reviewer_ip';
323
+ $Header[] = 'review_title';
324
+ $Header[] = 'review_text';
325
+ $Header[] = 'review_response';
326
+ $Header[] = 'status';
327
+ $Header[] = 'review_rating';
328
+ $Header[] = 'reviewer_url';
329
+ $Header[] = 'page_id';
330
+ $Header[] = 'custom_fields';
331
+
332
+ # GENERATE AS CSV
333
+ $CSVDATA = array();
334
+ for ($j = 0; $j < 11; $j++) {
335
+ foreach ($Header as $value) {
336
+ $CSVDATA[$j] .= '"' . $value[$j] . '",';
337
+ }
338
+ }
339
+ $CSV_FILE_CONTENT = array();
340
+ foreach ($Header as $csv_header) {
341
+ if ($csv_header == 'date_time') {
342
+ $csv_header = 'date_time';
343
+ }
344
+ if ($csv_header == 'reviewer_name') {
345
+ $csv_header = 'reviewer_name';
346
+ }
347
+ if ($csv_header == 'reviewer_email') {
348
+ $csv_header = 'reviewer_email';
349
+ }
350
+ if ($csv_header == 'reviewer_ip') {
351
+ $csv_header = 'reviewer_ip';
352
+ }
353
+ if ($csv_header == 'review_title') {
354
+ $csv_header = 'review_title';
355
+ }
356
+ if ($csv_header == 'review_text') {
357
+ $csv_header = 'review_text';
358
+ }
359
+ if ($csv_header == 'review_response') {
360
+ $csv_header = 'review_response';
361
+ }
362
+ if ($csv_header == 'status') {
363
+ $csv_header = 'status';
364
+ }
365
+ if ($csv_header == 'review_rating') {
366
+ $csv_header = 'review_rating';
367
+ }
368
+ if ($csv_header == 'reviewer_url') {
369
+ $csv_header = 'reviewer_url';
370
+ }
371
+ if ($csv_header == 'page_id') {
372
+ $csv_header = 'page_id';
373
+ }
374
+ if ($csv_header == 'custom_fields') {
375
+ $csv_header = 'custom_fields';
376
+ }
377
+
378
+ $isActive = false;
379
+ $active_plugins = get_option('active_plugins');
380
+ if (in_array('wp-customer-reviews/wp-customer-reviews.php', $active_plugins)) {
381
+ $isActive = true;
382
+ }
383
+ #TODO: $isActive not used in this function / overwritten immediately
384
+ $CSV_FILE_CONTENT .= $csv_header . ",";
385
+ }
386
+ $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
387
+ $CSV_FILE_CONTENT .= "\n";
388
+ if ($CSVDATA) {
389
+ foreach ($CSVDATA as $csv_content) {
390
+ $csv_content = substr($csv_content, 0, -1);
391
+ $CSV_FILE_CONTENT .= $csv_content . "\n";
392
+ }
393
+ }
394
+ } elseif ($exporttype == 'eshop') {
395
+ $exporttype = 'post';
396
+ $header_query1 = "SELECT wp.* FROM wp_posts wp where post_type = '$exporttype'";
397
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last')";
398
+ $result_header_query1 = $wpdb->get_results($header_query1);
399
+ $result_header_query2 = $wpdb->get_results($header_query2);
400
+ foreach ($result_header_query1 as $rhq1_key) {
401
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
402
+ if (!in_array($rhq1_headkey, $Header)) {
403
+ if ($rhq1_headkey != 'to_ping' && $rhq1_headkey != 'pinged' && $rhq1_headkey != 'post_mime_type') {
404
+ $Header[] = $rhq1_headkey;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ foreach ($result_header_query2 as $rhq2_headkey) {
410
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
411
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file' && $rhq2_headkey->meta_key != 'products' && $rhq2_headkey->meta_key != '_eshop_sale' && $rhq2_headkey->meta_key != 'post_mime_type' && $rhq2_headkey->meta_key != '_thumbnail_id' && $rhq2_headkey->meta_key != '_wp_attachment_metadata' && $rhq2_headkey->meta_key != '_eshop_featured') {
412
+ $Header[] = $rhq2_headkey->meta_key;
413
+ }
414
+ }
415
+ }
416
+ $Header[] = 'products_option';
417
+ $Header[] = 'regular_price';
418
+ $Header[] = 'sale_price';
419
+ $Header[] = 'featured_image';
420
+ $Header[] = 'post_tag';
421
+ $Header[] = 'post_category';
422
+ $get_post_ids = "select DISTINCT ID from wp_posts p join wp_postmeta pm on pm.post_id = p.ID where post_type = '$exporttype' and post_status in ('publish','draft','future','private','pending') and pm.meta_key = 'sku'";
423
+
424
+ $result = $wpdb->get_col($get_post_ids);
425
+ $fieldsCount = count($result);
426
+ if ($result) {
427
+ foreach ($result as $postID) {
428
+ $pId = $pId . ',' . $postID;
429
+ $query1 = "SELECT wp.* FROM wp_posts wp where ID=$postID";
430
+ $result_query1 = $wpdb->get_results($query1);
431
+ if (!empty($result_query1)) {
432
+ foreach ($result_query1 as $posts) {
433
+ foreach ($posts as $post_key => $post_value) {
434
+ if ($post_key == 'post_status') {
435
+ if (is_sticky($postID)) {
436
+ $PostData[$postID][$post_key] = 'Sticky';
437
+ $post_status = 'Sticky';
438
+ } else {
439
+ $PostData[$postID][$post_key] = $post_value;
440
+ $post_status = $post_value;
441
+ }
442
+ } else {
443
+ $PostData[$postID][$post_key] = $post_value;
444
+ }
445
+ if ($post_key == 'post_password') {
446
+ if ($post_value) {
447
+ $PostData[$postID]['post_status'] = "{" . $post_value . "}";
448
+ } else {
449
+ $PostData[$postID]['post_status'] = $post_status;
450
+ }
451
+ }
452
+ }
453
+ }
454
+ }
455
+ $query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
456
+ $result_query2 = $wpdb->get_results($query2);
457
+ if (!empty($result_query2)) {
458
+ foreach ($result_query2 as $postmeta) {
459
+ if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
460
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
461
+ }
462
+ $eshop_products = $postmeta->meta_value;
463
+ if ($postmeta->meta_key == 'products') {
464
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
465
+ $eshop_products = unserialize($eshop_products);
466
+ foreach ($eshop_products as $key) {
467
+ $PostMetaData[$postmeta->post_id]['products_option'] .= $key['option'] . ',';
468
+ $PostMetaData[$postmeta->post_id]['sale_price'] .= $key['saleprice'] . ',';
469
+ $PostMetaData[$postmeta->post_id]['regular_price'] .= $key['price'] . ',';
470
+ }
471
+ $PostMetaData[$postmeta->post_id]['products_option'] = substr($PostMetaData[$postmeta->post_id]['products_option'], 0, -1);
472
+ $PostMetaData[$postmeta->post_id]['sale_price'] = substr($PostMetaData[$postmeta->post_id]['sale_price'], 0, -1);
473
+ $PostMetaData[$postmeta->post_id]['regular_price'] = substr($PostMetaData[$postmeta->post_id]['regular_price'], 0, -1);
474
+ }
475
+ if ($postmeta->meta_key == '_thumbnail_id') {
476
+ $attachment_file = '';
477
+ #TODO: $attachment_file not used in this function / overwritten immediately
478
+ $get_attachement = "select guid from wp_posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
479
+ $attachment = $wpdb->get_results($get_attachement);
480
+ $attachment_file = $attachment[0]->guid;
481
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
482
+ $postmeta->meta_key = 'featured_image';
483
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
484
+ }
485
+ }
486
+
487
+ }
488
+ // Tags & Categories
489
+ $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
490
+ $postTags = $postCategory = '';
491
+ foreach ($get_tags as $tags) {
492
+ $postTags .= $tags . ',';
493
+ }
494
+ $postTags = substr($postTags, 0, -1);
495
+ $TermsData[$postID]['post_tag'] = $postTags;
496
+ $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
497
+ foreach ($get_categotries as $category) {
498
+ $postCategory .= $category . '|';
499
+ }
500
+ $postCategory = substr($postCategory, 0, -1);
501
+ $TermsData[$postID]['post_category'] = $postCategory;
502
+ }
503
+
504
+ $ExportData = array();
505
+ // Merge all arrays
506
+ foreach ($PostData as $pd_key => $pd_val) {
507
+ if (array_key_exists($pd_key, $PostMetaData)) {
508
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
509
+ }
510
+ if (array_key_exists($pd_key, $TermsData)) {
511
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
512
+ }
513
+ }
514
+ foreach ($Header as $header_key) {
515
+ foreach ($ExportData as $ED_key) {
516
+ if (array_key_exists($header_key, $ED_key)) {
517
+ $CSVContent[$header_key][] = $ED_key[$header_key];
518
+ } else {
519
+ $CSVContent[$header_key][] = '';
520
+ }
521
+ }
522
+ }
523
+ }
524
+ # GENERATE AS CSV
525
+ $CSVDATA = array();
526
+ for ($j = 0; $j < $fieldsCount; $j++) {
527
+ foreach ($Header as $value) {
528
+ $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '",';
529
+ }
530
+ }
531
+ $CSV_FILE_CONTENT = array();
532
+ foreach ($Header as $csv_header) {
533
+ if ($csv_header == '_eshop_stock') {
534
+ $csv_header = 'stock_available';
535
+ }
536
+ if ($csv_header == 'cart_radio') {
537
+ $csv_header = 'cart_option';
538
+ }
539
+ if ($csv_header == 'sale') {
540
+ $csv_header = 'product_in_sale';
541
+ }
542
+ if ($csv_header == 'featured') {
543
+ $csv_header = 'featured_product';
544
+ }
545
+ if ($csv_header == 'sku') {
546
+ $csv_header = 'SKU';
547
+ }
548
+ if ($csv_header == '_aioseop_keywords') {
549
+ $csv_header = 'seo_keywords';
550
+ }
551
+ if ($csv_header == '_aioseop_description') {
552
+ $csv_header = 'seo_description';
553
+ }
554
+ if ($csv_header == '_aioseop_title') {
555
+ $csv_header = 'seo_title';
556
+ }
557
+ if ($csv_header == '_aioseop_noindex') {
558
+ $csv_header = 'seo_noindex';
559
+ }
560
+ if ($csv_header == '_aioseop_nofollow') {
561
+ $csv_header = 'seo_nofollow';
562
+ }
563
+ if ($csv_header == '_aioseop_disable') {
564
+ $csv_header = 'seo_disable';
565
+ }
566
+ if ($csv_header == '_aioseop_disable_analytics') {
567
+ $csv_header = 'seo_disable_analytics';
568
+ }
569
+ if ($csv_header == '_yoast_wpseo_focuskw') {
570
+ $csv_header = 'focus_keyword';
571
+ }
572
+ if ($csv_header == '_yoast_wpseo_title') {
573
+ $csv_header = 'title';
574
+ }
575
+ if ($csv_header == '_yoast_wpseo_metadesc') {
576
+ $csv_header = 'meta_desc';
577
+ }
578
+ if ($csv_header == '_yoast_wpseo_meta-robots-noindex') {
579
+ $csv_header = 'meta-robots-noindex';
580
+ }
581
+ if ($csv_header == '_yoast_wpseo_meta-robots-nofollow') {
582
+ $csv_header = 'meta-robots-nofollow';
583
+ }
584
+ if ($csv_header == '_yoast_wpseo_meta-robots-adv') {
585
+ $csv_header = 'meta-robots-adv';
586
+ }
587
+ if ($csv_header == '_yoast_wpseo_sitemap-include') {
588
+ $csv_header = 'sitemap-include';
589
+ }
590
+ if ($csv_header == '_yoast_wpseo_sitemap-prio') {
591
+ $csv_header = 'sitemap-prio';
592
+ }
593
+ if ($csv_header == '_yoast_wpseo_canonical') {
594
+ $csv_header = 'canonical';
595
+ }
596
+ if ($csv_header == '_yoast_wpseo_redirect') {
597
+ $csv_header = 'redirect';
598
+ }
599
+ if ($csv_header == '_yoast_wpseo_opengraph-description') {
600
+ $csv_header = 'opengraph-description';
601
+ }
602
+ if ($csv_header == '_yoast_wpseo_google-plus-description') {
603
+ $csv_header = 'google-plus-description';
604
+ }
605
+
606
+ if ($csv_header == 'post_tag') {
607
+ $csv_header = 'tags';
608
+ }
609
+ if ($csv_header == 'post_category') {
610
+ $csv_header = 'category';
611
+ }
612
+ $CSV_FILE_CONTENT .= $csv_header . ",";
613
+ }
614
+ $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
615
+ $CSV_FILE_CONTENT .= "\n";
616
+ if ($CSVDATA) {
617
+ foreach ($CSVDATA as $csv_content) {
618
+ $csv_content = substr($csv_content, 0, -1);
619
+ $CSV_FILE_CONTENT .= $csv_content . "\n";
620
+ }
621
+ }
622
+ } elseif ($exporttype == 'wpcommerce') {
623
+ $exporttype = 'wpsc-product';
624
+ $header_query1 = "SELECT wp.* FROM wp_posts wp where post_type = '$exporttype'";
625
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last')";
626
+ $result_header_query1 = $wpdb->get_results($header_query1);
627
+ $result_header_query2 = $wpdb->get_results($header_query2);
628
+ foreach ($result_header_query1 as $rhq1_key) {
629
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
630
+ if (!in_array($rhq1_headkey, $Header)) {
631
+ $Header[] = $rhq1_headkey;
632
+ }
633
+ }
634
+ }
635
+ foreach ($result_header_query2 as $rhq2_headkey) {
636
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
637
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file' && $rhq2_headkey->meta_key != '_wpsc_product_metadata') {
638
+ $Header[] = $rhq2_headkey->meta_key;
639
+ }
640
+ }
641
+ }
642
+ $Header[] = 'featured_image';
643
+ $Header[] = 'product_tag';
644
+ $Header[] = 'wpsc_product_category';
645
+ $Header[] = 'notify_when_none_left';
646
+ $Header[] = 'unpublish_when_none_left';
647
+ $Header[] = 'wpec_taxes_taxable_amount';
648
+ $Header[] = 'wpec_taxes_taxable';
649
+ $Header[] = 'external_link';
650
+ $Header[] = 'external_link_text';
651
+ $Header[] = 'external_link_target';
652
+ $Header[] = 'no_shipping';
653
+ $Header[] = 'weight';
654
+ $Header[] = 'weight_unit';
655
+ $Header[] = 'height';
656
+ $Header[] = 'height_unit';
657
+ $Header[] = 'width';
658
+ $Header[] = 'width_unit';
659
+ $Header[] = 'length';
660
+ $Header[] = 'length_unit';
661
+ $Header[] = 'merchant_notes';
662
+ $Header[] = 'enable_comments';
663
+ $Header[] = 'quantity_limited';
664
+ $Header[] = 'special';
665
+ $Header[] = 'display_weight_as';
666
+ $Header[] = 'table_rate_price';
667
+ $Header[] = 'state';
668
+ $Header[] = 'quantity';
669
+ $Header[] = 'shipping';
670
+ $Header[] = 'table_price';
671
+ $Header[] = 'google_prohibited';
672
+
673
+ $get_post_ids = "select DISTINCT ID from wp_posts p join wp_postmeta pm on pm.post_id = p.ID where post_type = '$exporttype' and post_status in ('publish','draft','future','private','pending') and pm.meta_key = '_wpsc_sku'";
674
+ $result = $wpdb->get_col($get_post_ids);
675
+ $fieldsCount = count($result);
676
+ if ($result) {
677
+ foreach ($result as $postID) {
678
+ $pId = $pId . ',' . $postID;
679
+ $query1 = "SELECT wp.* FROM wp_posts wp where ID=$postID";
680
+ $result_query1 = $wpdb->get_results($query1);
681
+ if (!empty($result_query1)) {
682
+ foreach ($result_query1 as $posts) {
683
+ foreach ($posts as $post_key => $post_value) {
684
+ if ($post_key == 'post_status') {
685
+ if (is_sticky($postID)) {
686
+ $PostData[$postID][$post_key] = 'Sticky';
687
+ $post_status = 'Sticky';
688
+ } else {
689
+ $PostData[$postID][$post_key] = $post_value;
690
+ $post_status = $post_value;
691
+ }
692
+ } else {
693
+ $PostData[$postID][$post_key] = $post_value;
694
+ }
695
+ if ($post_key == 'post_password') {
696
+ if ($post_value) {
697
+ $PostData[$postID]['post_status'] = "{" . $post_value . "}";
698
+ } else {
699
+ $PostData[$postID]['post_status'] = $post_status;
700
+ }
701
+ }
702
+ }
703
+ }
704
+ }
705
+ $query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
706
+ $result_query2 = $wpdb->get_results($query2);
707
+ if (!empty($result_query2)) {
708
+ foreach ($result_query2 as $postmeta) {
709
+ if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
710
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
711
+ }
712
+ $eshop_products = $postmeta->meta_value;
713
+ if ($postmeta->meta_key == 'products') {
714
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
715
+ $eshop_products = unserialize($eshop_products);
716
+ foreach ($eshop_products as $key) {
717
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key['option'] . '|' . $key['price'] . '|' . $key['saleprice'] . ',';
718
+ }
719
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
720
+ }
721
+ if ($postmeta->meta_key == '_thumbnail_id') {
722
+ $attachment_file = '';
723
+ $get_attachement = "select guid from wp_posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
724
+ $attachment = $wpdb->get_results($get_attachement);
725
+ $attachment_file = $attachment[0]->guid;
726
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
727
+ $postmeta->meta_key = 'featured_image';
728
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
729
+ }
730
+ if ($postmeta->meta_key == '_wpsc_product_metadata') {
731
+ $productMeta = unserialize($postmeta->meta_value);
732
+ foreach ($productMeta as $metaKey => $metaValue) {
733
+ if ($metaKey == 'notify_when_none_left' || $metaKey == 'unpublish_when_none_left' || $metaKey == 'external_link' || $metaKey == 'external_link_text' || $metaKey == 'external_link_target' || $metaKey == 'no_shipping' || $metaKey == 'weight' || $metaKey == 'weight_unit' || $metaKey == 'merchant_notes' || $metaKey == 'enable_comments' || $metaKey == 'quantity_limited' || $metaKey == 'special' || $metaKey == 'display_weight_as' || $metaKey == 'google_prohibited') {
734
+ $PostMetaData[$postmeta->post_id][$metaKey] = $metaValue;
735
+ }
736
+ if ($metaKey == 'wpec_taxes_taxable_amount') {
737
+ $PostMetaData[$postmeta->post_id]['taxable_amount'] = $metaValue;
738
+ }
739
+ if ($metaKey == 'wpec_taxes_taxable') {
740
+ $PostMetaData[$postmeta->post_id]['is_taxable'] = $metaValue;
741
+ }
742
+ if ($metaKey == 'dimensions') {
743
+ foreach ($metaValue as $mk => $mv) {
744
+ $PostMetaData[$postmeta->post_id][$mk] = $mv;
745
+ }
746
+ }
747
+ if ($metaKey == 'shipping') {
748
+ $PostMetaData[$postmeta->post_id]['shipping'] = $metaKey['local'] . '|' . $metaKey['international'];
749
+ }
750
+ if ($metaKey == 'table_rate_price') {
751
+ $PostMetaData[$postmeta->post_id]['state'] = $metaKey['table_rate_price']['state'];
752
+ $PostMetaData[$postmeta->post_id]['quantity'] = $metaKey['table_rate_price']['quantity'][0];
753
+ $PostMetaData[$postmeta->post_id]['table_price'] = $metaKey['table_rate_price']['table_price'][0];
754
+ }
755
+ }
756
+ }
757
+ }
758
+
759
+ }
760
+ // Tags & Categories
761
+ $postTags = $postCategory = '';
762
+ $taxonomies = get_object_taxonomies($exporttype);
763
+ foreach ($taxonomies as $taxonomy) {
764
+ if ($taxonomy == 'product_tag') {
765
+ $get_tags = get_the_terms($postID, $taxonomy);
766
+ if ($get_tags) {
767
+ foreach ($get_tags as $tags) {
768
+ $postTags .= $tags->name . ',';
769
+ }
770
+ }
771
+ $postTags = substr($postTags, 0, -1);
772
+ $TermsData[$postID]['product_tag'] = $postTags;
773
+ }
774
+ if ($taxonomy == 'wpsc_product_category') {
775
+ $get_categotries = wp_get_post_terms($postID, $taxonomy);
776
+ if ($get_categotries) {
777
+ foreach ($get_categotries as $category) {
778
+ $postCategory .= $category->name . '|';
779
+ }
780
+ }
781
+ $postCategory = substr($postCategory, 0, -1);
782
+ $TermsData[$postID][$taxonomy] = $postCategory;
783
+ }
784
+ }
785
+ }
786
+
787
+ $ExportData = array();
788
+ // Merge all arrays
789
+ foreach ($PostData as $pd_key => $pd_val) {
790
+ if (array_key_exists($pd_key, $PostMetaData)) {
791
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
792
+ }
793
+ if (array_key_exists($pd_key, $TermsData)) {
794
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
795
+ }
796
+ }
797
+ foreach ($Header as $header_key) {
798
+ foreach ($ExportData as $ED_key) {
799
+ if (array_key_exists($header_key, $ED_key)) {
800
+ $CSVContent[$header_key][] = $ED_key[$header_key];
801
+ } else {
802
+ $CSVContent[$header_key][] = '';
803
+ }
804
+ }
805
+ }
806
+ }
807
+ # GENERATE AS CSV
808
+ $CSVDATA = array();
809
+ for ($j = 0; $j < $fieldsCount; $j++) {
810
+ foreach ($Header as $value) {
811
+ $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '",';
812
+ }
813
+ }
814
+
815
+ $CSV_FILE_CONTENT = array();
816
+ foreach ($Header as $csv_header) {
817
+ if ($csv_header == '_wpsc_stock') {
818
+ $csv_header = 'stock';
819
+ }
820
+ if ($csv_header == '_wpsc_price') {
821
+ $csv_header = 'price';
822
+ }
823
+ if ($csv_header == '_wpsc_special_price') {
824
+ $csv_header = 'sale_price';
825
+ }
826
+ if ($csv_header == '_wpsc_sku') {
827
+ $csv_header = 'SKU';
828
+ }
829
+ if ($csv_header == 'wpec_taxes_taxable_amount') {
830
+ $csv_header = 'taxable_amount';
831
+ }
832
+ if ($csv_header == 'wpec_taxes_taxable') {
833
+ $csv_header = 'is_taxable';
834
+ }
835
+ if ($csv_header == '_aioseop_keywords') {
836
+ $csv_header = 'seo_keywords';
837
+ }
838
+ if ($csv_header == '_aioseop_description') {
839
+ $csv_header = 'seo_description';
840
+ }
841
+ if ($csv_header == '_aioseop_title') {
842
+ $csv_header = 'seo_title';
843
+ }
844
+ if ($csv_header == '_aioseop_noindex') {
845
+ $csv_header = 'seo_noindex';
846
+ }
847
+ if ($csv_header == '_aioseop_nofollow') {
848
+ $csv_header = 'seo_nofollow';
849
+ }
850
+ if ($csv_header == '_aioseop_disable') {
851
+ $csv_header = 'seo_disable';
852
+ }
853
+ if ($csv_header == '_yoast_wpseo_focuskw') {
854
+ $csv_header = 'focus_keyword';
855
+ }
856
+ if ($csv_header == '_yoast_wpseo_title') {
857
+ $csv_header = 'title';
858
+ }
859
+ if ($csv_header == '_yoast_wpseo_metadesc') {
860
+ $csv_header = 'meta_desc';
861
+ }
862
+ if ($csv_header == '_yoast_wpseo_meta-robots-noindex') {
863
+ $csv_header = 'meta-robots-noindex';
864
+ }
865
+ if ($csv_header == '_yoast_wpseo_meta-robots-nofollow') {
866
+ $csv_header = 'meta-robots-nofollow';
867
+ }
868
+ if ($csv_header == '_yoast_wpseo_meta-robots-adv') {
869
+ $csv_header = 'meta-robots-adv';
870
+ }
871
+ if ($csv_header == '_yoast_wpseo_sitemap-include') {
872
+ $csv_header = 'sitemap-include';
873
+ }
874
+ if ($csv_header == '_yoast_wpseo_sitemap-prio') {
875
+ $csv_header = 'sitemap-prio';
876
+ }
877
+ if ($csv_header == '_yoast_wpseo_canonical') {
878
+ $csv_header = 'canonical';
879
+ }
880
+ if ($csv_header == '_yoast_wpseo_redirect') {
881
+ $csv_header = 'redirect';
882
+ }
883
+ if ($csv_header == '_yoast_wpseo_opengraph-description') {
884
+ $csv_header = 'opengraph-description';
885
+ }
886
+ if ($csv_header == '_yoast_wpseo_google-plus-description') {
887
+ $csv_header = 'google-plus-description';
888
+ }
889
+ if ($csv_header == '_aioseop_disable_analytics') {
890
+ $csv_header = 'seo_disable_analytics';
891
+ }
892
+ if ($csv_header == 'product_tag') {
893
+ $csv_header = 'product_tags';
894
+ }
895
+ if ($csv_header == 'wpsc_product_category') {
896
+ $csv_header = 'product_category';
897
+ }
898
+ // Code for wp-ecommerce-custom-fields support
899
+ $isActive = false;
900
+ $active_plugins = get_option('active_plugins');
901
+ if (in_array('wp-e-commerce-custom-fields/custom-fields.php', $active_plugins)) {
902
+ $isActive = true;
903
+ }
904
+ if ($isActive) {
905
+ $get_wpcf = unserialize(get_option('wpsc_cf_data'));
906
+ foreach ($get_wpcf as $wpcf_key => $wpcf_val) {
907
+ $key = '_wpsc_' . $wpcf_val['slug'];
908
+ if ($csv_header == $key) {
909
+ $csv_header = $wpcf_val['name'];
910
+ }
911
+ }
912
+ } // Code ends here
913
+
914
+ $CSV_FILE_CONTENT .= $csv_header . ",";
915
+ }
916
+ $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
917
+ $CSV_FILE_CONTENT .= "\n";
918
+ if ($CSVDATA) {
919
+ foreach ($CSVDATA as $csv_content) {
920
+ $csv_content = substr($csv_content, 0, -1);
921
+ $CSV_FILE_CONTENT .= $csv_content . "\n";
922
+ }
923
+ }
924
+ } elseif ($exporttype == 'woocommerce') {
925
+ $exporttype = 'product';
926
+ $header_query1 = "SELECT wp.* FROM wp_posts wp where post_type = '$exporttype'";
927
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last')";
928
+ $result_header_query1 = $wpdb->get_results($header_query1);
929
+ $result_header_query2 = $wpdb->get_results($header_query2);
930
+ foreach ($result_header_query1 as $rhq1_key) {
931
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
932
+ if (!in_array($rhq1_headkey, $Header)) {
933
+ $Header[] = $rhq1_headkey;
934
+ }
935
+ }
936
+ }
937
+ foreach ($result_header_query2 as $rhq2_headkey) {
938
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
939
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file') {
940
+ $Header[] = $rhq2_headkey->meta_key;
941
+ }
942
+ }
943
+ }
944
+ $Header[] = 'featured_image';
945
+ $Header[] = 'product_tag';
946
+ $Header[] = 'product_category';
947
+ $Header[] = '_product_attribute_name';
948
+ $Header[] = '_product_attribute_value';
949
+ $Header[] = '_product_attribute_visible';
950
+ $Header[] = '_product_attribute_variation';
951
+
952
+ $get_post_ids = "select DISTINCT ID from wp_posts p join wp_postmeta pm on pm.post_id = p.ID where post_type = '$exporttype' and post_status in ('publish','draft','future','private','pending') and pm.meta_key = '_sku'";
953
+
954
+ $result = $wpdb->get_col($get_post_ids);
955
+ $fieldsCount = count($result);
956
+ if ($result) {
957
+ foreach ($result as $postID) {
958
+ $pId = $pId . ',' . $postID;
959
+ $query1 = "SELECT wp.* FROM wp_posts wp where ID=$postID";
960
+ $result_query1 = $wpdb->get_results($query1);
961
+ if (!empty($result_query1)) {
962
+ foreach ($result_query1 as $posts) {
963
+ foreach ($posts as $post_key => $post_value) {
964
+ if ($post_key == 'post_status') {
965
+ if (is_sticky($postID)) {
966
+ $PostData[$postID][$post_key] = 'Sticky';
967
+ $post_status = 'Sticky';
968
+ } else {
969
+ $PostData[$postID][$post_key] = $post_value;
970
+ $post_status = $post_value;
971
+ }
972
+ } else {
973
+ $PostData[$postID][$post_key] = $post_value;
974
+ }
975
+ if ($post_key == 'post_password') {
976
+ if ($post_value) {
977
+ $PostData[$postID]['post_status'] = "{" . $post_value . "}";
978
+ } else {
979
+ $PostData[$postID]['post_status'] = $post_status;
980
+ }
981
+ }
982
+ if ($post_key == 'comment_status') {
983
+ if ($post_value == 'closed') {
984
+ $PostData[$postID]['comment_status'] = 0;
985
+ }
986
+ if ($post_value == 'open') {
987
+ $PostData[$postID]['comment_status'] = 1;
988
+ }
989
+ }
990
+
991
+ }
992
+ }
993
+ }
994
+ $query2 = "SELECT post_id, meta_key, meta_value FROM wp_posts wp JOIN wp_postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
995
+ $result_query2 = $wpdb->get_results($query2);
996
+ if (!empty($result_query2)) {
997
+ foreach ($result_query2 as $postmeta) {
998
+ if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
999
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
1000
+ }
1001
+ $eshop_products = $postmeta->meta_value;
1002
+ if ($postmeta->meta_key == '_product_attributes') {
1003
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
1004
+ $product_attribute_name = $product_attribute_value = $product_attribute_visible = $product_attribute_variation = '';
1005
+ $PostMetaData[$postmeta->post_id]['_product_attribute_name'] = '';
1006
+ $PostMetaData[$postmeta->post_id]['_product_attribute_value'] = '';
1007
+ $PostMetaData[$postmeta->post_id]['_product_attribute_visible'] = '';
1008
+ $PostMetaData[$postmeta->post_id]['_product_attribute_variation'] = '';
1009
+ $eshop_products_unser1 = unserialize($eshop_products);
1010
+ $check_attr_count1 = count($eshop_products_unser1);
1011
+ if ($check_attr_count1 == 1) {
1012
+ $eshop_products_unser2 = unserialize($eshop_products_unser1);
1013
+ $check_attr_count2 = count($eshop_products_unser2);
1014
+ }
1015
+ if ($check_attr_count1 < $check_attr_count2) {
1016
+ $unserialized_attributes = $eshop_products_unser2;
1017
+ } else {
1018
+ $unserialized_attributes = $eshop_products_unser1;
1019
+ }
1020
+
1021
+ foreach ($unserialized_attributes as $key) {
1022
+ foreach ($key as $attr_header => $attr_value) {
1023
+ if ($attr_header == 'name') {
1024
+ $product_attribute_name .= $attr_value . '|';
1025
+ }
1026
+ if ($attr_header == 'value') {
1027
+ $product_attribute_value .= $attr_value . '|';
1028
+ }
1029
+ if ($attr_header == 'is_visible') {
1030
+ $product_attribute_visible .= $attr_value . '|';
1031
+ }
1032
+ if ($attr_header == 'is_variation') {
1033
+ if (isset($attr_value)) {
1034
+ $product_attribute_variation .= $attr_value . '|';
1035
+ }
1036
+ }
1037
+ }
1038
+ }
1039
+ $PostMetaData[$postmeta->post_id]['_product_attribute_name'] = substr($product_attribute_name, 0, -1);
1040
+ $PostMetaData[$postmeta->post_id]['_product_attribute_value'] = substr($product_attribute_value, 0, -1);
1041
+ $PostMetaData[$postmeta->post_id]['_product_attribute_visible'] = substr($product_attribute_visible, 0, -1);
1042
+ $PostMetaData[$postmeta->post_id]['_product_attribute_variation'] = substr($product_attribute_variation, 0, -1);
1043
+ }
1044
+ $upsellids = array();
1045
+ $crosssellids = array();
1046
+ #TODO: $upsellids, $crosssellids not used in this function / overwritten immediately
1047
+ if ($postmeta->meta_key == '_upsell_ids') {
1048
+ if ($postmeta->meta_value != '' && $postmeta->meta_value != null) {
1049
+ $upsellids = unserialize($postmeta->meta_value);
1050
+ if (is_array($upsellids)) {
1051
+ $upsell_ids = null;
1052
+ foreach ($upsellids as $upsellID) {
1053
+ $upsell_ids .= $upsellID . ',';
1054
+ }
1055
+ $PostMetaData[$postmeta->post_id]['_upsell_ids'] = substr($upsell_ids, 0, -1);
1056
+ } else {
1057
+ $PostMetaData[$postmeta->post_id]['_upsell_ids'] = '';
1058
+ }
1059
+ }
1060
+ }
1061
+ if ($postmeta->meta_key == '_crosssell_ids') {
1062
+ if ($postmeta->meta_value != '' && $postmeta->meta_value != null) {
1063
+ $crosssellids = unserialize($postmeta->meta_value);
1064
+ if (is_array($crosssellids)) {
1065
+ $crosssell_ids = null;
1066
+ foreach ($crosssellids as $crosssellID) {
1067
+ $crosssell_ids .= $crosssellID . ',';
1068
+ }
1069
+ $PostMetaData[$postmeta->post_id]['_crosssell_ids'] = substr($crosssell_ids, 0, -1);
1070
+ } else {
1071
+ $PostMetaData[$postmeta->post_id]['_crosssell_ids'] = '';
1072
+ }
1073
+ }
1074
+ }
1075
+ if ($postmeta->meta_key == '_thumbnail_id') {
1076
+ $attachment_file = '';
1077
+ $get_attachement = "select guid from wp_posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
1078
+ $attachment = $wpdb->get_results($get_attachement);
1079
+ $attachment_file = $attachment[0]->guid;
1080
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
1081
+ $postmeta->meta_key = 'featured_image';
1082
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
1083
+ }
1084
+ if ($postmeta->meta_key == '_visibility') {
1085
+ if ($postmeta->meta_value == 'visible') {
1086
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
1087
+ }
1088
+ if ($postmeta->meta_value == 'catalog') {
1089
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
1090
+ }
1091
+ if ($postmeta->meta_value == 'search') {
1092
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
1093
+ }
1094
+ if ($postmeta->meta_value == 'hidden') {
1095
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 4;
1096
+ }
1097
+ }
1098
+ if ($postmeta->meta_key == '_stock_status') {
1099
+ if ($postmeta->meta_value == 'instock') {
1100
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
1101
+ }
1102
+ if ($postmeta->meta_value == 'outofstock') {
1103
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
1104
+ }
1105
+ }
1106
+ if ($postmeta->meta_key == '_tax_status') {
1107
+ if ($postmeta->meta_value == 'taxable') {
1108
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
1109
+ }
1110
+ if ($postmeta->meta_value == 'shipping') {
1111
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
1112
+ }
1113
+ if ($postmeta->meta_value == 'none') {
1114
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
1115
+ }
1116
+ }
1117
+ if ($postmeta->meta_key == '_tax_class') {
1118
+ if ($postmeta->meta_value == '') {
1119
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
1120
+ }
1121
+ if ($postmeta->meta_value == 'reduced-rate') {
1122
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
1123
+ }
1124
+ if ($postmeta->meta_value == 'zero-rate') {
1125
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
1126
+ }
1127
+ }
1128
+ if ($postmeta->meta_key == '_backorders') {
1129
+ if ($postmeta->meta_value == 'no') {
1130
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 1;
1131
+ }
1132
+ if ($postmeta->meta_value == 'notify') {
1133
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 2;
1134
+ }
1135
+ if ($postmeta->meta_value == 'yes') {
1136
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = 3;
1137
+ }
1138
+ }
1139
+ if ($postmeta->meta_key == '_featured') {
1140
+ if ($postmeta->meta_value == 'no') {
1141
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 1;
1142
+ }
1143
+ if ($postmeta->meta_value == 'yes') {
1144
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 2;
1145
+ }
1146
+ if ($postmeta->meta_value == 'zero-rate') {
1147
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 3;
1148
+ }
1149
+ }
1150
+ if ($postmeta->meta_key == '_product_type') {
1151
+ if ($postmeta->meta_value == 'simple') {
1152
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 1;
1153
+ }
1154
+ if ($postmeta->meta_value == 'grouped') {
1155
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 2;
1156
+ }
1157
+ if ($postmeta->meta_value == 'variable') {
1158
+ $PostMetaData[$postmeta->post_id]['featured_product'] = 4;
1159
+ }
1160
+ }
1161
+ }
1162
+
1163
+ }
1164
+ // Tags & Categories
1165
+ $postTags = $postCategory = '';
1166
+ $taxonomies = get_object_taxonomies($exporttype);
1167
+ $get_tags = get_the_terms($postID, 'product_tag');
1168
+ if ($get_tags) {
1169
+ foreach ($get_tags as $tags) {
1170
+ $postTags .= $tags->name . ',';
1171
+ }
1172
+ }
1173
+ $postTags = substr($postTags, 0, -1);
1174
+ $TermsData[$postID]['product_tag'] = $postTags;
1175
+ foreach ($taxonomies as $taxonomy) {
1176
+ if ($taxonomy == 'product_cat') {
1177
+ $get_categotries = wp_get_post_terms($postID, $taxonomy);
1178
+ if ($get_categotries) {
1179
+ foreach ($get_categotries as $category) {
1180
+ $postCategory .= $category->name . '|';
1181
+ }
1182
+ }
1183
+ $postCategory = substr($postCategory, 0, -1);
1184
+ $TermsData[$postID]['product_category'] = $postCategory;
1185
+ }
1186
+ }
1187
+ }
1188
+
1189
+ $ExportData = array();
1190
+ // Merge all arrays
1191
+ foreach ($PostData as $pd_key => $pd_val) {
1192
+ if (array_key_exists($pd_key, $PostMetaData)) {
1193
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
1194
+ }
1195
+ if (array_key_exists($pd_key, $TermsData)) {
1196
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
1197
+ }
1198
+ }
1199
+ foreach ($Header as $header_key) {
1200
+ foreach ($ExportData as $ED_key) {
1201
+ if (array_key_exists($header_key, $ED_key)) {
1202
+ $CSVContent[$header_key][] = $ED_key[$header_key];
1203
+ } else {
1204
+ $CSVContent[$header_key][] = '';
1205
+ }
1206
+ }
1207
+ }
1208
+ }
1209
+ # GENERATE AS CSV
1210
+ $CSVDATA = array();
1211
+ for ($j = 0; $j < $fieldsCount; $j++) {
1212
+ foreach ($Header as $value) {
1213
+ $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '",';
1214
+ }
1215
+ }
1216
+ $CSV_FILE_CONTENT = array();
1217
+ foreach ($Header as $csv_header) {
1218
+ if ($csv_header == 'post_title') {
1219
+ $csv_header = 'product_name';
1220
+ }
1221
+ if ($csv_header == 'post_content') {
1222
+ $csv_header = 'product_content';
1223
+ }
1224
+ if ($csv_header == 'post_name') {
1225
+ $csv_header = 'product_slug';
1226
+ }
1227
+ if ($csv_header == 'post_excerpt') {
1228
+ $csv_header = 'product_short_description';
1229
+ }
1230
+ if ($csv_header == 'post_status') {
1231
+ $csv_header = 'product_status';
1232
+ }
1233
+ if ($csv_header == 'post_date') {
1234
+ $csv_header = 'product_publish_date';
1235
+ }
1236
+ if ($csv_header == '_product_type') {
1237
+ $csv_header = 'product_type';
1238
+ }
1239
+ if ($csv_header == '_product_shipping_class') {
1240
+ $csv_header = 'product_shipping_class';
1241
+ }
1242
+ if ($csv_header == '_visibility') {
1243
+ $csv_header = 'visibility';
1244
+ }
1245
+ if ($csv_header == '_stock_status') {
1246
+ $csv_header = 'stock_status';
1247
+ }
1248
+ if ($csv_header == '_manage_stock') {
1249
+ $csv_header = 'manage_stock';
1250
+ }
1251
+ if ($csv_header == '_total_sales') {
1252
+ $csv_header = 'total_sales';
1253
+ }
1254
+ if ($csv_header == '_downloadable') {
1255
+ $csv_header = 'downloadable';
1256
+ }
1257
+ if ($csv_header == '_virtual') {
1258
+ $csv_header = 'virtual';
1259
+ }
1260
+ if ($csv_header == '_product_image_gallery') {
1261
+ $csv_header = 'product_image_gallery';
1262
+ }
1263
+ if ($csv_header == '_regular_price') {
1264
+ $csv_header = 'regular_price';
1265
+ }
1266
+ if ($csv_header == '_sale_price') {
1267
+ $csv_header = 'sale_price';
1268
+ }
1269
+ if ($csv_header == '_tax_status') {
1270
+ $csv_header = 'tax_status';
1271
+ }
1272
+ if ($csv_header == '_tax_class') {
1273
+ $csv_header = 'tax_class';
1274
+ }
1275
+ if ($csv_header == '_purchase_note') {
1276
+ $csv_header = 'purchase_note';
1277
+ }
1278
+ if ($csv_header == '_featured') {
1279
+ $csv_header = 'featured_product';
1280
+ }
1281
+ if ($csv_header == '_weight') {
1282
+ $csv_header = 'weight';
1283
+ }
1284
+ if ($csv_header == '_length') {
1285
+ $csv_header = 'length';
1286
+ }
1287
+ if ($csv_header == '_width') {
1288
+ $csv_header = 'width';
1289
+ }
1290
+ if ($csv_header == '_height') {
1291
+ $csv_header = 'height';
1292
+ }
1293
+ if ($csv_header == '_sku') {
1294
+ $csv_header = 'sku';
1295
+ }
1296
+ if ($csv_header == '_upsell_ids') {
1297
+ $csv_header = 'upsell_ids';
1298
+ }
1299
+ if ($csv_header == '_crosssell_ids') {
1300
+ $csv_header = 'crosssell_ids';
1301
+ }
1302
+ if ($csv_header == '_product_attribute_name') {
1303
+ $csv_header = 'product_attribute_name';
1304
+ }
1305
+ if ($csv_header == '_product_attribute_value') {
1306
+ $csv_header = 'product_attribute_value';
1307
+ }
1308
+ if ($csv_header == '_product_attribute_visible') {
1309
+ $csv_header = 'product_attribute_visible';
1310
+ }
1311
+ if ($csv_header == '_product_attribute_variation') {
1312
+ $csv_header = 'product_attribute_variation';
1313
+ }
1314
+ if ($csv_header == '_sale_price_dates_from') {
1315
+ $csv_header = 'sale_price_dates_from';
1316
+ }
1317
+ if ($csv_header == '_sale_price_dates_to') {
1318
+ $csv_header = 'sale_price_dates_to';
1319
+ }
1320
+ if ($csv_header == '_price') {
1321
+ $csv_header = 'price';
1322
+ }
1323
+ if ($csv_header == '_stock') {
1324
+ $csv_header = 'stock';
1325
+ }
1326
+ if ($csv_header == '_backorders') {
1327
+ $csv_header = 'backorders';
1328
+ }
1329
+ if ($csv_header == '_file_paths') {
1330
+ $csv_header = 'file_paths';
1331
+ }
1332
+ if ($csv_header == '_download_limit') {
1333
+ $csv_header = 'download_limit';
1334
+ }
1335
+ if ($csv_header == '_download_expiry') {
1336
+ $csv_header = 'download_expiry';
1337
+ }
1338
+ if ($csv_header == '_product_url') {
1339
+ $csv_header = 'product_url';
1340
+ }
1341
+ if ($csv_header == '_button_text') {
1342
+ $csv_header = 'button_text';
1343
+ }
1344
+ if ($csv_header == '_sold_individually') {
1345
+ $csv_header = 'sold_individually';
1346
+ }
1347
+ if ($csv_header == '_aioseop_keywords') {
1348
+ $csv_header = 'seo_keywords';
1349
+ }
1350
+ if ($csv_header == '_aioseop_description') {
1351
+ $csv_header = 'seo_description';
1352
+ }
1353
+ if ($csv_header == '_aioseop_title') {
1354
+ $csv_header = 'seo_title';
1355
+ }
1356
+ if ($csv_header == '_aioseop_noindex') {
1357
+ $csv_header = 'seo_noindex';
1358
+ }
1359
+ if ($csv_header == '_aioseop_nofollow') {
1360
+ $csv_header = 'seo_nofollow';
1361
+ }
1362
+ if ($csv_header == '_aioseop_disable') {
1363
+ $csv_header = 'seo_disable';
1364
+ }
1365
+ if ($csv_header == '_aioseop_disable_analytics') {
1366
+ $csv_header = 'seo_disable_analytics';
1367
+ }
1368
+ if ($csv_header == '_yoast_wpseo_focuskw') {
1369
+ $csv_header = 'focus_keyword';
1370
+ }
1371
+ if ($csv_header == '_yoast_wpseo_title') {
1372
+ $csv_header = 'title';
1373
+ }
1374
+ if ($csv_header == '_yoast_wpseo_metadesc') {
1375
+ $csv_header = 'meta_desc';
1376
+ }
1377
+ if ($csv_header == '_yoast_wpseo_meta-robots-noindex') {
1378
+ $csv_header = 'meta-robots-noindex';
1379
+ }
1380
+ if ($csv_header == '_yoast_wpseo_meta-robots-nofollow') {
1381
+ $csv_header = 'meta-robots-nofollow';
1382
+ }
1383
+ if ($csv_header == '_yoast_wpseo_meta-robots-adv') {
1384
+ $csv_header = 'meta-robots-adv';
1385
+ }
1386
+ if ($csv_header == '_yoast_wpseo_sitemap-include') {
1387
+ $csv_header = 'sitemap-include';
1388
+ }
1389
+ if ($csv_header == '_yoast_wpseo_sitemap-prio') {
1390
+ $csv_header = 'sitemap-prio';
1391
+ }
1392
+ if ($csv_header == '_yoast_wpseo_canonical') {
1393
+ $csv_header = 'canonical';
1394
+ }
1395
+ if ($csv_header == '_yoast_wpseo_redirect') {
1396
+ $csv_header = 'redirect';
1397
+ }
1398
+ if ($csv_header == '_yoast_wpseo_opengraph-description') {
1399
+ $csv_header = 'opengraph-description';
1400
+ }
1401
+ if ($csv_header == '_yoast_wpseo_google-plus-description') {
1402
+ $csv_header = 'google-plus-description';
1403
+ }
1404
+ $CSV_FILE_CONTENT .= $csv_header . ",";
1405
+ }
1406
+ $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
1407
+ $CSV_FILE_CONTENT .= "\n";
1408
+ if ($CSVDATA) {
1409
+ foreach ($CSVDATA as $csv_content) {
1410
+ $csv_content = substr($csv_content, 0, -1);
1411
+ $CSV_FILE_CONTENT .= $csv_content . "\n";
1412
+ }
1413
+ }
1414
+ }
1415
+ #TODO: What is this?
1416
+ echo '<pre>';
1417
+ print_r($CSV_FILE_CONTENT);
1418
+ die('it exiusrs');
1419
+ header("Content-type: text/x-csv"); # DECLARING FILE TYPE
1420
+ header("Content-Transfer-Encoding: binary");
1421
+ header("Content-Disposition: attachment; filename=" . $csv_file_name); # EXPORT GENERATED CSV FILE
1422
+ header("Pragma: no-cache");
1423
+ header("Expires: 0");
1424
+ print($CSV_FILE_CONTENT);
1425
+ die;
1426
+ return $data;
1427
+ }
1428
+ }
modules/old_export/templates/export.php ADDED
@@ -0,0 +1,663 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /******************************************************************************************
3
+ * Copyright (C) Smackcoders 2014 - All Rights Reserved
4
+ * Unauthorized copying of this file, via any medium is strictly prohibited
5
+ * Proprietary and confidential
6
+ * You can contact Smackcoders at email address info@smackcoders.com.
7
+ *******************************************************************************************/
8
+
9
+ require_once('../../../../../../wp-load.php');
10
+ require_once('../../../includes/Importer.php');
11
+
12
+ $ExportObj = new WPCSVProExportData();
13
+ #print('<pre>'); print_r($_POST); //die;
14
+ $ExportObj->executeIndex($_POST);
15
+ class WPCSVProExportData {
16
+ public function __construct() {
17
+
18
+ }
19
+
20
+ /**
21
+ * The actions index method
22
+ * @param array $request
23
+ * @return array
24
+ */
25
+ public function executeIndex($request) {
26
+ #print('<pre>'); print_r($request); print('</pre>'); die;
27
+ if($request['export'] == 'category') {
28
+ $this->WPImpExportCategories($request);
29
+ }
30
+ else if($request['export'] == 'tags') {
31
+ $this->WPImpExportTags($request);
32
+ }
33
+ else if($request['export'] == 'customtaxonomy') {
34
+ $this->WPImpExportTaxonomies($request);
35
+ }
36
+ else if($request['export'] == 'customerreviews') {
37
+ $this->WPImpExportCustomerReviews($request);
38
+ }
39
+ else if($request['export'] == 'comments') {
40
+ $this->WPImpExportComments($request);
41
+ }
42
+ else if($request['export'] == 'users') {
43
+ $this->WPImpExportUsers($request);
44
+ }
45
+ else {
46
+ $this->WPImpFreeExportData($request);#die;
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ */
53
+ public function generateCSVHeaders($exporttype){
54
+ global $wpdb;
55
+ $post_type = $exporttype;
56
+ $unwantedHeader = array('_eshop_product', '_wp_attached_file', '_wp_page_template', '_wp_attachment_metadata', '_encloseme');
57
+ if($exporttype == 'eshop')
58
+ $post_type = 'post';
59
+ if($exporttype == 'custompost') {
60
+ $post_type = $_POST['export_post_type'];
61
+ }
62
+ $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$post_type'";
63
+ $header_query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') and meta_key NOT LIKE 'field_%' and meta_key NOT LIKE '_wp_types%'";
64
+ $result_header_query1 = $wpdb->get_results($header_query1);
65
+ $result_header_query2 = $wpdb->get_results($header_query2);
66
+
67
+ foreach ($result_header_query1 as $rhq1_key) {
68
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
69
+ if (!in_array($rhq1_headkey, $Header))
70
+ $Header[] = $rhq1_headkey;
71
+ }
72
+ }
73
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
74
+ $Header[] = $aioseoval;
75
+ $unwantedHeader[] = $aioseokey;
76
+ }
77
+ foreach ($result_header_query2 as $rhq2_headkey) {
78
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
79
+ if(!in_array($rhq2_headkey->meta_key, $unwantedHeader)) {
80
+ $Header[] = $rhq2_headkey->meta_key;
81
+ }
82
+ }
83
+ }
84
+
85
+ #print('<pre>'); print_r($Header); die;
86
+ if($exporttype == 'eshop') {
87
+ foreach($this->EshopHeaders() as $eshop_hkey => $eshop_hval) {
88
+ if(in_array($eshop_hval, $Header))
89
+ $ProHeader[] = $eshop_hkey;
90
+ else
91
+ $ProHeader[] = $eshop_hkey;
92
+ }
93
+
94
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
95
+ $ProHeader[] = $aioseoval;
96
+ }
97
+ return $ProHeader;
98
+ }
99
+ if(!in_array('', $Header) && !in_array('', $Header)){
100
+ $Header[] = 'post_tag';
101
+ $Header[] = 'post_category';
102
+ }
103
+ return $Header;
104
+ }
105
+
106
+ /**
107
+ *
108
+ */
109
+ public function get_all_record_ids($exporttype, $request) {
110
+ global $wpdb;
111
+ $post_type = $exporttype;
112
+ $get_post_ids = "select DISTINCT ID from $wpdb->posts p join $wpdb->postmeta pm on pm.post_id = p.ID";
113
+ if($post_type == 'eshop')
114
+ $post_type = 'post';
115
+ if($post_type == 'custompost')
116
+ $post_type = $_POST['export_post_type'];
117
+
118
+ $get_post_ids .= " where p.post_type = '$post_type'";
119
+ if(isset($request['getdatawithspecificstatus'])) {
120
+ if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'All') {
121
+ $get_post_ids .= " and p.post_status in ('publish','draft','future','private','pending')";
122
+ } else if(isset($request['postwithstatus']) && ($request['postwithstatus'] == 'Publish' || $request['postwithstatus'] == 'Sticky')) {
123
+ $get_post_ids .= " and p.post_status in ('publish')";
124
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Draft') {
125
+ $get_post_ids .= " and p.post_status in ('draft')";
126
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Scheduled') {
127
+ $get_post_ids .= " and p.post_status in ('future')";
128
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Private') {
129
+ $get_post_ids .= " and p.post_status in ('private')";
130
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Pending') {
131
+ $get_post_ids .= " and p.post_status in ('pending')";
132
+ } else if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Protected') {
133
+ $get_post_ids .= " and p.post_status in ('publish') and post_password != ''";
134
+ }
135
+ } else {
136
+ $get_post_ids .= " and p.post_status in ('publish','draft','future','private','pending')";
137
+ }
138
+ if(isset($request['getdataforspecificperiod'])) {
139
+ $get_post_ids .= " and p.post_date >= '" . $request['postdatefrom'] . "' and p.post_date <= '" . $request['postdateto'] . "'";
140
+ }
141
+ if($exporttype == 'eshop')
142
+ $get_post_ids .= " and pm.meta_key = 'sku'";
143
+
144
+ if(isset($request['getdatabyspecificauthors'])) {
145
+ if(isset($request['postauthor']) && $request['postauthor'] != 0) {
146
+ $get_post_ids .= " and p.post_author = {$request['postauthor']}";
147
+ }
148
+ }
149
+ #print_r($get_post_ids); die;
150
+ $result = $wpdb->get_col($get_post_ids);
151
+ if(isset($request['getdatawithspecificstatus'])) {
152
+ if(isset($request['postwithstatus']) && $request['postwithstatus'] == 'Sticky') {
153
+ $get_sticky_posts = get_option('sticky_posts');
154
+ foreach($get_sticky_posts as $sticky_post_id) {
155
+ if(in_array($sticky_post_id, $result))
156
+ $sticky_posts[] = $sticky_post_id;
157
+ }
158
+ return $sticky_posts;
159
+ }
160
+ }
161
+ #print_r($get_sticky_posts);
162
+ #print_r($result);die;
163
+ return $result;
164
+ }
165
+
166
+ /**
167
+ *
168
+ */
169
+ public function getPostDatas($postID) {
170
+ global $wpdb;
171
+ $query1 = "SELECT wp.* FROM $wpdb->posts wp where ID=$postID";
172
+ $result_query1 = $wpdb->get_results($query1);
173
+ if (!empty($result_query1)) {
174
+ foreach ($result_query1 as $posts) {
175
+ foreach ($posts as $post_key => $post_value) {
176
+ if ($post_key == 'post_status') {
177
+ if (is_sticky($postID)) {
178
+ $PostData[$post_key] = 'Sticky';
179
+ $post_status = 'Sticky';
180
+ } else {
181
+ $PostData[$post_key] = $post_value;
182
+ $post_status = $post_value;
183
+ }
184
+ } else {
185
+ $PostData[$post_key] = $post_value;
186
+ }
187
+ if ($post_key == 'post_password') {
188
+ if ($post_value) {
189
+ $PostData['post_status'] = "{" . $post_value . "}";
190
+ } else {
191
+ $PostData['post_status'] = $post_status;
192
+ }
193
+ }
194
+ if ($post_key == 'comment_status') {
195
+ if ($post_value == 'closed') {
196
+ $PostData['comment_status'] = 0;
197
+ }
198
+ if ($post_value == 'open') {
199
+ $PostData['comment_status'] = 1;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ }
205
+ return $PostData;
206
+ }
207
+
208
+ /**
209
+ *
210
+ */
211
+ public function getPostMetaDatas($postID) {
212
+ global $wpdb;
213
+ $query2 = "SELECT post_id, meta_key, meta_value FROM $wpdb->posts wp JOIN $wpdb->postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last') AND ID=$postID";
214
+ #print($query2); print('<br>');
215
+ $result = $wpdb->get_results($query2);
216
+ return $result;
217
+ }
218
+
219
+ /**
220
+ *
221
+ */
222
+ public function getAIOSEOfields() {
223
+ $aioseofields = array('_aioseop_keywords' => 'seo_keywords',
224
+ '_aioseop_description' => 'seo_description',
225
+ '_aioseop_title' => 'seo_title',
226
+ '_aioseop_noindex' => 'seo_noindex',
227
+ '_aioseop_nofollow' => 'seo_nofollow',
228
+ '_aioseop_disable' => 'seo_disable',
229
+ '_aioseop_disable_analytics' => 'seo_disable_analytics',
230
+ '_aioseop_noodp' => 'seo_noodp',
231
+ '_aioseop_noydir' => 'seo_noydir',);
232
+ return $aioseofields;
233
+ }
234
+
235
+ /**
236
+ *
237
+ */
238
+ public function getAllTerms($postID, $type) {
239
+ // Tags & Categories
240
+ $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
241
+ $postTags = $postCategory = '';
242
+ foreach ($get_tags as $tags) {
243
+ $postTags .= $tags . ',';
244
+ }
245
+ $postTags = substr($postTags, 0, -1);
246
+ $TermsData['post_tag'] = $postTags;
247
+ $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
248
+ foreach ($get_categotries as $category) {
249
+ $postCategory .= $category . '|';
250
+ }
251
+ $postCategory = substr($postCategory, 0, -1);
252
+ $TermsData['post_category'] = $postCategory;
253
+ return $TermsData;
254
+ }
255
+
256
+ /**
257
+ *
258
+ */
259
+ public function EshopHeaders() {
260
+ $eshopHeaders = array('post_title' => 'post_title', 'post_content' => 'post_content', 'post_excerpt' => 'post_excerpt', 'post_date' => 'post_date', 'post_name' => 'post_name', 'post_status' => 'post_status', 'post_author' => 'post_author', 'post_parent' => 0, 'comment_status' => 'open', 'ping_status' => 'open', 'SKU' => 'sku', 'products_option' => 'products_option', 'sale_price' => 'sale_price', 'regular_price' => 'regular_price', 'description' => 'description', 'shiprate' => 'shiprate', 'optset' => null, 'featured_product' => 'featured', 'product_in_sale' => '_eshop_sale', 'stock_available' => '_eshop_stock', 'cart_option' => 'cart_radio', 'category' => 'post_category', 'tags' => 'post_tag', 'featured_image' => null,);
261
+ return $eshopHeaders;
262
+ }
263
+
264
+ /**
265
+ * @param $request
266
+ * @return array
267
+ */
268
+ public function WPImpFreeExportData($request) {
269
+ #print('<pre>'); print_r($this->getACFvalues()); die;
270
+ global $wpdb;
271
+ $export_delimiter = ',';
272
+ $exporttype = $_POST['export'];
273
+ $wpcsvsettings=get_option('wpcsvprosettings');
274
+ if(isset($wpcsvsettings['export_delimiter'])){
275
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
276
+ }
277
+ if($_POST['export_filename'])
278
+ $csv_file_name =$_POST['export_filename'].'.csv';
279
+ else
280
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
281
+ $wptypesfields = get_option('wpcf-fields');
282
+ #print('<pre>'); print_r($wptypesfields); die;
283
+ #print('<pre>'); print_r($_POST); print('</pre>');
284
+ //if($exporttype=='post' || $exporttype=='page' || $exporttype=='custompost') {
285
+ if($exporttype == 'custompost') {
286
+ $exporttype = $_POST['export_post_type'];
287
+ }
288
+ $Header = $this->generateCSVHeaders($exporttype);
289
+ $result = $this->get_all_record_ids($exporttype, $request);
290
+ #print('<pre>'); print_r($Header); print_r($result); print('</pre>'); die;
291
+ $fieldsCount = count($result);
292
+ if ($result) {
293
+ foreach ($result as $postID) {
294
+ $pId = $pId . ',' . $postID;
295
+ $PostData[$postID] = $this->getPostDatas($postID);
296
+ #print('<pre>'); print_r($PostData); #die;
297
+ $result_query2 = $this->getPostMetaDatas($postID);
298
+ #print('<pre>'); print_r($result_query2); print('</pre>'); #die;
299
+
300
+ $possible_values = array('s:', 'a:', ':{');
301
+ if (!empty($result_query2)) {
302
+ foreach ($result_query2 as $postmeta) {
303
+ $typesFserialized = 0;
304
+ $isFound = explode('wpcf-',$postmeta->meta_key);
305
+ if(count($isFound) == 2){
306
+ foreach($wptypesfields as $typesKey => $typesVal){
307
+ if($postmeta->meta_key == 'wpcf-'.$typesKey){
308
+ foreach($possible_values as $posval){
309
+ if(strpos($postmeta->meta_value,$posval)){
310
+ $typesFserialized = 1;
311
+ } else {
312
+ $typesFserialized = 0;
313
+ }
314
+ }
315
+ if($typesFserialized == 1){
316
+ $getMetaData = get_post_meta($postID, $postmeta->meta_key);
317
+ if(!is_array($getMetaData[0])){
318
+ $get_all_values = unserialize($getMetaData[0]);
319
+ $get_values = $get_all_values[0];
320
+ } else {
321
+ $get_values = $getMetaData[0];
322
+ }
323
+ $typesFVal = null;
324
+ if($typesVal['type'] == 'checkboxes'){
325
+ foreach($get_values as $authorKey => $authorVal) {
326
+ foreach($typesVal['data']['options'] as $doKey => $doVal){
327
+ if($doKey == $authorKey)
328
+ $typesFVal .= $doVal['title'].',';
329
+ }
330
+ }
331
+ $typesFVal = substr($typesFVal, 0, -1);
332
+ } elseif($typesVal['type'] == 'skype') {
333
+ $typesFVal = $get_values['skypename'];
334
+ }
335
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $typesFVal;
336
+ } else {
337
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
338
+ }
339
+ }
340
+ }
341
+ } else {
342
+ // Eshop product meta datas starts here
343
+ if ($postmeta->meta_key == 'featured') {
344
+ $isFeatured = strtolower($postmeta->meta_value);
345
+ $PostMetaData[$postmeta->post_id]['featured_product'] = $isFeatured;
346
+ }
347
+ else if ($postmeta->meta_key == 'sale') {
348
+ $is_prod_sale = strtolower($postmeta->meta_value);
349
+ $PostMetaData[$postmeta->post_id]['product_in_sale'] = $is_prod_sale;
350
+ }
351
+ else if ($postmeta->meta_key == '_eshop_stock') {
352
+ if($postmeta->meta_value == 1) {
353
+ $stock_available = 'yes';
354
+ } else {
355
+ $stock_available = 'no';
356
+ }
357
+ $PostMetaData[$postmeta->post_id]['stock_available'] = $stock_available;
358
+ }
359
+ else if ($postmeta->meta_key == 'cart_radio') {
360
+ $PostMetaData[$postmeta->post_id]['cart_option'] = $postmeta->meta_value;
361
+ }
362
+ else if ($postmeta->meta_key == 'shiprate') {
363
+ $PostMetaData[$postmeta->post_id]['shiprate'] = $postmeta->meta_value;
364
+ }
365
+ else if ($postmeta->meta_key == '_eshop_product') {
366
+ $product_attr_details = unserialize($postmeta->meta_value);
367
+ $prod_option = $sale_price = $reg_price = null;
368
+ #print('<pre>');print_r($product_attr_details); #die;
369
+ foreach($product_attr_details as $prod_att_det_Key => $prod_att_det_Val) {
370
+ if($prod_att_det_Key == 'sku') {
371
+ $PostMetaData[$postmeta->post_id]['sku'] = $prod_att_det_Val;
372
+ }
373
+ else if($prod_att_det_Key == 'products') {
374
+ foreach($prod_att_det_Val as $all_prod_options) {
375
+ $prod_option .= $all_prod_options['option'] . ',';
376
+ $sale_price .= $all_prod_options['saleprice'] . ',';
377
+ $reg_price .= $all_prod_options['price'] . ',';
378
+ }
379
+ $prod_option = substr($prod_option, 0, -1);
380
+ $sale_price = substr($sale_price, 0, -1);
381
+ $reg_price = substr($reg_price, 0, -1);
382
+ $PostMetaData[$postmeta->post_id]['products_option'] = $prod_option;
383
+ $PostMetaData[$postmeta->post_id]['sale_price'] = $sale_price;
384
+ $PostMetaData[$postmeta->post_id]['regular_price'] = $reg_price;
385
+ }
386
+ }
387
+ #$PostMetaData[$postmeta->post_id]['cart_option'] = $postmeta->meta_value;
388
+ }
389
+ // Eshop product meta datas ends here
390
+ else if ($postmeta->meta_key == '_thumbnail_id') {
391
+ $attachment_file = '';
392
+ $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
393
+ $attachment = $wpdb->get_results($get_attachement);
394
+ $attachment_file = $attachment[0]->guid;
395
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
396
+ $postmeta->meta_key = 'featured_image';
397
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
398
+ }
399
+ else if(is_array($checkbox_option_fields) && in_array($postmeta->meta_key,$checkbox_option_fields)){
400
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
401
+ $eshop_products = unserialize($eshop_products); //print_r($eshop_products);
402
+ foreach ($eshop_products as $key) {
403
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key . ',';
404
+ }
405
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
406
+ }
407
+ else {
408
+ $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
409
+ }
410
+ }
411
+ }
412
+ }
413
+ # print('PostMetaData: '); print('<pre>'); print_r($Header); print_r($PostMetaData); #die;
414
+ $TermsData[$postID] = $this->getAllTerms($postID,$exporttype);
415
+ }
416
+
417
+ #$ExportData = array();
418
+ // Merge all arrays
419
+ #echo '<pre>'; print_r($TermsData); die;
420
+ // echo '<pre>'; print_r($PostData); die('sds');
421
+ foreach ($PostData as $pd_key => $pd_val) {
422
+ if (array_key_exists($pd_key, $PostMetaData)) {
423
+ $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
424
+ // echo '<pre>'; print_r($ExportData); die('exist');
425
+ } else {
426
+ $ExportData[$pd_key] = $PostData[$pd_key];
427
+ }
428
+ if (array_key_exists($pd_key, $TermsData)) {
429
+ if (empty($ExportData[$pd_key]))
430
+ $ExportData[$pd_key] = array();
431
+ $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
432
+ }
433
+ }
434
+ }
435
+ #print('<pre>'); print_r($Header); die;
436
+ #print('<pre>'); print_r($ExportData); die;
437
+ if($exporttype == 'eshop') {
438
+ foreach($Header as $hkey) {
439
+ foreach($ExportData as $edkey => $edval) {
440
+ foreach($this->EshopHeaders() as $eshophkey => $eshophval) {
441
+ if(array_key_exists($eshophval, $ExportData[$edkey])) {
442
+ $ExportData[$edkey][$eshophkey] = $edval[$eshophval];
443
+ // unset($ExportData[$edkey][$wpcomhval]);
444
+ }
445
+ }
446
+ }
447
+ }
448
+ }
449
+ #print('<pre>'); print_r($Header); print('</pre>'); #die;
450
+ # print('<pre>'); print_r($ExportData); die;
451
+ foreach ($Header as $header_key) {
452
+ if (is_array($ExportData)) {
453
+ foreach ($ExportData as $ED_key => $ED_val) {
454
+ if (in_array($header_key, $this->getAIOSEOfields())) { #die($header_key);
455
+ foreach($this->getAIOSEOfields() as $aioseokey => $aioseoval) {
456
+ $CSVContent[$ED_key][$aioseoval] = $ED_val[$aioseokey];
457
+ #unset($CSVContent[$ED_key][$header_key]);
458
+ }
459
+ } else if (array_key_exists($header_key, $ED_val)) {
460
+ $CSVContent[$ED_key][$header_key] = $ED_val[$header_key];
461
+ } else {
462
+ $CSVContent[$ED_key][$header_key] = null;
463
+ }
464
+ }
465
+ }
466
+ }
467
+ #print(count($CSVContent[22]));print('<br>' . count($Header));
468
+ #print('<pre>'); print_r($CSVContent) ;print('</pre>'); die;
469
+ $csv = new ImporterLib();
470
+ $csv->wmyuyn_3 ($csv_file_name, $CSVContent, $Header, $export_delimiter);
471
+ }
472
+
473
+ /**
474
+ *
475
+ */
476
+ public function WPImpExportComments($request) {
477
+ global $wpdb;
478
+ $export_delimiter = ',';
479
+ $exporttype = $request['export'];
480
+ $wpcsvsettings=get_option('wpcsvprosettings');
481
+ if(isset($wpcsvsettings['export_delimiter'])){
482
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
483
+ }
484
+ if($_POST['export_filename'])
485
+ $csv_file_name =$_POST['export_filename'].'.csv';
486
+ else
487
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
488
+
489
+ $commentQuery = "SELECT * FROM $wpdb->comments " . $orderBy;
490
+ $comments = $wpdb->get_results( $commentQuery);
491
+ $mappedHeader = false;
492
+ $i = 0;
493
+ foreach($comments as $comment){
494
+ foreach($comment as $key => $value){
495
+ if(!$mappedHeader){
496
+ $Header[] = $key; // ."$export_delimiter";
497
+ }
498
+ $ExportData[$i][$key] = $value; //'"'.$value.'"'."$export_delimiter";
499
+ }
500
+ $mappedHeader = true;
501
+ $i++;
502
+ }
503
+ #print('<pre>'); print_r($header); print_r($singleCommentContent);die;
504
+ $csv = new ImporterLib();
505
+ $csv->wmyuyn_3 ($csv_file_name, $ExportData, $Header, $export_delimiter);
506
+ }
507
+
508
+ /**
509
+ *
510
+ */
511
+ public function WPImpExportUsers($request) {
512
+ global $wpdb;
513
+ $export_delimiter = ',';
514
+ $exporttype = $request['export'];
515
+ $wpcsvsettings=get_option('wpcsvprosettings');
516
+ if(isset($wpcsvsettings['export_delimiter'])){
517
+ $export_delimiter = $wpcsvsettings['export_delimiter'];
518
+ }
519
+ if($_POST['export_filename'])
520
+ $csv_file_name =$_POST['export_filename'].'.csv';
521
+ else
522
+ $csv_file_name='exportas_'.date("Y").'-'.date("m").'-'.date("d").'.csv';
523
+
524
+ $uId = '';
525
+ $header_query1 = "SELECT *FROM $wpdb->users";
526
+ $header_query2 = "SELECT user_id, meta_key, meta_value FROM $wpdb->users wp JOIN $wpdb->usermeta wpm ON wpm.user_id = wp.ID where meta_key NOT IN ('_edit_lock','_edit_last')";
527
+ $result_header_query1 = $wpdb->get_results($header_query1);
528
+ $result_header_query2 = $wpdb->get_results($header_query2);
529
+ /* print('<pre>'); print_r($result_header_query1);
530
+ print_r($result_header_query2);die; */
531
+ foreach ($result_header_query1 as $rhq1_key) {
532
+ foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
533
+ if (!in_array($rhq1_headkey, $Header))
534
+ $Header[] = $rhq1_headkey;
535
+ }
536
+ }
537
+ foreach ($result_header_query2 as $rhq2_headkey) {
538
+ if (!in_array($rhq2_headkey->meta_key, $Header)) {
539
+ if($rhq2_headkey->meta_key == 'mp_shipping_info' )
540
+ {
541
+ $mp_ship_header= unserialize($rhq2_headkey->meta_value);
542
+ foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "msi: ".$mp_ship_key; }
543
+ }
544
+ if($rhq2_headkey->meta_key == 'mp_billing_info' )
545
+ {
546
+ $mp_ship_header= unserialize($rhq2_headkey->meta_value);
547
+ foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "mbi: ".$mp_ship_key; }
548
+ }
549
+
550
+ if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file' && $rhq2_headkey->meta_key != 'mp_shipping_info' && $rhq2_headkey->meta_key != 'mp_billing_info' )
551
+ $Header[] = $rhq2_headkey->meta_key;
552
+ }
553
+ }
554
+ #echo '<pre>'; print_r($Header); die('dsd');
555
+ $get_user_ids = "select DISTINCT ID from $wpdb->users u join $wpdb->usermeta um on um.user_id = u.ID";
556
+
557
+ $result = $wpdb->get_col($get_user_ids);
558
+ $fieldsCount = count($result);
559
+ if ($result) {
560
+ foreach ($result as $userID) {
561
+ $uId = $uId . ',' . $userID;
562
+ $query1 = "SELECT *FROM $wpdb->users where ID in ($userID);";
563
+ $result_query1 = $wpdb->get_results($query1);
564
+ if (!empty($result_query1)) {
565
+ foreach ($result_query1 as $users) {
566
+ foreach ($users as $user_key => $user_value) {
567
+ $UserData[$userID][$user_key] = $user_value;
568
+ }
569
+ }
570
+ }
571
+ // echo '<pre>'; print_r($UserData); die ('dfdf');
572
+ $query2 = "SELECT user_id, meta_key, meta_value FROM $wpdb->users wp JOIN $wpdb->usermeta wpm ON wpm.user_id = wp.ID where ID=$userID";
573
+ $possible_values = array('s:', 'a:', ':{');
574
+ $result_query2 = $wpdb->get_results($query2);
575
+ if (!empty($result_query2)) {
576
+ foreach ($result_query2 as $usermeta) {
577
+ // echo '<pre>'; print_r($usermeta);
578
+
579
+ foreach($possible_values as $posval){
580
+ if(strpos($usermeta->meta_value,$posval)){
581
+ if($usermeta->meta_key == 'mp_shipping_info' || $usermeta->meta_key == 'mp_billing_info')
582
+ $typesFserialized = 1;
583
+ } else {
584
+ $typesFserialized = 0;
585
+ }
586
+ }
587
+ if($typesFserialized == 1)
588
+ {
589
+ if($usermeta->meta_key == 'mp_shipping_info')
590
+ {
591
+ $UserID = $usermeta->user_id;
592
+ $mp_ship_data = unserialize($usermeta->meta_value);
593
+ foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
594
+ {
595
+ $mp_ship_tempkey = "msi: ".$mp_ship_key;
596
+ $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
597
+ }
598
+ }
599
+
600
+ if($usermeta->meta_key == 'mp_billing_info')
601
+ {
602
+ $UserID = $usermeta->user_id;
603
+ $mp_ship_data = unserialize($usermeta->meta_value);
604
+ foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
605
+ {
606
+ $mp_ship_tempkey = "mbi: ".$mp_ship_key;
607
+ $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
608
+ }
609
+ }
610
+
611
+ if($usermeta->meta_key != 'wp_capabilities' && $usermeta->meta_key !='mp_shipping_info' && $usermeta->meta_key != 'mp_billing_info') {
612
+ $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
613
+ } else {
614
+ if($usermeta->meta_key == 'wp_capabilities') {
615
+ $getUserRole = unserialize($usermeta->meta_value);
616
+ // echo '<pre>'; print_r($getUserRole); die('ddf');
617
+ foreach($getUserRole as $urKey => $urVal) {
618
+ $getUserRole = get_role($urKey);
619
+ }
620
+ $rolelevel = 0;
621
+ $isfound = array();
622
+ foreach($getUserRole->capabilities as $roleKey => $roleVal){
623
+ $isfound = explode('level_', $roleKey);
624
+ if(is_array($isfound) && count($isfound) == 2){
625
+ $rolelevel = $rolelevel + 1;
626
+ }
627
+ } $rolelevel = $rolelevel - 1;
628
+ #$UserData[$userID][$usermeta->meta_key] = $rolelevel;
629
+ }
630
+ }
631
+ } else {
632
+ foreach($possible_values as $posval){
633
+ if(strpos($usermeta->meta_value,$posval)){
634
+ $UserData[$userID][$usermeta->meta_key] = null;
635
+ } else {
636
+ $ifSerialized = 0;
637
+ $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
638
+ }
639
+ }
640
+
641
+ }
642
+ } #echo '<pre>'; print_r($UserData); die('dd');
643
+ }
644
+ }
645
+ }
646
+ $UserHeader = array();
647
+ foreach ($Header as $header_key) {
648
+ foreach ($UserData as $UD_key => $UD_val) {
649
+ if(array_key_exists($header_key, $UD_val)) {
650
+ $CSVContent[$UD_key][$header_key] = $UD_val[$header_key];
651
+ if(!in_array($header_key, $UserHeader))
652
+ $UserHeader[] = $header_key;
653
+ }
654
+ else {
655
+ $CSVContent[$UD_key][$header_key] = null;
656
+ }
657
+ }
658
+ }
659
+
660
+ $csv = new ImporterLib();
661
+ $csv->wmyuyn_3 ($csv_file_name, $CSVContent, $UserHeader, $export_delimiter);
662
+ }
663
+ }
modules/old_export/templates/index.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /******************************************************************************************
3
+ * Copyright (C) Smackcoders 2014 - All Rights Reserved
4
+ * Unauthorized copying of this file, via any medium is strictly prohibited
5
+ * Proprietary and confidential
6
+ * You can contact Smackcoders at email address info@smackcoders.com.
7
+ *******************************************************************************************/
8
+ ?>
9
+ <div class="accordion" id="accordion2" style = 'width:98%;'>
10
+ <div class="accordion-group">
11
+ <div id="collapseTwo" class="accordion-body in collapse">
12
+ <div class="accordion-inner">
13
+ <div class="title">
14
+ <span class="settings-icon"> <img src="<?php echo WP_CONTENT_URL;?>/plugins/<?php echo WP_CONST_ULTIMATE_CSV_IMP_SLUG;?>/images/export.png" width="24" height="24" /> </span>
15
+ <label><h3>Export Data With Advanced Filters</h3></label>
16
+ </div>
17
+
18
+ <div style="margin-top:20px;">
19
+ <div style="display:none;" id="ShowMsg"><p class="alert alert-warning" id="warning-msg"></p></div>
20
+ <form class="form-horizontal" method="post" name="exportmodule" action="<?php echo WP_CONST_ULTIMATE_CSV_IMP_DIR; ?>modules/export/templates/export.php" onsubmit="return export_module();">
21
+ <!-- <form class="form-horizontal" method="post" name="exportmodule" action="" onsubmit="return export_module();"> -->
22
+ <div class="table-responsive">
23
+ <table style='width:100%;' class='table exportmodule'>
24
+ <th colspan='2'><label class='h-exportmodule'><h3 id="innertitle"> To export data based on the filters</h3> </label></th>
25
+ <tr>
26
+ <td><label><input type='checkbox' name='getdataforspecificperiod' id='getdataforspecificperiod' value='getdataforspecificperiod' onclick='addwpexportfilter(this.id);' /><span id="align"> Export data for the specific period</span></label>
27
+ <div id='specificperiodexport' style='padding:10px;display:none;'>
28
+ <label id='periodstartfrom'><b> Start From </b></label>
29
+ <input type='text' class='form-control' name='postdatefrom' style='cursor:default;width:25%;' readonly id='postdatefrom' value='' />
30
+ <label id='periodendto'><b> End To </b></label>
31
+ <input type='text' class='form-control' name='postdateto' style='cursor:default;width:25%;' readonly id='postdateto' value='' />
32
+ </div>
33
+ </td>
34
+ </tr>
35
+ <tr>
36
+ <td><label><input type='checkbox' name='getdatawithspecificstatus' id='getdatawithspecificstatus' value='getdatawithspecificstatus' onclick='addwpexportfilter(this.id);' /> <span id="align">Export data with the specific status</span></label>
37
+ <div id='specificstatusexport' style='padding:10px;display:none;'>
38
+ <label id='status'><b> Status </b></label>
39
+ <select name='postwithstatus' id='postwithstatus'>
40
+ <option>All</option>
41
+ <option>Publish</option>
42
+ <option>Sticky</option>
43
+ <option>Private</option>
44
+ <option>Protected</option>
45
+ <option>Draft</option>
46
+ <option>Pending</option>
47
+ </select>
48
+ </div>
49
+ </td>
50
+ </tr>
51
+ <tr>
52
+ <td><label><input type='checkbox' name='getdatabyspecificauthors' id='getdatabyspecificauthors' value='getdatabyspecificauthors' onclick='addwpexportfilter(this.id);' /><span id="align"> Export data by specific authors</span></label>
53
+ <div id='specificauthorexport' style='padding:10px;display:none;'>
54
+ <label id='authors'><b> Authors </b></label>
55
+ <?php $blogusers = get_users( 'blog_id=1&orderby=nicename' ); ?>
56
+ <select name='postauthor' id='postauthor' >
57
+ <option value='0'>All</option>
58
+ <?php foreach( $blogusers as $user ) { ?>
59
+ <option value='<?php echo esc_html( $user->ID ); ?>'> <?php echo esc_html( $user->display_name ); ?> </option>
60
+ <?php } ?>
61
+ </select>
62
+ </div>
63
+ </td>
64
+ </tr>
65
+ </table>
66
+ <script type = 'text/javascript'>
67
+ jQuery(document).ready(function() {
68
+ jQuery('#postdatefrom').datepicker({
69
+ dateFormat : 'yy-mm-dd'
70
+ });
71
+ jQuery('#postdateto').datepicker({
72
+ dateFormat : 'yy-mm-dd'
73
+ });
74
+ });
75
+ </script>
76
+ </div>
77
+ <div class="table-responsive" id="exporttable">
78
+ <table class='table exportmodule'>
79
+ <th colspan='2'><label class='h-exportmodule'><h3 id="innertitle"> Select your module to export the data</h3> </label></th>
80
+ <tr>
81
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="post" id="post"><span id="align"> Post</span> </label></td>
82
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="eshop" id="eshop"><span id="align"> Eshop</span> </label></td>
83
+ </tr>
84
+ <tr>
85
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="page" id="page"><span id="align"> Page</span> </label></td>
86
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="wpcommerce" id="wpcommerce" onclick="export_check(this.value);"><span id="align"> Wp-Commerce</span> <span class="mandatory">*</span></label></td>
87
+ </tr>
88
+ <tr>
89
+ <td class='exportdatatype'>
90
+ <label> <input type="radio" name="export" value="custompost" id="custompost" ><span id="align"> Custom Post</span> </label>
91
+ <select name="export_post_type" style="margin-left:10px">
92
+ <option>--Select--</option>
93
+ <?php
94
+ foreach (get_post_types() as $key => $value) {
95
+ if (($value != 'featured_image') && ($value != 'attachment') && ($value != 'wpsc-product') && ($value != 'wpsc-product-file') && ($value != 'revision') && ($value != 'nav_menu_item') && ($value != 'post') && ($value != 'page') && ($value != 'wp-types-group') && ($value != 'wp-types-user-group') && ($value != 'product') && ($value != 'product_variation') && ($value != 'shop_order') && ($value != 'shop_coupon') && ($value != 'acf')) {
96
+ ?>
97
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
98
+ <?php
99
+ }
100
+ }
101
+ ?>
102
+ </select>
103
+ </td>
104
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="woocommerce" id="woocommerce" onclick="export_check(this.value);"><span id="align"> Woo-Commerce</span> <span class="mandatory">*</span></label></td>
105
+ </tr>
106
+ <tr>
107
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="category" id="category" onclick="export_check(this.value);"><span id="align"> Category</span><span class="mandatory">*</span></label></td>
108
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="marketpress" id="marketpress" onclick="export_check(this.value);"><span id="align"> Marketpress</span> <span class="mandatory">*</span></label></td>
109
+ </tr>
110
+ <tr>
111
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="tags" id="tags" onclick="export_check(this.value);"><span id="align"> Tags</span> <span class="mandatory">*</span></label></td>
112
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="customerreviews" id="customerreviews" onclick="export_check(this.value);"><span id="align"> Customer Reviews</span><span class="mandatory">*</span></label></td>
113
+ </tr>
114
+ <tr>
115
+ <td class='exportdatatype'>
116
+ <label> <input type="radio" name="export" value="customtaxonomy" id="customtaxonomy" onclick="export_check(this.value);"><span id="align"> Custom Taxonomy</span> <span class="mandatory">*</span></label>
117
+ <select name="export_taxo_type" style="margin-left:10px;">
118
+ <option>--Select--</option>
119
+ <?php
120
+ foreach (get_taxonomies() as $key => $value) {
121
+ if (($value != 'category') && ($value != 'post_tag') && ($value != 'nav_menu') && ($value != 'link_category') && ($value != 'post_format') && ($value != 'product_tag') && ($value != 'wpsc_product_category') && ($value != 'wpsc-variation')) {
122
+ ?>
123
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
124
+ <?php
125
+ }
126
+ }
127
+ ?>
128
+ </select></td>
129
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="comments" id="comments"><span id="align"> Comments</span> </label></td>
130
+ </tr>
131
+ <tr>
132
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="users" id="users"><span id="align"> Users</span> </label></td>
133
+ <td class='exportdatatype'></td>
134
+ </tr>
135
+ </table>
136
+ </div>
137
+ <?php /*
138
+ <div class='form-group exportedas'>
139
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="post"> Post </label>
140
+ </div>
141
+ </div>
142
+ <div class='form-group exportedas'>
143
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="page"> Page </label>
144
+ </div>
145
+ </div>
146
+ <div class='form-group exportedas'>
147
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="custompost"> Custom Post </label>
148
+ <select name="export_post_type">
149
+ <option>--Select--</option>
150
+ <?php
151
+ foreach (get_post_types() as $key => $value) {
152
+ if (($value != 'featured_image') && ($value != 'attachment') && ($value != 'wpsc-product') && ($value != 'wpsc-product-file') && ($value != 'revision') && ($value != 'nav_menu_item') && ($value != 'post') && ($value != 'page') && ($value != 'wp-types-group') && ($value != 'wp-types-user-group') && ($value != 'product') && ($value != 'product_variation') && ($value != 'shop_order') && ($value != 'shop_coupon') && ($value != 'acf')) {
153
+ ?>
154
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
155
+ <?php
156
+ }
157
+ }
158
+ ?>
159
+ </select></div>
160
+ </div>
161
+ <div class='form-group exportedas'>
162
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="users"> Users </label>
163
+ </div>
164
+ </div>
165
+ <div class='form-group exportedas'><div class='col-sm-3 export_action'><label><input type='radio' name='export' value='comments' id='comments' onclick="export_check(this.value)">Comments </label> </div> </div>
166
+ <div class='form-group exportedas'>
167
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="category"> Category
168
+ </label></div>
169
+ </div>
170
+ <div class='form-group exportedas'>
171
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="tags"> Tags </label>
172
+ </div>
173
+ </div>
174
+ <div class='form-group exportedas'>
175
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="customtaxonomy"> Custom
176
+ Taxonomy </label>
177
+ <select name="export_taxo_type">
178
+ <option>--Select--</option>
179
+ <?php
180
+ foreach (get_taxonomies() as $key => $value) {
181
+ if (($value != 'category') && ($value != 'post_tag') && ($value != 'nav_menu') && ($value != 'link_category') && ($value != 'post_format') && ($value != 'product_tag') && ($value != 'wpsc_product_category') && ($value != 'wpsc-variation')) {
182
+ ?>
183
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
184
+ <?php
185
+ }
186
+ }
187
+ ?>
188
+ </select></div>
189
+ </div>
190
+ <div class='form-group exportedas'>
191
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="eshop"> Eshop </label>
192
+ </div>
193
+ </div>
194
+ <div class='form-group exportedas'>
195
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="wpcommerce">
196
+ Wp-Commerce </label></div>
197
+ </div>
198
+ <div class='form-group exportedas'>
199
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="woocommerce">
200
+ Woo-Commerce </label></div>
201
+ </div>
202
+ <div class='form-group exportedas'>
203
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="marketpress">
204
+ Marketpress </label></div>
205
+ </div>
206
+ <div class='form-group exportedas'>
207
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="customerreviews">
208
+ Customer Reviews </label></div>
209
+ </div>
210
+ */ ?>
211
+ <div class='form-group exportedas'>
212
+ <label class='col-sm-2 control-label'><b> File Name: </b></label>
213
+
214
+ <div class='col-sm-6'>
215
+ <input class='form-control' type='text' name='export_filename' id='export_filename' value=''
216
+ placeholder="export_as_<?php echo(date("Y-m-d")); ?>" size="18">
217
+ </div>
218
+ <div class='col-sm-3'><input type="submit" name="exportbutton" value="Export" class='btn btn-primary'></div>
219
+
220
+ </form>
221
+ </div>
222
+ </div>
223
+ </div>
224
+ </div>
225
+ </div>
templates/readfile.php CHANGED
@@ -37,11 +37,16 @@
37
 
38
  require_once('../includes/WPImporter_includes_helper.php');
39
  require_once('../../../../wp-load.php');
 
 
 
 
40
  $impObj = CallWPImporterObj::getInstance();
41
- $filename=$_POST['file_name'];
42
  $delimeter = '';
43
- $result = $impObj->csv_file_data($filename);
 
44
  foreach($result[$_REQUEST['record_no']] as $key => $value) {
45
- $data[] = $value;
46
  }
47
  print_r(json_encode($data));
37
 
38
  require_once('../includes/WPImporter_includes_helper.php');
39
  require_once('../../../../wp-load.php');
40
+ $requested_module = $_REQUEST['checkmodule'];
41
+ $post_url = admin_url() . 'admin.php?page=' . WP_CONST_ULTIMATE_CSV_IMP_SLUG . '/index.php&__module=' . $requested_module . '&step=mapping_settings';
42
+ if($post_url != $_SERVER['HTTP_REFERER'])
43
+ die('Your requested url were wrong! Please contact your admin.');
44
  $impObj = CallWPImporterObj::getInstance();
45
+ $filename = $_POST['file_name'];
46
  $delimeter = '';
47
+ $result = $impObj->csv_file_readdata($filename, $impObj);
48
+ #$result = $impObj->csv_file_data($filename);
49
  foreach($result[$_REQUEST['record_no']] as $key => $value) {
50
+ $data[] = html_entity_decode($value);
51
  }
52
  print_r(json_encode($data));
templates/savetemplate.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*********************************************************************************
3
+ * WP Ultimate CSV Importer is a Tool for importing CSV for the Wordpress
4
+ * plugin developed by Smackcoder. Copyright (C) 2014 Smackcoders.
5
+ *
6
+ * WP Ultimate CSV Importer is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Affero General Public License version 3
8
+ * as published by the Free Software Foundation with the addition of the
9
+ * following permission added to Section 15 as permitted in Section 7(a): FOR
10
+ * ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY WP Ultimate
11
+ * CSV Importer, WP Ultimate CSV Importer DISCLAIMS THE WARRANTY OF NON
12
+ * INFRINGEMENT OF THIRD PARTY RIGHTS.
13
+ *
14
+ * WP Ultimate CSV Importer is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
17
+ * License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public License
20
+ * along with this program; if not, see http://www.gnu.org/licenses or write
21
+ * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
+ * Boston, MA 02110-1301 USA.
23
+ *
24
+ * You can contact Smackcoders at email address info@smackcoders.com.
25
+ *
26
+ * The interactive user interfaces in original and modified versions
27
+ * of this program must display Appropriate Legal Notices, as required under
28
+ * Section 5 of the GNU Affero General Public License version 3.
29
+ *
30
+ * In accordance with Section 7(b) of the GNU Affero General Public License
31
+ * version 3, these Appropriate Legal Notices must retain the display of the
32
+ * WP Ultimate CSV Importer copyright notice. If the display of the logo is
33
+ * not reasonably feasible for technical reasons, the Appropriate Legal
34
+ * Notices must display the words
35
+ * "Copyright Smackcoders. 2014. All rights reserved".
36
+ ********************************************************************************/
37
+
38
+ require_once('../config/settings.php');
39
+ require_once('../lib/skinnymvc/controller/SkinnyController.php');
40
+ require_once('../../../../wp-load.php');
41
+ if($_REQUEST['stepstatus']){
42
+ foreach($_REQUEST as $reqKey => $reqVal){
43
+ if($reqKey == 'h2'){
44
+ $getArr = explode(',',$reqVal);
45
+ foreach($getArr as $v){
46
+ $mapArr[] = $v;
47
+ }
48
+ $_SESSION['SMACK_IMP_OPTIONS']['mapArr'] = $mapArr;
49
+ }elseif($reqKey != 'h2'){
50
+ $_SESSION['SMACK_IMP_OPTIONS'][$reqKey] = $reqVal;
51
+ }
52
+ }
53
+ print_r(json_encode($_REQUEST));
54
+ }
55
+ die;