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