]> git.mxchange.org Git - friendica.git/blob - mod/receive.php
Merge branch 'pull'
[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         
14 function receive_post(&$a) {
15
16         if($a->argc != 3 || $a->argv[1] !== 'users')
17                 http_status_exit(500);
18
19         $guid = $a->argv[2];
20
21         $r = q("SELECT * FROM `user` WHERE `guid` = '%s' LIMIT 1",
22                 dbesc($guid)
23         );
24         if(! count($r))
25                 http_status_exit(500);
26
27         $importer = $r[0];
28
29         $xml = $_POST['xml'];
30
31         logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
32
33         if(! $xml)
34                 http_status_exit(500);
35
36         $msg = diaspora_decode($importer,$xml);
37         if(! $msg)
38                 http_status_exit(500);
39
40
41         $parsed_xml = parse_xml_string($msg);
42
43         $xmlbase = $parsed_xml->post;
44
45         // If we reached this point, the message is good. 
46         // Now let's figure out if the author is allowed to send us stuff.
47
48         $r = q("SELECT * FROM `contact` WHERE `network` = 'dspr' AND ( `url` = '%s' OR `alias` = '%s') 
49                 AND `uid` = %d LIMIT 1",
50                 dbesc($author_link),
51                 dbesc($author_link),
52                 intval($importer['uid'])
53         );
54         if(! count($r)) {
55                 logger('mod-diaspora: Author unknown to us.');
56         }       
57
58         // is this a follower? Or have we ignored the person?
59         // If so we can not accept this post.
60         // However we will accept a sharing e.g. friend request
61
62         if((count($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) {
63                 if(! $xmlbase->request) {
64                         logger('mod-diaspora: Ignoring this author.');
65                         http_status_exit(202);
66                         // NOTREACHED
67                 }
68         }
69
70         require_once('include/items.php');
71
72         $contact = ((count($r)) ? $r[0] : null);
73
74         logger('diaspora msg: ' . $msg, LOGGER_DATA); 
75
76         if($xmlbase->request) {
77                 diaspora_request($importer,$contact,$xmlbase->request);
78         }
79         elseif($xmlbase->status_message) {
80                 diaspora_post($importer,$contact,$xmlbase->status_message);
81         }
82         elseif($xmlbase->comment) {
83                 diaspora_comment($importer,$contact,$xmlbase->comment);
84         }
85         elseif($xmlbase->like) {
86                 diaspora_like($importer,$contact,$xmlbase->like);
87         }
88         elseif($xmlbase->retraction) {
89                 diaspora_retraction($importer,$contact,$xmlbase->retraction);
90         }
91         else {
92                 logger('mod-diaspora: unknown message type: ' . print_r($xmlbase,true));
93         }
94
95         http_status_exit(200);
96         // NOTREACHED
97 }
98