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