diff options
-rw-r--r-- | include/identity.php | 37 | ||||
-rwxr-xr-x | include/items.php | 1 | ||||
-rw-r--r-- | mod/uexport.php | 14 |
3 files changed, 47 insertions, 5 deletions
diff --git a/include/identity.php b/include/identity.php index 8ba5d64db..5ca626c72 100644 --- a/include/identity.php +++ b/include/identity.php @@ -583,8 +583,14 @@ function identity_basic_export($channel_id, $items = false) { /** @warning this may run into memory limits on smaller systems */ - $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d", - intval($channel_id) + /** export one year of posts. If you want to export and import all posts you have to start with + * the first year and export/import them in ascending order. + */ + + $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created > %s - INTERVAL %s", + intval($channel_id), + db_utcnow(), + db_quoteinterval('1 YEAR') ); if($r) { $ret['item'] = array(); @@ -598,6 +604,33 @@ function identity_basic_export($channel_id, $items = false) { } +function identity_export_year($channel_id,$year) { + + if(! $year) + return array(); + + $ret = array(); + $mindate = datetime_convert('UTC','UTC',$year . '-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 and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' ", + 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; +} + + + /** * @brief Loads a profile into the App structure. * diff --git a/include/items.php b/include/items.php index c067d3c1e..b1a0dacdf 100755 --- a/include/items.php +++ b/include/items.php @@ -4389,7 +4389,6 @@ function first_post_date($uid,$wall = false) { $r = q("select id, created from item where uid = %d and id = parent $item_normal $wall_sql order by created asc limit 1", - intval(ITEM_VISIBLE), intval($uid) ); diff --git a/mod/uexport.php b/mod/uexport.php index edcb2fa84..8217a17c4 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -9,9 +9,17 @@ function uexport_init(&$a) { require_once('include/identity.php'); + if(argc() > 1 && intval(argv(1)) > 1900) { + $year = intval(argv(1)); + } + header('content-type: application/octet_stream'); - header('content-disposition: attachment; filename="' . $channel['channel_address'] . '.json"' ); + header('content-disposition: attachment; filename="' . $channel['channel_address'] . (($year) ? '-' . $year : '') . '.json"' ); + if($year) { + echo json_encode(identity_export_year(local_channel(),$year)); + killme(); + } if(argc() > 1 && argv(1) === 'basic') { echo json_encode(identity_basic_export(local_channel())); @@ -34,7 +42,9 @@ function uexport_content(&$a) { '$basictitle' => t('Export Channel'), '$basic' => t('Export your basic channel information to a small file. This acts as a backup of your connections, permissions, profile and basic data, which can be used to import your data to a new hub, but does not contain your content.'), '$fulltitle' => t('Export Content'), - '$full' => t('Export your channel information and all the content to a JSON backup. This backs up all of your connections, permissions, profile data and all of your content, but is generally not suitable for importing a channel to a new hub as this file may be VERY large. Please be patient - it may take several minutes for this download to begin.') + '$full' => t('Export your channel information and all the content to a JSON backup. This backs up all of your connections, permissions, profile data and the last year of posts. This file may be VERY large. Please be patient - it may take several minutes for this download to begin.'), + '$by_year' => t('Export your posts from a given year.'), + )); return $o; } |