]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
Move Composer autoload require out of boot.php
[friendica.git] / mod / receive.php
1 <?php
2 /**
3  * @file mod/receive.php
4  * @brief Diaspora endpoint
5  */
6
7 use Friendica\App;
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
14 /**
15  * @param object $a App
16  * @return void
17  */
18 function receive_post(App $a)
19 {
20         $enabled = intval(Config::get('system', 'diaspora_enabled'));
21         if (!$enabled) {
22                 Logger::log('mod-diaspora: disabled');
23                 System::httpExit(500);
24         }
25
26         if (($a->argc == 2) && ($a->argv[1] === 'public')) {
27                 $public = true;
28                 $importer = [];
29         } else {
30                 $public = false;
31
32                 if ($a->argc != 3 || $a->argv[1] !== 'users') {
33                         System::httpExit(500);
34                 }
35                 $guid = $a->argv[2];
36
37                 $importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
38                 if (!DBA::isResult($importer)) {
39                         System::httpExit(500);
40                 }
41         }
42
43         // It is an application/x-www-form-urlencoded
44
45         Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
46
47         if (empty($_POST['xml'])) {
48                 $postdata = file_get_contents("php://input");
49                 if ($postdata == '') {
50                         System::httpExit(500);
51                 }
52
53                 Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
54                 $msg = Diaspora::decodeRaw($importer, $postdata);
55         } else {
56                 $xml = urldecode($_POST['xml']);
57
58                 Logger::log('mod-diaspora: decode message in the old format', Logger::DEBUG);
59                 $msg = Diaspora::decode($importer, $xml);
60
61                 if ($public && !$msg) {
62                         Logger::log('mod-diaspora: decode message in the new format', Logger::DEBUG);
63                         $msg = Diaspora::decodeRaw($importer, $xml);
64                 }
65         }
66
67         Logger::log('mod-diaspora: decoded', Logger::DEBUG);
68
69         Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
70
71         if (!is_array($msg)) {
72                 System::httpExit(500);
73         }
74
75         Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
76
77         $ret = true;
78         if ($public) {
79                 Diaspora::dispatchPublic($msg);
80         } else {
81                 $ret = Diaspora::dispatch($importer, $msg);
82         }
83
84         System::httpExit(($ret) ? 200 : 500);
85         // NOTREACHED
86 }