From 00fc23bf4e169b4a48ae0bafae12cc3946b38cd6 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 4 Aug 2014 16:47:49 -0700 Subject: issue #551 provide import/export of profiles (if this feature is enabled) --- include/features.php | 4 ++-- include/identity.php | 16 +++++++--------- mod/profiles.php | 36 ++++++++++++++++++++++++++++++++++++ view/tpl/profile_edit.tpl | 8 +++++++- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/include/features.php b/include/features.php index 383cb739f..6bb444cb6 100644 --- a/include/features.php +++ b/include/features.php @@ -24,8 +24,8 @@ function get_features() { // This is per post, and different from fixed expiration 'expire' which isn't working yet array('content_expire', t('Content Expiration'), t('Remove posts/comments and/or private messages at a future time')), array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles')), - array('advanced_profiles', t('Advanced Profiles'), t('Additional profile sections and selections')), - + array('advanced_profiles', t('Advanced Profiles'), t('Additional profile sections and selections')), + array('profile_export', t('Profile Import/Export'), t('Save and load profile details across sites/channels')), array('webpages', t('Web Pages'), t('Provide managed web pages on your channel')), array('private_notes', t('Private Notes'), t('Enables a tool to store notes and reminders')), // prettyphoto has licensing issues and will no longer be provided in core - diff --git a/include/identity.php b/include/identity.php index feb249ea3..643961465 100644 --- a/include/identity.php +++ b/include/identity.php @@ -1313,12 +1313,12 @@ function is_public_profile() { return false; } -function get_profile_fields_basic() { - $profile_fields_basic = get_config('system','profile_fields_basic'); +function get_profile_fields_basic($filter = 0) { + + $profile_fields_basic = (($filter == 0) ? get_config('system','profile_fields_basic') : null); if(! $profile_fields_basic) - $profile_fields_basic = array('name','pdesc','gender','dob','address','locality','region','postal_code','country_name','marital','sexual','homepage','hometown','keywords','about','contact'); + $profile_fields_basic = array('name','pdesc','chandesc','gender','dob','dob_tz','address','locality','region','postal_code','country_name','marital','sexual','homepage','hometown','keywords','about','contact'); -// return $profile_fields_basic; $x = array(); if($profile_fields_basic) foreach($profile_fields_basic as $f) @@ -1329,14 +1329,12 @@ function get_profile_fields_basic() { } -function get_profile_fields_advanced() { - $basic = get_profile_fields_basic(); - $profile_fields_advanced = get_config('system','profile_fields_advanced'); +function get_profile_fields_advanced($filter = 0) { + $basic = get_profile_fields_basic($filter); + $profile_fields_advanced = (($filter == 0) ? get_config('system','profile_fields_advanced') : null); if(! $profile_fields_advanced) $profile_fields_advanced = array('with','howlong','politic','religion','likes','dislikes','interest','channels','music','book','film','tv','romance','work','education'); -// return $profile_fields_advanced; - $x = array(); if($basic) foreach($basic as $f => $v) diff --git a/mod/profiles.php b/mod/profiles.php index c063599b4..bcaae909b 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -186,6 +186,33 @@ function profiles_post(&$a) { call_hooks('profile_post', $_POST); + // import from json export file. + // Only import fields that are allowed on this hub + + if(x($_FILES,'userfile')) { + $src = $_FILES['userfile']['tmp_name']; + $filesize = intval($_FILES['userfile']['size']); + if($filesize) { + $j = @json_decode(@file_get_contents($src),true); + @unlink($src); + if($j) { + $fields = get_profile_fields_advanced(); + if($fields) { + foreach($j as $jj => $v) { + foreach($fields as $f => $n) { + if($jj == $f) { + $_POST[$f] = $v; + break; + } + } + } + } + } + } + } + + + if((argc() > 1) && (argv(1) !== "new") && intval(argv(1))) { $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), @@ -205,6 +232,12 @@ function profiles_post(&$a) { notify( t('Profile Name is required.') . EOL); return; } + + if($_POST['dob']) { + $year = substr($_POST['dob'],0,4); + $month = substr($_POST['dob'],5,2); + $day = substr($_POST['dob'],8,2); + } $year = intval($_POST['year']); if($year < 1900 || $year > 2100 || $year < 0) @@ -559,6 +592,9 @@ function profiles_content(&$a) { '$cr_prof' => t('Create a new profile using these settings'), '$cl_prof' => t('Clone this profile'), '$del_prof' => t('Delete this profile'), + '$exportable' => feature_enabled(local_user(),'profile_export'), + '$lbl_import' => t('Import profile from file'), + '$lbl_export' => t('Export profile to file'), '$lbl_profname' => t('Profile Name:'), '$lbl_fullname' => t('Your Full Name:'), '$lbl_title' => t('Title/Description:'), diff --git a/view/tpl/profile_edit.tpl b/view/tpl/profile_edit.tpl index 1a99a07be..afd24185c 100755 --- a/view/tpl/profile_edit.tpl +++ b/view/tpl/profile_edit.tpl @@ -2,23 +2,29 @@

{{$banner}}

+
+ + +
-
-- cgit v1.2.3