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;
13 use Friendica\Util\Network;
18 * @throws ImagickException
19 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
21 function receive_post(App $a)
23 $enabled = intval(Config::get('system', 'diaspora_enabled'));
25 Logger::log('mod-diaspora: disabled');
26 throw new \Friendica\Network\HTTPException\InternalServerErrorException();
29 if (($a->argc == 2) && ($a->argv[1] === 'public')) {
35 if ($a->argc != 3 || $a->argv[1] !== 'users') {
36 throw new \Friendica\Network\HTTPException\InternalServerErrorException();
40 $importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
41 if (!DBA::isResult($importer)) {
42 throw new \Friendica\Network\HTTPException\InternalServerErrorException();
46 // It is an application/x-www-form-urlencoded
48 Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
50 if (empty($_POST['xml'])) {
51 $postdata = Network::postdata();
52 if ($postdata == '') {
53 throw new \Friendica\Network\HTTPException\InternalServerErrorException();
56 Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
57 $msg = Diaspora::decodeRaw($importer, $postdata);
59 $xml = urldecode($_POST['xml']);
61 Logger::log('mod-diaspora: decode message in the old format', Logger::DEBUG);
62 $msg = Diaspora::decode($importer, $xml);
64 if ($public && !$msg) {
65 Logger::log('mod-diaspora: decode message in the new format', Logger::DEBUG);
66 $msg = Diaspora::decodeRaw($importer, $xml);
70 Logger::log('mod-diaspora: decoded', Logger::DEBUG);
72 Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
74 if (!is_array($msg)) {
75 throw new \Friendica\Network\HTTPException\InternalServerErrorException();
78 Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
82 Diaspora::dispatchPublic($msg);
84 $ret = Diaspora::dispatch($importer, $msg);
88 throw new \Friendica\Network\HTTPException\OKException();
90 throw new \Friendica\Network\HTTPException\InternalServerErrorException();