PluginProbe
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export / trunk
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export vtrunk
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 / PostExport.php

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

2,168 lines 96.7 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
8 namespace Smackcoders\SMEXP;
9
10 if (!defined('ABSPATH'))
11 exit; // Exit if accessed directly
12
13 /**
14 * Class PostExport
15 * @package Smackcoders\WCSV
16 */
17 require_once dirname(__FILE__) . '/ExportExtension.php';
18 use Smackcoders\SMEXP\ExportExtension;
19
20 class PostExport extends ExportExtension
21 {
22 protected static $instance = null, $mapping_instance, $export_handler, $export_instance, $jet_custom_table_export;
23 public $offset = 0;
24 public $limit;
25 public $totalRowCount;
26 public static function getInstance()
27 {
28 if (null == self::$instance) {
29 self::$instance = new self;
30 self::$export_instance = ExportExtension::getInstance();
31 PostExport::$jet_custom_table_export = JetCustomTableExport::getInstance();
32 }
33 return self::$instance;
34 }
35
36 /**
37 * PostExport constructor.
38 */
39 public function __construct()
40 {
41 $this->plugin = Plugin::getInstance();
42 }
43
44 public function get_total_rowCount()
45 {
46 $product_counts = wp_count_posts('product');
47 $statuses = ['publish', 'draft', 'future', 'private', 'pending'];
48
49 $total_count = 0;
50 foreach ($statuses as $status) {
51 if (isset($product_counts->$status)) {
52 $total_count += $product_counts->$status;
53 }
54 }
55
56 return $total_count;
57 }
58
59 /**
60 * Get records based on the post types
61 * @param $module
62 * @param $optionalType
63 * @param $conditions
64 * @return array
65 */
66 public function getRecordsBasedOnPostTypes($module, $optionalType, $conditions, $offset, $limit, $headers = '')
67 {
68 global $wpdb, $sitepress;
69 $offset = (int) $offset;
70 $limit = (int) $limit;
71 if ($module == 'JetBooking') {
72 if (!empty($conditions['specific_jetbooking_status']['is_check']) && $conditions['specific_jetbooking_status']['is_check'] == 'true' && !empty($conditions['specific_jetbooking_status']['status'])) {
73 $jet_booking_status = $conditions['specific_jetbooking_status']['status'];
74 $bookings = jet_abaf_get_bookings(['status' => $jet_booking_status, 'return' => 'arrays']);
75 $post_ids = wp_list_pluck($bookings, 'ID');
76 self::$export_instance->totalRowCount = count($post_ids);
77 return $post_ids;
78 } else {
79 $bookings = jet_abaf_get_bookings(['return' => 'arrays']);
80 $post_ids = wp_list_pluck($bookings, 'ID');
81 self::$export_instance->totalRowCount = count($post_ids);
82 return $post_ids;
83 }
84 }
85 if ($module == 'WooCommerceCustomer') {
86 // Get all customer user IDs
87 $post_ids = get_users([
88 'role' => 'customer',
89 'fields' => 'ID'
90 ]);
91
92 // Return the array of customer user IDs
93 return $post_ids;
94 }
95
96 if ($module == 'EDD_CUSTOMERS') {
97 $post_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}edd_customers ORDER BY id ASC LIMIT %d, %d", $offset, $limit));
98 self::$export_instance->totalRowCount = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}edd_customers");
99 return $post_ids;
100 }
101
102 if ($module == 'EDD_DISCOUNTS') {
103 if ($this->is_edd_3_0_plus()) {
104 $post_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}edd_adjustments WHERE type = 'discount' ORDER BY id ASC LIMIT %d, %d", $offset, $limit));
105 self::$export_instance->totalRowCount = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}edd_adjustments WHERE type = 'discount'");
106 } else {
107 $post_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}edd_discounts ORDER BY id ASC LIMIT %d, %d", $offset, $limit));
108 self::$export_instance->totalRowCount = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}edd_discounts");
109 }
110 return $post_ids;
111 }
112
113
114
115 if ($module == 'CustomPosts' && $optionalType == 'nav_menu_item') {
116 $get_menu_id = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}terms AS t LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'nav_menu' ", ARRAY_A);
117 $get_menu_arr = array_column($get_menu_id, 'term_id');
118 self::$export_instance->totalRowCount = count($get_menu_arr);
119 return $get_menu_arr;
120 }
121 if ($module == 'CustomPosts' && $optionalType == 'widgets') {
122 $get_widget_id = $wpdb->get_row("SELECT option_id FROM {$wpdb->prefix}options where option_name = 'widget_recent-posts' ", ARRAY_A);
123 self::$export_instance->totalRowCount = 1;
124 return $get_widget_id;
125 }
126 if ($module == 'WooCommerceOrders') {
127 $module = 'shop_order';
128 } elseif ($module == 'WooCommerceCoupons') {
129 $module = 'shop_coupon';
130 } elseif ($module == 'WooCommerceRefunds') {
131 $module = 'shop_order_refund';
132 } elseif ($module == 'WooCommerceVariations') {
133 if (is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')) {
134 $module = 'product_variation';
135 $extracted_ids = "select DISTINCT ID from {$wpdb->prefix}posts";
136 $extracted_ids .= $wpdb->prepare(" where post_type = %s", $module);
137 $extracted_ids .= " and post_status in ('publish','draft','future','private','pending') AND post_parent!=0";
138 $extracted_id = $wpdb->get_col($extracted_ids);
139 $extracted_ids = array();
140 foreach ($extracted_id as $ids) {
141
142 $parent_id = $wpdb->get_var($wpdb->prepare("SELECT post_parent FROM {$wpdb->prefix}posts where ID=%d", absint($ids)));
143
144 $post_status = $wpdb->get_var($wpdb->prepare("SELECT post_status FROM {$wpdb->prefix}posts where ID=%d", absint($parent_id)));
145 if (!empty($post_status)) {
146 if ($post_status != 'trash' && $post_status != 'inherit') {
147 $extracted_ids[] = $ids;
148 }
149
150 }
151 }
152 self::$export_instance->totalRowCount = count($extracted_ids);
153 return array_reverse($extracted_ids);
154 } else {
155 $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
156 $products = wc_get_products(array('status' => $product_statuses, 'limit' => -1));
157 $variable_product_ids = [];
158 foreach ($products as $product) {
159 if ($product->is_type('variable')) {
160 $variable_product_ids[] = $product->get_id();
161 }
162 }
163 $variation_ids = [];
164 foreach ($variable_product_ids as $variable_product_id) {
165 $variable_product = wc_get_product($variable_product_id);
166 $variation_ids[] = $variable_product->get_children();
167 }
168 $extracted_ids = [];
169 foreach ($variation_ids as $v_ids) {
170 foreach ($v_ids as $v_id) {
171 $extracted_ids[] = $v_id;
172 }
173 }
174 self::$export_instance->totalRowCount = count($extracted_ids);
175 return array_reverse($extracted_ids);
176 }
177 }elseif ($module == 'SURECART_PRODUCTS') {
178 $module = 'sc_product';
179 } elseif ($module == 'SURECART_CUSTOMERS') {
180 if (class_exists('\\SureCart\\Models\\Customer')) {
181 try {
182 $collection = \SureCart\Models\Customer::paginate(['per_page' => 1]);
183 $total_count = $collection->total();
184 if (isset(self::$export_instance)) {
185 self::$export_instance->totalRowCount = $total_count;
186 }
187
188 $customers = \SureCart\Models\Customer::where(['limit' => $limit, 'offset' => $offset])->get();
189 $result = [];
190 if (!empty($customers)) {
191 foreach ($customers as $customer) {
192 $result[] = $customer->id;
193 }
194 }
195 return $result;
196 } catch (\Throwable $e) {
197 return [];
198 }
199 }
200 return [];
201 } elseif ($module == 'SURECART_COUPONS') {
202 if (class_exists('\\SureCart\\Models\\Coupon')) {
203 try {
204 $collection = \SureCart\Models\Coupon::paginate(['per_page' => 1]);
205 $total_count = $collection->total();
206 if (isset(self::$export_instance)) {
207 self::$export_instance->totalRowCount = $total_count;
208 }
209
210 $coupons = \SureCart\Models\Coupon::where(['limit' => $limit, 'offset' => $offset])->get();
211 $result = [];
212 if (!empty($coupons)) {
213 foreach ($coupons as $coupon) {
214 $result[] = $coupon->id;
215 }
216 }
217 return $result;
218 } catch (\Throwable $e) {
219 return [];
220 }
221 }
222 }
223 elseif ($module == 'WPeCommerceCoupons') {
224 $module = 'wpsc-coupon';
225 } else {
226 $module = self::import_post_types($module, $optionalType);
227 }
228
229 $get_post_ids = "select DISTINCT ID from {$wpdb->prefix}posts";
230 $get_post_ids .= $wpdb->prepare(" where post_type = %s", $module);
231
232 /**
233 * Check for specific status
234 */
235 if ($module == 'product' && is_plugin_active('woocommerce/woocommerce.php')) {
236 if ($sitepress == null && !is_plugin_active('polylang/polylang.php') && !is_plugin_active('polylang-pro/polylang.php') && !is_plugin_active('polylang-wc/polylang-wc.php') && !is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && !is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
237 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
238 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
239 $from_date = $conditions['specific_period']['from'];
240 $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
241 $args = array('date_query' => array(array('year' => date('Y', strtotime($from_date)), 'month' => date('m', strtotime($from_date)), 'day' => date('d', strtotime($from_date)), ), ), 'status' => $product_statuses, 'limit' => $limit, 'offset' => $offset, 'orderby' => 'date');
242 } else {
243 $from_date = $conditions['specific_period']['from'] ?? null;
244 $to_date = $conditions['specific_period']['to'] ?? null;
245 $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
246 $args = array('date_query' => array(array('after' => $from_date, 'before' => $to_date, 'inclusive' => true, ), ), 'status' => $product_statuses, 'limit' => $limit, 'offset' => $offset, 'orderby' => 'date');
247 }
248 $products = wc_get_products($args);
249 } elseif (!empty($conditions['specific_post_id']['is_check']) && $conditions['specific_post_id']['is_check'] == 'true') {
250 $prod_id = explode(',', $conditions['specific_post_id']['post_id']);
251 $args = array('include' => $prod_id);
252 $products = wc_get_products($args);
253 } elseif (!empty($conditions['specific_status']['status'])) {
254 $status = $conditions['specific_status']['status'];
255 if ($conditions['specific_status']['status'] == 'all') {
256 $product_statuses = array('publish', 'draft', 'trash', 'private', 'pending');
257 $products = wc_get_products(array('status' => $product_statuses, 'limit' => $limit, 'offset' => $offset, 'orderby' => 'date'));
258 } else {
259 $product_statuses = array($status);
260 $products = wc_get_products(array('status' => $product_statuses, 'limit' => $limit, 'offset' => $offset, 'orderby' => 'date'));
261 }
262 } else {
263
264 // Define product statuses
265 $product_statuses = ['publish', 'draft', 'future', 'private', 'pending'];
266
267 // Prepare query arguments
268 $args = [
269 'status' => $product_statuses,
270 'limit' => $limit,
271 'offset' => $offset,
272 'orderby' => 'date',
273 'order' => 'DESC', // Order products by date in descending order
274 ];
275
276 // Fetch products
277 $products = wc_get_products($args);
278 }
279 // Initialize arrays to store IDs.
280 $product_ids = array();
281 $variable_product_ids = array();
282 $variation_ids = array();
283
284 // Iterate through products to separate parent and variable products.
285 foreach ($products as $product) {
286 $product_ids[] = $product->get_id(); // Store all product IDs.
287 if ($product->is_type('variable')) {
288 $variable_product_ids[] = $product->get_id(); // Store variable product IDs.
289 $variation_ids = array_merge($variation_ids, $product->get_children()); // Get variations of variable products.
290 }
291 }
292 // Merge parent product IDs and variation IDs.
293 $all_product_ids = array_merge($product_ids, $variation_ids);
294 // Remove duplicate IDs.
295 $all_product_ids = array_unique($all_product_ids);
296 self::$export_instance->totalRowCount = $this->get_total_rowCount();
297 $product_ids = !empty($all_product_ids) ? $all_product_ids : [];
298 return $product_ids;
299 } else {
300 //when polylang wpml active
301 $products = "select DISTINCT ID from {$wpdb->prefix}posts";
302 $products .= $wpdb->prepare(" where post_type = %s", $module);
303 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true' && !empty($conditions['specific_status']['status'])) { //Period and Status both are TRUE
304 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
305 $status = $conditions['specific_status']['status'];
306 $products .= $wpdb->prepare(" and post_status = %s", $status);
307 $products .= " and DATE(post_date) ='" . $conditions['specific_period']['from'] . "'";
308 } else {
309 $status = $conditions['specific_status']['status'];
310 $products .= $wpdb->prepare(" and post_status = %s", $status);
311 $products .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
312 }
313 } elseif (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
314 $products .= " and post_status in ('publish','draft','private','pending') ";
315 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
316 $products .= " and DATE(post_date) ='" . $conditions['specific_period']['from'] . "'";
317 } else {
318 $products .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
319 }
320 } elseif (!empty($conditions['specific_status']['status'])) {
321 $status = $conditions['specific_status']['status'];
322 if ($conditions['specific_status']['status'] == 'all') {
323 $products .= " and post_status in ('publish','draft','trash','private','pending') ORDER by post_date";
324 } else {
325 $products .= $wpdb->prepare(" and post_status = %s", $status) . " ORDER by post_date";
326 }
327 } elseif (!empty($conditions['specific_post_id']['is_check']) && $conditions['specific_post_id']['is_check'] == 'true') {
328 $prod_ids = array_filter(array_map('absint', explode(',', $conditions['specific_post_id']['post_id'])));
329 if (!empty($prod_ids)) {
330 $products .= " and ID in (" . implode(',', $prod_ids) . ")";
331 }
332
333 }
334 if (empty($conditions['specific_status']['status']) && empty($conditions['specific_period']['is_check'])) {
335 $products .= " and post_status in ('publish','draft','future','private','pending') ORDER by post_date";
336 }
337 $products = $wpdb->get_col($products);
338 $product_array = $products;
339 foreach ($products as $product_val) {
340 $products_var = "select DISTINCT ID from {$wpdb->prefix}posts";
341 $products_var .= $wpdb->prepare(" where post_type = 'product_variation' and post_parent = %d", absint($product_val));
342 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true' && !empty($conditions['specific_status']['status'])) { //Period and Status both are TRUE
343 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
344 $status = $conditions['specific_status']['status'];
345 $products_var .= $wpdb->prepare(" and post_status = %s", $status);
346 $products_var .= " and DATE(post_date) ='" . $conditions['specific_period']['from'] . "'";
347 } else {
348 $status = $conditions['specific_status']['status'];
349 $products_var .= $wpdb->prepare(" and post_status = %s", $status);
350 $products_var .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
351 }
352 } elseif (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
353 $products .= " and post_status in ('publish','draft','private','pending') ";
354 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
355 $products_var .= " and DATE(post_date) ='" . $conditions['specific_period']['from'] . "'";
356 } else {
357 $products_var .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
358 }
359 } elseif (!empty($conditions['specific_status']['status'])) {
360 $status = $conditions['specific_status']['status'];
361 if ($conditions['specific_status']['status'] == 'all') {
362 $products_var .= " and post_status in ('publish','draft','trash','private','pending') ORDER by post_date";
363 } else {
364 $products_var .= $wpdb->prepare(" and post_status = %s", $status) . " ORDER by post_date";
365 }
366 } elseif (!empty($conditions['specific_post_id']['is_check']) && $conditions['specific_post_id']['is_check'] == 'true') {
367 $prod_ids = array_filter(array_map('absint', explode(',', $conditions['specific_post_id']['post_id'])));
368 if (!empty($prod_ids)) {
369 $products_var .= " and ID in (" . implode(',', $prod_ids) . ")";
370 }
371
372 }
373 if (empty($conditions['specific_status']['status']) && empty($conditions['specific_period']['is_check'])) {
374 $products_var .= " and post_status in ('publish','draft','future','private','pending') ORDER by post_date";
375 }
376 $products_vars = $wpdb->get_col($products_var);
377 $product_array = array_merge($product_array, $products_vars);
378 }
379 self::$export_instance->totalRowCount = count($product_array);
380 $products_ids = !empty($products) ? array_slice($product_array, $offset, $limit) : [];
381 return $products_ids;
382 }
383 } elseif ($module == 'shop_order' && is_plugin_active('woocommerce/woocommerce.php')) {
384
385 if (!empty($conditions['specific_period']['is_check'])) {
386 $args = [
387 'return' => 'ids',
388 'limit' => $limit,
389 'offset' => $offset,
390 'orderby' => 'date',
391 'order' => 'DESC',
392 ];
393
394 if (!empty($conditions['specific_period']['is_check']) &&!empty($conditions['specific_period']['from']) &&!empty($conditions['specific_period']['to'])) {
395 $args['date_query'] = [[
396 'after' => $conditions['specific_period']['from'],
397 'before' => $conditions['specific_period']['to'],
398 'inclusive' => true,
399 ]];
400 }
401
402 $order_ids = wc_get_orders($args);
403 $count_args = $args;
404 $count_args['limit'] = -1;
405 $count_args['offset'] = 0;
406
407 self::$export_instance->totalRowCount = count(wc_get_orders($count_args));
408
409 return $order_ids;
410 }
411 if ($sitepress == null && !is_plugin_active('polylang/polylang.php') && !is_plugin_active('polylang-pro/polylang.php') && !is_plugin_active('polylang-wc/polylang-wc.php') && !is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php')) {
412 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') { //Specific period ONLY TRUE
413 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
414 $from_date = $conditions['specific_period']['from'];
415 $status = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
416 $args = array('date_query' => array(array('year' => date('Y', strtotime($from_date)), 'month' => date('m', strtotime($from_date)), 'day' => date('d', strtotime($from_date)), ), ), 'status' => $status, 'numberposts' => -1, 'orderby' => 'date', );
417 } else {
418 $from_date = $conditions['specific_period']['from'] ?? null;
419 $to_date = $conditions['specific_period']['to'] ?? null;
420 $status = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
421 ;
422 $args = array('date_query' => array(array('after' => $from_date, 'before' => $to_date, 'inclusive' => true, ), ), 'status' => $status, 'numberposts' => -1, 'orderby' => 'date');
423 }
424 $orders = wc_get_orders($args);
425 } else {
426 $order_statuses = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
427 $orders = wc_get_orders(array('status' => $order_statuses, 'numberposts' => -1, 'orderby' => 'date', 'order' => 'ASC'));
428 }
429 $get_order_ids = array();
430 if (!empty($orders)) {
431 $get_post_ids = array();
432 foreach ($orders as $my_orders) {
433 $get_post_ids[] = $my_orders->get_id();
434 }
435 self::$export_instance->totalRowCount = count($get_post_ids);
436 $get_order_ids = !empty($get_post_ids) ? array_slice($get_post_ids, $offset, $limit) : [];
437 }
438 return $get_order_ids;
439 } else {//polylang or wpml active
440 $order_statuses = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
441 $orders = wc_get_orders(array('status' => $order_statuses, 'numberposts' => -1, 'orderby' => 'date', 'order' => 'ASC'));
442 $get_post_ids = array();
443 foreach ($orders as $my_orders) {
444 $get_post_ids[] = $my_orders->get_id();
445 }
446 foreach ($get_post_ids as $ids) {
447 $module = $wpdb->get_var($wpdb->prepare("SELECT post_type FROM {$wpdb->prefix}posts where id=%d", absint($ids)));
448 }
449 if ($module == 'shop_order_placehold') {//post_status shop_order_placehold!
450 $orders = "select DISTINCT p.ID from {$wpdb->prefix}posts as p inner join {$wpdb->prefix}wc_orders as wc ON p.ID=wc.id";
451 $orders .= $wpdb->prepare(" where p.post_type = %s", $module);
452 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
453 $orders .= " and wc.status in ('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending')";
454 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
455 $orders .= " and DATE(p.post_date) ='" . $conditions['specific_period']['from'] . "'";
456 } else {
457 $orders .= " and p.post_date >= '" . $conditions['specific_period']['from'] . "' and p.post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
458 }
459 }
460 if (empty($conditions['specific_status']['status']) && empty($conditions['specific_period']['is_check'])) {
461 $orders .= " and wc.status in ('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending') ORDER BY post_date";
462 }
463 } else {//post_status shop_order!
464 $orders = "select DISTINCT ID from {$wpdb->prefix}posts";
465 $orders .= $wpdb->prepare(" where post_type = %s", $module);
466 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
467 $orders .= " and post_status in ('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending')";
468 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
469 $orders .= " and DATE(post_date) = '" . $conditions['specific_period']['from'] . "'";
470 } else {
471 $orders .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
472 }
473 } else {
474 $orders .= " and post_status in ('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending')";
475 }
476 }
477 $orders = $wpdb->get_col($orders);
478 self::$export_instance->totalRowCount = count($orders);
479 $get_order_ids = !empty($orders) ? array_slice($orders, $offset, $limit) : [];
480 return $get_order_ids;
481 }
482 } elseif ($module == 'shop_coupon') {
483 if (isset($conditions['specific_status']) && !empty($conditions['specific_status']['status'])) {
484 if ($conditions['specific_status']['status'] == 'All') {
485 $get_post_ids .= " and post_status in ('publish','draft','pending')";
486 } elseif ($conditions['specific_status']['status'] == 'Publish') {
487 $get_post_ids .= " and post_status in ('publish')";
488 } elseif ($conditions['specific_status']['status'] == 'Draft') {
489 $get_post_ids .= " and post_status in ('draft')";
490 } elseif ($conditions['specific_status']['status'] == 'Pending') {
491 $get_post_ids .= " and post_status in ('pending')";
492 }
493 } else {
494 $get_post_ids .= " and post_status in ('publish','draft','pending')";
495 }
496
497 } elseif ($module == 'shop_order_refund') {
498
499 } elseif ($module == 'lp_order') {
500 $get_post_ids .= " and post_status in ('lp-pending', 'lp-processing', 'lp-completed', 'lp-cancelled', 'lp-failed')";
501 } elseif ($module == 'forum') {
502 $get_post_ids .= " and post_status in ('publish','draft','future','private','pending','hidden')";
503 } elseif ($module == 'topic') {
504 $get_post_ids .= " and post_status in ('publish','draft','future','open','pending','closed','spam')";
505 } elseif ($module == 'reply') {
506 $get_post_ids .= " and post_status in ('publish','spam','pending')";
507 } else {
508 if (!empty($conditions['specific_status']['status'])) {
509 if ($conditions['specific_status']['status'] == 'All') {
510 $get_post_ids .= " and post_status in ('publish','draft','future','private','pending')";
511 } elseif ($conditions['specific_status']['status'] == 'Publish' || $conditions['specific_status']['status'] == 'Sticky') {
512 $get_post_ids .= " and post_status in ('publish')";
513 } elseif ($conditions['specific_status']['status'] == 'Draft') {
514 $get_post_ids .= " and post_status in ('draft')";
515 } elseif ($conditions['specific_status']['status'] == 'Scheduled') {
516 $get_post_ids .= " and post_status in ('future')";
517 } elseif ($conditions['specific_status']['status'] == 'Private') {
518 $get_post_ids .= " and post_status in ('private')";
519 } elseif ($conditions['specific_status']['status'] == 'Pending') {
520 $get_post_ids .= " and post_status in ('pending')";
521 } elseif ($conditions['specific_status']['status'] == 'Protected') {
522 $get_post_ids .= " and post_status in ('publish') and post_password != ''";
523 }
524 } else {
525 $get_post_ids .= " and post_status in ('publish','draft','future','private','pending')";
526 }
527 }
528 // Check for specific period
529 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
530 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
531 $get_post_ids .= " and post_date >= '" . $conditions['specific_period']['from'] . "'";
532 } else {
533 $get_post_ids .= " and post_date >= '" . $conditions['specific_period']['from'] . "' and post_date <= '" . $conditions['specific_period']['to'] . " 23:00:00'";
534 }
535 }
536 if ($module == 'woocommerce')
537 $get_post_ids .= " and pm.meta_key = '_sku'";
538
539 if ($module == 'wpcommerce')
540 $get_post_ids .= " and pm.meta_key = '_wpsc_sku'";
541
542 // Check for specific authors
543 if (!empty($conditions['specific_authors']['is_check'] == '1') && !empty($conditions['specific_authors']['author'])) {
544 if (isset($conditions['specific_authors']['author'])) {
545 $author_ids = array_filter(array_map('absint', (array) $conditions['specific_authors']['author']));
546 if (!empty($author_ids)) {
547 $get_post_ids .= " AND post_author IN (" . implode(',', $author_ids) . ")";
548 }
549
550 }
551 }
552
553
554 //WpeCommercecoupons
555 if ($module == 'wpsc-coupon') {
556 $get_post_ids = "select DISTINCT ID from {$wpdb->prefix}wpsc_coupon_codes";
557 }
558 //WpeCommercecoupons
559 $get_total_row_count = $wpdb->get_col($get_post_ids);
560 if (!empty($get_total_row_count)) {
561 if (!empty($conditions['specific_period']['is_check']) && $conditions['specific_period']['is_check'] == 'true') {
562 if ($conditions['specific_period']['from'] == $conditions['specific_period']['to']) {
563 $result = array();
564 foreach ($get_total_row_count as $result_value) {
565 //$get_post_date_time = $wpdb->get_results( $wpdb->prepare("SELECT post_date FROM {$wpdb->prefix}posts WHERE id=$result_value") ,ARRAY_A);
566 $get_post_date_time = $wpdb->get_results($wpdb->prepare("SELECT post_date FROM {$wpdb->prefix}posts WHERE id = %d", absint($result_value)), ARRAY_A);
567 $get_post_date = date("Y-m-d", strtotime($get_post_date_time[0]['post_date']));
568 if ($get_post_date == $conditions['specific_period']['from']) {
569 $get_post_date_value[] = $result_value;
570 }
571 }
572 self::$export_instance->totalRowCount = count($get_post_date_value);
573 $result = $get_post_date_value;
574 } else {
575 self::$export_instance->totalRowCount = count($get_total_row_count);
576 $offset_limit = " order by ID asc limit {$offset}, {$limit}";
577 $query_with_offset_limit = $get_post_ids . $offset_limit;
578 $result = $wpdb->get_col($query_with_offset_limit);
579 }
580 } else {
581 self::$export_instance->totalRowCount = count($get_total_row_count);
582 $offset_limit = " order by ID asc limit {$offset}, {$limit}";
583 $query_with_offset_limit = $get_post_ids . $offset_limit;
584 $result = $wpdb->get_col($query_with_offset_limit);
585 }
586 }
587 if ($module == 'JetReviews') {
588 // Check if specific review conditions are provided
589 if (!empty($conditions['specific_review_status']['approved'])) {
590 $approved = $conditions['specific_review_status']['approved'];
591 $reviews = $wpdb->get_results(
592 $wpdb->prepare(
593 "SELECT * FROM {$wpdb->prefix}jet_reviews WHERE approved = %d ORDER BY date DESC LIMIT %d OFFSET %d",
594 $approved,
595 $limit,
596 $offset
597 ),
598 ARRAY_A
599 );
600
601 // Collect review IDs
602 foreach ($reviews as $review) {
603 $result[] = $review['id']; // Assuming 'id' is the primary key for reviews
604 }
605
606 self::$export_instance->totalRowCount = !empty($result) ? count($result) : 0;
607 return !empty($result) ? array_slice($result, $offset, $limit) : [];
608 } else {
609 // Fetch all reviews if no specific conditions are set
610 $reviews = $wpdb->get_results(
611 $wpdb->prepare(
612 "SELECT * FROM {$wpdb->prefix}jet_reviews ORDER BY date DESC LIMIT %d OFFSET %d",
613 $limit,
614 $offset
615 ),
616 ARRAY_A
617 );
618
619 foreach ($reviews as $review) {
620 $result[] = $review['id'];
621 }
622
623 self::$export_instance->totalRowCount = !empty($result) ? count($result) : 0;
624 return !empty($result) ? array_slice($result, $offset, $limit) : [];
625 }
626 }
627
628 if (is_plugin_active('jet-engine/jet-engine.php')) {
629 $get_slug_name = $wpdb->get_results("SELECT slug FROM {$wpdb->prefix}jet_post_types WHERE status = 'content-type'");
630 foreach ($get_slug_name as $key => $get_slug) {
631 $value = $get_slug->slug;
632 $optional_type = $value;
633 if ($optionalType == $optional_type) {
634 $table_name = 'jet_cct_' . $optional_type;
635 $get_total_row_count = $wpdb->get_results("SELECT _ID FROM {$wpdb->prefix}$table_name ");
636 self::$export_instance->totalRowCount = count($get_total_row_count);
637 }
638 }
639 }
640
641 // Get sticky post alone on the specific post status
642 if (isset($conditions['specific_period']['is_check']) && isset($conditions['specific_status']['is_check']) && $conditions['specific_status']['is_check'] == 'true') {
643 if (isset($conditions['specific_status']['status']) && $conditions['specific_status']['status'] == 'Sticky') {
644 $get_sticky_posts = get_option('sticky_posts');
645 foreach ($get_sticky_posts as $sticky_post_id) {
646 if (in_array($sticky_post_id, $result))
647 $sticky_posts[] = $sticky_post_id;
648 }
649 return $sticky_posts;
650 }
651 }
652 $result = isset($result) ? $result : [];
653 return $result;
654 }
655
656 public function import_post_types($import_type, $importAs = null)
657 {
658 $import_type = trim($import_type);
659 $module = array('Posts' => 'post', 'Pages' => 'page', 'Users' => 'user', 'Comments' => 'comments', 'Taxonomies' => $importAs, 'CustomerReviews' => 'wpcr3_review', 'Categories' => 'categories', 'Tags' => 'tags', 'WooCommerce' => 'product', 'WPeCommerce' => 'wpsc-product', 'WPeCommerceCoupons' => 'wpsc-product', 'WooCommerceVariations' => 'product', 'WooCommerceOrders' => 'product', 'WooCommerceCoupons' => 'product', 'WooCommerceRefunds' => 'product', 'CustomPosts' => $importAs, 'EDD_DOWNLOADS' => 'download');
660 foreach (get_taxonomies() as $key => $taxonomy) {
661 $module[$taxonomy] = $taxonomy;
662 }
663 if (array_key_exists($import_type, $module)) {
664 return $module[$import_type];
665 } else {
666 return $import_type;
667 }
668 }
669
670 /**
671 * Function to export the meta information based on Fetch ACF field information to be export
672 * @param $id
673 * @return mixed
674 */
675 public function getPostsMetaDataBasedOnRecordId($id, $module, $optionalType)
676 {
677
678 global $wpdb;
679 $typeOftypesField = NULL;
680 $checkRep = NULL;
681 $allacf = NULL;
682 $alltype = NULL;
683 $parent = NULL;
684 $typesf = NULL;
685 $jet_metafields = NULL;
686 if ($module == 'Users') {
687 $query = "SELECT user_id, meta_key, meta_value FROM {$wpdb->prefix}users wp JOIN {$wpdb->prefix}usermeta wpm ON wpm.user_id = wp.ID WHERE meta_key NOT IN ('_edit_lock', '_edit_last') AND ID={$id}";
688 } elseif ($module == 'Categories' || $module == 'Taxonomies' || $module == 'Tags') {
689 $query = "SELECT wp.term_id, meta_key, meta_value FROM {$wpdb->prefix}terms wp JOIN {$wpdb->prefix}termmeta wpm ON wpm.term_id = wp.term_id WHERE meta_key NOT IN ('_edit_lock', '_edit_last') AND wp.term_id = {$id}";
690 } else {
691 $query = "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 ('_edit_lock', '_edit_last') AND ID={$id}";
692 }
693
694
695 $get_acf_fields = $wpdb->get_results("SELECT ID, post_excerpt, post_content, post_name, post_parent, post_type FROM {$wpdb->prefix}posts where post_type = 'acf-field'", ARRAY_A);
696
697 $group_unset = array('customer_email', 'product_categories', 'exclude_product_categories');
698
699 if (!empty($get_acf_fields)) {
700 foreach ($get_acf_fields as $key => $value) {
701
702 if (!empty($value['post_parent'])) {
703 $parent = get_post($value['post_parent']);
704 if (!empty($parent)) {
705 if ($parent->post_type == 'acf-field') {
706 $allacf[$value['post_excerpt']] = $parent->post_excerpt . '_' . $value['post_excerpt'];
707 } else {
708 $allacf[$value['post_excerpt']] = $value['post_excerpt'];
709 }
710 } else {
711 $allacf[$value['post_excerpt']] = $value['post_excerpt'];
712 }
713 } else {
714 $allacf[$value['post_excerpt']] = $value['post_excerpt'];
715 }
716
717 self::$export_instance->allacf = $allacf;
718
719 $content = unserialize($value['post_content']);
720 $alltype[$value['post_excerpt']] = $content['type'];
721
722 if ($content['type'] == 'repeater' || $content['type'] == 'flexible_content') {
723 $checkRep[$value['post_excerpt']] = $this->getRepeater($value['ID']);
724 } else {
725 $checkRep[$value['post_excerpt']] = "";
726 }
727 }
728 }
729
730 self::$export_instance->allpodsfields = $this->getAllPodsFields();
731
732 if ($module == 'Categories' || $module == 'Tags' || $module == 'Taxonomies') {
733 self::$export_instance->alltoolsetfields = get_option('wpcf-termmeta');
734 } elseif ($module == 'Users') {
735 self::$export_instance->alltoolsetfields = get_option('wpcf-usermeta');
736
737 } else {
738 self::$export_instance->alltoolsetfields = get_option('wpcf-fields');
739 }
740
741 if (!empty(self::$export_instance->alltoolsetfields)) {
742 $i = 1;
743 foreach (self::$export_instance->alltoolsetfields as $key => $value) {
744 $typesf[$i] = 'wpcf-' . $key;
745 $typeOftypesField[$typesf[$i]] = $value['type'];
746 $i++;
747 }
748 }
749 $typeOftypesField = isset($typeOftypesField) ? $typeOftypesField : '';
750 self::$export_instance->typeOftypesField = $typeOftypesField;
751 self::$export_instance->alltoolsetfields = get_option('wpcf-fields');
752
753 self::$export_instance->typeOftypesField = $typeOftypesField;
754
755 $result = $wpdb->get_results($query);
756
757 if (is_plugin_active('jet-booking/jet-booking.php')) {
758 $manage_units = jet_abaf()->db->get_apartment_units($id);
759 if (!empty($manage_units)) {
760
761 $titleCounts = [];
762 foreach ($manage_units as $unit) {
763 // Remove any trailing space followed by numbers (e.g., " 1", " 2", " 3") at the end of unit_title
764 $baseTitle = preg_replace('/\s+\d+$/', '', $unit['unit_title']);
765 if (!isset($titleCounts[$baseTitle])) {
766 $titleCounts[$baseTitle] = 0;
767 }
768 $titleCounts[$baseTitle]++;
769 }
770 self::$export_instance->data[$id]['unit_title'] = implode('|', array_keys($titleCounts));
771 self::$export_instance->data[$id]['unit_number'] = implode('|', array_values($titleCounts));
772 }
773 }
774
775 // jeteng fields
776 if (is_plugin_active('jet-engine/jet-engine.php')) {
777
778 $jetEnginefields = $wpdb->get_results($wpdb->prepare("SELECT id, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = %s AND status IN ('publish','built-in')", $optionalType), ARRAY_A);
779 $jetEnginefields[0]['meta_fields'] = isset($jetEnginefields[0]['meta_fields']) ? $jetEnginefields[0]['meta_fields'] : '';
780
781 $unserializedMeta = maybe_unserialize($jetEnginefields[0]['meta_fields']);
782 $unserializedMeta = isset($unserializedMeta) ? $unserializedMeta : '';
783
784 if (is_array($unserializedMeta)) {
785 foreach ($unserializedMeta as $jet_key => $jetValue) {
786 $jetFieldLabel = $jetValue['title'];
787 $jetFieldType = $jetValue['type'];
788 if ($jetFieldType != 'repeater' && $jetFieldType != 'media' && $jetFieldType != 'gallery' && $jetFieldType != 'posts' && $jetFieldType != 'html') {
789 $jetFieldNameArr[] = $jetValue['name'];
790 } else {
791 $jetFieldNameArr[] = $jetValue['name'];
792 $fields = $jetValue['repeater-fields'];
793 if (is_array($fields)) {
794 foreach ($fields as $repFieldKey => $repFieldVal) {
795 $jetFieldName[] = $repFieldVal['name'];
796
797 }
798 }
799 }
800 }
801 }
802
803 if (isset($jetFieldName) && is_array($jetFieldName)) {
804 if (is_array($jetFieldNameArr)) {
805 $jetCPTFieldsName = array_merge($jetFieldNameArr, $jetFieldName);
806 } else {
807 $jetCPTFieldsName = $jetFieldName;
808 }
809
810 } else {
811 $jetFieldNameArr = isset($jetFieldNameArr) ? $jetFieldNameArr : '';
812 $jetCPTFieldsName = $jetFieldNameArr;
813 }
814
815 //jeteng metabox fields
816
817 global $wpdb;
818 //$getMetaFields = $wpdb->get_results( $wpdb->prepare("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name=%s",'jet_engine_meta_boxes'),ARRAY_A);
819 $getMetaFields = $wpdb->get_results("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name='jet_engine_meta_boxes'", ARRAY_A);
820 if (!empty($getMetaFields)) {
821 $unserializedMeta = maybe_unserialize($getMetaFields[0]['option_value']);
822 } else {
823 $unserializedMeta = '';
824 }
825
826 if (is_array($unserializedMeta)) {
827 $arraykeys = array_keys($unserializedMeta);
828
829 foreach ($arraykeys as $val) {
830 $values = explode('-', $val);
831 $v = $values[1];
832 }
833 }
834
835
836 $jetMetaFieldName = [];
837 if (isset($v)) {
838 for ($i = 1; $i <= $v; $i++) {
839 $unserializedMeta['meta-' . $i] = isset($unserializedMeta['meta-' . $i]) ? $unserializedMeta['meta-' . $i] : '';
840 $fields = $unserializedMeta['meta-' . $i];
841 if (!empty($fields)) {
842 foreach ($fields['meta_fields'] as $jet_key => $jetValue) {
843 if ($jetValue['type'] != 'repeater') {
844 $jetMetaFieldName[] = $jetValue['name'];
845 } else {
846 $jetMetaFieldName[] = $jetValue['name'];
847 $jetRepFields = $jetValue['repeater-fields'];
848 foreach ($jetRepFields as $jetRepKey => $jetRepVal) {
849 $jetRepFieldName[] = $jetRepVal['name'];
850 }
851 }
852 }
853 }
854
855 }
856 }
857 if (isset($jetRepFieldName) && is_array($jetRepFieldName)) {
858 if (is_array($jetMetaFieldName)) {
859 $jetFName = array_merge($jetMetaFieldName, $jetRepFieldName);
860 } else {
861 $jetFName = $jetRepFieldName;
862 }
863 } else {
864 $jetFName = $jetMetaFieldName;
865 }
866
867 /*jet releation export support added */
868 $get_rel_fields = $wpdb->get_results("SELECT id,labels, args, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE status = 'relation' ", ARRAY_A);
869 $get_cpt_fields = $wpdb->get_results($wpdb->prepare("SELECT id,labels, args, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = %s ", $optionalType), ARRAY_A);
870 if (!empty($get_rel_fields)) {
871 foreach ($get_rel_fields as $get_rel_values) {
872 $imported_type = !empty($optionalType) ? $optionalType : $module;
873
874 $jet_relation_names = maybe_unserialize($get_rel_values['labels']);
875 $jet_relation_name = maybe_unserialize($jet_relation_names['name']);
876 $jet_relation_id = $get_rel_values['id'];
877
878 $get_rel_fields_args = maybe_unserialize($get_rel_values['args']);
879 $get_rel_parent_value = $get_rel_fields_args['parent_object'];
880 $get_rel_child_value = $get_rel_fields_args['child_object'];
881 $get_rel_db_table = $get_rel_fields_args['db_table'];
882
883 $get_rel_parent1 = explode('::', $get_rel_parent_value);
884 $get_rel_parent = $get_rel_parent1[1];
885 $get_rel_parent_type = $get_rel_parent1[0];
886
887 $get_rel_child1 = explode('::', $get_rel_child_value);
888 $get_rel_child = $get_rel_child1[1];
889 $get_rel_child_type = $get_rel_child1[0];
890
891 if ($imported_type == 'user') {
892 $imported_type = 'users';
893 }
894 if ($imported_type == 'posts') {
895 $imported_type = 'post';
896 }
897
898 if ($get_rel_db_table == 1) {
899 $jet_rel_table_name = $wpdb->prefix . 'jet_rel_' . $jet_relation_id;
900 $jet_relmeta_table_name = $wpdb->prefix . 'jet_rel_' . $jet_relation_id . '_meta';
901 } else {
902 $jet_rel_table_name = $wpdb->prefix . 'jet_rel_default';
903 $jet_relmeta_table_name = $wpdb->prefix . 'jet_rel_default_meta';
904 }
905 if ($imported_type == $get_rel_parent || $imported_type == $get_rel_child) {
906 $get_rel_metafields = maybe_unserialize($get_rel_values['meta_fields']);
907
908 if ($imported_type == $get_rel_parent) {
909 $get_jet_rel_object_connections = array();
910 $get_jet_rel_connections = $wpdb->get_results("SELECT child_object_id FROM $jet_rel_table_name WHERE parent_object_id = $id and rel_id = $jet_relation_id", ARRAY_A);
911 $get_jet_rel_object_connections = array_column($get_jet_rel_connections, 'child_object_id');
912
913 if (!empty($get_jet_rel_object_connections) && !empty($get_rel_metafields)) {
914 $this->get_jetengine_relation_meta_fields($jet_relation_id, $id, $get_rel_metafields, $get_jet_rel_object_connections, 'parent', $jet_relmeta_table_name);
915 }
916 } elseif ($imported_type == $get_rel_child) {
917 $get_jet_rel_object_connections = array();
918 $get_jet_rel_connections = $wpdb->get_results("SELECT parent_object_id FROM $jet_rel_table_name WHERE child_object_id = $id and rel_id = $jet_relation_id", ARRAY_A);
919 $get_jet_rel_object_connections = array_column($get_jet_rel_connections, 'parent_object_id');
920
921 if (!empty($get_jet_rel_object_connections) && !empty($get_rel_metafields)) {
922 $this->get_jetengine_relation_meta_fields($jet_relation_id, $id, $get_rel_metafields, $get_jet_rel_object_connections, 'child', $jet_relmeta_table_name);
923 }
924 }
925 $get_rel_object_value = '';
926 if (!empty($get_jet_rel_object_connections)) {
927 if ($imported_type == $get_rel_parent) {
928
929
930 if ($get_rel_child == 'users') {
931 $users = $wpdb->prefix . 'users';
932 $get_jet_rel_object_connections = implode(",", $get_jet_rel_object_connections);
933 $get_jet_rel_connections = $wpdb->get_col("SELECT user_login FROM $users WHERE ID IN ($get_jet_rel_object_connections)");
934 $get_rel_object_value = implode('|', $get_jet_rel_connections);
935 } elseif ($get_rel_parent_type == 'terms' && $get_rel_child_type == 'terms') {
936 $stored_objects = [];
937 foreach ($get_jet_rel_object_connections as $my_jet_rel_objects) {
938 $stored_objects[] = $wpdb->get_col("SELECT wp_terms.name FROM {$wpdb->prefix}terms AS wp_terms INNER JOIN {$wpdb->prefix}jet_rel_default AS wp_jet_rel_default ON wp_terms.term_id = wp_jet_rel_default.child_object_id WHERE wp_jet_rel_default.child_object_id = $my_jet_rel_objects");
939 }
940 $stored_objects_results = [];
941 foreach ($stored_objects as $inner_array_values) {
942 $stored_objects_results[] = implode('|', $inner_array_values);
943 }
944 $get_rel_object_value = implode('|', $stored_objects_results);
945 } else {
946 $posts = $wpdb->prefix . 'posts';
947 $get_jet_rel_object_connections = implode(",", $get_jet_rel_object_connections);
948 $get_jet_rel_connections = $wpdb->get_col("SELECT post_title FROM $posts WHERE ID IN ($get_jet_rel_object_connections)");
949 $get_rel_object_value = implode('|', $get_jet_rel_connections);
950 }
951 } else if ($imported_type == $get_rel_child) {
952
953
954 if ($get_rel_parent == 'users') {
955 $users = $wpdb->prefix . 'users';
956 $get_jet_rel_object_connections = implode(",", $get_jet_rel_object_connections);
957 $get_jet_rel_connections = $wpdb->get_col("SELECT user_login FROM $users WHERE ID IN ($get_jet_rel_object_connections)");
958 $get_rel_object_value = implode('|', $get_jet_rel_connections);
959 } elseif ($get_rel_parent_type == 'terms' && $get_rel_child_type == 'terms') {
960 $stored_objects = [];
961 foreach ($get_jet_rel_object_connections as $my_jet_rel_objects) {
962 $stored_objects[] = $wpdb->get_col("SELECT wp_terms.name FROM {$wpdb->prefix}terms AS wp_terms INNER JOIN {$wpdb->prefix}jet_rel_default AS wp_jet_rel_default ON wp_terms.term_id = wp_jet_rel_default.parent_object_id WHERE wp_jet_rel_default.parent_object_id = $my_jet_rel_objects");
963 }
964 $stored_objects_results = [];
965 foreach ($stored_objects as $inner_array_values) {
966 $stored_objects_results[] = implode('|', $inner_array_values);
967 }
968 $get_rel_object_value = implode('|', $stored_objects_results);
969 } else {
970 $posts = $wpdb->prefix . 'posts';
971 $get_jet_rel_object_connections = implode(",", $get_jet_rel_object_connections);
972 $get_jet_rel_connections = $wpdb->get_col("SELECT post_title FROM $posts WHERE ID IN ($get_jet_rel_object_connections)");
973 $get_rel_object_value = implode('|', $get_jet_rel_connections);
974 }
975 }
976 }
977 self::$export_instance->data[$id]['jet_related_post :: ' . $jet_relation_id] = $get_rel_object_value;
978 }
979 }
980 } else if (!empty($get_cpt_fields[0])) {
981 $get_cpt_fields_args = maybe_unserialize($get_cpt_fields[0]['args']);
982 $check_custom_table = $get_cpt_fields_args['custom_storage'];
983 if ($check_custom_table && isset($check_custom_table)) {
984 $table_name = $wpdb->prefix . $optionalType . '_meta';
985 // Check if the table exists
986 if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name) {
987 // Call the function if the table exists
988 PostExport::$jet_custom_table_export->get_custom_table_meta_fields($module, $id, $table_name, $optionalType);
989 }
990 }
991 }
992
993 } else {
994 $jetCPTFieldsName = $jetFName = $jet_tax_fields_name = '';
995 }
996
997 //added for metabox plugin fields
998 if (is_plugin_active('meta-box/meta-box.php') || is_plugin_active('meta-box-aio/meta-box-aio.php')) {
999 $metabox_import_type = self::import_post_types($module, $optionalType);
1000 $metabox_fields = \rwmb_get_object_fields($metabox_import_type);
1001
1002 $taxonomies = get_taxonomies();
1003
1004 if ($metabox_import_type == 'user') {
1005 $metabox_fields = \rwmb_get_object_fields($metabox_import_type, 'user');
1006 } else if (array_key_exists($metabox_import_type, $taxonomies)) {
1007 $metabox_fields = \rwmb_get_object_fields($metabox_import_type, 'term');
1008 } else {
1009 $metabox_fields = \rwmb_get_object_fields($metabox_import_type);
1010 }
1011 $this->getCustomFieldValue($id, $value = null, $checkRep, $allacf, $typeOftypesField, $alltype, $jet_fields = null, $jet_types = null, $jet_rep_fields = null, $jet_rep_types = null, $parent, $typesf, $group_unset, $optionalType, self::$export_instance->allpodsfields, $metabox_fields, $module, $metabox_relation_fields = null);
1012
1013 } else {
1014 $metabox_fields = [];
1015 }
1016
1017 if (!empty($result)) {
1018
1019 foreach ($result as $key => $value) {
1020
1021 if ($value->meta_key == 'rank_math_schema_BlogPosting') {
1022 $rank_value = $value->meta_value;
1023 $rank_math = unserialize($rank_value);
1024 $headline = $rank_math['headline'];
1025 $schema_description = $rank_math['description'];
1026 $article_type = $rank_math['@type'];
1027 $re_id = $wpdb->get_results($wpdb->prepare("SELECT redirection_id FROM {$wpdb->prefix}rank_math_redirections_cache where object_id=%d", absint($id)));
1028 $redirect_id = $re_id[0];
1029 $redirection_id = $redirect_id->redirection_id;
1030 $result = $wpdb->get_results($wpdb->prepare("SELECT url_to,header_code FROM {$wpdb->prefix}rank_math_redirections where id=%d", absint($redirection_id)));
1031 $rank_math_redirections = $result[0];
1032 $url_to = $rank_math_redirections->url_to;
1033 $header_code = $rank_math_redirections->header_code;
1034
1035 self::$export_instance->data[$id]['headline'] = $headline;
1036 self::$export_instance->data[$id]['schema_description'] = $schema_description;
1037 self::$export_instance->data[$id]['article_type'] = $article_type;
1038 self::$export_instance->data[$id]['destination_url'] = $url_to;
1039 self::$export_instance->data[$id]['redirection_type'] = $header_code;
1040 }
1041 if ($value->meta_key == 'rank_math_schema_Dataset') {
1042
1043 $schema_data = get_post_meta($id, 'rank_math_schema_Dataset', true);
1044 self::$export_instance->data[$id]['ds_name'] = $schema_data['name'];
1045 self::$export_instance->data[$id]['ds_description'] = $schema_data['description'];
1046 self::$export_instance->data[$id]['ds_url'] = $schema_data['url'];
1047 self::$export_instance->data[$id]['ds_sameAs'] = $schema_data['sameAs'];
1048 self::$export_instance->data[$id]['ds_license'] = $schema_data['license'];
1049 self::$export_instance->data[$id]['ds_temp_coverage'] = $schema_data['temporalCoverage'];
1050 self::$export_instance->data[$id]['ds_spatial_coverage'] = $schema_data['spatialCoverage'];
1051 $distribution = $schema_data['distribution'];
1052 $identifier = $schema_data['identifier'];
1053 $keywords = $schema_data['keywords'];
1054 if (is_array($distribution)) {
1055 $encodeFormat = '';
1056 $contenUrl = '';
1057 foreach ($distribution as $disKey => $disVal) {
1058 $encodeFormat .= $disVal['encodingFormat'] . ',';
1059 $contentUrl .= $disVal['contentUrl'] . ',';
1060 self::$export_instance->data[$id]['encodingFormat'] = rtrim($encodeFormat, ',');
1061 self::$export_instance->data[$id]['contentUrl'] = rtrim($contentUrl, ',');
1062 }
1063
1064 }
1065
1066 if (is_array($identifier)) {
1067 $ident = '';
1068 foreach ($identifier as $identKey => $identVal) {
1069 $ident .= $identVal . ',';
1070
1071 self::$export_instance->data[$id]['ds_identifier'] = rtrim($ident, ',');
1072
1073 }
1074 }
1075
1076 if (is_array($keywords)) {
1077 $keyword = '';
1078 foreach ($keywords as $kwKey => $keyVal) {
1079 $keyword .= $keyVal . ',';
1080 self::$export_instance->data[$id]['ds_keywords'] = rtrim($keyword, ',');
1081 }
1082 }
1083
1084 }
1085 if ($value->meta_key == 'rank_math_advanced_robots') {
1086 $rank_robots_value = $value->meta_value;
1087 $rank_robots = unserialize($rank_robots_value);
1088 $max_snippet = $rank_robots['max-snippet'];
1089 $max_video_preview = $rank_robots['max-video-preview'];
1090 $max_image_preview = $rank_robots['max-image-preview'];
1091 $rank_math_advanced_robots = $max_snippet . ',' . $max_video_preview . ',' . $max_image_preview;
1092 self::$export_instance->data[$id]['rank_math_advanced_robots'] = $rank_math_advanced_robots;
1093 }
1094 if (is_plugin_active('advanced-classifieds-and-directory-pro/acadp.php')) {
1095 $listingFields = array('price', 'views', 'views', 'zipcode', 'phone', 'email', 'website', 'images', 'video', 'latitude', 'longitude', 'location');
1096
1097
1098 if (isset($value->meta_key) && in_array($value->meta_key, $listingFields)) {
1099
1100 if (is_serialized($value->meta_value)) {
1101 $value->meta_value = unserialize($value->meta_value);
1102 }
1103
1104 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1105
1106 }
1107
1108
1109 }
1110 if ((isset($value->meta_key) && is_array($jetFName))) {
1111 if (in_array($value->meta_key, $jetFName)) {
1112 $getMetaFields = $wpdb->get_results($wpdb->prepare("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name=%s", 'jet_engine_meta_boxes'), ARRAY_A);
1113 $getMetaFields[0]['option_value'] = isset($getMetaFields[0]) ? $getMetaFields[0]['option_value'] : '';
1114 $unserializedMeta = maybe_unserialize($getMetaFields[0]['option_value']);
1115 if (is_array($unserializedMeta)) {
1116 $arraykeys = array_keys($unserializedMeta);
1117
1118 foreach ($arraykeys as $val) {
1119 $values = explode('-', $val);
1120 $v = $values[1];
1121 }
1122 }
1123
1124
1125
1126 for ($i = 1; $i <= $v; $i++) {
1127 $unserializedMeta['meta-' . $i] = isset($unserializedMeta['meta-' . $i]) ? $unserializedMeta['meta-' . $i] : '';
1128 $fields = $unserializedMeta['meta-' . $i];
1129 if (!empty($fields)) {
1130 $jet_metatypes = array();
1131 $jet_reptype = array();
1132 foreach ($fields['meta_fields'] as $jet_key => $jetValue) {
1133 $jetFieldLabel = $jetValue['title'];
1134 $jetFNames = $jetValue['name'];
1135 $jetFieldType = $jetValue['type'];
1136 if ($jetFieldType != 'repeater') {
1137
1138 $jet_metafields[$jetFNames] = $jetFNames;
1139
1140 $jet_metatypes[$jetFNames] = $jetFieldType;
1141
1142 } else {
1143 $jet_metafields[$jetFNames] = $jetFNames;
1144 $jet_metatypes[$jetFNames] = $jetFieldType;
1145 $repfields = $jetValue['repeater-fields'];
1146 $jet_repfield = array();
1147 foreach ($repfields as $repFieldKey => $repFieldVal) {
1148 $jetRepFields_label = $repFieldVal['name'];
1149 $jetRepFields_type = $repFieldVal['type'];
1150
1151 $jet_repfield[$jetRepFields_label] = $jetRepFields_label;
1152 $jet_reptype[$jetRepFields_label] = $jetRepFields_type;
1153 }
1154 }
1155 }
1156 }
1157
1158 self::$export_instance->jet_metafields = $jet_metafields;
1159 self::$export_instance->jet_metatypes = $jet_metatypes;
1160 if (!empty($jet_repfield)) {
1161 self::$export_instance->jet_repfield = $jet_repfield;
1162 self::$export_instance->jet_reptype = $jet_reptype;
1163 } else {
1164 $jet_repfield = '';
1165 $jet_reptype = '';
1166 }
1167 $this->getCustomFieldValue($id, $value, $checkRep, $allacf, $typeOftypesField, $alltype, $jet_metafields, $jet_metatypes, $jet_repfield, $jet_reptype, $parent, $typesf, $group_unset, $optionalType, self::$export_instance->allpodsfields, $metabox_fields, $module);
1168 }
1169 }
1170 }
1171 if (is_array($jetCPTFieldsName) && isset($value->meta_key)) {
1172 if (in_array($value->meta_key, $jetCPTFieldsName)) {
1173 $jetEnginefields = $wpdb->get_results($wpdb->prepare("SELECT id, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = %s AND status IN ('publish','built-in')", $optionalType), ARRAY_A);
1174
1175 if (!empty($jetEnginefields)) {
1176 $unserializedMeta = maybe_unserialize($jetEnginefields[0]['meta_fields']);
1177 } else {
1178 $unserializedMeta = '';
1179 }
1180 $jetTypes = array();
1181 $jet_rep_cpttypes = array();
1182 foreach ($unserializedMeta as $jet_key => $jetValue) {
1183 $jetFieldLabel = $jetValue['title'];
1184 $jet_cptfield_names = $jetValue['name'];
1185 $jetFieldType = $jetValue['type'];
1186 if ($jetFieldType != 'repeater') {
1187 $jet_cptfields[$jet_cptfield_names] = $jet_cptfield_names;
1188 $jetTypes[$jet_cptfield_names] = $jetFieldType;
1189 } else {
1190 $jet_cptfields[$jet_cptfield_names] = $jet_cptfield_names;
1191 $jetTypes[$jet_cptfield_names] = $jetFieldType;
1192 $fields = $jetValue['repeater-fields'];
1193 foreach ($fields as $repFieldKey => $repFieldVal) {
1194 $jet_rep_cptfields_label = $repFieldVal['name'];
1195 $jet_rep_cptfields_type = $repFieldVal['type'];
1196 $jet_rep_cptfields[$jet_rep_cptfields_label] = $jet_rep_cptfields_label;
1197 $jet_rep_cpttypes[$jet_rep_cptfields_label] = $jet_rep_cptfields_type;
1198 }
1199 }
1200
1201 }
1202 self::$export_instance->jet_cptfields = $jet_cptfields;
1203 self::$export_instance->jet_types = $jetTypes;
1204 if (isset($jet_rep_cptfields)) {
1205 self::$export_instance->jet_rep_cptfields = $jet_rep_cptfields;
1206 self::$export_instance->jet_rep_cpttypes = $jet_rep_cpttypes;
1207 } else {
1208 $jet_rep_cptfields = '';
1209 $jet_rep_cpttypes = '';
1210 }
1211 $this->getCustomFieldValue($id, $value, $checkRep, $allacf, $typeOftypesField, $alltype, $jet_cptfields, $jetTypes, $jet_rep_cptfields, $jet_rep_cpttypes, $parent, $typesf, $group_unset, $optionalType, self::$export_instance->allpodsfields, $metabox_fields, $module);
1212 }
1213 } else {
1214 $jet_fields = $jetFieldType = $jetRepFields = $jet_rep_types = '';
1215 $typesf = isset($typesf) ? $typesf : '';
1216 $jetTypes = isset($jetTypes) ? $jetTypes : '';
1217 $this->getCustomFieldValue($id, $value, $checkRep, $allacf, $typeOftypesField, $alltype, $jet_fields, $jetTypes, $jetRepFields, $jet_rep_types, $parent, $typesf, $group_unset, $optionalType, self::$export_instance->allpodsfields, $metabox_fields, $module);
1218 }
1219 }
1220 }
1221
1222 if (is_plugin_active('wordpress-seo/wp-seo.php') || is_plugin_active('wordpress-seo-premium/wp-seo-premium.php')) {
1223 self::$export_instance->data[$id]['title'] = self::$export_instance->data[$id]['post_title'];
1224 if ($value->meta_key == '_yoast_wpseo_focuskw') {
1225 self::$export_instance->data[$id]['focus_keyword'] = $value->meta_value;
1226 }
1227 if ($value->meta_key == '_yoast_wpseo_linkdex') {
1228 self::$export_instance->data[$id]['linkdex'] = $value->meta_value;
1229 }
1230 if ($value->meta_key == '_yoast_wpseo_meta-robots-noindex') {
1231 self::$export_instance->data[$id]['meta-robots-noindex'] = $value->meta_value;
1232 }
1233 if ($value->meta_key == '_yoast_wpseo_metadesc') {
1234 self::$export_instance->data[$id]['meta_desc'] = $value->meta_value;
1235 }
1236 if ($value->meta_key == '_yoast_wpseo_opengraph-description') {
1237 self::$export_instance->data[$id]['opengraph-description'] = $value->meta_value;
1238 }
1239 if ($value->meta_key == '_yoast_wpseo_opengraph-title') {
1240 self::$export_instance->data[$id]['opengraph-title'] = $value->meta_value;
1241 }
1242 if ($value->meta_key == '_yoast_wpseo_twitter-title') {
1243 self::$export_instance->data[$id]['twitter-title'] = $value->meta_value;
1244 }
1245 if ($value->meta_key == '_yoast_wpseo_google-plus-title') {
1246 self::$export_instance->data[$id]['google-plus-title'] = $value->meta_value;
1247 }
1248 if ($value->meta_key == '_yoast_wpseo_google-plus-description') {
1249 self::$export_instance->data[$id]['google-plus-description'] = $value->meta_value;
1250 }
1251 if ($value->meta_key == '_yoast_wpseo_google-plus-image') {
1252 self::$export_instance->data[$id]['google-plus-image'] = $value->meta_value;
1253 }
1254 if ($value->meta_key == '_yoast_wpseo_twitter-description') {
1255 self::$export_instance->data[$id]['twitter-description'] = $value->meta_value;
1256 }
1257 if ($value->meta_key == '_yoast_wpseo_twitter-image') {
1258 self::$export_instance->data[$id]['twitter-image'] = $value->meta_value;
1259 }
1260 if ($value->meta_key == '_yoast_wpseo_bctitle') {
1261 self::$export_instance->data[$id]['bctitle'] = $value->meta_value;
1262 }
1263 if ($value->meta_key == '_yoast_wpseo_canonical') {
1264 self::$export_instance->data[$id]['canonical'] = $value->meta_value;
1265 }
1266 if ($value->meta_key == '_yoast_wpseo_redirect') {
1267 self::$export_instance->data[$id]['redirect'] = $value->meta_value;
1268 }
1269 if ($value->meta_key == '_yoast_wpseo_opengraph-image') {
1270 self::$export_instance->data[$id]['opengraph-image'] = $value->meta_value;
1271 }
1272 if ($value->meta_key == '_yoast_wpseo_meta-robots-nofollow') {
1273 self::$export_instance->data[$id]['meta-robots-nofollow'] = $value->meta_value;
1274 }
1275 if ($value->meta_key == '_yoast_wpseo_meta-robots-adv') {
1276 self::$export_instance->data[$id]['meta-robots-adv'] = $value->meta_value;
1277 }
1278 if ($value->meta_key == '_yoast_wpseo_cornerstone-content') {
1279 self::$export_instance->data[$id]['cornerstone-content'] = $value->meta_value;
1280 }
1281 if ($value->meta_key == '_yoast_wpseo_focuskeywords') {
1282 self::$export_instance->data[$id]['focuskeywords'] = $value->meta_value;
1283 }
1284 if ($value->meta_key == '_yoast_wpseo_keywordsynonyms') {
1285 self::$export_instance->data[$id]['keywordsynonyms'] = $value->meta_value;
1286 }
1287 if ($value->meta_key == '_yoast_wpseo_schema_page_type') {
1288 self::$export_instance->data[$id]['schema_page_type'] = $value->meta_value;
1289 }
1290 if ($value->meta_key == '_yoast_wpseo_schema_article_type') {
1291 self::$export_instance->data[$id]['schema_article_type'] = $value->meta_value;
1292 }
1293 }
1294
1295 return self::$export_instance->data;
1296 }
1297 public function get_jetengine_relation_meta_fields($jet_relation_id, $posted_id, $get_rel_metafields, $get_jet_rel_object_connections, $connection_type, $jet_relmeta_table_name)
1298 {
1299 global $wpdb;
1300 foreach ($get_rel_metafields as $get_rel_metavalue) {
1301 $rel_meta_key = $get_rel_metavalue['name'];
1302
1303 $get_jet_rel_values = [];
1304 foreach ($get_jet_rel_object_connections as $get_jet_rel_object_connection_values) {
1305 if ($connection_type == 'parent') {
1306 $get_jet_rel_value = $wpdb->get_var("SELECT meta_value FROM $jet_relmeta_table_name WHERE rel_id = $jet_relation_id AND meta_key = '$rel_meta_key' AND parent_object_id = $posted_id AND child_object_id = $get_jet_rel_object_connection_values ");
1307 if (is_serialized($get_jet_rel_value)) {
1308 $unser_relvalue = unserialize($get_jet_rel_value);
1309 //Added for export only media id,while media have return format as both[if]
1310 if ($rel_meta_key == 'media') {
1311 if (!empty($unser_relvalue) && array_key_exists('id', $unser_relvalue))
1312 $get_jet_rel_value = $unser_relvalue['id'];
1313 } else
1314 $get_jet_rel_value = implode(',', $unser_relvalue);
1315 }
1316 $get_jet_rel_values[] = $get_jet_rel_value;
1317 } else {
1318 $get_jet_rel_values[] = $wpdb->get_var("SELECT meta_value FROM $jet_relmeta_table_name WHERE rel_id = $jet_relation_id AND meta_key = '$rel_meta_key' AND parent_object_id = $get_jet_rel_object_connection_values AND child_object_id = $posted_id ");
1319 }
1320 }
1321 $get_rel_meta_value = '';
1322 if (!empty($get_jet_rel_values)) {
1323 $get_rel_meta_value = implode('|', $get_jet_rel_values);
1324 }
1325 self::$export_instance->data[$posted_id][$rel_meta_key . ' :: ' . $jet_relation_id] = $get_rel_meta_value;
1326
1327 }
1328 }
1329
1330 public function getAllPodsFields()
1331 {
1332
1333 $pods_fields = [];
1334 if (in_array('pods/init.php', self::$export_instance->get_active_plugins())) {
1335 global $wpdb;
1336 $pods_fields_query_result = $wpdb->get_results("SELECT post_name FROM " . $wpdb->prefix . "posts WHERE post_type = '_pods_field'");
1337 foreach ($pods_fields_query_result as $single_result) {
1338 $pods_fields[] = $single_result->post_name;
1339 }
1340 }
1341 return $pods_fields;
1342 }
1343
1344 public function getCustomFieldValue($id, $value, $checkRep, $allacf, $typeOftypesField, $alltype, $jet_fields, $jetTypes, $jetRepFields, $jet_rep_types, $parent, $typesf, $group_unset, $optionalType, $pods_type, $metabox_fields, $module)
1345 {
1346 global $wpdb;
1347 $taxonomies = get_taxonomies();
1348 $down_file = false;
1349
1350 if ($value !== null && $value->meta_key == '_thumbnail_id') {
1351 $attachment_file = null;
1352 $thumbnail_id = $value->meta_value;
1353 $get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $value->meta_value, 'attachment');
1354 $attachment_file = $wpdb->get_var($get_attachment);
1355 self::$export_instance->data[$id][$value->meta_key] = '';
1356 $value->meta_key = 'featured_image';
1357 self::$export_instance->data[$id][$value->meta_key] = $attachment_file;
1358 if (isset($attachment_file)) {
1359 $attachment = get_post($thumbnail_id);
1360 $image_meta = wp_get_attachment_metadata($thumbnail_id);
1361 $title = get_the_title($thumbnail_id);
1362 $alt_text = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
1363 $description = $attachment->post_content;
1364 $caption = $attachment->post_excerpt;
1365 $file_name = isset($image_meta['file']) ? basename($image_meta['file']) : '';
1366
1367 self::$export_instance->data[$id]['featured_image_title'] = isset($title) ? $title : '';
1368 self::$export_instance->data[$id]['featured_image_alt_text'] = isset($alt_text) ? $alt_text : '';
1369 self::$export_instance->data[$id]['featured_image_caption'] = isset($caption) ? $caption : '';
1370 self::$export_instance->data[$id]['featured_image_description'] = isset($description) ? $description : '';
1371 self::$export_instance->data[$id]['featured_file_name'] = isset($file_name) ? $file_name : '';
1372 }
1373 } else if (is_plugin_active('jet-booking/jet-booking.php')) {
1374
1375 if (isset($value->meta_key) && $value->meta_key == 'jet_abaf_price') {
1376 self::$export_instance->data[$id]['jet_abaf_price'] = $value->meta_value;
1377 } else if (isset($value->meta_key) && $value->meta_key == 'jet_abaf_configuration') {
1378 self::$export_instance->data[$id]['jet_abaf_configuration'] = $value->meta_value;
1379 } else if (isset($value->meta_key) && $value->meta_key == 'jet_abaf_custom_schedule') {
1380 self::$export_instance->data[$id]['jet_abaf_custom_schedule'] = $value->meta_value;
1381 }
1382 } else if (isset($value->meta_key) && $value->meta_key == '_downloadable_files') {
1383
1384 $downfiles = unserialize($value->meta_value);
1385 if (!empty($downfiles)) {
1386 foreach ($downfiles as $dk => $dv) {
1387 $down_file .= $dv['name'] . ',' . $dv['file'] . '|';
1388 }
1389 self::$export_instance->data[$id]['downloadable_files'] = rtrim($down_file, "|");
1390 }
1391 } elseif ($value !== null && $value->meta_key == '_downloadable') {
1392 self::$export_instance->data[$id]['downloadable'] = $value->meta_value;
1393 } elseif ($value !== null && $value->meta_key == '_upsell_ids') {
1394 $upselldata = unserialize($value->meta_value);
1395 if (!empty($upselldata)) {
1396 foreach ($upselldata as $upselldata_value) {
1397 $upselldata_query = $wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts where id = %d", $upselldata_value);
1398 $upselldata_value = $wpdb->get_results($upselldata_query);
1399 $upselldata_item[] = $upselldata_value[0]->post_title;
1400 }
1401 $upsellids = implode(',', $upselldata_item);
1402 self::$export_instance->data[$id]['upsell_ids'] = $upsellids;
1403 }
1404 } elseif ($value !== null && $value->meta_key == '_crosssell_ids') {
1405 $cross_selldata = unserialize($value->meta_value);
1406 if (!empty($cross_selldata)) {
1407 foreach ($cross_selldata as $cross_selldata_value) {
1408 $cross_selldata_query = $wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts where id = %d", $cross_selldata_value);
1409 $cross_selldata_value = $wpdb->get_results($cross_selldata_query);
1410
1411 $cross_selldata_item[] = $cross_selldata_value[0]->post_title;
1412 }
1413 $cross_sellids = implode(',', $cross_selldata_item);
1414 self::$export_instance->data[$id]['crosssell_ids'] = $cross_sellids;
1415 }
1416 } elseif ($value !== null && $value->meta_key == '_wc_pb_bundle_sell_ids') {
1417 $bundleselldata = unserialize($value->meta_value);
1418 if (!empty($bundleselldata) && is_array($bundleselldata)) {
1419 $bundsell = [];
1420 foreach ($bundleselldata as $bundle_id) {
1421 $bundleids = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE post_type = 'product' AND ID = '$bundle_id'");
1422 foreach ($bundleids as $bundid) {
1423 $bundsell[] = $bundid->post_title;
1424 }
1425 }
1426 $value->meta_value = implode(',', $bundsell);
1427 self::$export_instance->data[$id]['_wc_pb_bundle_sell_ids'] = $value->meta_value;
1428 }
1429 } elseif ($value !== null && $value->meta_key == '_children') {
1430 $grpdata = unserialize($value->meta_value);
1431 if (!empty($grpdata)) {
1432 $grpids = implode(',', $grpdata);
1433 self::$export_instance->data[$id]['grouping_product'] = $grpids;
1434 }
1435 } elseif ($value !== null && $value->meta_key == '_product_image_gallery') {
1436 if (strpos($value->meta_value, ',') !== false) {
1437 // $file_data = explode(',',$value->meta_value);
1438 // foreach($file_data as $k => $v){
1439 // $attachment = wp_get_attachment_image_src($v);
1440 // $attach[$k] = $attachment[0];
1441 // }
1442 $file_data = explode(',', $value->meta_value);
1443 foreach ($file_data as $k => $v) {
1444 $attachment = wp_get_attachment_image_src($v);
1445 if ($attachment !== false && is_array($attachment) && isset($attachment[0])) {
1446 $attach[$k] = $attachment[0];
1447 } else {
1448 $attach[$k] = '';
1449 }
1450 }
1451 $gallery_data = '';
1452 foreach ($attach as $values) {
1453 $gallery_data .= $values . '|';
1454 }
1455 $gallery_data = rtrim($gallery_data, '|');
1456 self::$export_instance->data[$id]['product_image_gallery'] = $gallery_data;
1457 } else {
1458 $attachment = wp_get_attachment_image_src($value->meta_value);
1459 self::$export_instance->data[$id]['product_image_gallery'] = $attachment[0];
1460 }
1461 } elseif ($value !== null && $value->meta_key == '_sale_price_dates_from') {
1462 $sales_price_date_from_value = '';
1463 if (!empty($value->meta_value)) {
1464 $sales_price_date_from_value = date('Y-m-d', $value->meta_value);
1465 }
1466 self::$export_instance->data[$id]['sale_price_dates_from'] = $sales_price_date_from_value;
1467 } elseif ($value !== null && $value->meta_key == '_lp_faqs') {
1468 $faqs = $value->meta_value;
1469 $unserialize_faq_value = unserialize($faqs);
1470 $faqs_value = '';
1471 foreach ($unserialize_faq_value as $faq_key => $faq_value) {
1472 $faqs_value .= $faq_value[0] . ',' . $faq_value[1] . '|';
1473 }
1474 self::$export_instance->data[$id][$value->meta_key] = rtrim($faqs_value, '|');
1475 } elseif ($value !== null && $value->meta_key == '_sale_price_dates_to') {
1476 $sales_price_dates_value = '';
1477 if (!empty($value->meta_value)) {
1478 $sales_price_dates_value = date('Y-m-d', $value->meta_value);
1479 }
1480 self::$export_instance->data[$id]['sale_price_dates_to'] = $sales_price_dates_value;
1481 } else {
1482
1483 // commented this if statement
1484 // if(preg_match('/group_/',$value->meta_key)){
1485 // $value->meta_key = preg_replace('/group_/','', $value->meta_key );
1486 // }
1487
1488
1489 if ($value !== null && isset($allacf) && array_search($value->meta_key, $allacf)) {
1490 $repeaterOfrepeater = false;
1491 $getType = $alltype[$value->meta_key];
1492 if (empty($getType)) {
1493 $tempFieldname = array_search($value->meta_key, $allacf);
1494 $getType = $alltype[$tempFieldname];
1495 }
1496
1497 if ($getType == 'flexible_content' || $getType == 'repeater') {
1498 if (is_serialized($value->meta_value)) {
1499 $value->meta_value = unserialize($value->meta_value);
1500 $count = count($value->meta_value);
1501 } else {
1502 $count = $value->meta_value;
1503 }
1504
1505 $getRF = $checkRep[$value->meta_key];
1506 $repeater_data = [];
1507
1508 if ($getType == 'flexible_content') {
1509 $flexible_value = '';
1510 foreach ($value->meta_value as $values) {
1511 $flexible_value .= $values . '|';
1512 }
1513 $flexible_value = rtrim($flexible_value, '|');
1514 self::$export_instance->data[$id][$value->meta_key] = self::$export_instance->returnMetaValueAsCustomerInput($flexible_value);
1515 }
1516
1517 foreach ($getRF as $rep => $rep1) {
1518 $repType = $alltype[$rep1];
1519
1520 $reval = "";
1521 for ($z = 0; $z < $count; $z++) {
1522 $var = $value->meta_key . '_' . $z . '_' . $rep1;
1523
1524 if (in_array($optionalType, $taxonomies)) {
1525 $qry = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}terms wp JOIN {$wpdb->prefix}termmeta wpm ON wpm.term_id = wp.term_id where meta_key = %s AND wp.term_id = %d", $var, $id));
1526 } else {
1527 $qry = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}posts wp JOIN {$wpdb->prefix}postmeta wpm ON wpm.post_id = wp.ID where meta_key = %s AND ID=%d", $var, $id));
1528 }
1529
1530 $meta = $qry[0]->meta_value;
1531 if ($repType == 'image')
1532 $meta = $this->getAttachment($meta);
1533 if ($repType == 'file')
1534 $meta = $this->getAttachment($meta);
1535 if ($repType == 'repeater' || $repType == 'flexible_content')
1536 $meta = $this->getRepeaterofRepeater($value->meta_key);
1537 if (is_serialized($meta)) {
1538 $unmeta = unserialize($meta);
1539 $meta = "";
1540 foreach ($unmeta as $unmeta1) {
1541 if ($repType == 'image' || $repType == 'gallery')
1542 $meta .= $this->getAttachment($unmeta1) . ",";
1543 elseif ($repType == 'taxonomy') {
1544 $meta .= $unmeta1 . ',';
1545 } elseif ($repType == 'user') {
1546 $meta .= $unmeta1 . ',';
1547 } elseif ($repType == 'post_object') {
1548 $meta .= $unmeta1 . ',';
1549 } elseif ($repType == 'relationship') {
1550 $meta .= $unmeta1 . ',';
1551 } elseif ($repType == 'page_link') {
1552 $meta .= $unmeta1 . ',';
1553 } elseif ($repType == 'link') {
1554 $meta .= $unmeta1;
1555 } else
1556 $meta .= $unmeta1 . ",";
1557 }
1558 $meta = rtrim($meta, ',');
1559 }
1560 if ($meta != "")
1561 $reval .= $meta . "|";
1562 }
1563 self::$export_instance->data[$id][$rep1] = self::$export_instance->returnMetaValueAsCustomerInput(rtrim($reval, '|'));
1564 }
1565 } elseif (is_serialized($value->meta_value)) {
1566
1567 $acfva = unserialize($value->meta_value);
1568 $acfdata = "";
1569 foreach ($acfva as $key1 => $value1) {
1570 if ($getType == 'checkbox')
1571 $acfdata .= $value1 . ',';
1572 elseif ($getType == 'gallery' || $getType == 'image') {
1573 $attach = $this->getAttachment($value1);
1574 $acfdata .= $attach . ',';
1575 } elseif ($getType == 'google_map') {
1576 $acfdata = $acfva['address'];
1577 } else {
1578 if (!empty($value1)) {
1579 $acfdata .= $value1 . ',';
1580 }
1581 }
1582
1583 }
1584 self::$export_instance->data[$id][$value->meta_key] = self::$export_instance->returnMetaValueAsCustomerInput(rtrim($acfdata, ','));
1585 } elseif ($getType == 'gallery' || $getType == 'image' || $getType == 'file') {
1586 $attach1 = $this->getAttachment($value->meta_value);
1587 self::$export_instance->data[$id][$value->meta_key] = $attach1;
1588 } else {
1589 self::$export_instance->data[$id][$value->meta_key] = self::$export_instance->returnMetaValueAsCustomerInput($value->meta_value);
1590 }
1591 } elseif (is_array($jet_fields) && in_array($value->meta_key, $jet_fields) && !empty($value->meta_value)) {
1592 $getjetType = isset($jetTypes[$value->meta_key]) ? $jetTypes[$value->meta_key] : '';
1593 if (empty($getjetType)) {
1594 $tempFieldname = array_search($value->meta_key, $jet_fields);
1595 $getjetType = isset($jetTypes[$tempFieldname]) ? $jetTypes[$tempFieldname] : '';
1596 }
1597
1598 if ($getjetType == 'checkbox' && is_string($value->meta_value)) {
1599 $value->meta_value = unserialize($value->meta_value);
1600 $check = '';
1601 foreach ($value->meta_value as $key => $metvalue) {
1602 if (is_numeric($key)) {
1603 $check .= $metvalue . ',';
1604 $rcheck = substr($check, 0, -1);
1605 self::$export_instance->data[$id][$value->meta_key] = $rcheck;
1606 } else {
1607 if ($metvalue == 'true') {
1608
1609 $exp_value[] = $key;
1610 }
1611 if (isset($exp_value) && is_array($exp_value)) {
1612 $value->meta_value = implode(',', $exp_value);
1613 }
1614
1615 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1616 }
1617
1618 }
1619
1620 } elseif ($getjetType == 'select') {
1621 if (is_serialized($value->meta_value)) {
1622 $value->meta_value = unserialize($value->meta_value);
1623 foreach ($value->meta_value as $metkey => $metselectvalue) {
1624 $select[] = $metselectvalue;
1625 $value->meta_value = implode(',', $select);
1626 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1627 }
1628 } else {
1629 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1630 }
1631 } elseif ($getjetType == 'date') {
1632 if (!empty($value->meta_value)) {
1633 if (strpos($value->meta_value, '-') !== FALSE) {
1634 } else {
1635 $value->meta_value = date('Y-m-d', $value->meta_value);
1636 }
1637 }
1638 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1639 } elseif ($getjetType == 'datetime-local') {
1640 if (!empty($value->meta_value)) {
1641 if (strpos($value->meta_value, '-') !== FALSE) {
1642 } else {
1643 $value->meta_value = date('Y-m-d H:i', $value->meta_value);
1644 }
1645 $value->meta_value = str_replace(' ', 'T', $value->meta_value);
1646 }
1647 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1648 } else if (is_object($value) && isset($value->meta_value)) {
1649 $meta_value = $value->meta_value;
1650
1651 // Check if $meta_value is a JSON string
1652 if (is_string($meta_value) && json_decode($meta_value)) {
1653 $meta_value = json_decode($meta_value, true);
1654 }
1655
1656 $is_unserialized = is_array($meta_value);
1657
1658 if ($is_unserialized) {
1659 $output_array = [];
1660
1661 foreach ($meta_value as $key => $val) {
1662 // If the value is an array (like 'week_days'), use '|' as a separator
1663 if (is_array($val)) {
1664 $output_array[] = implode('|', $val); // Use '|' for arrays
1665 } else {
1666 // Otherwise, just add the value as is
1667 $output_array[] = $val;
1668 }
1669 }
1670
1671 // Join values with commas for CSV format
1672 $value_all = implode(',', $output_array);
1673
1674 self::$export_instance->data[$id][$value->meta_key] = $value_all;
1675 }
1676 } else {
1677 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1678 }
1679 } elseif (!empty($typesf) && isset($value->meta_key) && in_array($value->meta_key, $typesf)) {
1680 global $wpdb;
1681 $type_value = '';
1682 $typeoftype = $typeOftypesField[$value->meta_key];
1683 if (in_array($optionalType, $taxonomies)) {
1684 $type_data = get_term_meta($id, $value->meta_key);
1685 } elseif ($optionalType == 'user' || $optionalType == 'users') {
1686 $type_data = get_user_meta($id, $value->meta_key);
1687 } else {
1688 $type_data = get_post_meta($id, $value->meta_key);
1689 $typcap = "";
1690 foreach ($type_data as $type_key => $type_value) {
1691 if (!is_array($type_value)) {
1692 $substring = 'http';
1693 $string = substr($type_value, 0, 4);
1694 if ($string == $substring) {
1695 $getid = $wpdb->get_results("select ID from {$wpdb->prefix}posts where guid= '$type_value'", ARRAY_A);
1696 foreach ($getid as $getkey => $getval) {
1697 global $wpdb;
1698 $ids = $getval['ID'];
1699 $types_caption = $wpdb->get_results("select post_excerpt from {$wpdb->prefix}posts where ID= '$ids'", ARRAY_A);
1700 $types_description = $wpdb->get_results("select post_content from {$wpdb->prefix}posts where ID= '$ids'", ARRAY_A);
1701 $types_title = $wpdb->get_results("select post_title from {$wpdb->prefix}posts where ID= '$ids'", ARRAY_A);
1702 $types_alt_text = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where meta_key= '_wp_attachment_image_alt' AND post_id='$ids'", ARRAY_A);
1703 $types_filename = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where meta_key= '_wp_attached_file' AND post_id='$ids'", ARRAY_A);
1704 if (isset($types_filename[0])) {
1705 $filename = $types_filename[0]['meta_value'];
1706 }
1707 if (isset($filename)) {
1708 $file_names = explode('/', $filename);
1709 }
1710 if (isset($file_names[2])) {
1711 $file_name = $file_names[2];
1712 }
1713 $file_name = isset($file_name) ? $file_name : '';
1714 self::$export_instance->data[$id]['types_caption'] = $types_caption[0]['post_excerpt'];
1715 self::$export_instance->data[$id]['types_description'] = $types_description;
1716 self::$export_instance->data[$id]['types_title'] = $types_title;
1717 self::$export_instance->data[$id]['types_alt_text'] = $types_alt_text;
1718 self::$export_instance->data[$id]['types_file_name'] = $file_name;
1719
1720
1721 }
1722 }
1723
1724 $type_value = rtrim($type_value, '|');
1725
1726 }
1727
1728 }
1729
1730 self::$export_instance->data[$id][$value->meta_key] = $type_value;
1731
1732 }
1733
1734 if (is_array($type_data)) {
1735 $type_value = "";
1736 foreach ($type_data as $k => $mid) {
1737 if (is_array($mid) && !empty($mid)) {
1738 if ($typeoftype == 'skype') {
1739 $type_value .= $mid['skypename'] . '|';
1740 } elseif ($typeoftype == 'checkboxes') {
1741 $check_type_value = '';
1742 foreach ($mid as $mid_value) {
1743 $check_type_value .= $mid_value[0] . ',';
1744 }
1745 $type_value .= rtrim($check_type_value, ',');
1746 }
1747 } elseif ($typeoftype == 'date') {
1748 $wptypesfields = get_option('wpcf-fields');
1749 $fd_name = preg_replace('/wpcf-/', '', $value->meta_key);
1750 if (isset($wptypesfields[$fd_name]['data']['date_and_time'])) {
1751 $format = $wptypesfields[$fd_name]['data']['date_and_time'];
1752 $dateformat = $format == 'date' ? "Y-m-d" : "Y-m-d H:i:s";
1753 if (!empty($mid))
1754 $type_value .= date($dateformat, $mid) . '|';
1755 }
1756 } else {
1757 if (!is_array($mid)) {
1758 $type_value .= $mid . '|';
1759 }
1760 }
1761 }
1762 if (preg_match('/wpcf-/', $value->meta_key)) {
1763 $value->meta_key = preg_replace('/wpcf-/', '', $value->meta_key);
1764 self::$export_instance->data[$id][$value->meta_key] = rtrim($type_value, '|');
1765 }
1766 }
1767
1768 // if(preg_match('/group_/',$value->meta_key)){
1769 // $getType = $alltype[$value->meta_key];
1770 // if($value->meta_key == 'group_gallery' || $value->meta_key == 'group_image'|| $value->meta_key == 'file' ){
1771 // $groupattach = $this->getAttachment($value->meta_value);
1772 // self::$export_instance->data[$id][ $value->meta_key ] = $groupattach;
1773 // }
1774 // else{
1775 // $value->meta_key = preg_replace('/group_/','', $value->meta_key );
1776 // self::$export_instance->data[$id][ $value->meta_key ] = $value->meta_value;
1777 // }
1778 // }
1779
1780 //TYPES Allow multiple-instances of this field
1781 } elseif (!empty($group_unset) && is_array($value) && isset($value['meta_key']) && in_array($value['meta_key'], $group_unset) && is_serialized($value['meta_value'])) {
1782
1783 $unser = unserialize($value->meta_value);
1784 $data = "";
1785 foreach ($unser as $key4 => $value4)
1786 $data .= $value4 . ',';
1787 self::$export_instance->data[$id][$value->meta_key] = substr($data, 0, -1);
1788 } elseif (!empty($pods_type) && in_array($value->meta_key, $pods_type)) {
1789 if (!isset(self::$export_instance->data[$id][$value->meta_key])) {
1790 if (in_array($optionalType, $taxonomies)) {
1791 $pods_file_data = get_term_meta($id, $value->meta_key);
1792 } else {
1793 $pods_file_data = get_post_meta($id, $value->meta_key);
1794 }
1795
1796 $pods_value = '';
1797 foreach ($pods_file_data as $pods_file_value) {
1798 if (!empty($pods_file_value)) {
1799 if (is_array($pods_file_value)) {
1800 $pods_file_value['post_type'] = isset($pods_file_value['post_type']) ? $pods_file_value['post_type'] : '';
1801 $posts_type = $pods_file_value['post_type'];
1802 if ($posts_type == 'attachment') {
1803 $pods_value .= $pods_file_value['guid'] . ',';
1804 } elseif ($posts_type !== 'attachment') {
1805 $pods_file_value['guid'] = isset($pods_file_value['guid']) ? $pods_file_value['guid'] : '';
1806 $p_guid = $pods_file_value['guid'];
1807 $pod_tit = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts where guid='$p_guid'");
1808 if (!empty($pod_tit)) {
1809 foreach ($pod_tit as $pods_title) {
1810 $pods_title_value = $pods_title->post_title;
1811 $pods_value .= $pods_title_value . ',';
1812 }
1813 } else {
1814 $podstaxval = $pods_file_value['name'];
1815 $pods_value .= $podstaxval . ',';
1816 }
1817 }
1818 } else {
1819 $pods_value .= $pods_file_value . ',';
1820 }
1821 }
1822 }
1823 self::$export_instance->data[$id][$value->meta_key] = rtrim($pods_value, ',');
1824 }
1825 } elseif (!empty($metabox_fields) && is_array($metabox_fields) || (is_array($metabox_fields) && array_key_exists($value->meta_key, $metabox_fields))) {
1826 foreach ($metabox_fields as $meta_val) {
1827 if ($meta_val['type'] == 'taxonomy') {
1828 $meta_tax = $meta_val['taxonomy'];
1829
1830 $meta_key = $meta_val['id'];
1831 foreach ($meta_tax as $meta_val) {
1832 $get_metabox_titles[] = $wpdb->get_results("SELECT t.name FROM {$wpdb->prefix}terms t Inner join {$wpdb->prefix}term_taxonomy tax ON t.term_id=tax.term_id INNER JOIN {$wpdb->prefix}term_relationships tr ON tr.term_taxonomy_id=tax.term_taxonomy_id WHERE tr.object_id =$id AND tax.taxonomy ='$meta_val'", ARRAY_A);
1833 }
1834
1835
1836 $titles = array();
1837 if (is_array($get_metabox_titles)) {
1838 foreach ($get_metabox_titles as $title => $value) {
1839 foreach ($value as $valu => $val) {
1840 $titles[] = $val['name'];
1841 }
1842 }
1843 $tax_val = implode('|', $titles);
1844
1845 self::$export_instance->data[$id][$meta_key] = $tax_val;
1846 }
1847 }
1848 }
1849
1850 $get_metabox_fieldtype = $metabox_fields[$value->meta_key]['type'];
1851
1852 if ($get_metabox_fieldtype == 'select' || $get_metabox_fieldtype == 'select_advanced' || $get_metabox_fieldtype == 'checkbox_list' || $get_metabox_fieldtype == 'text_list' || $get_metabox_fieldtype == 'file_advanced') {
1853
1854 $metabox_metakey = $value->meta_key;
1855 if ($module == 'Users') {
1856 $get_metabox_values = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}usermeta WHERE meta_key = '$metabox_metakey' AND user_id = $id ", ARRAY_A);
1857 } else if ($module == 'Categories' || $module == 'Taxonomies' || $module == 'Tags') {
1858 $get_metabox_values = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}termmeta WHERE meta_key = '$metabox_metakey' AND term_id = $id ", ARRAY_A);
1859 } else {
1860 $get_metabox_values = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '$metabox_metakey' AND post_id = $id ", ARRAY_A);
1861 }
1862
1863 $metabox_values = array_column($get_metabox_values, 'meta_value');
1864 if ($get_metabox_fieldtype == 'file_advanced' || $get_metabox_fieldtype == 'image_advanced') {
1865 $get_metabox_file_url = [];
1866 foreach ($metabox_values as $metavalue) {
1867 $get_metabox_file_url[] = $wpdb->get_var("SELECT guid FROM {$wpdb->prefix}posts WHERE ID = $metavalue AND post_type = 'attachment' ");
1868 }
1869
1870 $metabox_file_value = implode(',', $get_metabox_file_url);
1871 self::$export_instance->data[$id][$value->meta_key] = $metabox_file_value;
1872 } else {
1873 $metabox_value = implode(',', $metabox_values);
1874 self::$export_instance->data[$id][$value->meta_key] = $metabox_value;
1875 }
1876 } elseif ($get_metabox_fieldtype == 'fieldset_text') {
1877 $fieldset_values = unserialize($value->meta_value);
1878 $fieldset_value = implode(',', array_values($fieldset_values));
1879 self::$export_instance->data[$id][$value->meta_key] = $fieldset_value;
1880 } elseif ($get_metabox_fieldtype == 'post' || $get_metabox_fieldtype == 'taxonomy' || $get_metabox_fieldtype == 'user') {
1881 if ($get_metabox_fieldtype == 'post') {
1882 $get_metabox_titles = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $value->meta_value ");
1883 } elseif ($get_metabox_fieldtype == 'taxonomy' || $get_metabox_fieldtype == 'taxonomy_advanced') {
1884 $get_metabox_titles = $wpdb->get_var("SELECT name FROM {$wpdb->prefix}terms WHERE term_id = $value->meta_value ");
1885 } elseif ($get_metabox_fieldtype == 'user') {
1886 $get_metabox_titles = $wpdb->get_var("SELECT user_login FROM {$wpdb->prefix}users WHERE ID = $value->meta_value ");
1887 }
1888 self::$export_instance->data[$id][$value->meta_key] = $get_metabox_titles;
1889 } elseif ($get_metabox_fieldtype == 'image' || $get_metabox_fieldtype == 'file') {
1890 $upload_values = $value->meta_value;
1891 $upload_value = $wpdb->get_var("SELECT guid FROM {$wpdb->prefix}posts WHERE ID = $upload_values AND post_type = 'attachment' ");
1892 self::$export_instance->data[$id][$value->meta_key] = $upload_value;
1893 } else {
1894 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1895 }
1896 } else {
1897 self::$export_instance->data[$id][$value->meta_key] = $value->meta_value;
1898 }
1899
1900
1901 }
1902 }
1903
1904 public function getRepeater($parent)
1905 {
1906 global $wpdb;
1907
1908 $get_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts where post_parent = %d", $parent), ARRAY_A);
1909 $i = 0;
1910 foreach ($get_fields as $key => $value) {
1911 $array[$i] = $value['post_excerpt'];
1912 $i++;
1913 }
1914
1915 return $array;
1916 }
1917
1918 public function getRepeaterofRepeater($parent)
1919 {
1920 global $wpdb;
1921 $get_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts where post_parent = %d", $parent), ARRAY_A);
1922 $test = $get_fields[0]->ID;
1923 $get_fieldss = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts where post_parent = %d", $test), ARRAY_A);
1924 $i = 0;
1925 foreach ($get_fieldss as $key => $value) {
1926 $array[$i] = $value['post_excerpt'];
1927 $i++;
1928 }
1929
1930 return $array;
1931 }
1932
1933
1934
1935 /**
1936 * Fetch all Categories
1937 * @param $mode
1938 * @param $module
1939 * @param $optionalType
1940 * @return array
1941 */
1942 public function FetchCategories($module, $optionalType, $mode = null)
1943 {
1944 $headers = self::$export_instance->generateHeaders($module, $optionalType);
1945 global $wpdb;
1946 // $get_all_terms = get_categories('hide_empty=0');
1947 // self::$export_instance->totalRowCount = count($get_all_terms);
1948 $query = "SELECT * FROM {$wpdb->prefix}terms t INNER JOIN {$wpdb->prefix}term_taxonomy tax
1949 ON `tax`.term_id = `t`.term_id WHERE `tax`.taxonomy = 'category'";
1950 $get_all_taxonomies = $wpdb->get_results($query);
1951 self::$export_instance->totalRowCount = count($get_all_taxonomies);
1952 $offset = self::$export_instance->offset;
1953 $limit = self::$export_instance->limit;
1954
1955
1956 $query = "SELECT term_id FROM {$wpdb->prefix}term_taxonomy where taxonomy='category'";
1957
1958 $offset_limit = " order by term_id asc limit $offset, $limit";
1959 $query_with_offset_limit = $query . $offset_limit;
1960
1961 $result = $wpdb->get_col($query_with_offset_limit);
1962 $query1 = array();
1963 foreach ($result as $res => $re) {
1964 $query1[] = $wpdb->get_results(" SELECT t.name, t.slug, tx.description, tx.parent, t.term_id FROM {$wpdb->prefix}terms as t join {$wpdb->prefix}term_taxonomy as tx on t.term_id = tx.term_id where t.term_id = '$re'");
1965 }
1966 $new = array();
1967 foreach ($query1 as $qkey => $qval) {
1968 foreach ($qval as $qid) {
1969 $new[] = $qid;
1970 }
1971
1972 }
1973 if (!empty($new)) {
1974 foreach ($new as $termKey => $termValue) {
1975 $termID = $termValue->term_id;
1976 $termName = $termValue->name;
1977 $termSlug = $termValue->slug;
1978 $termDesc = $termValue->description;
1979 $termParent = $termValue->parent;
1980 if ($termParent == 0) {
1981 self::$export_instance->data[$termID]['name'] = $termName;
1982 } else {
1983 $termParentName = get_cat_name($termParent);
1984 self::$export_instance->data[$termID]['name'] = $termParentName . '|' . $termName;
1985 }
1986 self::$export_instance->data[$termID]['slug'] = $termSlug;
1987 self::$export_instance->data[$termID]['description'] = $termDesc;
1988 self::$export_instance->data[$termID]['parent'] = $termParent;
1989 self::$export_instance->data[$termID]['TERMID'] = $termID;
1990
1991 self::$export_instance->getWPMLData($termID, $optionalType, $module);
1992 if (is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')) {
1993 self::$export_instance->getPolylangData($termID, $optionalType, $module);
1994 }
1995 $this->getPostsMetaDataBasedOnRecordId($termID, $module, $optionalType);
1996
1997 if (in_array('wordpress-seo/wp-seo.php', self::$export_instance->get_active_plugins())) {
1998 $seo_yoast_taxonomies = get_option('wpseo_taxonomy_meta');
1999 if (isset($seo_yoast_taxonomies['category'])) {
2000
2001 self::$export_instance->data[$termID]['title'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_title'];
2002 self::$export_instance->data[$termID]['meta_desc'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_desc'];
2003 self::$export_instance->data[$termID]['canonical'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_canonical'];
2004 self::$export_instance->data[$termID]['bctitle'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_bctitle'];
2005 self::$export_instance->data[$termID]['meta-robots-noindex'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_noindex'];
2006 self::$export_instance->data[$termID]['sitemap-include'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_sitemap_include'];
2007 self::$export_instance->data[$termID]['opengraph-title'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_opengraph-title'];
2008 self::$export_instance->data[$termID]['opengraph-description'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_opengraph-description'];
2009 self::$export_instance->data[$termID]['opengraph-image'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_opengraph-image'];
2010 self::$export_instance->data[$termID]['twitter-title'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_twitter-title'];
2011 self::$export_instance->data[$termID]['twitter-description'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_twitter-description'];
2012 self::$export_instance->data[$termID]['twitter-image'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_twitter-image'];
2013 self::$export_instance->data[$termID]['focus_keyword'] = $seo_yoast_taxonomies['category'][$termID]['wpseo_focuskw'];
2014
2015 }
2016 }
2017 }
2018 }
2019 $result = self::$export_instance->finalDataToExport(self::$export_instance->data, $module);
2020
2021 if ($mode == null) {
2022 self::$export_instance->proceedExport($result);
2023 } else {
2024 return $result;
2025 }
2026 }
2027
2028
2029 public function get_common_post_metadata($meta_id)
2030 {
2031 global $wpdb;
2032 $mdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id), ARRAY_A);
2033 return $mdata[0];
2034 }
2035
2036 public function getAttachment($id)
2037 {
2038 global $wpdb;
2039 $get_attachment = $wpdb->prepare("select guid from $wpdb->posts where ID = %d AND post_type = %s", $id, 'attachment');
2040 $attachment = $wpdb->get_results($get_attachment);
2041 if (!empty($attachment) && is_array($attachment)) {
2042 if (isset($attachment[0]->guid)) {
2043 $attachment_file = $attachment[0]->guid;
2044 return $attachment_file;
2045 }
2046 }
2047 return null;
2048 }
2049
2050 /**
2051 * Fetch all Tags
2052 * @param $mode
2053 * @param $module
2054 * @param $optionalType
2055 * @return array
2056 */
2057 public function FetchTags($module, $optionalType, $mode = null)
2058 {
2059 global $wpdb;
2060 self::$export_instance->generateHeaders($module, $optionalType);
2061 // $get_all_terms = get_tags('hide_empty=0');
2062
2063 // self::$export_instance->totalRowCount = count($get_all_terms);
2064 $query = "SELECT * FROM {$wpdb->prefix}terms t INNER JOIN {$wpdb->prefix}term_taxonomy tax
2065 ON `tax`.term_id = `t`.term_id WHERE `tax`.taxonomy = 'post_tag'";
2066 $get_all_taxonomies = $wpdb->get_results($query);
2067 self::$export_instance->totalRowCount = count($get_all_taxonomies);
2068 $offset = self::$export_instance->offset;
2069 $limit = self::$export_instance->limit;
2070
2071 $query = "SELECT term_id FROM {$wpdb->prefix}term_taxonomy where taxonomy='post_tag'";
2072
2073 $offset_limit = " order by term_id asc limit $offset, $limit";
2074 $query_with_offset_limit = $query . $offset_limit;
2075
2076 $result = $wpdb->get_col($query_with_offset_limit);
2077 $query1 = array();
2078 foreach ($result as $res => $id) {
2079 $query1[] = $wpdb->get_results(" SELECT t.name, t.slug, tx.description, tx.parent, t.term_id FROM {$wpdb->prefix}terms as t join {$wpdb->prefix}term_taxonomy as tx on t.term_id = tx.term_id where t.term_id = '$id'");
2080 }
2081 $new = array();
2082 foreach ($query1 as $qkey => $qval) {
2083 foreach ($qval as $qid) {
2084 $new[] = $qid;
2085 }
2086
2087 }
2088 if (!empty($new)) {
2089 foreach ($new as $termKey => $termValue) {
2090 $termID = $termValue->term_id;
2091 $termName = $termValue->name;
2092 $termSlug = $termValue->slug;
2093 $termDesc = $termValue->description;
2094 self::$export_instance->data[$termID]['name'] = $termName;
2095 self::$export_instance->data[$termID]['slug'] = $termSlug;
2096 self::$export_instance->data[$termID]['description'] = $termDesc;
2097
2098 $this->getPostsMetaDataBasedOnRecordId($termID, $module, $optionalType);
2099 self::$export_instance->getWPMLData($termID, $optionalType, $module);
2100 if (is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')) {
2101 self::$export_instance->getPolylangData($termID, $optionalType, $module);
2102 }
2103 if (in_array('wordpress-seo/wp-seo.php', self::$export_instance->get_active_plugins())) {
2104 $seo_yoast_taxonomies = get_option('wpseo_taxonomy_meta');
2105 if (isset($seo_yoast_taxonomies['post_tag'])) {
2106
2107 self::$export_instance->data[$termID]['title'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_title'];
2108 self::$export_instance->data[$termID]['meta_desc'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_desc'];
2109 self::$export_instance->data[$termID]['canonical'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_canonical'];
2110 self::$export_instance->data[$termID]['bctitle'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_bctitle'];
2111 self::$export_instance->data[$termID]['meta-robots-noindex'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_noindex'];
2112 self::$export_instance->data[$termID]['sitemap-include'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_sitemap_include'];
2113 self::$export_instance->data[$termID]['opengraph-title'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_opengraph-title'];
2114 self::$export_instance->data[$termID]['opengraph-description'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_opengraph-description'];
2115 self::$export_instance->data[$termID]['opengraph-image'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_opengraph-image'];
2116 self::$export_instance->data[$termID]['twitter-title'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_twitter-title'];
2117 self::$export_instance->data[$termID]['twitter-description'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_twitter-description'];
2118 self::$export_instance->data[$termID]['twitter-image'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_twitter-image'];
2119 self::$export_instance->data[$termID]['focus_keyword'] = $seo_yoast_taxonomies['post_tag'][$termID]['wpseo_focuskw'];
2120
2121 }
2122 }
2123 }
2124 }
2125
2126 $result = self::$export_instance->finalDataToExport(self::$export_instance->data, $module);
2127 if ($mode == null)
2128 self::$export_instance->proceedExport($result);
2129 else
2130 return $result;
2131 }
2132
2133 /**
2134 * Check if EDD 3.0+ is active (uses custom order tables)
2135 *
2136 * @return bool True if EDD 3.0+, false otherwise
2137 */
2138 private function is_edd_3_0_plus()
2139 {
2140 if (!class_exists('Easy_Digital_Downloads')) {
2141 return false;
2142 }
2143
2144 // Check for EDD 3.0+ Order class
2145 if (class_exists('\\EDD\\Orders\\Order')) {
2146 return true;
2147 }
2148
2149 // Check for Order_Query class
2150 if (class_exists('\\EDD\\Orders\\Order_Query')) {
2151 return true;
2152 }
2153
2154 // Check version if function exists
2155 if (function_exists('edd_get_version')) {
2156 $version = edd_get_version();
2157 if ($version && version_compare($version, '3.0', '>=')) {
2158 return true;
2159 }
2160 }
2161
2162 return false;
2163 }
2164 }
2165
2166 global $post_export_class;
2167 $post_export_class = new PostExport();
2168