From 6bd90816dd76d5fbd2374f72ac302537bc1ef047 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 19 Jun 2015 16:39:03 -0700 Subject: very early attempt diaspora import from diaspora export file. Currently the json export has to be gunzipped prior to uploading and we're net yet adding connections (which should come soon) and we can't import items until they add guids to the export file - so consider it a work in progress. This first attempt should create a channel and get your profile details setup providing there isn't a nickname conflict on the server. That will also be handled later. --- include/Import/import_diaspora.php | 100 +++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 include/Import/import_diaspora.php (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php new file mode 100644 index 000000000..c9c785385 --- /dev/null +++ b/include/Import/import_diaspora.php @@ -0,0 +1,100 @@ +get_account(); + if(! $account) + return false; + + + $c = create_identity(array( + 'name' => $data['user']['name'], + 'nickname' => $data['user']['username'], + 'account_id' => $account['account_id'], + 'permissions_role' => 'social' + )); + + + if(! $c['success']) + return; + + $channel_id = $c['channel']['channel_id']; + + // todo - add nsfw, auto follow, (and strip exif in hubzilla) + + $location = escape_tags($data['user']['profile']['location']); + if(! $location) + $location = ''; + + q("update channel set channel_location = '%s' where channel_id = %d", + dbesc($location) + ); + + + $photos = import_profile_photo($data['user']['profile']['image_url'],$c['channel']['channel_hash']); + if($photos[4]) + $photodate = NULL_DATE; + else + $photodate = $xchan['xchan_photo_date']; + + $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' + where xchan_hash = '%s'", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($photodate), + dbesc($c['channel']['channel_hash']) + ); + + + $gender = escape_tags($data['user']['profile']['gender']); + $about = diaspora2bb($data['user']['profile']['bio']); + if($data['user']['profile']['birthday']) + $dob = datetime_convert('UTC','UTC',$data['user']['profile']['birthday'],'Y-m-d'); + else + $dob = '0000-00-00'; + + $r = q("update profile set gender = '%s', about = '%s', dob = '%s' where uid = %d", + dbesc($gender), + dbesc($about), + dbesc($dob), + intval($channel_id) + ); + + if($data['aspects']) { + foreach($data['aspects'] as $aspect) { + group_add($channel_id,escape_tags($aspect['name']),intval($aspect['contacts_visible'])); + } + } + + // now add connections and send friend requests + + + + + + + // Then add items - note this can't be done until Diaspora adds guids to exported + // items and comments + + + + + proc_run('php','include/notifier.php','location',$channel_id); + + // This will indirectly perform a refresh_all *and* update the directory + + proc_run('php', 'include/directory.php', $channel_id); + + notice( t('Import completed.') . EOL); + + change_channel($channel_id); + + goaway(z_root() . '/network' ); + +} \ No newline at end of file -- cgit v1.2.3 From e85d2c4b907ba1ba5aee658ba37c26eaaafc6ef5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 19 Jun 2015 17:07:31 -0700 Subject: import_diaspora: add all the friends --- include/Import/import_diaspora.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index c9c785385..060a1b38d 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -2,6 +2,7 @@ require_once('include/bb2diaspora.php'); require_once('include/group.php'); +require_once('include/follow.php'); function import_diaspora($data) { $a = get_app(); @@ -75,16 +76,24 @@ function import_diaspora($data) { // now add connections and send friend requests - - + if($data['contacts']) { + foreach($data['contacts'] as $contact) { + $result = new_contact($channel_id, $contact['person_diaspora_handle'], $c['channel']); + if($result['success']) { + if($contact['aspects']) { + foreach($contact['aspects'] as $aspect) { + group_add_member($channel_id,$aspect['name'],$result['abook']['xchan_hash']); + } + } + } + } + } // Then add items - note this can't be done until Diaspora adds guids to exported // items and comments - - proc_run('php','include/notifier.php','location',$channel_id); // This will indirectly perform a refresh_all *and* update the directory -- cgit v1.2.3 From 94e7a425e6fe455238379800c2a8c30bac70ce2f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 19 Jun 2015 18:06:55 -0700 Subject: import_diaspora - a few more atypical settings --- include/Import/import_diaspora.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index 060a1b38d..f81f28273 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -25,16 +25,27 @@ function import_diaspora($data) { $channel_id = $c['channel']['channel_id']; - // todo - add nsfw, auto follow, (and strip exif in hubzilla) + // todo - add auto follow settings, (and strip exif in hubzilla) $location = escape_tags($data['user']['profile']['location']); if(! $location) $location = ''; + q("update channel set channel_location = '%s' where channel_id = %d", - dbesc($location) + dbesc($location), + intval($channel_id) ); + if($data['user']['profile']['nsfw']) { + // fixme for hubzilla which doesn't use pageflags any more + q("update channel set channel_pageflags = (channel_pageflags & %d) where channel_id = %d", + intval(PAGE_ADULT), + intval($channel_id) + ); + } + + $photos = import_profile_photo($data['user']['profile']['image_url'],$c['channel']['channel_hash']); if($photos[4]) @@ -55,15 +66,20 @@ function import_diaspora($data) { $gender = escape_tags($data['user']['profile']['gender']); $about = diaspora2bb($data['user']['profile']['bio']); + $publish = intval($data['user']['profile']['searchable']); if($data['user']['profile']['birthday']) $dob = datetime_convert('UTC','UTC',$data['user']['profile']['birthday'],'Y-m-d'); else $dob = '0000-00-00'; - $r = q("update profile set gender = '%s', about = '%s', dob = '%s' where uid = %d", + // we're relying on the fact that this channel was just created and will only + // have the default profile currently + + $r = q("update profile set gender = '%s', about = '%s', dob = '%s', publish = %d where uid = %d", dbesc($gender), dbesc($about), dbesc($dob), + dbesc($publish), intval($channel_id) ); -- cgit v1.2.3 From ddbaabd62d814bb520ac800ef26d36b083e8c094 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 19 Jun 2015 18:08:10 -0700 Subject: wrong logic --- include/Import/import_diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index f81f28273..9fcea918c 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -39,7 +39,7 @@ function import_diaspora($data) { if($data['user']['profile']['nsfw']) { // fixme for hubzilla which doesn't use pageflags any more - q("update channel set channel_pageflags = (channel_pageflags & %d) where channel_id = %d", + q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d", intval(PAGE_ADULT), intval($channel_id) ); -- cgit v1.2.3 From dd950baa82ba413e234a479b71a33e895a1835ec Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 20 Jun 2015 16:21:25 -0700 Subject: import_diaspora - incorrect method for importing channel photo, and add duplicate reddress detection/correction --- include/Import/import_diaspora.php | 62 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index 9fcea918c..dccb2d6ec 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -11,10 +11,42 @@ function import_diaspora($data) { if(! $account) return false; + $address = escape_tags($data['user']['username']); + if(! $address) { + notice( t('No username found in import file.') . EOL); + return false; + } + + $r = q("select * from channel where channel_address = '%s' limit 1", + dbesc($address) + ); + if($r) { + // try at most ten times to generate a unique address. + $x = 0; + $found_unique = false; + do { + $tmp = $address . mt_rand(1000,9999); + $r = q("select * from channel where channel_address = '%s' limit 1", + dbesc($tmp) + ); + if(! $r) { + $address = $tmp; + $found_unique = true; + break; + } + $x ++; + } while ($x < 10); + if(! $found_unique) { + logger('import_diaspora: duplicate channel address. randomisation failed.'); + notice( t('Unable to create a unique channel address. Import failed.') . EOL); + return; + } + } + $c = create_identity(array( - 'name' => $data['user']['name'], - 'nickname' => $data['user']['username'], + 'name' => escape_tags($data['user']['name']), + 'nickname' => $address, 'account_id' => $account['account_id'], 'permissions_role' => 'social' )); @@ -45,24 +77,14 @@ function import_diaspora($data) { ); } - - - $photos = import_profile_photo($data['user']['profile']['image_url'],$c['channel']['channel_hash']); - if($photos[4]) - $photodate = NULL_DATE; - else - $photodate = $xchan['xchan_photo_date']; - - $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' - where xchan_hash = '%s'", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc($photos[3]), - dbesc($photodate), - dbesc($c['channel']['channel_hash']) - ); - + if($data['user']['profile']['image_url']) { + $p = z_fetch_url($data['user']['profile']['image_url'],true); + if($p['success']) { + $rawbytes = $p['body']; + $type = guess_image_type('dummyfile',$p['header']); + import_channel_photo($rawbytes,$type,$c['channel']['channel_account_id'],$channel_id); + } + } $gender = escape_tags($data['user']['profile']['gender']); $about = diaspora2bb($data['user']['profile']['bio']); -- cgit v1.2.3 From 9dfb8a3401fcca98ca647d913faa55f8c56fd350 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 20 Jun 2015 16:24:10 -0700 Subject: ensure the photo driver is included --- include/Import/import_diaspora.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index dccb2d6ec..f755c39e2 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -3,6 +3,7 @@ require_once('include/bb2diaspora.php'); require_once('include/group.php'); require_once('include/follow.php'); +require_once('include/photo/photo_driver.php'); function import_diaspora($data) { $a = get_app(); -- cgit v1.2.3 From 68534fd5dc6fdc879b075c32849d6cbc8a5fc905 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 21 Jun 2015 17:30:23 -0700 Subject: some diaspora import issues uncovered during dry-run tests --- include/Import/import_diaspora.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'include/Import') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index f755c39e2..fca9fa4f2 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -51,7 +51,6 @@ function import_diaspora($data) { 'account_id' => $account['account_id'], 'permissions_role' => 'social' )); - if(! $c['success']) return; @@ -106,8 +105,8 @@ function import_diaspora($data) { intval($channel_id) ); - if($data['aspects']) { - foreach($data['aspects'] as $aspect) { + if($data['user']['aspects']) { + foreach($data['user']['aspects'] as $aspect) { group_add($channel_id,escape_tags($aspect['name']),intval($aspect['contacts_visible'])); } } @@ -115,8 +114,8 @@ function import_diaspora($data) { // now add connections and send friend requests - if($data['contacts']) { - foreach($data['contacts'] as $contact) { + if($data['user']['contacts']) { + foreach($data['user']['contacts'] as $contact) { $result = new_contact($channel_id, $contact['person_diaspora_handle'], $c['channel']); if($result['success']) { if($contact['aspects']) { @@ -133,7 +132,6 @@ function import_diaspora($data) { // items and comments - proc_run('php','include/notifier.php','location',$channel_id); // This will indirectly perform a refresh_all *and* update the directory -- cgit v1.2.3