]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
Fix for massively slow friends timeline query due to indexing bug introduced with...
[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                             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     }
140 }
141 ?>