From 08bcd29eeee1166d62791b04c7de4a6c1a4e7456 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 1 May 2018 16:15:59 -0700 Subject: hubzilla issue #1149, don't duplicate addressbook entries on repeated channel imports --- Zotlabs/Module/Import.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 81c405f00..58f0c60d5 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -363,11 +363,27 @@ class Import extends \Zotlabs\Web\Controller { continue; } - abook_store_lowlevel($abook); + $r = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($abook['abook_xchan']), + intval($channel['channel_id']) + ); + if($r) { + foreach($abook as $k => $v) { + $r = q("UPDATE abook SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE abook_xchan = '%s' AND abook_channel = %d", + dbesc($k), + dbesc($v), + dbesc($abook['abook_xchan']), + intval($channel['channel_id']) + ); + } + } + else { + abook_store_lowlevel($abook); - $friends ++; - if(intval($abook['abook_feed'])) - $feeds ++; + $friends ++; + if(intval($abook['abook_feed'])) + $feeds ++; + } translate_abook_perms_inbound($channel,$abook_copy); -- cgit v1.2.3 From db930b794dc228f24549d7ef8052be8110990e1f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 1 May 2018 16:54:54 -0700 Subject: provide warnings about profile photo and cover photo permissions --- Zotlabs/Module/Cover_photo.php | 1 + Zotlabs/Module/Profile_photo.php | 1 + view/tpl/cover_photo.tpl | 3 +++ view/tpl/profile_photo.tpl | 4 +++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Cover_photo.php b/Zotlabs/Module/Cover_photo.php index d76c1b408..76e80156c 100644 --- a/Zotlabs/Module/Cover_photo.php +++ b/Zotlabs/Module/Cover_photo.php @@ -355,6 +355,7 @@ class Cover_photo extends \Zotlabs\Web\Controller { $o .= replace_macros($tpl,array( '$user' => \App::$channel['channel_address'], + '$info' => t('Your cover photo may be visible to anybody on the internet'), '$existing' => get_cover_photo(local_channel(),'array',PHOTO_RES_COVER_850), '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php index 2ce8686b9..751c4338f 100644 --- a/Zotlabs/Module/Profile_photo.php +++ b/Zotlabs/Module/Profile_photo.php @@ -451,6 +451,7 @@ class Profile_photo extends \Zotlabs\Web\Controller { $o .= replace_macros($tpl,array( '$user' => \App::$channel['channel_address'], + '$info' => ((count($profiles) > 1) ? t('Your default profile photo is visible to anybody on the internet. Profile photos for alternate profiles will inherit the permissions of the profile') : t('Your profile photo is visible to anybody on the internet and may be distributed to other websites.')), '$importfile' => (($importing) ? \App::$data['importfile'] : ''), '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), diff --git a/view/tpl/cover_photo.tpl b/view/tpl/cover_photo.tpl index 92efcdf02..5a5bf2286 100755 --- a/view/tpl/cover_photo.tpl +++ b/view/tpl/cover_photo.tpl @@ -86,6 +86,9 @@

{{$title}}

+ {{if $info}} +
{{$info}}
+ {{/if}} {{if $existing}} {{t('Cover Photo')}} {{/if}} diff --git a/view/tpl/profile_photo.tpl b/view/tpl/profile_photo.tpl index e48d05330..819502df5 100755 --- a/view/tpl/profile_photo.tpl +++ b/view/tpl/profile_photo.tpl @@ -94,7 +94,9 @@
- + {{if $info}} +
{{$info}}
+ {{/if}} {{if $importfile}} {{else}} -- cgit v1.2.3 From cd200ee7064159e4bc253fefe04ddf6ba25d4dde Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 1 May 2018 19:38:32 -0700 Subject: The channel import page seems to have missed the big theme cleanup of the last couple of years. --- Zotlabs/Module/Import.php | 19 ++++++++------ include/dba/dba_driver.php | 25 +++++++++++++++++++ view/css/mod_import.css | 37 ---------------------------- view/tpl/channel_import.tpl | 60 ++++++++++++++++++++------------------------- 4 files changed, 62 insertions(+), 79 deletions(-) delete mode 100644 view/css/mod_import.css diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 58f0c60d5..c36e4723a 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -532,16 +532,19 @@ class Import extends \Zotlabs\Web\Controller { '$desc' => t('Use this form to import an existing channel from a different server/hub. You may retrieve the channel identity from the old server/hub via the network or provide an export file.'), '$label_filename' => t('File to Upload'), '$choice' => t('Or provide the old server/hub details'), - '$label_old_address' => t('Your old identity address (xyz@example.com)'), - '$label_old_email' => t('Your old login email address'), - '$label_old_pass' => t('Your old login password'), + + '$old_address' => [ 'old_address', t('Your old identity address (xyz@example.com)'), '', ''], + '$email' => [ 'email', t('Your old login email address'), '', '' ], + '$password' => [ 'password', t('Your old login password'), '', '' ], + '$import_posts' => [ 'import_posts', t('Import a few months of posts if possible (limited by available memory'), false, '', [ t('No'), t('Yes') ]], + '$common' => t('For either option, please choose whether to make this hub your new primary address, or whether your old location should continue this role. You will be able to post from either location, but only one can be marked as the primary location for files, photos, and media.'), - '$label_import_primary' => t('Make this hub my primary location'), - '$label_import_moving' => t('Move this channel (disable all previous locations)'), - '$label_import_posts' => t('Import a few months of posts if possible (limited by available memory'), + + '$make_primary' => [ 'make_primary', t('Make this hub my primary location'), false, '', [ t('No'), t('Yes') ] ], + '$moving' => [ 'moving', t('Move this channel (disable all previous locations)'), false, '', [ t('No'), t('Yes') ] ], + '$pleasewait' => t('This process may take several minutes to complete. Please submit the form only once and leave this page open until finished.'), - '$email' => '', - '$pass' => '', + '$form_security_token' => get_form_security_token('channel_import'), '$submit' => t('Submit') )); diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index b3298b673..9e9f24bb3 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -460,3 +460,28 @@ function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) { \DBA::$logging = false; \DBA::$dba->debug = $saved; } + + +function db_columns($table) { + + if($table) { + if(ACTIVE_DBTYPE === DBTYPE_POSTGRES) { + $r = q("SELECT column_name as field FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '%s'", + dbesc($table) + ); + if($r) { + return ids_to_array($r,'field'); + } + } + else { + $r = q("show columns in %s", + dbesc($table) + ); + if($r) { + return ids_to_array($r,'Field'); + } + } + } + + return []; +} \ No newline at end of file diff --git a/view/css/mod_import.css b/view/css/mod_import.css deleted file mode 100644 index 8b988b324..000000000 --- a/view/css/mod_import.css +++ /dev/null @@ -1,37 +0,0 @@ -h2 { - margin-left: 15%; - margin-top: 8%; -} - -#import-channel-form { - font-size: 1.4em; - margin-left: 15%; - margin-top: 5%; - width: 50%; -} - - - -#import-channel-form .descriptive-paragraph { - color: #888; - margin-left: 20px; - margin-bottom: 25px; -} - -.import-label { - float: left; - width: 275px; -} - -.import-input { - float: left; - width: 275px; - padding: 5px; -} - - -.import-field-end { - clear: both; - margin-bottom: 20px; -} - diff --git a/view/tpl/channel_import.tpl b/view/tpl/channel_import.tpl index baffe9b06..d702a2437 100755 --- a/view/tpl/channel_import.tpl +++ b/view/tpl/channel_import.tpl @@ -1,43 +1,35 @@ -

{{$title}}

+
+
+

{{$title}}

+
+
+
-
- -
{{$desc}}
+ + + - - -
+ + +
-
{{$choice}}
+ - - -
+ {{include file="field_input.tpl" field=$old_address}} + {{include file="field_input.tpl" field=$email}} + {{include file="field_password.tpl" field=$password}} + {{include file="field_checkbox.tpl" field=$import_posts}} - - -
+ - - -
+ {{include file="field_checkbox.tpl" field=$make_primary}} + {{include file="field_checkbox.tpl" field=$moving}} - - -
+ -
{{$common}}
+ +
- - -
- - - -
- - -
- -
{{$pleasewait}}
-
+ +
+
-- cgit v1.2.3 From 7a55ead97db94284146612364b8ce1c59de8771f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 1 May 2018 20:29:07 -0700 Subject: new feature (post 3.4): allow a different username to be used when importing. --- Zotlabs/Module/Import.php | 18 +++++++++++++++++- include/import.php | 7 ++++++- view/tpl/channel_import.tpl | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index c36e4723a..d031bf16b 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -6,6 +6,7 @@ require_once('include/zot.php'); require_once('include/channel.php'); require_once('include/import.php'); require_once('include/perm_upgrade.php'); +require_once('library/urlify/URLify.php'); /** @@ -38,6 +39,7 @@ class Import extends \Zotlabs\Web\Controller { $filename = basename($_FILES['filename']['name']); $filesize = intval($_FILES['filename']['size']); $filetype = $_FILES['filename']['type']; + $newname = trim(strtolower($_REQUEST['newname'])); // import channel from file if($src) { @@ -146,7 +148,20 @@ class Import extends \Zotlabs\Web\Controller { } } - $channel = import_channel($data['channel'], $account_id, $seize); + if($newname) { + $x = false; + + if(get_config('system','unicode_usernames')) { + $x = punify(mb_strtolower($newname)); + } + + if((! $x) || strlen($x) > 64) { + $x = strtolower(\URLify::transliterate($newname)); + } + $newname = $x; + } + + $channel = import_channel($data['channel'], $account_id, $seize, $newname); } else { $moving = false; @@ -542,6 +557,7 @@ class Import extends \Zotlabs\Web\Controller { '$make_primary' => [ 'make_primary', t('Make this hub my primary location'), false, '', [ t('No'), t('Yes') ] ], '$moving' => [ 'moving', t('Move this channel (disable all previous locations)'), false, '', [ t('No'), t('Yes') ] ], + '$newname' => [ 'newname', t('Use this channel nickname instead of the one provided'), '', t('Leave blank to keep your existing channel nickname. You will be randomly assigned a similar nickname if either name is already allocated on this site.')], '$pleasewait' => t('This process may take several minutes to complete. Please submit the form only once and leave this page open until finished.'), diff --git a/include/import.php b/include/import.php index 0d3fb8c32..ae6a0ab6a 100644 --- a/include/import.php +++ b/include/import.php @@ -14,7 +14,7 @@ require_once('include/perm_upgrade.php'); * @param int $seize * @return boolean|array */ -function import_channel($channel, $account_id, $seize) { +function import_channel($channel, $account_id, $seize, $newname = '') { if(! array_key_exists('channel_system',$channel)) { $channel['channel_system'] = (($channel['channel_pageflags'] & 0x1000) ? 1 : 0); @@ -30,6 +30,11 @@ function import_channel($channel, $account_id, $seize) { $channel['channel_hash'] = make_xchan_hash($channel['channel_guid'],$channel['channel_guid_sig']); + if($newname) { + $channel['channel_address'] = $newname; + } + + // Check for duplicate channels $r = q("select * from channel where (channel_guid = '%s' or channel_hash = '%s' or channel_address = '%s' ) limit 1", diff --git a/view/tpl/channel_import.tpl b/view/tpl/channel_import.tpl index d702a2437..c7cbb1742 100755 --- a/view/tpl/channel_import.tpl +++ b/view/tpl/channel_import.tpl @@ -24,6 +24,7 @@ {{include file="field_checkbox.tpl" field=$make_primary}} {{include file="field_checkbox.tpl" field=$moving}} + {{include file="field_input.tpl" field=$newname}} -- cgit v1.2.3