]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
add a print_r for the yadis doc returned
[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/rdf+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                                                         $user->uri);
62
63                 $this->show_service(OAUTH_ENDPOINT_ACCESS,
64                                                         common_local_url('accesstoken'),
65                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
66                                                         array(OAUTH_HMAC_SHA1));
67
68                 $this->show_service(OAUTH_ENDPOINT_RESOURCE,
69                                                         NULL,
70                                                         array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
71                                                         array(OAUTH_HMAC_SHA1));
72                 
73                 common_element_end('XRD');
74                 
75                 # XXX: decide whether to include user's ID/nickname in postNotice URL
76                 
77                 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
78                                                   'xml:id' => 'omb',
79                                                                                   'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
80                                                                                   'version' => '2.0'));
81                 
82                 common_element('Type', NULL, 'xri://$xrds*simple');
83                 
84                 $this->show_service(OMB_ENDPOINT_POSTNOTICE,
85                                                         common_local_url('postnotice'));
86
87                 $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
88                                                         common_local_url('updateprofile'));
89
90                 common_element_end('XRD');
91                 
92                 common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
93                                                                                   'version' => '2.0'));
94
95                 common_element('Type', NULL, 'xri://$xrds*simple');
96                 
97                 $this->show_service(OAUTH_DISCOVERY,
98                                                         '#oauth');
99                 $this->show_service(OMB_NAMESPACE,
100                                                         '#omb');
101                 
102                 common_element_end('XRD');
103                 
104                 common_element_end('XRDS');
105                 common_end_xml();
106         }
107         
108         function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
109                 common_element_start('Service');
110                 if ($uri) {
111                         common_element('URI', NULL, $uri);
112                 }
113                 common_element('Type', NULL, $type);
114                 if ($params) {
115                         foreach ($params as $param) {
116                                 common_element('Type', NULL, $param);
117                         }
118                 }
119                 if ($sigs) {
120                         foreach ($sigs as $sig) {
121                                 common_element('Type', NULL, $sig);
122                         }
123                 }
124                 if ($localId) {
125                         common_element('LocalID', NULL, $localID);
126                 }
127                 common_element_end('Service');
128         }
129 }