3 function uexport_init(App &$a){
7 require_once("mod/settings.php");
11 function uexport_content(App &$a){
14 header("Content-type: application/json");
15 header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
17 case "backup": uexport_all($a); killme(); break;
18 case "account": uexport_account($a); killme(); break;
25 * options shown on "Export personal data" page
26 * list of array( 'link url', 'link text', 'help text' )
29 array('uexport/account',t('Export account'),t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')),
30 array('uexport/backup',t('Export all'),t('Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account (photos are not exported)')),
32 call_hooks('uexport_options', $options);
34 $tpl = get_markup_template("uexport.tpl");
35 return replace_macros($tpl, array(
36 '$baseurl' => App::get_baseurl(),
37 '$title' => t('Export personal data'),
38 '$options' => $options
44 function _uexport_multirow($query) {
47 // if (dbm::is_result($r)) {
51 foreach($rr as $k => $v)
59 function _uexport_row($query) {
64 foreach($rr as $k => $v)
72 function uexport_account($a){
75 sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
78 $contact = _uexport_multirow(
79 sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
83 $profile =_uexport_multirow(
84 sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
87 $photo = _uexport_multirow(
88 sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) )
90 foreach ($photo as &$p) $p['data'] = bin2hex($p['data']);
92 $pconfig = _uexport_multirow(
93 sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) )
96 $group = _uexport_multirow(
97 sprintf( "SELECT * FROM `group` WHERE uid = %d",intval(local_user()) )
100 $group_member = _uexport_multirow(
101 sprintf( "SELECT * FROM `group_member` WHERE uid = %d",intval(local_user()) )
105 'version' => FRIENDICA_VERSION,
106 'schema' => DB_UPDATE_VERSION,
107 'baseurl' => App::get_baseurl(),
109 'contact' => $contact,
110 'profile' => $profile,
112 'pconfig' => $pconfig,
114 'group_member' => $group_member,
117 //echo "<pre>"; var_dump(json_encode($output)); killme();
118 echo json_encode($output);
123 * echoes account data and items as separated json, one per line
125 function uexport_all(App &$a) {
130 $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
133 if (dbm::is_result($r))
134 $total = $r[0]['total'];
136 // chunk the output to avoid exhausting memory
138 for($x = 0; $x < $total; $x += 500) {
140 $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
141 intval(local_user()),
145 /*if (dbm::is_result($r)) {
147 foreach($rr as $k => $v)
151 $output = array('item' => $r);
152 echo json_encode($output)."\n";