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