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