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

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

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