4 function uexport_init(&$a){
10 'label' => t('Account settings'),
11 'url' => $a->get_baseurl(true).'/settings',
15 'label' => t('Display settings'),
16 'url' => $a->get_baseurl(true).'/settings/display',
21 'label' => t('Connector settings'),
22 'url' => $a->get_baseurl(true).'/settings/connectors',
26 'label' => t('Plugin settings'),
27 'url' => $a->get_baseurl(true).'/settings/addon',
31 'label' => t('Connected apps'),
32 'url' => $a->get_baseurl(true) . '/settings/oauth',
36 'label' => t('Export personal data'),
37 'url' => $a->get_baseurl(true) . '/uexport',
38 'selected' => 'active'
41 'label' => t('Remove account'),
42 'url' => $a->get_baseurl(true) . '/removeme',
47 $tabtpl = get_markup_template("generic_links_widget.tpl");
48 $a->page['aside'] = replace_macros($tabtpl, array(
49 '$title' => t('Settings'),
50 '$class' => 'settings-widget',
55 function uexport_content(&$a){
58 header("Content-type: application/json");
59 header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
61 case "backup": uexport_all($a); killme(); break;
62 case "account": uexport_account($a); killme(); break;
69 * options shown on "Export personal data" page
70 * list of array( 'link url', 'link text', 'help text' )
73 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.')),
74 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)')),
76 call_hooks('uexport_options', $options);
78 $tpl = get_markup_template("uexport.tpl");
79 return replace_macros($tpl, array(
80 '$baseurl' => $a->get_baseurl(),
81 '$title' => t('Export personal data'),
82 '$options' => $options
88 function _uexport_multirow($query) {
94 foreach($rr as $k => $v)
102 function _uexport_row($query) {
107 foreach($rr as $k => $v)
115 function uexport_account($a){
117 $user = _uexport_row(
118 sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
121 $contact = _uexport_multirow(
122 sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
126 $profile =_uexport_multirow(
127 sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
130 $photo = _uexport_multirow(
131 sprintf( "SELECT * FROM photo WHERE uid = %d AND profile = 1", intval(local_user()) )
133 foreach ($photo as &$p) $p['data'] = bin2hex($p['data']);
135 $pconfig = _uexport_multirow(
136 sprintf( "SELECT * FROM pconfig WHERE uid = %d",intval(local_user()) )
139 $group = _uexport_multirow(
140 sprintf( "SELECT * FROM group WHERE uid = %d",intval(local_user()) )
143 $group_member = _uexport_multirow(
144 sprintf( "SELECT * FROM group_member WHERE uid = %d",intval(local_user()) )
148 'version' => FRIENDICA_VERSION,
149 'schema' => DB_UPDATE_VERSION,
150 'baseurl' => $a->get_baseurl(),
152 'contact' => $contact,
153 'profile' => $profile,
155 'pconfig' => $pconfig,
157 'group_member' => $group_member,
160 //echo "<pre>"; var_dump(json_encode($output)); killme();
161 echo json_encode($output);
166 * echoes account data and items as separated json, one per line
168 function uexport_all(&$a) {
172 $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
176 $total = $r[0]['total'];
178 // chunk the output to avoid exhausting memory
180 for($x = 0; $x < $total; $x += 500) {
182 $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
183 intval(local_user()),
189 foreach($rr as $k => $v)
193 $output = array('item' => $item);
194 echo json_encode($output);