]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/lib/xrdaction.php
send a salmon slap to mentioned person when we reply to a notice
[quix0rs-gnu-social.git] / plugins / OStatus / lib / xrdaction.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  * @maintainer James Walker <james@status.net>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
26
27 class XrdAction extends Action
28 {
29
30     public $uri;
31     
32     public $user;
33
34     public $xrd;
35     
36     function handle()
37     {
38         $nick =  $this->user->nickname;
39
40         if (empty($this->xrd)) {
41             $xrd = new XRD();
42         } else {
43             $xrd = $this->xrd;
44         }
45
46         if (empty($xrd->subject)) {
47             $xrd->subject = Discovery::normalize($this->uri);
48         }
49         $xrd->alias[] = $this->user->uri;
50         $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
51                               'type' => 'text/html',
52                               'href' => $this->user->uri);
53
54         $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
55                               'href' => common_local_url('ApiTimelineUser',
56                                                          array('id' => $this->user->id,
57                                                                'format' => 'atom')),
58                               'type' => 'application/atom+xml');
59
60         // hCard
61         $xrd->links[] = array('rel' => Discovery::HCARD,
62                               'type' => 'text/html',
63                               'href' => common_local_url('hcard', array('nickname' => $nick)));
64
65         // XFN
66         $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
67                               'type' => 'text/html',
68                               'href' => $this->user->uri);
69         // FOAF
70         $xrd->links[] = array('rel' => 'describedby',
71                               'type' => 'application/rdf+xml',
72                               'href' => common_local_url('foaf',
73                                                          array('nickname' => $nick)));
74
75         // Salmon
76         $salmon_url = common_local_url('usersalmon',
77                                        array('id' => $this->user->id));
78
79         $xrd->links[] = array('rel' => Salmon::REL_SALMON,
80                               'href' => $salmon_url);
81         // XXX : Deprecated - to be removed.
82         $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
83                               'href' => $salmon_url);
84
85         $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
86                               'href' => $salmon_url);
87
88         // Get this user's keypair
89         $magickey = Magicsig::staticGet('user_id', $this->user->id);
90         if (!$magickey) {
91             // No keypair yet, let's generate one.
92             $magickey = new Magicsig();
93             $magickey->generate($this->user->id);
94         }
95
96         $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
97                               'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
98
99         // TODO - finalize where the redirect should go on the publisher
100         $url = common_local_url('ostatussub') . '?profile={uri}';
101         $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
102                               'template' => $url );
103
104         header('Content-type: application/xrd+xml');
105         print $xrd->toXML();
106     }
107
108 }