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;
17 * @throws ImagickException
18 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
20 function receive_post(App $a)
22 $enabled = intval(Config::get('system', 'diaspora_enabled'));
24 Logger::log('mod-diaspora: disabled');
25 System::httpExit(500);
28 if (($a->argc == 2) && ($a->argv[1] === 'public')) {
34 if ($a->argc != 3 || $a->argv[1] !== 'users') {
35 System::httpExit(500);
39 $importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
40 if (!DBA::isResult($importer)) {
41 System::httpExit(500);
45 // It is an application/x-www-form-urlencoded
47 Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
49 if (empty($_POST['xml'])) {
50 $postdata = file_get_contents("php://input");
51 if ($postdata == '') {
52 System::httpExit(500);
55 Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
56 $msg = Diaspora::decodeRaw($importer, $postdata);
58 $xml = urldecode($_POST['xml']);
60 Logger::log('mod-diaspora: decode message in the old format', Logger::DEBUG);
61 $msg = Diaspora::decode($importer, $xml);
63 if ($public && !$msg) {
64 Logger::log('mod-diaspora: decode message in the new format', Logger::DEBUG);
65 $msg = Diaspora::decodeRaw($importer, $xml);
69 Logger::log('mod-diaspora: decoded', Logger::DEBUG);
71 Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
73 if (!is_array($msg)) {
74 System::httpExit(500);
77 Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
81 Diaspora::dispatchPublic($msg);
83 $ret = Diaspora::dispatch($importer, $msg);
86 System::httpExit(($ret) ? 200 : 500);