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