]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusesshow.php
Remove more redundant $formats
[quix0rs-gnu-social.git] / actions / apistatusesshow.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a notice (as a Twitter-style status)
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  API
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/api.php';
35
36 /**
37  * Returns the notice specified by id as a Twitter-style status and inline user
38  *
39  * @category API
40  * @package  StatusNet
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/
44  */
45
46 class ApiStatusesShowAction extends ApiAction
47 {
48
49     var $notice_id = null;
50     var $notice    = null;
51
52     /**
53      * Take arguments for running
54      *
55      * @param array $args $_REQUEST args
56      *
57      * @return boolean success flag
58      *
59      */
60
61     function prepare($args)
62     {
63         parent::prepare($args);
64
65         // 'id' is an undocumented parameter in Twitter's API. Several
66         // clients make use of it, so we support it too.
67
68         // show.json?id=12345 takes precedence over /show/12345.json
69
70         $this->notice_id = (int)$this->trimmed('id');
71
72         if (empty($notice_id)) {
73             $this->notice_id = (int)$this->arg('id');
74         }
75
76         $this->notice = Notice::staticGet((int)$this->notice_id);
77
78         return true;
79     }
80
81     /**
82      * Handle the request
83      *
84      * Check the format and show the notice
85      *
86      * @param array $args $_REQUEST data (unused)
87      *
88      * @return void
89      */
90
91     function handle($args)
92     {
93         parent::handle($args);
94
95         if (!in_array($this->format, array('xml', 'json'))) {
96             $this->clientError(_('API method not found!'), $code = 404);
97             return;
98         }
99
100         $this->showNotice();
101     }
102
103     /**
104      * Show the notice
105      *
106      * @return void
107      */
108
109     function showNotice()
110     {
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);
116             }
117         } else {
118
119             // XXX: Twitter just sets a 404 header and doens't bother
120             // to return an err msg
121
122             $deleted = Deleted_notice::staticGet($this->notice_id);
123
124             if (!empty($deleted)) {
125                 $this->clientError(
126                     _('Status deleted.'),
127                     410,
128                     $this->format
129                 );
130             } else {
131                 $this->clientError(
132                     _('No status with that ID found.'),
133                     404,
134                     $this->format
135                 );
136             }
137         }
138     }
139
140     /**
141      * Is this action read only?
142      *
143      * @param array $args other arguments
144      *
145      * @return boolean true
146      */
147
148     function isReadOnly($args)
149     {
150         return true;
151     }
152
153     /**
154      * When was this notice last modified?
155      *
156      * @return string datestamp of the latest notice in the stream
157      */
158
159     function lastModified()
160     {
161         if (!empty($this->notice)) {
162             return strtotime($this->notice->created);
163         }
164
165         return null;
166     }
167
168     /**
169      * An entity tag for this notice
170      *
171      * Returns an Etag based on the action name, language, and
172      * timestamps of the notice
173      *
174      * @return string etag
175      */
176
177     function etag()
178     {
179         if (!empty($this->notice)) {
180
181             return '"' . implode(
182                 ':',
183                 array($this->arg('action'),
184                       common_language(),
185                       $this->notice->id,
186                       strtotime($this->notice->created))
187             )
188             . '"';
189         }
190
191         return null;
192     }
193
194 }