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