]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
replace all tabs with four spaces
[quix0rs-gnu-social.git] / actions / xrds.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, 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 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/omb.php');
23
24 class XrdsAction extends Action {
25
26     function is_readonly() {                
27         return true;
28     }
29
30     function handle($args) {
31         parent::handle($args);
32         $nickname = $this->trimmed('nickname');
33         $user = User::staticGet('nickname', $nickname);
34         if (!$user) {
35             common_user_error(_('No such user.'));
36             return;
37         }
38         $this->show_xrds($user);
39     }
40
41     function show_xrds($user) {
42
43         header('Content-Type: application/xrds+xml');
44
45         common_start_xml();
46         common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
47
48         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
49                                           'xml:id' => 'oauth',
50                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
51                                           'version' => '2.0'));
52
53         common_element('Type', NULL, 'xri://$xrds*simple');
54
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),
59                             $user->uri);
60
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));
65
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));
70
71         $this->show_service(OAUTH_ENDPOINT_RESOURCE,
72                             NULL,
73                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
74                             array(OAUTH_HMAC_SHA1));
75
76         common_element_end('XRD');
77
78         # XXX: decide whether to include user's ID/nickname in postNotice URL
79
80         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
81                                           'xml:id' => 'omb',
82                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
83                                           'version' => '2.0'));
84
85         common_element('Type', NULL, 'xri://$xrds*simple');
86
87         $this->show_service(OMB_ENDPOINT_POSTNOTICE,
88                             common_local_url('postnotice'));
89
90         $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
91                             common_local_url('updateprofile'));
92
93         common_element_end('XRD');
94
95         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
96                                           'version' => '2.0'));
97
98         common_element('Type', NULL, 'xri://$xrds*simple');
99
100         $this->show_service(OAUTH_DISCOVERY,
101                             '#oauth');
102         $this->show_service(OMB_NAMESPACE,
103                             '#omb');
104
105         common_element_end('XRD');
106
107         common_element_end('XRDS');
108         common_end_xml();
109     }
110
111     function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
112         common_element_start('Service');
113         if ($uri) {
114             common_element('URI', NULL, $uri);
115         }
116         common_element('Type', NULL, $type);
117         if ($params) {
118             foreach ($params as $param) {
119                 common_element('Type', NULL, $param);
120             }
121         }
122         if ($sigs) {
123             foreach ($sigs as $sig) {
124                 common_element('Type', NULL, $sig);
125             }
126         }
127         if ($localId) {
128             common_element('LocalID', NULL, $localId);
129         }
130         common_element_end('Service');
131     }
132 }