| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP Ultimate Exporter plugin file. |
| 4 |
* |
| 5 |
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Smackcoders\SMEXP; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) |
| 11 |
exit; // Exit if accessed directly |
| 12 |
|
| 13 |
if(class_exists('\Smackcoders\FCSV\MappingExtension')){ |
| 14 |
|
| 15 |
class ExportExtension extends \Smackcoders\FCSV\MappingExtension{ |
| 16 |
|
| 17 |
public $response = array(); |
| 18 |
public $headers = array(); |
| 19 |
public $module; |
| 20 |
public $exportType = 'csv'; |
| 21 |
public $optionalType = null; |
| 22 |
public $conditions = array(); |
| 23 |
public $eventExclusions = array(); |
| 24 |
public $fileName; |
| 25 |
public $data = array(); |
| 26 |
public $heading = true; |
| 27 |
public $delimiter = ','; |
| 28 |
public $enclosure = '"'; |
| 29 |
public $auto_preferred = ",;\t.:|"; |
| 30 |
public $output_delimiter = ','; |
| 31 |
public $linefeed = "\r\n"; |
| 32 |
public $export_mode; |
| 33 |
public $export_log = array(); |
| 34 |
public $limit; |
| 35 |
protected static $instance = null,$mapping_instance,$metabox_export,$jetengine_export,$export_handler,$post_export,$woocom_export,$review_export,$ecom_export,$learnpress_export; |
| 36 |
protected $plugin,$activateCrm,$crmFunctionInstance; |
| 37 |
public $plugisnScreenHookSuffix=null; |
| 38 |
|
| 39 |
public static function getInstance() { |
| 40 |
if ( null == self::$instance ) { |
| 41 |
self::$instance = new self; |
| 42 |
ExportExtension::$export_handler = ExportHandler::getInstance(); |
| 43 |
ExportExtension::$post_export = PostExport::getInstance(); |
| 44 |
ExportExtension::$woocom_export = WooCommerceExport::getInstance(); |
| 45 |
ExportExtension::$review_export = CustomerReviewExport::getInstance(); |
| 46 |
ExportExtension::$learnpress_export = LearnPressExport::getInstance(); |
| 47 |
ExportExtension::$jetengine_export = JetEngineExport::getInstance(); |
| 48 |
ExportExtension::$metabox_export = metabox::getInstance(); |
| 49 |
self::$instance->doHooks(); |
| 50 |
} |
| 51 |
return self::$instance; |
| 52 |
} |
| 53 |
|
| 54 |
public function doHooks(){ |
| 55 |
$plugin_pages = ['com.smackcoders.csvimporternew.menu']; |
| 56 |
require_once WP_PLUGIN_DIR . '/wp-ultimate-exporter/wp-exp-hooks.php'; |
| 57 |
global $plugin_ajax_hooks; |
| 58 |
|
| 59 |
$request_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : ''; |
| 60 |
$request_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 61 |
if (in_array($request_page, $plugin_pages) || in_array($request_action, $plugin_ajax_hooks)) { |
| 62 |
add_action('wp_ajax_parse_data',array($this,'parseData')); |
| 63 |
add_action('wp_ajax_total_records', array($this, 'totalRecords')); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
public function totalRecords(){ |
| 69 |
check_ajax_referer('smack-ultimate-csv-importer', 'securekey'); |
| 70 |
global $wpdb; |
| 71 |
//$module = 'WooCommerce'; |
| 72 |
$module = sanitize_text_field($_POST['module']); |
| 73 |
//$_POST['optionalType'] = ''; |
| 74 |
// $optionalType = sanitize_text_field($_POST['optionalType']); |
| 75 |
$optionalType = isset($_POST['optionalType'])?sanitize_text_field($_POST['optionalType']):''; |
| 76 |
if ($module == 'WooCommerceOrders') { |
| 77 |
$module = 'shop_order'; |
| 78 |
} |
| 79 |
elseif ($module == 'WooCommerceCoupons') { |
| 80 |
$module = 'shop_coupon'; |
| 81 |
} |
| 82 |
elseif ($module == 'WooCommerceRefunds') { |
| 83 |
$module = 'shop_order_refund'; |
| 84 |
} |
| 85 |
elseif ($module == 'WooCommerceVariations') { |
| 86 |
$module = 'product_variation'; |
| 87 |
} |
| 88 |
elseif($module == 'WPeCommerceCoupons'){ |
| 89 |
$module = 'wpsc-coupon'; |
| 90 |
} |
| 91 |
elseif($module == 'Users'){ |
| 92 |
$get_available_user_ids = "select DISTINCT ID from $wpdb->users u join $wpdb->usermeta um on um.user_id = u.ID"; |
| 93 |
$availableUsers = $wpdb->get_col($get_available_user_ids); |
| 94 |
$total = count($availableUsers); |
| 95 |
return $total; |
| 96 |
} |
| 97 |
elseif($module == 'Tags'){ |
| 98 |
$get_all_terms = get_tags('hide_empty=0'); |
| 99 |
return count($get_all_terms); |
| 100 |
wp_die(); |
| 101 |
} |
| 102 |
elseif($module == 'Categories'){ |
| 103 |
$get_all_terms = get_categories('hide_empty=0'); |
| 104 |
return count($get_all_terms); |
| 105 |
wp_die(); |
| 106 |
} |
| 107 |
elseif($module == 'CustomPosts' && $optionalType == 'nav_menu_item'){ |
| 108 |
$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); |
| 109 |
echo wp_json_encode(count($get_menu_ids)); |
| 110 |
wp_die(); |
| 111 |
} |
| 112 |
// elseif($module == 'CustomPosts' && $optionalType == 'widgets'){ |
| 113 |
// echo wp_json_encode(1); |
| 114 |
// wp_die(); |
| 115 |
// } |
| 116 |
else { |
| 117 |
$optional_type = NULL; |
| 118 |
if($module == 'CustomPosts') { |
| 119 |
$optional_type = $optionalType; |
| 120 |
} |
| 121 |
$module = ExportExtension::$post_export->import_post_types($module,$optional_type); |
| 122 |
} |
| 123 |
|
| 124 |
$get_post_ids = "select DISTINCT ID from $wpdb->posts"; |
| 125 |
$get_post_ids .= " where post_type = '$module'"; |
| 126 |
|
| 127 |
/** |
| 128 |
* Check for specific status |
| 129 |
*/ |
| 130 |
if($module == 'shop_order'){ |
| 131 |
$get_post_ids .= " and post_status in ('wc-completed','wc-cancelled','wc-on-hold','wc-processing','wc-pending')"; |
| 132 |
|
| 133 |
}elseif ($module == 'shop_coupon') { |
| 134 |
$get_post_ids .= " and post_status in ('publish','draft','pending')"; |
| 135 |
|
| 136 |
}elseif ($module == 'shop_order_refund') { |
| 137 |
|
| 138 |
}elseif ($module == 'forum') { |
| 139 |
$get_post_ids .= " and post_status in ('publish','draft','future','private','pending','hidden')"; |
| 140 |
} |
| 141 |
elseif ($module == 'topic') { |
| 142 |
$get_post_ids .= " and post_status in ('publish','draft','future','open','pending','closed','spam')"; |
| 143 |
} |
| 144 |
elseif ($module == 'reply') { |
| 145 |
$get_post_ids .= " and post_status in ('publish','spam','pending')"; |
| 146 |
} |
| 147 |
$get_post_ids .= " and post_status in ('publish','draft','future','private','pending')"; |
| 148 |
$get_total_row_count = $wpdb->get_col($get_post_ids); |
| 149 |
$total = count($get_total_row_count); |
| 150 |
return $total; |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* ExportExtension constructor. |
| 155 |
* Set values into global variables based on post value |
| 156 |
*/ |
| 157 |
public function __construct() { |
| 158 |
$this->plugin = Plugin::getInstance(); |
| 159 |
} |
| 160 |
|
| 161 |
public function parseData(){ |
| 162 |
check_ajax_referer('smack-ultimate-csv-importer', 'securekey'); |
| 163 |
if(!empty($_POST)) { |
| 164 |
|
| 165 |
$this->module = sanitize_text_field($_POST['module']); |
| 166 |
$this->exportType = isset( $_POST['exp_type'] ) ? sanitize_text_field( $_POST['exp_type'] ) : 'csv'; |
| 167 |
$conditions = str_replace("\\" , '' , sanitize_text_field($_POST['conditions'])); |
| 168 |
$conditions = json_decode($conditions, True); |
| 169 |
$conditions['specific_period']['to'] = date("Y-m-d", strtotime($conditions['specific_period']['to']) ); |
| 170 |
$conditions['specific_period']['from'] = date("Y-m-d", strtotime($conditions['specific_period']['from']) ); |
| 171 |
$this->conditions = isset( $conditions ) && ! empty( $conditions ) ? $conditions : array(); |
| 172 |
if($this->module == 'Taxonomies' || $this->module == 'CustomPosts' ){ |
| 173 |
$this->optionalType = sanitize_text_field($_POST['optionalType']); |
| 174 |
} |
| 175 |
else{ |
| 176 |
$this->optionalType = $this->getOptionalType($this->module); |
| 177 |
} |
| 178 |
$eventExclusions = str_replace("\\" , '' , sanitize_text_field(isset($_POST['eventExclusions']) ? sanitize_text_field($_POST['eventExclusions']) :'')); |
| 179 |
$eventExclusions = json_decode($eventExclusions, True); |
| 180 |
$this->eventExclusions = isset( $eventExclusions ) && ! empty( $eventExclusions ) ? $eventExclusions : array(); |
| 181 |
$this->fileName = isset( $_POST['fileName'] ) ? sanitize_text_field( $_POST['fileName'] ) : ''; |
| 182 |
if(empty($_POST['offset'] ) || sanitize_text_field($_POST['offset']) == 'undefined'){ |
| 183 |
$this->offset = 0 ; |
| 184 |
} |
| 185 |
else{ |
| 186 |
$this->offset = isset( $_POST['offset'] ) ? sanitize_text_field( $_POST['offset'] ) : 0; |
| 187 |
} |
| 188 |
if(!empty($_POST['limit'] )){ |
| 189 |
$this->limit = isset( $_POST['limit'] ) ? sanitize_text_field( $_POST['limit'] ) : 1000; |
| 190 |
} |
| 191 |
else{ |
| 192 |
$this->limit = 50; |
| 193 |
} |
| 194 |
if(!empty($this->conditions['delimiter']['optional_delimiter'])){ |
| 195 |
$this->delimiter = $this->conditions['delimiter']['optional_delimiter'] ? $this->conditions['delimiter']['optional_delimiter']: ','; |
| 196 |
} |
| 197 |
elseif(!empty($this->conditions['delimiter']['delimiter'])){ |
| 198 |
$this->delimiter = $this->conditions['delimiter']['delimiter'] ? $this->conditions['delimiter']['delimiter'] : ','; |
| 199 |
if($this->delimiter == '{Tab}'){ |
| 200 |
$this->delimiter = " "; |
| 201 |
} |
| 202 |
elseif($this->delimiter == '{Space}'){ |
| 203 |
$this->delimiter = " "; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
$this->export_mode = 'normal'; |
| 208 |
$this->checkSplit = isset( $_POST['is_check_split'] ) ? sanitize_text_field( $_POST['is_check_split'] ) : 'false'; |
| 209 |
$this->exportData(); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
public function commentsCount($mode = null) { |
| 214 |
global $wpdb; |
| 215 |
self::generateHeaders($this->module, $this->optionalType); |
| 216 |
$get_comments = "select * from {$wpdb->prefix}comments"; |
| 217 |
// Check status |
| 218 |
if($this->conditions['specific_status']['is_check'] == 'true') { |
| 219 |
if($this->conditions['specific_status']['status'] == 'Pending') |
| 220 |
$get_comments .= " where comment_approved = '0'"; |
| 221 |
elseif($this->conditions['specific_status']['status'] == 'Approved') |
| 222 |
$get_comments .= " where comment_approved = '1'"; |
| 223 |
else |
| 224 |
$get_comments .= " where comment_approved in ('0','1')"; |
| 225 |
} |
| 226 |
else |
| 227 |
$get_comments .= " where comment_approved in ('0','1')"; |
| 228 |
// Check for specific period |
| 229 |
if($this->conditions['specific_period']['is_check'] == 'true') { |
| 230 |
if($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']){ |
| 231 |
$get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "'"; |
| 232 |
}else{ |
| 233 |
$get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "' and comment_date <= '" . $this->conditions['specific_period']['to'] . "'"; |
| 234 |
} |
| 235 |
} |
| 236 |
// Check for specific authors |
| 237 |
if($this->conditions['specific_authors']['is_check'] == '1') { |
| 238 |
if(isset($this->conditions['specific_authors']['author'])) { |
| 239 |
$get_comments .= " and comment_author_email = '".$this->conditions['specific_authors']['author']."'"; |
| 240 |
} |
| 241 |
} |
| 242 |
$get_comments .= " order by comment_ID"; |
| 243 |
$comments = $wpdb->get_results( $get_comments ); |
| 244 |
$totalRowCount = count($comments); |
| 245 |
return $totalRowCount; |
| 246 |
} |
| 247 |
|
| 248 |
public function getOptionalType($module){ |
| 249 |
if($module == 'Tags'){ |
| 250 |
$optionalType = 'post_tag'; |
| 251 |
} |
| 252 |
elseif($module == 'Posts'){ |
| 253 |
$optionalType = 'posts'; |
| 254 |
} |
| 255 |
elseif($module == 'Pages'){ |
| 256 |
$optionalType = 'pages'; |
| 257 |
} |
| 258 |
elseif($module == 'Categories'){ |
| 259 |
$optionalType = 'category'; |
| 260 |
} |
| 261 |
elseif($module == 'Users'){ |
| 262 |
$optionalType = 'users'; |
| 263 |
} |
| 264 |
elseif($module == 'Comments'){ |
| 265 |
$optionalType = 'comments'; |
| 266 |
} |
| 267 |
elseif($module == 'CustomerReviews'){ |
| 268 |
$optionalType = 'wpcr3_review'; |
| 269 |
} |
| 270 |
elseif($module == 'WooCommerce' || $module == 'WooCommerceOrders' || $module == 'WooCommerceCoupons' || $module == 'WooCommerceRefunds' || $module == 'WooCommerceVariations'){ |
| 271 |
$optionalType = 'product'; |
| 272 |
} |
| 273 |
elseif($module == 'WooCommerce'){ |
| 274 |
$optionalType = 'product'; |
| 275 |
} |
| 276 |
elseif($module == 'WPeCommerce'){ |
| 277 |
$optionalType = 'wpsc-product'; |
| 278 |
} |
| 279 |
elseif($module == 'WPeCommerce' ||$module == 'WPeCommerceCoupons'){ |
| 280 |
$optionalType = 'wpsc-product'; |
| 281 |
} |
| 282 |
return $optionalType; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* set the delimiter |
| 287 |
*/ |
| 288 |
public function setDelimiter($conditions) |
| 289 |
{ |
| 290 |
if (isset($conditions['optional_delimiter']) && $conditions['optional_delimiter'] != '') { |
| 291 |
return $conditions['optional_delimiter']; |
| 292 |
} |
| 293 |
elseif(isset($conditions['delimiter']) && $conditions['delimiter'] != 'Select'){ |
| 294 |
if($conditions['delimiter'] == '{Tab}') |
| 295 |
return "\t"; |
| 296 |
elseif ($conditions['delimiter'] == '{Space}') |
| 297 |
return " "; |
| 298 |
else |
| 299 |
return $conditions['delimiter']; |
| 300 |
} |
| 301 |
else{ |
| 302 |
return ','; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Export records based on the requested module |
| 308 |
*/ |
| 309 |
public function exportData( ) { |
| 310 |
switch ($this->module) { |
| 311 |
case 'Posts': |
| 312 |
case 'Pages': |
| 313 |
case 'CustomPosts': |
| 314 |
case 'WooCommerce': |
| 315 |
case 'WooCommerceVariations': |
| 316 |
case 'WooCommerceOrders': |
| 317 |
case 'WooCommerceCoupons': |
| 318 |
case 'WooCommerceRefunds': |
| 319 |
case 'WPeCommerce': |
| 320 |
case 'WPeCommerceCoupons': |
| 321 |
self::FetchDataByPostTypes(); |
| 322 |
break; |
| 323 |
case 'Users': |
| 324 |
self::FetchUsers(); |
| 325 |
break; |
| 326 |
case 'Comments': |
| 327 |
self::FetchComments(); |
| 328 |
break; |
| 329 |
case 'CustomerReviews': |
| 330 |
ExportExtension::$review_export->FetchCustomerReviews($this->module, $this->optionalType, $this->conditions, $this->offset, $this->limit, $this->mode); |
| 331 |
break; |
| 332 |
case 'Categories': |
| 333 |
ExportExtension::$post_export->FetchCategories($this->module,$this->optionalType); |
| 334 |
break; |
| 335 |
case 'Tags': |
| 336 |
ExportExtension::$post_export->FetchTags($this->mode,$this->module,$this->optionalType); |
| 337 |
case 'Taxonomies': |
| 338 |
ExportExtension::$woocom_export->FetchTaxonomies($this->module, $this->optionalType, $this->mode); |
| 339 |
break; |
| 340 |
|
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Fetch users and their meta information |
| 346 |
* @param $mode |
| 347 |
* |
| 348 |
* @return array |
| 349 |
*/ |
| 350 |
public function FetchUsers($mode = null) { |
| 351 |
global $wpdb; |
| 352 |
self::generateHeaders($this->module, $this->optionalType); |
| 353 |
$get_available_user_ids = "select DISTINCT ID from {$wpdb->prefix}users u join {$wpdb->prefix}usermeta um on um.user_id = u.ID"; |
| 354 |
// Check for specific period |
| 355 |
if($this->conditions['specific_period']['is_check'] == 'true') { |
| 356 |
if($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']){ |
| 357 |
$get_available_user_ids .= " where u.user_registered >= '" . $this->conditions['specific_period']['from'] . "'"; |
| 358 |
}else{ |
| 359 |
$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'"; |
| 360 |
} |
| 361 |
} |
| 362 |
$availableUsers = $wpdb->get_col($get_available_user_ids); |
| 363 |
|
| 364 |
if(!empty($this->conditions['specific_period']['is_check']) && $this->conditions['specific_period']['is_check'] == 'true') { |
| 365 |
if($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']){ |
| 366 |
$availableUserss= array(); |
| 367 |
foreach($availableUsers as $user_value){ |
| 368 |
$get_user_date_time = $wpdb->get_results( $wpdb->prepare("SELECT user_registered FROM {$wpdb->prefix}users WHERE ID=$user_value") ,ARRAY_A); |
| 369 |
$get_user_date = date("Y-m-d",strtotime($get_user_date_time[0]['user_registered'] )); |
| 370 |
if($get_user_date == $this->conditions['specific_period']['from']){ |
| 371 |
$get_user_id_value[] = $user_value; |
| 372 |
} |
| 373 |
|
| 374 |
} |
| 375 |
$this->totalRowCount = count($get_user_id_value); |
| 376 |
$availableUserss = $get_user_id_value; |
| 377 |
} |
| 378 |
else{ |
| 379 |
$this->totalRowCount = count($availableUsers); |
| 380 |
$get_available_user_ids .= " order by ID asc limit $this->offset, $this->limit"; |
| 381 |
$availableUserss = $wpdb->get_col($get_available_user_ids); |
| 382 |
} |
| 383 |
} |
| 384 |
else{ |
| 385 |
$this->totalRowCount = count($availableUsers); |
| 386 |
$get_available_user_ids .= " order by ID asc limit $this->offset, $this->limit"; |
| 387 |
$availableUserss = $wpdb->get_col($get_available_user_ids); |
| 388 |
} |
| 389 |
|
| 390 |
if(!empty($availableUserss)) { |
| 391 |
$whereCondition = ''; |
| 392 |
foreach($availableUserss as $userId) { |
| 393 |
if($whereCondition != ''){ |
| 394 |
$whereCondition = $whereCondition . ',' . $userId; |
| 395 |
}else{ |
| 396 |
$whereCondition = $userId; |
| 397 |
} |
| 398 |
// Prepare the user details to be export |
| 399 |
$query_to_fetch_users = "SELECT * FROM {$wpdb->prefix}users where ID in ($whereCondition);"; |
| 400 |
$users = $wpdb->get_results($query_to_fetch_users); |
| 401 |
if(!empty($users)) { |
| 402 |
foreach($users as $userInfo) { |
| 403 |
foreach($userInfo as $userKey => $userVal) { |
| 404 |
$this->data[$userId][$userKey] = $userVal; |
| 405 |
} |
| 406 |
} |
| 407 |
} |
| 408 |
// Prepare the user meta details to be export |
| 409 |
$query_to_fetch_users_meta = $wpdb->prepare("SELECT user_id, meta_key, meta_value FROM {$wpdb->prefix}users wp JOIN {$wpdb->prefix}usermeta wpm ON wpm.user_id = wp.ID where ID= %d", $userId); |
| 410 |
$userMeta = $wpdb->get_results($query_to_fetch_users_meta); |
| 411 |
|
| 412 |
$wptypesfields = get_option('wpcf-usermeta'); |
| 413 |
$wptypesfields = get_option('wpcf-usermeta'); |
| 414 |
|
| 415 |
if(!empty($wptypesfields)){ |
| 416 |
$i = 1; |
| 417 |
foreach ($wptypesfields as $key => $value) { |
| 418 |
$typesf[$i] = 'wpcf-'.$key; |
| 419 |
$typeOftypesField[$typesf[$i]] = $value['type']; |
| 420 |
$i++; |
| 421 |
} |
| 422 |
} |
| 423 |
if(!empty($userMeta)) { |
| 424 |
foreach($userMeta as $userMetaInfo) { |
| 425 |
if($userMetaInfo->meta_key == 'wp_capabilities') { |
| 426 |
$userRole = $this->getUserRole($userMetaInfo->meta_value); |
| 427 |
$this->data[ $userId ][ 'role' ] = $userRole; |
| 428 |
} |
| 429 |
elseif($userMetaInfo->meta_key == 'description') { |
| 430 |
$this->data[ $userId ][ 'biographical_info' ] = $userMetaInfo->meta_value; |
| 431 |
} |
| 432 |
elseif($userMetaInfo->meta_key == 'comment_shortcuts') { |
| 433 |
$this->data[ $userId ][ 'enable_keyboard_shortcuts' ] = $userMetaInfo->meta_value; |
| 434 |
} |
| 435 |
elseif($userMetaInfo->meta_key == 'show_admin_bar_front') { |
| 436 |
$this->data[ $userId ][ 'show_toolbar' ] = $userMetaInfo->meta_value; |
| 437 |
} |
| 438 |
elseif($userMetaInfo->meta_key == 'rich_editing') { |
| 439 |
$this->data[ $userId ][ 'disable_visual_editor' ] = $userMetaInfo->meta_value; |
| 440 |
} |
| 441 |
elseif($userMetaInfo->meta_key == 'locale') { |
| 442 |
$this->data[ $userId ][ 'language' ] = $userMetaInfo->meta_value; |
| 443 |
} |
| 444 |
elseif (isset($typesf) && in_array($userMetaInfo->meta_key, $typesf)) { |
| 445 |
$typeoftype = $typeOftypesField[$userMetaInfo->meta_key]; |
| 446 |
if(is_serialized($userMetaInfo->meta_value)){ |
| 447 |
$typefileds = unserialize($userMetaInfo->meta_value); |
| 448 |
$typedata = ""; |
| 449 |
foreach ($typefileds as $key2 => $value2) { |
| 450 |
if(is_array($value2)){ |
| 451 |
foreach ($value2 as $key3 => $value3) { |
| 452 |
$typedata .= $value3.','; |
| 453 |
} |
| 454 |
} |
| 455 |
else |
| 456 |
$typedata .= $value2.','; |
| 457 |
} |
| 458 |
if(preg_match('/wpcf-/',$userMetaInfo->meta_key)){ |
| 459 |
$userMetaInfo->meta_key = preg_replace('/wpcf-/','', $userMetaInfo->meta_key ); |
| 460 |
$this->data[$userId][ $userMetaInfo->meta_key ] = substr($typedata, 0, -1); |
| 461 |
} |
| 462 |
} |
| 463 |
elseif ($typeoftype == 'date') { |
| 464 |
$this->data[$userId][ $userMetaInfo->meta_key ] = date('Y-m-d', $userMetaInfo->meta_value); |
| 465 |
} |
| 466 |
$multi_row = '_'.$userMetaInfo->meta_key.'-sort-order'; |
| 467 |
|
| 468 |
$multi_data = get_user_meta($userId,$multi_row); |
| 469 |
$multi_data = $multi_data[0]; |
| 470 |
if(is_array($multi_data)){ |
| 471 |
foreach($multi_data as $k => $mid){ |
| 472 |
$m_data = $this->get_common_post_metadata($mid); |
| 473 |
if($typeoftype == 'date') |
| 474 |
$multi_data[$k] = date('Y-m-d H:i:s',$m_data['meta_value']); |
| 475 |
else |
| 476 |
$multi_data[$k] = $m_data['meta_value']; } |
| 477 |
$this->data[$userId][ $userMetaInfo->meta_key ] = implode('|',$multi_data); |
| 478 |
if(preg_match('/wpcf-/',$userMetaInfo->meta_key)){ |
| 479 |
$userMetaInfo->meta_key = preg_replace('/wpcf-/','', $userMetaInfo->meta_key ); |
| 480 |
|
| 481 |
$this->data[$userId][ $userMetaInfo->meta_key ] = implode('|',$multi_data); |
| 482 |
} |
| 483 |
} |
| 484 |
else{ |
| 485 |
if(preg_match('/wpcf-/',$userMetaInfo->meta_key)){ |
| 486 |
$userMetaInfo->meta_key = preg_replace('/wpcf-/','', $userMetaInfo->meta_key ); |
| 487 |
$this->data[$userId][ $userMetaInfo->meta_key ] = $userMetaInfo->meta_value; |
| 488 |
} |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
else { |
| 494 |
|
| 495 |
$this->data[ $userId ][ $userMetaInfo->meta_key ] = $userMetaInfo->meta_value; |
| 496 |
} |
| 497 |
} |
| 498 |
// Prepare the buddy meta details to be export |
| 499 |
if(is_plugin_active('buddypress/bp-loader.php')){ |
| 500 |
$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); |
| 501 |
$buddy = $wpdb->get_results($query_to_fetch_buddy_meta); |
| 502 |
if(!empty($buddy)) { |
| 503 |
foreach($buddy as $buddyInfo) { |
| 504 |
foreach($buddyInfo as $field_id => $value) { |
| 505 |
$this->data[$userId][$buddyInfo->name] = $buddyInfo->value; |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
ExportExtension::$post_export->getPostsMetaDataBasedOnRecordId($userId, $this->module, $this->optionalType); |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
$result = self::finalDataToExport($this->data, $this->module); |
| 516 |
if($mode == null) |
| 517 |
self::proceedExport($result); |
| 518 |
else |
| 519 |
return $result; |
| 520 |
} |
| 521 |
|
| 522 |
public function mergeWithUserMeta($acf_field_values){ |
| 523 |
|
| 524 |
foreach($acf_field_values as $acf_field_value){ |
| 525 |
|
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
/** |
| 530 |
* Fetch all Comments |
| 531 |
* @param $mode |
| 532 |
* |
| 533 |
* @return array |
| 534 |
*/ |
| 535 |
public function FetchComments($mode = null) { |
| 536 |
global $wpdb; |
| 537 |
self::generateHeaders($this->module, $this->optionalType); |
| 538 |
$get_comments = "select * from {$wpdb->prefix}comments"; |
| 539 |
// Check status |
| 540 |
if(isset($this->conditions['specific_status']['is_check']) && $this->conditions['specific_status']['is_check'] == 'true') { |
| 541 |
if($this->conditions['specific_status']['status'] == 'Pending') |
| 542 |
$get_comments .= " where comment_approved = '0'"; |
| 543 |
elseif($this->conditions['specific_status']['status'] == 'Approved') |
| 544 |
$get_comments .= " where comment_approved = '1'"; |
| 545 |
else |
| 546 |
$get_comments .= " where comment_approved in ('0','1')"; |
| 547 |
} |
| 548 |
else |
| 549 |
$get_comments .= " where comment_approved in ('0','1')"; |
| 550 |
// Check for specific period |
| 551 |
if($this->conditions['specific_period']['is_check'] == 'true') { |
| 552 |
if($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']){ |
| 553 |
$get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "'"; |
| 554 |
}else{ |
| 555 |
$get_comments .= " and comment_date >= '" . $this->conditions['specific_period']['from'] . "' and comment_date <= '" . $this->conditions['specific_period']['to'] . " 23:00:00'"; |
| 556 |
} |
| 557 |
} |
| 558 |
// Check for specific authors |
| 559 |
if($this->conditions['specific_authors']['is_check'] == '1') { |
| 560 |
if(isset($this->conditions['specific_authors']['author'])) { |
| 561 |
$get_comments .= " and comment_author_email = '".$this->conditions['specific_authors']['author']."'"; |
| 562 |
} |
| 563 |
} |
| 564 |
$comments = $wpdb->get_results( $get_comments ); |
| 565 |
|
| 566 |
if(!empty($this->conditions['specific_period']['is_check']) && $this->conditions['specific_period']['is_check'] == 'true') { |
| 567 |
if($this->conditions['specific_period']['from'] == $this->conditions['specific_period']['to']){ |
| 568 |
$limited_comments = array(); |
| 569 |
foreach($comments as $comments_value){ |
| 570 |
$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); |
| 571 |
$get_comment_date = date("Y-m-d",strtotime($get_comment_date_time[0]['comment_date'] )); |
| 572 |
if($get_comment_date == $this->conditions['specific_period']['from']){ |
| 573 |
$get_comment_date_value[] = $comments_value; |
| 574 |
} |
| 575 |
|
| 576 |
} |
| 577 |
$this->totalRowCount = count($get_comment_date_value); |
| 578 |
$limited_comments = $get_comment_date_value; |
| 579 |
} |
| 580 |
else{ |
| 581 |
$this->totalRowCount = count($comments); |
| 582 |
$get_comments .= " order by comment_ID asc limit $this->offset, $this->limit"; |
| 583 |
$limited_comments = $wpdb->get_results( $get_comments ); |
| 584 |
} |
| 585 |
} |
| 586 |
else{ |
| 587 |
$this->totalRowCount = count($comments); |
| 588 |
$get_comments .= " order by comment_ID asc limit $this->offset, $this->limit"; |
| 589 |
$limited_comments = $wpdb->get_results( $get_comments ); |
| 590 |
} |
| 591 |
|
| 592 |
if(!empty($limited_comments)) { |
| 593 |
foreach($limited_comments as $commentInfo) { |
| 594 |
$user_id=$commentInfo->user_id; |
| 595 |
if(!empty($user_id)) { |
| 596 |
$users_login = $wpdb->get_results("SELECT user_login FROM {$wpdb->prefix}users WHERE ID = '$user_id'"); |
| 597 |
foreach($users_login as $users_key => $users_value){ |
| 598 |
foreach($users_value as $u_key => $u_value){ |
| 599 |
$users_id=$u_value; |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
foreach($commentInfo as $commentKey => $commentVal) { |
| 604 |
$this->data[$commentInfo->comment_ID][$commentKey] = $commentVal; |
| 605 |
$this->data[$commentInfo->comment_ID]['user_id'] = isset($users_id) ? $users_id :''; |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
$result = self::finalDataToExport($this->data, $this->module); |
| 610 |
if($mode == null) |
| 611 |
self::proceedExport($result); |
| 612 |
else |
| 613 |
return $result; |
| 614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* Generate CSV headers |
| 618 |
* |
| 619 |
* @param $module - Module to be export |
| 620 |
* @param $optionalType - Exclusions |
| 621 |
*/ |
| 622 |
public function generateHeaders ($module, $optionalType) { |
| 623 |
if($module == 'CustomPosts' || $module == 'Taxonomies'){ |
| 624 |
$default = $this->get_fields($optionalType); // Call the super class function |
| 625 |
} |
| 626 |
else{ |
| 627 |
$default = $this->get_fields($module); |
| 628 |
} |
| 629 |
|
| 630 |
$headers = []; |
| 631 |
foreach ($default as $key => $fields) { |
| 632 |
foreach($fields as $groupKey => $fieldArray) { |
| 633 |
|
| 634 |
foreach ( $fieldArray as $fKey => $fVal ) { |
| 635 |
if (is_array($fVal) || is_object($fVal)){ |
| 636 |
foreach ( $fVal as $rKey => $rVal ) { |
| 637 |
if(!in_array($rVal['name'], $headers)) |
| 638 |
$headers[] = $rVal['name']; |
| 639 |
} |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
} |
| 644 |
} |
| 645 |
if(isset($this->eventExclusions['is_check']) && $this->eventExclusions['is_check'] == 'true') : |
| 646 |
$headers_with_exclusion = self::applyEventExclusion($headers); |
| 647 |
$this->headers = $headers_with_exclusion; |
| 648 |
else: |
| 649 |
$this->headers = $headers; |
| 650 |
endif; |
| 651 |
} |
| 652 |
|
| 653 |
/** |
| 654 |
* Fetch data by requested Post types |
| 655 |
* @param $mode |
| 656 |
* @return array |
| 657 |
*/ |
| 658 |
public function FetchDataByPostTypes ($mode = null) { |
| 659 |
if(empty($this->headers)) |
| 660 |
$this->generateHeaders($this->module, $this->optionalType); |
| 661 |
$recordsToBeExport = ExportExtension::$post_export->getRecordsBasedOnPostTypes($this->module, $this->optionalType, $this->conditions,$this->offset,$this->limit,$this->headers); |
| 662 |
if(!empty($recordsToBeExport)) { |
| 663 |
foreach($recordsToBeExport as $postId) { |
| 664 |
$this->data[$postId] = $this->getPostsDataBasedOnRecordId($postId); |
| 665 |
$exp_module = $this->module; |
| 666 |
|
| 667 |
if($exp_module == 'Posts' || $exp_module =='WooCommerce' || $exp_module == 'CustomPosts' || $exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies' || $exp_module == 'Pages'){ |
| 668 |
$this->getWPMLData($postId,$this->optionalType,$exp_module); |
| 669 |
} |
| 670 |
|
| 671 |
if($exp_module == 'Posts' || $exp_module == 'CustomPosts' ||$exp_module == 'Pages'||$exp_module == 'WooCommerce'){ |
| 672 |
$this->getPolylangData($postId,$this->optionalType,$exp_module); |
| 673 |
} |
| 674 |
ExportExtension::$post_export->getPostsMetaDataBasedOnRecordId($postId, $this->module, $this->optionalType); |
| 675 |
$this->getTermsAndTaxonomies($postId, $this->module, $this->optionalType); |
| 676 |
|
| 677 |
if($this->module == 'WooCommerce') |
| 678 |
ExportExtension::$woocom_export->getProductData($postId, $this->module, $this->optionalType); |
| 679 |
if($this->module == 'WooCommerceRefunds') |
| 680 |
ExportExtension::$woocom_export->getWooComCustomerUser($postId, $this->module, $this->optionalType); |
| 681 |
if($this->module == 'WooCommerceOrders') |
| 682 |
ExportExtension::$woocom_export->getWooComOrderData($postId, $this->module, $this->optionalType); |
| 683 |
if($this->module == 'WooCommerceVariations') |
| 684 |
ExportExtension::$woocom_export->getProductData($postId, $this->module, $this->optionalType); |
| 685 |
if($this->module == 'WPeCommerce') |
| 686 |
ExportExtension::$ecom_export->getEcomData($postId, $this->module, $this->optionalType); |
| 687 |
if($this->module == 'WPeCommerceCoupons') |
| 688 |
ExportExtension::$ecom_export->getEcomCouponData($postId, $this->module, $this->optionalType); |
| 689 |
|
| 690 |
if($this->optionalType == 'lp_course') |
| 691 |
ExportExtension::$learnpress_export->getCourseData($postId); |
| 692 |
if($this->optionalType == 'lp_lesson') |
| 693 |
ExportExtension::$learnpress_export->getLessonData($postId); |
| 694 |
if($this->optionalType == 'lp_quiz') |
| 695 |
ExportExtension::$learnpress_export->getQuizData($postId); |
| 696 |
if($this->optionalType == 'lp_question') |
| 697 |
ExportExtension::$learnpress_export->getQuestionData($postId); |
| 698 |
if($this->optionalType == 'lp_order') |
| 699 |
ExportExtension::$learnpress_export->getOrderData($postId); |
| 700 |
|
| 701 |
|
| 702 |
if($this->optionalType == 'nav_menu_item') |
| 703 |
ExportExtension::$woocom_export->getMenuData($postId); |
| 704 |
|
| 705 |
if($this->optionalType == 'widgets') |
| 706 |
self::$instance->getWidgetData($postId,$this->headers); |
| 707 |
} |
| 708 |
} |
| 709 |
/** Added post format for 'standard' property */ |
| 710 |
if($exp_module == 'Posts' || $exp_module == 'CustomPosts') { |
| 711 |
foreach($this->data as $id => $records) { |
| 712 |
if(!array_key_exists('post_format',$records)) |
| 713 |
{ |
| 714 |
$records['post_format'] = 'standard'; |
| 715 |
$this->data[$id] = $records; |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
/** End post format */ |
| 721 |
$result = self::finalDataToExport($this->data, $this->module); |
| 722 |
|
| 723 |
if($mode == null) |
| 724 |
self::proceedExport( $result ); |
| 725 |
else |
| 726 |
return $result; |
| 727 |
} |
| 728 |
|
| 729 |
public function getWidgetData($postId, $headers){ |
| 730 |
|
| 731 |
global $wpdb; |
| 732 |
$get_sidebar_widgets = get_option('sidebars_widgets'); |
| 733 |
|
| 734 |
$total_footer_arr = []; |
| 735 |
|
| 736 |
foreach($get_sidebar_widgets as $footer_key => $footer_arr){ |
| 737 |
if($footer_key != 'wp_inactive_widgets' || $footer_key != 'array_version'){ |
| 738 |
if( strpos($footer_key, 'sidebar') !== false ){ |
| 739 |
$get_footer = explode('-', $footer_key); |
| 740 |
$footer_number = $get_footer[1]; |
| 741 |
|
| 742 |
foreach($footer_arr as $footer_values){ |
| 743 |
$total_footer_arr[$footer_values] = $footer_number; |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
foreach ($headers as $key => $value){ |
| 750 |
$get_widget_value[$value] = $wpdb->get_row("SELECT option_value FROM {$wpdb->prefix}options where option_name = '{$value}'", ARRAY_A); |
| 751 |
|
| 752 |
$header_key = explode('widget_', $value); |
| 753 |
|
| 754 |
if ($value == 'widget_recent-posts'){ |
| 755 |
$recent_posts = unserialize($get_widget_value[$value]['option_value']); |
| 756 |
$recent_post = ''; |
| 757 |
foreach($recent_posts as $dk => $dv){ |
| 758 |
if($dk != '_multiwidget'){ |
| 759 |
$post_key = $header_key[1].'-'.$dk; |
| 760 |
$recent_post .= $dv['title'].','.$dv['number'].','.$dv['show_date'].'->'.$total_footer_arr[$post_key].'|'; |
| 761 |
} |
| 762 |
} |
| 763 |
$recent_post = rtrim($recent_post , '|'); |
| 764 |
} |
| 765 |
elseif ($value == 'widget_pages'){ |
| 766 |
$recent_pages = unserialize($get_widget_value[$value]['option_value']); |
| 767 |
$recent_page = ''; |
| 768 |
foreach($recent_pages as $dk => $dv){ |
| 769 |
if(isset($dv['exclude'])){ |
| 770 |
$exclude_value = str_replace(',', '/', $dv['exclude']); |
| 771 |
} |
| 772 |
|
| 773 |
if($dk != '_multiwidget'){ |
| 774 |
$page_key = $header_key[1].'-'.$dk; |
| 775 |
$recent_page .= $dv['title'].','.$dv['sortby'].','.$exclude_value.'->'.$total_footer_arr[$page_key].'|'; |
| 776 |
} |
| 777 |
} |
| 778 |
$recent_page = rtrim($recent_page , '|'); |
| 779 |
} |
| 780 |
elseif ($value == 'widget_recent-comments'){ |
| 781 |
$recent_comments = unserialize($get_widget_value[$value]['option_value']); |
| 782 |
$recent_comment = ''; |
| 783 |
foreach($recent_comments as $dk => $dv){ |
| 784 |
if($dk != '_multiwidget'){ |
| 785 |
$comment_key = $header_key[1].'-'.$dk; |
| 786 |
$recent_comment .= $dv['title'].','.$dv['number'].'->'.$total_footer_arr[$comment_key].'|'; |
| 787 |
} |
| 788 |
} |
| 789 |
$recent_comment = rtrim($recent_comment , '|'); |
| 790 |
} |
| 791 |
elseif ($value == 'widget_archives'){ |
| 792 |
$recent_archives = unserialize($get_widget_value[$value]['option_value']); |
| 793 |
$recent_archive = ''; |
| 794 |
foreach($recent_archives as $dk => $dv){ |
| 795 |
if($dk != '_multiwidget'){ |
| 796 |
$archive_key = $header_key[1].'-'.$dk; |
| 797 |
$recent_archive .= $dv['title'].','.$dv['count'].','.$dv['dropdown'].'->'.$total_footer_arr[$archive_key].'|'; |
| 798 |
} |
| 799 |
} |
| 800 |
$recent_archive = rtrim($recent_archive , '|'); |
| 801 |
} |
| 802 |
elseif ($value == 'widget_categories'){ |
| 803 |
$recent_categories = unserialize($get_widget_value[$value]['option_value']); |
| 804 |
$recent_category = ''; |
| 805 |
foreach($recent_categories as $dk => $dv){ |
| 806 |
if($dk != '_multiwidget'){ |
| 807 |
$cat_key = $header_key[1].'-'.$dk; |
| 808 |
$recent_category .= $dv['title'].','.$dv['count'].','.$dv['hierarchical'].','.$dv['dropdown'].'->'.$total_footer_arr[$cat_key].'|'; |
| 809 |
} |
| 810 |
} |
| 811 |
$recent_category = rtrim($recent_category , '|'); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
$this->data[$postId]['widget_recent-posts'] = $recent_post; |
| 816 |
$this->data[$postId]['widget_pages'] = $recent_page; |
| 817 |
$this->data[$postId]['widget_recent-comments'] = $recent_comment; |
| 818 |
$this->data[$postId]['widget_archives'] = $recent_archive; |
| 819 |
$this->data[$postId]['widget_categories'] = $recent_category; |
| 820 |
} |
| 821 |
|
| 822 |
/** |
| 823 |
* Function used to fetch the Terms & Taxonomies for the specific posts |
| 824 |
* |
| 825 |
* @param $id |
| 826 |
* @param $type |
| 827 |
* @param $optionalType |
| 828 |
*/ |
| 829 |
public function getTermsAndTaxonomies ($id, $type, $optionalType) { |
| 830 |
$TermsData = array(); |
| 831 |
|
| 832 |
if($type == 'WooCommerce' || ($type == 'CustomPosts' && $type == 'WooCommerce')) { |
| 833 |
$type = 'product'; |
| 834 |
$postTags = ''; |
| 835 |
$taxonomies = get_object_taxonomies($type); |
| 836 |
$get_tags = get_the_terms( $id, 'product_tag' ); |
| 837 |
if($get_tags){ |
| 838 |
foreach($get_tags as $tags){ |
| 839 |
$postTags .= $tags->name . ','; |
| 840 |
} |
| 841 |
} |
| 842 |
$postTags = substr($postTags, 0, -1); |
| 843 |
$this->data[$id]['product_tag'] = $postTags; |
| 844 |
foreach ($taxonomies as $taxonomy) { |
| 845 |
$postCategory = ''; |
| 846 |
if($taxonomy == 'product_cat' || $taxonomy == 'product_category'){ |
| 847 |
$get_categories = get_the_terms( $id, $taxonomy ); |
| 848 |
if($get_categories){ |
| 849 |
$postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy) ; |
| 850 |
// foreach($get_categories as $category){ |
| 851 |
// $postCategory .= $this->hierarchy_based_term_name($category, $taxonomy) . ','; |
| 852 |
// } |
| 853 |
} |
| 854 |
$postCategory = substr($postCategory, 0 , -1); |
| 855 |
$this->data[$id]['product_category'] = $postCategory; |
| 856 |
}else{ |
| 857 |
$get_categories = get_the_terms( $id, $taxonomy ); |
| 858 |
if($get_categories){ |
| 859 |
$postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy) ; |
| 860 |
// foreach($get_categories as $category){ |
| 861 |
// $postCategory .= $this->hierarchy_based_term_name($category, $taxonomy) . ','; |
| 862 |
// } |
| 863 |
} |
| 864 |
$postCategory = substr($postCategory, 0 , -1); |
| 865 |
$this->data[$id][$taxonomy] = $postCategory; |
| 866 |
} |
| 867 |
} |
| 868 |
if($type == 'WooCommerce' && $type != 'CustomPosts') { |
| 869 |
$product = wc_get_product ($id); |
| 870 |
$pro_type = $product->get_type(); |
| 871 |
switch ($pro_type) { |
| 872 |
case 'simple': |
| 873 |
$product_type = 1; |
| 874 |
break; |
| 875 |
case 'grouped': |
| 876 |
$product_type = 2; |
| 877 |
break; |
| 878 |
case 'external': |
| 879 |
$product_type = 3; |
| 880 |
break; |
| 881 |
case 'variable': |
| 882 |
$product_type = 4; |
| 883 |
break; |
| 884 |
case 'subscription': |
| 885 |
$product_type = 5; |
| 886 |
break; |
| 887 |
case 'variable-subscription': |
| 888 |
$product_type = 6; |
| 889 |
break; |
| 890 |
case 'bundle': |
| 891 |
$product_type = 7; |
| 892 |
break; |
| 893 |
default: |
| 894 |
$product_type = 1; |
| 895 |
break; |
| 896 |
} |
| 897 |
$this->data[$id]['product_type'] = $product_type; |
| 898 |
} |
| 899 |
|
| 900 |
//product_shipping_class |
| 901 |
$shipping = get_the_terms( $id, 'product_shipping_class' ); |
| 902 |
if($shipping){ |
| 903 |
$taxo_shipping = $shipping[0]->name; |
| 904 |
$this->data[$id][ 'product_shipping_class' ] = $taxo_shipping; |
| 905 |
} |
| 906 |
//product_shipping_class |
| 907 |
} else if($type == 'WPeCommerce') { |
| 908 |
$type = 'wpsc-product'; |
| 909 |
$postTags = $postCategory = ''; |
| 910 |
$taxonomies = get_object_taxonomies($type); |
| 911 |
$get_tags = get_the_terms( $id, 'product_tag' ); |
| 912 |
if($get_tags){ |
| 913 |
foreach($get_tags as $tags){ |
| 914 |
$postTags .= $tags->name.','; |
| 915 |
} |
| 916 |
} |
| 917 |
$postTags = substr($postTags,0,-1); |
| 918 |
$this->data[$id]['product_tag'] = $postTags; |
| 919 |
foreach ($taxonomies as $taxonomy) { |
| 920 |
$postCategory = ''; |
| 921 |
if($taxonomy == 'wpsc_product_category'){ |
| 922 |
$get_categories = wp_get_post_terms( $id, $taxonomy ); |
| 923 |
if($get_categories){ |
| 924 |
$postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy); |
| 925 |
|
| 926 |
} |
| 927 |
$postCategory = substr($postCategory, 0 , -1); |
| 928 |
$this->data[$id]['product_category'] = $postCategory; |
| 929 |
}else{ |
| 930 |
$get_categories = wp_get_post_terms( $id, $taxonomy ); |
| 931 |
if($get_categories){ |
| 932 |
$postCategory = $this->hierarchy_based_term_name($get_categories, $taxonomy); |
| 933 |
|
| 934 |
} |
| 935 |
$postCategory = substr($postCategory, 0 , -1); |
| 936 |
$this->data[$id]['product_category'] = $postCategory; |
| 937 |
} |
| 938 |
} |
| 939 |
} else { |
| 940 |
global $wpdb; |
| 941 |
$postTags = $postCategory = ''; |
| 942 |
$taxonomyId = $wpdb->get_col($wpdb->prepare("select term_taxonomy_id from {$wpdb->prefix}term_relationships where object_id = %d", $id)); |
| 943 |
$taxo = []; |
| 944 |
foreach($taxonomyId as $taxonomy) { |
| 945 |
$taxo[] = get_term($taxonomy); |
| 946 |
} |
| 947 |
foreach($taxonomyId as $taxonomy) { |
| 948 |
$taxonomytypeid =$wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy WHERE term_taxonomy_id='$taxonomy' "); |
| 949 |
if($taxonomytypeid[0]->taxonomy == 'course_category') { |
| 950 |
$taxonomyTypeId = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomytypeid[0]->term_taxonomy_id)); |
| 951 |
$taxonomy_Type_Id = $taxonomyTypeId[0]; |
| 952 |
$taxo0[] = get_term($taxonomy_Type_Id); |
| 953 |
} |
| 954 |
if($taxonomytypeid[0]->taxonomy =='course_tag') { |
| 955 |
$taxonomyTypeId1 = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomytypeid[0]->term_taxonomy_id)); |
| 956 |
$taxonomy_Type_Id1 = $taxonomyTypeId1[0]; |
| 957 |
$taxo2[] = get_term($taxonomy_Type_Id1); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
if(!empty($taxo)){ |
| 962 |
foreach($taxo as $key=>$taxo_val){ |
| 963 |
if($taxo_val->taxonomy == 'category'){ |
| 964 |
$taxo1[]=$taxo_val; |
| 965 |
} |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
if(!empty($taxonomyId)) { |
| 970 |
foreach($taxonomyId as $taxonomy) { |
| 971 |
$taxonomyType = $wpdb->get_col($wpdb->prepare("select taxonomy from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d", $taxonomy)); |
| 972 |
if(!empty($taxonomyType)) { |
| 973 |
foreach($taxonomyType as $taxanomy_name) { |
| 974 |
if($taxanomy_name == 'category'){ |
| 975 |
$termName = 'post_category'; |
| 976 |
}else{ |
| 977 |
$termName = $taxanomy_name; |
| 978 |
} |
| 979 |
if(in_array($termName, $this->headers)) { |
| 980 |
if($termName != 'post_tag' && $termName !='post_category') { |
| 981 |
|
| 982 |
$taxonomyData = $wpdb->get_col($wpdb->prepare("select name from {$wpdb->prefix}terms where term_id = %d",$taxonomy)); |
| 983 |
if(!empty($taxonomyData)) { |
| 984 |
|
| 985 |
if(isset($TermsData[$termName])){ |
| 986 |
$this->data[$id][$termName] = $TermsData[$termName] . ',' . $taxonomyData[0]; |
| 987 |
}else{ |
| 988 |
$get_exist_data = $this->data[$id][$termName]; |
| 989 |
} |
| 990 |
|
| 991 |
if( $get_exist_data == '' ){ |
| 992 |
$this->data[$id][$termName] = $taxonomyData[0]; |
| 993 |
}else { |
| 994 |
$taxonomyID = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}terms where name = %s",$taxonomyData[0])); |
| 995 |
if($taxanomy_name =='course_category') { |
| 996 |
foreach($taxo0 as $taxo_key => $taxo_value){ |
| 997 |
$postterm1 .= $taxo_value->name.','; |
| 998 |
} |
| 999 |
//$postterm1 = substr($this->hierarchy_based_term_name($taxo0, $taxanomy_name), 0 , -1); |
| 1000 |
$this->data[$id][$termName] =rtrim($postterm1,','); |
| 1001 |
} |
| 1002 |
elseif($taxanomy_name =='course_tag') { |
| 1003 |
foreach($taxo2 as $taxo_key1 => $taxo_value1){ |
| 1004 |
$postterm2 .= $taxo_value1->name.','; |
| 1005 |
} |
| 1006 |
//$postterm2 = substr($this->hierarchy_based_term_name($taxo2, $taxanomy_name), 0 , -1); |
| 1007 |
$this->data[$id][$termName] = rtrim($postterm2,','); |
| 1008 |
} |
| 1009 |
else{ |
| 1010 |
$postterm = substr($this->hierarchy_based_term_name($taxo, $taxanomy_name), 0 , -1); |
| 1011 |
$this->data[$id][$termName] = $postterm; |
| 1012 |
} |
| 1013 |
//$this->data[$id][$termName] = $get_exist_data . ',' . $this->hierarchy_based_term_name(get_term($taxonomy), $taxanomy_name); |
| 1014 |
//$this->data[$id][$taxanomy_name] = $get_exist_data . '|' . $this->hierarchy_based_term_name(get_term($taxonomy), $taxanomy_name); |
| 1015 |
} |
| 1016 |
|
| 1017 |
} |
| 1018 |
} else { |
| 1019 |
if(!isset($TermsData['post_tag'])) { |
| 1020 |
if($termName == 'post_tag'){ |
| 1021 |
$postTags = ''; |
| 1022 |
$get_tags = wp_get_post_tags($id, array('fields' => 'names')); |
| 1023 |
foreach ($get_tags as $tags) { |
| 1024 |
$postTags .= $tags . ','; |
| 1025 |
} |
| 1026 |
$postTags = substr($postTags, 0, -1); |
| 1027 |
|
| 1028 |
//if( $this->data[$id][$termName] == '' ) { |
| 1029 |
$this->data[$id][$termName] = $postTags; |
| 1030 |
//} |
| 1031 |
} |
| 1032 |
if($termName == 'post_category'){ |
| 1033 |
$postCategory = ''; |
| 1034 |
$get_categories = wp_get_post_categories($id, array('fields' => 'names')); |
| 1035 |
|
| 1036 |
$postterm1= substr($this->hierarchy_based_term_name($taxo1, $taxanomy_name), 0 , -1); |
| 1037 |
$this->data[$id][$termName] = $postterm1; |
| 1038 |
|
| 1039 |
} |
| 1040 |
|
| 1041 |
} |
| 1042 |
} |
| 1043 |
} |
| 1044 |
else{ |
| 1045 |
$this->data[$id][$termName] = ''; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
/** |
| 1055 |
* Get user role based on the capability |
| 1056 |
* @param null $capability - User capability |
| 1057 |
* @return int|string - Role of the user |
| 1058 |
*/ |
| 1059 |
public function getUserRole ($capability = null) { |
| 1060 |
if($capability != null) { |
| 1061 |
$getRole = unserialize($capability); |
| 1062 |
foreach($getRole as $roleName => $roleStatus) { |
| 1063 |
$role = $roleName; |
| 1064 |
} |
| 1065 |
return $role; |
| 1066 |
} else { |
| 1067 |
return 'subscriber'; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
/** |
| 1072 |
* Get activated plugins |
| 1073 |
* @return mixed |
| 1074 |
*/ |
| 1075 |
public function get_active_plugins() { |
| 1076 |
$active_plugins = get_option('active_plugins'); |
| 1077 |
return $active_plugins; |
| 1078 |
} |
| 1079 |
|
| 1080 |
public function array_to_xml( $data, &$xml_data ) { |
| 1081 |
foreach( $data as $key => $value ) { |
| 1082 |
if( is_numeric($key) ){ |
| 1083 |
$key = 'item'; //dealing with <0/>..<n/> issues |
| 1084 |
} |
| 1085 |
if( is_array($value) ) { |
| 1086 |
$subnode = $xml_data->addChild($key); |
| 1087 |
$this->array_to_xml($value, $subnode); |
| 1088 |
} else { |
| 1089 |
$xml_data->addChild("$key",htmlspecialchars("$value")); |
| 1090 |
} |
| 1091 |
} |
| 1092 |
} |
| 1093 |
public function getPolylangData ($id,$optional_type,$exp_module) { |
| 1094 |
global $wpdb; |
| 1095 |
global $sitepress; |
| 1096 |
$terms=$wpdb->get_results("select term_taxonomy_id from $wpdb->term_relationships where object_id ='{$id}'"); |
| 1097 |
$terms_id=json_decode(json_encode($terms),true); |
| 1098 |
foreach($terms_id as $termkey => $termvalue){ |
| 1099 |
$termids=$termvalue['term_taxonomy_id']; |
| 1100 |
$check=$wpdb->get_var("select taxonomy from $wpdb->term_taxonomy where term_id ='{$termids}'"); |
| 1101 |
if($check == 'category'){ |
| 1102 |
$category=$wpdb->get_var("select name from $wpdb->terms where term_id ='{$termids}'"); |
| 1103 |
} |
| 1104 |
elseif($check =='language'){ |
| 1105 |
$language=$wpdb->get_var("select description from $wpdb->term_taxonomy where term_id ='{$termids}'"); |
| 1106 |
$lang=unserialize($language); |
| 1107 |
$langcode=explode('_',$lang['locale']); |
| 1108 |
$lang_code=$langcode[0]; |
| 1109 |
$this->data[$id]['language_code'] = $lang_code; |
| 1110 |
} |
| 1111 |
elseif($check == 'post_translations'){ |
| 1112 |
$description=$wpdb->get_var("select description from $wpdb->term_taxonomy where term_id ='{$termids}'"); |
| 1113 |
$desc=unserialize($description); |
| 1114 |
$post_id = is_array($desc)? array_values($desc): array(); |
| 1115 |
$postid = min($post_id); |
| 1116 |
|
| 1117 |
$post_title=$wpdb->get_var("select post_title from $wpdb->posts where ID ='{$postid}'"); |
| 1118 |
$this->data[$id]['translated_post_title'] = $post_title; |
| 1119 |
} |
| 1120 |
elseif($check == 'post_tag'){ |
| 1121 |
$tag=$wpdb->get_var("select name from $wpdb->terms where term_id ='{$termids}'"); |
| 1122 |
|
| 1123 |
} |
| 1124 |
} |
| 1125 |
} |
| 1126 |
|
| 1127 |
/** |
| 1128 |
* Export Data |
| 1129 |
* @param $data |
| 1130 |
*/ |
| 1131 |
public function proceedExport ($data) { |
| 1132 |
$upload_dir = ABSPATH .'wp-content/uploads/smack_uci_uploads/exports/'; |
| 1133 |
if(!is_dir($upload_dir)) { |
| 1134 |
wp_mkdir_p($upload_dir); |
| 1135 |
} |
| 1136 |
$base_dir = wp_upload_dir(); |
| 1137 |
$upload_url = $base_dir['baseurl'].'/smack_uci_uploads/exports/'; |
| 1138 |
chmod($upload_dir, 0777); |
| 1139 |
if($this->checkSplit == 'true'){ |
| 1140 |
$i = 1; |
| 1141 |
while ( $i != 0) { |
| 1142 |
$file = $upload_dir . $this->fileName .'_'.$i.'.' . $this->exportType; |
| 1143 |
if(file_exists($file)){ |
| 1144 |
$allfiles[$i] = $file; |
| 1145 |
$i++; |
| 1146 |
} |
| 1147 |
else |
| 1148 |
break; |
| 1149 |
} |
| 1150 |
$fileURL = $upload_url . $this->fileName.'_'.$i.'.' .$this->exportType; |
| 1151 |
} |
| 1152 |
else{ |
| 1153 |
$file = $upload_dir . $this->fileName .'.' . $this->exportType; |
| 1154 |
$fileURL = $upload_url . $this->fileName.'.' .$this->exportType; |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
$spsize = 100; |
| 1159 |
if ($this->offset == 0) { |
| 1160 |
if(file_exists($file)) |
| 1161 |
unlink($file); |
| 1162 |
} |
| 1163 |
|
| 1164 |
$checkRun = "no"; |
| 1165 |
if($this->checkSplit == 'true' && ($this->totalRowCount - $this->offset) > 0){ |
| 1166 |
$checkRun = 'yes'; |
| 1167 |
} |
| 1168 |
if($this->checkSplit != 'true'){ |
| 1169 |
$checkRun = 'yes'; |
| 1170 |
} |
| 1171 |
|
| 1172 |
if($checkRun == 'yes'){ |
| 1173 |
if($this->exportType == 'xml'){ |
| 1174 |
$xml_data = new \SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
| 1175 |
$this->array_to_xml($data,$xml_data); |
| 1176 |
$result = $xml_data->asXML($file); |
| 1177 |
}else{ |
| 1178 |
if($this->exportType == 'json') |
| 1179 |
$csvData = json_encode($data); |
| 1180 |
else |
| 1181 |
$csvData = $this->unParse($data, $this->headers); |
| 1182 |
try { |
| 1183 |
|
| 1184 |
file_put_contents( $file, $csvData, FILE_APPEND | LOCK_EX ); |
| 1185 |
|
| 1186 |
} catch (\Exception $e) { |
| 1187 |
// TODO - write exception in log |
| 1188 |
} |
| 1189 |
} |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
$this->offset = $this->offset + $this->limit; |
| 1194 |
|
| 1195 |
$filePath = $upload_dir . $this->fileName . '.' . $this->exportType; |
| 1196 |
$filename = $fileURL; |
| 1197 |
if(($this->offset) > ($this->totalRowCount) && $this->checkSplit == 'true'){ |
| 1198 |
$allfiles[$i] = $file; |
| 1199 |
$zipname = $upload_dir . $this->fileName .'.' . 'zip'; |
| 1200 |
$zip = new \ZipArchive; |
| 1201 |
$zip->open($zipname, \ZipArchive::CREATE); |
| 1202 |
foreach ($allfiles as $allfile) { |
| 1203 |
$newname = str_replace($upload_dir, '', $allfile); |
| 1204 |
$zip->addFile($allfile, $newname); |
| 1205 |
} |
| 1206 |
$zip->close(); |
| 1207 |
$fileURL = $upload_url . $this->fileName.'.'.'zip'; |
| 1208 |
foreach ($allfiles as $removefile) { |
| 1209 |
unlink($removefile); |
| 1210 |
} |
| 1211 |
$filename = $upload_url . $this->fileName.'.'.'zip'; |
| 1212 |
} |
| 1213 |
if($this->checkSplit == 'true' && !($this->offset) > ($this->totalRowCount)){ |
| 1214 |
$responseTojQuery = array('success' => false, 'new_offset' => $this->offset, 'limit' => $this->limit, 'total_row_count' => $this->totalRowCount, 'exported_file' => $zipname, 'exported_path' => $zipname,'export_type'=>$this->exportType); |
| 1215 |
} |
| 1216 |
elseif($this->checkSplit == 'true' && (($this->offset) > ($this->totalRowCount))){ |
| 1217 |
$responseTojQuery = array('success' => true, 'new_offset' => $this->offset, 'limit' => $this->limit, 'total_row_count' => $this->totalRowCount, 'exported_file' => $fileURL, 'exported_path' => $fileURL,'export_type'=>$this->exportType); |
| 1218 |
} |
| 1219 |
elseif(!(($this->offset) > ($this->totalRowCount))){ |
| 1220 |
$responseTojQuery = array('success' => false, 'new_offset' => $this->offset, 'limit' => $this->limit, 'total_row_count' => $this->totalRowCount, 'exported_file' => $filename, 'exported_path' => $filePath,'export_type'=>$this->exportType); |
| 1221 |
} |
| 1222 |
else{ |
| 1223 |
$responseTojQuery = array('success' => true, 'new_offset' => $this->offset, 'limit' => $this->limit, 'total_row_count' => $this->totalRowCount, 'exported_file' => $filename, 'exported_path' => $filePath,'export_type'=>$this->exportType); |
| 1224 |
} |
| 1225 |
|
| 1226 |
if($this->export_mode == 'normal'){ |
| 1227 |
echo wp_json_encode($responseTojQuery); |
| 1228 |
wp_die(); |
| 1229 |
} |
| 1230 |
elseif($this->export_mode == 'FTP'){ |
| 1231 |
$this->export_log = $responseTojQuery; |
| 1232 |
} |
| 1233 |
} |
| 1234 |
|
| 1235 |
/** |
| 1236 |
* Fetch ACF field information to be export |
| 1237 |
* @param $recordId - Id of the Post (or) Page (or) Product (or) User |
| 1238 |
*/ |
| 1239 |
public function FetchACFData ($recordId) { |
| 1240 |
|
| 1241 |
} |
| 1242 |
|
| 1243 |
/** |
| 1244 |
* Get post data based on the record id |
| 1245 |
* @param $id - Id of the records |
| 1246 |
* @return array - Data based on the requested id. |
| 1247 |
*/ |
| 1248 |
public function getPostsDataBasedOnRecordId ($id) { |
| 1249 |
global $wpdb; |
| 1250 |
$PostData = array(); |
| 1251 |
$query1 = $wpdb->prepare("SELECT wp.* FROM {$wpdb->prefix}posts wp where ID=%d", $id); |
| 1252 |
$result_query1 = $wpdb->get_results($query1); |
| 1253 |
if (!empty($result_query1)) { |
| 1254 |
foreach ($result_query1 as $posts) { |
| 1255 |
|
| 1256 |
//pods export |
| 1257 |
$post_type=isset($posts->post_type)?$posts->post_type:''; |
| 1258 |
$p_type=$post_type; |
| 1259 |
$posid = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts where post_name='$p_type' and post_type='_pods_pod'"); |
| 1260 |
foreach($posid as $podid){ |
| 1261 |
$pods_id = $podid->ID; |
| 1262 |
$storage = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta where post_id=$pods_id AND meta_key='storage'"); |
| 1263 |
foreach($storage as $pod_storage){ |
| 1264 |
$pod_stype = $pod_storage->meta_value; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
if(isset($pod_stype) && $pod_stype=='table'){ |
| 1268 |
$tab='pods_'.$p_type; |
| 1269 |
$tab_val = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}$tab where id=$id"); |
| 1270 |
foreach($tab_val as $table_key =>$table_val ){ |
| 1271 |
$posts = array_merge((array)$posts,(array)$table_val); |
| 1272 |
} |
| 1273 |
} |
| 1274 |
|
| 1275 |
foreach ($posts as $post_key => $post_value) { |
| 1276 |
if ($post_key == 'post_status') { |
| 1277 |
if (is_sticky($id)) { |
| 1278 |
$PostData[$post_key] = 'Sticky'; |
| 1279 |
$post_status = 'Sticky'; |
| 1280 |
} else { |
| 1281 |
$PostData[$post_key] = $post_value; |
| 1282 |
$post_status = $post_value; |
| 1283 |
} |
| 1284 |
} else { |
| 1285 |
$PostData[$post_key] = $post_value; |
| 1286 |
} |
| 1287 |
if ($post_key == 'post_password') { |
| 1288 |
if ($post_value) { |
| 1289 |
$PostData['post_status'] = "{" . $post_value . "}"; |
| 1290 |
} else { |
| 1291 |
$PostData['post_status'] = $post_status; |
| 1292 |
} |
| 1293 |
} |
| 1294 |
|
| 1295 |
if($post_key == 'post_author'){ |
| 1296 |
$user_info = get_userdata($post_value); |
| 1297 |
$PostData['post_author'] = $user_info->user_login; |
| 1298 |
} |
| 1299 |
} |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
return $PostData; |
| 1304 |
} |
| 1305 |
|
| 1306 |
public function getWPMLData ($id,$optional_type,$exp_module) { |
| 1307 |
global $wpdb; |
| 1308 |
global $sitepress; |
| 1309 |
if($sitepress != null && is_plugin_active('wpml-ultimate-importer/wpml-ultimate-importer.php')) { |
| 1310 |
$icl_translation_table = $wpdb->prefix.'icl_translations'; |
| 1311 |
if($exp_module == 'Categories' || $exp_module == 'Tags' || $exp_module == 'Taxonomies'){ |
| 1312 |
$get_element_type = 'tax_'.$optional_type; |
| 1313 |
} |
| 1314 |
else{ |
| 1315 |
$get_element_type = 'post_'.$optional_type; |
| 1316 |
} |
| 1317 |
$args = array('element_id' => $id ,'element_type' => $get_element_type); |
| 1318 |
$get_language_code = apply_filters( 'wpml_element_language_code', null, $args ); |
| 1319 |
|
| 1320 |
$get_source_language = $wpdb->get_var("select source_language_code from {$icl_translation_table} where element_id ='{$id}' and language_code ='{$get_language_code}'"); |
| 1321 |
|
| 1322 |
$get_trid = apply_filters( 'wpml_element_trid', NULL, $id,$get_element_type ); |
| 1323 |
if(!empty($get_source_language)){ |
| 1324 |
$original_element_id_prepared = $wpdb->prepare( |
| 1325 |
"SELECT element_id |
| 1326 |
FROM {$wpdb->prefix}icl_translations |
| 1327 |
WHERE trid=%d |
| 1328 |
AND source_language_code IS NULL |
| 1329 |
LIMIT 1",$get_trid |
| 1330 |
); |
| 1331 |
|
| 1332 |
$element_id = $wpdb->get_var( $original_element_id_prepared ); |
| 1333 |
if($exp_module == 'Posts' || $exp_module == 'WooCommerce' || $exp_module == 'CustomPosts' || $exp_module == 'Pages'){ |
| 1334 |
$element_title = get_the_title( $element_id ); |
| 1335 |
$this->data[$id]['translated_post_title'] = $element_title; |
| 1336 |
} |
| 1337 |
else{ |
| 1338 |
$element_title = $wpdb->get_var("select name from $wpdb->terms where term_id ='{$element_id}'"); |
| 1339 |
$this->data[$id]['translated_taxonomy_title'] = $element_title; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
$this->data[$id]['language_code'] = $get_language_code; |
| 1343 |
return $this->data[$id]; |
| 1344 |
} |
| 1345 |
} |
| 1346 |
|
| 1347 |
public function getAttachment($id) |
| 1348 |
{ |
| 1349 |
global $wpdb; |
| 1350 |
$get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $id, 'attachment'); |
| 1351 |
$attachment = $wpdb->get_results($get_attachment); |
| 1352 |
$attachment_file = $attachment[0]->guid; |
| 1353 |
return $attachment_file; |
| 1354 |
|
| 1355 |
} |
| 1356 |
|
| 1357 |
public function getRepeater($parent) |
| 1358 |
{ |
| 1359 |
global $wpdb; |
| 1360 |
$get_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts where post_parent = %d", $parent), ARRAY_A); |
| 1361 |
$i = 0; |
| 1362 |
foreach ($get_fields as $key => $value) { |
| 1363 |
$array[$i] = $value['post_excerpt']; |
| 1364 |
$i++; |
| 1365 |
} |
| 1366 |
return $array; |
| 1367 |
} |
| 1368 |
|
| 1369 |
/** |
| 1370 |
* Get types fields |
| 1371 |
* @return array - Types fields |
| 1372 |
*/ |
| 1373 |
public function getTypesFields() { |
| 1374 |
$getWPTypesFields = get_option('wpcf-fields'); |
| 1375 |
$typesFields = array(); |
| 1376 |
if(!empty($getWPTypesFields) && is_array($getWPTypesFields)) { |
| 1377 |
foreach($getWPTypesFields as $fKey){ |
| 1378 |
$typesFields[$fKey['meta_key']] = $fKey['name']; |
| 1379 |
} |
| 1380 |
} |
| 1381 |
return $typesFields; |
| 1382 |
} |
| 1383 |
|
| 1384 |
/** |
| 1385 |
* Final data to be export |
| 1386 |
* @param $data - Data to be export based on the requested information |
| 1387 |
* @return array - Final data to be export |
| 1388 |
*/ |
| 1389 |
public function finalDataToExport ($data, $module = false) { |
| 1390 |
$result = array(); |
| 1391 |
foreach ($this->headers as $key => $value) { |
| 1392 |
if(empty($value)){ |
| 1393 |
unset($this->headers[$key]); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
// Fetch Category Custom Field Values |
| 1398 |
if($module){ |
| 1399 |
if($module == 'Categories'){ |
| 1400 |
return $this->fetchCategoryFieldValue($data, $this->module); |
| 1401 |
} |
| 1402 |
} |
| 1403 |
|
| 1404 |
foreach ( $data as $recordId => $rowValue ) { |
| 1405 |
foreach ($this->headers as $hKey) { |
| 1406 |
if(array_key_exists($hKey, $rowValue) && (!empty($rowValue[$hKey])) ){ |
| 1407 |
$result[$recordId][$hKey] = $this->returnMetaValueAsCustomerInput($rowValue[$hKey], $hKey); |
| 1408 |
} |
| 1409 |
else{ |
| 1410 |
$key = $hKey; |
| 1411 |
//$rowValue['post_type'] = ''; |
| 1412 |
// Replace the third party plugin name from the fieldname |
| 1413 |
$key = $this->replace_prefix_aioseop_from_fieldname($key); |
| 1414 |
$key = $this->replace_prefix_yoast_wpseo_from_fieldname($key); |
| 1415 |
$key = $this->replace_prefix_wpcf_from_fieldname($key); |
| 1416 |
$key = $this->replace_prefix_wpsc_from_fieldname($key); |
| 1417 |
$key = $this->replace_underscore_from_fieldname($key); |
| 1418 |
$key = $this->replace_wpcr3_from_fieldname($key); |
| 1419 |
// Change fieldname depends on the post type |
| 1420 |
$key = $this->change_fieldname_depends_on_post_type($rowValue['post_type'], $key); |
| 1421 |
|
| 1422 |
if(isset($rowValue['wpcr3_'.$key])){ |
| 1423 |
$rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['wpcr3_'.$key], $hKey); |
| 1424 |
}else{ |
| 1425 |
if(isset($rowValue['_yoast_wpseo_'.$key])){ // Is available in yoast plugin |
| 1426 |
$rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_yoast_wpseo_'.$key]); |
| 1427 |
} |
| 1428 |
else if(isset($rowValue['_aioseop_'.$key])){ // Is available in all seo plugin |
| 1429 |
$rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_aioseop_'.$key]); |
| 1430 |
} |
| 1431 |
else if(isset($rowValue['_'.$key])){ // Is wp custom fields |
| 1432 |
$rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue['_'.$key], $hKey); |
| 1433 |
} |
| 1434 |
else if($fieldvalue = $this->getWoocommerceMetaValue($key, $rowValue['post_type'], $rowValue)){ |
| 1435 |
$rowValue[$key] = $fieldvalue; |
| 1436 |
} |
| 1437 |
else if(isset($rowValue['ID']) && $aioseo_field_value = $this->getaioseoFieldValue($rowValue['ID'])){ |
| 1438 |
$rowValue['og_title'] = $aioseo_field_value[0]->og_title; |
| 1439 |
$rowValue['og_description']= $aioseo_field_value[0]->og_description; |
| 1440 |
$rowValue['custom_link'] = $aioseo_field_value[0]->canonical_url; |
| 1441 |
$rowValue['og_image_type'] = $aioseo_field_value[0]->og_image_type; |
| 1442 |
$rowValue['og_image_custom_fields'] = $aioseo_field_value[0]->og_image_custom_fields; |
| 1443 |
$rowValue['og_video'] = $aioseo_field_value[0]->og_video; |
| 1444 |
$rowValue['og_object_type'] = $aioseo_field_value[0]->og_object_type; |
| 1445 |
$value=$aioseo_field_value[0]->og_article_tags; |
| 1446 |
$article_tags = json_decode($value); |
| 1447 |
$og_article_tags=$article_tags[0]->value; |
| 1448 |
$rowValue['og_article_tags'] = $og_article_tags; |
| 1449 |
$rowValue['og_article_section'] = $aioseo_field_value[0]->og_article_section; |
| 1450 |
$rowValue['twitter_use_og'] = $aioseo_field_value[0]->twitter_use_og; |
| 1451 |
$rowValue['twitter_card'] = $aioseo_field_value[0]->twitter_card; |
| 1452 |
$rowValue['twitter_image_type'] = $aioseo_field_value[0]->twitter_image_type; |
| 1453 |
$rowValue['twitter_image_custom_fields'] = $aioseo_field_value[0]->twitter_image_custom_fields; |
| 1454 |
$rowValue['twitter_title'] = $aioseo_field_value[0]->twitter_title; |
| 1455 |
$rowValue['twitter_description'] = $aioseo_field_value[0]->twitter_description; |
| 1456 |
$rowValue['robots_default'] = $aioseo_field_value[0]->robots_default; |
| 1457 |
// $rowValue['robots_noindex'] = $aioseo_field_value[0]->robots_noindex; |
| 1458 |
$rowValue['robots_noarchive'] = $aioseo_field_value[0]->robots_noarchive; |
| 1459 |
$rowValue['robots_nosnippet'] = $aioseo_field_value[0]->robots_nosnippet; |
| 1460 |
// $rowValue['robots_nofollow'] = $aioseo_field_value[0]->robots_nofollow; |
| 1461 |
$rowValue['robots_noimageindex'] = $aioseo_field_value[0]->robots_noimageindex; |
| 1462 |
$rowValue['noodp'] = $aioseo_field_value[0]->robots_noodp; |
| 1463 |
$rowValue['robots_notranslate'] = $aioseo_field_value[0]->robots_notranslate; |
| 1464 |
$rowValue['robots_max_snippet'] = $aioseo_field_value[0]->robots_max_snippet; |
| 1465 |
$rowValue['robots_max_videopreview'] = $aioseo_field_value[0]->robots_max_videopreview; |
| 1466 |
$rowValue['robots_max_imagepreview'] = $aioseo_field_value[0]->robots_max_imagepreview; |
| 1467 |
$rowValue['aioseo_title'] = $aioseo_field_value[0]->title; |
| 1468 |
$rowValue['aioseo_description'] = $aioseo_field_value[0]->description; |
| 1469 |
$key=$aioseo_field_value[0]->keyphrases; |
| 1470 |
|
| 1471 |
$key1=json_decode($key); |
| 1472 |
$rowValue['keyphrases'] = $key1->focus->keyphrase; |
| 1473 |
} |
| 1474 |
else{ |
| 1475 |
$rowValue[$key] = isset($rowValue[$key]) ? $rowValue[$key] :''; |
| 1476 |
$rowValue[$key] = $this->returnMetaValueAsCustomerInput($rowValue[$key], $hKey); |
| 1477 |
} |
| 1478 |
} |
| 1479 |
global $wpdb; |
| 1480 |
//Added for user export |
| 1481 |
if($key =='user_login') |
| 1482 |
{ |
| 1483 |
$wpsc_query = $wpdb->prepare("select ID from {$wpdb->prefix}users where user_login =%s", $rowValue['user_login']); |
| 1484 |
$wpsc_meta = $wpdb->get_results($wpsc_query,ARRAY_A); |
| 1485 |
} |
| 1486 |
if(isset($rowValue['_bbp_forum_type']) && ($rowValue['_bbp_forum_type'] =='forum'||$rowValue['_bbp_forum_type']=='category' )){ |
| 1487 |
if($key =='Visibility'){ |
| 1488 |
$rowValue[$key]=$rowValue['post_status']; |
| 1489 |
} |
| 1490 |
if($key =='bbp_moderators') { |
| 1491 |
$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); |
| 1492 |
$forum_moderators = ''; |
| 1493 |
foreach($get_forum_moderator_ids as $get_moderator_id){ |
| 1494 |
$forum_user_meta = get_user_by('id', $get_moderator_id['meta_value']); |
| 1495 |
$forum_user = $forum_user_meta->data->user_login; |
| 1496 |
$forum_moderators .= $forum_user. ','; |
| 1497 |
} |
| 1498 |
|
| 1499 |
$rowValue[$key] = rtrim($forum_moderators, ','); |
| 1500 |
} |
| 1501 |
|
| 1502 |
} |
| 1503 |
if($key =='topic_status' ||$key =='author' ||$key =='topic_type' ){ |
| 1504 |
$rowValue['topic_status']=$rowValue['post_status']; |
| 1505 |
$rowValue['author']=$rowValue['post_author']; |
| 1506 |
if($key =='topic_type'){ |
| 1507 |
$Topictype =get_post_meta($rowValue['_bbp_forum_id'],'_bbp_sticky_topics'); |
| 1508 |
$topic_types = get_option('_bbp_super_sticky_topics'); |
| 1509 |
$rowValue['topic_type']='normal'; |
| 1510 |
if($Topictype){ |
| 1511 |
foreach($Topictype as $t_type){ |
| 1512 |
if($t_type['0']== $recordId){ |
| 1513 |
$rowValue['topic_type']='sticky'; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
}elseif(!empty($topic_types)){ |
| 1517 |
foreach($topic_types as $top_type){ |
| 1518 |
if($top_type == $rowValue['ID']){ |
| 1519 |
$rowValue['topic_type']='super sticky'; |
| 1520 |
} |
| 1521 |
} |
| 1522 |
} |
| 1523 |
} |
| 1524 |
}if($key =='reply_status'||$key =='reply_author'){ |
| 1525 |
$rowValue['reply_status']=$rowValue['post_status']; |
| 1526 |
$rowValue['reply_author']=$rowValue['post_author']; |
| 1527 |
} |
| 1528 |
if(array_key_exists($hKey, $rowValue)){ |
| 1529 |
$result[$recordId][$hKey] = $rowValue[$hKey]; |
| 1530 |
}else{ |
| 1531 |
$result[$recordId][$hKey] = ''; |
| 1532 |
} |
| 1533 |
} |
| 1534 |
} |
| 1535 |
} |
| 1536 |
return $result; |
| 1537 |
} |
| 1538 |
|
| 1539 |
function get_common_post_metadata($meta_id){ |
| 1540 |
global $wpdb; |
| 1541 |
$mdata = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$wpdb->prefix}usermeta WHERE umeta_id = %d", $meta_id) ,ARRAY_A); |
| 1542 |
return $mdata[0]; |
| 1543 |
} |
| 1544 |
|
| 1545 |
function get_common_unserialize($serialize_data){ |
| 1546 |
return unserialize($serialize_data); |
| 1547 |
} |
| 1548 |
|
| 1549 |
/** |
| 1550 |
* Create CSV data from array |
| 1551 |
* @param array $data 2D array with data |
| 1552 |
* @param array $fields field names |
| 1553 |
* @param bool $append if true, field names will not be output |
| 1554 |
* @param bool $is_php if a php die() call should be put on the first |
| 1555 |
* line of the file, this is later ignored when read. |
| 1556 |
* @param null $delimiter field delimiter to use |
| 1557 |
* @return string CSV data (text string) |
| 1558 |
*/ |
| 1559 |
public function unParse ( $data = array(), $fields = array(), $append = false , $is_php = false, $delimiter = null) { |
| 1560 |
if ( !is_array($data) || empty($data) ) $data = &$this->data; |
| 1561 |
if ( !is_array($fields) || empty($fields) ) $fields = &$this->titles; |
| 1562 |
if ( $delimiter === null ) $delimiter = $this->delimiter; |
| 1563 |
|
| 1564 |
$string = ( $is_php ) ? "<?php header('Status: 403'); die(' '); ?>".$this->linefeed : '' ; |
| 1565 |
$entry = array(); |
| 1566 |
|
| 1567 |
// create heading |
| 1568 |
if ($this->offset == 0 || $this->checkSplit == 'true') { |
| 1569 |
if ( $this->heading && !$append && !empty($fields) ) { |
| 1570 |
foreach( $fields as $key => $value ) { |
| 1571 |
$entry[] = $this->_enclose_value($value); |
| 1572 |
} |
| 1573 |
$string .= implode($delimiter, $entry).$this->linefeed; |
| 1574 |
$entry = array(); |
| 1575 |
} |
| 1576 |
} |
| 1577 |
|
| 1578 |
// create data |
| 1579 |
foreach( $data as $key => $row ) { |
| 1580 |
foreach( $row as $field => $value ) { |
| 1581 |
$entry[] = $this->_enclose_value($value); |
| 1582 |
} |
| 1583 |
$string .= implode($delimiter, $entry).$this->linefeed; |
| 1584 |
$entry = array(); |
| 1585 |
} |
| 1586 |
return $string; |
| 1587 |
} |
| 1588 |
|
| 1589 |
/** |
| 1590 |
* Enclose values if needed |
| 1591 |
* - only used by unParse() |
| 1592 |
* @param null $value |
| 1593 |
* @return mixed|null|string |
| 1594 |
*/ |
| 1595 |
public function _enclose_value ($value = null) { |
| 1596 |
if ( $value !== null && $value != '' ) { |
| 1597 |
$delimiter = preg_quote($this->delimiter, '/'); |
| 1598 |
$enclosure = preg_quote($this->enclosure, '/'); |
| 1599 |
if($value[0]=='=') $value="'".$value; # Fix for the Comma separated vulnerabilities. |
| 1600 |
if ( preg_match("/".$delimiter."|".$enclosure."|\n|\r/i", $value) || ($value[0] == ' ' || substr($value, -1) == ' ') ) { |
| 1601 |
$value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value); |
| 1602 |
$value = $this->enclosure.$value.$this->enclosure; |
| 1603 |
} |
| 1604 |
else |
| 1605 |
$value = $this->enclosure.$value.$this->enclosure; |
| 1606 |
} |
| 1607 |
return $value; |
| 1608 |
} |
| 1609 |
|
| 1610 |
/** |
| 1611 |
* Apply exclusion before export |
| 1612 |
* @param $headers - Apply exclusion headers |
| 1613 |
* @return array - Available headers after applying the exclusions |
| 1614 |
*/ |
| 1615 |
public function applyEventExclusion ($headers) { |
| 1616 |
$header_exclusion = array(); |
| 1617 |
foreach ($headers as $hVal) { |
| 1618 |
if(array_key_exists($hVal, $this->eventExclusions['exclusion_headers']['header'])) { |
| 1619 |
$header_exclusion[] = $hVal; |
| 1620 |
} |
| 1621 |
} |
| 1622 |
return $header_exclusion; |
| 1623 |
} |
| 1624 |
|
| 1625 |
public function replace_prefix_aioseop_from_fieldname($fieldname){ |
| 1626 |
if(preg_match('/_aioseop_/', $fieldname)){ |
| 1627 |
return preg_replace('/_aioseop_/', '', $fieldname); |
| 1628 |
} |
| 1629 |
|
| 1630 |
return $fieldname; |
| 1631 |
} |
| 1632 |
public function getaioseoFieldValue($post_id){ |
| 1633 |
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')) |
| 1634 |
{ |
| 1635 |
global $wpdb; |
| 1636 |
$aioseo_slug =$wpdb->get_results("SELECT * FROM {$wpdb->prefix}aioseo_posts WHERE post_id='$post_id' "); |
| 1637 |
return $aioseo_slug; |
| 1638 |
} |
| 1639 |
|
| 1640 |
} |
| 1641 |
|
| 1642 |
public function replace_prefix_pods_from_fieldname($fieldname){ |
| 1643 |
if(preg_match('/_pods_/', $fieldname)){ |
| 1644 |
return preg_replace('/_pods_/', '', $fieldname); |
| 1645 |
} |
| 1646 |
|
| 1647 |
return $fieldname; |
| 1648 |
} |
| 1649 |
|
| 1650 |
public function replace_prefix_yoast_wpseo_from_fieldname($fieldname){ |
| 1651 |
|
| 1652 |
if(preg_match('/_yoast_wpseo_/', $fieldname)){ |
| 1653 |
$fieldname = preg_replace('/_yoast_wpseo_/', '', $fieldname); |
| 1654 |
|
| 1655 |
if($fieldname == 'focuskw') { |
| 1656 |
$fieldname = 'focus_keyword'; |
| 1657 |
}else if($fieldname == 'bread-crumbs-title') { // It is comming as bctitle nowadays |
| 1658 |
$fieldname = 'bctitle'; |
| 1659 |
}elseif($fieldname == 'metadesc') { |
| 1660 |
$fieldname = 'meta_desc'; |
| 1661 |
} |
| 1662 |
} |
| 1663 |
|
| 1664 |
return $fieldname; |
| 1665 |
} |
| 1666 |
|
| 1667 |
public function replace_prefix_wpcf_from_fieldname($fieldname){ |
| 1668 |
if(preg_match('/_wpcf/', $fieldname)){ |
| 1669 |
return preg_replace('/_wpcf/', '', $fieldname); |
| 1670 |
} |
| 1671 |
|
| 1672 |
return $fieldname; |
| 1673 |
} |
| 1674 |
|
| 1675 |
public function replace_prefix_wpsc_from_fieldname($fieldname){ |
| 1676 |
if(preg_match('/_wpsc_/', $fieldname)){ |
| 1677 |
return preg_replace('/_wpsc_/', '', $fieldname); |
| 1678 |
} |
| 1679 |
|
| 1680 |
return $fieldname; |
| 1681 |
} |
| 1682 |
|
| 1683 |
public function replace_wpcr3_from_fieldname($fieldname){ |
| 1684 |
if(preg_match('/wpcr3_/', $fieldname)){ |
| 1685 |
$fieldname = preg_replace('/wpcr3_/', '', $fieldname); |
| 1686 |
} |
| 1687 |
|
| 1688 |
return $fieldname; |
| 1689 |
} |
| 1690 |
|
| 1691 |
public function change_fieldname_depends_on_post_type($post_type, $fieldname){ |
| 1692 |
if($post_type == 'wpcr3_review'){ |
| 1693 |
switch ($fieldname) { |
| 1694 |
case 'ID': |
| 1695 |
return 'review_id'; |
| 1696 |
case 'post_status': |
| 1697 |
return 'status'; |
| 1698 |
case 'post_content': |
| 1699 |
return 'review_text'; |
| 1700 |
case 'post_date': |
| 1701 |
return 'date_time'; |
| 1702 |
default: |
| 1703 |
return $fieldname; |
| 1704 |
} |
| 1705 |
} |
| 1706 |
if($post_type == 'shop_order_refund'){ |
| 1707 |
switch ($fieldname) { |
| 1708 |
case 'ID': |
| 1709 |
return 'REFUNDID'; |
| 1710 |
default: |
| 1711 |
return $fieldname; |
| 1712 |
} |
| 1713 |
}else if($post_type == 'shop_order'){ |
| 1714 |
switch ($fieldname) { |
| 1715 |
case 'ID': |
| 1716 |
return 'ORDERID'; |
| 1717 |
case 'post_status': |
| 1718 |
return 'order_status'; |
| 1719 |
case 'post_excerpt': |
| 1720 |
return 'customer_note'; |
| 1721 |
case 'post_date': |
| 1722 |
return 'order_date'; |
| 1723 |
default: |
| 1724 |
return $fieldname; |
| 1725 |
} |
| 1726 |
}else if($post_type == 'shop_coupon'){ |
| 1727 |
switch ($fieldname) { |
| 1728 |
case 'ID': |
| 1729 |
return 'COUPONID'; |
| 1730 |
case 'post_status': |
| 1731 |
return 'coupon_status'; |
| 1732 |
case 'post_excerpt': |
| 1733 |
return 'description'; |
| 1734 |
case 'post_date': |
| 1735 |
return 'coupon_date'; |
| 1736 |
case 'post_title': |
| 1737 |
return 'coupon_code'; |
| 1738 |
default: |
| 1739 |
return $fieldname; |
| 1740 |
} |
| 1741 |
}else if($post_type == 'product_variation'){ |
| 1742 |
switch ($fieldname) { |
| 1743 |
case 'ID': |
| 1744 |
return 'VARIATIONID'; |
| 1745 |
case 'post_parent': |
| 1746 |
return 'PRODUCTID'; |
| 1747 |
case 'sku': |
| 1748 |
return 'VARIATIONSKU'; |
| 1749 |
default: |
| 1750 |
return $fieldname; |
| 1751 |
} |
| 1752 |
} |
| 1753 |
|
| 1754 |
return $fieldname; |
| 1755 |
} |
| 1756 |
|
| 1757 |
public function replace_underscore_from_fieldname($fieldname){ |
| 1758 |
if(preg_match('/_/', $fieldname)){ |
| 1759 |
$fieldname = preg_replace('/^_/', '', $fieldname); |
| 1760 |
} |
| 1761 |
|
| 1762 |
return $fieldname; |
| 1763 |
} |
| 1764 |
|
| 1765 |
public function fetchCategoryFieldValue($categories){ |
| 1766 |
|
| 1767 |
global $wpdb; |
| 1768 |
$bulk_category = []; |
| 1769 |
|
| 1770 |
foreach($categories as $category_id => $category){ |
| 1771 |
$term_meta = get_term_meta($category_id); |
| 1772 |
$single_category = []; |
| 1773 |
foreach($this->headers as $header){ |
| 1774 |
|
| 1775 |
if($header == 'name'){ |
| 1776 |
$cato[] = get_term($category_id); |
| 1777 |
$single_category[$header] = $this->hierarchy_based_term_cat_name($cato, 'category'); |
| 1778 |
//$single_category[$header] = $this->hierarchy_based_term_name(get_term($category_id), 'category'); |
| 1779 |
continue; |
| 1780 |
} |
| 1781 |
|
| 1782 |
if(array_key_exists($header, $category)){ |
| 1783 |
$single_category[$header] = $category[$header]; |
| 1784 |
}else{ |
| 1785 |
if(isset($term_meta[$header])){ |
| 1786 |
$single_category[$header] = $this->returnMetaValueAsCustomerInput($term_meta[$header]); |
| 1787 |
}else{ |
| 1788 |
$single_category[$header] = null; |
| 1789 |
} |
| 1790 |
} |
| 1791 |
} |
| 1792 |
array_push($bulk_category, $single_category); |
| 1793 |
} |
| 1794 |
return $bulk_category; |
| 1795 |
} |
| 1796 |
|
| 1797 |
public function returnMetaValueAsCustomerInput($meta_value, $header = false){ |
| 1798 |
|
| 1799 |
if(is_array($meta_value)){ |
| 1800 |
$meta_value = $meta_value[0]; |
| 1801 |
if(!empty($meta_value)){ |
| 1802 |
if(is_serialized($meta_value)){ |
| 1803 |
return unserialize($meta_value); |
| 1804 |
}else if(is_array($meta_value)){ |
| 1805 |
return implode('|', $meta_value); |
| 1806 |
}else if(is_string($meta_value)){ |
| 1807 |
return $meta_value; |
| 1808 |
}else if($this->isJSON($meta_value) === true){ |
| 1809 |
return json_decode($meta_value); |
| 1810 |
} |
| 1811 |
|
| 1812 |
return $meta_value; |
| 1813 |
} |
| 1814 |
|
| 1815 |
return $meta_value; |
| 1816 |
}else{ |
| 1817 |
if(is_serialized($meta_value)){ |
| 1818 |
$meta_value = unserialize($meta_value); |
| 1819 |
if(is_array($meta_value)){ |
| 1820 |
return implode('|', $meta_value); |
| 1821 |
} |
| 1822 |
return $meta_value; |
| 1823 |
}else if(is_array($meta_value)){ |
| 1824 |
return implode('|', $meta_value); |
| 1825 |
}else if(is_string($meta_value)){ |
| 1826 |
return $meta_value; |
| 1827 |
}else if($this->isJSON($meta_value) === true){ |
| 1828 |
return json_decode($meta_value); |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
return $meta_value; |
| 1833 |
} |
| 1834 |
|
| 1835 |
public function isJSON($meta_value) { |
| 1836 |
$json = json_decode($meta_value); |
| 1837 |
return $json && $meta_value != $json; |
| 1838 |
} |
| 1839 |
|
| 1840 |
public function hierarchy_based_term_name($term, $taxanomy_type){ |
| 1841 |
|
| 1842 |
$tempo = array(); |
| 1843 |
$termo = ''; |
| 1844 |
$i=0; |
| 1845 |
foreach($term as $termkey => $terms){ |
| 1846 |
$tempo[] = $terms->name; |
| 1847 |
$temp_hierarchy_terms = []; |
| 1848 |
|
| 1849 |
if(!empty($terms->parent)){ |
| 1850 |
$temp1 = $terms->name; |
| 1851 |
//$termo = ''; |
| 1852 |
$i++; |
| 1853 |
|
| 1854 |
$termexp = explode(',',$termo); |
| 1855 |
|
| 1856 |
|
| 1857 |
$termo = implode(',',$termexp); |
| 1858 |
//$termo = implode(',',$termunset); |
| 1859 |
|
| 1860 |
$temp_hierarchy_terms[] = $terms->name; |
| 1861 |
$hierarchy_terms = $this->call_back_to_get_parent($terms->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms); |
| 1862 |
$parent_name=get_term($terms->parent); |
| 1863 |
$termo .= $this->split_terms_by_arrow($hierarchy_terms,$parent_name->name).','; |
| 1864 |
|
| 1865 |
|
| 1866 |
}else{ |
| 1867 |
|
| 1868 |
|
| 1869 |
if(in_array($terms->name,$tempo)){ |
| 1870 |
|
| 1871 |
$termo .= $terms->name.','; |
| 1872 |
|
| 1873 |
} |
| 1874 |
} |
| 1875 |
} |
| 1876 |
return $termo; |
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
} |
| 1881 |
|
| 1882 |
public function hierarchy_based_term_cat_name($term, $taxanomy_type){ |
| 1883 |
$tempo = array(); |
| 1884 |
$termo = ''; |
| 1885 |
foreach($term as $terms){ |
| 1886 |
$tempo[] = $terms->name; |
| 1887 |
$temp_hierarchy_terms = []; |
| 1888 |
if(!empty($terms->parent)){ |
| 1889 |
$temp_hierarchy_terms[] = $terms->name; |
| 1890 |
$hierarchy_terms = $this->call_back_to_get_parent($terms->parent, $taxanomy_type, $tempo, $temp_hierarchy_terms); |
| 1891 |
$parent_name=get_term($terms->parent); |
| 1892 |
$termo = $this->split_terms_by_arrow($hierarchy_terms,$parent_name->name); |
| 1893 |
|
| 1894 |
}else{ |
| 1895 |
$termo = $terms->name; |
| 1896 |
|
| 1897 |
} |
| 1898 |
} |
| 1899 |
return $termo; |
| 1900 |
} |
| 1901 |
public function call_back_to_get_parent($term_id, $taxanomy_type,$tempo, $temp_hierarchy_terms = []){ |
| 1902 |
$term = get_term($term_id, $taxanomy_type); |
| 1903 |
if(!empty($term->parent)){ |
| 1904 |
if(in_array($term->name,$tempo)){ |
| 1905 |
|
| 1906 |
$temp_hierarchy_terms[] = $term->name; |
| 1907 |
|
| 1908 |
$temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type,$tempo, $temp_hierarchy_terms); |
| 1909 |
} |
| 1910 |
else{ |
| 1911 |
$temp_hierarchy_terms[] = ''; |
| 1912 |
|
| 1913 |
$temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type,$tempo, $temp_hierarchy_terms); |
| 1914 |
} |
| 1915 |
|
| 1916 |
}else{ |
| 1917 |
if(in_array($term->name,$tempo)){ |
| 1918 |
$temp_hierarchy_terms[] = $term->name; |
| 1919 |
} |
| 1920 |
else{ |
| 1921 |
$temp_hierarchy_terms[] = ''; |
| 1922 |
} |
| 1923 |
} |
| 1924 |
return $temp_hierarchy_terms; |
| 1925 |
} |
| 1926 |
// public function call_back_to_get_parent($term_id, $taxanomy_type, $temp_hierarchy_terms = []){ |
| 1927 |
|
| 1928 |
// $term = get_term($term_id, $taxanomy_type); |
| 1929 |
// if(!empty($term->parent)){ |
| 1930 |
// $temp_hierarchy_terms[] = $term->name; |
| 1931 |
// $temp_hierarchy_terms = $this->call_back_to_get_parent($term->parent, $taxanomy_type, $temp_hierarchy_terms); |
| 1932 |
// }else{ |
| 1933 |
// $temp_hierarchy_terms[] = $term->name; |
| 1934 |
// } |
| 1935 |
|
| 1936 |
// return $temp_hierarchy_terms; |
| 1937 |
// } |
| 1938 |
|
| 1939 |
public function split_terms_by_arrow($hierarchy_terms,$termParentName){ |
| 1940 |
|
| 1941 |
krsort($hierarchy_terms); |
| 1942 |
$terms_value = $termParentName.'>'.$hierarchy_terms[0]; |
| 1943 |
//return implode('>', $hierarchy_terms); |
| 1944 |
return $terms_value; |
| 1945 |
} |
| 1946 |
|
| 1947 |
public function getWoocommerceMetaValue($fieldname, $post_type, $post){ |
| 1948 |
$post_type=isset($post_type)?$post_type:''; |
| 1949 |
if($post_type == 'shop_order_refund'){ |
| 1950 |
switch ($fieldname) { |
| 1951 |
case 'REFUNDID': |
| 1952 |
return $post['ID']; |
| 1953 |
default: |
| 1954 |
return $post[$fieldname]; |
| 1955 |
} |
| 1956 |
}else if($post_type == 'shop_order'){ |
| 1957 |
switch ($fieldname) { |
| 1958 |
case 'ORDERID': |
| 1959 |
return $post['ID']; |
| 1960 |
case 'order_status': |
| 1961 |
return $post['post_status']; |
| 1962 |
case 'customer_note': |
| 1963 |
return $post['post_excerpt']; |
| 1964 |
case 'order_date': |
| 1965 |
return $post['post_date']; |
| 1966 |
default: |
| 1967 |
return $post[$fieldname]; |
| 1968 |
} |
| 1969 |
}else if($post_type == 'shop_coupon'){ |
| 1970 |
switch ($fieldname) { |
| 1971 |
case 'COUPONID': |
| 1972 |
return $post['ID']; |
| 1973 |
case 'coupon_status': |
| 1974 |
return $post['post_status']; |
| 1975 |
case 'description': |
| 1976 |
return $post['post_excerpt']; |
| 1977 |
case 'coupon_date': |
| 1978 |
return $post['post_date']; |
| 1979 |
case 'coupon_code': |
| 1980 |
return $post['post_title']; |
| 1981 |
case 'expiry_date': |
| 1982 |
if(isset($post['date_expires'])){ |
| 1983 |
$timeinfo=date('m/d/Y',$post['date_expires']); |
| 1984 |
} |
| 1985 |
$timeinfo=isset($timeinfo)?$timeinfo:''; |
| 1986 |
return $timeinfo; |
| 1987 |
default: |
| 1988 |
return $post[$fieldname]; |
| 1989 |
} |
| 1990 |
}else if($post_type == 'product_variation'){ |
| 1991 |
switch ($fieldname) { |
| 1992 |
case 'VARIATIONID': |
| 1993 |
return $post['ID']; |
| 1994 |
case 'PRODUCTID': |
| 1995 |
return $post['post_parent']; |
| 1996 |
case 'VARIATIONSKU': |
| 1997 |
return $post['sku']; |
| 1998 |
default: |
| 1999 |
return $post[$fieldname]; |
| 2000 |
} |
| 2001 |
} |
| 2002 |
return false; |
| 2003 |
} |
| 2004 |
|
| 2005 |
} |
| 2006 |
|
| 2007 |
return new exportExtension(); |
| 2008 |
} |