]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
Move App to src
[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
15         $enabled = intval(get_config('system','diaspora_enabled'));
16         if(! $enabled) {
17                 logger('mod-diaspora: disabled');
18                 http_status_exit(500);
19         }
20
21         $public = false;
22
23         if(($a->argc == 2) && ($a->argv[1] === 'public')) {
24                 $public = true;
25         }
26         else {
27
28                 if($a->argc != 3 || $a->argv[1] !== 'users')
29                         http_status_exit(500);
30
31                 $guid = $a->argv[2];
32
33                 $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
34                         dbesc($guid)
35                 );
36                 if (! dbm::is_result($r)) {
37                         http_status_exit(500);
38                 }
39
40                 $importer = $r[0];
41         }
42
43         // It is an application/x-www-form-urlencoded
44
45         logger('mod-diaspora: receiving post', LOGGER_DEBUG);
46
47         $xml = urldecode($_POST['xml']);
48
49         logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
50
51         if(! $xml)
52                 http_status_exit(500);
53
54         logger('mod-diaspora: message is okay', LOGGER_DEBUG);
55
56         $msg = Diaspora::decode($importer,$xml);
57
58         logger('mod-diaspora: decoded', LOGGER_DEBUG);
59
60         logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA);
61
62         if(! is_array($msg))
63                 http_status_exit(500);
64
65         logger('mod-diaspora: dispatching', LOGGER_DEBUG);
66
67         $ret = 0;
68         if($public) {
69                 Diaspora::dispatch_public($msg);
70         } else {
71                 $ret = Diaspora::dispatch($importer,$msg);
72         }
73
74         http_status_exit(($ret) ? $ret : 200);
75         // NOTREACHED
76 }
77