]> git.mxchange.org Git - friendica.git/blob - mod/uexport.php
Merge branch 'master' of git://github.com/friendika/friendika
[friendica.git] / mod / uexport.php
1 <?php
2
3 function uexport_init(&$a) {
4
5         if(! local_user())
6                 killme();
7
8         $user = array();
9         $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
10                 local_user()
11         );
12         if(count($r)) {
13                 foreach($r as $rr)
14                         foreach($rr as $k => $v)
15                                 $user[$k] = $v;
16
17         }
18         $contact = array();
19         $r = q("SELECT * FROM `contact` WHERE `uid` = %d ",
20                 intval(local_user())
21         );
22         if(count($r)) {
23                 foreach($r as $rr)
24                         foreach($rr as $k => $v)
25                                 $contact[][$k] = $v;
26
27         }
28
29         $profile = array();
30         $r = q("SELECT * FROM `profile` WHERE `uid` = %d ",
31                 intval(local_user())
32         );
33         if(count($r)) {
34                 foreach($r as $rr)
35                         foreach($rr as $k => $v)
36                                 $profile[][$k] = $v;
37         }
38
39         $output = array('user' => $user, 'contact' => $contact, 'profile' => $profile );
40
41         header("Content-type: application/json");
42         echo json_encode($output);
43
44         $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
45                 intval(local_user())
46         );
47         if(count($r))
48                 $total = $r[0]['total'];
49
50         // chunk the output to avoid exhausting memory
51
52         for($x = 0; $x < $total; $x += 500) {
53                 $item = array();
54                 $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
55                         intval(local_user()),
56                         intval($x),
57                         intval(500)
58                 );
59                 if(count($r)) {
60                         foreach($r as $rr)
61                                 foreach($rr as $k => $v)
62                                         $item[][$k] = $v;
63                 }
64
65                 $output = array('item' => $item);
66                 echo json_encode($output);
67         }
68
69
70         killme();
71
72 }