]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
Cleanup /format pre-move
[friendica.git] / mod / receive.php
1 <?php
2
3 /**
4  * Diaspora endpoint
5  */
6
7
8 require_once('include/salmon.php');
9 require_once('include/crypto.php');
10 require_once('include/diaspora.php');
11
12 function receive_post(App $a) {
13
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         }
25         else {
26
27                 if($a->argc != 3 || $a->argv[1] !== 'users')
28                         http_status_exit(500);
29
30                 $guid = $a->argv[2];
31
32                 $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
33                         dbesc($guid)
34                 );
35                 if (! dbm::is_result($r)) {
36                         http_status_exit(500);
37                 }
38
39                 $importer = $r[0];
40         }
41
42         // It is an application/x-www-form-urlencoded
43
44         logger('mod-diaspora: receiving post', LOGGER_DEBUG);
45
46         $xml = urldecode($_POST['xml']);
47
48         logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
49
50         if(! $xml)
51                 http_status_exit(500);
52
53         logger('mod-diaspora: message is okay', LOGGER_DEBUG);
54
55         $msg = Diaspora::decode($importer,$xml);
56
57         logger('mod-diaspora: decoded', LOGGER_DEBUG);
58
59         logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA);
60
61         if(! is_array($msg))
62                 http_status_exit(500);
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