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