Ultimate CSV Importer - Version 3.6.4

Version Description

Download this release

Release Info

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

Code changes from version 3.6.3 to 3.6.4

Readme.txt CHANGED
@@ -1,21 +1,21 @@
1
  === WP Ultimate CSV Importer Plugin ===
2
  Contributors: smackcoders
3
  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, buddypress, 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
5
  Requires at least: 3.8
6
  Tested up to: 4.0
7
- Stable tag: 3.6.3
8
- Version: 3.6.3
9
  Author: smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
 
12
  License: GPLv2 or later
13
 
14
- Advanced CSV Importer plugin to import posts, pages, eshop products, custom posts with custom fields with few simple clicks
15
 
16
  == Description ==
17
 
18
- **Version 3.6.3 is now available with eshop(ecommerce) products import feature. Visit [www.wpultimatecsvimporter.com](http://www.wpultimatecsvimporter.com) for more news and future plans.
19
 
20
  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.
21
 
@@ -151,7 +151,7 @@ Need More Help, Cool. Browse Below Links
151
  5. Detailed real time log to know pinpoint status.
152
  6. Module based environment for easy and reduced interface to enable most required modules and when ever needed.
153
  7. Inbuilt support form for easy feedback, support, feature request with all useful links for easy and better csv import.
154
- 8. New export module for posts, page, users, comments and all custom posts type plugins.
155
 
156
 
157
  == Frequently Asked Questions ==
@@ -173,6 +173,15 @@ This will solve your issue or get support from hosting if you dint have sufficie
173
 
174
 
175
  == Changelog ==
 
 
 
 
 
 
 
 
 
176
  = 3.6.3 =
177
  * Added: Eshop import support.
178
  * Fixed reported conflicts with other plugins.
@@ -348,6 +357,9 @@ This will solve your issue or get support from hosting if you dint have sufficie
348
 
349
  == Upgrade Notice ==
350
 
 
 
 
351
  = 3.6.3 =
352
  * Upgrade now for Eshop product import feature.
353
 
1
  === WP Ultimate CSV Importer Plugin ===
2
  Contributors: smackcoders
3
  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, buddypress, 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.8
6
  Tested up to: 4.0
7
+ Stable tag: 3.6.4
8
+ Version: 3.6.4
9
  Author: smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
 
12
  License: GPLv2 or later
13
 
14
+ Advanced CSV Importer plugin to import/export posts, pages, eshop products, custom posts with custom fields with few simple clicks
15
 
16
  == Description ==
17
 
18
+ ** Now version 3.6.4 available with much advanced log and advanced filtered export features. Visit [www.wpultimatecsvimporter.com](http://www.wpultimatecsvimporter.com) for more news and future plans.
19
 
20
  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.
21
 
151
  5. Detailed real time log to know pinpoint status.
152
  6. Module based environment for easy and reduced interface to enable most required modules and when ever needed.
153
  7. Inbuilt support form for easy feedback, support, feature request with all useful links for easy and better csv import.
154
+ 8. New export module for posts, page, eshop, users, comments and all custom posts type plugins.
155
 
156
 
157
  == Frequently Asked Questions ==
173
 
174
 
175
  == Changelog ==
176
+
177
+ = 3.6.5 =
178
+
179
+ = 3.6.4 =
180
+ * Added: Advanced export features with filter options.
181
+ * Improved: Advanced log section.
182
+ * Fixed reported jquery issues.
183
+ * WordPress 4.0 compatibility checked.
184
+
185
  = 3.6.3 =
186
  * Added: Eshop import support.
187
  * Fixed reported conflicts with other plugins.
357
 
358
  == Upgrade Notice ==
359
 
360
+ = 3.6.4 =
361
+ * Upgrade Now for filtered export and improved log features.
362
+
363
  = 3.6.3 =
364
  * Upgrade now for Eshop product import feature.
365
 
css/style.css CHANGED
@@ -293,6 +293,13 @@ div#mappingheader select {
293
  width:23%;
294
  }
295
 
 
 
 
 
 
 
 
296
  /*.mappingheader .table-condensed label {
297
  margin-top:13px;
298
  }
293
  width:23%;
294
  }
295
 
296
+ .exportmodule > thead > tr > th, .exportmodule > tbody > tr > th, .exportmodule > tfoot > tr > th, .exportmodule > thead > tr > td, .exportmodule > tbody > tr > td, .exportmodule > tfoot > tr > td {
297
+ padding: 8px;
298
+ line-height: 1.428571429;
299
+ vertical-align: top;
300
+ border-top: 1px solid #ffffff !important;
301
+ }
302
+
303
  /*.mappingheader .table-condensed label {
304
  margin-top:13px;
305
  }
includes/WPImporter_includes_helper.php CHANGED
@@ -303,7 +303,7 @@ class WPImporter_includes_helper {
303
  * @param string type = (title|content), string content
304
  * @return boolean
305
  */
306
- function duplicateChecks($type = 'title', $text, $gettype)
307
  {
308
  global $wpdb;
309
  if ($type == 'content') {
@@ -319,6 +319,7 @@ class WPImporter_includes_helper {
319
  similar_text($strippedTextPCont, $strippedText, $p);
320
  if ($p == 100) {
321
  $this->dupPostCount++;
 
322
  return false;
323
  }
324
  }
@@ -329,14 +330,20 @@ class WPImporter_includes_helper {
329
  return true;
330
  }
331
  $this->dupPostCount++;
 
332
  return false;
333
  }
334
 
335
  /**
336
- * function to fetch the featured image from remote URL
337
- *
 
 
 
 
 
338
  */
339
- function get_fimg_from_URL($f_img,$fimg_path,$fimg_name,$post_slug_value){
340
  if($fimg_path!="" && $fimg_path){
341
  $fimg_path = $fimg_path . "/" . $post_slug_value . "-" . $fimg_name;
342
  }
@@ -344,26 +351,27 @@ class WPImporter_includes_helper {
344
  curl_setopt($ch, CURLOPT_HEADER, 0);
345
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
346
  curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
347
- curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
348
- $rawdata=curl_exec($ch);
349
-
350
  if(strpos($rawdata, 'Not Found') != 0) {
351
  $rawdata = false;
352
  }
353
  if ($rawdata == false) {
354
- $this->detailedLog[] = "<span style='color:red;'><b>Failed to download</b></span> Attachment file " . $f_img . " cannot be saved locally as " . $fimg_path;
 
 
 
 
355
  } else {
356
- $this->detailedLog[] = "<span style='color:green;'><b>Media File Added</b></span> Attachment file " . $f_img . " has been saved locally as " . $fimg_path;
357
- }
358
-
359
-
360
- curl_close ($ch);
361
- if(file_exists($fimg_path)){
362
- unlink($fimg_path);
363
- }
364
- $fp = fopen($fimg_path,'x');
365
- fwrite($fp, $rawdata);
366
- fclose($fp);
367
  }
368
 
369
  /**
@@ -371,7 +379,7 @@ class WPImporter_includes_helper {
371
  *
372
  * @return boolean
373
  */
374
- function processDataInWP($data_rows,$ret_array,$session_arr)
375
  {
376
  global $wpdb;
377
  $post_id = '';
@@ -485,7 +493,7 @@ class WPImporter_includes_helper {
485
  $f_img_slug = preg_replace('/\s/', '-', $f_img_slug);
486
 
487
  $post_slug_value = strtolower($f_img_slug);
488
- $this->get_fimg_from_URL($f_img,$fimg_path,$fimg_name,$post_slug_value);
489
  $filepath = $fimg_path."/" . $post_slug_value . "-" . $fimg_name;
490
 
491
  if(@getimagesize($filepath)){
@@ -523,10 +531,10 @@ class WPImporter_includes_helper {
523
  $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['custompostlist'];
524
  }
525
  if ($this->titleDupCheck == 'true')
526
- $this->postFlag = $this->duplicateChecks('title', $data_array ['post_title'], $data_array ['post_type']);
527
 
528
  if ($this->conDupCheck == 'true' && $this->postFlag)
529
- $this->postFlag = $this->duplicateChecks('content', $data_array ['post_content'], $data_array ['post_type']);
530
 
531
  if ($this->postFlag) {
532
  unset ($sticky);
@@ -539,23 +547,29 @@ class WPImporter_includes_helper {
539
  switch ($data_array ['post_status']) {
540
  case 1 :
541
  $data_array['post_status'] = 'publish';
 
542
  break;
543
  case 2 :
544
  $data_array['post_status'] = 'publish';
545
  $sticky = true;
 
546
  break;
547
  case 3 :
548
  $data_array['post_status'] = 'publish';
549
  $data_array ['post_password'] = $_POST ['postsPassword'];
 
550
  break;
551
  case 4 :
552
  $data_array ['post_status'] = 'private';
 
553
  break;
554
  case 5 :
555
  $data_array ['post_status'] = 'draft';
 
556
  break;
557
  case 6 :
558
  $data_array ['post_status'] = 'pending';
 
559
  break;
560
  default :
561
  $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
@@ -568,19 +582,25 @@ class WPImporter_includes_helper {
568
  $postpwd = substr($poststatus, 0, -1);
569
  $data_array['post_status'] = 'publish';
570
  $data_array ['post_password'] = $postpwd;
 
571
  } else {
572
  $data_array['post_status'] = 'publish';
573
  $data_array ['post_password'] = $poststatus;
 
574
  }
575
  } else {
576
  $data_array['post_status'] = 'publish';
 
577
  }
578
  }
579
  if ($data_array['post_status'] == 'sticky') {
580
  $data_array['post_status'] = 'publish';
581
  $sticky = true;
 
 
 
 
582
  }
583
-
584
  }
585
  // Post Format Options
586
 
@@ -624,31 +644,39 @@ class WPImporter_includes_helper {
624
  $postauthor = array();
625
 
626
  if ($authorLen == $postAuthorLen) {
627
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where ID = \"{$postuserid}\"");
628
  if(empty($postauthor) || !$postauthor[0]->ID) { // If user name are numeric Ex: 1300001
629
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where user_login = \"{$postuserid}\"");
630
  }
631
  } else {
632
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where user_login = \"{$postuserid}\"");
633
  }
634
 
635
  if (empty($postauthor) || !$postauthor[0]->ID) {
636
  $data_array ['post_author'] = 1;
 
 
637
  $this->noPostAuthCount++;
638
  } else {
639
  $data_array ['post_author'] = $postauthor [0]->ID;
 
640
  }
641
  }
642
  else{
643
  $data_array ['post_author'] = 1;
 
 
644
  $this->noPostAuthCount++;
645
  }
646
 
647
  // Date format post
 
648
  if (!isset($data_array ['post_date'])){
649
  $data_array ['post_date'] = date('Y-m-d H:i:s');
 
650
  }else{
651
  $data_array ['post_date'] = date('Y-m-d H:i:s', strtotime($data_array ['post_date']));
 
652
  }
653
  if(isset($data_array ['post_slug'])){
654
  $data_array ['post_name'] = $data_array ['post_slug'];
@@ -658,12 +686,13 @@ class WPImporter_includes_helper {
658
  if($data_array){
659
  if($ret_array['importallwithps'] == 3){
660
  $data_array['post_password'] = $ret_array['globalpassword_txt'];
661
-
662
  }
663
  }
664
- if ($data_array)
665
  $post_id = wp_insert_post($data_array);
666
-
 
667
  unset($postauthor);
668
  if ($post_id) {
669
  $uploaded_file_name=$session_arr['uploadedFile'];
@@ -727,18 +756,30 @@ class WPImporter_includes_helper {
727
 
728
  // Create/Add tags to post
729
  if (!empty ($tags)) {
 
730
  foreach ($tags as $tag_key => $tag_value) {
 
731
  wp_set_post_tags($post_id, $tag_value);
732
  }
 
733
  }
734
 
735
  // Create/Add category to post
736
  if (!empty ($categories)) {
 
 
737
  $split_cate = explode('|', $categories ['post_category']);
738
  foreach ($split_cate as $key => $val) {
739
- if (is_numeric($val))
740
  $split_cate[$key] = 'uncategorized';
 
 
 
741
  }
 
 
 
 
742
  wp_set_object_terms($post_id, $split_cate, 'category');
743
  }
744
  // Add featured image
@@ -768,11 +809,17 @@ class WPImporter_includes_helper {
768
  $skippedRecords[] = $_SESSION['SMACK_SKIPPED_RECORDS'];
769
  }
770
  }
 
 
771
  unset($data_array);
772
  }
773
 
774
  // Create Data base for Statistic chart
775
  public static function activate() {
 
 
 
 
776
  global $wpdb;
777
  $sql1="CREATE TABLE `smackcsv_pie_log` (
778
  `id` int(11) NOT NULL AUTO_INCREMENT,
303
  * @param string type = (title|content), string content
304
  * @return boolean
305
  */
306
+ function duplicateChecks($type = 'title', $text, $gettype, $currentLimit, $postTitle)
307
  {
308
  global $wpdb;
309
  if ($type == 'content') {
319
  similar_text($strippedTextPCont, $strippedText, $p);
320
  if ($p == 100) {
321
  $this->dupPostCount++;
322
+ $this->detailedLog[$currentLimit]['post_id'] = "Created record no $currentLimit - failed";
323
  return false;
324
  }
325
  }
330
  return true;
331
  }
332
  $this->dupPostCount++;
333
+ $this->detailedLog[$currentLimit]['post_id'] = "Created record no $currentLimit - failed";
334
  return false;
335
  }
336
 
337
  /**
338
+ * function to fetch the featured image from remote URL
339
+ * @param $f_img
340
+ * @param $fimg_path
341
+ * @param $fimg_name
342
+ * @param $post_slug_value
343
+ * @param $currentLimit
344
+ * @param string $logObj
345
  */
346
+ public static function get_fimg_from_URL($f_img, $fimg_path, $fimg_name, $post_slug_value, $currentLimit = null, $logObj = ""){
347
  if($fimg_path!="" && $fimg_path){
348
  $fimg_path = $fimg_path . "/" . $post_slug_value . "-" . $fimg_name;
349
  }
351
  curl_setopt($ch, CURLOPT_HEADER, 0);
352
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
353
  curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
354
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
355
+ $rawdata = curl_exec($ch);
 
356
  if(strpos($rawdata, 'Not Found') != 0) {
357
  $rawdata = false;
358
  }
359
  if ($rawdata == false) {
360
+ if ($logObj == '') {
361
+ $this->detailedLog[$currentLimit]['image'] = "<b>Image -</b> host not resolved";
362
+ } else {
363
+ $logObj->detailedLog[$currentLimit]['image'] = "<b>Image -</b> host not resolved";
364
+ }
365
  } else {
366
+ if (file_exists($fimg_path)) {
367
+ unlink($fimg_path);
368
+ }
369
+ $fp = fopen($fimg_path, 'x');
370
+ fwrite($fp, $rawdata);
371
+ fclose($fp);
372
+ $logObj->detailedLog[$currentLimit]['image'] = "<b>Image -</b>" . $fimg_name;
373
+ }
374
+ curl_close($ch);
 
 
375
  }
376
 
377
  /**
379
  *
380
  * @return boolean
381
  */
382
+ function processDataInWP($data_rows,$ret_array,$session_arr,$currentLimit)
383
  {
384
  global $wpdb;
385
  $post_id = '';
493
  $f_img_slug = preg_replace('/\s/', '-', $f_img_slug);
494
 
495
  $post_slug_value = strtolower($f_img_slug);
496
+ $this->get_fimg_from_URL($f_img, $fimg_path, $fimg_name, $post_slug_value, $currentLimit, $this);
497
  $filepath = $fimg_path."/" . $post_slug_value . "-" . $fimg_name;
498
 
499
  if(@getimagesize($filepath)){
531
  $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['custompostlist'];
532
  }
533
  if ($this->titleDupCheck == 'true')
534
+ $this->postFlag = $this->duplicateChecks('title', $data_array ['post_title'], $data_array ['post_type'], $currentLimit, $data_array ['post_title']);
535
 
536
  if ($this->conDupCheck == 'true' && $this->postFlag)
537
+ $this->postFlag = $this->duplicateChecks('content', $data_array ['post_content'], $data_array ['post_type'], $currentLimit, $data_array ['post_title']);
538
 
539
  if ($this->postFlag) {
540
  unset ($sticky);
547
  switch ($data_array ['post_status']) {
548
  case 1 :
549
  $data_array['post_status'] = 'publish';
550
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>publish";
551
  break;
552
  case 2 :
553
  $data_array['post_status'] = 'publish';
554
  $sticky = true;
555
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>sticky";
556
  break;
557
  case 3 :
558
  $data_array['post_status'] = 'publish';
559
  $data_array ['post_password'] = $_POST ['postsPassword'];
560
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
561
  break;
562
  case 4 :
563
  $data_array ['post_status'] = 'private';
564
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>private";
565
  break;
566
  case 5 :
567
  $data_array ['post_status'] = 'draft';
568
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>draft";
569
  break;
570
  case 6 :
571
  $data_array ['post_status'] = 'pending';
572
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>pending";
573
  break;
574
  default :
575
  $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
582
  $postpwd = substr($poststatus, 0, -1);
583
  $data_array['post_status'] = 'publish';
584
  $data_array ['post_password'] = $postpwd;
585
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
586
  } else {
587
  $data_array['post_status'] = 'publish';
588
  $data_array ['post_password'] = $poststatus;
589
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
590
  }
591
  } else {
592
  $data_array['post_status'] = 'publish';
593
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>publish";
594
  }
595
  }
596
  if ($data_array['post_status'] == 'sticky') {
597
  $data_array['post_status'] = 'publish';
598
  $sticky = true;
599
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>sticky";
600
+ }
601
+ else {
602
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>" . $data_array['post_status'];
603
  }
 
604
  }
605
  // Post Format Options
606
 
644
  $postauthor = array();
645
 
646
  if ($authorLen == $postAuthorLen) {
647
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = \"{$postuserid}\"");
648
  if(empty($postauthor) || !$postauthor[0]->ID) { // If user name are numeric Ex: 1300001
649
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where user_login = \"{$postuserid}\"");
650
  }
651
  } else {
652
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where user_login = \"{$postuserid}\"");
653
  }
654
 
655
  if (empty($postauthor) || !$postauthor[0]->ID) {
656
  $data_array ['post_author'] = 1;
657
+ $admindet = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = 1");
658
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
659
  $this->noPostAuthCount++;
660
  } else {
661
  $data_array ['post_author'] = $postauthor [0]->ID;
662
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - </b>" . $postauthor[0]->user_login;
663
  }
664
  }
665
  else{
666
  $data_array ['post_author'] = 1;
667
+ $admindet = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = 1");
668
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
669
  $this->noPostAuthCount++;
670
  }
671
 
672
  // Date format post
673
+ $data_array ['post_date'] = str_replace('/', '-', $data_array ['post_date']);
674
  if (!isset($data_array ['post_date'])){
675
  $data_array ['post_date'] = date('Y-m-d H:i:s');
676
+ $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array ['post_date'];
677
  }else{
678
  $data_array ['post_date'] = date('Y-m-d H:i:s', strtotime($data_array ['post_date']));
679
+ $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array ['post_date'];
680
  }
681
  if(isset($data_array ['post_slug'])){
682
  $data_array ['post_name'] = $data_array ['post_slug'];
686
  if($data_array){
687
  if($ret_array['importallwithps'] == 3){
688
  $data_array['post_password'] = $ret_array['globalpassword_txt'];
689
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $ret_array['globalpassword_txt'];
690
  }
691
  }
692
+ if ($data_array) {
693
  $post_id = wp_insert_post($data_array);
694
+ $this->detailedLog[$currentLimit]['post_id'] = "<b>Created Post_ID - </b>" . $post_id . " - success";
695
+ }
696
  unset($postauthor);
697
  if ($post_id) {
698
  $uploaded_file_name=$session_arr['uploadedFile'];
756
 
757
  // Create/Add tags to post
758
  if (!empty ($tags)) {
759
+ $this->detailedLog[$currentLimit]['tags'] = "";
760
  foreach ($tags as $tag_key => $tag_value) {
761
+ $this->detailedLog[$currentLimit]['tags'] .= $tag_value . "|";
762
  wp_set_post_tags($post_id, $tag_value);
763
  }
764
+ $this->detailedLog[$currentLimit]['tags'] = "<b>Tags - </b>" .substr($this->detailedLog[$currentLimit]['tags'], 0, -1);
765
  }
766
 
767
  // Create/Add category to post
768
  if (!empty ($categories)) {
769
+ $this->detailedLog[$currentLimit]['category'] = "";
770
+ $assigned_categories = array();
771
  $split_cate = explode('|', $categories ['post_category']);
772
  foreach ($split_cate as $key => $val) {
773
+ if (is_numeric($val)) {
774
  $split_cate[$key] = 'uncategorized';
775
+ $assigned_categories['uncategorized'] = 'uncategorized';
776
+ }
777
+ $assigned_categories[$val] = $val;
778
  }
779
+ foreach($assigned_categories as $cateKey => $cateVal) {
780
+ $this->detailedLog[$currentLimit]['category'] .= $cateKey . "|";
781
+ }
782
+ $this->detailedLog[$currentLimit]['category'] = "<b>Category - </b>" .substr($this->detailedLog[$currentLimit]['category'], 0, -1);
783
  wp_set_object_terms($post_id, $split_cate, 'category');
784
  }
785
  // Add featured image
809
  $skippedRecords[] = $_SESSION['SMACK_SKIPPED_RECORDS'];
810
  }
811
  }
812
+ $this->detailedLog[$currentLimit]['verify_here'] = "<b>Verify Here -</b> <a href='" . get_permalink( $post_id ) . "' title='" . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $data_array['post_title'] ) ) . "' rel='permalink'>" . __( 'Web View' ) . "</a> | <a href='" . get_edit_post_link( $post_id, true ) . "' title='" . esc_attr( __( 'Edit this item' ) ) . "'>" . __( 'Admin View' ) . "</a>";
813
+
814
  unset($data_array);
815
  }
816
 
817
  // Create Data base for Statistic chart
818
  public static function activate() {
819
+ if (!defined('PDO::ATTR_DRIVER_NAME')) {
820
+ echo("Make sure you have enable the PDO extensions in your environment before activate the plugin!");
821
+ die;
822
+ }
823
  global $wpdb;
824
  $sql1="CREATE TABLE `smackcsv_pie_log` (
825
  `id` int(11) NOT NULL AUTO_INCREMENT,
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.3
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
@@ -51,7 +51,7 @@ define('WP_CONST_ULTIMATE_CSV_IMP_URL', 'http://www.smackcoders.com/wp-ultimate-
51
  define('WP_CONST_ULTIMATE_CSV_IMP_NAME', 'WP Ultimate CSV Importer');
52
  define('WP_CONST_ULTIMATE_CSV_IMP_SLUG', 'wp-ultimate-csv-importer');
53
  define('WP_CONST_ULTIMATE_CSV_IMP_SETTINGS', 'WP Ultimate CSV Importer');
54
- define('WP_CONST_ULTIMATE_CSV_IMP_VERSION', '3.6.2');
55
  define('WP_CONST_ULTIMATE_CSV_IMP_DIR', WP_PLUGIN_URL . '/' . WP_CONST_ULTIMATE_CSV_IMP_SLUG . '/');
56
  define('WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY', plugin_dir_path(__FILE__));
57
  define('WP_CSVIMP_PLUGIN_BASE', WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY);
@@ -94,7 +94,7 @@ function action_csv_imp_admin_init() {
94
  if (isset($_REQUEST['page']) && ($_REQUEST['page'] == 'wp-ultimate-csv-importer/index.php' || $_REQUEST['page'] == 'page')) {
95
  wp_enqueue_script('jquery-ui-datepicker');
96
  wp_enqueue_style('jquery-style', plugins_url('css/jquery-ui.css', __FILE__));
97
- wp_register_script('ultimate-importer-js', plugins_url('js/ultimate-importer-pro.js', __FILE__));
98
  wp_enqueue_script('ultimate-importer-js');
99
  wp_register_script('ultimate-importer-button', plugins_url('js/buttons.js', __FILE__));
100
  wp_enqueue_script('ultimate-importer-button');
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.4
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
51
  define('WP_CONST_ULTIMATE_CSV_IMP_NAME', 'WP Ultimate CSV Importer');
52
  define('WP_CONST_ULTIMATE_CSV_IMP_SLUG', 'wp-ultimate-csv-importer');
53
  define('WP_CONST_ULTIMATE_CSV_IMP_SETTINGS', 'WP Ultimate CSV Importer');
54
+ define('WP_CONST_ULTIMATE_CSV_IMP_VERSION', '3.6.4');
55
  define('WP_CONST_ULTIMATE_CSV_IMP_DIR', WP_PLUGIN_URL . '/' . WP_CONST_ULTIMATE_CSV_IMP_SLUG . '/');
56
  define('WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY', plugin_dir_path(__FILE__));
57
  define('WP_CSVIMP_PLUGIN_BASE', WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY);
94
  if (isset($_REQUEST['page']) && ($_REQUEST['page'] == 'wp-ultimate-csv-importer/index.php' || $_REQUEST['page'] == 'page')) {
95
  wp_enqueue_script('jquery-ui-datepicker');
96
  wp_enqueue_style('jquery-style', plugins_url('css/jquery-ui.css', __FILE__));
97
+ wp_register_script('ultimate-importer-js', plugins_url('js/ultimate-importer-free.js', __FILE__));
98
  wp_enqueue_script('ultimate-importer-js');
99
  wp_register_script('ultimate-importer-button', plugins_url('js/buttons.js', __FILE__));
100
  wp_enqueue_script('ultimate-importer-button');
js/dashchart.js CHANGED
@@ -15,10 +15,13 @@ jQuery.ajax({
15
  cache: false,
16
  success: function(data) {
17
 
18
- var browser = JSON.parse(data);
19
- if (browser['label'] == 'No Imports Yet') {
20
- document.getElementById('pieStats').innerHTML = "<h2 style='color: red;text-align: center;padding-top: 100px;' >No Imports Yet</h2>";
21
- }
 
 
 
22
  else {
23
  jQuery('#pieStats').highcharts({
24
  chart: {
15
  cache: false,
16
  success: function(data) {
17
 
18
+ var browser = JSON.parse(data);
19
+ var checkmodule = document.getElementById('checkmodule').value;
20
+ if(checkmodule == 'dashboard') {
21
+ if (browser['label'] == 'No Imports Yet') {
22
+ document.getElementById('pieStats').innerHTML = "<h2 style='color: red;text-align: center;padding-top: 100px;' >No Imports Yet</h2>";
23
+ }
24
+ }
25
  else {
26
  jQuery('#pieStats').highcharts({
27
  chart: {
js/{ultimate-importer-pro.js → ultimate-importer-free.js} RENAMED
@@ -1,7 +1,7 @@
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>';
@@ -12,43 +12,50 @@ 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'){
@@ -722,7 +729,7 @@ function export_module(){
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();
@@ -768,3 +775,42 @@ function selectModules(id) {
768
  }
769
  }
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' && checkmodule !='support' && checkmodule !='export') {
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>';
12
 
13
 
14
  }
15
+ if (checkmodule == 'custompost') {
16
+ var step = jQuery('#stepstatus').val();
17
+ if (step == 'mapping_settings') {
18
+ var cust_post_list_count = jQuery('#cust_post_list_count').val();
19
+ if (cust_post_list_count == '0')
20
+ document.getElementById('cust_post_empty').style.display = '';
21
+ }
22
+ }
23
+ if (checkmodule != 'filemanager' && checkmodule != 'settings' && checkmodule !='support' && checkmodule !='export') {
24
+ var checkfile = jQuery('#checkfile').val();
25
+ var uploadedFile = jQuery('#uploadedFile').val();
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({
45
+ url: tmpLoc + 'templates/readfile.php',
46
+ type: 'post',
47
+ data: doaction,
48
+ dataType: 'json',
49
+ success: function (response) {
50
+ if (response != null) {
51
+ var totalLength = response.length;
52
+ var setHeight = (parseInt(totalLength) * 30) + 250;
53
+ }
54
+ }
55
+ });
56
+ }
57
+ }
58
+ }
59
  });
60
  function goto_mapping(id){
61
  if(id == 'importfile'){
729
  return false;
730
  }
731
  function export_check(value) {
732
+ if( value == 'woocommerce' || value == 'wpcommerce' || value == 'marketpress' || value == 'users' || value == 'category' || value == 'tags' || value == 'customtaxonomy' || value == 'customerreviews') {
733
  document.getElementById(value).checked = false;
734
  document.getElementById('ShowMsg').style.display = "";
735
  value = value.toUpperCase();
775
  }
776
  }
777
 
778
+ function addwpexportfilter(id) {
779
+ if(document.getElementById(id).checked == true) {
780
+ if(id == 'getdataforspecificperiod') {
781
+ document.getElementById('specificperiodexport').style.display = '';
782
+ document.getElementById('periodstartfrom').style.display = '';
783
+ document.getElementById('postdatefrom').style.display = '';
784
+ document.getElementById('periodendto').style.display = '';
785
+ document.getElementById('postdateto').style.display = '';
786
+ }
787
+ else if(id == 'getdatawithspecificstatus') {
788
+ document.getElementById('specificstatusexport').style.display = '';
789
+ document.getElementById('status').style.display = '';
790
+ document.getElementById('postwithstatus').style.display = '';
791
+ }
792
+ else if(id == 'getdatabyspecificauthors') {
793
+ document.getElementById('specificauthorexport').style.display = '';
794
+ document.getElementById('authors').style.display = '';
795
+ document.getElementById('postauthor').style.display = '';
796
+ }
797
+ } else if (document.getElementById(id).checked == false) {
798
+ if(id == 'getdataforspecificperiod') {
799
+ document.getElementById('specificperiodexport').style.display = 'none';
800
+ document.getElementById('periodstartfrom').style.display = 'none';
801
+ document.getElementById('postdatefrom').style.display = 'none';
802
+ document.getElementById('periodendto').style.display = 'none';
803
+ document.getElementById('postdateto').style.display = 'none';
804
+ }
805
+ else if(id == 'getdatawithspecificstatus') {
806
+ document.getElementById('specificstatusexport').style.display = 'none';
807
+ document.getElementById('status').style.display = 'none';
808
+ document.getElementById('postwithstatus').style.display = 'none';
809
+ }
810
+ else if(id == 'getdatabyspecificauthors') {
811
+ document.getElementById('specificauthorexport').style.display = 'none';
812
+ document.getElementById('authors').style.display = 'none';
813
+ document.getElementById('postauthor').style.display = 'none';
814
+ }
815
+ }
816
+ }
modules/comments/actions/actions.php CHANGED
@@ -113,6 +113,7 @@ class CommentsActions extends SkinnyActions
113
  similar_text($strippedTextPCont, $strippedText, $p);
114
  if ($p == 100) {
115
  $this->dupPostCount++;
 
116
  return false;
117
  }
118
  }
@@ -123,6 +124,7 @@ class CommentsActions extends SkinnyActions
123
  return true;
124
  }
125
  $this->dupPostCount++;
 
126
  return false;
127
  }
128
 
@@ -318,14 +320,19 @@ class CommentsActions extends SkinnyActions
318
  {
319
  $commentid=wp_insert_comment($dat_array);
320
 
321
- if($commentid)
322
  $this->insPostCount+=1;
323
- else
 
 
324
  $this->dupPostCount+=1;
 
 
325
  }
326
  else
327
  {
328
  $this->dupPostCount+=1;
 
329
  }
330
  return $commentid;
331
  }//add comments ends
113
  similar_text($strippedTextPCont, $strippedText, $p);
114
  if ($p == 100) {
115
  $this->dupPostCount++;
116
+ $this->detailedLog[$currentLimit][] = "Comment - <b>skipped</b>, Comment tile - " .$commentTitle . " Duplicate found";
117
  return false;
118
  }
119
  }
124
  return true;
125
  }
126
  $this->dupPostCount++;
127
+ $this->detailedLog[$currentLimit][] = "Comment - <b>skipped</b>, Comment tile - " .$commentTitle . " Duplicate found";
128
  return false;
129
  }
130
 
320
  {
321
  $commentid=wp_insert_comment($dat_array);
322
 
323
+ if($commentid) {
324
  $this->insPostCount+=1;
325
+ $this->detailedLog[$currentLimit][] = "Comment added to <b>Post_ID</b> - " . $dat_array ['comment_post_ID'] . ", <b>Author</b> - " . $dat_array['comment_author'] . ", <b>Author Email</b> - " . $dat_array['comment_author_email'] . ", <b>Author URL</b> - " . $dat_array['comment_author_url'] . ", <b>Date</b> - " . $dat_array['comment_date'] . ", <b>Verify Here</b> - <a href='" . get_permalink( $post_id ) . "' rel='permalink'>" . __( 'Web View' ) . "</a> | <a href='" . get_edit_post_link( $post_id, true ) . "' title='" . esc_attr( __( 'Edit this item' ) ) . "'>" . __( 'Admin View' ) . "</a>";
326
+ }
327
+ else {
328
  $this->dupPostCount+=1;
329
+ $this->detailedLog[$currentLimit][] = "<b>Comment - </b>skipped, <b>Post_ID</b> - " . $dat_array ['comment_post_ID']. " not available";
330
+ }
331
  }
332
  else
333
  {
334
  $this->dupPostCount+=1;
335
+ $this->detailedLog[$currentLimit][] = "<b>Comment - </b>skipped, <b>Post_ID</b> - " . $dat_array ['comment_post_ID']. " not available";
336
  }
337
  return $commentid;
338
  }//add comments ends
modules/eshop/actions/actions.php CHANGED
@@ -96,7 +96,7 @@ class EshopActions extends SkinnyActions {
96
  * @param string type = (title|content), string content
97
  * @return boolean
98
  */
99
- function duplicateChecks($type = 'title', $text, $gettype)
100
  {
101
  global $wpdb;
102
  $gettype = 'post';
@@ -113,6 +113,7 @@ class EshopActions extends SkinnyActions {
113
  similar_text($strippedTextPCont, $strippedText, $p);
114
  if ($p == 100) {
115
  $this->dupPostCount++;
 
116
  return false;
117
  }
118
  }
@@ -123,6 +124,7 @@ class EshopActions extends SkinnyActions {
123
  return true;
124
  }
125
  $this->dupPostCount++;
 
126
  return false;
127
  }
128
 
@@ -162,7 +164,7 @@ class EshopActions extends SkinnyActions {
162
  * @param $post_id
163
  * @return mixed
164
  */
165
- public function eshopMetaData($new_post, $post_id) {
166
  global $wpdb;
167
  $eshopoptions = get_option('eshop_plugin_settings');
168
  foreach ($new_post as $ckey => $cval) {
@@ -197,7 +199,7 @@ class EshopActions extends SkinnyActions {
197
  update_post_meta($post_id, '_eshop_stock', 1);
198
  }
199
  break;
200
- case 'cart-option' :
201
  $cartOption = strtolower($new_post[$ckey]);
202
  if ($cartOption == 'yes' || $cartOption == 'no') {
203
  $cartOption = 0;
@@ -215,6 +217,7 @@ class EshopActions extends SkinnyActions {
215
  break;
216
  case 'SKU' :
217
  $metaDatas['sku'] = $new_post[$ckey];
 
218
  break;
219
  case 'products_option':
220
  $productOptions = $new_post[$ckey];
@@ -276,16 +279,22 @@ class EshopActions extends SkinnyActions {
276
  update_post_meta($post_id, '_eshop_product', $metaDatas);
277
  }
278
  if (!empty($tags)) {
 
279
  foreach ($tags as $tag_key => $tag_value) {
 
280
  $split_line = explode(',', $tag_value);
281
  $term_taxonomy_id_t = wp_set_object_terms($post_id, $split_line, "post_tag");
282
  }
 
283
  }
284
  if (!empty($categories)) {
 
285
  foreach ($categories as $cat_key => $cat_value) {
 
286
  $split_line = explode('|', $cat_value);
287
  $term_taxonomy_id_c = wp_set_object_terms($post_id, $split_line, "category");
288
  }
 
289
  }
290
  #TODO: $term_taxonomy_id_c, $term_taxonomy_id_t not used in this function / overwritten immediately
291
  return $metaDatas;
@@ -296,7 +305,7 @@ class EshopActions extends SkinnyActions {
296
  *
297
  * @return boolean
298
  */
299
- function processDataInWP($data_rows,$ret_array,$session_arr)
300
  {
301
  global $wpdb;
302
  $post_id = '';
@@ -413,7 +422,7 @@ class EshopActions extends SkinnyActions {
413
  require_once(WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY.'/includes/WPImporter_includes_helper.php');
414
  $impCE = new WPImporter_includes_helper();
415
 
416
- $impCE->get_fimg_from_URL($f_img,$fimg_path,$fimg_name,$post_slug_value);
417
  $filepath = $fimg_path."/" . $post_slug_value . "-" . $fimg_name;
418
 
419
  if(@getimagesize($filepath)){
@@ -452,10 +461,10 @@ class EshopActions extends SkinnyActions {
452
  $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['custompostlist'];
453
  }
454
  if ($this->titleDupCheck == 'true')
455
- $this->postFlag = $this->duplicateChecks('title', $data_array ['post_title'], $data_array ['post_type']);
456
 
457
  if ($this->conDupCheck == 'true' && $this->postFlag)
458
- $this->postFlag = $this->duplicateChecks('content', $data_array ['post_content'], $data_array ['post_type']);
459
 
460
  if ($this->postFlag) {
461
  unset ($sticky);
@@ -469,23 +478,29 @@ class EshopActions extends SkinnyActions {
469
  switch ($data_array ['post_status']) {
470
  case 1 :
471
  $data_array['post_status'] = 'publish';
 
472
  break;
473
  case 2 :
474
  $data_array['post_status'] = 'publish';
475
  $sticky = true;
 
476
  break;
477
  case 3 :
478
  $data_array['post_status'] = 'publish';
479
  $data_array ['post_password'] = $_POST ['postsPassword'];
 
480
  break;
481
  case 4 :
482
  $data_array ['post_status'] = 'private';
 
483
  break;
484
  case 5 :
485
  $data_array ['post_status'] = 'draft';
 
486
  break;
487
  case 6 :
488
  $data_array ['post_status'] = 'pending';
 
489
  break;
490
  default :
491
  $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
@@ -498,19 +513,25 @@ class EshopActions extends SkinnyActions {
498
  $postpwd = substr($poststatus, 0, -1);
499
  $data_array['post_status'] = 'publish';
500
  $data_array ['post_password'] = $postpwd;
 
501
  } else {
502
  $data_array['post_status'] = 'publish';
503
  $data_array ['post_password'] = $poststatus;
 
504
  }
505
  } else {
506
  $data_array['post_status'] = 'publish';
 
507
  }
508
  }
509
  if ($data_array['post_status'] == 'sticky') {
510
  $data_array['post_status'] = 'publish';
511
  $sticky = true;
 
 
 
 
512
  }
513
-
514
  }
515
 
516
  // Author name/id update
@@ -522,31 +543,39 @@ class EshopActions extends SkinnyActions {
522
  $postauthor = array();
523
 
524
  if ($authorLen == $postAuthorLen) {
525
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where ID = \"{$postuserid}\"");
526
  if(empty($postauthor) || !$postauthor[0]->ID) { // If user name are numeric Ex: 1300001
527
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where user_login = \"{$postuserid}\"");
528
  }
529
  } else {
530
- $postauthor = $wpdb->get_results("select ID from $wpdb->users where user_login = \"{$postuserid}\"");
531
  }
532
 
533
  if (empty($postauthor) || !$postauthor[0]->ID) {
534
  $data_array ['post_author'] = 1;
 
 
535
  $this->noPostAuthCount++;
536
  } else {
537
  $data_array ['post_author'] = $postauthor [0]->ID;
 
538
  }
539
  }
540
  else{
541
  $data_array ['post_author'] = 1;
 
 
542
  $this->noPostAuthCount++;
543
  }
544
 
545
  // Date format post
 
546
  if (!isset($data_array ['post_date'])){
547
  $data_array ['post_date'] = date('Y-m-d H:i:s');
 
548
  }else{
549
  $data_array ['post_date'] = date('Y-m-d H:i:s', strtotime($data_array ['post_date']));
 
550
  }
551
  if(isset($data_array ['post_slug'])){
552
  $data_array ['post_name'] = $data_array ['post_slug'];
@@ -556,15 +585,17 @@ class EshopActions extends SkinnyActions {
556
  if($data_array){
557
  if($ret_array['importallwithps'] == 3){
558
  $data_array['post_password'] = $ret_array['globalpassword_txt'];
559
-
560
  }
561
  }
562
- if ($data_array)
563
  $post_id = wp_insert_post($data_array);
 
 
564
 
565
  unset($postauthor);
566
  if ($post_id) {
567
- $custom_array = $this->eshopMetaData($new_post, $post_id);
568
  $uploaded_file_name=$session_arr['uploadedFile'];
569
  $real_file_name = $session_arr['uploaded_csv_name'];
570
  // $version = $session_arr['currentfileversion'];
@@ -615,18 +646,30 @@ class EshopActions extends SkinnyActions {
615
 
616
  // Create/Add tags to post
617
  if (!empty ($tags)) {
 
618
  foreach ($tags as $tag_key => $tag_value) {
 
619
  wp_set_post_tags($post_id, $tag_value);
620
  }
 
621
  }
622
 
623
  // Create/Add category to post
624
  if (!empty ($categories)) {
 
 
625
  $split_cate = explode('|', $categories ['post_category']);
626
  foreach ($split_cate as $key => $val) {
627
- if (is_numeric($val))
628
  $split_cate[$key] = 'uncategorized';
 
 
 
629
  }
 
 
 
 
630
  wp_set_object_terms($post_id, $split_cate, 'category');
631
  }
632
  // Add featured image
@@ -656,6 +699,8 @@ class EshopActions extends SkinnyActions {
656
  $skippedRecords[] = $_SESSION['SMACK_SKIPPED_RECORDS'];
657
  }
658
  }
 
 
659
  unset($data_array);
660
  }
661
  /**
96
  * @param string type = (title|content), string content
97
  * @return boolean
98
  */
99
+ function duplicateChecks($type = 'title', $text, $gettype, $currentLimit, $postTitle)
100
  {
101
  global $wpdb;
102
  $gettype = 'post';
113
  similar_text($strippedTextPCont, $strippedText, $p);
114
  if ($p == 100) {
115
  $this->dupPostCount++;
116
+ $this->detailedLog[$currentLimit]['post_id'] = "Created record no $currentLimit - failed";
117
  return false;
118
  }
119
  }
124
  return true;
125
  }
126
  $this->dupPostCount++;
127
+ $this->detailedLog[$currentLimit]['post_id'] = "Created record no $currentLimit - failed";
128
  return false;
129
  }
130
 
164
  * @param $post_id
165
  * @return mixed
166
  */
167
+ public function eshopMetaData($new_post, $post_id, $currentLimit) {
168
  global $wpdb;
169
  $eshopoptions = get_option('eshop_plugin_settings');
170
  foreach ($new_post as $ckey => $cval) {
199
  update_post_meta($post_id, '_eshop_stock', 1);
200
  }
201
  break;
202
+ case 'cart_option' :
203
  $cartOption = strtolower($new_post[$ckey]);
204
  if ($cartOption == 'yes' || $cartOption == 'no') {
205
  $cartOption = 0;
217
  break;
218
  case 'SKU' :
219
  $metaDatas['sku'] = $new_post[$ckey];
220
+ $this->detailedLog[$currentLimit]['SKU'] = "<b>SKU - </b>" . $metaDatas['sku'];
221
  break;
222
  case 'products_option':
223
  $productOptions = $new_post[$ckey];
279
  update_post_meta($post_id, '_eshop_product', $metaDatas);
280
  }
281
  if (!empty($tags)) {
282
+ $this->detailedLog[$currentLimit]['tags'] = "";
283
  foreach ($tags as $tag_key => $tag_value) {
284
+ $this->detailedLog[$currentLimit]['tags'] .= $tag_value . "|";
285
  $split_line = explode(',', $tag_value);
286
  $term_taxonomy_id_t = wp_set_object_terms($post_id, $split_line, "post_tag");
287
  }
288
+ $this->detailedLog[$currentLimit]['tags'] = "<b>Tags - </b>" .substr($this->detailedLog[$currentLimit]['tags'], 0, -1);
289
  }
290
  if (!empty($categories)) {
291
+ $this->detailedLog[$currentLimit]['category'] = "";
292
  foreach ($categories as $cat_key => $cat_value) {
293
+ $this->detailedLog[$currentLimit]['category'] .= $cat_value . "|";
294
  $split_line = explode('|', $cat_value);
295
  $term_taxonomy_id_c = wp_set_object_terms($post_id, $split_line, "category");
296
  }
297
+ $this->detailedLog[$currentLimit]['category'] = "<b>Category - </b>" .substr($this->detailedLog[$currentLimit]['category'], 0, -1);
298
  }
299
  #TODO: $term_taxonomy_id_c, $term_taxonomy_id_t not used in this function / overwritten immediately
300
  return $metaDatas;
305
  *
306
  * @return boolean
307
  */
308
+ function processDataInWP($data_rows,$ret_array,$session_arr,$currentLimit)
309
  {
310
  global $wpdb;
311
  $post_id = '';
422
  require_once(WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY.'/includes/WPImporter_includes_helper.php');
423
  $impCE = new WPImporter_includes_helper();
424
 
425
+ $impCE->get_fimg_from_URL($f_img,$fimg_path,$fimg_name,$post_slug_value,$currentLimit,$this);
426
  $filepath = $fimg_path."/" . $post_slug_value . "-" . $fimg_name;
427
 
428
  if(@getimagesize($filepath)){
461
  $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['custompostlist'];
462
  }
463
  if ($this->titleDupCheck == 'true')
464
+ $this->postFlag = $this->duplicateChecks('title', $data_array ['post_title'], $data_array ['post_type'], $currentLimit, $data_array ['post_title']);
465
 
466
  if ($this->conDupCheck == 'true' && $this->postFlag)
467
+ $this->postFlag = $this->duplicateChecks('content', $data_array ['post_content'], $data_array ['post_type'], $currentLimit, $data_array ['post_title']);
468
 
469
  if ($this->postFlag) {
470
  unset ($sticky);
478
  switch ($data_array ['post_status']) {
479
  case 1 :
480
  $data_array['post_status'] = 'publish';
481
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>publish";
482
  break;
483
  case 2 :
484
  $data_array['post_status'] = 'publish';
485
  $sticky = true;
486
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>sticky";
487
  break;
488
  case 3 :
489
  $data_array['post_status'] = 'publish';
490
  $data_array ['post_password'] = $_POST ['postsPassword'];
491
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
492
  break;
493
  case 4 :
494
  $data_array ['post_status'] = 'private';
495
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>private";
496
  break;
497
  case 5 :
498
  $data_array ['post_status'] = 'draft';
499
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>draft";
500
  break;
501
  case 6 :
502
  $data_array ['post_status'] = 'pending';
503
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>pending";
504
  break;
505
  default :
506
  $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
513
  $postpwd = substr($poststatus, 0, -1);
514
  $data_array['post_status'] = 'publish';
515
  $data_array ['post_password'] = $postpwd;
516
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
517
  } else {
518
  $data_array['post_status'] = 'publish';
519
  $data_array ['post_password'] = $poststatus;
520
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $data_array['post_password'];
521
  }
522
  } else {
523
  $data_array['post_status'] = 'publish';
524
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>publish";
525
  }
526
  }
527
  if ($data_array['post_status'] == 'sticky') {
528
  $data_array['post_status'] = 'publish';
529
  $sticky = true;
530
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>sticky";
531
+ }
532
+ else {
533
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>" . $data_array['post_status'];
534
  }
 
535
  }
536
 
537
  // Author name/id update
543
  $postauthor = array();
544
 
545
  if ($authorLen == $postAuthorLen) {
546
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = \"{$postuserid}\"");
547
  if(empty($postauthor) || !$postauthor[0]->ID) { // If user name are numeric Ex: 1300001
548
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where user_login = \"{$postuserid}\"");
549
  }
550
  } else {
551
+ $postauthor = $wpdb->get_results("select ID,user_login from $wpdb->users where user_login = \"{$postuserid}\"");
552
  }
553
 
554
  if (empty($postauthor) || !$postauthor[0]->ID) {
555
  $data_array ['post_author'] = 1;
556
+ $admindet = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = 1");
557
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
558
  $this->noPostAuthCount++;
559
  } else {
560
  $data_array ['post_author'] = $postauthor [0]->ID;
561
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - </b>" . $postauthor[0]->user_login;
562
  }
563
  }
564
  else{
565
  $data_array ['post_author'] = 1;
566
+ $admindet = $wpdb->get_results("select ID,user_login from $wpdb->users where ID = 1");
567
+ $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
568
  $this->noPostAuthCount++;
569
  }
570
 
571
  // Date format post
572
+ $data_array ['post_date'] = str_replace('/', '-', $data_array ['post_date']);
573
  if (!isset($data_array ['post_date'])){
574
  $data_array ['post_date'] = date('Y-m-d H:i:s');
575
+ $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array ['post_date'];
576
  }else{
577
  $data_array ['post_date'] = date('Y-m-d H:i:s', strtotime($data_array ['post_date']));
578
+ $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array ['post_date'];
579
  }
580
  if(isset($data_array ['post_slug'])){
581
  $data_array ['post_name'] = $data_array ['post_slug'];
585
  if($data_array){
586
  if($ret_array['importallwithps'] == 3){
587
  $data_array['post_password'] = $ret_array['globalpassword_txt'];
588
+ $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $ret_array['globalpassword_txt'];
589
  }
590
  }
591
+ if ($data_array) {
592
  $post_id = wp_insert_post($data_array);
593
+ $this->detailedLog[$currentLimit]['post_id'] = "<b>Created Post_ID - </b>" . $post_id . " - success";
594
+ }
595
 
596
  unset($postauthor);
597
  if ($post_id) {
598
+ $custom_array = $this->eshopMetaData($new_post, $post_id, $currentLimit);
599
  $uploaded_file_name=$session_arr['uploadedFile'];
600
  $real_file_name = $session_arr['uploaded_csv_name'];
601
  // $version = $session_arr['currentfileversion'];
646
 
647
  // Create/Add tags to post
648
  if (!empty ($tags)) {
649
+ $this->detailedLog[$currentLimit]['tags'] = "";
650
  foreach ($tags as $tag_key => $tag_value) {
651
+ $this->detailedLog[$currentLimit]['tags'] .= $tag_value . "|";
652
  wp_set_post_tags($post_id, $tag_value);
653
  }
654
+ $this->detailedLog[$currentLimit]['tags'] = "<b>Tags - </b>" .substr($this->detailedLog[$currentLimit]['tags'], 0, -1);
655
  }
656
 
657
  // Create/Add category to post
658
  if (!empty ($categories)) {
659
+ $this->detailedLog[$currentLimit]['category'] = "";
660
+ $assigned_categories = array();
661
  $split_cate = explode('|', $categories ['post_category']);
662
  foreach ($split_cate as $key => $val) {
663
+ if (is_numeric($val)) {
664
  $split_cate[$key] = 'uncategorized';
665
+ $assigned_categories['uncategorized'] = 'uncategorized';
666
+ }
667
+ $assigned_categories[$val] = $val;
668
  }
669
+ foreach($assigned_categories as $cateKey => $cateVal) {
670
+ $this->detailedLog[$currentLimit]['category'] .= $cateKey . "|";
671
+ }
672
+ $this->detailedLog[$currentLimit]['category'] = "<b>Category - </b>" .substr($this->detailedLog[$currentLimit]['category'], 0, -1);
673
  wp_set_object_terms($post_id, $split_cate, 'category');
674
  }
675
  // Add featured image
699
  $skippedRecords[] = $_SESSION['SMACK_SKIPPED_RECORDS'];
700
  }
701
  }
702
+ $this->detailedLog[$currentLimit]['verify_here'] = "<b>Verify Here -</b> <a href='" . get_permalink( $post_id ) . "' title='" . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $data_array['post_title'] ) ) . "' rel='permalink'>" . __( 'Web View' ) . "</a> | <a href='" . get_edit_post_link( $post_id, true ) . "' title='" . esc_attr( __( 'Edit this item' ) ) . "'>" . __( 'Admin View' ) . "</a>";
703
+
704
  unset($data_array);
705
  }
706
  /**
modules/export/actions/actions.php CHANGED
@@ -1,44 +1,13 @@
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
- class ExportActions extends SkinnyActions
39
- {
40
- public function __construct()
41
- {
42
 
43
  }
44
 
@@ -47,16 +16,13 @@ class ExportActions extends SkinnyActions
47
  * @param array $request
48
  * @return array
49
  */
50
- public function executeIndex($request)
51
- {
52
  // return an array of name value pairs to send data to the template
53
  $data = array();
54
- if(!empty($request['POST']))
55
- {
56
  $type = $request['POST']['export'];
57
  $filename = $request['POST']['export_filename'];
58
- if(!empty($type) && !empty($filename))
59
- {
60
  $helper = new ultimatecsv_include_helper();
61
  $helper->generateanddownloadcsv($type, $filename);
62
  }
@@ -64,21 +30,27 @@ class ExportActions extends SkinnyActions
64
  return $data;
65
  }
66
 
67
- public function executeExport($request)
68
- {
 
 
 
 
69
  $data = array();
 
70
  ob_start();
71
  global $wpdb;
72
  $Header = $PostData = $PostMetaData = $TermsData = $ExportData = array();
73
  $exporttype = $request['POST']['export'];
74
  $export_filename = $request['POST']['export_filename'];
75
- if($export_filename)
76
- $csv_file_name = $export_filename.'.csv';
77
- else
78
- $csv_file_name='exportas_'.$exporttype.'_'.date("Y-m-d").'.csv';;
 
 
79
 
80
- if($exporttypei == 'post' || $exporttype == 'page')
81
- {
82
  $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$exporttype'";
83
  $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_%'";
84
  $result_header_query1 = $wpdb->get_results($header_query1);
@@ -86,15 +58,17 @@ class ExportActions extends SkinnyActions
86
 
87
  foreach ($result_header_query1 as $rhq1_key) {
88
  foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
89
- if (!in_array($rhq1_headkey, $Header))
90
  $Header[] = $rhq1_headkey;
 
91
  }
92
  }
93
 
94
  foreach ($result_header_query2 as $rhq2_headkey) {
95
  if (!in_array($rhq2_headkey->meta_key, $Header)) {
96
- if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file')
97
  $Header[] = $rhq2_headkey->meta_key;
 
98
  }
99
  }
100
 
@@ -102,21 +76,21 @@ class ExportActions extends SkinnyActions
102
  $Header[] = 'featured_image';
103
  $Header[] = 'post_category';
104
  // Code for ACF fields
105
- $limit = ( int ) apply_filters ( 'postmeta_form_limit', 30 );
106
- $get_acf_fields = $wpdb->get_col ( "SELECT meta_value FROM $wpdb->postmeta
107
  GROUP BY meta_key
108
  HAVING meta_key LIKE 'field_%'
109
  ORDER BY meta_key
110
- LIMIT $limit" );
111
 
112
- foreach ( $get_acf_fields as $acf_value ){
113
  $get_acf_field = unserialize($acf_value);
114
- $acf_fields[$get_acf_field['name']] = "CF: ".$get_acf_field['name'];
115
- $acf_fields_slug[$get_acf_field['name']] = "_".$get_acf_field['name'];
116
- if(in_array("_".$get_acf_field['name'],$Header)){
117
- $Header = array_diff($Header,$acf_fields_slug);
118
  }
119
- if($get_acf_field['type'] == 'checkbox'){
120
  $checkbox_option_fields[] = $get_acf_field['name'];
121
  }
122
  } // Code ends here
@@ -154,12 +128,13 @@ class ExportActions extends SkinnyActions
154
  }
155
  }
156
  $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";
157
- $result_query2 = $wpdb->get_results($query2);
158
  if (!empty($result_query2)) {
159
  foreach ($result_query2 as $postmeta) {
160
  if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
161
- if(is_array($acf_fields_slug) && !in_array($postmeta->meta_key,$acf_fields_slug))
162
  $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
 
163
  }
164
  $eshop_products = $postmeta->meta_value;
165
  if ($postmeta->meta_key == 'products') {
@@ -179,9 +154,9 @@ class ExportActions extends SkinnyActions
179
  $postmeta->meta_key = 'featured_image';
180
  $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
181
  }
182
- if(is_array($checkbox_option_fields) && in_array($postmeta->meta_key,$checkbox_option_fields)){
183
  $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
184
- $eshop_products = unserialize($eshop_products);
185
  foreach ($eshop_products as $key) {
186
  $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key . ',';
187
  }
@@ -214,84 +189,1220 @@ class ExportActions extends SkinnyActions
214
  $ExportData[$pd_key] = $PostData[$pd_key];
215
  }
216
  if (array_key_exists($pd_key, $TermsData)) {
217
- if (empty($ExportData[$pd_key]))
218
  $ExportData[$pd_key] = array();
 
219
  $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
220
  }
221
  }
222
 
223
  foreach ($Header as $header_key) {
224
  foreach ($ExportData as $ED_key) {
225
- if (array_key_exists($header_key, $ED_key))
226
  $CSVContent[$header_key][] = $ED_key[$header_key];
227
- else
228
  $CSVContent[$header_key][] = '';
 
229
  }
230
  }
231
  }
232
 
233
- # GENERATE AS CSV
 
234
  for ($j = 0; $j < $fieldsCount; $j++) {
235
  foreach ($Header as $value) {
236
  $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '",';
237
  }
238
  }
239
-
240
  foreach ($Header as $csv_header) {
241
- if ($csv_header == '_eshop_stock')
242
  $csv_header = 'stock_available';
243
- if ($csv_header == 'cart_radio')
 
244
  $csv_header = 'cart_option';
245
- if ($csv_header == 'sale')
 
246
  $csv_header = 'product_in_sale';
247
- if ($csv_header == 'featured')
 
248
  $csv_header = 'featured_product';
249
- if ($csv_header == 'sku' || $csv_header == '_wpsc_sku')
 
250
  $csv_header = 'SKU';
251
- if ($csv_header == '_aioseop_keywords')
 
252
  $csv_header = 'seo_keywords';
253
- if ($csv_header == '_aioseop_description')
 
254
  $csv_header = 'seo_description';
255
- if ($csv_header == '_aioseop_title')
 
256
  $csv_header = 'seo_title';
257
- if ($csv_header == '_aioseop_noindex')
 
258
  $csv_header = 'seo_noindex';
259
- if ($csv_header == '_aioseop_nofollow')
 
260
  $csv_header = 'seo_nofollow';
261
- if ($csv_header == '_aioseop_disable')
 
262
  $csv_header = 'seo_disable';
263
- if ($csv_header == '_aioseop_disable_analytics')
 
264
  $csv_header = 'seo_disable_analytics';
265
- if ($csv_header == '_yoast_wpseo_focuskw')
 
266
  $csv_header = 'focus_keyword';
267
- if ($csv_header == '_yoast_wpseo_title')
 
268
  $csv_header = 'title';
269
- if ($csv_header == '_yoast_wpseo_metadesc')
 
270
  $csv_header = 'meta_desc';
271
- if ($csv_header == '_yoast_wpseo_meta-robots-noindex')
 
272
  $csv_header = 'meta-robots-noindex';
273
- if ($csv_header == '_yoast_wpseo_meta-robots-nofollow')
 
274
  $csv_header = 'meta-robots-nofollow';
275
- if ($csv_header == '_yoast_wpseo_meta-robots-adv')
 
276
  $csv_header = 'meta-robots-adv';
277
- if ($csv_header == '_yoast_wpseo_sitemap-include')
 
278
  $csv_header = 'sitemap-include';
279
- if ($csv_header == '_yoast_wpseo_sitemap-prio')
 
280
  $csv_header = 'sitemap-prio';
281
- if ($csv_header == '_yoast_wpseo_canonical')
 
282
  $csv_header = 'canonical';
283
- if ($csv_header == '_yoast_wpseo_redirect')
 
284
  $csv_header = 'redirect';
285
- if ($csv_header == '_yoast_wpseo_opengraph-description')
 
286
  $csv_header = 'opengraph-description';
287
- if ($csv_header == '_yoast_wpseo_google-plus-description')
 
288
  $csv_header = 'google-plus-description';
289
- if (array_key_exists($csv_header,$acf_fields))
 
290
  $csv_header = $acf_fields[$csv_header];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
 
 
 
 
 
 
 
292
  $CSV_FILE_CONTENT .= $csv_header . ",";
293
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
296
  $CSV_FILE_CONTENT .= "\n";
297
  if ($CSVDATA) {
@@ -301,6 +1412,10 @@ class ExportActions extends SkinnyActions
301
  }
302
  }
303
  }
 
 
 
 
304
  header("Content-type: text/x-csv"); # DECLARING FILE TYPE
305
  header("Content-Transfer-Encoding: binary");
306
  header("Content-Disposition: attachment; filename=" . $csv_file_name); # EXPORT GENERATED CSV FILE
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
 
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
  }
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);
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
 
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
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') {
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
  }
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) {
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
modules/export/templates/export.php CHANGED
@@ -1,787 +1,663 @@
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('../../../../../../wp-load.php');
39
- global $wpdb;
40
- $Header = $PostData = $PostMetaData = $TermsData = $ExportData = array();
41
- $checkbox_option_fields = $CSVDATA = array();
42
- $acf_fields_slug = array();
43
- $acf_fields = array();
44
- $export_delimiter = ',';
45
- $CSV_FILE_CONTENT = $pId = '';
46
- $exporttype = $_POST['export'];
47
- $wpcsvsettings = get_option('wpcsvfreesettings');
48
- if(isset($wpcsvsettings['export_delimiter'])) {
49
- $export_delimiter = $wpcsvsettings['export_delimiter'];
50
- }
51
 
52
- if ($_POST['export_filename']) {
53
- $csv_file_name = $_POST['export_filename'] . '.csv';
54
- } else {
55
- $csv_file_name = 'exportas_' . date("Y") . '-' . date("m") . '-' . date("d") . '.csv';
56
- }
57
- $wptypesfields = get_option('wpcf-fields');
58
 
59
- function get_types_values($value) {
60
- return true;
61
- }
62
 
63
- if ($exporttype == 'post' || $exporttype == 'page' || $exporttype == 'custompost') {
64
- if ($exporttype == 'custompost') {
65
- $exporttype = $_POST['export_post_type'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
- $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$exporttype'";
68
- $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%'";
69
- $result_header_query1 = $wpdb->get_results($header_query1);
70
- $result_header_query2 = $wpdb->get_results($header_query2);
71
 
72
- foreach ($result_header_query1 as $rhq1_key) {
73
- foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
74
- if (!in_array($rhq1_headkey, $Header)) {
75
- $Header[] = $rhq1_headkey;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
  }
78
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- foreach ($result_header_query2 as $rhq2_headkey) {
81
- if (!in_array($rhq2_headkey->meta_key, $Header)) {
82
- if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file') {
83
- $Header[] = $rhq2_headkey->meta_key;
84
  }
 
85
  }
 
 
 
 
 
86
  }
87
 
88
- $Header[] = 'post_tag';
89
- $Header[] = 'featured_image';
90
- $Header[] = 'post_category';
91
- // Code for ACF fields
92
- $limit = ( int )apply_filters('postmeta_form_limit', 30);
93
- $get_acf_fields = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta
94
- GROUP BY meta_key
95
- HAVING meta_key LIKE 'field_%'
96
- ORDER BY meta_key
97
- LIMIT $limit");
 
98
 
99
- foreach ($get_acf_fields as $acf_value) {
100
- $get_acf_field = unserialize($acf_value);
101
- $acf_fields[$get_acf_field['name']] = "CF: " . $get_acf_field['name'];
102
- $acf_fields_slug[$get_acf_field['name']] = "_" . $get_acf_field['name'];
103
- if (in_array("_" . $get_acf_field['name'], $Header)) {
104
- $Header = array_diff($Header, $acf_fields_slug);
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
- if ($get_acf_field['type'] == 'checkbox') {
107
- $checkbox_option_fields[] = $get_acf_field['name'];
108
  }
109
- } // Code ends here
110
- $get_post_ids = "select DISTINCT ID from $wpdb->posts where post_type = '$exporttype' and post_status in ('publish','draft','future','private','pending')";
111
 
112
- $result = $wpdb->get_col($get_post_ids);
113
- $fieldsCount = count($result);
114
- // $pId='';
115
- if ($result) {
116
- foreach ($result as $postID) {
117
- $pId = $pId . ',' . $postID;
118
- $query1 = "SELECT wp.* FROM $wpdb->posts wp where ID=$postID";
119
- $result_query1 = $wpdb->get_results($query1);
120
- if (!empty($result_query1)) {
121
- foreach ($result_query1 as $posts) {
122
- foreach ($posts as $post_key => $post_value) {
123
- if ($post_key == 'post_status') {
124
- if (is_sticky($postID)) {
125
- $PostData[$postID][$post_key] = 'Sticky';
126
- $post_status = 'Sticky';
127
- } else {
128
- $PostData[$postID][$post_key] = $post_value;
129
- $post_status = $post_value;
130
- }
131
- } else {
132
- $PostData[$postID][$post_key] = $post_value;
133
- }
134
- if ($post_key == 'post_password') {
135
- if ($post_value) {
136
- $PostData[$postID]['post_status'] = "{" . $post_value . "}";
137
- } else {
138
- $PostData[$postID]['post_status'] = $post_status;
139
- }
140
- }
141
- }
142
  }
 
143
  }
144
- $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";
145
- $result_query2 = $wpdb->get_results($query2);
146
- $possible_values = array('s:', 'a:', ':{');
147
- if (!empty($result_query2)) {
148
- foreach ($result_query2 as $postmeta) {
149
- $typesFserialized = 0;
150
- $isFound = explode('wpcf-', $postmeta->meta_key);
151
- if (count($isFound) == 2) {
152
- foreach ($wptypesfields as $typesKey => $typesVal) {
153
- if ($postmeta->meta_key == 'wpcf-' . $typesKey) {
154
- foreach ($possible_values as $posval) {
155
- if (strpos($postmeta->meta_value, $posval)) {
156
- $typesFserialized = 1;
157
- } else {
158
- $typesFserialized = 0;
159
- }
160
- }
161
- if ($typesFserialized == 1) {
162
- $getMetaData = get_post_meta($postID, $postmeta->meta_key);
163
- if (!is_array($getMetaData[0])) {
164
- $get_all_values = unserialize($getMetaData[0]);
165
- $get_values = $get_all_values[0];
166
- } else {
167
- $get_values = $getMetaData[0];
168
- }
169
- $typesFVal = null;
170
- if ($typesVal['type'] == 'checkboxes') {
171
- foreach ($get_values as $authorKey => $authorVal) {
172
- foreach ($typesVal['data']['options'] as $doKey => $doVal) {
173
- if ($doKey == $authorKey) {
174
- $typesFVal .= $doVal['title'] . ',';
175
- }
176
- }
177
- }
178
- $typesFVal = substr($typesFVal, 0, -1);
179
- } elseif ($typesVal['type'] == 'skype') {
180
- $typesFVal = $get_values['skypename'];
181
- }
182
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $typesFVal;
183
- } else {
184
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
185
- }
186
- }
187
  }
188
  } else {
189
- if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
190
- if (is_array($acf_fields_slug) && !in_array($postmeta->meta_key, $acf_fields_slug)) {
191
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
192
- }
 
 
 
193
  }
194
- $eshop_products = $postmeta->meta_value;
195
- if ($postmeta->meta_key == 'products') {
196
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
197
- $eshop_products = unserialize($eshop_products);
198
- foreach ($eshop_products as $key) {
199
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key['option'] . '|' . $key['price'] . '|' . $key['saleprice'] . ',';
200
- }
201
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
202
  }
203
- if ($postmeta->meta_key == '_thumbnail_id') {
204
- $attachment_file = '';
205
- $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
206
- $attachment = $wpdb->get_results($get_attachement);
207
- $attachment_file = $attachment[0]->guid;
208
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
209
- $postmeta->meta_key = 'featured_image';
210
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
211
- }
212
- if (is_array($checkbox_option_fields) && in_array($postmeta->meta_key, $checkbox_option_fields)) {
213
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
214
- $eshop_products = unserialize($eshop_products);
215
- foreach ($eshop_products as $key) {
216
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] .= $key . ',';
217
- }
218
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = substr($PostMetaData[$postmeta->post_id][$postmeta->meta_key], 0, -1);
219
  }
220
  }
221
  }
222
  }
223
- // Tags & Categories
224
- $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
225
- $postTags = $postCategory = '';
226
- foreach ($get_tags as $tags) {
227
- $postTags .= $tags . ',';
228
- }
229
- $postTags = substr($postTags, 0, -1);
230
- $TermsData[$postID]['post_tag'] = $postTags;
231
- $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
232
- foreach ($get_categotries as $category) {
233
- $postCategory .= $category . '|';
234
- }
235
- $postCategory = substr($postCategory, 0, -1);
236
- $TermsData[$postID]['post_category'] = $postCategory;
237
- }
238
- $ExportData = array();
239
- // Merge all arrays
240
- foreach ($PostData as $pd_key => $pd_val) {
241
- if (array_key_exists($pd_key, $PostMetaData)) {
242
- $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
243
- } else {
244
- $ExportData[$pd_key] = $PostData[$pd_key];
245
- }
246
- if (array_key_exists($pd_key, $TermsData)) {
247
- if (empty($ExportData[$pd_key])) {
248
- $ExportData[$pd_key] = array();
249
- }
250
- $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
251
- }
252
- }
253
-
254
- foreach ($Header as $header_key) {
255
- foreach ($ExportData as $ED_key) {
256
- if (array_key_exists($header_key, $ED_key)) {
257
- $CSVContent[$header_key][] = $ED_key[$header_key];
258
- } else {
259
- $CSVContent[$header_key][] = '';
260
- }
261
- }
262
- }
263
- }
264
- for ($j = 0; $j < $fieldsCount; $j++) {
265
- foreach ($Header as $value) {
266
- if (!isset($CSVDATA[$j])) {
267
- $CSVDATA[$j] = null;
268
- }
269
- $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '"' . $export_delimiter;
270
  }
 
271
  }
272
- foreach ($Header as $csv_header) {
273
- if ($csv_header == '_eshop_stock') {
274
- $csv_header = 'stock_available';
275
- }
276
- if ($csv_header == 'cart_radio') {
277
- $csv_header = 'cart_option';
278
- }
279
- if ($csv_header == 'sale') {
280
- $csv_header = 'product_in_sale';
281
- }
282
- if ($csv_header == 'featured') {
283
- $csv_header = 'featured_product';
284
- }
285
- if ($csv_header == 'sku' || $csv_header == '_wpsc_sku') {
286
- $csv_header = 'SKU';
287
- }
288
- if ($csv_header == '_aioseop_keywords') {
289
- $csv_header = 'seo_keywords';
290
- }
291
- if ($csv_header == '_aioseop_description') {
292
- $csv_header = 'seo_description';
293
- }
294
- if ($csv_header == '_aioseop_title') {
295
- $csv_header = 'seo_title';
296
- }
297
- if ($csv_header == '_aioseop_noindex') {
298
- $csv_header = 'seo_noindex';
299
- }
300
- if ($csv_header == '_aioseop_nofollow') {
301
- $csv_header = 'seo_nofollow';
302
- }
303
- if ($csv_header == '_aioseop_disable') {
304
- $csv_header = 'seo_disable';
305
- }
306
- if ($csv_header == '_aioseop_disable_analytics') {
307
- $csv_header = 'seo_disable_analytics';
308
- }
309
- if ($csv_header == '_yoast_wpseo_focuskw') {
310
- $csv_header = 'focus_keyword';
311
- }
312
- if ($csv_header == '_yoast_wpseo_title') {
313
- $csv_header = 'title';
314
- }
315
- if ($csv_header == '_yoast_wpseo_metadesc') {
316
- $csv_header = 'meta_desc';
317
- }
318
- if ($csv_header == '_yoast_wpseo_meta-robots-noindex') {
319
- $csv_header = 'meta-robots-noindex';
320
- }
321
- if ($csv_header == '_yoast_wpseo_meta-robots-nofollow') {
322
- $csv_header = 'meta-robots-nofollow';
323
- }
324
- if ($csv_header == '_yoast_wpseo_meta-robots-adv') {
325
- $csv_header = 'meta-robots-adv';
326
- }
327
- if ($csv_header == '_yoast_wpseo_sitemap-include') {
328
- $csv_header = 'sitemap-include';
329
- }
330
- if ($csv_header == '_yoast_wpseo_sitemap-prio') {
331
- $csv_header = 'sitemap-prio';
332
- }
333
- if ($csv_header == '_yoast_wpseo_canonical') {
334
- $csv_header = 'canonical';
335
- }
336
- if ($csv_header == '_yoast_wpseo_redirect') {
337
- $csv_header = 'redirect';
338
- }
339
- if ($csv_header == '_yoast_wpseo_opengraph-description') {
340
- $csv_header = 'opengraph-description';
341
- }
342
- if ($csv_header == '_yoast_wpseo_google-plus-description') {
343
- $csv_header = 'google-plus-description';
344
- }
345
- if (array_key_exists($csv_header, $acf_fields)) {
346
- $csv_header = $acf_fields[$csv_header];
347
- }
348
- if($csv_header == 'ID')
349
- $csv_header = 'Id';
350
 
351
- $CSV_FILE_CONTENT .= $csv_header . "$export_delimiter";
 
 
 
 
 
 
 
 
352
  }
353
 
354
- $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
355
- $CSV_FILE_CONTENT .= "\n";
356
- if ($CSVDATA) {
357
- foreach ($CSVDATA as $csv_content) {
358
- $csv_content = substr($csv_content, 0, -1);
359
- $CSV_FILE_CONTENT .= $csv_content . "\n";
360
- }
 
 
 
 
 
 
 
361
  }
362
- }
363
- elseif($exporttype=='eshop')
364
- {
365
- $exporttype='post';
366
- //$csv_file_name='eshop_exported.csv';
367
- $header_query1 = "SELECT wp.* FROM $wpdb->posts wp where post_type = '$exporttype'";
368
- $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')";
369
- $result_header_query1 = $wpdb->get_results($header_query1);
370
- $result_header_query2 = $wpdb->get_results($header_query2);
371
- foreach ($result_header_query1 as $rhq1_key) {
372
- foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
373
- if (!in_array($rhq1_headkey, $Header))
374
- if($rhq1_headkey != 'to_ping' && $rhq1_headkey != 'pinged' && $rhq1_headkey != 'post_mime_type')
375
- $Header[] = $rhq1_headkey;
376
- }
 
 
 
 
 
377
  }
378
- foreach ($result_header_query2 as $rhq2_headkey) {
379
- if (!in_array($rhq2_headkey->meta_key, $Header)) {
380
- 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')
381
- $Header[] = $rhq2_headkey->meta_key;
382
- }
 
 
383
  }
384
- $Header[] = 'products_option';
385
- $Header[] = 'regular_price';
386
- $Header[] = 'sale_price';
387
- $Header[] = 'featured_image';
388
- $Header[] = 'post_tag';
389
- $Header[] = 'post_category';
390
- $get_post_ids = "select DISTINCT ID from $wpdb->posts p join $wpdb->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'";
391
 
392
- $result = $wpdb->get_col($get_post_ids);
393
- $fieldsCount = count($result);
394
- if ($result) {
395
- foreach ($result as $postID) {
396
- $pId = $pId . ',' . $postID;
397
- $query1 = "SELECT wp.* FROM $wpdb->posts wp where ID=$postID";
398
- $result_query1 = $wpdb->get_results($query1);
399
- if (!empty($result_query1)) {
400
- foreach ($result_query1 as $posts) {
401
- foreach ($posts as $post_key => $post_value) {
402
- if ($post_key == 'post_status') {
403
- if (is_sticky($postID)) {
404
- $PostData[$postID][$post_key] = 'Sticky';
405
- $post_status = 'Sticky';
406
- } else {
407
- $PostData[$postID][$post_key] = $post_value;
408
- $post_status = $post_value;
409
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  } else {
411
- $PostData[$postID][$post_key] = $post_value;
412
- }
413
- if ($post_key == 'post_password') {
414
- if ($post_value) {
415
- $PostData[$postID]['post_status'] = "{" . $post_value . "}";
416
- } else {
417
- $PostData[$postID]['post_status'] = $post_status;
418
  }
419
- }
420
- }
421
- }
422
- }
423
- $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";
424
- $result_query2 = $wpdb->get_results($query2);
425
- $possible_values = array('s:', 'a:', ':{');
426
- if (!empty($result_query2)) {
427
- foreach ($result_query2 as $postmeta) {
428
- $typesFserialized = 0;
429
- $isFound = explode('wpcf-',$postmeta->meta_key);
430
- if(count($isFound) == 2){
431
- foreach($wptypesfields as $typesKey => $typesVal){
432
- if($postmeta->meta_key == 'wpcf-'.$typesKey){
433
- foreach($possible_values as $posval){
434
- if(strpos($postmeta->meta_value,$posval)){
435
- $typesFserialized = 1;
436
  } else {
437
- $typesFserialized = 0;
438
  }
 
439
  }
440
- if($typesFserialized == 1){
441
- $getMetaData = get_post_meta($postID, $postmeta->meta_key);
442
- if(!is_array($getMetaData[0])){
443
- $get_all_values = unserialize($getMetaData[0]);
444
- $get_values = $get_all_values[0];
445
- } else {
446
- $get_values = $getMetaData[0];
447
- }
448
- $typesFVal = null;
449
- if($typesVal['type'] == 'checkboxes'){
450
- foreach($get_values as $authorKey => $authorVal) {
451
- foreach($typesVal['data']['options'] as $doKey => $doVal){
452
- if($doKey == $authorKey)
453
- $typesFVal .= $doVal['title'].',';
454
- }
455
  }
456
- $typesFVal = substr($typesFVal, 0, -1);
457
- } elseif($typesVal['type'] == 'skype') {
458
- $typesFVal = $get_values['skypename'];
 
 
 
 
 
 
 
 
 
 
459
  }
460
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $typesFVal;
461
- } else {
462
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
 
 
 
 
 
 
 
 
463
  }
 
 
 
 
 
 
 
 
 
 
 
464
  }
465
- }
466
- } else {
467
- if ($postmeta->meta_key != '_eshop_product' && $postmeta->meta_key != '_thumbnail_id') {
468
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $postmeta->meta_value;
469
  }
470
- $eshop_products = $postmeta->meta_value;
471
- if ($postmeta->meta_key == 'products') {
472
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
473
- $eshop_products = unserialize($eshop_products);
474
- $PostMetaData[$postmeta->post_id]['products_option']='';
475
- $PostMetaData[$postmeta->post_id]['sale_price']='';
476
- $PostMetaData[$postmeta->post_id]['regular_price']='';
477
- foreach ($eshop_products as $key) {
478
- $PostMetaData[$postmeta->post_id]['products_option'] .= $key['option'] . ',';
479
- $PostMetaData[$postmeta->post_id]['sale_price'] .= $key['saleprice'] . ',';
480
- $PostMetaData[$postmeta->post_id]['regular_price'] .= $key['price'] . ',';
481
- }
482
- $PostMetaData[$postmeta->post_id]['products_option'] = substr($PostMetaData[$postmeta->post_id]['products_option'], 0, -1);
483
- $PostMetaData[$postmeta->post_id]['sale_price'] = substr($PostMetaData[$postmeta->post_id]['sale_price'], 0, -1);
484
- $PostMetaData[$postmeta->post_id]['regular_price'] = substr($PostMetaData[$postmeta->post_id]['regular_price'], 0, -1);
485
  }
486
- if ($postmeta->meta_key == '_thumbnail_id') {
487
- $attachment_file = '';
488
- $get_attachement = "select guid from $wpdb->posts where ID = $postmeta->meta_value AND post_type = 'attachment'";
489
- $attachment = $wpdb->get_results($get_attachement);
490
- $attachment_file = $attachment[0]->guid;
491
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = '';
492
- $postmeta->meta_key = 'featured_image';
493
- $PostMetaData[$postmeta->post_id][$postmeta->meta_key] = $attachment_file;
494
  }
495
  }
496
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  }
498
- // Tags & Categories
499
- $get_tags = wp_get_post_tags($postID, array('fields' => 'names'));
500
- $postTags = $postCategory = '';
501
- foreach ($get_tags as $tags) {
502
- $postTags .= $tags . ',';
503
- }
504
- $postTags = substr($postTags, 0, -1);
505
- $TermsData[$postID]['post_tag'] = $postTags;
506
- $get_categotries = wp_get_post_categories($postID, array('fields' => 'names'));
507
- foreach ($get_categotries as $category) {
508
- $postCategory .= $category . '|';
509
- }
510
- $postCategory = substr($postCategory, 0, -1);
511
- $TermsData[$postID]['post_category'] = $postCategory;
512
- }
513
-
514
- $ExportData = array();
515
- // Merge all arrays
516
- foreach ($PostData as $pd_key => $pd_val) {
517
- if (array_key_exists($pd_key, $PostMetaData)) {
518
- $ExportData[$pd_key] = array_merge($PostData[$pd_key], $PostMetaData[$pd_key]);
519
- }
520
- if (array_key_exists($pd_key, $TermsData)) {
521
- $ExportData[$pd_key] = array_merge($ExportData[$pd_key], $TermsData[$pd_key]);
522
- }
523
- }
524
- foreach ($Header as $header_key) {
525
- foreach ($ExportData as $ED_key) {
526
- if (array_key_exists($header_key, $ED_key))
527
- $CSVContent[$header_key][] = $ED_key[$header_key];
528
- else
529
- $CSVContent[$header_key][] = '';
530
- }
531
- }
532
- }
533
- for ($j = 0; $j < $fieldsCount; $j++) {
534
- foreach ($Header as $value) {
535
- if ( ! isset($CSVDATA[$j])) {
536
- $CSVDATA[$j]= null;
537
- }
538
- $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '"' . $export_delimiter;
539
- }
540
  }
541
- foreach ($Header as $csv_header) {
542
- if ($csv_header == '_eshop_stock')
543
- $csv_header = 'stock_available';
544
- if ($csv_header == 'cart_radio')
545
- $csv_header = 'cart_option';
546
- if ($csv_header == 'sale')
547
- $csv_header = 'product_in_sale';
548
- if ($csv_header == 'featured')
549
- $csv_header = 'featured_product';
550
- if ($csv_header == 'sku')
551
- $csv_header = 'SKU';
552
- if ($csv_header == '_aioseop_keywords')
553
- $csv_header = 'seo_keywords';
554
- if ($csv_header == '_aioseop_description')
555
- $csv_header = 'seo_description';
556
- if ($csv_header == '_aioseop_title')
557
- $csv_header = 'seo_title';
558
- if ($csv_header == '_aioseop_noindex')
559
- $csv_header = 'seo_noindex';
560
- if ($csv_header == '_aioseop_nofollow')
561
- $csv_header = 'seo_nofollow';
562
- if ($csv_header == '_aioseop_disable')
563
- $csv_header = 'seo_disable';
564
- if ($csv_header == '_aioseop_disable_analytics')
565
- $csv_header = 'seo_disable_analytics';
566
- if ($csv_header == '_yoast_wpseo_focuskw')
567
- $csv_header = 'focus_keyword';
568
- if ($csv_header == '_yoast_wpseo_title')
569
- $csv_header = 'title';
570
- if ($csv_header == '_yoast_wpseo_metadesc')
571
- $csv_header = 'meta_desc';
572
- if ($csv_header == '_yoast_wpseo_meta-robots-noindex')
573
- $csv_header = 'meta-robots-noindex';
574
- if ($csv_header == '_yoast_wpseo_meta-robots-nofollow')
575
- $csv_header = 'meta-robots-nofollow';
576
- if ($csv_header == '_yoast_wpseo_meta-robots-adv')
577
- $csv_header = 'meta-robots-adv';
578
- if ($csv_header == '_yoast_wpseo_sitemap-include')
579
- $csv_header = 'sitemap-include';
580
- if ($csv_header == '_yoast_wpseo_sitemap-prio')
581
- $csv_header = 'sitemap-prio';
582
- if ($csv_header == '_yoast_wpseo_canonical')
583
- $csv_header = 'canonical';
584
- if ($csv_header == '_yoast_wpseo_redirect')
585
- $csv_header = 'redirect';
586
- if ($csv_header == '_yoast_wpseo_opengraph-description')
587
- $csv_header = 'opengraph-description';
588
- if ($csv_header == '_yoast_wpseo_google-plus-description')
589
- $csv_header = 'google-plus-description';
590
 
591
- if ($csv_header == 'post_tag')
592
- $csv_header = 'tags';
593
- if ($csv_header == 'post_category')
594
- $csv_header = 'category';
595
- if($csv_header == 'ID')
596
- $csv_header = 'Id';
597
- $CSV_FILE_CONTENT .= $csv_header . "$export_delimiter";
598
- }
599
- $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
600
- $CSV_FILE_CONTENT .= "\n";
601
- if ($CSVDATA) {
602
- foreach ($CSVDATA as $csv_content) {
603
- $csv_content = substr($csv_content, 0, -1);
604
- $CSV_FILE_CONTENT .= $csv_content . "\n";
605
- }
606
- }
607
- }
608
- elseif($exporttype=='users')
609
- {
610
- $uId = '';
611
- $header_query1 = "SELECT *FROM $wpdb->users";
612
- $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')";
613
- $result_header_query1 = $wpdb->get_results($header_query1);
614
- $result_header_query2 = $wpdb->get_results($header_query2);
615
- foreach ($result_header_query1 as $rhq1_key) {
616
- foreach ($rhq1_key as $rhq1_headkey => $rhq1_headval) {
617
- if (!in_array($rhq1_headkey, $Header))
618
- $Header[] = $rhq1_headkey;
619
- }
 
 
 
 
620
  }
621
- foreach ($result_header_query2 as $rhq2_headkey) {
622
- if (!in_array($rhq2_headkey->meta_key, $Header)) {
623
- if($rhq2_headkey->meta_key == 'mp_shipping_info' )
624
- {
625
- $mp_ship_header= unserialize($rhq2_headkey->meta_value);
626
- foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "msi: ".$mp_ship_key; }
627
- }
628
- if($rhq2_headkey->meta_key == 'mp_billing_info' )
629
- {
630
- $mp_ship_header= unserialize($rhq2_headkey->meta_value);
631
- foreach($mp_ship_header as $mp_ship_key => $mp_value) { $Header[] = "mbi: ".$mp_ship_key; }
632
- }
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
 
636
- if ($rhq2_headkey->meta_key != '_eshop_product' && $rhq2_headkey->meta_key != '_wp_attached_file')
637
- $Header[] = $rhq2_headkey->meta_key;
 
638
  }
639
- }
640
- $get_user_ids = "select DISTINCT ID from $wpdb->users u join $wpdb->usermeta um on um.user_id = u.ID";
641
 
642
- $result = $wpdb->get_col($get_user_ids);
643
- $fieldsCount = count($result);
644
- if ($result) {
645
- foreach ($result as $userID) {
646
- $uId = $uId . ',' . $userID;
647
- $query1 = "SELECT *FROM $wpdb->users where ID in ($userID);";
648
- $result_query1 = $wpdb->get_results($query1);
649
- if (!empty($result_query1)) {
650
- foreach ($result_query1 as $users) {
651
- foreach ($users as $user_key => $user_value) {
652
- $UserData[$userID][$user_key] = $user_value;
 
653
  }
654
  }
655
- }
656
- $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";
657
- $possible_values = array('s:', 'a:', ':{');
658
- $result_query2 = $wpdb->get_results($query2);
659
- if (!empty($result_query2)) {
660
- foreach ($result_query2 as $usermeta) {
661
- foreach($possible_values as $posval){
662
- if(strpos($usermeta->meta_value,$posval)){
663
- if($usermeta->meta_key == 'mp_shipping_info' || $usermeta->meta_key == 'mp_billing_info')
664
- $typesFserialized = 1;
665
- } else {
666
- $typesFserialized = 0;
 
 
 
667
  }
668
- }
669
- if($typesFserialized == 1)
670
- {
671
- if($usermeta->meta_key == 'mp_shipping_info')
672
  {
673
- $UserID = $usermeta->user_id;
674
- $mp_ship_data = unserialize($usermeta->meta_value);
675
- foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
676
  {
677
- $mp_ship_tempkey = "msi: ".$mp_ship_key;
678
- $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
 
 
 
 
 
679
  }
680
- }
681
 
682
- if($usermeta->meta_key == 'mp_billing_info')
683
- {
684
- $UserID = $usermeta->user_id;
685
- $mp_ship_data = unserialize($usermeta->meta_value);
686
- foreach($mp_ship_data as $mp_ship_key => $mp_ship_value)
687
  {
688
- $mp_ship_tempkey = "mbi: ".$mp_ship_key;
689
- $UserData[$UserID][$mp_ship_tempkey]= $mp_ship_value;
 
 
 
 
 
690
  }
691
- }
692
 
693
- if($usermeta->meta_key != 'wp_capabilities' && $usermeta->meta_key !='mp_shipping_info' && $usermeta->meta_key != 'mp_billing_info') {
694
- $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
695
- } else {
696
- if($usermeta->meta_key == 'wp_capabilities') {
697
- $getUserRole = unserialize($usermeta->meta_value);
698
- foreach($getUserRole as $urKey => $urVal) {
699
- $getUserRole = get_role($urKey);
700
- }
701
- $rolelevel = 0;
702
- $isfound = array();
703
- foreach($getUserRole->capabilities as $roleKey => $roleVal){
704
- $isfound = explode('level_', $roleKey);
705
- if(is_array($isfound) && count($isfound) == 2){
706
- $rolelevel = $rolelevel + 1;
707
  }
708
- } $rolelevel = $rolelevel - 1;
 
 
 
 
 
 
 
 
 
709
  }
710
- }
711
- } else {
712
- foreach($possible_values as $posval){
713
- if(strpos($usermeta->meta_value,$posval)){
714
- $UserData[$userID][$usermeta->meta_key] = null;
715
- } else {
716
- $ifSerialized = 0;
717
- $UserData[$userID][$usermeta->meta_key] = $usermeta->meta_value;
718
  }
719
- }
720
 
721
- }
 
722
  }
723
  }
724
  }
725
- }
726
-
727
- foreach ($Header as $header_key) {
728
- foreach ($UserData as $UD_key) {
729
- if (array_key_exists($header_key, $UD_key))
730
- $CSVContent[$header_key][] = $UD_key[$header_key];
731
- else
732
- $CSVContent[$header_key][] = '';
733
- }
734
- }
735
- for ($j = 0; $j < $fieldsCount; $j++) {
736
- foreach ($Header as $value) {
737
- if ( ! isset($CSVDATA[$j])) {
738
- $CSVDATA[$j] = null;
739
  }
740
- $CSVDATA[$j] .= '"' . $CSVContent[$value][$j] . '"' . $export_delimiter;
741
- }
742
- }
743
- foreach ($Header as $csv_header) {
744
- if($csv_header == 'wp_user_level')
745
- $csv_header = 'role';
746
- $CSV_FILE_CONTENT .= $csv_header . "$export_delimiter";
747
- }
748
- $CSV_FILE_CONTENT = substr($CSV_FILE_CONTENT, 0, -1);
749
- $CSV_FILE_CONTENT .= "\n";
750
- if ($CSVDATA) {
751
- foreach ($CSVDATA as $csv_content) {
752
- $csv_content = substr($csv_content, 0, -1);
753
- $CSV_FILE_CONTENT .= $csv_content . "\n";
754
  }
755
- }
756
- }
757
- elseif($exporttype == 'comments'){
758
-
759
- $commentQuery = "SELECT * FROM $wpdb->comments " . $orderBy;
760
- $comments = $wpdb->get_results( $commentQuery);
761
- $mappedHeader = false;
762
- foreach($comments as $comment){
763
- foreach($comment as $key => $value){
764
 
765
- if(!$mappedHeader){
766
- $header .= $key."$export_delimiter";
767
- }
768
- $singleCommentContent .= '"'.$value.'"'."$export_delimiter";
769
-
770
- }
771
- $mappedHeader = true;
772
- $singleCommentContent = substr($singleCommentContent,0,-1);
773
- $content .= $singleCommentContent."\n";
774
- $singleCommentContent = '';
775
  }
776
-
777
- $header = substr($header,0,-1);
778
- $header = $header."\n";
779
- $CSV_FILE_CONTENT = $header.$content;
780
-
781
- }
782
- header("Content-type: text/x-csv"); # DECLARING FILE TYPE
783
- header("Content-Transfer-Encoding: binary");
784
- header("Content-Disposition: attachment; filename=" . $csv_file_name); # EXPORT GENERATED CSV FILE
785
- header("Pragma: no-cache");
786
- header("Expires: 0");
787
- print($CSV_FILE_CONTENT);
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/export/templates/index.php CHANGED
@@ -1,93 +1,221 @@
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
 
39
- <div style="margin-top:30px;width:98%;">
40
  <div style="display:none;" id="ShowMsg"><p class="alert alert-warning" id="warning-msg"></p></div>
41
- <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();" >
42
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="post"> Post </label> </div> </div>
43
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="page"> Page </label> </div> </div>
44
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="custompost"> Custom Post </label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  <select name="export_post_type">
46
- <?php
47
- foreach (get_post_types() as $key => $value) {
48
- 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')) {?>
49
- <option id="<?php echo($value); ?>"> <?php echo($value);?> </option>
 
 
50
  <?php
51
- }
52
- }
53
- ?>
54
- </select> </div>
55
- </div>
56
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="users" id='users' > Users <span class="mandatory"></span></label> </div> </div>
57
- <div class='form-group'><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>
58
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label > <input type='radio' name='export' value='eshop' id='eshop' onclick="export_check(this.value)"> Eshop </label> </div> </div>
59
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="category" id='category' onclick="export_check(this.value)"> Category <span class="mandatory">*</span></label> </div> </div>
60
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="tags" id='tags' onclick="export_check(this.value)"> Tags <span class="mandatory">*</span></label> </div> </div>
61
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" value="customtaxonomy" id='customtaxonomy' onclick="export_check(this.value)" > Custom Taxonomy <span class="mandatory">*</span></label>
 
 
 
 
 
 
 
62
  <select name="export_taxo_type">
63
- <option>--Select--</option>
64
- </select> </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  </div>
66
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" id='wpcommerce'value="wpcommerce" onclick="export_check(this.value)" > Wp-Commerce <span class="mandatory">*</span></label> </div> </div>
67
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" id='woocommerce'value="woocommerce" onclick="export_check(this.value)"> Woo-Commerce <span class="mandatory">*</span></label> </div> </div>
68
- <div class = 'form-group'> <div class = 'col-sm-3 export_action'> <label> <input type="radio" name="export" id='marketpress' value="marketpress" onclick="export_check(this.value)"> Marketpress <span class="mandatory">*</span></label> </div> </div>
69
- <div class = 'form-group'>
70
- <label class = 'col-sm-1 control-label'> File Name: </label>
71
- <div class = 'col-sm-6'>
72
- <input class = 'form-control' type = 'text' name = 'export_filename' id = 'export_filename' value = '' placeholder = "export_as_<?php echo (date("Y-m-d"));?>" size="18">
73
  </div>
74
- <div class = 'col-sm-3'> <input type = "submit" name = "exportbutton" value = "Export" class = 'btn btn-primary'> </div>
75
- </form>
76
- </div>
77
- <div align=center style=''><label style="font-size:1.2em;">Note:- <span class="mandatory">*</span> Available in PRO version!</label></div>
78
- <!-- Promotion footer for other useful plugins -->
79
- <?php $impCE = new WPImporter_includes_helper(); ?>
80
- <div class= "promobox" id="pluginpromo" style="width:98%;">
81
- <div class="accordion-group" >
82
- <!-- <div class="accordion-heading">
83
- <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo"> OTHER USEFUL LINKS </a>
84
- </div> -->
85
- <div class="accordion-body in collapse">
86
- <div>
87
- <?php // $impCE->common_footer_for_other_plugin_promotions(); ?>
88
- <?php $impCE->common_footer(); ?>
89
- </div>
90
- </div>
91
- </div>
92
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
14
+ <div style="margin-top:30px;">
15
  <div style="display:none;" id="ShowMsg"><p class="alert alert-warning" id="warning-msg"></p></div>
16
+ <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();">
17
+ <!-- <form class="form-horizontal" method="post" name="exportmodule" action="" onsubmit="return export_module();"> -->
18
+ <div class="table-responsive">
19
+ <table style='width:100%;' class='table exportmodule'>
20
+ <th colspan='2'><label class='h-exportmodule'> To export data based on the filters </label></th>
21
+ <tr>
22
+ <td><input type='checkbox' name='getdataforspecificperiod' id='getdataforspecificperiod' value='getdataforspecificperiod' onclick='addwpexportfilter(this.id);' /> Export data for the specific period
23
+ <div id='specificperiodexport' style='padding:10px;display:none;'>
24
+ <label id='periodstartfrom'><b> Start From </b></label>
25
+ <input type='text' class='form-control' name='postdatefrom' style='cursor:default;width:25%;' readonly id='postdatefrom' value='' />
26
+ <label id='periodendto'><b> End To </b></label>
27
+ <input type='text' class='form-control' name='postdateto' style='cursor:default;width:25%;' readonly id='postdateto' value='' />
28
+ </div>
29
+ </td>
30
+ </tr>
31
+ <tr>
32
+ <td><input type='checkbox' name='getdatawithspecificstatus' id='getdatawithspecificstatus' value='getdatawithspecificstatus' onclick='addwpexportfilter(this.id);' /> Export data with the specific status
33
+ <div id='specificstatusexport' style='padding:10px;display:none;'>
34
+ <label id='status'><b> Status </b></label>
35
+ <select name='postwithstatus' id='postwithstatus'>
36
+ <option>All</option>
37
+ <option>Publish</option>
38
+ <option>Sticky</option>
39
+ <option>Private</option>
40
+ <option>Protected</option>
41
+ <option>Draft</option>
42
+ <option>Pending</option>
43
+ </select>
44
+ </div>
45
+ </td>
46
+ </tr>
47
+ <tr>
48
+ <td><input type='checkbox' name='getdatabyspecificauthors' id='getdatabyspecificauthors' value='getdatabyspecificauthors' onclick='addwpexportfilter(this.id);' /> Export data by specific authors
49
+ <div id='specificauthorexport' style='padding:10px;display:none;'>
50
+ <label id='authors'><b> Authors </b></label>
51
+ <?php $blogusers = get_users( 'blog_id=1&orderby=nicename' ); ?>
52
+ <select name='postauthor' id='postauthor' >
53
+ <option value='0'>All</option>
54
+ <?php foreach( $blogusers as $user ) { ?>
55
+ <option value='<?php echo esc_html( $user->ID ); ?>'> <?php echo esc_html( $user->display_name ); ?> </option>
56
+ <?php } ?>
57
+ </select>
58
+ </div>
59
+ </td>
60
+ </tr>
61
+ </table>
62
+ <script type = 'text/javascript'>
63
+ jQuery(document).ready(function() {
64
+ jQuery('#postdatefrom').datepicker({
65
+ dateFormat : 'yy-mm-dd'
66
+ });
67
+ jQuery('#postdateto').datepicker({
68
+ dateFormat : 'yy-mm-dd'
69
+ });
70
+ });
71
+ </script>
72
+ </div>
73
+ <div class="table-responsive">
74
+ <table class='table exportmodule'>
75
+ <th colspan='2'><label class='h-exportmodule'> Select your module to export the data </label></th>
76
+ <tr>
77
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="post" id="post"> Post </label></td>
78
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="eshop" id="eshop"> Eshop </label></td>
79
+ </tr>
80
+ <tr>
81
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="page" id="page"> Page </label></td>
82
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="wpcommerce" id="wpcommerce" onclick="export_check(this.value);"> Wp-Commerce <span class="mandatory">*</span></label></td>
83
+ </tr>
84
+ <tr>
85
+ <td class='exportdatatype'>
86
+ <label> <input type="radio" name="export" value="custompost" id="custompost" > Custom Post </label>
87
  <select name="export_post_type">
88
+ <option>--Select--</option>
89
+ <?php
90
+ foreach (get_post_types() as $key => $value) {
91
+ 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')) {
92
+ ?>
93
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
94
  <?php
95
+ }
96
+ }
97
+ ?>
98
+ </select>
99
+ </td>
100
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="woocommerce" id="woocommerce" onclick="export_check(this.value);"> Woo-Commerce <span class="mandatory">*</span></label></td>
101
+ </tr>
102
+ <tr>
103
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="category" id="category" onclick="export_check(this.value);"> Category <span class="mandatory">*</span></label></td>
104
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="marketpress" id="marketpress" onclick="export_check(this.value);"> Marketpress <span class="mandatory">*</span></label></td>
105
+ </tr>
106
+ <tr>
107
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="tags" id="tags" onclick="export_check(this.value);"> Tags <span class="mandatory">*</span></label></td>
108
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="customerreviews" id="customerreviews" onclick="export_check(this.value);"> Customer Reviews <span class="mandatory">*</span></label></td>
109
+ </tr>
110
+ <tr>
111
+ <td class='exportdatatype'>
112
+ <label> <input type="radio" name="export" value="customtaxonomy" id="customtaxonomy" onclick="export_check(this.value);"> Custom Taxonomy <span class="mandatory">*</span></label>
113
  <select name="export_taxo_type">
114
+ <option>--Select--</option>
115
+ <?php
116
+ foreach (get_taxonomies() as $key => $value) {
117
+ 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')) {
118
+ ?>
119
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
120
+ <?php
121
+ }
122
+ }
123
+ ?>
124
+ </select></td>
125
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="comments" id="comments"> Comments </label></td>
126
+ </tr>
127
+ <tr>
128
+ <td class='exportdatatype'><label> <input type="radio" name="export" value="users" id="users"> Users </label></td>
129
+ <td class='exportdatatype'></td>
130
+ </tr>
131
+ </table>
132
  </div>
133
+ <?php /*
134
+ <div class='form-group exportedas'>
135
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="post"> Post </label>
136
+ </div>
 
 
 
137
  </div>
138
+ <div class='form-group exportedas'>
139
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="page"> Page </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="custompost"> Custom Post </label>
144
+ <select name="export_post_type">
145
+ <option>--Select--</option>
146
+ <?php
147
+ foreach (get_post_types() as $key => $value) {
148
+ 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')) {
149
+ ?>
150
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
151
+ <?php
152
+ }
153
+ }
154
+ ?>
155
+ </select></div>
156
+ </div>
157
+ <div class='form-group exportedas'>
158
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="users"> Users </label>
159
+ </div>
160
+ </div>
161
+ <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>
162
+ <div class='form-group exportedas'>
163
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="category"> Category
164
+ </label></div>
165
+ </div>
166
+ <div class='form-group exportedas'>
167
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="tags"> Tags </label>
168
+ </div>
169
+ </div>
170
+ <div class='form-group exportedas'>
171
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="customtaxonomy"> Custom
172
+ Taxonomy </label>
173
+ <select name="export_taxo_type">
174
+ <option>--Select--</option>
175
+ <?php
176
+ foreach (get_taxonomies() as $key => $value) {
177
+ 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')) {
178
+ ?>
179
+ <option id="<?php echo($value); ?>"> <?php echo($value); ?> </option>
180
+ <?php
181
+ }
182
+ }
183
+ ?>
184
+ </select></div>
185
+ </div>
186
+ <div class='form-group exportedas'>
187
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="eshop"> Eshop </label>
188
+ </div>
189
+ </div>
190
+ <div class='form-group exportedas'>
191
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="wpcommerce">
192
+ Wp-Commerce </label></div>
193
+ </div>
194
+ <div class='form-group exportedas'>
195
+ <div class='col-sm-3 export_action'><label> <input type="radio" name="export" value="woocommerce">
196
+ Woo-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="marketpress">
200
+ Marketpress </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="customerreviews">
204
+ Customer Reviews </label></div>
205
+ </div>
206
+ */ ?>
207
+ <div class='form-group exportedas'>
208
+ <label class='col-sm-2 control-label'><b> File Name: </b></label>
209
 
210
+ <div class='col-sm-6'>
211
+ <input class='form-control' type='text' name='export_filename' id='export_filename' value=''
212
+ placeholder="export_as_<?php echo(date("Y-m-d")); ?>" size="18">
213
+ </div>
214
+ <div class='col-sm-3'><input type="submit" name="exportbutton" value="Export" class='btn btn-primary'></div>
215
+
216
+ </form>
217
+ </div>
218
+ </div>
219
+ </div>
220
+ </div>
221
+ </div>
modules/users/actions/actions.php CHANGED
@@ -101,7 +101,7 @@ class UsersActions extends SkinnyActions {
101
  *
102
  * @return boolean
103
  */
104
- function processDataInWP($data_rows,$ret_array,$session_arr)
105
  {
106
  $impCE = new WPImporter_includes_helper();
107
  $smack_taxo = array();
@@ -165,6 +165,8 @@ class UsersActions extends SkinnyActions {
165
  if(! array_key_exists($data_array['role'],$roles)){
166
  $data_array['role'] = 'subscriber';
167
  }
 
 
168
  $user_table = $wpdb->users;
169
  $user_id = '';
170
  $user_role= '';
@@ -174,17 +176,21 @@ class UsersActions extends SkinnyActions {
174
  }
175
  if($user_id){
176
  $this->dupPostCount = $this->dupPostCount+1;
 
177
  }
178
  else{
179
  $user_id = wp_insert_user( $data_array );
180
- if($user_id){
181
- $this->insPostCount++; // = $this->insPostCount+1;
182
- }
183
  $user = new WP_User( $user_id );
184
  if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
185
  foreach ( $user->roles as $role )
186
  $user_role = $role;
187
  }
 
 
 
 
 
 
188
  $getUsers1 = $wpdb->get_results("select count(ID) as users from $user_table");
189
  $no_of_users = ($getUsers1[0]->users) - ($getUsers[0]->users);
190
  $termcount = $userscount+$no_of_users;
101
  *
102
  * @return boolean
103
  */
104
+ function processDataInWP($data_rows,$ret_array,$session_arr,$currentLimit)
105
  {
106
  $impCE = new WPImporter_includes_helper();
107
  $smack_taxo = array();
165
  if(! array_key_exists($data_array['role'],$roles)){
166
  $data_array['role'] = 'subscriber';
167
  }
168
+ $UserLogin = $data_array['user_login'];
169
+ $UserEmail = $data_array['user_email'];
170
  $user_table = $wpdb->users;
171
  $user_id = '';
172
  $user_role= '';
176
  }
177
  if($user_id){
178
  $this->dupPostCount = $this->dupPostCount+1;
179
+ $this->detailedLog[$currentLimit][] = "<b>Username</b> - " . $UserLogin . " - already exists(skipped), <b>E-mail</b> - " . $UserEmail . " - found as duplicate.";
180
  }
181
  else{
182
  $user_id = wp_insert_user( $data_array );
 
 
 
183
  $user = new WP_User( $user_id );
184
  if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
185
  foreach ( $user->roles as $role )
186
  $user_role = $role;
187
  }
188
+ if($user_id){
189
+ $this->insPostCount++; // = $this->insPostCount+1;
190
+ }
191
+
192
+ $this->detailedLog[$currentLimit][] = "<b>Created User_ID: </b>" . $user_id ." - Success, <b>Username</b> - " . $UserLogin . " , <b>E-mail</b> - " . $UserEmail . " , <b>Role</b> - " . $user_role . " , <b>Verify Here</b> - <a href='" . get_edit_user_link( $user_id, true ) . "'>" . __( 'User Profile' ) . "</a>";
193
+
194
  $getUsers1 = $wpdb->get_results("select count(ID) as users from $user_table");
195
  $no_of_users = ($getUsers1[0]->users) - ($getUsers[0]->users);
196
  $termcount = $userscount+$no_of_users;
screenshot-5.png CHANGED
Binary file
screenshot-8.png CHANGED
Binary file
templates/import.php CHANGED
@@ -96,6 +96,7 @@ if ($count < $totRecords) {
96
  $count = $totRecords;
97
  }
98
  $resultArr = array();
 
99
  $filename = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['uploadedFile'];
100
  $delim = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['select_delimeter'];
101
  $resultArr = $skinnyObj->csv_file_data($filename);
@@ -106,14 +107,53 @@ if ($_POST['postdata']['dupContent']) {
106
  $importObj->conDupCheck = $_POST['postdata']['dupContent'];
107
  }
108
  $csv_rec_count = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['h2'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  for ($i = $limit; $i < $count; $i++) {
 
 
 
 
 
 
110
  $colCount = count($resultArr[$i]);
111
  $_SESSION['SMACK_SKIPPED_RECORDS'] = $i;
112
  foreach($resultArr[$i] as $resultKey => $resultVal) {
113
  $to_be_import_rec[] = $resultVal;
114
  }
 
115
 
116
- $importObj->processDataInWP($to_be_import_rec,$_SESSION['SMACK_MAPPING_SETTINGS_VALUES'], $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  $limit++;
118
  unset($to_be_import_rec);
119
  }
@@ -163,8 +203,10 @@ if ($totRecords <= ($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['insPostCount'] +
163
  unset($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['updatedPostCount']);
164
  unset($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['captureId']);
165
  }
166
-
167
- if ($curr_action == 'users') {
 
 
168
  echo "<div style='margin-left:7px;'>";
169
  if (($limit == $requested_limit) && ($limit <= $count)) {
170
  echo "<div style='margin-left:3px;'>Chosen server request is " . $count . " .</div><br>";
@@ -257,7 +299,7 @@ if ($curr_action == 'users') {
257
  echo "<br><div style='margin-left:3px;'>Import successfully completed!.</div>";
258
  }
259
  echo "</div>";
260
- }
261
  foreach ($_SESSION['SMACK_MAPPING_SETTINGS_VALUES'] as $key => $value) {
262
  for ($j = 0; $j < $csv_rec_count; $j++) {
263
  if ($key == 'mapping' . $j) {
96
  $count = $totRecords;
97
  }
98
  $resultArr = array();
99
+
100
  $filename = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['uploadedFile'];
101
  $delim = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['select_delimeter'];
102
  $resultArr = $skinnyObj->csv_file_data($filename);
107
  $importObj->conDupCheck = $_POST['postdata']['dupContent'];
108
  }
109
  $csv_rec_count = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['h2'];
110
+
111
+ //mapped and unmapped count
112
+ for($i=0;$i<$csv_rec_count;$i++) {
113
+ $mapping_value = $_SESSION[$_POST['postdata']['uploadedFile']]['SMACK_MAPPING_SETTINGS_VALUES']['mapping'.$i];
114
+ if($mapping_value == '-- Select --' ) {
115
+ $res1[] = $mapping_value;
116
+ }
117
+ else {
118
+ $res2[] = $mapping_value;
119
+ }
120
+ }
121
+ $mapped = count($res2);
122
+ $unmapped = count($res1);
123
+
124
  for ($i = $limit; $i < $count; $i++) {
125
+ if ($limit == 0) {
126
+ echo "<div style='margin-left:10px;'> Total no of records - " . $totRecords . ".</div><br>";
127
+ echo "<div style='margin-left:10px;'> Total no of mapped fields for single record - " . $mapped . ".</div><br>";
128
+ echo "<div style='margin-left:10px;'> Total no of unmapped fields for a record - " . $unmapped . ".</div><br>";
129
+ echo "<div style='margin-left:10px;'> Chosen server request is " . $count . " .</div><br>";
130
+ }
131
  $colCount = count($resultArr[$i]);
132
  $_SESSION['SMACK_SKIPPED_RECORDS'] = $i;
133
  foreach($resultArr[$i] as $resultKey => $resultVal) {
134
  $to_be_import_rec[] = $resultVal;
135
  }
136
+ $importObj->detailedLog = array();
137
 
138
+ $importObj->processDataInWP($to_be_import_rec,$_SESSION['SMACK_MAPPING_SETTINGS_VALUES'], $_SESSION['SMACK_MAPPING_SETTINGS_VALUES'], $i);
139
+ if ($curr_action == 'post' || $curr_action == 'page' || $curr_action == 'custompost' || $curr_action == 'eshop') {
140
+ foreach($importObj->detailedLog as $logKey => $logVal) {
141
+ echo "<p style='margin-left:10px;'> " . $logVal['post_id'] . " , " . $logVal['assigned_author'] . " , " . $logVal['category'] . " , " . $logVal['tags'] . " , " . $logVal['postdate'] . " , " . $logVal['image'] . " , " . $logVal['poststatus'];
142
+ if($curr_action == 'eshop') {
143
+ echo " , " . $logVal['SKU'] . ", " . $logVal['verify_here'] . "</p>";
144
+ } else {
145
+ echo " , " . $logVal['verify_here'] . "</p>";
146
+ }
147
+ }
148
+ }
149
+ else if ($curr_action == 'comments' || $curr_action == 'users') {
150
+ foreach($importObj->detailedLog as $logVal) {
151
+ for ($l = 0; $l < count($logVal); $l++) {
152
+ echo "<p style='margin-left:10px;'> " . $logVal[$l] . "</p>";
153
+ }
154
+ }
155
+ }
156
+
157
  $limit++;
158
  unset($to_be_import_rec);
159
  }
203
  unset($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['updatedPostCount']);
204
  unset($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['captureId']);
205
  }
206
+ if ($limit == $totRecords) {
207
+ echo "<br><div style='margin-left:3px;'>Import successfully completed!.</div>";
208
+ }
209
+ /*if ($curr_action == 'users') {
210
  echo "<div style='margin-left:7px;'>";
211
  if (($limit == $requested_limit) && ($limit <= $count)) {
212
  echo "<div style='margin-left:3px;'>Chosen server request is " . $count . " .</div><br>";
299
  echo "<br><div style='margin-left:3px;'>Import successfully completed!.</div>";
300
  }
301
  echo "</div>";
302
+ } */
303
  foreach ($_SESSION['SMACK_MAPPING_SETTINGS_VALUES'] as $key => $value) {
304
  for ($j = 0; $j < $csv_rec_count; $j++) {
305
  if ($key == 'mapping' . $j) {