]> 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                 receive_return(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                 receive_return(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                 receive_return(500);
35
36         $msg = diaspora_decode($importer,$xml);
37         if(! $msg)
38                 receive_return(500);
39
40         // If we reached this point, the message is good. 
41         // Now let's figure out if the author is allowed to send us stuff.
42
43         $r = q("SELECT * FROM `contact` WHERE `network` = 'dspr' AND ( `url` = '%s' OR `alias` = '%s') 
44                 AND `uid` = %d LIMIT 1",
45                 dbesc($author_link),
46                 dbesc($author_link),
47                 intval($importer['uid'])
48         );
49         if(! count($r)) {
50                 logger('mod-diaspora: Author unknown to us.');
51         }       
52
53         // is this a follower? Or have we ignored the person?
54         // If so we can not accept this post.
55
56         if((count($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) {
57                 logger('mod-diaspora: Ignoring this author.');
58                 receive_return(202);
59                 // NOTREACHED
60         }
61
62         require_once('include/items.php');
63
64         // Placeholder for hub discovery. We shouldn't find any hubs
65         // since we supplied the fake feed header - and it doesn't have any.
66
67         $hub = '';
68
69         /**
70          *
71          * anti-spam measure: consume_feed will accept a follow activity from 
72          * this person (and nothing else) if there is no existing contact record.
73          *
74          */
75
76         $contact_rec = ((count($r)) ? $r[0] : null);
77
78
79         receive_return(200);
80
81
82
83
84 }
85