aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-01-31 16:01:47 -0800
committerzotlabs <mike@macgirvin.com>2017-01-31 16:01:47 -0800
commitf4aca35a889753be85cb0db5fbfb19824b882fdb (patch)
tree0fad72dbce746ec2425bdc6cb9ded8e8d43217d8
parent732065bf13af96f680bc9874afee71c07f74e40a (diff)
downloadvolse-hubzilla-f4aca35a889753be85cb0db5fbfb19824b882fdb.tar.gz
volse-hubzilla-f4aca35a889753be85cb0db5fbfb19824b882fdb.tar.bz2
volse-hubzilla-f4aca35a889753be85cb0db5fbfb19824b882fdb.zip
move diaspora account import to the diaspora plugin
-rw-r--r--Zotlabs/Module/Import.php78
-rw-r--r--include/Import/import_diaspora.php148
2 files changed, 40 insertions, 186 deletions
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 69e06d256..c44234e34 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -112,12 +112,12 @@ class Import extends \Zotlabs\Web\Controller {
// print_r($data);
- if(array_key_exists('user',$data) && array_key_exists('version',$data)) {
- require_once('include/Import/import_diaspora.php');
- import_diaspora($data);
- return;
+ if(! array_key_exists('compatibility,$data)) {
+ call_hooks('import_foreign_channel_data',$data);
+ if($data['handled'])
+ return;
}
-
+
$moving = intval($_REQUEST['moving']);
if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) {
@@ -181,14 +181,15 @@ class Import extends \Zotlabs\Web\Controller {
if($completed < 3) {
- if($data['photo']) {
- require_once('include/photo/photo_driver.php');
- import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],$account_id,$channel['channel_id']);
- }
-
- if(is_array($data['profile']))
- import_profiles($channel,$data['profile']);
+ if(array_key_exists('channel',$data)) {
+ if($data['photo']) {
+ require_once('include/photo/photo_driver.php');
+ import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],$account_id,$channel['channel_id']);
+ }
+ if(is_array($data['profile']))
+ import_profiles($channel,$data['profile']);
+ }
logger('import step 3');
$_SESSION['import_step'] = 3;
}
@@ -207,31 +208,34 @@ class Import extends \Zotlabs\Web\Controller {
if($completed < 5) {
// create new hubloc for the new channel at this site
- $r = hubloc_store_lowlevel(
- [
- 'hubloc_guid' => $channel['channel_guid'],
- 'hubloc_guid_sig' => $channel['channel_guid_sig'],
- 'hubloc_hash' => $channel['channel_hash'],
- 'hubloc_addr' => channel_reddress($channel),
- 'hubloc_network' => 'zot',
- 'hubloc_primary' => (($seize) ? 1 : 0),
- 'hubloc_url' => z_root(),
- 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
- 'hubloc_host' => \App::get_hostname(),
- 'hubloc_callback' => z_root() . '/post',
- 'hubloc_sitekey' => get_config('system','pubkey'),
- 'hubloc_updated' => datetime_convert()
- ]
- );
+ if(array_key_exists('channel',$data)) {
+ $r = hubloc_store_lowlevel(
+ [
+ 'hubloc_guid' => $channel['channel_guid'],
+ 'hubloc_guid_sig' => $channel['channel_guid_sig'],
+ 'hubloc_hash' => $channel['channel_hash'],
+ 'hubloc_addr' => channel_reddress($channel),
+ 'hubloc_network' => 'zot',
+ 'hubloc_primary' => (($seize) ? 1 : 0),
+ 'hubloc_url' => z_root(),
+ 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
+ 'hubloc_host' => \App::get_hostname(),
+ 'hubloc_callback' => z_root() . '/post',
+ 'hubloc_sitekey' => get_config('system','pubkey'),
+ 'hubloc_updated' => datetime_convert()
+ ]
+ );
- // reset the original primary hubloc if it is being seized
+ // reset the original primary hubloc if it is being seized
- if($seize) {
- $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ",
- dbesc($channel['channel_hash']),
- dbesc(z_root())
- );
+ if($seize) {
+ $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ",
+ dbesc($channel['channel_hash']),
+ dbesc(z_root())
+ );
+ }
}
+
logger('import step 5');
$_SESSION['import_step'] = 5;
}
@@ -241,7 +245,7 @@ class Import extends \Zotlabs\Web\Controller {
// import xchans and contact photos
- if($seize) {
+ if(array_key_exists('channel',$data) && $seize) {
// replace any existing xchan we may have on this site if we're seizing control
@@ -327,9 +331,7 @@ class Import extends \Zotlabs\Web\Controller {
$_SESSION['import_step'] = 7;
}
-
-
-
+
// FIXME - ensure we have an xchan if somebody is trying to pull a fast one
if($completed < 8) {
diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php
deleted file mode 100644
index c6dae0117..000000000
--- a/include/Import/import_diaspora.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-
-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) {
-
- $account = App::get_account();
- 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' => escape_tags($data['user']['name']),
- 'nickname' => $address,
- 'account_id' => $account['account_id'],
- 'permissions_role' => 'social'
- ));
-
- if(! $c['success'])
- return;
-
- $channel_id = $c['channel']['channel_id'];
-
- // Hubzilla only: Turn on the Diaspora protocol so that follow requests will be sent.
-
- set_pconfig($channel_id,'system','diaspora_allowed','1');
-
- // 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),
- intval($channel_id)
- );
-
- if($data['user']['profile']['nsfw']) {
- q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d",
- intval(PAGE_ADULT),
- intval($channel_id)
- );
- }
-
- 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 = markdown_to_bb($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';
-
- // 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)
- );
-
- if($data['user']['aspects']) {
- foreach($data['user']['aspects'] as $aspect) {
- group_add($channel_id,escape_tags($aspect['name']),intval($aspect['contacts_visible']));
- }
- }
-
- // now add connections and send friend requests
-
-
- 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']) {
- 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
-
-
-
- // 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