PluginProbe
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export / 2.0
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export v2.0
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.0, at exportExtensions/CustomerReviewsExport.php

190 lines 7.4 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 * Check for specific period
69 */
70
71 // if($conditions['specific_period']['from'] == $conditions['specific_period']['to']){
72 // $get_customer_reviews .= " and c.comment_date >= '" . $conditions['specific_period']['from'] . "'";
73 // }
74 // else{
75 // $get_customer_reviews .= " and c.comment_date >= '" . $conditions['specific_period']['from'] . "' and c.comment_date <= '" . $conditions['specific_period']['to'] . "'";
76 // }
77
78 /**
79 * Check for specific authors
80 */
81
82 if($conditions['specific_authors']['is_check'] == 'true') {
83 if(isset($conditions['specific_authors']['author']) && $conditions['specific_authors']['author'] != 0) {
84 $get_customer_reviews .= " and c.comment_author_email = {$conditions['specific_authors']['author']}";
85 }
86 }
87 $get_total_row_count = $wpdb->get_col($get_customer_reviews);
88 CustomerReviewExport::$export_instance->totalRowCount = count($get_total_row_count);
89 $offset_limit = " order by ID asc limit $offset, $limit";
90 $query_with_offset_limit = $get_customer_reviews . $offset_limit;
91 $result = $wpdb->get_col($query_with_offset_limit);
92
93 if(!empty($result)) {
94 foreach($result as $reviewId) {
95
96 /**
97 * Review Core Information
98 */
99
100 $query_for_reviews = $wpdb->prepare("SELECT wp.* FROM {$wpdb->prefix}posts wp where ID=%d", $reviewId);
101 $reviewDetails = $wpdb->get_results($query_for_reviews);
102 if (!empty($reviewDetails)) {
103 foreach ($reviewDetails as $posts) {
104 foreach ($posts as $post_key => $post_value) {
105 $post_key = CustomerReviewExport::$export_instance->change_fieldname_depends_on_post_type('wpcr3_review', $post_key);
106 if ($post_key == 'post_status') {
107 if (is_sticky($reviewId)) {
108 // $headers[] = $post_key;
109 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = 'Sticky';
110 $post_status = 'Sticky';
111 } else {
112 // $headers[] = $post_key;
113 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value;
114 $post_status = $post_value;
115 }
116 } else {
117 // $headers[] = $post_key;
118 CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value;
119 }
120 if ($post_key == 'post_password') {
121 if ($post_value) {
122 // $headers[] = $post_key;
123 CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = "{" . $post_value . "}";
124 } else {
125 // $headers[] = $post_key;
126 CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = $post_status;
127 }
128 }
129 if ($post_key == 'comment_status') {
130 if ($post_value == 'closed') {
131 // $headers[] = $post_key;
132 CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 0;
133 }
134 if ($post_value == 'open') {
135 // $headers[] = $post_key;
136 CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 1;
137 }
138 }
139 }
140 }
141 }
142
143 /**
144 * Review Meta Information
145 */
146
147 $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);
148 $reviewMetaDetails = $wpdb->get_results($query_for_review_meta);
149
150 if(!empty($reviewMetaDetails)) :
151 foreach($reviewMetaDetails as $key => $value) :
152 if ($value->meta_key == '_thumbnail_id') {
153 $attachment_file = null;
154 $get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $value->meta_value, 'attachment');
155 $attachment = $wpdb->get_results($get_attachment);
156 $attachment_file = $attachment[0]->guid;
157 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = '';
158 $value->meta_key = 'featured_image';
159 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $attachment_file;
160 } else {
161 CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $value->meta_value;
162 // $headers[] = $value->meta_key;
163 }
164 endforeach;
165 endif;
166
167 /**
168 * Prepare the headers
169 */
170
171 if(!empty($headers)) {
172 foreach($headers as $hKey) {
173 if(!in_array($hKey, CustomerReviewExport::$export_instance->headers)) {
174 CustomerReviewExport::$export_instance->headers[] = $hKey;
175
176 }
177 }
178 }
179 }
180 }
181 $result = CustomerReviewExport::$export_instance->finalDataToExport(CustomerReviewExport::$export_instance->data);
182 if($mode == null)
183 CustomerReviewExport::$export_instance->proceedExport($result);
184 else
185 return $result;
186 }
187 }
188 global $customer_rev_class;
189 $customer_rev_class = new CustomerReviewExport();
190