3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
21 * @package OStatusPlugin
22 * @maintainer James Walker <james@status.net>
25 if (!defined('STATUSNET')) {
29 class XrdAction extends Action
39 $nick = $this->user->nickname;
40 $profile = $this->user->getProfile();
42 if (empty($this->xrd)) {
48 if (empty($xrd->subject)) {
49 $xrd->subject = Discovery::normalize($this->uri);
52 // Possible aliases for the user
54 $uris = array($this->user->uri, $profile->profileurl);
56 // FIXME: Webfinger generation code should live somewhere on its own
58 $path = common_config('site', 'path');
61 $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server'));
64 foreach ($uris as $uri) {
65 if ($uri != $xrd->subject) {
70 $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
71 'type' => 'text/html',
72 'href' => $profile->profileurl);
74 $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
75 'href' => common_local_url('ApiTimelineUser',
76 array('id' => $this->user->id,
78 'type' => 'application/atom+xml');
81 $xrd->links[] = array('rel' => Discovery::HCARD,
82 'type' => 'text/html',
83 'href' => common_local_url('hcard', array('nickname' => $nick)));
86 $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
87 'type' => 'text/html',
88 'href' => $profile->profileurl);
90 $xrd->links[] = array('rel' => 'describedby',
91 'type' => 'application/rdf+xml',
92 'href' => common_local_url('foaf',
93 array('nickname' => $nick)));
96 $salmon_url = common_local_url('usersalmon',
97 array('id' => $this->user->id));
99 $xrd->links[] = array('rel' => Salmon::REL_SALMON,
100 'href' => $salmon_url);
101 // XXX : Deprecated - to be removed.
102 $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
103 'href' => $salmon_url);
105 $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
106 'href' => $salmon_url);
108 // Get this user's keypair
109 $magickey = Magicsig::staticGet('user_id', $this->user->id);
111 // No keypair yet, let's generate one.
112 $magickey = new Magicsig();
113 $magickey->generate($this->user->id);
116 $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
117 'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
119 // TODO - finalize where the redirect should go on the publisher
120 $url = common_local_url('ostatussub') . '?profile={uri}';
121 $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
122 'template' => $url );
124 header('Content-type: application/xrd+xml');