]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/lib/xrdaction.php
Merge branch '0.9.x' into 1.0.x
[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')) {
26     exit(1);
27 }
28
29 class XrdAction extends Action
30 {
31     public $uri;
32
33     public $user;
34
35     public $xrd;
36
37     function handle()
38     {
39         $nick =  $this->user->nickname;
40
41         if (empty($this->xrd)) {
42             $xrd = new XRD();
43         } else {
44             $xrd = $this->xrd;
45         }
46
47         if (empty($xrd->subject)) {
48             $xrd->subject = Discovery::normalize($this->uri);
49         }
50         $xrd->alias[] = $this->user->uri;
51         $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
52                               'type' => 'text/html',
53                               'href' => $this->user->uri);
54
55         $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
56                               'href' => common_local_url('ApiTimelineUser',
57                                                          array('id' => $this->user->id,
58                                                                'format' => 'atom')),
59                               'type' => 'application/atom+xml');
60
61         // hCard
62         $xrd->links[] = array('rel' => Discovery::HCARD,
63                               'type' => 'text/html',
64                               'href' => common_local_url('hcard', array('nickname' => $nick)));
65
66         // XFN
67         $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
68                               'type' => 'text/html',
69                               'href' => $this->user->uri);
70         // FOAF
71         $xrd->links[] = array('rel' => 'describedby',
72                               'type' => 'application/rdf+xml',
73                               'href' => common_local_url('foaf',
74                                                          array('nickname' => $nick)));
75
76         // Salmon
77         $salmon_url = common_local_url('usersalmon',
78                                        array('id' => $this->user->id));
79
80         $xrd->links[] = array('rel' => Salmon::REL_SALMON,
81                               'href' => $salmon_url);
82         // XXX : Deprecated - to be removed.
83         $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
84                               'href' => $salmon_url);
85
86         $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
87                               'href' => $salmon_url);
88
89         // Get this user's keypair
90         $magickey = Magicsig::staticGet('user_id', $this->user->id);
91         if (!$magickey) {
92             // No keypair yet, let's generate one.
93             $magickey = new Magicsig();
94             $magickey->generate($this->user->id);
95         }
96
97         $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
98                               'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
99
100         // TODO - finalize where the redirect should go on the publisher
101         $url = common_local_url('ostatussub') . '?profile={uri}';
102         $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
103                               'template' => $url );
104
105         header('Content-type: application/xrd+xml');
106         print $xrd->toXML();
107     }
108 }