3 * @file mod/receive.php
4 * @brief Diaspora endpoint
8 use Friendica\Core\Config;
9 use Friendica\Database\DBM;
10 use Friendica\Protocol\Diaspora;
13 * @param object $a App
16 function receive_post(App $a)
18 $enabled = intval(Config::get('system', 'diaspora_enabled'));
20 logger('mod-diaspora: disabled');
21 http_status_exit(500);
24 if (($a->argc == 2) && ($a->argv[1] === 'public')) {
30 if ($a->argc != 3 || $a->argv[1] !== 'users') {
31 http_status_exit(500);
35 $importer = dba::select('user', array(), array('guid' => $guid, 'account_expired' => false, 'account_removed' => false), array('limit' => 1));
36 if (!DBM::is_result($importer)) {
37 http_status_exit(500);
41 // It is an application/x-www-form-urlencoded
43 logger('mod-diaspora: receiving post', LOGGER_DEBUG);
45 $xml = urldecode($_POST['xml']);
48 $postdata = file_get_contents("php://input");
49 if ($postdata == '') {
50 http_status_exit(500);
53 logger('mod-diaspora: message is in the new format', LOGGER_DEBUG);
54 $msg = Diaspora::decodeRaw($importer, $postdata);
56 logger('mod-diaspora: decode message in the old format', LOGGER_DEBUG);
57 $msg = Diaspora::decode($importer, $xml);
59 if ($public && !$msg) {
60 logger('mod-diaspora: decode message in the new format', LOGGER_DEBUG);
61 $msg = Diaspora::decodeRaw($importer, $xml);
65 logger('mod-diaspora: decoded', LOGGER_DEBUG);
67 logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
69 if (!is_array($msg)) {
70 http_status_exit(500);
73 logger('mod-diaspora: dispatching', LOGGER_DEBUG);
77 Diaspora::dispatchPublic($msg);
79 $ret = Diaspora::dispatch($importer, $msg);
82 http_status_exit(($ret) ? 200 : 500);