3 * @file mod/receive.php
4 * @brief Diaspora endpoint
8 use Friendica\Core\Config;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Protocol\Diaspora;
14 * @param object $a App
17 function receive_post(App $a)
19 $enabled = intval(Config::get('system', 'diaspora_enabled'));
21 logger('mod-diaspora: disabled');
22 System::httpExit(500);
25 if (($a->argc == 2) && ($a->argv[1] === 'public')) {
31 if ($a->argc != 3 || $a->argv[1] !== 'users') {
32 System::httpExit(500);
36 $importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
37 if (!DBM::is_result($importer)) {
38 System::httpExit(500);
42 // It is an application/x-www-form-urlencoded
44 logger('mod-diaspora: receiving post', LOGGER_DEBUG);
46 $xml = urldecode($_POST['xml']);
49 $postdata = file_get_contents("php://input");
50 if ($postdata == '') {
51 System::httpExit(500);
54 logger('mod-diaspora: message is in the new format', LOGGER_DEBUG);
55 $msg = Diaspora::decodeRaw($importer, $postdata);
57 logger('mod-diaspora: decode message in the old format', LOGGER_DEBUG);
58 $msg = Diaspora::decode($importer, $xml);
60 if ($public && !$msg) {
61 logger('mod-diaspora: decode message in the new format', LOGGER_DEBUG);
62 $msg = Diaspora::decodeRaw($importer, $xml);
66 logger('mod-diaspora: decoded', LOGGER_DEBUG);
68 logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
70 if (!is_array($msg)) {
71 System::httpExit(500);
74 logger('mod-diaspora: dispatching', LOGGER_DEBUG);
78 Diaspora::dispatchPublic($msg);
80 $ret = Diaspora::dispatch($importer, $msg);
83 System::httpExit(($ret) ? 200 : 500);