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.

68 lines
1.2 KiB

10 years ago
  1. <?php
  2. /**
  3. * Diaspora endpoint
  4. */
  5. require_once('include/salmon.php');
  6. require_once('include/crypto.php');
  7. require_once('include/diaspora.php');
  8. function receive_post(&$a) {
  9. $enabled = intval(get_config('system','diaspora_enabled'));
  10. if(! $enabled) {
  11. logger('mod-diaspora: disabled');
  12. http_status_exit(500);
  13. }
  14. $public = false;
  15. if(($a->argc == 2) && ($a->argv[1] === 'public')) {
  16. $public = true;
  17. }
  18. else {
  19. if($a->argc != 3 || $a->argv[1] !== 'users')
  20. http_status_exit(500);
  21. $guid = $a->argv[2];
  22. $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
  23. dbesc($guid)
  24. );
  25. if(! count($r))
  26. http_status_exit(500);
  27. $importer = $r[0];
  28. }
  29. // It is an application/x-www-form-urlencoded
  30. $xml = urldecode($_POST['xml']);
  31. logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
  32. if(! $xml)
  33. http_status_exit(500);
  34. $msg = diaspora_decode($importer,$xml);
  35. logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA);
  36. if(! is_array($msg))
  37. http_status_exit(500);
  38. $ret = 0;
  39. if($public)
  40. diaspora_dispatch_public($msg);
  41. else
  42. $ret = diaspora_dispatch($importer,$msg);
  43. http_status_exit(($ret) ? $ret : 200);
  44. // NOTREACHED
  45. }