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

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