]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/xrds.php
Merge branch '0.8.x' into 0.9.x
[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
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     /**
53      * Is read only?
54      *
55      * @return boolean true
56      */
57     function isReadOnly()
58     {
59         return true;
60     }
61
62     /**
63      * Class handler.
64      *
65      * @param array $args query arguments
66      *
67      * @return void
68      */
69     function handle($args)
70     {
71         parent::handle($args);
72         $nickname = $this->trimmed('nickname');
73         $user     = User::staticGet('nickname', $nickname);
74         if (!$user) {
75             $this->clientError(_('No such user.'));
76             return;
77         }
78         $this->showXrds($user);
79     }
80
81     /**
82      * Show XRDS for a user.
83      *
84      * @param class $user XRDS for this user.
85      *
86      * @return void
87      */
88     function showXrds($user)
89     {
90         $srv = new OMB_Service_Provider(profile_to_omb_profile($user->uri,
91                                         $user->getProfile()));
92         /* Use libomb’s default XRDS Writer. */
93         $xrds_writer = null;
94         $srv->writeXRDS(new Laconica_XRDS_Mapper(), $xrds_writer);
95     }
96 }
97
98 class Laconica_XRDS_Mapper implements OMB_XRDS_Mapper
99 {
100     protected $urls;
101
102     public function __construct()
103     {
104         $this->urls = array(
105             OAUTH_ENDPOINT_REQUEST => 'requesttoken',
106             OAUTH_ENDPOINT_AUTHORIZE => 'userauthorization',
107             OAUTH_ENDPOINT_ACCESS => 'accesstoken',
108             OMB_ENDPOINT_POSTNOTICE => 'postnotice',
109             OMB_ENDPOINT_UPDATEPROFILE => 'updateprofile');
110     }
111
112     public function getURL($action)
113     {
114         return common_local_url($this->urls[$action]);
115     }
116 }
117 ?>