]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/lib/xrdaction.php
The overloaded DB_DataObject function staticGet is now called getKV
[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         $profile = $this->user->getProfile();
41
42         if (empty($this->xrd)) {
43             $xrd = new XRD();
44         } else {
45             $xrd = $this->xrd;
46         }
47
48         if (empty($xrd->subject)) {
49             $xrd->subject = Discovery::normalize($this->uri);
50         }
51
52         // Possible aliases for the user
53
54         $uris = array($this->user->uri, $profile->profileurl);
55
56         // FIXME: Webfinger generation code should live somewhere on its own
57
58         $path = common_config('site', 'path');
59
60         if (empty($path)) {
61             $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server'));
62         }
63
64         foreach ($uris as $uri) {
65             if ($uri != $xrd->subject) {
66                 $xrd->alias[] = $uri;
67             }
68         }
69
70         $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
71                               'type' => 'text/html',
72                               'href' => $profile->profileurl);
73
74         $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
75                               'href' => common_local_url('ApiTimelineUser',
76                                                          array('id' => $this->user->id,
77                                                                'format' => 'atom')),
78                               'type' => 'application/atom+xml');
79
80         // XFN
81         $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
82                               'type' => 'text/html',
83                               'href' => $profile->profileurl);
84         // FOAF
85         $xrd->links[] = array('rel' => 'describedby',
86                               'type' => 'application/rdf+xml',
87                               'href' => common_local_url('foaf',
88                                                          array('nickname' => $nick)));
89
90         // Salmon
91         $salmon_url = common_local_url('usersalmon',
92                                        array('id' => $this->user->id));
93
94         $xrd->links[] = array('rel' => Salmon::REL_SALMON,
95                               'href' => $salmon_url);
96         // XXX : Deprecated - to be removed.
97         $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
98                               'href' => $salmon_url);
99
100         $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
101                               'href' => $salmon_url);
102
103         // Get this user's keypair
104         $magickey = Magicsig::getKV('user_id', $this->user->id);
105         if (!$magickey) {
106             // No keypair yet, let's generate one.
107             $magickey = new Magicsig();
108             $magickey->generate($this->user->id);
109         }
110
111         $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
112                               'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
113
114         // TODO - finalize where the redirect should go on the publisher
115         $url = common_local_url('ostatussub') . '?profile={uri}';
116         $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
117                               'template' => $url );
118
119         $url = common_local_url('tagprofile') . '?uri={uri}';
120         $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/tag',
121                               'template' => $url );
122
123         header('Content-type: application/xrd+xml');
124         print $xrd->toXML();
125     }
126 }