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;
53 * Take arguments for running
55 * @param array $args $_REQUEST args
57 * @return boolean success flag
61 function prepare($args)
63 parent::prepare($args);
65 // 'id' is an undocumented parameter in Twitter's API. Several
66 // clients make use of it, so we support it too.
68 // show.json?id=12345 takes precedence over /show/12345.json
70 $this->notice_id = (int)$this->trimmed('id');
72 if (empty($notice_id)) {
73 $this->notice_id = (int)$this->arg('id');
76 $this->notice = Notice::staticGet((int)$this->notice_id);
84 * Check the format and show the notice
86 * @param array $args $_REQUEST data (unused)
91 function handle($args)
93 parent::handle($args);
95 if (!in_array($this->format, array('xml', 'json'))) {
96 $this->clientError(_('API method not found!'), $code = 404);
109 function showNotice()
111 if (!empty($this->notice)) {
112 if ($this->format == 'xml') {
113 $this->show_single_xml_status($this->notice);
114 } elseif ($this->format == 'json') {
115 $this->show_single_json_status($this->notice);
119 // XXX: Twitter just sets a 404 header and doens't bother
120 // to return an err msg
122 $deleted = Deleted_notice::staticGet($this->notice_id);
124 if (!empty($deleted)) {
126 _('Status deleted.'),
132 _('No status with that ID found.'),
141 * Is this action read only?
143 * @param array $args other arguments
145 * @return boolean true
148 function isReadOnly($args)
154 * When was this notice last modified?
156 * @return string datestamp of the latest notice in the stream
159 function lastModified()
161 if (!empty($this->notice)) {
162 return strtotime($this->notice->created);
169 * An entity tag for this notice
171 * Returns an Etag based on the action name, language, and
172 * timestamps of the notice
174 * @return string etag
179 if (!empty($this->notice)) {
181 return '"' . implode(
183 array($this->arg('action'),
186 strtotime($this->notice->created))