3 function uexport_init(&$a){
7 require_once("mod/settings.php");
13 'label' => t('Account settings'),
14 'url' => $a->get_baseurl(true).'/settings',
18 'label' => t('Display settings'),
19 'url' => $a->get_baseurl(true).'/settings/display',
24 'label' => t('Connector settings'),
25 'url' => $a->get_baseurl(true).'/settings/connectors',
29 'label' => t('Plugin settings'),
30 'url' => $a->get_baseurl(true).'/settings/addon',
34 'label' => t('Connected apps'),
35 'url' => $a->get_baseurl(true) . '/settings/oauth',
39 'label' => t('Export personal data'),
40 'url' => $a->get_baseurl(true) . '/uexport',
41 'selected' => 'active'
44 'label' => t('Remove account'),
45 'url' => $a->get_baseurl(true) . '/removeme',
50 $tabtpl = get_markup_template("generic_links_widget.tpl");
51 $a->page['aside'] = replace_macros($tabtpl, array(
52 '$title' => t('Settings'),
53 '$class' => 'settings-widget',
59 function uexport_content(&$a){
62 header("Content-type: application/json");
63 header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
65 case "backup": uexport_all($a); killme(); break;
66 case "account": uexport_account($a); killme(); break;
73 * options shown on "Export personal data" page
74 * list of array( 'link url', 'link text', 'help text' )
77 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.')),
78 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)')),
80 call_hooks('uexport_options', $options);
82 $tpl = get_markup_template("uexport.tpl");
83 return replace_macros($tpl, array(
84 '$baseurl' => $a->get_baseurl(),
85 '$title' => t('Export personal data'),
86 '$options' => $options
92 function _uexport_multirow($query) {
99 foreach($rr as $k => $v)
107 function _uexport_row($query) {
112 foreach($rr as $k => $v)
120 function uexport_account($a){
122 $user = _uexport_row(
123 sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
126 $contact = _uexport_multirow(
127 sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
131 $profile =_uexport_multirow(
132 sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
135 $photo = _uexport_multirow(
136 sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) )
138 foreach ($photo as &$p) $p['data'] = bin2hex($p['data']);
140 $pconfig = _uexport_multirow(
141 sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) )
144 $group = _uexport_multirow(
145 sprintf( "SELECT * FROM `group` WHERE uid = %d",intval(local_user()) )
148 $group_member = _uexport_multirow(
149 sprintf( "SELECT * FROM `group_member` WHERE uid = %d",intval(local_user()) )
153 'version' => FRIENDICA_VERSION,
154 'schema' => DB_UPDATE_VERSION,
155 'baseurl' => $a->get_baseurl(),
157 'contact' => $contact,
158 'profile' => $profile,
160 'pconfig' => $pconfig,
162 'group_member' => $group_member,
165 //echo "<pre>"; var_dump(json_encode($output)); killme();
166 echo json_encode($output);
171 * echoes account data and items as separated json, one per line
173 function uexport_all(&$a) {
178 $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
182 $total = $r[0]['total'];
184 // chunk the output to avoid exhausting memory
186 for($x = 0; $x < $total; $x += 500) {
188 $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
189 intval(local_user()),
195 foreach($rr as $k => $v)
199 $output = array('item' => $r);
200 echo json_encode($output)."\n";