10 * @author Evan Prodromou <evan@controlyourself.ca>
11 * @author Robin Millette <millette@controlyourself.ca>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://laconi.ca/
15 * Laconica - a distributed open-source microblogging tool
16 * Copyright (C) 2008, Controlez-Vous, Inc.
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Affero General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Affero General Public License for more details.
28 * You should have received a copy of the GNU Affero General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 if (!defined('LACONICA')) {
36 require_once INSTALLDIR.'/lib/omb.php';
43 * @author Evan Prodromou <evan@controlyourself.ca>
44 * @author Robin Millette <millette@controlyourself.ca>
45 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46 * @link http://laconi.ca/
48 class XrdsAction extends Action
53 * @return boolean true
55 function isReadOnly($args)
63 * @param array $args query arguments
67 function handle($args)
69 parent::handle($args);
70 $nickname = $this->trimmed('nickname');
71 $user = User::staticGet('nickname', $nickname);
73 $this->clientError(_('No such user.'));
76 $this->showXrds($user);
80 * Show XRDS for a user.
82 * @param class $user XRDS for this user.
86 function showXrds($user)
88 header('Content-Type: application/xrds+xml');
90 $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds'));
92 $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
94 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
96 $this->element('Type', null, 'xri://$xrds*simple');
97 $this->showService(OAUTH_ENDPOINT_REQUEST,
98 common_local_url('requesttoken'),
99 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
100 array(OAUTH_HMAC_SHA1),
102 $this->showService(OAUTH_ENDPOINT_AUTHORIZE,
103 common_local_url('userauthorization'),
104 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
105 array(OAUTH_HMAC_SHA1));
106 $this->showService(OAUTH_ENDPOINT_ACCESS,
107 common_local_url('accesstoken'),
108 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
109 array(OAUTH_HMAC_SHA1));
110 $this->showService(OAUTH_ENDPOINT_RESOURCE,
112 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
113 array(OAUTH_HMAC_SHA1));
114 $this->elementEnd('XRD');
116 // XXX: decide whether to include user's ID/nickname in postNotice URL
117 $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
119 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
120 'version' => '2.0'));
121 $this->element('Type', null, 'xri://$xrds*simple');
122 $this->showService(OMB_ENDPOINT_POSTNOTICE,
123 common_local_url('postnotice'));
124 $this->showService(OMB_ENDPOINT_UPDATEPROFILE,
125 common_local_url('updateprofile'));
126 $this->elementEnd('XRD');
127 $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
128 'version' => '2.0'));
129 $this->element('Type', null, 'xri://$xrds*simple');
130 $this->showService(OAUTH_DISCOVERY,
132 $this->showService(OMB_NAMESPACE,
134 $this->elementEnd('XRD');
135 $this->elementEnd('XRDS');
142 * @param string $type XRDS type
143 * @param string $uri URI
144 * @param array $params type parameters, null by default
145 * @param array $sigs type signatures, null by default
146 * @param string $localId local ID, null by default
150 function showService($type, $uri, $params=null, $sigs=null, $localId=null)
152 $this->elementStart('Service');
154 $this->element('URI', null, $uri);
156 $this->element('Type', null, $type);
158 foreach ($params as $param) {
159 $this->element('Type', null, $param);
163 foreach ($sigs as $sig) {
164 $this->element('Type', null, $sig);
168 $this->element('LocalID', null, $localId);
170 $this->elementEnd('Service');