]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
define LACONICA and accept LACONICA for backwards compatibility
[quix0rs-gnu-social.git] / actions / xrds.php
1 <?php
2
3 /**
4  * XRDS for OpenID
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Robin Millette <millette@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('STATUSNET') && !defined('LACONICA')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/omb.php';
37
38 /**
39  * XRDS for OpenID
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @author   Robin Millette <millette@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://status.net/
47  */
48 class XrdsAction extends Action
49 {
50     /**
51      * Is read only?
52      *
53      * @return boolean true
54      */
55     function isReadOnly($args)
56     {
57         return true;
58     }
59
60     /**
61      * Class handler.
62      *
63      * @param array $args query arguments
64      *
65      * @return void
66      */
67     function handle($args)
68     {
69         parent::handle($args);
70         $nickname = $this->trimmed('nickname');
71         $user     = User::staticGet('nickname', $nickname);
72         if (!$user) {
73             $this->clientError(_('No such user.'));
74             return;
75         }
76         $this->showXrds($user);
77     }
78
79     /**
80      * Show XRDS for a user.
81      *
82      * @param class $user XRDS for this user.
83      *
84      * @return void
85      */
86     function showXrds($user)
87     {
88         header('Content-Type: application/xrds+xml');
89         $this->startXML();
90         $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds'));
91
92         $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
93                                           'xml:id' => 'oauth',
94                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
95                                           'version' => '2.0'));
96         $this->element('Type', null, 'xri://$xrds*simple');
97         $this->showService(OAUTH_ENDPOINT_REQUEST,
98                             common_local_url('requesttoken'),
99                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
100                             array(OAUTH_HMAC_SHA1),
101                             $user->uri);
102         $this->showService(OAUTH_ENDPOINT_AUTHORIZE,
103                             common_local_url('userauthorization'),
104                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
105                             array(OAUTH_HMAC_SHA1));
106         $this->showService(OAUTH_ENDPOINT_ACCESS,
107                             common_local_url('accesstoken'),
108                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
109                             array(OAUTH_HMAC_SHA1));
110         $this->showService(OAUTH_ENDPOINT_RESOURCE,
111                             null,
112                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
113                             array(OAUTH_HMAC_SHA1));
114         $this->elementEnd('XRD');
115
116         // XXX: decide whether to include user's ID/nickname in postNotice URL
117         $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
118                                           'xml:id' => 'omb',
119                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
120                                           'version' => '2.0'));
121         $this->element('Type', null, 'xri://$xrds*simple');
122         $this->showService(OMB_ENDPOINT_POSTNOTICE,
123                             common_local_url('postnotice'));
124         $this->showService(OMB_ENDPOINT_UPDATEPROFILE,
125                             common_local_url('updateprofile'));
126         $this->elementEnd('XRD');
127         $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
128                                           'version' => '2.0'));
129         $this->element('Type', null, 'xri://$xrds*simple');
130         $this->showService(OAUTH_DISCOVERY,
131                             '#oauth');
132         $this->showService(OMB_NAMESPACE,
133                             '#omb');
134         $this->elementEnd('XRD');
135         $this->elementEnd('XRDS');
136         $this->endXML();
137     }
138
139     /**
140      * Show service.
141      *
142      * @param string $type    XRDS type
143      * @param string $uri     URI
144      * @param array  $params  type parameters, null by default
145      * @param array  $sigs    type signatures, null by default
146      * @param string $localId local ID, null by default
147      *
148      * @return void
149      */
150     function showService($type, $uri, $params=null, $sigs=null, $localId=null)
151     {
152         $this->elementStart('Service');
153         if ($uri) {
154             $this->element('URI', null, $uri);
155         }
156         $this->element('Type', null, $type);
157         if ($params) {
158             foreach ($params as $param) {
159                 $this->element('Type', null, $param);
160             }
161         }
162         if ($sigs) {
163             foreach ($sigs as $sig) {
164                 $this->element('Type', null, $sig);
165             }
166         }
167         if ($localId) {
168             $this->element('LocalID', null, $localId);
169         }
170         $this->elementEnd('Service');
171     }
172 }
173