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