3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/omb.php');
24 class XrdsAction extends Action {
26 function is_readonly() {
30 function handle($args) {
31 parent::handle($args);
32 $nickname = $this->trimmed('nickname');
33 $user = User::staticGet('nickname', $nickname);
35 common_user_error(_('No such user.'));
38 $this->show_xrds($user);
41 function show_xrds($user) {
43 header('Content-Type: application/xrds+xml');
46 common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
48 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
50 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
53 common_element('Type', NULL, 'xri://$xrds*simple');
55 $this->show_service(OAUTH_ENDPOINT_REQUEST,
56 common_local_url('requesttoken'),
57 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
58 array(OAUTH_HMAC_SHA1),
61 $this->show_service(OAUTH_ENDPOINT_AUTHORIZE,
62 common_local_url('userauthorization'),
63 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
64 array(OAUTH_HMAC_SHA1));
66 $this->show_service(OAUTH_ENDPOINT_ACCESS,
67 common_local_url('accesstoken'),
68 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
69 array(OAUTH_HMAC_SHA1));
71 $this->show_service(OAUTH_ENDPOINT_RESOURCE,
73 array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
74 array(OAUTH_HMAC_SHA1));
76 common_element_end('XRD');
78 # XXX: decide whether to include user's ID/nickname in postNotice URL
80 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
82 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
85 common_element('Type', NULL, 'xri://$xrds*simple');
87 $this->show_service(OMB_ENDPOINT_POSTNOTICE,
88 common_local_url('postnotice'));
90 $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
91 common_local_url('updateprofile'));
93 common_element_end('XRD');
95 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
98 common_element('Type', NULL, 'xri://$xrds*simple');
100 $this->show_service(OAUTH_DISCOVERY,
102 $this->show_service(OMB_NAMESPACE,
105 common_element_end('XRD');
107 common_element_end('XRDS');
111 function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
112 common_element_start('Service');
114 common_element('URI', NULL, $uri);
116 common_element('Type', NULL, $type);
118 foreach ($params as $param) {
119 common_element('Type', NULL, $param);
123 foreach ($sigs as $sig) {
124 common_element('Type', NULL, $sig);
128 common_element('LocalID', NULL, $localId);
130 common_element_end('Service');