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