optionally include wall items (posts) in import/export
This commit is contained in:
parent
e75f1ccb2e
commit
d8c03526ed
@ -546,8 +546,8 @@ require_once('include/items.php');
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once('include/identity.php');
|
require_once('include/identity.php');
|
||||||
|
|
||||||
json_return_and_die(identity_basic_export(api_user()));
|
json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
|
||||||
}
|
}
|
||||||
api_register_func('api/export/basic','api_export_basic', true);
|
api_register_func('api/export/basic','api_export_basic', true);
|
||||||
api_register_func('api/red/channel/export/basic','api_export_basic', true);
|
api_register_func('api/red/channel/export/basic','api_export_basic', true);
|
||||||
|
@ -431,14 +431,15 @@ function set_default_login_identity($account_id,$channel_id,$force = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function identity_basic_export($channel_id)
|
* @function identity_basic_export($channel_id,$items = false)
|
||||||
* Create an array representing the important channel information
|
* Create an array representing the important channel information
|
||||||
* which would be necessary to create a nomadic identity clone. This includes
|
* which would be necessary to create a nomadic identity clone. This includes
|
||||||
* most channel resources and connection information with the exception of content.
|
* most channel resources and connection information with the exception of content.
|
||||||
*
|
*
|
||||||
* @param int $channel_id
|
* @param int $channel_id
|
||||||
* Channel_id to export
|
* Channel_id to export
|
||||||
*
|
* @param boolean $items
|
||||||
|
* Include channel posts (wall items), default false
|
||||||
*
|
*
|
||||||
* @returns array
|
* @returns array
|
||||||
* See function for details
|
* See function for details
|
||||||
@ -521,7 +522,7 @@ function identity_basic_export($channel_id, $items = false) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
|
|
||||||
$r = q("select * from item_id where uid = %d",
|
$r = q("select item_id.*, item.mid from item_id left join item on item_id.iid = item.id where item_id.uid = %d",
|
||||||
intval($channel_id)
|
intval($channel_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -865,15 +865,37 @@ function get_item_elements($x) {
|
|||||||
// We have to do that here because we need to cleanse the input and prevent bad stuff from getting in,
|
// We have to do that here because we need to cleanse the input and prevent bad stuff from getting in,
|
||||||
// and we need plaintext to do that.
|
// and we need plaintext to do that.
|
||||||
|
|
||||||
|
$key = get_config('system','pubkey');
|
||||||
|
|
||||||
|
|
||||||
if(intval($arr['item_private'])) {
|
if(intval($arr['item_private'])) {
|
||||||
$arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED;
|
$arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED;
|
||||||
$key = get_config('system','pubkey');
|
|
||||||
if($arr['title'])
|
if($arr['title'])
|
||||||
$arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key));
|
$arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key));
|
||||||
if($arr['body'])
|
if($arr['body'])
|
||||||
$arr['body'] = json_encode(crypto_encapsulate($arr['body'],$key));
|
$arr['body'] = json_encode(crypto_encapsulate($arr['body'],$key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(array_key_exists('revision',$x)) {
|
||||||
|
// extended export encoding
|
||||||
|
|
||||||
|
$arr['revision'] = $x['revision'];
|
||||||
|
$arr['allow_cid'] = $x['allow_cid'];
|
||||||
|
$arr['allow_gid'] = $x['allow_gid'];
|
||||||
|
$arr['deny_cid'] = $x['deny_cid'];
|
||||||
|
$arr['deny_gid'] = $x['deny_gid'];
|
||||||
|
$arr['layout_mid'] = $x['layout_mid'];
|
||||||
|
$arr['postopts'] = $x['postopts'];
|
||||||
|
$arr['resource_id'] = $x['resource_id'];
|
||||||
|
$arr['resource_type'] = $x['resource_type'];
|
||||||
|
$arr['item_restrict'] = $x['item_restrict'];
|
||||||
|
$arr['item_flags'] = $x['item_flags'];
|
||||||
|
$arr['diaspora_meta'] = (($x['diaspora_meta']) ? json_encode(crypto_encapsulate($x['diaspora_meta'],$key)) : '');
|
||||||
|
$arr['attach'] = $x['attach'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ function import_post(&$a) {
|
|||||||
|
|
||||||
$data = null;
|
$data = null;
|
||||||
$seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);
|
$seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);
|
||||||
|
$import_posts = ((x($_REQUEST,'import_posts')) ? intval($_REQUEST['import_posts']) : 0);
|
||||||
$src = $_FILES['filename']['tmp_name'];
|
$src = $_FILES['filename']['tmp_name'];
|
||||||
$filename = basename($_FILES['filename']['name']);
|
$filename = basename($_FILES['filename']['name']);
|
||||||
$filesize = intval($_FILES['filename']['size']);
|
$filesize = intval($_FILES['filename']['size']);
|
||||||
@ -60,6 +60,8 @@ function import_post(&$a) {
|
|||||||
|
|
||||||
$scheme = 'https://';
|
$scheme = 'https://';
|
||||||
$api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname;
|
$api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname;
|
||||||
|
if($import_posts)
|
||||||
|
$api_path .= '&posts=1';
|
||||||
$binary = false;
|
$binary = false;
|
||||||
$redirects = 0;
|
$redirects = 0;
|
||||||
$opts = array('http_auth' => $email . ':' . $password);
|
$opts = array('http_auth' => $email . ':' . $password);
|
||||||
@ -376,7 +378,57 @@ function import_post(&$a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME just a note here for when folks want to import content - be very careful to unset ITEM_ORIGIN on all imported content. Or you could end up with a nasty routing loop when somebody tries to reply to one of those posts.
|
if($import_posts && array_key_exists('item',$data) && $data['item']) {
|
||||||
|
foreach($data['item'] as $i) {
|
||||||
|
$item = get_item_elements($i);
|
||||||
|
|
||||||
|
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
|
||||||
|
dbesc($item['mid']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
if($item['edited'] > $r[0]['edited']) {
|
||||||
|
$item['id'] = $r[0]['id'];
|
||||||
|
$item['uid'] = $channel['channel_id'];
|
||||||
|
item_store_update($item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$item['aid'] = $channel['channel_account_id'];
|
||||||
|
$item['uid'] = $channel['channel_id'];
|
||||||
|
$item_result = item_store($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(array_key_exists('item_id',$data) && $data['item_id']) {
|
||||||
|
foreach($data['item_id'] as $i) {
|
||||||
|
$r = q("select id from item where mid = '%s' and uid = %d limit 1",
|
||||||
|
dbesc($i['mid']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if(! $r)
|
||||||
|
continue;
|
||||||
|
$z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1",
|
||||||
|
dbesc($i['service']),
|
||||||
|
dbesc($i['sid']),
|
||||||
|
intval($r[0]['id']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if(! $z) {
|
||||||
|
q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')",
|
||||||
|
intval($r[0]['id']),
|
||||||
|
intval($channel['channel_id']),
|
||||||
|
dbesc($i['sid']),
|
||||||
|
dbesc($i['service'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
|
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
|
||||||
@ -417,6 +469,7 @@ function import_content(&$a) {
|
|||||||
'$label_old_pass' => t('Your old login password'),
|
'$label_old_pass' => t('Your old login password'),
|
||||||
'$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.'),
|
'$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_primary' => t('Make this hub my primary location'),
|
||||||
|
'$label_import_posts' => t('Import existing posts if possible'),
|
||||||
'$email' => '',
|
'$email' => '',
|
||||||
'$pass' => '',
|
'$pass' => '',
|
||||||
'$submit' => t('Submit')
|
'$submit' => t('Submit')
|
||||||
|
@ -1 +1 @@
|
|||||||
2014-09-24.808
|
2014-09-25.809
|
||||||
|
@ -22,6 +22,11 @@
|
|||||||
<input type="password" name="password" id="import-old-pass" class="import-input" value="{{$pass}}" />
|
<input type="password" name="password" id="import-old-pass" class="import-input" value="{{$pass}}" />
|
||||||
<div id="import-old-pass-end" class="import-field-end"></div>
|
<div id="import-old-pass-end" class="import-field-end"></div>
|
||||||
|
|
||||||
|
<input type="checkbox" name="import_posts" id="import-posts" value="1" />
|
||||||
|
<label for="import-posts" id="label-import-posts">{{$label_import_posts}}</label>
|
||||||
|
<div id="import-posts-end" class="import-field-end"></div>
|
||||||
|
|
||||||
|
|
||||||
<div id="import-common-desc" class="descriptive-paragraph">{{$common}}</div>
|
<div id="import-common-desc" class="descriptive-paragraph">{{$common}}</div>
|
||||||
|
|
||||||
<input type="checkbox" name="make_primary" id="import-make-primary" value="1" />
|
<input type="checkbox" name="make_primary" id="import-make-primary" value="1" />
|
||||||
|
Reference in New Issue
Block a user