]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
Fixes:
[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\DBA;
11 use Friendica\Database\DBM;
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('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 (!DBM::is_result($importer)) {
39                         System::httpExit(500);
40                 }
41         }
42
43         // It is an application/x-www-form-urlencoded
44
45         logger('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('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('mod-diaspora: decode message in the old format', LOGGER_DEBUG);
59                 $msg = Diaspora::decode($importer, $xml);
60
61                 if ($public && !$msg) {
62                         logger('mod-diaspora: decode message in the new format', LOGGER_DEBUG);
63                         $msg = Diaspora::decodeRaw($importer, $xml);
64                 }
65         }
66
67         logger('mod-diaspora: decoded', LOGGER_DEBUG);
68
69         logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
70
71         if (!is_array($msg)) {
72                 System::httpExit(500);
73         }
74
75         logger('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 }