3 * @file mod/receive.php
4 * @brief Diaspora endpoint
8 use Friendica\Core\Config;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
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 (!DBA::isResult($importer)) {
38 System::httpExit(500);
42 // It is an application/x-www-form-urlencoded
44 logger('mod-diaspora: receiving post', LOGGER_DEBUG);
46 if (empty($_POST['xml'])) {
47 $postdata = file_get_contents("php://input");
48 if ($postdata == '') {
49 System::httpExit(500);
52 logger('mod-diaspora: message is in the new format', LOGGER_DEBUG);
53 $msg = Diaspora::decodeRaw($importer, $postdata);
55 $xml = urldecode($_POST['xml']);
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);