3 * @file mod/receive.php
4 * @brief Diaspora endpoint
8 use Friendica\Core\Config;
9 use Friendica\Core\Logger;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Protocol\Diaspora;
15 * @param object $a App
18 function receive_post(App $a)
20 $enabled = intval(Config::get('system', 'diaspora_enabled'));
22 Logger::log('mod-diaspora: disabled');
23 System::httpExit(500);
26 if (($a->argc == 2) && ($a->argv[1] === 'public')) {
32 if ($a->argc != 3 || $a->argv[1] !== 'users') {
33 System::httpExit(500);
37 $importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
38 if (!DBA::isResult($importer)) {
39 System::httpExit(500);
43 // It is an application/x-www-form-urlencoded
45 Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
47 if (empty($_POST['xml'])) {
48 $postdata = file_get_contents("php://input");
49 if ($postdata == '') {
50 System::httpExit(500);
53 Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
54 $msg = Diaspora::decodeRaw($importer, $postdata);
56 $xml = urldecode($_POST['xml']);
58 Logger::log('mod-diaspora: decode message in the old format', Logger::DEBUG);
59 $msg = Diaspora::decode($importer, $xml);
61 if ($public && !$msg) {
62 Logger::log('mod-diaspora: decode message in the new format', Logger::DEBUG);
63 $msg = Diaspora::decodeRaw($importer, $xml);
67 Logger::log('mod-diaspora: decoded', Logger::DEBUG);
69 Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
71 if (!is_array($msg)) {
72 System::httpExit(500);
75 Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
79 Diaspora::dispatchPublic($msg);
81 $ret = Diaspora::dispatch($importer, $msg);
84 System::httpExit(($ret) ? 200 : 500);