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

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