8 require_once('include/salmon.php');
9 require_once('include/crypto.php');
10 require_once('include/diaspora.php');
14 function receive_post(&$a) {
16 if($a->argc != 3 || $a->argv[1] !== 'users')
17 http_status_exit(500);
21 $r = q("SELECT * FROM `user` WHERE `guid` = '%s' LIMIT 1",
25 http_status_exit(500);
29 // I really don't know why we need urldecode - PHP should be doing this for us.
30 // It is an application/x-www-form-urlencoded
32 $xml = urldecode($_POST['xml']);
34 logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
37 http_status_exit(500);
39 $msg = diaspora_decode($importer,$xml);
41 logger('mod-diaspora: decoded msg: ' . $msg, LOGGER_DATA);
44 http_status_exit(500);
47 $parsed_xml = parse_xml_string($msg,false);
49 $xmlbase = $parsed_xml->post;
51 // If we reached this point, the message is good.
52 // Now let's figure out if the author is allowed to send us stuff.
54 $r = q("SELECT * FROM `contact` WHERE `network` = 'dspr' AND ( `url` = '%s' OR `alias` = '%s')
55 AND `uid` = %d LIMIT 1",
58 intval($importer['uid'])
61 logger('mod-diaspora: Author unknown to us.');
64 // is this a follower? Or have we ignored the person?
65 // If so we can not accept this post.
66 // However we will accept a sharing e.g. friend request
67 // or a retraction of same.
70 $allow_blocked = (($xmlbase->request || ($xmlbase->retraction && $xmlbase->retraction->type == 'Person')) ? true : false);
73 && (($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']) || ($r[0]['readonly']))
74 && (! $allow_blocked)) {
75 logger('mod-diaspora: Ignoring this author.');
76 http_status_exit(202);
80 require_once('include/items.php');
82 $contact = ((count($r)) ? $r[0] : null);
84 if($xmlbase->request) {
85 diaspora_request($importer,$contact,$xmlbase->request);
87 elseif($xmlbase->status_message) {
88 diaspora_post($importer,$contact,$xmlbase->status_message);
90 elseif($xmlbase->comment) {
91 diaspora_comment($importer,$contact,$xmlbase->comment);
93 elseif($xmlbase->like) {
94 diaspora_like($importer,$contact,$xmlbase->like);
96 elseif($xmlbase->retraction) {
97 diaspora_retraction($importer,$contact,$xmlbase->retraction);
100 logger('mod-diaspora: unknown message type: ' . print_r($xmlbase,true));
103 http_status_exit(200);