3 * StatusNet, the distributed open-source microblogging tool
5 * Show a notice (as a Twitter-style status)
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR.'/lib/api.php';
37 * Returns the notice specified by id as a Twitter-style status and inline user
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApiStatusesShowAction extends ApiAction
49 var $notice_id = null;
54 * Take arguments for running
56 * @param array $args $_REQUEST args
58 * @return boolean success flag
62 function prepare($args)
64 parent::prepare($args);
66 // 'id' is an undocumented parameter in Twitter's API. Several
67 // clients make use of it, so we support it too.
69 // show.json?id=12345 takes precedence over /show/12345.json
71 $this->notice_id = (int)$this->trimmed('id');
73 if (empty($notice_id)) {
74 $this->notice_id = (int)$this->arg('id');
77 $this->format = $this->arg('format');
78 $this->notice = Notice::staticGet((int)$this->notice_id);
86 * Check the format and show the notice
88 * @param array $args $_REQUEST data (unused)
93 function handle($args)
95 parent::handle($args);
97 if (!in_array($this->format, array('xml', 'json'))) {
98 $this->clientError(_('API method not found!'), $code = 404);
111 function showNotice()
113 if (!empty($this->notice)) {
114 if ($this->format == 'xml') {
115 $this->show_single_xml_status($this->notice);
116 } elseif ($this->format == 'json') {
117 $this->show_single_json_status($this->notice);
121 // XXX: Twitter just sets a 404 header and doens't bother
122 // to return an err msg
124 $deleted = Deleted_notice::staticGet($this->notice_id);
126 if (!empty($deleted)) {
128 _('Status deleted.'),
134 _('No status with that ID found.'),
143 * Is this action read only?
145 * @param array $args other arguments
147 * @return boolean true
150 function isReadOnly($args)
156 * When was this notice last modified?
158 * @return string datestamp of the latest notice in the stream
161 function lastModified()
163 if (!empty($this->notice)) {
164 return strtotime($this->notice->created);
171 * An entity tag for this notice
173 * Returns an Etag based on the action name, language, and
174 * timestamps of the notice
176 * @return string etag
181 if (!empty($this->notice)) {
183 return '"' . implode(
185 array($this->arg('action'),
188 strtotime($this->notice->created))