Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.3 KiB

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