| 1 |
<?php |
| 2 |
/****************************************************************************************** |
| 3 |
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License |
| 4 |
* Unauthorized copying of this file, via any medium is strictly prohibited |
| 5 |
* Proprietary and confidential |
| 6 |
* You can contact Smackcoders at email address info@smackcoders.com. |
| 7 |
*******************************************************************************************/ |
| 8 |
|
| 9 |
namespace Smackcoders\SMUSERS; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) |
| 12 |
exit; // Exit if accessed directly |
| 13 |
|
| 14 |
class BuddyImport extends UsersImport{ |
| 15 |
private static $buddy_instance = null; |
| 16 |
|
| 17 |
public static function getInstance() { |
| 18 |
|
| 19 |
if (BuddyImport::$buddy_instance == null) { |
| 20 |
BuddyImport::$buddy_instance = new BuddyImport; |
| 21 |
return BuddyImport::$buddy_instance; |
| 22 |
} |
| 23 |
return BuddyImport::$buddy_instance; |
| 24 |
} |
| 25 |
|
| 26 |
function set_buddy_values($header_array ,$value_array , $map, $post_id , $type){ |
| 27 |
$post_values = []; |
| 28 |
$helpers_instance = ImportHelpers::getInstance(); |
| 29 |
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array); |
| 30 |
$this->buddy_import_function($post_values,$type, $post_id); |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
function buddy_import_function($data_array, $importas,$uID) { |
| 35 |
|
| 36 |
global $wpdb; |
| 37 |
foreach($data_array as $data_key => $data_value) { |
| 38 |
$get_buddy_fields = $wpdb->get_results($wpdb->prepare("select type , name from {$wpdb->prefix}bp_xprofile_fields where id= $data_key" ), ARRAY_A); |
| 39 |
foreach($get_buddy_fields as $buddy_fields){ |
| 40 |
$field_type = $buddy_fields['type']; |
| 41 |
if($field_type == 'multiselect_custom_post_type') |
| 42 |
{ |
| 43 |
$explode = explode('|',$data_value); |
| 44 |
$data_value = serialize($explode); |
| 45 |
} |
| 46 |
elseif($field_type == 'multiselectbox') |
| 47 |
{ |
| 48 |
$explode = explode('|',$data_value); |
| 49 |
$data_value = serialize($explode); |
| 50 |
|
| 51 |
} |
| 52 |
elseif($field_type == 'multiselect_custom_taxonomy') |
| 53 |
{ |
| 54 |
$explode = explode('|',$data_value); |
| 55 |
$data_value = serialize($explode); |
| 56 |
} |
| 57 |
|
| 58 |
elseif($field_type == 'fromto') |
| 59 |
{ |
| 60 |
$explode = explode('|',$data_value); |
| 61 |
$data_results['from'] = $explode[0]; |
| 62 |
$data_results['to'] = $explode[1]; |
| 63 |
$data_value = serialize($data_results); |
| 64 |
} |
| 65 |
elseif($field_type == 'image') |
| 66 |
{ |
| 67 |
$image_name = $data_value; |
| 68 |
$upload_path = wp_upload_dir(); |
| 69 |
$path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/image'; |
| 70 |
$base_name=basename($image_name); |
| 71 |
wp_mkdir_p($path); |
| 72 |
$data = file_get_contents($image_name); |
| 73 |
$new = $path.'/'.$base_name; |
| 74 |
file_put_contents($new, $data); |
| 75 |
$image_path = "bpxcftr-profile-uploads/$uID/image/".basename($image_name); |
| 76 |
$data_value = $image_path; |
| 77 |
} |
| 78 |
elseif($field_type == 'file') |
| 79 |
{ |
| 80 |
$file_name = $data_value; |
| 81 |
$upload_path = wp_upload_dir(); |
| 82 |
$path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/file'; |
| 83 |
$base_name=basename($file_name); |
| 84 |
wp_mkdir_p($path); |
| 85 |
$data = file_get_contents($file_name); |
| 86 |
$new = $path.'/'.$base_name; |
| 87 |
file_put_contents($new, $data); |
| 88 |
$file_path = "bpxcftr-profile-uploads/$uID/file/".basename($file_name); |
| 89 |
$data_value = $file_path; |
| 90 |
} |
| 91 |
} |
| 92 |
$wpdb->insert("{$wpdb->prefix}bp_xprofile_data", array('field_id' => $data_key,'user_id' => $uID,'value' => $data_value)); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
global $buddy_class; |
| 97 |
$buddy_class = new BuddyImport; |