]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
Give NoticeListItem its own class
[quix0rs-gnu-social.git] / actions / xrds.php
1 <?php
2 /**
3  * XRDS for OpenMicroBlogging
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/omb.php';
36 require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
37 require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php';
38 require_once INSTALLDIR.'/lib/xrdsoutputter.php';
39
40 /**
41  * XRDS for OpenMicroBlogging
42  *
43  * @category Action
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Robin Millette <millette@status.net>
47  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
48  * @link     http://status.net/
49  */
50 class XrdsAction extends Action
51 {
52     var $user;
53
54     /**
55      * Is read only?
56      *
57      * @return boolean true
58      */
59     function isReadOnly()
60     {
61         return true;
62     }
63
64     function prepare($args)
65     {
66         parent::prepare($args);
67         $nickname = $this->trimmed('nickname');
68         $this->user     = User::staticGet('nickname', $nickname);
69         if (!$this->user) {
70             // TRANS: Client error displayed providing a non-existing nickname.
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                             null,
102                             $this->user->uri);
103         $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE,
104                             common_local_url('userauthorization'),
105                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
106         $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS,
107                             common_local_url('accesstoken'),
108                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
109         $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE,
110                             null,
111                             array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
112         $xrdsOutputter->elementEnd('XRD');
113
114         //omb
115         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
116                                           'xml:id' => 'omb',
117                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
118                                           'version' => '2.0'));
119         $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
120         $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE,
121                             common_local_url('postnotice'));
122         $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE,
123                             common_local_url('updateprofile'));
124         $xrdsOutputter->elementEnd('XRD');
125
126         Event::handle('EndUserXRDS', array($this,&$xrdsOutputter));
127
128         //misc
129         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
130                                           'version' => '2.0'));
131         $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY,
132                             '#oauth');
133         $xrdsOutputter->showXrdsService(OMB_VERSION,
134                             '#omb');
135         $xrdsOutputter->elementEnd('XRD');
136
137         $xrdsOutputter->endXRDS();
138     }
139 }