aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-06-20 16:21:25 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-06-20 16:21:25 -0700
commitdd950baa82ba413e234a479b71a33e895a1835ec (patch)
treeb19c2d29a15da4158a411f599f427dfa3269f751 /include
parentddbaabd62d814bb520ac800ef26d36b083e8c094 (diff)
downloadvolse-hubzilla-dd950baa82ba413e234a479b71a33e895a1835ec.tar.gz
volse-hubzilla-dd950baa82ba413e234a479b71a33e895a1835ec.tar.bz2
volse-hubzilla-dd950baa82ba413e234a479b71a33e895a1835ec.zip
import_diaspora - incorrect method for importing channel photo, and add duplicate reddress detection/correction
Diffstat (limited to 'include')
-rw-r--r--include/Import/import_diaspora.php62
1 files changed, 42 insertions, 20 deletions
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']);