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

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

3,598 lines 120.2 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')) exit; // Exit if accessed directly
11 $parent_autoload_path = WP_PLUGIN_DIR . '/wp-ultimate-csv-importer/vendor/autoload.php';
12 if (file_exists($parent_autoload_path)) {
13 require_once $parent_autoload_path;
14 }
15 use PhpOffice\PhpSpreadsheet\Spreadsheet;
16 use PhpOffice\PhpSpreadsheet\IOFactory;
17 if (class_exists('\Smackcoders\FCSV\MappingExtension'))
18 {
19
20 class ExportExtension extends \Smackcoders\FCSV\MappingExtension
21 {
22 public $allacf;
23
24 public $allpodsfields;
25
26 public $alltoolsetfields;
27
28 public $typeOftypesField;
29 public $offset=0;
30 public $checkSplit;
31 public $mode;
32 public $totalRowCount;
33 public $response = array();
34 public $headers = array();
35 public $module;
36 public $exportType = 'csv';
37 public $optionalType = null;
38 public $conditions = array();
39 public $eventExclusions = array();
40 public $fileName;
41 public $data = array();
42 public $heading = true;
43 public $delimiter = ',';
44 public $enclosure = '"';
45 public $auto_preferred = ",;\t.:|";
46 public $output_delimiter = ',';
47 public $linefeed = "\r\n";
48 public $export_mode;
49 public $export_log = array();
50 public $limit;
51 protected static $instance = null, $mapping_instance, $metabox_export, $jet_reviews_export, $jet_book_export, $jetengine_export, $export_handler, $post_export, $woocom_export, $review_export, $ecom_export, $learnpress_export;
52 protected $plugin, $activateCrm, $crmFunctionInstance;
53 public $plugisnScreenHookSuffix = null;
54 public $random_data = '';
55
56 public static function getInstance()
57 {
58 if (null == self::$instance)
59 {
60 self::$instance = new self;
61 ExportExtension::$export_handler = ExportHandler::getInstance();
62 ExportExtension::$post_export = PostExport::getInstance();
63 ExportExtension::$woocom_export = WooCommerceExport::getInstance();
64 ExportExtension::$review_export = CustomerReviewExport::getInstance();
65 ExportExtension::$learnpress_export = LearnPressExport::getInstance();
66 ExportExtension::$jetengine_export = JetEngineExport::getInstance();
67 ExportExtension::$jet_book_export = JetBookingExport::getInstance();
68 ExportExtension::$jet_reviews_export = JetReviewsExport::getInstance();
69 ExportExtension::$metabox_export = metabox::getInstance();
70 self::$instance->doHooks();
71 }
72 return self::$instance;
73 }
74
75 public function doHooks()
76 {
77 $plugin_pages = ['com.smackcoders.csvimporternew.menu'];
78 require_once WP_PLUGIN_DIR . '/wp-ultimate-exporter/wp-exp-hooks.php';
79 global $plugin_ajax_hooks;
80
81 $request_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
82 $request_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
83 if (in_array($request_page, $plugin_pages) || in_array($request_action, $plugin_ajax_hooks))
84 {
85 add_action('wp_ajax_parse_data', array(
86 $this,
87 'parseData'
88 ));
89 add_action('wp_ajax_total_records', array(
90 $this,
91 'totalRecords'
92 ));
93 add_action('wp_ajax_get_download', array(
94 $this,
95 'downloadFunction'
96 ));
97 }
98 }
99
100 public function downloadFunction(){
101
102 check_ajax_referer('smack-ultimate-csv-importer', 'securekey');
103
104 //Vulnerability fix - Arbitrary file download
105 if (!is_user_logged_in() || !current_user_can('administrator')) {
106 wp_die('You do not have sufficient permissions to access this file.');
107 }
108
109 $file_name = sanitize_file_name($_POST['fileName'] ?? '');
110 $file_path = $_POST['filePath'] ?? '';
111 $random_folder = wp_generate_password(16, false); // 16-character random folder name
112
113 $allowed_directory = wp_upload_dir()['basedir'] . '/smack_uci_uploads/exports/'; // Example allowed directory
114
115 $real_file_path = realpath($file_path);
116 $real_allowed_directory = realpath($allowed_directory);
117
118 if (strpos($real_file_path, $real_allowed_directory) !== 0) {
119 wp_die('Invalid file path or file not found.', 'Error', ['response' => 400]);
120 }
121
122 header('Content-Description: File Transfer');
123 header('Content-Type: application/octet-stream');
124 header('Content-Disposition: attachment; filename="' . $file_name . '"');
125 header('Content-Transfer-Encoding: binary');
126 header('Expires: 0');
127 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
128 header('Pragma: public');
129 header('Content-Length: ' . filesize($real_file_path));
130 ob_clean();
131 flush();
132 readfile($real_file_path);
133 wp_die();
134
135 }
136
137 public function totalRecords()
138 {
139
140 check_ajax_referer('smack-ultimate-csv-importer', 'securekey');
141 global $wpdb;
142 $module = sanitize_text_field($_POST['module']);
143
144 $optionalType = isset($_POST['optionalType']) ? sanitize_text_field($_POST['optionalType']) : '';
145 if ($module == 'WooCommerceOrders')
146 {
147 $module = 'shop_order';
148 }
149 elseif ($module == 'WooCommerceCoupons')
150 {
151 $module = 'shop_coupon';
152 }
153 elseif ($module == 'WooCommerceRefunds')
154 {
155 $module = 'shop_order_refund';
156 }
157 elseif ($module == 'WooCommerceVariations')
158 {
159 $module = 'product_variation';
160 }
161 elseif ($module == 'WPeCommerceCoupons')
162 {
163 $module = 'wpsc-coupon';
164 }
165 elseif ($module == 'Users')
166 {
167 $get_available_user_ids = "select DISTINCT ID from $wpdb->users u join $wpdb->usermeta um on um.user_id = u.ID";
168 $availableUsers = $wpdb->get_col($get_available_user_ids);
169 $total = count($availableUsers);
170 return $total;
171 }
172 elseif ($module == 'Tags')
173 {
174 $get_all_terms = get_tags('hide_empty=0');
175 return count($get_all_terms);
176 wp_die();
177 }
178 elseif ($module == 'Categories')
179 {
180 $get_all_terms = get_categories('hide_empty=0');
181 return count($get_all_terms);
182 wp_die();
183 }
184 elseif ($module == 'CustomPosts' && $optionalType == 'nav_menu_item')
185 {
186 $get_menu_ids = $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);
187 echo wp_json_encode(count($get_menu_ids));
188 wp_die();
189 }
190 // elseif($module == 'CustomPosts' && $optionalType == 'widgets'){
191 // echo wp_json_encode(1);
192 // wp_die();
193 // }
194 else
195 {
196 $optional_type = NULL;
197 if ($module == 'CustomPosts')
198 {
199 $optional_type = $optionalType;
200 }
201 $module = ExportExtension::$post_export->import_post_types($module, $optional_type);
202 }
203 // JetBooking module logic
204 if ($module == 'JetBooking') {
205 if (!is_plugin_active('jet-booking/jet-booking.php')) {
206 echo wp_json_encode(0); // Return 0 if JetBooking plugin is not active
207 wp_die();
208 }
209
210 // Get JetBooking bookings count
211 $result = jet_abaf_get_bookings(['return' => 'arrays']);
212 $total = $result ? count($result) : 0; // Count bookings or return 0
213 echo wp_json_encode($total);
214 wp_die();
215 }
216
217 // WooCommerceCustomer module logic
218 if ($module == 'WooCommerceCustomer') {
219 $user_count = count_users();
220 $result = isset($user_count['avail_roles']['customer']) ? $user_count['avail_roles']['customer'] : 0;
221 $total = $result;
222 echo wp_json_encode($total);
223 wp_die();
224 }
225
226 elseif ($module == 'JetReviews') {
227 global $wpdb;
228
229 // Verify if the JetReviews plugin is active
230 if (!is_plugin_active('jet-reviews/jet-reviews.php')) {
231 echo wp_json_encode(0);
232 wp_die();
233 }
234
235 // Query to count approved reviews
236 $query = "SELECT COUNT(*) FROM {$wpdb->prefix}jet_reviews";
237 $count = $wpdb->get_var($query);
238
239 // Ensure count is an integer and return the result
240 $count = ($count !== null) ? intval($count) : 0;
241 echo wp_json_encode($count);
242 wp_die();
243 }
244
245 if(is_plugin_active('jet-engine/jet-engine.php')){
246 $get_slug_name = $wpdb->get_results("SELECT slug FROM {$wpdb->prefix}jet_post_types WHERE status = 'content-type'");
247 foreach($get_slug_name as $key=>$get_slug){
248 $value=$get_slug->slug;
249 $optional_type=$value;
250 if($optionalType == $optional_type){
251 $table_name='jet_cct_'.$optional_type;
252 $get_menu= $wpdb->get_results("SELECT * FROM {$wpdb->prefix}$table_name");
253 if(is_array($get_menu))
254 $total = count($get_menu);
255 else
256 $total = 0;
257 echo wp_json_encode($total);
258 wp_die();
259 }
260 }
261 }
262 $get_post_ids = "select DISTINCT ID from $wpdb->posts";
263 $get_post_ids .= " where post_type = '$module'";
264
265 /**
266 * Check for specific status
267 */
268 if($module == 'product' && is_plugin_active('woocommerce/woocommerce.php')){
269 if(is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')){
270 //TODO temporary fix
271 //wc_get_products only exports default language product
272 $products = "select DISTINCT ID from {$wpdb->prefix}posts";
273 $products .= " where post_type = '$module'";
274 $products .= "and post_status in ('publish','draft','future','private','pending') ";
275 $products = $wpdb->get_col($products);
276
277 }
278 else{
279 $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
280 $products = wc_get_products(array('status' => $product_statuses , 'limit' => -1));
281 }
282 $total = count($products);
283 return $total;
284
285 }
286 elseif($module == 'shop_order'){
287 if( is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')){
288 $order_statuses = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
289 $orders_id = wc_get_orders(array('status' => $order_statuses , 'limit' => -1));
290 $get_post_ids = array();
291 foreach($orders_id as $my_orders){
292 $get_post_ids[] = $my_orders->get_id();
293 }
294 foreach($get_post_ids as $ids){
295 $module =$wpdb->get_var("SELECT post_type FROM {$wpdb->prefix}posts where id=$ids");
296 }
297 if($module == 'shop_order_placehold'){
298 $orders = "select DISTINCT p.ID from {$wpdb->prefix}posts as p inner join {$wpdb->prefix}wc_orders as wc ON p.ID=wc.id";
299 $orders.= " where p.post_type = '$module'";
300 $orders .= "and wc.status in ('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending')";
301 $orders = $wpdb->get_col($orders);
302 }
303 else{
304 $orders = "select DISTINCT ID from {$wpdb->prefix}posts";
305 $orders.= " where post_type = '$module'";
306 $orders .= "and post_status in ('wc-completed','wc-cancelled','wc-on-hold','wc-processing','wc-pending')";
307 $orders = $wpdb->get_col($orders);
308 }
309
310 }
311 else{
312 $order_statuses = array('wc-completed', 'wc-cancelled', 'wc-on-hold', 'wc-processing', 'wc-pending');
313 $orders = wc_get_orders(array('status' => $order_statuses , 'limit' => -1));
314 }
315 $total = count($orders);
316 return $total;
317
318 }
319 elseif($module == 'product_variation'){
320 if(is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')){
321 $extracted_ids = "select DISTINCT ID from {$wpdb->prefix}posts";
322 $extracted_ids .= " where post_type = '$module'";
323 $extracted_ids .= "and post_status in ('publish','draft','future','private','pending') AND post_parent !=0";
324 $extracted_id = $wpdb->get_col($extracted_ids);
325 $extracted_ids =array();
326 //fix added for prema
327 foreach($extracted_id as $ids){
328 $parent_id = $wpdb->get_var("SELECT post_parent FROM {$wpdb->prefix}posts where ID=$ids");
329 $post_status =$wpdb->get_var("SELECT post_status FROM {$wpdb->prefix}posts where ID=$parent_id");
330 if(!empty($post_status )){
331 if($post_status !='trash' && $post_status != 'inherit'){
332 $extracted_ids [] =$ids;
333 }
334
335 }
336
337 }
338
339 }
340 else{
341 $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
342 $products = wc_get_products(array('status' => $product_statuses , 'limit' => -1));
343 $variable_product_ids = [];
344 foreach($products as $product){
345 if ($product->is_type('variable')) {
346 $variable_product_ids[] = $product->get_id();
347 }
348 }
349 $variation_count = 0;
350 $variation_ids = array();
351 foreach($variable_product_ids as $variable_product_id){
352 $variable_product = wc_get_product($variable_product_id);
353 $variation_ids[] = $variable_product->get_children();
354 }
355 $extracted_ids = [];
356 foreach ($variation_ids as $v_ids) {
357 foreach ($v_ids as $v_id) {
358 $extracted_ids[] = $v_id;
359 }
360 }
361 }
362
363 // $product_statuses = array('publish', 'draft', 'future', 'private', 'pending');
364 // $products = wc_get_products(array('status' => $product_statuses));
365 // $variable_product_ids = [];
366 // foreach($products as $product){
367 // if ($product->is_type('variable')) {
368 // $variable_product_ids[] = $product->get_id();
369 // }
370 // }
371 // $variation_count = 0;
372 // foreach($variable_product_ids as $variable_product_id){
373 // $variations = wc_get_products(array('parent_id' => $variable_product_id,'type' => 'variation','limit'=> -1));
374 // $variation_count += count($variations);
375 // }
376 // $total = $variation_count;
377 $total=count($extracted_ids);
378 return $total;
379 }
380 elseif ($module == 'shop_coupon')
381 {
382 $get_post_ids .= " and post_status in ('publish','draft','pending')";
383
384 }
385 elseif ($module == 'shop_order_refund')
386 {
387
388 }
389 elseif ($module == 'forum')
390 {
391 $get_post_ids .= " and post_status in ('publish','draft','future','private','pending','hidden')";
392 }
393 elseif ($module == 'topic')
394 {
395 $get_post_ids .= " and post_status in ('publish','draft','future','open','pending','closed','spam')";
396 }
397 elseif ($module == 'reply')
398 {
399 $get_post_ids .= " and post_status in ('publish','spam','pending')";
400 }
401 $get_post_ids .= " and post_status in ('publish','draft','future','private','pending')";
402 $get_total_row_count = $wpdb->get_col($get_post_ids);
403 $total = count($get_total_row_count);
404 return $total;
405 }
406
407 /**
408 * ExportExtension constructor.
409 * Set values into global variables based on post value
410 */
411 public function __construct()
412 {
413 $this->plugin = Plugin::getInstance();
414 }
415
416 public function parseData()
417 {
418 check_ajax_referer('smack-ultimate-csv-importer', 'securekey');
419 if (!empty($_POST))
420 {
421
422 $this->module = sanitize_text_field($_POST['module']);
423 $this->random_data = sanitize_text_field($_POST['random_data']);
424 //Whitelist of allowed export types
425 $allowed_export_types = ['csv', 'xls', 'xlsx', 'json', 'xml'];
426 // Sanitize and validate the export type
427 $export_type = isset($_POST['exp_type']) ? sanitize_text_field($_POST['exp_type']) : 'csv';
428 $this->exportType = in_array($export_type, $allowed_export_types) ? $export_type : 'csv';
429 $conditions = str_replace("\\", '', sanitize_text_field($_POST['conditions']));
430 $conditions = json_decode($conditions, True);
431 $conditions['specific_period']['to'] = date("Y-m-d", strtotime($conditions['specific_period']['to']));
432 $conditions['specific_period']['from'] = date("Y-m-d", strtotime($conditions['specific_period']['from']));
433 $this->conditions = isset($conditions) && !empty($conditions) ? $conditions : array();
434 if ($this->module == 'Taxonomies' || $this->module == 'CustomPosts')
435 {
436 $this->optionalType = sanitize_text_field($_POST['optionalType']);
437 }
438 else
439 {
440 $this->optionalType = $this->getOptionalType($this->module);
441 }
442 $eventExclusions = str_replace("\\", '', sanitize_text_field(isset($_POST['eventExclusions']) ? sanitize_text_field($_POST['eventExclusions']) : ''));
443 $eventExclusions = json_decode($eventExclusions, True);
444 $this->eventExclusions = isset($eventExclusions) && !empty($eventExclusions) ? $eventExclusions : array();
445 $this->fileName = isset($_POST['fileName']) ? sanitize_text_field($_POST['fileName']) : '';
446 if (empty($_POST['offset']) || sanitize_text_field($_POST['offset']) == 'undefined')
447 {
448 $this->offset = 0;
449 }
450 else
451 {
452 $this->offset = isset($_POST['offset']) ? sanitize_text_field($_POST['offset']) : 0;
453 }
454 if (!empty($_POST['limit']))
455 {
456 $this->limit = isset($_POST['limit']) ? sanitize_text_field($_POST['limit']) : 1000;
457 }
458 else
459 {
460 $this->limit = 50;
461 }
462 if (!empty($this->conditions['delimiter']['optional_delimiter']))
463 {
464 $this->delimiter = $this->conditions['delimiter']['optional_delimiter'] ? $this->conditions['delimiter']['optional_delimiter'] : ',';
465 }
466 elseif (!empty($this->conditions['delimiter']['delimiter']))
467 {
468 $this->delimiter = $this->conditions['delimiter']['delimiter'] ? $this->conditions['delimiter']['delimiter'] : ',';
469 if ($this->delimiter == '{Tab}')
470 {
471 $this->delimiter = " ";
472 }
473 elseif ($this->delimiter == '{Space}')
474 {
475 $this->delimiter = " ";
476 }
477 }
478
479 $this->export_mode = 'normal';
480 $this->checkSplit = isset($_POST['is_check_split']) ? sanitize_text_field($_POST['is_check_split']) : 'false';
481 $this->exportData();
482 }
483 }
484
485 public function commentsCount($mode = null)
486 {
487 global $wpdb;
488 self::generateHeaders($this->module, $this->optionalType);
489 $get_comments = "select * from {$wpdb->prefix}comments";
490 // Check status
491 if ($this->conditions['specific_status']['is_check'] == 'true')
492 {
493 if ($this->conditions['specific_status']['status'] == 'Pending') $get_comments .= " where comment_approved = '0'";
494 elseif ($this->conditions['specific_status']['status'] == 'Approved') $get_comments .= " where comment_approved = '1'";
495 else $get_comments .= " where comment_approved in ('0','1')";
496 }
497 else $get_comments .= " where comment_approved in ('0','1')";
498 // Check for specific period
499 if ($this->conditions['specific_period']['is_check'] == 'true')
500 {
501 if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to'])
502 {
503 $get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "'";
504 }
505 else
506 {
507 $get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "' and comment_date <= '" . $this->conditions['specific_period']['to'] . "'";
508 }
509 }
510 // Check for specific authors
511 if ($this->conditions['specific_authors']['is_check'] == '1')
512 {
513 if (isset($this->conditions['specific_authors']['author']))
514 {
515 $get_comments .= " and comment_author_email = '" . $this->conditions['specific_authors']['author'] . "'";
516 }
517 }
518 $get_comments .= " order by comment_ID";
519 $comments = $wpdb->get_results($get_comments);
520 $totalRowCount = count($comments);
521 return $totalRowCount;
522 }
523
524 public function getOptionalType($module)
525 {
526 if ($module == 'Tags')
527 {
528 $optionalType = 'post_tag';
529 }
530 elseif ($module == 'Posts')
531 {
532 $optionalType = 'posts';
533 }
534 elseif ($module == 'Pages')
535 {
536 $optionalType = 'pages';
537 }
538 elseif ($module == 'Categories')
539 {
540 $optionalType = 'category';
541 }
542 elseif ($module == 'Users')
543 {
544 $optionalType = 'users';
545 }
546 elseif ($module == 'Comments')
547 {
548 $optionalType = 'comments';
549 }
550 elseif($module == 'JetBooking'){
551 $optionalType = 'JetBooking';
552 }
553 elseif ($module == 'CustomerReviews')
554 {
555 $optionalType = 'wpcr3_review';
556 }
557 elseif ($module == 'WooCommerce' || $module == 'WooCommerceOrders' || $module == 'WooCommerceCoupons' || $module == 'WooCommerceRefunds' || $module == 'WooCommerceVariations')
558 {
559 $optionalType = 'product';
560 }
561 elseif ($module == 'WooCommerce')
562 {
563 $optionalType = 'product';
564 }
565 elseif ($module == 'WooCommerceCustomer')
566 {
567 $optionalType = 'users';
568 }
569 elseif ($module == 'WPeCommerce')
570 {
571 $optionalType = 'wpsc-product';
572 }
573 elseif($module == 'JetReviews'){
574 $optionalType = 'JetReviews';
575 }
576 elseif ($module == 'WPeCommerce' || $module == 'WPeCommerceCoupons')
577 {
578 $optionalType = 'wpsc-product';
579 }
580 return $optionalType;
581 }
582
583 /**
584 * set the delimiter
585 */
586 public function setDelimiter($conditions)
587 {
588 if (isset($conditions['optional_delimiter']) && $conditions['optional_delimiter'] != '')
589 {
590 return $conditions['optional_delimiter'];
591 }
592 elseif (isset($conditions['delimiter']) && $conditions['delimiter'] != 'Select')
593 {
594 if ($conditions['delimiter'] == '{Tab}') return "\t";
595 elseif ($conditions['delimiter'] == '{Space}') return " ";
596 else return $conditions['delimiter'];
597 }
598 else
599 {
600 return ',';
601 }
602 }
603
604 /**
605 * Export records based on the requested module
606 */
607 public function exportData()
608 {
609 $this->mode = isset($this->mode) ? $this->mode : '';
610 switch ($this->module)
611 {
612 case 'Posts':
613 case 'Pages':
614 case 'CustomPosts':
615 case 'WooCommerce':
616 case 'WooCommerceVariations':
617 case 'WooCommerceOrders':
618 case 'WooCommerceCoupons':
619 case 'WooCommerceRefunds':
620 case 'WPeCommerce':
621 case 'WPeCommerceCoupons':
622 self::FetchDataByPostTypes();
623 break;
624 case 'Users':
625 case 'WooCommerceCustomer':
626 self::FetchUsers($this->module, $this->optionalType, $this->conditions, $this->offset, $this->limit, $this->mode);
627 break;
628 // case 'WooCommerceCustomer':
629 // ExportExtension::$wc_customer->FetchWooCommerceCustomer($this->module, $this->optionalType, $this->conditions, $this->offset, $this->limit, $this->mode);
630 // break;
631 case 'WooCommerceReviews':
632 case 'Comments':
633 self::FetchComments();
634 break;
635 case 'CustomerReviews':
636 ExportExtension::$review_export->FetchCustomerReviews($this->module, $this->optionalType, $this->conditions, $this->offset, $this->limit, $this->mode);
637 break;
638 case 'Categories':
639 ExportExtension::$post_export->FetchCategories($this->module, $this->optionalType);
640 break;
641 case 'JetBooking':
642 $result = self::FetchDataByPostTypes();
643 break;
644 case 'JetReviews':
645 $result = self::FetchDataByPostTypes($mod,$cat, $is_filter);
646 break;
647
648 case 'Tags':
649 ExportExtension::$post_export->FetchTags($this->mode, $this->module, $this->optionalType);
650 case 'Taxonomies':
651 ExportExtension::$woocom_export->FetchTaxonomies($this->module, $this->optionalType);
652 break;
653
654 }
655 }
656
657 /**
658 * Fetch users and their meta information
659 * @param $mode
660 *
661 * @return array
662 */
663 public function FetchUsers($module, $optionalType, $conditions, $offset, $limit,$mode = null)
664 {
665 global $wpdb;
666 self::generateHeaders($this->module, $this->optionalType);
667 // $get_available_user_ids = "select DISTINCT ID from {$wpdb->prefix}users u join {$wpdb->prefix}usermeta um on um.user_id = u.ID";
668
669 // // Check for specific period
670 // if ($this->conditions['specific_period']['is_check'] == 'true')
671 // {
672 // if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to'])
673 // {
674 // $get_available_user_ids .= " where u.user_registered >= '" . $this->conditions['specific_period']['from'] . "'";
675 // }
676 // else
677 // {
678 // $get_available_user_ids .= " where u.user_registered >= '" . $this->conditions['specific_period']['from'] . "' and u.user_registered <= '" . $this->conditions['specific_period']['to'] . " 23:00:00'";
679 // }
680 // }
681 // $availableUsers = $wpdb->get_col($get_available_user_ids);
682
683 // if (!empty($this->conditions['specific_period']['is_check']) && $this->conditions['specific_period']['is_check'] == 'true')
684 // {
685 // if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to'])
686 // {
687 // $availableUserss = array();
688 // foreach ($availableUsers as $user_value)
689 // {
690 // $get_user_date_time = $wpdb->get_results("SELECT user_registered FROM {$wpdb->prefix}users WHERE ID={$user_value}", ARRAY_A);
691 // $get_user_date = date("Y-m-d", strtotime($get_user_date_time[0]['user_registered']));
692 // if ($get_user_date == $this->conditions['specific_period']['from'])
693 // {
694 // $get_user_id_value[] = $user_value;
695 // }
696
697 // }
698 // $this->totalRowCount = count($get_user_id_value);
699 // $availableUserss = $get_user_id_value;
700 // }
701 // else
702 // {
703 // $this->totalRowCount = count($availableUsers);
704 // $get_available_user_ids .= " order by ID asc limit $this->offset, $this->limit";
705 // $availableUserss = $wpdb->get_col($get_available_user_ids);
706 // }
707 // }
708 // else
709 // {
710 // $this->totalRowCount = count($availableUsers);
711 // $get_available_user_ids .= " order by ID asc limit $this->offset, $this->limit";
712 // $availableUserss = $wpdb->get_col($get_available_user_ids);
713 // }
714 if ($module == 'WooCommerceCustomer') {
715 $this->module = 'Users';
716 // Get only users with the "customer" role
717 $args = [
718 'role' => 'customer',
719 'fields' => 'ID'
720 ];
721
722 // Check for specific period
723 if ($this->conditions['specific_period']['is_check'] == 'true') {
724 $from = $this->conditions['specific_period']['from'];
725 $to = $this->conditions['specific_period']['to'];
726
727 if ($from == $to) {
728 $args['date_query'] = [
729 [
730 'after' => $from,
731 'inclusive' => true,
732 ]
733 ];
734 } else {
735 $args['date_query'] = [
736 [
737 'after' => $from,
738 'before' => $to . ' 23:59:59',
739 'inclusive' => true,
740 ]
741 ];
742 }
743 }
744
745 // Get customer user IDs
746 $availableUserss = get_users($args);
747 } else {
748 // Fetch all user IDs with the additional condition
749 $get_available_user_ids = "SELECT DISTINCT u.ID
750 FROM {$wpdb->prefix}users u
751 JOIN {$wpdb->prefix}usermeta um ON um.user_id = u.ID";
752
753 // Check for specific period
754 if ($this->conditions['specific_period']['is_check'] == 'true') {
755 if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']) {
756 $get_available_user_ids .= " WHERE u.user_registered >= '" . esc_sql($this->conditions['specific_period']['from']) . "'";
757 } else {
758 $get_available_user_ids .= " WHERE u.user_registered >= '" . esc_sql($this->conditions['specific_period']['from']) . "'
759 AND u.user_registered <= '" . esc_sql($this->conditions['specific_period']['to']) . " 23:59:59'";
760 }
761 }
762
763 $availableUserss = $wpdb->get_col($get_available_user_ids);
764 }
765
766
767 if (!empty($availableUserss))
768 {
769 $this->totalRowCount = count($availableUserss);
770 $whereCondition = '';
771 foreach ($availableUserss as $userId)
772 {
773 if ($whereCondition != '')
774 {
775 $whereCondition = $whereCondition . ',' . $userId;
776 }
777 else
778 {
779 $whereCondition = $userId;
780 }
781 // Prepare the user details to be export
782 $query_to_fetch_users = "SELECT * FROM {$wpdb->prefix}users where ID in ($whereCondition);";
783 $users = $wpdb->get_results($query_to_fetch_users);
784 if (!empty($users))
785 {
786 foreach ($users as $userInfo)
787 {
788 foreach ($userInfo as $userKey => $userVal)
789 {
790 $this->data[$userId][$userKey] = $userVal;
791 }
792 }
793 }
794 $userMeta = $wpdb->get_results("SELECT user_id, meta_key, meta_value FROM {$wpdb->prefix}users wp JOIN {$wpdb->prefix}usermeta wpm ON wpm.user_id = wp.ID WHERE ID = {$userId}");
795 $wptypesfields = get_option('wpcf-usermeta');
796 $wptypesfields = get_option('wpcf-usermeta');
797
798 if (!empty($wptypesfields))
799 {
800 $i = 1;
801 foreach ($wptypesfields as $key => $value)
802 {
803 $typesf[$i] = 'wpcf-' . $key;
804 $typeOftypesField[$typesf[$i]] = $value['type'];
805 $i++;
806 }
807 }
808 if (!empty($userMeta))
809 {
810 foreach ($userMeta as $userMetaInfo)
811 {
812 if ($userMetaInfo->meta_key == $wpdb->prefix.'capabilities')
813 {
814
815 if(is_plugin_active('members/members.php')){
816 $data = unserialize($userMetaInfo->meta_value);
817 $roles = array_keys(array_filter($data));
818 $role = implode('|', $roles);
819 $this->data[ $userId ][ 'multi_user_role' ] = $role;
820 }
821 else{
822 $userRole = $this->getUserRole($userMetaInfo->meta_value);
823 $this->data[ $userId ][ 'role' ] = $userRole;
824 }
825
826 }
827 elseif ($userMetaInfo->meta_key == 'description')
828 {
829 $this->data[$userId]['biographical_info'] = $userMetaInfo->meta_value;
830 }
831 elseif ($userMetaInfo->meta_key == 'comment_shortcuts')
832 {
833 $this->data[$userId]['enable_keyboard_shortcuts'] = $userMetaInfo->meta_value;
834 }
835 elseif ($userMetaInfo->meta_key == 'show_admin_bar_front')
836 {
837 $this->data[$userId]['show_toolbar'] = $userMetaInfo->meta_value;
838 }
839 elseif ($userMetaInfo->meta_key == 'rich_editing')
840 {
841 $this->data[$userId]['disable_visual_editor'] = $userMetaInfo->meta_value;
842 }
843 elseif ($userMetaInfo->meta_key == 'locale')
844 {
845 $this->data[$userId]['language'] = $userMetaInfo->meta_value;
846 }
847 elseif (isset($typesf) && in_array($userMetaInfo->meta_key, $typesf))
848 {
849 $typeoftype = $typeOftypesField[$userMetaInfo->meta_key];
850 if (is_serialized($userMetaInfo->meta_value))
851 {
852 $typefileds = unserialize($userMetaInfo->meta_value);
853 $typedata = "";
854 foreach ($typefileds as $key2 => $value2)
855 {
856 if (is_array($value2))
857 {
858 foreach ($value2 as $key3 => $value3)
859 {
860 $typedata .= $value3 . ',';
861 }
862 }
863 else $typedata .= $value2 . ',';
864 }
865 if (preg_match('/wpcf-/', $userMetaInfo->meta_key))
866 {
867 $userMetaInfo->meta_key = preg_replace('/wpcf-/', '', $userMetaInfo->meta_key);
868 $this->data[$userId][$userMetaInfo->meta_key] = substr($typedata, 0, -1);
869 }
870 }
871 elseif ($typeoftype == 'date')
872 {
873 $this->data[$userId][$userMetaInfo->meta_key] = date('Y-m-d', $userMetaInfo->meta_value);
874 }
875 $multi_row = '_' . $userMetaInfo->meta_key . '-sort-order';
876
877 $multi_data = get_user_meta($userId, $multi_row);
878 $multi_data = $multi_data[0];
879 if (is_array($multi_data))
880 {
881 foreach ($multi_data as $k => $mid)
882 {
883 $m_data = $this->get_common_post_metadata($mid);
884 if ($typeoftype == 'date') $multi_data[$k] = date('Y-m-d H:i:s', $m_data['meta_value']);
885 else $multi_data[$k] = $m_data['meta_value'];
886 }
887 $this->data[$userId][$userMetaInfo->meta_key] = implode('|', $multi_data);
888 if (preg_match('/wpcf-/', $userMetaInfo->meta_key))
889 {
890 $userMetaInfo->meta_key = preg_replace('/wpcf-/', '', $userMetaInfo->meta_key);
891
892 $this->data[$userId][$userMetaInfo->meta_key] = implode('|', $multi_data);
893 }
894 }
895 else
896 {
897 if (preg_match('/wpcf-/', $userMetaInfo->meta_key))
898 {
899 $userMetaInfo->meta_key = preg_replace('/wpcf-/', '', $userMetaInfo->meta_key);
900 $this->data[$userId][$userMetaInfo
901 ->meta_key] = $userMetaInfo->meta_value;
902 }
903 }
904 }
905
906 else
907 {
908
909 $this->data[$userId][$userMetaInfo
910 ->meta_key] = $userMetaInfo->meta_value;
911 }
912 }
913 // Prepare the buddy meta details to be export
914 if (is_plugin_active('buddypress/bp-loader.php'))
915 {
916 $query_to_fetch_buddy_meta = $wpdb->prepare("SELECT user_id,field_id,value,name FROM {$wpdb->prefix}bp_xprofile_data bxd inner join {$wpdb->prefix}users wp on bxd.user_id = wp.ID inner join {$wpdb->prefix}bp_xprofile_fields bxf on bxf.id = bxd.field_id where user_id=%d", $userId);
917 $buddy = $wpdb->get_results($query_to_fetch_buddy_meta);
918 if (!empty($buddy))
919 {
920 foreach ($buddy as $buddyInfo)
921 {
922 foreach ($buddyInfo as $field_id => $value)
923 {
924 $this->data[$userId][$buddyInfo
925 ->name] = $buddyInfo->value;
926 }
927 }
928 }
929 }
930 ExportExtension::$post_export->getPostsMetaDataBasedOnRecordId($userId, $this->module, $this->optionalType);
931 }
932 }
933 }
934
935 $result = self::finalDataToExport($this->data, $this->module,$this->optionalType);
936 if ($mode == null) self::proceedExport($result);
937 else return $result;
938 }
939
940 public function mergeWithUserMeta($acf_field_values)
941 {
942
943 foreach ($acf_field_values as $acf_field_value)
944 {
945
946 }
947 }
948
949 /**
950 * Fetch all Comments
951 * @param $mode
952 *
953 * @return array
954 */
955 public function FetchComments($mode = null)
956 {
957
958 global $wpdb;
959 self::generateHeaders($this->module, $this->optionalType);
960 $get_comments = "select * from {$wpdb->prefix}comments";
961 // Check status
962 if (isset($this->conditions['specific_status']['is_check']) && $this->conditions['specific_status']['is_check'] == 'true')
963 {
964 if ($this->conditions['specific_status']['status'] == 'Pending') $get_comments .= " where comment_approved = '0'";
965 elseif ($this->conditions['specific_status']['status'] == 'Approved') $get_comments .= " where comment_approved = '1'";
966 else $get_comments .= " where comment_approved in ('0','1')";
967 }
968 else $get_comments .= " where comment_approved in ('0','1')";
969 // Check for specific period
970 if ($this->conditions['specific_period']['is_check'] == 'true')
971 {
972 if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to'])
973 {
974 $get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "'";
975 }
976 else
977 {
978 $get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "' and comment_date <= '" . $this->conditions['specific_period']['to'] . " 23:00:00'";
979 }
980 }
981 // Check for specific authors
982 if ($this->conditions['specific_authors']['is_check'] == '1')
983 {
984 if (isset($this->conditions['specific_authors']['author']))
985 {
986 $get_comments .= " and comment_author_email = '" . $this->conditions['specific_authors']['author'] . "'";
987 }
988 }
989
990 if($this->module == 'WooCommerceReviews'){
991 $get_comments .= " and comment_type = 'review'";
992 }
993
994 $comments = $wpdb->get_results($get_comments);
995
996 if (!empty($this->conditions['specific_period']['is_check']) && $this->conditions['specific_period']['is_check'] == 'true')
997 {
998 if ($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to'])
999 {
1000 $limited_comments = array();
1001 foreach ($comments as $comments_value)
1002 {
1003 // $get_comment_date_time = $wpdb->get_results($wpdb->prepare("SELECT comment_date FROM {$wpdb->prefix}comments WHERE comment_id=$comments_value->comment_ID") , ARRAY_A);
1004 $get_comment_date_time = $wpdb->get_results("SELECT comment_date FROM {$wpdb->prefix}comments WHERE comment_id = {$comments_value->comment_ID}", ARRAY_A);
1005 $get_comment_date = date("Y-m-d", strtotime($get_comment_date_time[0]['comment_date']));
1006 if ($get_comment_date == $this->conditions['specific_period']['from'])
1007 {
1008 $get_comment_date_value[] = $comments_value;
1009 }
1010
1011 }
1012 $this->totalRowCount = count($get_comment_date_value);
1013 $limited_comments = $get_comment_date_value;
1014 }
1015 else
1016 {
1017 $this->totalRowCount = count($comments);
1018 $get_comments .= " order by comment_ID asc limit $this->offset, $this->limit";
1019 $limited_comments = $wpdb->get_results($get_comments);
1020 }
1021 }
1022 else
1023 {
1024 $this->totalRowCount = count($comments);
1025 $get_comments .= " order by comment_ID asc limit $this->offset, $this->limit";
1026 $limited_comments = $wpdb->get_results($get_comments);
1027 }
1028
1029 if (!empty($limited_comments))
1030 {
1031 foreach ($limited_comments as $commentInfo)
1032 {
1033 $user_id = $commentInfo->user_id;
1034 if (!empty($user_id))
1035 {
1036 $users_login = $wpdb->get_results("SELECT user_login FROM {$wpdb->prefix}users WHERE ID = '$user_id'");
1037 foreach ($users_login as $users_key => $users_value)
1038 {
1039 foreach ($users_value as $u_key => $u_value)
1040 {
1041 $users_id = $u_value;
1042 }
1043 }
1044 }
1045 foreach ($commentInfo as $commentKey => $commentVal)
1046 {
1047 $this->data[$commentInfo->comment_ID][$commentKey] = $commentVal;
1048 $this->data[$commentInfo->comment_ID]['user_id'] = isset($users_id) ? $users_id : '';
1049 }
1050 $get_comment_rating = get_comment_meta($commentInfo->comment_ID, 'rating', true);
1051 if(!empty($get_comment_rating)){
1052 $this->data[$commentInfo->comment_ID]['comment_rating'] = $get_comment_rating;
1053 }
1054 }
1055 }
1056 $result = self::finalDataToExport($this->data, $this->module,$this->optionalType);
1057 if ($mode == null) self::proceedExport($result);
1058 else return $result;
1059 }
1060
1061 /**
1062 * Generate CSV headers
1063 *
1064 * @param $module - Module to be export
1065 * @param $optionalType - Exclusions
1066 */
1067 public function generateHeaders($module, $optionalType)
1068 {
1069 if ($module == 'CustomPosts' || $module == 'Taxonomies' || $module == 'Categories' || $module == 'Tags')
1070 {
1071 if(is_plugin_active('events-manager/events-manager.php') &&$optionalType == 'event'){
1072 $optionalType = 'Events';
1073 }
1074 $default = $this->get_fields($optionalType); // Call the super class function
1075
1076 }
1077 else
1078 {
1079 $default = $this->get_fields($module);
1080 }
1081
1082 $headers = [];
1083 foreach ($default as $key => $fields)
1084 {
1085 foreach ($fields as $groupKey => $fieldArray)
1086 {
1087
1088 foreach ($fieldArray as $fKey => $fVal)
1089 {
1090 if (is_array($fVal) || is_object($fVal))
1091 {
1092 foreach ($fVal as $rKey => $rVal)
1093 {
1094 if (!in_array($rVal['name'], $headers)) $headers[] = $rVal['name'];
1095 }
1096 }
1097 }
1098
1099 }
1100 }
1101 if ($optionalType == 'elementor_library')
1102 {
1103 $headers = [];
1104 $headers = ['ID', 'Template title', 'Template content', 'Style', 'Template type', 'Created time', 'Created by', 'Template status', 'Category'];
1105 }
1106 if (isset($this->eventExclusions['is_check']) && $this->eventExclusions['is_check'] == 'true'):
1107 $headers_with_exclusion = self::applyEventExclusion($headers, $optionalType);
1108 $this->headers = $headers_with_exclusion;
1109 else:
1110 $this->headers = $headers;
1111 endif;
1112 }
1113
1114 /**
1115 * Fetch data by requested Post types
1116 * @param $mode
1117 * @return array
1118 */
1119 public function FetchDataByPostTypes($mode = null)
1120 {
1121 $exp_module = '';
1122 if (empty($this->headers)) $this->generateHeaders($this->module, $this->optionalType);
1123 $recordsToBeExport = ExportExtension::$post_export->getRecordsBasedOnPostTypes($this->module, $this->optionalType, $this->conditions, $this->offset, $this->limit, $this->headers);
1124 if (!empty($recordsToBeExport))
1125 {
1126 foreach ($recordsToBeExport as $postId)
1127 {
1128 $exp_module = $this->module;
1129 if($exp_module !== 'JetBooking' && $exp_module !== 'JetReviews') {
1130 $this->data[$postId] = $this->getPostsDataBasedOnRecordId($postId,$this->module);
1131 }
1132 $this->data[$postId] = $this->getPostsDataBasedOnRecordId($postId,$this->module);
1133 if ($exp_module == 'Posts' || $exp_module == 'WooCommerce' || $exp_module == 'CustomPosts' || $exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies' || $exp_module == 'Pages')
1134 {
1135 $this->getWPMLData($postId, $this->optionalType, $exp_module);
1136 }
1137
1138 if ($exp_module == 'Posts' || $exp_module == 'CustomPosts' || $exp_module == 'Pages' || $exp_module == 'WooCommerce')
1139 {
1140 if(is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php') || is_plugin_active('polylang-wc/polylang-wc.php')){
1141 $this->getPolylangData($postId, $this->optionalType, $exp_module);
1142 }
1143 }
1144 if($exp_module == 'CustomPosts'){
1145 if(is_plugin_active('geodirectory/geodirectory.php')){
1146 $this->getGeoPlaceData($postId,$this->optionalType,$exp_module);
1147 }
1148 }
1149 ExportExtension::$post_export->getPostsMetaDataBasedOnRecordId($postId, $this->module, $this->optionalType);
1150 $this->getTermsAndTaxonomies($postId, $this->module, $this->optionalType);
1151 if($this->module == 'JetBooking')
1152 ExportExtension::$jet_book_export->getJetBookingData($postId, $this->module, $this->optionalType);
1153 if ($this->module == 'JetReviews') {
1154 ExportExtension::$jet_reviews_export->getJetReviewsData($postId, $this->module, $this->optionalType);
1155 }
1156 if ($this->module == 'WooCommerce') ExportExtension::$woocom_export->getProductData($postId, $this->module, $this->optionalType);
1157 if ($this->module == 'WooCommerceRefunds') ExportExtension::$woocom_export->getWooComCustomerUser($postId, $this->module, $this->optionalType);
1158 if ($this->module == 'WooCommerceOrders') ExportExtension::$woocom_export->getWooComOrderData($postId, $this->module, $this->optionalType);
1159 if ($this->module == 'WooCommerceVariations') ExportExtension::$woocom_export->getVariationData($postId, $this->module, $this->optionalType);
1160 if($this->module == 'WooCommerceCoupons') ExportExtension::$woocom_export->getCouponsData($postId, $this->module, $this->optionalType);
1161 if ($this->module == 'WPeCommerce') ExportExtension::$ecom_export->getEcomData($postId, $this->module, $this->optionalType);
1162 if ($this->module == 'WPeCommerceCoupons') ExportExtension::$ecom_export->getEcomCouponData($postId, $this->module, $this->optionalType);
1163
1164 if ($this->optionalType == 'lp_course') ExportExtension::$learnpress_export->getCourseData($postId);
1165 if ($this->optionalType == 'lp_lesson') ExportExtension::$learnpress_export->getLessonData($postId);
1166 if ($this->optionalType == 'lp_quiz') ExportExtension::$learnpress_export->getQuizData($postId);
1167 if ($this->optionalType == 'lp_question') ExportExtension::$learnpress_export->getQuestionData($postId);
1168 if ($this->optionalType == 'lp_order') ExportExtension::$learnpress_export->getOrderData($postId);
1169
1170 if ($this->optionalType == 'stm-courses') ExportExtension::$woocom_export->getCourseDataMasterLMS($postId);
1171
1172 if ($this->optionalType == 'stm-questions') ExportExtension::$woocom_export->getQuestionDataMasterLMS($postId);
1173
1174 if ($this->optionalType == 'stm-lessons') ExportExtension::$woocom_export->getLessonDataMasterLMS($postId);
1175 if ($this->optionalType == 'stm-orders') ExportExtension::$woocom_export->orderDataMasterLMS($postId);
1176 if ($this->optionalType == 'stm-quizzes') ExportExtension::$woocom_export->quizzDataMasterLMS($postId);
1177 if ($this->optionalType == 'elementor_library') ExportExtension::$woocom_export->elementor_export($postId);
1178 if ($this->optionalType == 'nav_menu_item') ExportExtension::$woocom_export->getMenuData($postId);
1179
1180 if ($this->optionalType == 'widgets') self::$instance->getWidgetData($postId, $this->headers);
1181 }
1182 }
1183 $exp_module = $this->module;
1184 if(is_plugin_active('jet-engine/jet-engine.php')){
1185 global $wpdb;
1186 $get_slug_name = $wpdb->get_results("SELECT slug FROM {$wpdb->prefix}jet_post_types WHERE status = 'content-type'");
1187
1188 foreach($get_slug_name as $key=>$get_slug){
1189 $value = $get_slug->slug;
1190 $optional_type = $value;
1191 if($this->optionalType == $optional_type){
1192 $table_name='jet_cct_'.$this->optionalType;
1193
1194 $jet_values = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}$table_name order by _ID asc limit $this->offset,$this->limit ");
1195 if(!empty($jet_values)) {
1196 foreach($jet_values as $jet_value) {
1197 foreach($jet_value as $field_id => $value) {
1198 $this->data[$jet_value->_ID][$field_id] = $value;
1199
1200 }
1201 }
1202 }
1203 foreach($this->data as $id => $value){
1204 ExportExtension::$post_export->getPostsMetaDataBasedOnRecordId($id, $this->module, $this->optionalType);
1205 }
1206 }
1207 }
1208 $slug = $this->optionalType;
1209 $getarg = $wpdb->get_results("SELECT args from {$wpdb->prefix}jet_post_types where slug = '$slug' and status = 'content-type'",ARRAY_A);
1210 foreach($getarg as $key => $value){
1211 $arg_data = $value['args'];
1212 break;
1213 }
1214 if(!empty($arg_data)){
1215 $arg_data = unserialize($arg_data);
1216 if(!empty($arg_data) && array_key_exists('has_single',$arg_data) && $arg_data['has_single']){
1217 $this->data[$id]['cct_single_post_title'] = $arg_data['related_post_type_title'] ?? '';
1218 $this->data[$id]['cct_single_post_content'] = $arg_data['related_post_type_content'] ?? '';
1219 }
1220 }
1221 }
1222 /** Added post format for 'standard' property */
1223 if ($exp_module == 'Posts' || $exp_module == 'CustomPosts' || $exp_module == 'WooCommerce')
1224 {
1225 foreach ($this->data as $id => $records)
1226 {
1227 if (!array_key_exists('post_format', $records))
1228 {
1229 $records['post_format'] = 'standard';
1230 $this->data[$id] = $records;
1231 }
1232 }
1233
1234 }
1235 if($this->optionalType == 'course'){
1236 foreach($this->data as $id => $records){
1237 if(array_key_exists('_llms_instructors',$records)){
1238 $instructor=unserialize($records['_llms_instructors']);
1239 if(is_array($instructor)){
1240 $arr_ins=array();
1241 foreach($instructor as $ins_val){
1242 $arr_val=array_values($ins_val);
1243 unset($arr_val[0]);
1244 unset($arr_val[2]);
1245 $arr_ins[] = implode(',',$arr_val);
1246
1247 }
1248 $records['_llms_instructors'] = implode('|',$arr_ins);
1249 $this->data[$id] = $records;
1250
1251 }
1252
1253
1254 }
1255 }
1256 }
1257
1258
1259 /** End post format */
1260
1261 $result = self::finalDataToExport($this->data, $this->module,$this->optionalType);
1262 if ($mode == null) self::proceedExport($result);
1263 else return $result;
1264 }
1265
1266 public function getWidgetData($postId, $headers)
1267 {
1268
1269 global $wpdb;
1270 $get_sidebar_widgets = get_option('sidebars_widgets');
1271
1272 $total_footer_arr = [];
1273
1274 foreach ($get_sidebar_widgets as $footer_key => $footer_arr)
1275 {
1276 if ($footer_key != 'wp_inactive_widgets' || $footer_key != 'array_version')
1277 {
1278 if (strpos($footer_key, 'sidebar') !== false)
1279 {
1280 $get_footer = explode('-', $footer_key);
1281 $footer_number = $get_footer[1];
1282
1283 foreach ($footer_arr as $footer_values)
1284 {
1285 $total_footer_arr[$footer_values] = $footer_number;
1286 }
1287 }
1288 }
1289 }
1290
1291 foreach ($headers as $key => $value)
1292 {
1293 $get_widget_value[$value] = $wpdb->get_row("SELECT option_value FROM {$wpdb->prefix}options where option_name = '{$value}'", ARRAY_A);
1294
1295 $header_key = explode('widget_', $value);
1296
1297 if ($value == 'widget_recent-posts')
1298 {
1299 $recent_posts = unserialize($get_widget_value[$value]['option_value']);
1300 $recent_post = '';
1301 foreach ($recent_posts as $dk => $dv)
1302 {
1303 if ($dk != '_multiwidget')
1304 {
1305 $post_key = $header_key[1] . '-' . $dk;
1306 $recent_post .= $dv['title'] . ',' . $dv['number'] . ',' . $dv['show_date'] . '->' . $total_footer_arr[$post_key] . '|';
1307 }
1308 }
1309 $recent_post = rtrim($recent_post, '|');
1310 }
1311 elseif ($value == 'widget_pages')
1312 {
1313 $recent_pages = unserialize($get_widget_value[$value]['option_value']);
1314 $recent_page = '';
1315 foreach ($recent_pages as $dk => $dv)
1316 {
1317 if (isset($dv['exclude']))
1318 {
1319 $exclude_value = str_replace(',', '/', $dv['exclude']);
1320 }
1321
1322 if ($dk != '_multiwidget')
1323 {
1324 $page_key = $header_key[1] . '-' . $dk;
1325 $recent_page .= $dv['title'] . ',' . $dv['sortby'] . ',' . $exclude_value . '->' . $total_footer_arr[$page_key] . '|';
1326 }
1327 }
1328 $recent_page = rtrim($recent_page, '|');
1329 }
1330 elseif ($value == 'widget_recent-comments')
1331 {
1332 $recent_comments = unserialize($get_widget_value[$value]['option_value']);
1333 $recent_comment = '';
1334 foreach ($recent_comments as $dk => $dv)
1335 {
1336 if ($dk != '_multiwidget')
1337 {
1338 $comment_key = $header_key[1] . '-' . $dk;
1339 $recent_comment .= $dv['title'] . ',' . $dv['number'] . '->' . $total_footer_arr[$comment_key] . '|';
1340 }
1341 }
1342 $recent_comment = rtrim($recent_comment, '|');
1343 }
1344 elseif ($value == 'widget_archives')
1345 {
1346 $recent_archives = unserialize($get_widget_value[$value]['option_value']);
1347 $recent_archive = '';
1348 foreach ($recent_archives as $dk => $dv)
1349 {
1350 if ($dk != '_multiwidget')
1351 {
1352 $archive_key = $header_key[1] . '-' . $dk;
1353 $recent_archive .= $dv['title'] . ',' . $dv['count'] . ',' . $dv['dropdown'] . '->' . $total_footer_arr[$archive_key] . '|';
1354 }
1355 }
1356 $recent_archive = rtrim($recent_archive, '|');
1357 }
1358 elseif ($value == 'widget_categories')
1359 {
1360 $recent_categories = unserialize($get_widget_value[$value]['option_value']);
1361 $recent_category = '';
1362 foreach ($recent_categories as $dk => $dv)
1363 {
1364 if ($dk != '_multiwidget')
1365 {
1366 $cat_key = $header_key[1] . '-' . $dk;
1367 $recent_category .= $dv['title'] . ',' . $dv['count'] . ',' . $dv['hierarchical'] . ',' . $dv['dropdown'] . '->' . $total_footer_arr[$cat_key] . '|';
1368 }
1369 }
1370 $recent_category = rtrim($recent_category, '|');
1371 }
1372 }
1373
1374 $this->data[$postId]['widget_recent-posts'] = $recent_post;
1375 $this->data[$postId]['widget_pages'] = $recent_page;
1376 $this->data[$postId]['widget_recent-comments'] = $recent_comment;
1377 $this->data[$postId]['widget_archives'] = $recent_archive;
1378 $this->data[$postId]['widget_categories'] = $recent_category;
1379 }
1380
1381 /**
1382 * Function used to fetch the Terms & Taxonomies for the specific posts
1383 *
1384 * @param $id
1385 * @param $type
1386 * @param $optionalType
1387 */
1388 public function getTermsAndTaxonomies($id, $type, $optionalType)
1389 {
1390 $TermsData = array();
1391
1392 if ($type == 'WooCommerce' || ($type == 'CustomPosts' && $type == 'WooCommerce'))
1393 {
1394 $type = 'product';
1395 $postTags = '';
1396 $taxonomies = get_object_taxonomies($type);
1397 $get_tags = get_the_terms($id, 'product_tag');
1398 if ($get_tags)
1399 {
1400 foreach ($get_tags as $tags)
1401 {
1402 $postTags .= $tags->name . ',';
1403 }
1404 }
1405 $postTags = substr($postTags, 0, -1);
1406 $this->data[$id]['product_tag'] = $postTags;
1407 foreach ($taxonomies as $taxonomy)
1408 {
1409 $postCategory = '';
1410 if ($taxonomy == 'product_cat' || $taxonomy == 'product_category')
1411 {
1412 $get_categories = get_the_terms($id, $taxonomy);
1413 if ($get_categories)
1414 {
1415 $postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy);
1416 // foreach($get_categories as $category){
1417 // $postCategory .= $this->hierarchy_based_term_name($category, $taxonomy) . ',';
1418 // }
1419
1420 }
1421 $postCategory = substr($postCategory, 0, -1);
1422 $this->data[$id]['product_category'] = $postCategory;
1423 }
1424 else
1425 {
1426 $get_categories = get_the_terms($id, $taxonomy);
1427 if ($get_categories)
1428 {
1429 $postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy);
1430 // foreach($get_categories as $category){
1431 // $postCategory .= $this->hierarchy_based_term_name($category, $taxonomy) . ',';
1432 // }
1433
1434 }
1435 $postCategory = substr($postCategory, 0, -1);
1436 $this->data[$id][$taxonomy] = $postCategory;
1437 }
1438 }
1439 if ($type == 'WooCommerce' && $type != 'CustomPosts')
1440 {
1441 $product = wc_get_product($id);
1442 $pro_type = $product->get_type();
1443 switch ($pro_type)
1444 {
1445 case 'simple':
1446 $product_type = 1;
1447 break;
1448 case 'grouped':
1449 $product_type = 2;
1450 break;
1451 case 'external':
1452 $product_type = 3;
1453 break;
1454 case 'variable':
1455 $product_type = 4;
1456 break;
1457 case 'subscription':
1458 $product_type = 5;
1459 break;
1460 case 'variable-subscription':
1461 $product_type = 6;
1462 break;
1463 case 'bundle':
1464 $product_type = 7;
1465 break;
1466 default:
1467 $product_type = 1;
1468 break;
1469 }
1470 $this->data[$id]['product_type'] = $product_type;
1471 }
1472
1473 //product_shipping_class
1474 $shipping = get_the_terms($id, 'product_shipping_class');
1475 if ($shipping)
1476 {
1477 $taxo_shipping = $shipping[0]->name;
1478 $this->data[$id]['product_shipping_class'] = $taxo_shipping;
1479 }
1480 //product_shipping_class
1481
1482 }
1483 else if ($type == 'WPeCommerce')
1484 {
1485 $type = 'wpsc-product';
1486 $postTags = $postCategory = '';
1487 $taxonomies = get_object_taxonomies($type);
1488 $get_tags = get_the_terms($id, 'product_tag');
1489 if ($get_tags)
1490 {
1491 foreach ($get_tags as $tags)
1492 {
1493 $postTags .= $tags->name . ',';
1494 }
1495 }
1496 $postTags = substr($postTags, 0, -1);
1497 $this->data[$id]['product_tag'] = $postTags;
1498 foreach ($taxonomies as $taxonomy)
1499 {
1500 $postCategory = '';
1501 if ($taxonomy == 'wpsc_product_category')
1502 {
1503 $get_categories = wp_get_post_terms($id, $taxonomy);
1504 if ($get_categories)
1505 {
1506 $postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy);
1507
1508 }
1509 $postCategory = substr($postCategory, 0, -1);
1510 $this->data[$id]['product_category'] = $postCategory;
1511 }
1512 else
1513 {
1514 $get_categories = wp_get_post_terms($id, $taxonomy);
1515 if ($get_categories)
1516 {
1517 $postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy);
1518
1519 }
1520 $postCategory = substr($postCategory, 0, -1);
1521 $this->data[$id]['product_category'] = $postCategory;
1522 }
1523 }
1524 }
1525 else
1526 {
1527 global $wpdb;
1528 $postTags = $postCategory = '';
1529 // $taxonomyId = $wpdb->get_col($wpdb->prepare("select term_taxonomy_id from {$wpdb->prefix}term_relationships where object_id = %d", $id));
1530 $taxonomyId = $wpdb->get_col("SELECT term_taxonomy_id FROM {$wpdb->prefix}term_relationships WHERE object_id = {$id}");
1531 $taxo = [];
1532 $termTaxonomyIds = array();
1533 foreach ($taxonomyId as $taxonomyIds)
1534 {
1535
1536 // $termTaxonomyId = $wpdb->get_results($wpdb->prepare("select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomyIds));
1537 $termTaxonomyId = $wpdb->get_results("SELECT term_id FROM {$wpdb->prefix}term_taxonomy WHERE term_taxonomy_id = {$taxonomyIds}");
1538 foreach ($termTaxonomyId as $term)
1539 {
1540 $termTaxonomyIds[] = $term->term_id;
1541 }
1542 }
1543 foreach ($termTaxonomyIds as $taxonomy)
1544 {
1545
1546 $taxo[] = get_term($taxonomy);
1547 }
1548 foreach ($taxonomyId as $taxonomy)
1549 {
1550 $taxonomytypeid = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy WHERE term_taxonomy_id='$taxonomy' ");
1551 if ($taxonomytypeid[0]->taxonomy == 'course_category')
1552 {
1553 $taxonomyTypeId = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomytypeid[0]->term_taxonomy_id));
1554 $taxonomy_Type_Id = $taxonomyTypeId[0];
1555 $taxo0[] = get_term($taxonomy_Type_Id);
1556 }
1557 if ($taxonomytypeid[0]->taxonomy == 'course_tag')
1558 {
1559 $taxonomyTypeId1 = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomytypeid[0]->term_taxonomy_id));
1560 $taxonomy_Type_Id1 = $taxonomyTypeId1[0];
1561 $taxo2[] = get_term($taxonomy_Type_Id1);
1562 }
1563 }
1564
1565 if (!empty($taxo))
1566 {
1567 foreach ($taxo as $key => $taxo_val)
1568 {
1569 if ($taxo_val->taxonomy == 'category')
1570 {
1571 $taxo1[] = $taxo_val;
1572 }
1573 }
1574 }
1575
1576 if (!empty($taxonomyId))
1577 {
1578 foreach ($taxonomyId as $taxonomy)
1579 {
1580 $taxonomyType = $wpdb->get_col($wpdb->prepare("select taxonomy from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomy));
1581 if (!empty($taxonomyType))
1582 {
1583 foreach ($taxonomyType as $taxanomy_name)
1584 {
1585 if ($taxanomy_name == 'category')
1586 {
1587 $termName = 'post_category';
1588 }
1589 else
1590 {
1591 $termName = $taxanomy_name;
1592 }
1593 if (in_array($termName, $this->headers))
1594 {
1595 if ($termName != 'post_tag' && $termName != 'post_category')
1596 {
1597 $postterm1 = $postterm2 = '';
1598 $taxonomyData = $wpdb->get_col($wpdb->prepare("select name from {$wpdb->prefix}terms where term_id = %d", $taxonomy));
1599 if (!empty($taxonomyData))
1600 {
1601
1602 if (isset($TermsData[$termName]))
1603 {
1604 $this->data[$id][$termName] = $TermsData[$termName] . ',' . $taxonomyData[0];
1605 }
1606 else
1607 {
1608 $get_exist_data = isset($this->data[$id][$termName]) ? $this->data[$id][$termName] : '';
1609 }
1610
1611 if ($get_exist_data == '')
1612 {
1613 $this->data[$id][$termName] = $taxonomyData[0];
1614 }
1615 else
1616 {
1617 $taxonomyID = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}terms where name = %s", $taxonomyData[0]));
1618 if ($taxanomy_name == 'course_category')
1619 {
1620 foreach ($taxo0 as $taxo_key => $taxo_value)
1621 {
1622 $postterm1 .= $taxo_value->name . ',';
1623 }
1624 $this->data[$id][$termName] = rtrim($postterm1, ',');
1625 }
1626 elseif ($taxanomy_name == 'course_tag')
1627 {
1628 foreach ($taxo2 as $taxo_key1 => $taxo_value1)
1629 {
1630 $postterm2 .= $taxo_value1->name . ',';
1631 }
1632 $this->data[$id][$termName] = rtrim($postterm2, ',');
1633 }
1634 else
1635 {
1636 $postterm = substr($this->hierarchy_based_term_name($taxo, $taxanomy_name) , 0, -1);
1637 $this->data[$id][$termName] = $postterm;
1638 }
1639 }
1640
1641 }
1642 }
1643 else
1644 {
1645 if (!isset($TermsData['post_tag']))
1646 {
1647 if ($termName == 'post_tag')
1648 {
1649 $postTags = '';
1650 $get_tags = wp_get_post_tags($id, array(
1651 'fields' => 'names'
1652 ));
1653 foreach ($get_tags as $tags)
1654 {
1655 $postTags .= $tags . ',';
1656 }
1657 $postTags = substr($postTags, 0, -1);
1658 $this->data[$id][$termName] = $postTags;
1659 }
1660 if ($termName == 'post_category')
1661 {
1662 $postCategory = '';
1663 $get_categories = wp_get_post_categories($id, array(
1664 'fields' => 'names'
1665 ));
1666
1667 $postterm1 = substr($this->hierarchy_based_term_name($taxo1, $taxanomy_name) , 0, -1);
1668 $this->data[$id][$termName] = $postterm1;
1669
1670 }
1671
1672 }
1673 }
1674 }
1675 else
1676 {
1677 $this->data[$id][$termName] = '';
1678 }
1679 }
1680 }
1681 }
1682 }
1683 }
1684 }
1685
1686 /**
1687 * Get user role based on the capability
1688 * @param null $capability - User capability
1689 * @return int|string - Role of the user
1690 */
1691 public function getUserRole($capability = null)
1692 {
1693 if ($capability != null)
1694 {
1695 $getRole = unserialize($capability);
1696 foreach ($getRole as $roleName => $roleStatus)
1697 {
1698 $role = $roleName;
1699 }
1700 return $role;
1701 }
1702 else
1703 {
1704 return 'subscriber';
1705 }
1706 }
1707
1708 /**
1709 * Get activated plugins
1710 * @return mixed
1711 */
1712 public function get_active_plugins()
1713 {
1714 $active_plugins = get_option('active_plugins');
1715 return $active_plugins;
1716 }
1717 public function array_to_xml( $data, &$xml_data ) {
1718 foreach( $data as $key => $value ) {
1719 if( is_numeric($key) ){
1720 $key = 'item';
1721 }
1722 if (strpos($key, '::') !== false) {
1723 $key = str_replace('::', '_COLON_', $key);
1724 $key = str_replace(' ', '_', $key);
1725 }
1726 if( is_array($value) ) {
1727 $subnode = $xml_data->addChild($key);
1728 $this->array_to_xml($value, $subnode);
1729 } else {
1730 $xml_data->addChild("$key",htmlspecialchars("$value"));
1731 }
1732 }
1733 }
1734 public function getPolylangData($id, $optional_type, $exp_module=null)
1735 {
1736 global $wpdb;
1737 global $sitepress;
1738 $post_title = '';
1739 if($exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies'){
1740 $terms = $wpdb->get_results("select term_taxonomy_id from {$wpdb->prefix}term_taxonomy where description like '%$id%'",ARRAY_A);
1741 $terms_id = json_decode(json_encode($terms) , true);
1742 }
1743 else{
1744 $terms = $wpdb->get_results("select term_taxonomy_id from $wpdb->term_relationships where object_id ='{$id}' order by term_taxonomy_id desc");
1745 $terms_id = json_decode(json_encode($terms) , true);
1746 }
1747 if(is_plugin_active('polylang-pro/polylang.php')){
1748 if($exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies'){
1749 $get_language = pll_get_term_language($id);
1750 $get_translation = pll_get_term_translations($id);
1751 unset($get_translation[$get_language]);
1752 $this->data[$id]['language_code'] = $get_language;
1753 foreach($get_translation as $trans_key => $trans_val){
1754 $title = $wpdb->get_var("SELECT name FROM {$wpdb->prefix}terms where term_id=$trans_val");
1755 $post_title .= $title.',';
1756 }
1757 $this->data[$id]['translated_taxonomy_title'] = rtrim($post_title,',');
1758 }
1759 else{
1760 $get_language=pll_get_post_language( $id );
1761 $get_translation=pll_get_post_translations($id);
1762 unset($get_translation[$get_language]);
1763 $this->data[$id]['language_code'] = $get_language;
1764 foreach($get_translation as $trans_key => $trans_val){
1765 $title = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts where id=$trans_val");
1766 $post_title .= $title.',';
1767 }
1768 $this->data[$id]['translated_post_title'] = rtrim($post_title,',');
1769 }
1770 }
1771 else{
1772 foreach ($terms_id as $termkey => $termvalue)
1773 {
1774 $post_title = '';
1775 $termids = $termvalue['term_taxonomy_id'];
1776 $check = $wpdb->get_var("select taxonomy from $wpdb->term_taxonomy where term_taxonomy_id ='{$termids}'");
1777 if ($check == 'category')
1778 {
1779 $category = $wpdb->get_var("select name from $wpdb->terms where term_id ='{$termids}'");
1780 }
1781 elseif ($check == 'language')
1782 {
1783 $language = $wpdb->get_var("select description from $wpdb->term_taxonomy where term_id ='{$termids}'");
1784 $lang = unserialize($language);
1785 $langcode = explode('_', $lang['locale']);
1786 $lang_code = $langcode[0];
1787 $this->data[$id]['language_code'] = $lang_code;
1788
1789 }
1790
1791 elseif($check == 'term_language'){
1792 if($exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies'){
1793 $language = $wpdb->get_var("select description from $wpdb->term_taxonomy where term_taxonomy_id ='{$termids}'");
1794 $lang = unserialize($language);
1795 $langcode = explode('_', $lang['locale']);
1796 $lang_code = $langcode[0];
1797 if(empty($this->data[$id]['language_code'])){
1798 $this->data[$id]['language_code'] = $lang_code;
1799 }
1800
1801 }
1802 }
1803 elseif(($exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies') && $check == 'term_translations'){
1804 $description = $wpdb->get_var("select description from $wpdb->term_taxonomy where term_taxonomy_id ='{$termids}'");
1805 $desc = unserialize($description);
1806 //$post_id = is_array($desc) ? array_values($desc) : array();
1807 $post_id = is_array($desc) ? $desc : array();
1808
1809 // $postid = min($post_id);
1810 foreach($post_id as $post_key => $post_value){
1811 if($id == $post_value){
1812 $this->data[$id]['language_code'] = $post_key;
1813 unset($post_id[$post_key]);
1814 }
1815 }
1816
1817 foreach($post_id as $trans_key => $trans_val){
1818 $title = $wpdb->get_var("SELECT name FROM {$wpdb->prefix}terms where term_id=$trans_val");
1819 $post_title .= $title.',';
1820 }
1821
1822 $this->data[$id]['translated_taxonomy_title'] = rtrim($post_title,',');
1823 }
1824 elseif (($exp_module !== 'Categories' && $exp_module !== 'Tags') && $check == 'post_translations')
1825 {
1826 $description = $wpdb->get_var("select description from $wpdb->term_taxonomy where term_id ='{$termids}'");
1827 $desc = unserialize($description);
1828 $post_id = is_array($desc) ? array_values($desc) : array();
1829 // $postid = min($post_id);
1830 foreach($post_id as $post_key => $post_value){
1831 if($id == $post_value){
1832 unset($post_id[$post_key]);
1833 }
1834 }
1835 foreach($post_id as $trans_key => $trans_val){
1836 $post_title = $wpdb->get_var("select post_title from $wpdb->posts where ID ='{$trans_val}'");
1837 $this->data[$id]['translated_post_title'] = $post_title;
1838 }
1839 }
1840 elseif ($check == 'post_tag')
1841 {
1842 $tag = $wpdb->get_var("select name from $wpdb->terms where term_id ='{$termids}'");
1843
1844 }
1845 }
1846 }
1847 }
1848
1849 public function getGeoPlaceData ($id,$optional_type,$exp_module) {
1850
1851 $post_info = geodir_get_post_info($id);
1852 foreach ($post_info as $gdKey => $gdVal){
1853 if(!empty($gdVal)){
1854 $this->data[$id][ $gdKey ] = $gdVal ;
1855 }
1856 }
1857 }
1858
1859 /**
1860 * Export Data
1861 * @param $data
1862 */
1863 public function proceedExport($data)
1864 {
1865
1866 if (is_user_logged_in() && current_user_can('administrator'))
1867 {
1868 $upload_dir = ABSPATH . 'wp-content/uploads/smack_uci_uploads/exports/';
1869
1870 $index_php_file = $upload_dir . 'index.php';
1871
1872 if (!file_exists($index_php_file)) {
1873 $file_content = '<?php' . PHP_EOL . '?>';
1874 file_put_contents($index_php_file, $file_content);
1875 }
1876
1877 if (empty($this->random_data))
1878 {
1879 $random_folder = wp_generate_password(16, false); // 16-character random folder name
1880 $upload_dir = $upload_dir . '/' . $random_folder . '/';
1881 }
1882 else{
1883 $random_folder = $this->random_data;
1884 $upload_dir = $upload_dir . '/' . $random_folder . '/'; }
1885 if (!is_dir($upload_dir))
1886 {
1887 wp_mkdir_p($upload_dir);
1888 }
1889 $base_dir = wp_upload_dir();
1890 $upload_url = $base_dir['baseurl'] . '/smack_uci_uploads/exports/'.$random_folder . '/';
1891 chmod($upload_dir, 0777);
1892 }
1893
1894 if ($this->checkSplit == 'true')
1895 {
1896 $i = 1;
1897 while ($i != 0)
1898 {
1899 $file = $upload_dir . $this->fileName . '_' . $i . '.' . $this->exportType;
1900 if (file_exists($file))
1901 {
1902 $allfiles[$i] = $file;
1903 $i++;
1904 }
1905 else break;
1906 }
1907 $fileURL = $upload_url . $this->fileName . '_' . $i . '.' . $this->exportType;
1908 }
1909 else
1910 {
1911 $file = $upload_dir . $this->fileName . '.' . $this->exportType;
1912 $fileURL = $upload_url . $this->fileName . '.' . $this->exportType;
1913 }
1914
1915 $spsize = 100;
1916 if ($this->offset == 0)
1917 {
1918 if (file_exists($file)) unlink($file);
1919 }
1920
1921 $checkRun = "no";
1922 if ($this->checkSplit == 'true' && ($this->totalRowCount - $this->offset) > 0)
1923 {
1924 $checkRun = 'yes';
1925 }
1926 if ($this->checkSplit != 'true')
1927 {
1928 $checkRun = 'yes';
1929 }
1930
1931 if ($checkRun == 'yes')
1932 {
1933 if ($this->exportType == 'xml')
1934 {
1935 $xml_data = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
1936 $this->array_to_xml($data, $xml_data);
1937 $result = $xml_data->asXML($file);
1938 }
1939 else
1940 {
1941 if ($this->exportType == 'json') $csvData = json_encode($data);
1942 else $csvData = $this->unParse($data, $this->headers);
1943 try
1944 {
1945
1946 file_put_contents($file, $csvData, FILE_APPEND | LOCK_EX);
1947
1948 }
1949 catch(\Exception $e)
1950 {
1951 // TODO - write exception in log
1952
1953 }
1954 }
1955 }
1956
1957 $this->offset = $this->offset + $this->limit;
1958
1959 $filePath = $upload_dir . $this->fileName . '.' . $this->exportType;
1960 $filename = $fileURL;
1961 if (($this->offset) > ($this->totalRowCount) && $this->checkSplit == 'true')
1962 {
1963 $allfiles[$i] = $file;
1964 $zipname = $upload_dir . $this->fileName . '.' . 'zip';
1965 $zip = new \ZipArchive;
1966 $zip->open($zipname, \ZipArchive::CREATE);
1967 foreach ($allfiles as $allfile)
1968 {
1969 $newname = str_replace($upload_dir, '', $allfile);
1970 $zip->addFile($allfile, $newname);
1971 }
1972 $zip->close();
1973 $fileURL = $upload_url . $this->fileName . '.' . 'zip';
1974 foreach ($allfiles as $removefile)
1975 {
1976 unlink($removefile);
1977 }
1978 $filename = $upload_url . $this->fileName . '.' . 'zip';
1979 }
1980 if ($this->checkSplit == 'true' && !($this->offset) > ($this->totalRowCount))
1981 {
1982 $responseTojQuery = array(
1983 'success' => false,
1984 'new_offset' => $this->offset,
1985 'limit' => $this->limit,
1986 'total_row_count' => $this->totalRowCount,
1987 'exported_file' => $zipname,
1988 'exported_path' => $zipname,
1989 'export_type' => $this->exportType
1990 );
1991 }
1992 elseif ($this->checkSplit == 'true' && (($this->offset) > ($this->totalRowCount)))
1993 {
1994 if ($this->exportType == 'xls' || $this->exportType == 'xlsx') {
1995 // Convert CSV to XLS or XLSX depending on the export type
1996 $newpath = str_replace('.csv', '.' . $this->exportType, $filePath);
1997 $newfilename = str_replace('.csv', '.' . $this->exportType, $fileURL);
1998 if($this->exportType == 'xlsx'){
1999 $reader = IOFactory::createReader('Xlsx');
2000 }else{
2001 $reader = IOFactory::createReader('Xls');
2002 }
2003 if (file_exists($filePath)) {
2004 $objPHPExcel = $reader->load($filePath);
2005 $spreadsheet = new Spreadsheet(); // Create new Spreadsheet object
2006 if($this->exportType == 'xlsx'){
2007 $objWriter = IOFactory::createWriter($spreadsheet, 'Xlsx');
2008 }else{
2009 $objWriter = IOFactory::createWriter($spreadsheet, 'Xls');
2010 }
2011 $objWriter->save($newpath);
2012 }
2013
2014 // Response after conversion
2015 $responseTojQuery = array(
2016 'success' => true,
2017 'new_offset' => $this->offset,
2018 'limit' => $this->limit,
2019 'total_row_count' => $this->totalRowCount,
2020 'exported_file' => $newfilename,
2021 'exported_path' => $newpath,
2022 'export_type' => $this->exportType
2023 );
2024 }
2025 else {
2026 // If export type is neither XLS nor XLSX, return original file
2027 $responseTojQuery = array(
2028 'success' => true,
2029 'new_offset' => $this->offset,
2030 'limit' => $this->limit,
2031 'total_row_count' => $this->totalRowCount,
2032 'exported_file' => $fileURL,
2033 'exported_path' => $fileURL,
2034 'export_type' => $this->exportType
2035 );
2036 }
2037 }
2038 elseif (!(($this->offset) > ($this->totalRowCount)))
2039 {
2040 $responseTojQuery = array(
2041 'success' => false,
2042 'new_offset' => $this->offset,
2043 'limit' => $this->limit,
2044 'total_row_count' => $this->totalRowCount,
2045 // 'exported_file' => $random_folder.'/'.$filename,
2046 // 'exported_path' => $random_folder.'/'.$filePath,
2047 'exported_file' => $filename,
2048 'exported_path' => $filePath,
2049 'export_type' => $this->exportType,
2050 'random_data' => $random_folder
2051 );
2052 }
2053 else
2054 {
2055 // General case where we perform export
2056 if ($this->exportType == 'xls' || $this->exportType == 'xlsx') {
2057 // Convert CSV to XLS or XLSX depending on the export type
2058 $newpath = str_replace('.csv', '.' . $this->exportType, $filePath);
2059 $newfilename = str_replace('.csv', '.' . $this->exportType, $fileURL);
2060
2061 // Load the CSV and save as XLS or XLSX based on export type
2062 $reader = IOFactory::createReader('Csv');
2063 $objPHPExcel = $reader->load($filePath);
2064 if ($this->exportType == 'xls') {
2065 // If export type is XLS, save it as XLS
2066 $objWriter = IOFactory::createWriter($objPHPExcel, 'Xls');
2067 } else {
2068 // If export type is XLSX, save it as XLSX
2069 $objWriter = IOFactory::createWriter($objPHPExcel, 'Xlsx');
2070 }
2071 $objWriter->save($newpath);
2072
2073 $responseTojQuery = array(
2074 'success' => true,
2075 'new_offset' => $this->offset,
2076 'limit' => $this->limit,
2077 'total_row_count' => $this->totalRowCount,
2078 'exported_file' => $newfilename,
2079 'exported_path' => $newpath,
2080 'export_type' => $this->exportType
2081 );
2082 } else {
2083 // If export type is neither XLS nor XLSX, return original file
2084 $responseTojQuery = array(
2085 'success' => true,
2086 'new_offset' => $this->offset,
2087 'limit' => $this->limit,
2088 'total_row_count' => $this->totalRowCount,
2089 'exported_file' => $filename,
2090 'exported_path' => $filePath,
2091 'export_type' => $this->exportType
2092 );
2093 }
2094 }
2095 // $responseTojQuery["file_path"]=WP_PLUGIN_DIR . '/wp-ultimate-exporter/download.php';
2096 if ($this->export_mode == 'normal')
2097 {
2098 echo wp_json_encode($responseTojQuery);
2099 wp_die();
2100 }
2101 elseif ($this->export_mode == 'FTP')
2102 {
2103 $this->export_log = $responseTojQuery;
2104 }
2105 }
2106
2107 /**
2108 * Fetch ACF field information to be export
2109 * @param $recordId - Id of the Post (or) Page (or) Product (or) User
2110 */
2111 public function FetchACFData($recordId)
2112 {
2113
2114 }
2115
2116 /**
2117 * Get post data based on the record id
2118 * @param $id - Id of the records
2119 * @return array - Data based on the requested id.
2120 */
2121 public function getPostsDataBasedOnRecordId($id,$module = null)
2122 {
2123 global $wpdb;
2124 $PostData = array();
2125 $query1 = $wpdb->prepare("SELECT wp.* FROM {$wpdb->prefix}posts wp where ID=%d", $id);
2126 $result_query1 = $wpdb->get_results($query1);
2127 if (!empty($result_query1))
2128 {
2129 foreach ($result_query1 as $posts)
2130 {
2131 if($posts->post_type =='event' ||$posts->post_type =='event-recurring'){
2132
2133 $loc=get_post_meta($id , '_location_id' , true);
2134 $event_id=get_post_meta($id , '_event_id' , true);
2135 $res = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}em_locations WHERE location_id='$loc' ");
2136
2137 if($res){
2138 foreach($res as $location){
2139 unset($location-> post_content);
2140 $posts=array_merge((array)$posts,(array)$location);
2141 }
2142 }
2143
2144 $ticket = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}em_tickets WHERE event_id='$event_id' ");
2145
2146 $ticket[0]=isset($ticket[0])?$ticket[0]:'';
2147 $ticket_meta= $ticket[0];
2148 if(isset($ticket_meta->{'ticket_meta'})){
2149 $ticket_meta_value=$ticket_meta->{'ticket_meta'};
2150 }
2151 $ticket_meta_value=isset($ticket_meta_value)?$ticket_meta_value:'';
2152 $ticket_value=unserialize($ticket_meta_value);
2153 if(isset($ticket_id)){
2154 $ticket_values = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}em_tickets WHERE ticket_id='$ticket_id' ");
2155 }
2156 $count=count($ticket);
2157 if($count>1){
2158 $ticknamevalue = '';
2159 $tickidvalue = '';
2160 $eventidvalue = '';
2161 $tickdescvalue = '';
2162 $tickpricevalue = '';
2163 $tickstartvalue = '';
2164 $tickendvalue = '';
2165 $tickminvalue = '';
2166 $tickmaxvalue = '';
2167 $tickspacevalue = '';
2168 $tickmemvalue = '';
2169 $tickmemrolevalue = '';
2170 $tickguestvalue = '';
2171 $tickreqvalue = '';
2172 $tickparvalue = '';
2173 $tickordervalue = '';
2174 $tickmetavalue = '';
2175 $tickstartdays = '';
2176 $tickenddays = '';
2177 $tickstarttime = '';
2178 $tickendtime = '';
2179 $t=0;
2180
2181 foreach($ticket as $tic => $ticval){
2182 $ticknamevalue .= $ticval->ticket_name . ', ';
2183 $tickidvalue .=$ticval->ticket_id . ', ';
2184 $eventidvalue .=$ticval->event_id . ', ';
2185 $tickdescvalue .=$ticval->ticket_description . ', ';
2186 $tickpricevalue .=$ticval->ticket_price . ', ';
2187 $tickstartvalue .=$ticval->ticket_start . ', ';
2188 $tickendvalue .=$ticval->ticket_end . ', ';
2189 $tickminvalue .=$ticval->ticket_min . ', ';
2190 $tickmaxvalue .=$ticval->ticket_max . ', ';
2191 $tickspacevalue .=$ticval->ticket_spaces . ', ';
2192 $tickmemvalue .=$ticval->ticket_members . ', ';
2193 $tickmemroles =unserialize($ticval->ticket_members_roles);
2194 $tickmemroleval=implode('| ',(array)$tickmemroles);
2195 $tickmemrolevalue .=$tickmemroleval . ', ';
2196
2197
2198 $tickguestvalue .=$ticval->ticket_guests . ', ';
2199 $tickreqvalue .=$ticval->ticket_required . ', ';
2200 $tickparvalue .=$ticval->ticket_parent . ', ';
2201 $tickordervalue .=$ticval->ticket_order . ', ';
2202 $tickmetavalue .=$ticval->ticket_meta . ', ';
2203 $ticket[$t]=isset($ticket[$t])?$ticket[$t]:'';
2204 $ticket_meta= $ticket[$t];
2205 if(isset($ticket_meta->{'ticket_meta'})){
2206 $ticket_meta_value=$ticket_meta->{'ticket_meta'};
2207 }
2208 $ticket_meta_value=isset($ticket_meta_value)?$ticket_meta_value:'';
2209 if(!empty($ticket_meta_value)){
2210 $ticket_value=unserialize($ticket_meta_value);
2211 }
2212
2213 foreach($ticket_value as $tickval => $val){
2214 $tickstartdays .= $val['start_days'].', ';
2215 $tickenddays .= $val['end_days'].', ';
2216 $tickstarttime .= $val['start_time'].', ';
2217 $tickendtime .= $val['end_time'].', ';
2218 }
2219
2220 $ticknamevalues = rtrim($ticknamevalue, ', ');
2221 $tickidvalues = rtrim($tickidvalue, ', ');
2222 $eventidvalues=rtrim($eventidvalue, ', ');
2223 $tickdescvalues=rtrim($tickdescvalue, ', ');
2224 $tickpricevalues =rtrim($tickpricevalue, ', ');
2225 $tickstartvalues =rtrim($tickstartvalue, ', ');
2226 $tickendvalues =rtrim($tickendvalue, ', ');
2227 $tickminvalues =rtrim($tickminvalue, ', ');
2228 $tickmaxvalues =rtrim($tickmaxvalue, ', ');
2229 $tickspacevalues =rtrim($tickspacevalue, ', ');
2230 $tickmemvalues =rtrim($tickmemvalue, ', ');
2231 $tickmemrolevalues =rtrim($tickmemrolevalue, ', ');
2232 $tickguestvalues =rtrim($tickguestvalue, ', ');
2233 $tickreqvalues =rtrim($tickreqvalue, ', ');
2234 $tickparvalues =rtrim($tickparvalue, ', ');
2235 $tickordervalues =rtrim($tickordervalue, ', ');
2236 $tickmetavalues =rtrim($tickmetavalue, ', ');
2237 $tickstartdaysvalues = rtrim($tickstartdays, ', ');
2238 $tickenddaysvalues = rtrim($tickenddays, ', ');
2239 $tickstarttimevalues = rtrim($tickstarttime, ', ');
2240 $tickendtimevalues = rtrim($tickendtime, ', ');
2241
2242
2243 $tic_key1 = array('ticket_id', 'event_id', 'ticket_name','ticket_description','ticket_price','ticket_start','ticket_end','ticket_min','ticket_max','ticket_spaces','ticket_members','ticket_members_roles','ticket_guests','ticket_required','ticket_parent','ticket_order','ticket_meta','start_days','end_days','start_time','end_time');
2244 $tic_val1 = array($tickidvalues,$eventidvalues, $ticknamevalues,$tickdescvalues,$tickpricevalues,$tickstartvalues,$tickendvalues,$tickminvalues,$tickmaxvalues,$tickspacevalues,$tickmemvalues,$tickmemrolevalues,$tickguestvalues,$tickreqvalues,$tickparvalues,$tickordervalues,$tickmetavalues,$tickstartdaysvalues,$tickenddaysvalues,$tickstarttimevalues,$tickendtimevalues);
2245
2246 $tickets1 = array_combine($tic_key1,$tic_val1);
2247 $posts=array_merge((array)$posts,(array)$tickets1);
2248 $ticket_start[] = $ticval->ticket_start;
2249
2250 $ticket_start_date = '';
2251 $ticket_start_time ='';
2252 foreach( $ticket_start as $loc =>$locval){
2253 $date = strtotime($locval);
2254 $ticket_start_date .= date('Y-m-d', $date) . ', ';
2255
2256 $ticket_start_time .= date('H:i:s',$date) .', ';
2257
2258
2259 }
2260 $ticket_start_times = rtrim($ticket_start_time, ', ');
2261 $ticket_start_dates = rtrim($ticket_start_date, ', ');
2262 $ticket_end[] = trim($ticval->ticket_end);
2263 $ticket_end_time = '';
2264 $ticket_end_date = '';
2265 foreach($ticket_end as $loc => $locvalend){
2266 if(isset($locvalend) && !empty($locvalend)){
2267 $time = strtotime($locvalend);
2268 $ticket_end_date .= date('Y-m-d', $time) .', ';
2269 $ticket_end_time .= date('H:i:s',$time) .', ';
2270 }
2271
2272 }
2273 if(isset($ticket_start_date) && !empty($ticket_start_date)){
2274 $ticket_end_times = rtrim($ticket_end_time, ', ');
2275 $ticket_end_dates = rtrim($ticket_end_date, ', ');
2276 $tic_key = array('ticket_start_date', 'ticket_start_time', 'ticket_end_date','ticket_end_time');
2277 $tic_val = array($ticket_start_dates,$ticket_start_times, $ticket_end_dates,$ticket_end_times);
2278 $tickets = array_combine($tic_key,$tic_val);
2279 $posts=array_merge((array)$posts,(array)$tickets);
2280 }
2281
2282 }
2283
2284 }
2285 else{
2286 foreach($ticket as $tic => $ticval){
2287 $posts=array_merge((array)$posts,(array)$ticval);
2288 if(isset($ticval->ticket_start)){
2289 $ticket_start=$ticval->ticket_start;
2290 }
2291 if(is_array($ticket_value)){
2292 foreach($ticket_value as $tick => $val){
2293 $posts=array_merge((array)$posts,(array)$val);
2294 }
2295 }
2296 if(isset($ticket_start) && ($ticket_start != null)){
2297 $date = strtotime($ticket_start);
2298 $ticket_start_date = date('Y-m-d', $date);
2299 $ticket_start_time= date('H:i:s',$date);
2300 $ticket_end=$ticval->ticket_end;
2301 $time = strtotime($ticket_end);
2302 $ticket_end_date = date('Y-m-d', $time);
2303 $ticket_end_time= date('H:i:s',$time);
2304 $tic_key = array('ticket_start_date', 'ticket_start_time', 'ticket_end_date','ticket_end_time');
2305 $tic_val = array($ticket_start_date,$ticket_start_time, $ticket_end_date,$ticket_end_time);
2306 $tickets = array_combine($tic_key,$tic_val);
2307 $posts=array_merge((array)$posts,(array)$tickets);
2308
2309 }
2310 }
2311 }
2312
2313 }
2314
2315 //pods export
2316 $post_type = isset($posts->post_type) ? $posts->post_type : '';
2317 $p_type = $post_type;
2318 $posid = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts where post_name='$p_type' and post_type='_pods_pod'");
2319 foreach ($posid as $podid)
2320 {
2321 $pods_id = $podid->ID;
2322 $storage = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta where post_id=$pods_id AND meta_key='storage'");
2323 foreach ($storage as $pod_storage)
2324 {
2325 $pod_stype = $pod_storage->meta_value;
2326 }
2327 }
2328 if (isset($pod_stype) && $pod_stype == 'table')
2329 {
2330 $tab = 'pods_' . $p_type;
2331 $tab_val = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}$tab where id=$id");
2332 foreach ($tab_val as $table_key => $table_val)
2333 {
2334 $posts = array_merge((array)$posts, (array)$table_val);
2335 }
2336 }
2337
2338 foreach ($posts as $post_key => $post_value)
2339 {
2340 if ($post_key == 'post_status')
2341 {
2342 if (is_sticky($id))
2343 {
2344 $PostData[$post_key] = 'Sticky';
2345 $post_status = 'Sticky';
2346 }
2347 else
2348 {
2349 $PostData[$post_key] = $post_value;
2350 $post_status = $post_value;
2351 }
2352 }
2353 else
2354 {
2355 $PostData[$post_key] = $post_value;
2356 }
2357 if ($post_key == 'post_password')
2358 {
2359 if ($post_value)
2360 {
2361 $PostData['post_status'] = "{" . $post_value . "}";
2362 }
2363 else
2364 {
2365 $PostData['post_status'] = $post_status;
2366 }
2367 }
2368
2369 if ($post_key == 'post_author')
2370 {
2371 $user_info = get_userdata($post_value);
2372 $PostData['post_author'] = $user_info->user_login;
2373 }
2374 }
2375 }
2376 }
2377
2378 return $PostData;
2379 }
2380
2381 public function getWPMLData($id, $optional_type, $exp_module)
2382 {
2383 global $wpdb;
2384 global $sitepress;
2385 if($sitepress != null) {
2386 $icl_translation_table = $wpdb->prefix.'icl_translations';
2387
2388 $get_element_type = 'post_'.$optional_type;
2389 $args = array('element_id' => $id ,'element_type' => $get_element_type);
2390 $get_language_code = apply_filters( 'wpml_element_language_code', null, $args );
2391 $get_source_language = $wpdb->get_var("select source_language_code from {$icl_translation_table} where element_id ='{$id}' and language_code ='{$get_language_code}'");
2392
2393 $this->data[$id]['language_code'] = $get_language_code;
2394
2395 $get_trid = apply_filters( 'wpml_element_trid', NULL, $id,$get_element_type );
2396 $translations_query = $wpdb->prepare(
2397 "SELECT element_id
2398 FROM {$wpdb->prefix}icl_translations
2399 WHERE trid = %d
2400 AND language_code != %s", $get_trid, $get_language_code
2401 );
2402 $element_id = $wpdb->get_results( $translations_query );
2403 $translated_post_title = '';
2404 foreach ($element_id as $translation) {
2405 $element_id = $translation->element_id;
2406 if(trim($exp_module) == 'Posts' || trim($exp_module) == 'Pages'){
2407 $element_title = $wpdb->get_var("select post_title from $wpdb->posts where ID ='{$element_id}'");
2408 $translated_post_title .= $element_title.",";
2409 }
2410 }
2411 $this->data[$id]['translated_post_title'] = rtrim($translated_post_title, ",");
2412
2413
2414
2415 return $this->data[$id];
2416 }
2417 }
2418
2419 public function getAttachment($id)
2420 {
2421 global $wpdb;
2422 $get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $id, 'attachment');
2423 $attachment = $wpdb->get_results($get_attachment);
2424 $attachment_file = $attachment[0]->guid;
2425 return $attachment_file;
2426
2427 }
2428
2429 public function getRepeater($parent)
2430 {
2431 global $wpdb;
2432 $get_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts where post_parent = %d", $parent) , ARRAY_A);
2433 $i = 0;
2434 foreach ($get_fields as $key => $value)
2435 {
2436 $array[$i] = $value['post_excerpt'];
2437 $i++;
2438 }
2439 return $array;
2440 }
2441
2442 /**
2443 * Get types fields
2444 * @return array - Types fields
2445 */
2446 public function getTypesFields()
2447 {
2448 $getWPTypesFields = get_option('wpcf-fields');
2449 $typesFields = array();
2450 if (!empty($getWPTypesFields) && is_array($getWPTypesFields))
2451 {
2452 foreach ($getWPTypesFields as $fKey)
2453 {
2454 $typesFields[$fKey['meta_key']] = $fKey['name'];
2455 }
2456 }
2457 return $typesFields;
2458 }
2459
2460 /**
2461 * Final data to be export
2462 * @param $data - Data to be export based on the requested information
2463 * @return array - Final data to be export
2464 */
2465 public function finalDataToExport ($data, $module = false , $optionalType = false) {
2466 global $wpdb;
2467 $result = array();
2468 foreach ($this->headers as $key => $value)
2469 {
2470 if (empty($value))
2471 {
2472 unset($this->headers[$key]);
2473 }
2474 }
2475 // Fetch Category Custom Field Values
2476 if ($module)
2477 {
2478 if ($module == 'Categories')
2479 {
2480 return $this->fetchCategoryFieldValue($data, $this->module);
2481 }
2482 }
2483 foreach ( $data as $recordId => $rowValue ) {
2484 $optional_type = '';
2485 if(is_plugin_active('jet-engine/jet-engine.php')){
2486 global $wpdb;
2487 $get_slug_name = $wpdb->get_results("SELECT slug FROM {$wpdb->prefix}jet_post_types WHERE status = 'content-type'");
2488 foreach($get_slug_name as $key=>$get_slug){
2489 $value=$get_slug->slug;
2490 $optionaltype=$value;
2491 if($optionalType == $optionaltype){
2492 $optional_type=$optionaltype;
2493 }
2494 }
2495 }
2496
2497 foreach ($this->headers as $htemp => $hKey) {
2498 if(is_array($rowValue) && array_key_exists($hKey, $rowValue) && (!empty($rowValue[$hKey])) ){
2499
2500 if(!empty($optional_type) && $optionalType == $optional_type){
2501 if(is_plugin_active('jet-engine/jet-engine.php')){
2502 $result = $this->getJetCCTValue($data,$optionalType);
2503 if(is_array($result)){
2504 return $result;
2505 }
2506 else{
2507 $result[$recordId][$hKey] = $this->returnMetaValueAsCustomerInput($rowValue[$hKey], $hKey);return $result;
2508 }
2509 }
2510 }
2511 else{
2512 $result[$recordId][$hKey] = $this->returnMetaValueAsCustomerInput($rowValue[$hKey], $hKey);
2513 }
2514 }
2515 else
2516 {
2517 $key = $hKey;
2518 $rowValue['post_type'] = isset($rowValue['post_type']) ? $rowValue['post_type'] : '';
2519 // Replace the third party plugin name from the fieldname
2520 $key = $this->replace_prefix_aioseop_from_fieldname($key);
2521 $key = $this->replace_prefix_yoast_wpseo_from_fieldname($key);
2522 $key = $this->replace_prefix_wpcf_from_fieldname($key);
2523 $key = $this->replace_prefix_wpsc_from_fieldname($key);
2524 $key = $this->replace_underscore_from_fieldname($key);
2525 $key = $this->replace_wpcr3_from_fieldname($key);
2526 // Change fieldname depends on the post type
2527 $key = $this->change_fieldname_depends_on_post_type($rowValue['post_type'], $key);
2528
2529 if (isset($rowValue['wpcr3_' . $key]))
2530 {
2531 $rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['wpcr3_' . $key], $hKey);
2532 }
2533 else
2534 {
2535 if (isset($rowValue['_yoast_wpseo_' . $key]))
2536 { // Is available in yoast plugin
2537 $rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_yoast_wpseo_' . $key]);
2538 }
2539 else if (isset($rowValue['_aioseop_' . $key]))
2540 { // Is available in all seo plugin
2541 $rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_aioseop_' . $key]);
2542 }
2543 else if (isset($rowValue['_' . $key]))
2544 { // Is wp custom fields
2545 $rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_' . $key], $hKey);
2546 }
2547 else if ($fieldvalue = $this->getWoocommerceMetaValue($key, $rowValue['post_type'], $rowValue))
2548 {
2549 $rowValue[$key] = $fieldvalue;
2550 }
2551 else if (isset($rowValue['ID']) && $aioseo_field_value = $this->getaioseoFieldValue($rowValue['ID']))
2552 {
2553 $rowValue['og_title'] = $aioseo_field_value[0]->og_title;
2554 $rowValue['og_description'] = $aioseo_field_value[0]->og_description;
2555 $rowValue['custom_link'] = $aioseo_field_value[0]->canonical_url;
2556 $rowValue['og_image_type'] = $aioseo_field_value[0]->og_image_type;
2557 $rowValue['og_image_custom_url'] = $aioseo_field_value[0]->og_image_custom_url;
2558 $rowValue['og_image_custom_fields'] = $aioseo_field_value[0]->og_image_custom_fields;
2559 $rowValue['og_video'] = $aioseo_field_value[0]->og_video;
2560 $rowValue['og_object_type'] = $aioseo_field_value[0]->og_object_type;
2561 $value = $aioseo_field_value[0]->og_article_tags;
2562 $article_tags = json_decode($value);
2563 $og_article_tags = $article_tags[0]->value;
2564 $rowValue['og_article_tags'] = $og_article_tags;
2565 $rowValue['og_article_section'] = $aioseo_field_value[0]->og_article_section;
2566 $rowValue['twitter_use_og'] = $aioseo_field_value[0]->twitter_use_og;
2567 $rowValue['twitter_card'] = $aioseo_field_value[0]->twitter_card;
2568 $rowValue['twitter_image_type'] = $aioseo_field_value[0]->twitter_image_type;
2569 $rowValue['twitter_image_custom_url'] = $aioseo_field_value[0]->twitter_image_custom_url;
2570 $rowValue['twitter_image_custom_fields'] = $aioseo_field_value[0]->twitter_image_custom_fields;
2571 $rowValue['twitter_title'] = $aioseo_field_value[0]->twitter_title;
2572 $rowValue['twitter_description'] = $aioseo_field_value[0]->twitter_description;
2573 $rowValue['robots_default'] = $aioseo_field_value[0]->robots_default;
2574 // $rowValue['robots_noindex'] = $aioseo_field_value[0]->robots_noindex;
2575 $rowValue['robots_noarchive'] = $aioseo_field_value[0]->robots_noarchive;
2576 $rowValue['robots_nosnippet'] = $aioseo_field_value[0]->robots_nosnippet;
2577 // $rowValue['robots_nofollow'] = $aioseo_field_value[0]->robots_nofollow;
2578 $rowValue['robots_noimageindex'] = $aioseo_field_value[0]->robots_noimageindex;
2579 $rowValue['noodp'] = $aioseo_field_value[0]->robots_noodp;
2580 $rowValue['robots_notranslate'] = $aioseo_field_value[0]->robots_notranslate;
2581 $rowValue['robots_max_snippet'] = $aioseo_field_value[0]->robots_max_snippet;
2582 $rowValue['robots_max_videopreview'] = $aioseo_field_value[0]->robots_max_videopreview;
2583 $rowValue['robots_max_imagepreview'] = $aioseo_field_value[0]->robots_max_imagepreview;
2584 $rowValue['aioseo_title'] = $aioseo_field_value[0]->title;
2585 $rowValue['aioseo_description'] = $aioseo_field_value[0]->description;
2586 $key = $aioseo_field_value[0]->keyphrases;
2587
2588 $key1 = json_decode($key);
2589 $rowValue['keyphrases'] = $key1
2590 ->focus->keyphrase;
2591 }
2592 else
2593 {
2594 $rowValue[$key] = isset($rowValue[$key]) ? $rowValue[$key] : '';
2595 $rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue[$key], $hKey);
2596 }
2597 }
2598 global $wpdb;
2599 //Added for user export
2600 if ($key == 'user_login')
2601 {
2602 $wpsc_query = $wpdb->prepare("select ID from {$wpdb->prefix}users where user_login =%s", $rowValue['user_login']);
2603 $wpsc_meta = $wpdb->get_results($wpsc_query, ARRAY_A);
2604 }
2605 if (isset($rowValue['_bbp_forum_type']) && ($rowValue['_bbp_forum_type'] == 'forum' || $rowValue['_bbp_forum_type'] == 'category'))
2606 {
2607 if ($key == 'Visibility')
2608 {
2609 $rowValue[$key] = $rowValue['post_status'];
2610 }
2611 if ($key == 'bbp_moderators')
2612 {
2613 $get_forum_moderator_ids = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $recordId AND meta_key = '_bbp_moderator_id' ", ARRAY_A);
2614 $forum_moderators = '';
2615 foreach ($get_forum_moderator_ids as $get_moderator_id)
2616 {
2617 $forum_user_meta = get_user_by('id', $get_moderator_id['meta_value']);
2618 $forum_user = $forum_user_meta
2619 ->data->user_login;
2620 $forum_moderators .= $forum_user . ',';
2621 }
2622
2623 $rowValue[$key] = rtrim($forum_moderators, ',');
2624 }
2625
2626 }
2627 if ($key == 'topic_status' || $key == 'author' || $key == 'topic_type')
2628 {
2629 $rowValue['topic_status'] = $rowValue['post_status'];
2630 $rowValue['author'] = $rowValue['post_author'];
2631 if ($key == 'topic_type')
2632 {
2633 $Topictype = get_post_meta($rowValue['_bbp_forum_id'], '_bbp_sticky_topics');
2634 $topic_types = get_option('_bbp_super_sticky_topics');
2635 $rowValue['topic_type'] = 'normal';
2636 if ($Topictype)
2637 {
2638 foreach ($Topictype as $t_type)
2639 {
2640 if ($t_type['0'] == $recordId)
2641 {
2642 $rowValue['topic_type'] = 'sticky';
2643 }
2644 }
2645 }
2646 elseif (!empty($topic_types))
2647 {
2648 foreach ($topic_types as $top_type)
2649 {
2650 if ($top_type == $rowValue['ID'])
2651 {
2652 $rowValue['topic_type'] = 'super sticky';
2653 }
2654 }
2655 }
2656 }
2657 }
2658 if ($key == 'reply_status' || $key == 'reply_author')
2659 {
2660 $rowValue['reply_status'] = $rowValue['post_status'];
2661 $rowValue['reply_author'] = $rowValue['post_author'];
2662 }
2663 if (array_key_exists($hKey, $rowValue))
2664 {
2665 $result[$recordId][$hKey] = $rowValue[$hKey];
2666 }
2667 else
2668 {
2669 $result[$recordId][$hKey] = '';
2670 }
2671 }
2672 }
2673 }
2674 return $result;
2675 }
2676
2677 function get_common_post_metadata($meta_id)
2678 {
2679 global $wpdb;
2680 $mdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}usermeta WHERE umeta_id = %d", $meta_id) , ARRAY_A);
2681 return $mdata[0];
2682 }
2683
2684 function get_common_unserialize($serialize_data)
2685 {
2686 return unserialize($serialize_data);
2687 }
2688
2689 /**
2690 * Create CSV data from array
2691 * @param array $data 2D array with data
2692 * @param array $fields field names
2693 * @param bool $append if true, field names will not be output
2694 * @param bool $is_php if a php die() call should be put on the first
2695 * line of the file, this is later ignored when read.
2696 * @param null $delimiter field delimiter to use
2697 * @return string CSV data (text string)
2698 */
2699 public function unParse($data = array() , $fields = array() , $append = false, $is_php = false, $delimiter = null)
2700 {
2701 if (!is_array($data) || empty($data)) $data = & $this->data;
2702 if (!is_array($fields) || empty($fields)) $fields = & $this->titles;
2703 if ($delimiter === null) $delimiter = $this->delimiter;
2704
2705 $string = ($is_php) ? "<?php header('Status: 403'); die(' '); ?>" . $this->linefeed : '';
2706 $entry = array();
2707
2708 // create heading
2709 if ($this->offset == 0 || $this->checkSplit == 'true')
2710 {
2711 if ($this->heading && !$append && !empty($fields))
2712 {
2713 foreach ($fields as $key => $value)
2714 {
2715 $entry[] = $this->_enclose_value($value);
2716 }
2717 $string .= implode($delimiter, $entry) . $this->linefeed;
2718 $entry = array();
2719 }
2720 }
2721
2722 // create data
2723 foreach ($data as $key => $row)
2724 {
2725 foreach ($row as $field => $value)
2726 {
2727 $entry[] = $this->_enclose_value($value);
2728 }
2729 $string .= implode($delimiter, $entry) . $this->linefeed;
2730 $entry = array();
2731 }
2732 return $string;
2733 }
2734
2735 /**
2736 * Enclose values if needed
2737 * - only used by unParse()
2738 * @param null $value
2739 * @return mixed|null|string
2740 */
2741 public function _enclose_value($value = null)
2742 {
2743 if ($value !== null && $value != '')
2744 {
2745 $delimiter = preg_quote($this->delimiter, '/');
2746 $enclosure = preg_quote($this->enclosure, '/');
2747
2748 if ( is_array($value) && isset($value[0]) && $value[0] == '=' ) {
2749 $value = "'" . $value; // Fix for the comma-separated vulnerabilities.
2750 }
2751 // Add a check to ensure $value is not an object
2752 if ( isset($value) && is_string($value) && preg_match("/".$delimiter."|".$enclosure."|\n|\r/i", $value) ||
2753 !is_object($value) && isset($value[0]) && ($value[0] == ' ' || isset($value) && substr($value, -1) == ' ') ) {
2754 // Handle enclosure
2755 $value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value);
2756 $value = $this->enclosure.$value.$this->enclosure;
2757 }
2758 else{
2759 if(is_string($value) || is_numeric($value)){
2760 $value = $this->enclosure.$value.$this->enclosure;
2761 }
2762 else {
2763 $value = '';
2764 }
2765 }
2766 }
2767 return $value;
2768 }
2769
2770 /**
2771 * Apply exclusion before export
2772 * @param $headers - Apply exclusion headers
2773 * @return array - Available headers after applying the exclusions
2774 */
2775 public function applyEventExclusion($headers, $optionalType)
2776 {
2777 $header_exclusion = array();
2778 $exclusion = $this->eventExclusions['exclusion_headers']['header'];
2779 $this->eventExclusions['exclusion_headers']['header'] = $exclusion;
2780 $required_header = $this->eventExclusions['exclusion_headers']['header'];
2781
2782 if ($optionalType == 'elementor_library')
2783 {
2784 $required_head = array();
2785
2786 if (isset($required_header['ID']))
2787 {
2788 $required_head['ID'] = $required_header['ID'];
2789 }
2790 if (isset($required_header['Template title']))
2791 {
2792 $required_head['Template title'] = $required_header['Template title'];
2793 }
2794 if (isset($required_header['Template content']))
2795 {
2796 $required_head['Template content'] = $required_header['Template content'];
2797 }
2798 if (isset($required_header['Style']))
2799 {
2800 $required_head['Style'] = $required_header['Style'];
2801 }
2802 if (isset($required_header['Template type']))
2803 {
2804 $required_head['Template type'] = $required_header['Template type'];
2805 }
2806 if (isset($required_header['Created time']))
2807 {
2808 $required_head['Created time'] = $required_header['Created time'];
2809 }
2810 if (isset($required_header['Template status']))
2811 {
2812 $required_head['Template status'] = $required_header['Template status'];
2813 }
2814 if (isset($required_header['Category']))
2815 {
2816 $required_head['Category'] = $required_header['Category'];
2817 }
2818 if (isset($required_header['Created by']))
2819 {
2820 $required_head['Created by'] = $required_header['Created by'];
2821 }
2822 if (!empty($required_head))
2823 {
2824 foreach ($headers as $hVal)
2825 {
2826 if (array_key_exists($hVal, $required_head))
2827 {
2828 $header_exclusion[] = $hVal;
2829 }
2830 }
2831 return $header_exclusion;
2832 }
2833 else
2834 {
2835 return $headers;
2836 }
2837 }
2838 else
2839 {
2840 if (!empty($required_header))
2841 {
2842 foreach ($headers as $hVal)
2843 {
2844 if (array_key_exists($hVal, $required_header))
2845 {
2846 $header_exclusion[] = $hVal;
2847 }
2848 }
2849 return $header_exclusion;
2850 }
2851 else
2852 {
2853 return $headers;
2854 }
2855 }
2856 }
2857
2858 public function replace_prefix_aioseop_from_fieldname($fieldname)
2859 {
2860 if (preg_match('/_aioseop_/', $fieldname))
2861 {
2862 return preg_replace('/_aioseop_/', '', $fieldname);
2863 }
2864
2865 return $fieldname;
2866 }
2867 public function getaioseoFieldValue($post_id)
2868 {
2869 if (is_plugin_active('all-in-one-seo-pack/all_in_one_seo_pack.php') || is_plugin_active('all-in-one-seo-pack-pro/all_in_one_seo_pack.php'))
2870 {
2871 global $wpdb;
2872 $aioseo_slug = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}aioseo_posts WHERE post_id='$post_id' ");
2873 return $aioseo_slug;
2874 }
2875
2876 }
2877
2878 public function replace_prefix_pods_from_fieldname($fieldname)
2879 {
2880 if (preg_match('/_pods_/', $fieldname))
2881 {
2882 return preg_replace('/_pods_/', '', $fieldname);
2883 }
2884
2885 return $fieldname;
2886 }
2887
2888 public function replace_prefix_yoast_wpseo_from_fieldname($fieldname)
2889 {
2890
2891 if (preg_match('/_yoast_wpseo_/', $fieldname))
2892 {
2893 $fieldname = preg_replace('/_yoast_wpseo_/', '', $fieldname);
2894
2895 if ($fieldname == 'focuskw')
2896 {
2897 $fieldname = 'focus_keyword';
2898 }
2899 else if ($fieldname == 'bread-crumbs-title')
2900 { // It is comming as bctitle nowadays
2901 $fieldname = 'bctitle';
2902 }
2903 elseif ($fieldname == 'metadesc')
2904 {
2905 $fieldname = 'meta_desc';
2906 }
2907 }
2908
2909 return $fieldname;
2910 }
2911
2912 public function replace_prefix_wpcf_from_fieldname($fieldname)
2913 {
2914 if (preg_match('/_wpcf/', $fieldname))
2915 {
2916 return preg_replace('/_wpcf/', '', $fieldname);
2917 }
2918
2919 return $fieldname;
2920 }
2921
2922 public function replace_prefix_wpsc_from_fieldname($fieldname)
2923 {
2924 if (preg_match('/_wpsc_/', $fieldname))
2925 {
2926 return preg_replace('/_wpsc_/', '', $fieldname);
2927 }
2928
2929 return $fieldname;
2930 }
2931
2932 public function replace_wpcr3_from_fieldname($fieldname)
2933 {
2934 if (preg_match('/wpcr3_/', $fieldname))
2935 {
2936 $fieldname = preg_replace('/wpcr3_/', '', $fieldname);
2937 }
2938
2939 return $fieldname;
2940 }
2941
2942 public function change_fieldname_depends_on_post_type($post_type, $fieldname)
2943 {
2944 if ($post_type == 'wpcr3_review')
2945 {
2946 switch ($fieldname)
2947 {
2948 case 'ID':
2949 return 'review_id';
2950 case 'post_status':
2951 return 'status';
2952 case 'post_content':
2953 return 'review_text';
2954 case 'post_date':
2955 return 'date_time';
2956 default:
2957 return $fieldname;
2958 }
2959 }
2960 if ($post_type == 'shop_order_refund')
2961 {
2962 switch ($fieldname)
2963 {
2964 case 'ID':
2965 return 'REFUNDID';
2966 default:
2967 return $fieldname;
2968 }
2969 }
2970 else if ($post_type == 'shop_order')
2971 {
2972 switch ($fieldname)
2973 {
2974 case 'ID':
2975 return 'ORDERID';
2976 case 'post_status':
2977 return 'order_status';
2978 case 'post_excerpt':
2979 return 'customer_note';
2980 case 'post_date':
2981 return 'order_date';
2982 default:
2983 return $fieldname;
2984 }
2985 }
2986 else if ($post_type == 'shop_coupon')
2987 {
2988 switch ($fieldname)
2989 {
2990 case 'ID':
2991 return 'COUPONID';
2992 case 'post_status':
2993 return 'coupon_status';
2994 case 'post_excerpt':
2995 return 'description';
2996 case 'post_date':
2997 return 'coupon_date';
2998 case 'post_title':
2999 return 'coupon_code';
3000 default:
3001 return $fieldname;
3002 }
3003 }
3004 else if ($post_type == 'product_variation')
3005 {
3006 switch ($fieldname)
3007 {
3008 case 'ID':
3009 return 'VARIATIONID';
3010 case 'post_parent':
3011 return 'PRODUCTID';
3012 case 'sku':
3013 return 'VARIATIONSKU';
3014 default:
3015 return $fieldname;
3016 }
3017 }
3018
3019 return $fieldname;
3020 }
3021
3022 public function replace_underscore_from_fieldname($fieldname)
3023 {
3024 if (preg_match('/_/', $fieldname))
3025 {
3026 $fieldname = preg_replace('/^_/', '', $fieldname);
3027 }
3028
3029 return $fieldname;
3030 }
3031
3032 public function fetchCategoryFieldValue($categories)
3033 {
3034
3035 global $wpdb;
3036 $bulk_category = [];
3037
3038 foreach ($categories as $category_id => $category)
3039 {
3040 $term_meta = get_term_meta($category_id);
3041 $single_category = [];
3042 foreach ($this->headers as $header)
3043 {
3044
3045 if ($header == 'name')
3046 {
3047 $cato[] = get_term($category_id);
3048 $single_category[$header] = $this->hierarchy_based_term_cat_name($cato, 'category');
3049 continue;
3050 }
3051
3052 if (array_key_exists($header, $category))
3053 {
3054 $single_category[$header] = $category[$header];
3055 }
3056 else
3057 {
3058 if (isset($term_meta[$header]))
3059 {
3060 $single_category[$header] = $this->returnMetaValueAsCustomerInput($term_meta[$header]);
3061 }
3062 else
3063 {
3064 $single_category[$header] = null;
3065 }
3066 }
3067 }
3068 array_push($bulk_category, $single_category);
3069 }
3070 return $bulk_category;
3071 }
3072 public function getJetCCTValue($data, $type, $data_type = false){
3073 global $wpdb;
3074 $jet_data = $this->JetEngineCCTFields($type);
3075 $darray_value=array();
3076 $darray2 = array();
3077 $cct_rel = [];
3078
3079 foreach ($data as $key => $dvalue) {
3080 $get_guid ='';
3081 $select_value='';
3082 $checkbox_key_value='';
3083 $checkbox_key_value1 ='';
3084 foreach($dvalue as $dkey=>$value){
3085 if($dkey == '_ID'){
3086 $darray[$dkey] = $value;
3087 }
3088 elseif($dkey =='cct_status'){
3089 $darray[$dkey] = $value;
3090 }
3091
3092 //JET CCT Relation
3093 if(!empty($jet_data)){
3094 if(in_array($dkey,$this->headers) && !array_key_exists($dkey,$jet_data['JECCT']) ){
3095 $cct_rel[$key][$dkey] = $data[$key][$dkey];
3096 }
3097
3098 if(array_key_exists($dkey,$jet_data['JECCT'])){
3099 if(empty($value)) {
3100 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3101 }
3102 else {
3103 if($jet_data['JECCT'][$dkey]['type'] == 'text'){
3104 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3105 }
3106 elseif($jet_data['JECCT'][$dkey]['type'] == 'textarea'){
3107 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3108 }
3109 elseif($jet_data['JECCT'][$dkey]['type'] == 'colorpicker'){
3110 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3111 }
3112 elseif($jet_data['JECCT'][$dkey]['type'] == 'iconpicker'){
3113 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3114 }
3115 elseif($jet_data['JECCT'][$dkey]['type'] == 'radio'){
3116 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3117 }
3118 elseif($jet_data['JECCT'][$dkey]['type'] == 'number'){
3119 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3120 }
3121 elseif($jet_data['JECCT'][$dkey]['type'] == 'wysiwyg'){
3122 $value = preg_replace('/\s+/', ' ', $value);
3123
3124 // Minify the HTML content
3125 $value = trim($value);
3126 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3127 }
3128 elseif($jet_data['JECCT'][$dkey]['type'] == 'switcher'){
3129 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3130 }
3131 elseif($jet_data['JECCT'][$dkey]['type'] == 'time'){
3132 $darray1[$jet_data['JECCT'][$dkey]['name']] = $value;
3133 }
3134 elseif( $jet_data['JECCT'][$dkey]['type'] == 'media'){
3135 if(is_numeric($value)){
3136 if($value != 0) {
3137 $get_guid_name = $wpdb->get_results("SELECT guid FROM {$wpdb->prefix}posts WHERE id = '$value'");
3138 foreach($get_guid_name as $media_key=>$value){
3139 $darray1[$jet_data['JECCT'][$dkey]['name']]=$value->guid;
3140 }
3141 }
3142 else {
3143
3144 $darray1[$jet_data['JECCT'][$dkey]['name']]=$value;
3145 }
3146 }
3147 elseif(is_serialized($value)){
3148 $media_value=unserialize($value);
3149 $darray1[$jet_data['JECCT'][$dkey]['name']] = $media_value['url'];
3150 }
3151 else{
3152 $media_field_val=$value;
3153 $darray1[$jet_data['JECCT'][$dkey]['name']]=$media_field_val;
3154 }
3155 }
3156 elseif( $jet_data['JECCT'][$dkey]['type'] == 'gallery'){
3157 $get_meta_list = explode(',', $value);
3158 $get_guid ='';
3159 foreach($get_meta_list as $get_meta){
3160 if(is_numeric($get_meta)){
3161 $get_guid_name = $wpdb->get_results("SELECT guid FROM {$wpdb->prefix}posts WHERE id = '$get_meta'");
3162 foreach($get_guid_name as $gallery_key=>$value){
3163 $get_guid.=$value->guid.',';
3164 }
3165 }
3166 elseif(is_serialized($get_meta)){
3167 $gal_value=unserialize($get_meta);
3168 foreach($gal_value as $gal_key1=>$gal_val){
3169 $get_guid.=$gal_val['url'].',';
3170 }
3171 }
3172 else{
3173 $get_guid .= $get_meta.',';
3174 }
3175 }
3176 $darray1[$jet_data['JECCT'][$dkey]['name']]=rtrim($get_guid,',');
3177 }
3178
3179 elseif($jet_data['JECCT'][$dkey]['type'] == 'date'){
3180 if(!empty($value)){
3181 if(strpos($value, '-') !== FALSE){
3182 $date_value= $value;
3183 }else{
3184 $date_value = date('Y-m-d', $value);
3185 }
3186 }
3187 $darray1[$jet_data['JECCT'][$dkey]['name']] = $date_value;
3188 }
3189
3190 elseif($jet_data['JECCT'][$dkey]['type'] == 'datetime-local'){
3191 if(!empty($value)){
3192 if(strpos($value, '-') !== FALSE){
3193 $datetime_value = $value;
3194 }else{
3195 $datetime_value = date('Y-m-d H:i', $value);
3196 }
3197 $datetime_value = str_replace(' ', 'T', $datetime_value);
3198 }
3199 $darray1[$jet_data['JECCT'][$dkey]['name']] = $datetime_value;
3200 }
3201
3202 elseif($jet_data['JECCT'][$dkey]['type'] == 'checkbox'){
3203 if($jet_data['JECCT'][$dkey]['is_array'] == 1){
3204 $checkbox_value=unserialize($value);
3205 if (is_array($checkbox_value)) {
3206 $darray1[$jet_data['JECCT'][$dkey]['name']] = implode(',', $checkbox_value);
3207 } else {
3208 $darray1[$jet_data['JECCT'][$dkey]['name']] = ''; // or handle as needed
3209 }
3210 }
3211 else{
3212 $checkbox_value=unserialize($value);
3213 $checkbox_key_value='';
3214 foreach($checkbox_value as $check_key=>$check_val){
3215 if($check_val == 'true'){
3216 $checkbox_key_value.=$check_key.',';
3217 }
3218 }
3219 $darray1[$jet_data['JECCT'][$dkey]['name']] = rtrim($checkbox_key_value,',');
3220 }
3221 }
3222
3223 elseif($jet_data['JECCT'][$dkey]['type'] == 'posts'){
3224 if(is_serialized($value)){
3225 $jet_posts = unserialize($value);
3226 $jet_posts_value='';
3227 foreach($jet_posts as $posts_key=>$post_val){
3228 $query = "SELECT post_title FROM {$wpdb->prefix}posts WHERE id ='{$post_val}' AND post_status='publish'";
3229 $name = $wpdb->get_results($query);
3230 if (!empty($name)) {
3231 $jet_posts_value.=$name[0]->post_title.',';
3232 }
3233 }
3234 $post_names=rtrim($jet_posts_value,',');
3235 }
3236 else{
3237 $query = "SELECT post_title FROM {$wpdb->prefix}posts WHERE id ='{$value}' AND post_status='publish'";
3238 $name = $wpdb->get_results($query);
3239 if (!empty($name)) {
3240 $post_names=$name[0]->post_title;
3241 }
3242 }
3243 $darray1[$jet_data['JECCT'][$dkey]['name']] = $post_names;
3244 }
3245 elseif($jet_data['JECCT'][$dkey]['type'] == 'select'){
3246 if(is_serialized($value)){
3247 $select_value='';
3248 $gal_value=unserialize($value);
3249 foreach($gal_value as $select_key=>$gal_val){
3250 $select_value.=$gal_val.',';
3251 }
3252 }
3253 else{
3254 $select_val=$value;
3255 $select_value=$select_val;
3256 }
3257
3258 $darray1[$jet_data['JECCT'][$dkey]['name']] = rtrim($select_value,',');
3259 }
3260 }
3261 }
3262
3263 }
3264 }
3265 if(!empty($darray1) && empty($darray2)){
3266 $data_array_values=array_merge($darray,$darray1);
3267 }
3268 elseif(empty($darray1) && !empty($darray2)){
3269 $data_array_values=array_merge($darray,$darray2);
3270 }
3271 else if (!empty($darray1) && !empty($darray2)){
3272 $data_array_values=array_merge($darray,$darray1,$darray2);
3273 }
3274
3275 $darray_value[$key]=$data_array_values;
3276 }
3277 //CCT Relation
3278 if(!empty($cct_rel) && !empty($darray_value)){
3279 foreach($cct_rel as $id => $value){
3280 unset($value['_ID']);
3281 unset($value['cct_status']);
3282 $get_val = $darray_value[$id];
3283 $all_data[$id] = array_merge($get_val,$value);
3284 }
3285 $darray_value = $all_data;
3286 }
3287 //End CCT Relation
3288 //For correct the CSV columns
3289 foreach($this->headers as $row_header){
3290 foreach($darray_value as $key => $value){
3291 if(!empty($value)){
3292 if(array_key_exists($row_header,$value)){
3293 $new_data[$key][$row_header] = $value[$row_header];
3294 }
3295 else {
3296 $new_data[$key][$row_header] = $value[$row_header];
3297 }
3298 }
3299 }
3300 }
3301 $darray_value = $new_data;
3302 //added
3303 if(!empty($darray_value)){
3304 return $darray_value;
3305 }
3306 else{
3307 return ;
3308 }
3309 }
3310 public function JetEngineCCTFields($type){
3311 global $wpdb;
3312 $jet_field = array();
3313 $customFields = [];
3314 $get_meta_fields = $wpdb->get_results($wpdb->prepare("select id, meta_fields from {$wpdb->prefix}jet_post_types where slug = %s and status = %s", $type, 'content-type'));
3315
3316 if(!empty($get_meta_fields)){
3317 $unserialized_meta = maybe_unserialize($get_meta_fields[0]->meta_fields);
3318
3319 foreach($unserialized_meta as $jet_key => $jet_value){
3320 $customFields["JECCT"][ $jet_value['name']]['label'] = $jet_value['title'];
3321 $customFields["JECCT"][ $jet_value['name']]['name'] = $jet_value['name'];
3322 $customFields["JECCT"][ $jet_value['name']]['type'] = $jet_value['type'];
3323 $customFields["JECCT"][ $jet_value['name']]['options'] = isset($jet_value['options']) ? $jet_value['options'] : '';
3324 $customFields["JECCT"][ $jet_value['name']]['is_multiple'] = isset($jet_value['is_multiple']) ? $jet_value['is_multiple'] : '';
3325 $customFields["JECCT"][ $jet_value['name']]['is_array'] = isset($jet_value['is_array']) ? $jet_value['is_array'] : '';
3326 $jet_field[] = $jet_value['name'];
3327 }
3328 }
3329 return $customFields;
3330 }
3331
3332 public function returnMetaValueAsCustomerInput($meta_value, $header = false)
3333 {
3334 if ($header == 'rating_data') {
3335 return $meta_value;
3336 }
3337 if ($header != 'jet_abaf_price' && $header != 'jet_abaf_custom_schedule' && $header != 'jet_abaf_configuration' && $header != '_elementor_css' && $header != '_elementor_controls_usage' && $header != 'elementor_library_category' && $header != '_elementor_page_assets' && $header != '_elementor_page_settings' && $header != '_elementor_data'){
3338
3339 if (is_array($meta_value))
3340 {
3341 $meta_value = $meta_value[0];
3342 if (!empty($meta_value))
3343 {
3344 if (is_serialized($meta_value))
3345 {
3346 return unserialize($meta_value);
3347 }
3348 else if (is_array($meta_value))
3349 {
3350 return implode('|', $meta_value);
3351 }
3352 else if (is_string($meta_value))
3353 {
3354 return $meta_value;
3355 }
3356 else if ($this->isJSON($meta_value) === true)
3357 {
3358 return json_decode($meta_value);
3359 }
3360
3361 return $meta_value;
3362 }
3363
3364 return $meta_value;
3365 }
3366 else
3367 {
3368 if (is_serialized($meta_value))
3369 {
3370 $meta_value = unserialize($meta_value);
3371 if (is_array($meta_value))
3372 {
3373 $meta_value = array_map('strval', $meta_value);
3374 return implode('|', $meta_value);
3375 }
3376 return $meta_value;
3377 }
3378 else if (is_array($meta_value))
3379 {
3380 return implode('|', $meta_value);
3381 }
3382 else if (is_string($meta_value))
3383 {
3384 return $meta_value;
3385 }
3386 else if ($this->isJSON($meta_value) === true)
3387 {
3388 return json_decode($meta_value);
3389 }
3390 }
3391 }
3392 elseif($header == '_elementor_data'){
3393 $meta_value = base64_encode($meta_value);
3394 }
3395
3396
3397 return $meta_value;
3398 }
3399
3400 public function isJSON($meta_value)
3401 {
3402 $json = json_decode($meta_value);
3403 return $json && $meta_value != $json;
3404 }
3405
3406 public function hierarchy_based_term_name($term, $taxanomy_type)
3407 {
3408
3409 $tempo = array();
3410 $termo = '';
3411 $i = 0;
3412 foreach ($term as $termkey => $terms)
3413 {
3414 $tempo[] = $terms->name;
3415 $temp_hierarchy_terms = [];
3416
3417 if (!empty($terms->parent))
3418 {
3419 $temp1 = $terms->name;
3420 $i++;
3421
3422 $termexp = explode(',', $termo);
3423
3424 $termo = implode(',', $termexp);
3425 $temp_hierarchy_terms[] = $terms->name;
3426 $hierarchy_terms = $this->call_back_to_get_parent($terms->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms);
3427 $parent_name = get_term($terms->parent);
3428 $termo .= $this->split_terms_by_arrow($hierarchy_terms, $parent_name->name) . ',';
3429
3430 }
3431 else
3432 {
3433
3434 if (in_array($terms->name, $tempo))
3435 {
3436
3437 $termo .= $terms->name . ',';
3438
3439 }
3440 }
3441 }
3442 return $termo;
3443
3444 }
3445
3446 public function hierarchy_based_term_cat_name($term, $taxanomy_type)
3447 {
3448 $tempo = array();
3449 $termo = '';
3450 foreach ($term as $terms)
3451 {
3452 $tempo[] = $terms->name;
3453 $temp_hierarchy_terms = [];
3454 if (!empty($terms->parent))
3455 {
3456 $temp_hierarchy_terms[] = $terms->name;
3457 $hierarchy_terms = $this->call_back_to_get_parent($terms->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms);
3458 $parent_name = get_term($terms->parent);
3459 $termo = $this->split_terms_by_arrow($hierarchy_terms, $parent_name->name);
3460
3461 }
3462 else
3463 {
3464 $termo = $terms->name;
3465
3466 }
3467 }
3468 return $termo;
3469 }
3470 public function call_back_to_get_parent($term_id, $taxanomy_type, $tempo, $temp_hierarchy_terms = [])
3471 {
3472 $term = get_term($term_id, $taxanomy_type);
3473 if (!empty($term->parent))
3474 {
3475 if (in_array($term->name, $tempo))
3476 {
3477
3478 $temp_hierarchy_terms[] = $term->name;
3479
3480 $temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms);
3481 }
3482 else
3483 {
3484 $temp_hierarchy_terms[] = '';
3485
3486 $temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms);
3487 }
3488
3489 }
3490 else
3491 {
3492 if (in_array($term->name, $tempo))
3493 {
3494 $temp_hierarchy_terms[] = $term->name;
3495 }
3496 else
3497 {
3498 $temp_hierarchy_terms[] = '';
3499 }
3500 }
3501 return $temp_hierarchy_terms;
3502 }
3503 // public function call_back_to_get_parent($term_id, $taxanomy_type, $temp_hierarchy_terms = []){
3504 // $term = get_term($term_id, $taxanomy_type);
3505 // if(!empty($term->parent)){
3506 // $temp_hierarchy_terms[] = $term->name;
3507 // $temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type, $temp_hierarchy_terms);
3508 // }else{
3509 // $temp_hierarchy_terms[] = $term->name;
3510 // }
3511 // return $temp_hierarchy_terms;
3512 // }
3513 public function split_terms_by_arrow($hierarchy_terms, $termParentName)
3514 {
3515
3516 krsort($hierarchy_terms);
3517 $terms_value = $termParentName . '>' . $hierarchy_terms[0];
3518 //return implode('>', $hierarchy_terms);
3519 return $terms_value;
3520 }
3521
3522 public function getWoocommerceMetaValue($fieldname, $post_type, $post)
3523 {
3524 $post_type = isset($post_type) ? $post_type : '';
3525 if ($post_type == 'shop_order_refund')
3526 {
3527 switch ($fieldname)
3528 {
3529 case 'REFUNDID':
3530 return $post['ID'];
3531 default:
3532 return $post[$fieldname];
3533 }
3534 }
3535 else if ($post_type == 'shop_order')
3536 {
3537 switch ($fieldname)
3538 {
3539 case 'ORDERID':
3540 return $post['ID'];
3541 case 'order_status':
3542 return $post['post_status'];
3543 case 'customer_note':
3544 return $post['post_excerpt'];
3545 case 'order_date':
3546 return $post['post_date'];
3547 default:
3548 return $post[$fieldname];
3549 }
3550 }
3551 else if ($post_type == 'shop_coupon')
3552 {
3553 switch ($fieldname)
3554 {
3555 case 'COUPONID':
3556 return $post['ID'];
3557 case 'coupon_status':
3558 return $post['post_status'];
3559 case 'description':
3560 return $post['post_excerpt'];
3561 case 'coupon_date':
3562 return $post['post_date'];
3563 case 'coupon_code':
3564 return $post['post_title'];
3565 case 'expiry_date':
3566 if (isset($post['date_expires']))
3567 {
3568 $timeinfo = date('m/d/Y', $post['date_expires']);
3569 }
3570 $timeinfo = isset($timeinfo) ? $timeinfo : '';
3571 return $timeinfo;
3572 default:
3573 return $post[$fieldname];
3574 }
3575 }
3576 else if ($post_type == 'product_variation')
3577 {
3578 switch ($fieldname)
3579 {
3580 case 'VARIATIONID':
3581 return $post['ID'];
3582 case 'PRODUCTID':
3583 return $post['post_parent'];
3584 case 'VARIATIONSKU':
3585 return $post['sku'];
3586 default:
3587 return $post[$fieldname];
3588 }
3589 }
3590 return false;
3591 }
3592
3593 }
3594
3595 return new exportExtension();
3596 }
3597
3598