]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
OStatus conversation are now checked every 30 minutes for new answers.
[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(&$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(! count($r))
38                         http_status_exit(500);
39
40                 $importer = $r[0];
41         }
42
43         // It is an application/x-www-form-urlencoded
44
45         $xml = urldecode($_POST['xml']);
46
47         logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
48
49         if(! $xml)
50                 http_status_exit(500);
51
52         $msg = diaspora_decode($importer,$xml);
53
54         logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA);
55
56         if(! is_array($msg))
57                 http_status_exit(500);
58
59         $ret = 0;
60         if($public)
61                 diaspora_dispatch_public($msg);
62         else
63                 $ret = diaspora_dispatch($importer,$msg);
64
65         http_status_exit(($ret) ? $ret : 200);
66         // NOTREACHED
67 }
68