Merge branch 'dev' into 'dev'
zot api changes to support combined content (items+files) import addon See merge request hubzilla/core!1533
This commit is contained in:
commit
04b9216758
@ -6,6 +6,8 @@
|
|||||||
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);
|
||||||
api_register_func('api/z/1.0/channel/export/basic','api_export_basic', true);
|
api_register_func('api/z/1.0/channel/export/basic','api_export_basic', true);
|
||||||
|
api_register_func('api/red/item/export/page','api_item_export_page', true);
|
||||||
|
api_register_func('api/z/1.0/item/export/page','api_item_export_page', true);
|
||||||
api_register_func('api/red/channel/list','api_channel_list', true);
|
api_register_func('api/red/channel/list','api_channel_list', true);
|
||||||
api_register_func('api/z/1.0/channel/list','api_channel_list', true);
|
api_register_func('api/z/1.0/channel/list','api_channel_list', true);
|
||||||
api_register_func('api/red/channel/stream','api_channel_stream', true);
|
api_register_func('api/red/channel/stream','api_channel_stream', true);
|
||||||
@ -80,6 +82,26 @@
|
|||||||
json_return_and_die(identity_basic_export(api_user(),$sections));
|
json_return_and_die(identity_basic_export(api_user(),$sections));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function api_item_export_page($type) {
|
||||||
|
if(api_user() === false) {
|
||||||
|
logger('api_item_export_page: no user');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$page = intval($_REQUEST['page']);
|
||||||
|
$records = intval($_REQUEST['records']);
|
||||||
|
if(! $records) {
|
||||||
|
$records = 50;
|
||||||
|
}
|
||||||
|
if(! $_REQUEST['since'])
|
||||||
|
$start = NULL_DATE;
|
||||||
|
else {
|
||||||
|
$start = datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['since']);
|
||||||
|
}
|
||||||
|
$finish = datetime_convert(date_default_timezone_get(),'UTC', (($_REQUEST['until']) ? $_REQUEST['until'] : 'now'));
|
||||||
|
|
||||||
|
json_return_and_die(channel_export_items_page(api_user(),$start,$finish,$page,$records));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function api_network_stream($type) {
|
function api_network_stream($type) {
|
||||||
if(api_user() === false) {
|
if(api_user() === false) {
|
||||||
|
@ -1080,6 +1080,7 @@ function identity_basic_export($channel_id, $sections = null) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Export items for a year, or a month of a year.
|
* @brief Export items for a year, or a month of a year.
|
||||||
*
|
*
|
||||||
@ -1102,34 +1103,14 @@ function identity_export_year($channel_id, $year, $month = 0) {
|
|||||||
else
|
else
|
||||||
$target_month = '01';
|
$target_month = '01';
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
$ch = channelx_by_n($channel_id);
|
|
||||||
if($ch) {
|
|
||||||
$ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()];
|
|
||||||
}
|
|
||||||
$mindate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00');
|
$mindate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00');
|
||||||
if($month && $month < 12)
|
if($month && $month < 12)
|
||||||
$maxdate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00');
|
$maxdate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00');
|
||||||
else
|
else
|
||||||
$maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00');
|
$maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00');
|
||||||
|
|
||||||
$r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' and resource_type = '' order by created",
|
return channel_export_items_date($channel_id,$mindate,$maxdate);
|
||||||
intval(ITEM_TYPE_POST),
|
|
||||||
intval($channel_id),
|
|
||||||
dbesc($mindate),
|
|
||||||
dbesc($maxdate)
|
|
||||||
);
|
|
||||||
|
|
||||||
if($r) {
|
|
||||||
$ret['item'] = array();
|
|
||||||
xchan_query($r);
|
|
||||||
$r = fetch_post_tags($r, true);
|
|
||||||
foreach($r as $rr)
|
|
||||||
$ret['item'][] = encode_item($rr, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1142,7 +1123,8 @@ function identity_export_year($channel_id, $year, $month = 0) {
|
|||||||
* @param string $finish
|
* @param string $finish
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function channel_export_items($channel_id, $start, $finish) {
|
|
||||||
|
function channel_export_items_date($channel_id, $start, $finish) {
|
||||||
|
|
||||||
if(! $start)
|
if(! $start)
|
||||||
return array();
|
return array();
|
||||||
@ -1179,6 +1161,71 @@ function channel_export_items($channel_id, $start, $finish) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Export items with pagination
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param int $channel_id The channel ID
|
||||||
|
* @param int $page
|
||||||
|
* @param int $limit (default 50)
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
|
||||||
|
function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50) {
|
||||||
|
|
||||||
|
if(intval($page) < 1) {
|
||||||
|
$page = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(intval($limit) < 1) {
|
||||||
|
$limit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(intval($limit) > 5000) {
|
||||||
|
$limit = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $start)
|
||||||
|
$start = NULL_DATE;
|
||||||
|
else
|
||||||
|
$start = datetime_convert('UTC', 'UTC', $start);
|
||||||
|
|
||||||
|
$finish = datetime_convert('UTC', 'UTC', (($finish) ? $finish : 'now'));
|
||||||
|
if($finish < $start)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
$offset = intval($limit) * intval($page);
|
||||||
|
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
$ch = channelx_by_n($channel_id);
|
||||||
|
if($ch) {
|
||||||
|
$ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()];
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type = '' and created >= '%s' and created <= '%s' order by created limit %d offset %d",
|
||||||
|
intval(ITEM_TYPE_POST),
|
||||||
|
intval($channel_id),
|
||||||
|
dbesc($start),
|
||||||
|
dbesc($finish),
|
||||||
|
intval($limit),
|
||||||
|
intval($offset)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
$ret['item'] = array();
|
||||||
|
xchan_query($r);
|
||||||
|
$r = fetch_post_tags($r, true);
|
||||||
|
foreach($r as $rr)
|
||||||
|
$ret['item'][] = encode_item($rr, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads a profile into the App structure.
|
* @brief Loads a profile into the App structure.
|
||||||
*
|
*
|
||||||
|
@ -3246,7 +3246,7 @@ function flatten_array_recursive($arr) {
|
|||||||
$ret = array_merge($ret, $tmp);
|
$ret = array_merge($ret, $tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif($a) {
|
elseif(isset($a)) {
|
||||||
$ret[] = $a;
|
$ret[] = $a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user