| 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 |
$offset = (int) $offset; |
| 39 |
$limit = (int) $limit; |
| 40 |
$headers = array(); |
| 41 |
CustomerReviewExport::$export_instance->generateHeaders($module, $optionalType); |
| 42 |
$get_customer_reviews = "select DISTINCT ID from {$wpdb->prefix}posts"; |
| 43 |
$get_customer_reviews .= $wpdb->prepare(" where post_type = %s", $optionalType); |
| 44 |
|
| 45 |
/** |
| 46 |
* Check for specific status |
| 47 |
*/ |
| 48 |
|
| 49 |
if($conditions['specific_status']['status'] == 'true') { |
| 50 |
if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'All') { |
| 51 |
$get_customer_reviews .= " and post_status in ('publish','draft','future','private','pending')"; |
| 52 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Publish' || $conditions['specific_status']['status'] == 'Sticky') { |
| 53 |
$get_customer_reviews .= " and post_status in ('publish')"; |
| 54 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Draft') { |
| 55 |
$get_customer_reviews .= " and post_status in ('draft')"; |
| 56 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Scheduled') { |
| 57 |
$get_customer_reviews .= " and post_status in ('future')"; |
| 58 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Private') { |
| 59 |
$get_customer_reviews .= " and post_status in ('private')"; |
| 60 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Pending') { |
| 61 |
$get_customer_reviews .= " and post_status in ('pending')"; |
| 62 |
} else if(isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Protected') { |
| 63 |
$get_customer_reviews .= " and post_status in ('publish') and post_password != ''"; |
| 64 |
} |
| 65 |
} else { |
| 66 |
$get_customer_reviews .= " and post_status in ('publish','draft','future','private','pending')"; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* Check for specific authors |
| 72 |
*/ |
| 73 |
|
| 74 |
if($conditions['specific_authors']['is_check'] == 'true') { |
| 75 |
if(isset($conditions['specific_authors']['author']) && $conditions['specific_authors']['author'] != 0) { |
| 76 |
$get_customer_reviews .= $wpdb->prepare(" and c.comment_author_email = %s", $conditions['specific_authors']['author']); |
| 77 |
} |
| 78 |
} |
| 79 |
$get_total_row_count = $wpdb->get_col($get_customer_reviews); |
| 80 |
CustomerReviewExport::$export_instance->totalRowCount = count($get_total_row_count); |
| 81 |
$offset_limit = " order by ID asc limit {$offset}, {$limit}"; |
| 82 |
$query_with_offset_limit = $get_customer_reviews . $offset_limit; |
| 83 |
$result = $wpdb->get_col($query_with_offset_limit); |
| 84 |
|
| 85 |
if(!empty($result)) { |
| 86 |
foreach($result as $reviewId) { |
| 87 |
|
| 88 |
/** |
| 89 |
* Review Core Information |
| 90 |
*/ |
| 91 |
|
| 92 |
$query_for_reviews = $wpdb->prepare("SELECT wp.* FROM {$wpdb->prefix}posts wp where ID=%d", $reviewId); |
| 93 |
$reviewDetails = $wpdb->get_results($query_for_reviews); |
| 94 |
if (!empty($reviewDetails)) { |
| 95 |
foreach ($reviewDetails as $posts) { |
| 96 |
foreach ($posts as $post_key => $post_value) { |
| 97 |
$post_key = CustomerReviewExport::$export_instance->change_fieldname_depends_on_post_type('wpcr3_review', $post_key); |
| 98 |
if ($post_key == 'post_status') { |
| 99 |
if (is_sticky($reviewId)) { |
| 100 |
CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = 'Sticky'; |
| 101 |
$post_status = 'Sticky'; |
| 102 |
} else { |
| 103 |
CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value; |
| 104 |
$post_status = $post_value; |
| 105 |
} |
| 106 |
} else { |
| 107 |
CustomerReviewExport::$export_instance->data[$reviewId][$post_key] = $post_value; |
| 108 |
} |
| 109 |
if ($post_key == 'post_password') { |
| 110 |
if ($post_value) { |
| 111 |
CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = "{" . $post_value . "}"; |
| 112 |
} else { |
| 113 |
CustomerReviewExport::$export_instance->data[$reviewId]['post_status'] = $post_status; |
| 114 |
} |
| 115 |
} |
| 116 |
if ($post_key == 'comment_status') { |
| 117 |
if ($post_value == 'closed') { |
| 118 |
CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 0; |
| 119 |
} |
| 120 |
if ($post_value == 'open') { |
| 121 |
CustomerReviewExport::$export_instance->data[$reviewId]['comment_status'] = 1; |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Review Meta Information |
| 130 |
*/ |
| 131 |
|
| 132 |
$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); |
| 133 |
$reviewMetaDetails = $wpdb->get_results($query_for_review_meta); |
| 134 |
|
| 135 |
if(!empty($reviewMetaDetails)) : |
| 136 |
foreach($reviewMetaDetails as $key => $value) : |
| 137 |
if ($value->meta_key == '_thumbnail_id') { |
| 138 |
$attachment_file = null; |
| 139 |
$get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $value->meta_value, 'attachment'); |
| 140 |
$attachment = $wpdb->get_results($get_attachment); |
| 141 |
$attachment_file = $attachment[0]->guid; |
| 142 |
CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = ''; |
| 143 |
$value->meta_key = 'featured_image'; |
| 144 |
CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $attachment_file; |
| 145 |
} else { |
| 146 |
CustomerReviewExport::$export_instance->data[$reviewId][$value->meta_key] = $value->meta_value; |
| 147 |
} |
| 148 |
endforeach; |
| 149 |
endif; |
| 150 |
|
| 151 |
/** |
| 152 |
* Prepare the headers |
| 153 |
*/ |
| 154 |
|
| 155 |
if(!empty($headers)) { |
| 156 |
foreach($headers as $hKey) { |
| 157 |
if(!in_array($hKey, CustomerReviewExport::$export_instance->headers)) { |
| 158 |
CustomerReviewExport::$export_instance->headers[] = $hKey; |
| 159 |
|
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
$result = CustomerReviewExport::$export_instance->finalDataToExport(CustomerReviewExport::$export_instance->data); |
| 166 |
if($mode == null) |
| 167 |
CustomerReviewExport::$export_instance->proceedExport($result); |
| 168 |
else |
| 169 |
return $result; |
| 170 |
} |
| 171 |
} |
| 172 |
global $customer_rev_class; |
| 173 |
$customer_rev_class = new CustomerReviewExport(); |
| 174 |
|