PluginProbe
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export / 2.13
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export v2.13
3.0 2.24.2 2.24.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 2.0 2.0.1 2.1 2.1.1 2.1.2 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.16.1 2.16.2 All 96 releases
wp-ultimate-exporter / exportExtensions / CustomerReviewsExport.php

CustomerReviewsExport.php in Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export 2.13, at exportExtensions/CustomerReviewsExport.php

172 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP Ultimate Exporter plugin file.
4 *
5 * Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
6 */
7 namespace Smackcoders\SMEXP;
8
9 if ( ! defined( 'ABSPATH' ) )
10 exit; // Exit if accessed directly
11
12 /**
13 * Class CustomerReviewExport
14 * @package Smackcoders\WCSV
15 */
16
17 class CustomerReviewExport extends ExportExtension{
18
19 protected static $instance = null,$mapping_instance,$export_handler,$export_instance;
20 public $totalRowCount;
21 public static function getInstance() {
22 if ( null == self::$instance ) {
23 self::$instance = new self;
24 CustomerReviewExport::$export_instance = ExportExtension::getInstance();
25 }
26 return self::$instance;
27 }
28
29 /**
30 * CustomerReviewExport constructor.
31 */
32 public function __construct() {
33 $this->plugin = Plugin::getInstance();
34 }
35
36 public function FetchCustomerReviews($module, $optionalType, $conditions, $offset, $limit, $mode = null) {
37 global $wpdb;
38 $headers = array();
39 CustomerReviewExport::$export_instance->generateHeaders($module, $optionalType);
40 $get_customer_reviews = "select DISTINCT ID from {$wpdb->prefix}posts";
41 $get_customer_reviews .= " where post_type = '$optionalType'";
42
43 /**
44 * Check for specific status
45 */
46
47 if($conditions['specific_status']['status'] == 'true') {
48 if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'All') {
49 $get_customer_reviews .= " and post_status in ('publish','draft','future','private','pending')";
50 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Publish' || $conditions['specific_status']['status'] == 'Sticky') {
51 $get_customer_reviews .= " and post_status in ('publish')";
52 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Draft') {
53 $get_customer_reviews .= " and post_status in ('draft')";
54 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Scheduled') {
55 $get_customer_reviews .= " and post_status in ('future')";
56 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Private') {
57 $get_customer_reviews .= " and post_status in ('private')";
58 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Pending') {
59 $get_customer_reviews .= " and post_status in ('pending')";
60 } else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Protected') {
61 $get_customer_reviews .= " and post_status in ('publish') and post_password != ''";
62 }
63 } else {
64 $get_customer_reviews .= " and post_status in ('publish','draft','future','private','pending')";
65 }
66
67
68 /**
69 * Check for specific authors
70 */
71
72 if($conditions['specific_authors']['is_check'] == 'true') {
73 if(isset($conditions['specific_authors']['author']) && $conditions['specific_authors']['author'] != 0) {
74 $get_customer_reviews .= " and c.comment_author_email = {$conditions['specific_authors']['author']}";
75 }
76 }
77 $get_total_row_count = $wpdb->get_col($get_customer_reviews);
78 CustomerReviewExport::$export_instance->totalRowCount = count($get_total_row_count);
79 $offset_limit = " order by ID asc limit $offset, $limit";
80 $query_with_offset_limit = $get_customer_reviews . $offset_limit;
81 $result = $wpdb->get_col($query_with_offset_limit);
82
83 if(!empty($result)) {
84 foreach($result as $reviewId) {
85
86 /**
87 * Review Core Information
88 */
89
90 $query_for_reviews = $wpdb->prepare("SELECT wp.* FROM {$wpdb->prefix}posts wp where ID=%d", $reviewId);
91 $reviewDetails = $wpdb->get_results($query_for_reviews);
92 if (!empty($reviewDetails)) {
93 foreach ($reviewDetails as $posts) {
94 foreach ($posts as $post_key => $post_value) {
95 $post_key = CustomerReviewExport::$export_instance->change_fieldname_depends_on_post_type('wpcr3_review', $post_key);
96 if ($post_key == 'post_status') {
97 if (is_sticky($reviewId)) {
98 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = 'Sticky';
99 $post_status = 'Sticky';
100 } else {
101 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value;
102 $post_status = $post_value;
103 }
104 } else {
105 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value;
106 }
107 if ($post_key == 'post_password') {
108 if ($post_value) {
109 CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = "{" . $post_value . "}";
110 } else {
111 CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = $post_status;
112 }
113 }
114 if ($post_key == 'comment_status') {
115 if ($post_value == 'closed') {
116 CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 0;
117 }
118 if ($post_value == 'open') {
119 CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 1;
120 }
121 }
122 }
123 }
124 }
125
126 /**
127 * Review Meta Information
128 */
129
130 $query_for_review_meta = $wpdb->prepare("SELECT post_id,meta_key,meta_value FROM {$wpdb->prefix}posts wp JOIN {$wpdb->prefix}postmeta wpm ON wpm.post_id = wp.ID where meta_key NOT IN (%s,%s) AND ID=%d", '_edit_lock', '_edit_last', $reviewId);
131 $reviewMetaDetails = $wpdb->get_results($query_for_review_meta);
132
133 if(!empty($reviewMetaDetails)) :
134 foreach($reviewMetaDetails as $key => $value) :
135 if ($value->meta_key == '_thumbnail_id') {
136 $attachment_file = null;
137 $get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $value->meta_value, 'attachment');
138 $attachment = $wpdb->get_results($get_attachment);
139 $attachment_file = $attachment[0]->guid;
140 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = '';
141 $value->meta_key = 'featured_image';
142 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $attachment_file;
143 } else {
144 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $value->meta_value;
145 }
146 endforeach;
147 endif;
148
149 /**
150 * Prepare the headers
151 */
152
153 if(!empty($headers)) {
154 foreach($headers as $hKey) {
155 if(!in_array($hKey, CustomerReviewExport::$export_instance->headers)) {
156 CustomerReviewExport::$export_instance->headers[] = $hKey;
157
158 }
159 }
160 }
161 }
162 }
163 $result = CustomerReviewExport::$export_instance->finalDataToExport(CustomerReviewExport::$export_instance->data);
164 if($mode == null)
165 CustomerReviewExport::$export_instance->proceedExport($result);
166 else
167 return $result;
168 }
169 }
170 global $customer_rev_class;
171 $customer_rev_class = new CustomerReviewExport();
172