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