3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008-2010, StatusNet, Inc.
6 * Really Simple Discovery (RSD) for API access
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
27 * @link http://status.net/
31 if (!defined('STATUSNET')) {
38 * Really Simple Discovery (RSD) is a simple (to a fault, maybe)
39 * discovery tool for blog APIs.
41 * http://tales.phrasewise.com/rfc/rsd
43 * Anil Dash suggested that RSD be used for services that implement
46 * http://dashes.com/anil/2009/12/the-twitter-api-is-finished.html
48 * It's in use now for WordPress.com blogs:
50 * http://matt.wordpress.com/xmlrpc.php?rsd
52 * I (evan@status.net) have tried to stay faithful to the premise of
53 * RSD, while adding information useful to StatusNet client developers.
56 * - There is a link from each user's profile page to their personal
57 * RSD feed. A personal rsd.xml includes a 'blogID' element that is
59 * - There is a link from the public root to '/rsd.xml', a public RSD
60 * feed. It's identical to the personal rsd except it doesn't include
62 * - I've added a setting to the API to indicate that OAuth support is
67 * @author Evan Prodromou <evan@status.net>
68 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
69 * @link http://status.net/
72 class RsdAction extends Action
75 * Optional attribute for the personal rsd.xml file.
81 * Prepare the action for use.
83 * Check for a nickname; redirect if non-canonical; if
84 * not provided, assume public rsd.xml.
86 * @param array $args GET, POST, and URI arguments.
88 * @return boolean success flag
91 function prepare($args)
93 parent::prepare($args);
97 $nickname_arg = $this->arg('nickname');
99 if (empty($nickname_arg)) {
102 $nickname = common_canonical_nickname($nickname_arg);
104 // Permanent redirect on non-canonical nickname
106 if ($nickname_arg != $nickname) {
107 common_redirect(common_local_url('rsd',
108 array('nickname' => $nickname)),
113 $this->user = User::staticGet('nickname', $nickname);
115 if (empty($this->user)) {
116 $this->clientError(_('No such user.'), 404);
127 * Outputs the XML format for an RSD file. May include
128 * personal information if this is a personal file
129 * (based on whether $user attribute is set).
131 * @param array $args array of arguments
136 function handle($args)
138 header('Content-Type: application/rsd+xml');
142 $rsdNS = 'http://archipelago.phrasewise.com/rsd';
143 $this->elementStart('rsd', array('version' => '1.0',
145 $this->elementStart('service');
146 $this->element('engineName', null, _('StatusNet'));
147 $this->element('engineLink', null, 'http://status.net/');
148 $this->elementStart('apis');
149 if (Event::handle('StartRsdListApis', array($this, $this->user))) {
151 $blogID = (empty($this->user)) ? '' : $this->user->nickname;
152 $apiAttrs = array('name' => 'Twitter',
153 'preferred' => 'true',
154 'apiLink' => $this->_apiRoot(),
155 'blogID' => $blogID);
157 $this->elementStart('api', $apiAttrs);
158 $this->elementStart('settings');
159 $this->element('docs', null,
160 'http://status.net/wiki/TwitterCompatibleAPI');
161 $this->element('setting', array('name' => 'OAuth'),
163 $this->elementEnd('settings');
164 $this->elementEnd('api');
165 Event::handle('EndRsdListApis', array($this, $this->user));
167 $this->elementEnd('apis');
168 $this->elementEnd('service');
169 $this->elementEnd('rsd');
177 * Returns last-modified date for use in caching
179 * Per-user rsd.xml is dated to last change of user
180 * (in case of nickname change); public has no date.
182 * @return string date of last change of this page
185 function lastModified()
187 if (!empty($this->user)) {
188 return $this->user->modified;
195 * Flag to indicate if this action is read-only
197 * It is; it doesn't change the DB.
199 * @param array $args ignored
201 * @return boolean true
204 function isReadOnly($args)
210 * Return current site's API root
212 * Varies based on URL parameters, like if fancy URLs are
215 * @return string API root URI for this site
218 private function _apiRoot()
220 if (common_config('site', 'fancy')) {
221 return common_path('api/', true);
223 return common_path('index.php/api/', true);