]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
1d4961d4658f05ddd9336e7302e0c263c27a3240
[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     {                
28         return true;
29     }
30
31     function handle($args)
32     {
33         parent::handle($args);
34         $nickname = $this->trimmed('nickname');
35         $user = User::staticGet('nickname', $nickname);
36         if (!$user) {
37             common_user_error(_('No such user.'));
38             return;
39         }
40         $this->show_xrds($user);
41     }
42
43     function show_xrds($user)
44     {
45
46         header('Content-Type: application/xrds+xml');
47
48         common_start_xml();
49         common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
50
51         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
52                                           'xml:id' => 'oauth',
53                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
54                                           'version' => '2.0'));
55
56         common_element('Type', null, 'xri://$xrds*simple');
57
58         $this->show_service(OAUTH_ENDPOINT_REQUEST,
59                             common_local_url('requesttoken'),
60                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
61                             array(OAUTH_HMAC_SHA1),
62                             $user->uri);
63
64         $this->show_service(OAUTH_ENDPOINT_AUTHORIZE,
65                             common_local_url('userauthorization'),
66                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
67                             array(OAUTH_HMAC_SHA1));
68
69         $this->show_service(OAUTH_ENDPOINT_ACCESS,
70                             common_local_url('accesstoken'),
71                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
72                             array(OAUTH_HMAC_SHA1));
73
74         $this->show_service(OAUTH_ENDPOINT_RESOURCE,
75                             null,
76                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
77                             array(OAUTH_HMAC_SHA1));
78
79         common_element_end('XRD');
80
81         # XXX: decide whether to include user's ID/nickname in postNotice URL
82
83         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
84                                           'xml:id' => 'omb',
85                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
86                                           'version' => '2.0'));
87
88         common_element('Type', null, 'xri://$xrds*simple');
89
90         $this->show_service(OMB_ENDPOINT_POSTNOTICE,
91                             common_local_url('postnotice'));
92
93         $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
94                             common_local_url('updateprofile'));
95
96         common_element_end('XRD');
97
98         common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
99                                           'version' => '2.0'));
100
101         common_element('Type', null, 'xri://$xrds*simple');
102
103         $this->show_service(OAUTH_DISCOVERY,
104                             '#oauth');
105         $this->show_service(OMB_NAMESPACE,
106                             '#omb');
107
108         common_element_end('XRD');
109
110         common_element_end('XRDS');
111         common_end_xml();
112     }
113
114     function show_service($type, $uri, $params=null, $sigs=null, $localId=null)
115     {
116         common_element_start('Service');
117         if ($uri) {
118             common_element('URI', null, $uri);
119         }
120         common_element('Type', null, $type);
121         if ($params) {
122             foreach ($params as $param) {
123                 common_element('Type', null, $param);
124             }
125         }
126         if ($sigs) {
127             foreach ($sigs as $sig) {
128                 common_element('Type', null, $sig);
129             }
130         }
131         if ($localId) {
132             common_element('LocalID', null, $localId);
133         }
134         common_element_end('Service');
135     }
136 }