]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
Merge branch '0.9.x' into adminpanel
[quix0rs-gnu-social.git] / actions / xrds.php
1 <?php
2
3 /**
4  * XRDS for OpenMicroBlogging
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 require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
38 require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php';
39 require_once INSTALLDIR.'/lib/xrdsoutputter.php';
40
41 /**
42  * XRDS for OpenMicroBlogging
43  *
44  * @category Action
45  * @package  StatusNet
46  * @author   Evan Prodromou <evan@status.net>
47  * @author   Robin Millette <millette@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
49  * @link     http://status.net/
50  */
51 class XrdsAction extends Action
52 {
53     var $user;
54
55     /**
56      * Is read only?
57      *
58      * @return boolean true
59      */
60     function isReadOnly()
61     {
62         return true;
63     }
64     
65     function prepare($args)
66     {
67         parent::prepare($args);
68         $nickname = $this->trimmed('nickname');
69         $this->user     = User::staticGet('nickname', $nickname);
70         if (!$this->user) {
71             $this->clientError(_('No such user.'));
72             return;
73         }
74         return true;
75     }
76
77     /**
78      * Class handler.
79      *
80      * @param array $args query arguments
81      *
82      * @return void
83      */
84     function handle($args)
85     {
86         parent::handle($args);
87         $xrdsOutputter = new XRDSOutputter();
88         $xrdsOutputter->startXRDS();
89
90         Event::handle('StartUserXRDS', array($this,&$xrdsOutputter));
91
92         //oauth
93         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
94                                           'xml:id' => 'oauth',
95                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
96                                           'version' => '2.0'));
97         $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
98         $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_REQUEST,
99                             common_local_url('requesttoken'),
100                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
101         $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE,
102                             common_local_url('userauthorization'),
103                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
104                             null,
105                             $this->user->getIdentifierURI());
106         $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS,
107                             common_local_url('accesstoken'),
108                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
109                             null,
110                             $this->user->getIdentifierURI());
111         $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE,
112                             null,
113                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
114                             null,
115                             $this->user->getIdentifierURI());
116         $xrdsOutputter->elementEnd('XRD');
117         
118         //omb
119         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
120                                           'xml:id' => 'oauth',
121                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
122                                           'version' => '2.0'));
123         $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
124         $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE,
125                             common_local_url('postnotice'));
126         $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE,
127                             common_local_url('updateprofile'));
128         $xrdsOutputter->elementEnd('XRD');
129         
130         //misc
131         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
132                                           'xml:id' => 'oauth',
133                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
134                                           'version' => '2.0'));
135         $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY,
136                             '#oauth');
137         $xrdsOutputter->showXrdsService(OMB_VERSION,
138                             '#omb');
139         $xrdsOutputter->elementEnd('XRD');
140
141         Event::handle('EndUserXRDS', array($this,&$xrdsOutputter));
142
143         $xrdsOutputter->endXRDS();
144         
145     }
146 }
147 ?>