aboutsummaryrefslogtreecommitdiffstats
path: root/mod/import.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/import.php')
-rw-r--r--mod/import.php133
1 files changed, 122 insertions, 11 deletions
diff --git a/mod/import.php b/mod/import.php
index f35ca149b..d3b237c3a 100644
--- a/mod/import.php
+++ b/mod/import.php
@@ -4,24 +4,29 @@
// connection to original server.
require_once('include/Contact.php');
-
+require_once('include/zot.php');
+require_once('include/identity.php');
function import_post(&$a) {
+ if(! get_account_id()) {
+ return;
+ }
$data = null;
$seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);
- $src = $_FILES['userfile']['tmp_name'];
- $filename = basename($_FILES['userfile']['name']);
- $filesize = intval($_FILES['userfile']['size']);
- $filetype = $_FILES['userfile']['type'];
+ $src = $_FILES['filename']['tmp_name'];
+ $filename = basename($_FILES['filename']['name']);
+ $filesize = intval($_FILES['filename']['size']);
+ $filetype = $_FILES['filename']['type'];
if($src) {
if($filesize) {
$data = @file_get_contents($src);
}
+ unlink($src);
}
if(! $src) {
@@ -39,7 +44,7 @@ function import_post(&$a) {
$servername = substr($old_address,strpos($old_address,'@')+1);
$scheme = 'https://';
- $api_path = '/api/export/basic?f=&channel=' . $channelname;
+ $api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname;
$binary = false;
$redirects = 0;
$opts = array('http_auth' => $email . ':' . $password);
@@ -60,6 +65,7 @@ function import_post(&$a) {
return;
}
+ $data = json_decode($data,true);
// logger('import: data: ' . print_r($data,true));
@@ -113,9 +119,11 @@ function import_post(&$a) {
// reset
$channel = $r[0];
+ set_default_login_identity(get_account_id(),$channel['channel_id'],false);
+
if($data['photo']) {
- require_once('include/Photo.php');
- import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id,$channel['channel_id']);
+ require_once('include/photo/photo_driver.php');
+ import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id(),$channel['channel_id']);
}
$profiles = $data['profile'];
@@ -198,10 +206,37 @@ function import_post(&$a) {
// import xchans and contact photos
+ if($seize) {
+
+ // replace our existing xchan if we're seizing control
+
+ $r = q("delete from xchan where xchan_hash = '%s' limit 1",
+ dbesc($channel['channel_hash'])
+ );
+
+ $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
+ dbesc($channel['channel_hash']),
+ dbesc($channel['channel_guid']),
+ dbesc($channel['channel_guid_sig']),
+ dbesc($channel['channel_pubkey']),
+ dbesc($a->get_baseurl() . "/photo/profile/l/" . $channel['channel_id']),
+ dbesc($a->get_baseurl() . "/photo/profile/m/" . $channel['channel_id']),
+ dbesc($a->get_baseurl() . "/photo/profile/s/" . $channel['channel_id']),
+ dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()),
+ dbesc(z_root() . '/channel/' . $channel['channel_address']),
+ dbesc(z_root() . '/follow?f=&url=%s'),
+ dbesc(z_root() . '/poco/' . $channel['channel_address']),
+ dbesc($channel['channel_name']),
+ dbesc('zot'),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert())
+ );
+ }
$xchans = $data['xchan'];
if($xchans) {
foreach($xchans as $xchan) {
+
$r = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1",
dbesc($xchan['xchan_hash'])
);
@@ -217,14 +252,20 @@ function import_post(&$a) {
. "')" );
- require_once("Photo.php");
+ require_once('include/photo/photo_driver.php');
$photos = import_profile_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']);
- $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
+ if($photos[4])
+ $photodate = '0000-00-00 00:00:00';
+ 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' limit 1",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc($photos[3]),
+ dbesc($photodate),
dbesc($xchan_hash)
);
@@ -250,6 +291,63 @@ function import_post(&$a) {
}
}
+
+ $configs = $data['config'];
+ if($configs) {
+ foreach($configs as $config) {
+ unset($config['id']);
+ $config['uid'] = $channel['channel_id'];
+ dbesc_array($config);
+ $r = dbq("INSERT INTO pconfig (`"
+ . implode("`, `", array_keys($config))
+ . "`) VALUES ('"
+ . implode("', '", array_values($config))
+ . "')" );
+ }
+ }
+
+ $groups = $data['group'];
+ if($groups) {
+ $saved = array();
+ foreach($groups as $group) {
+ $saved[$group['hash']] = array('old' => $group['id']);
+ unset($group['id']);
+ $group['uid'] = $channel['channel_id'];
+ dbesc_array($group);
+ $r = dbq("INSERT INTO group (`"
+ . implode("`, `", array_keys($group))
+ . "`) VALUES ('"
+ . implode("', '", array_values($group))
+ . "')" );
+ }
+ $r = q("select * from `groups` where uid = %d",
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ foreach($r as $rr) {
+ $saved[$rr['hash']]['new'] = $rr['id'];
+ }
+ }
+ }
+
+ $group_members = $data['group_member'];
+ if($groups_members) {
+ foreach($group_members as $group_member) {
+ unset($group_member['id']);
+ $group_member['uid'] = $channel['channel_id'];
+ foreach($saved as $x) {
+ if($x['old'] == $group_member['gid'])
+ $group_member['gid'] = $x['new'];
+ }
+ dbesc_array($group_member);
+ $r = dbq("INSERT INTO group_member (`"
+ . implode("`, `", array_keys($group_member))
+ . "`) VALUES ('"
+ . implode("', '", array_values($group_member))
+ . "')" );
+ }
+ }
+
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
if($seize) {
@@ -257,15 +355,28 @@ function import_post(&$a) {
}
+ // This will indirectly perform a refresh_all *and* update the directory
+
+ proc_run('php', 'include/directory.php', $channel['channel_id']);
+
// send out refresh requests
notice( t('Import completed.') . EOL);
+ change_channel($channel['channel_id']);
+
+ goaway(z_root() . '/network' );
+
+
}
function import_content(&$a) {
+ if(! get_account_id()) {
+ notice( t('You must be logged in to use this feature.'));
+ return '';
+ }
$o = replace_macros(get_markup_template('channel_import.tpl'),array(
'$title' => t('Import Channel'),
@@ -284,4 +395,4 @@ function import_content(&$a) {
return $o;
-} \ No newline at end of file
+}