]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusesshow.php
Lots of tiny message changes.
[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    Craig Andrews <candrews@integralblue.com>
25  * @author    Evan Prodromou <evan@status.net>
26  * @author    Jeffery To <jeffery.to@gmail.com>
27  * @author    Tom Blankenship <mac65@mac65.com>
28  * @author    Mike Cochrane <mikec@mikenz.geek.nz>
29  * @author    Robin Millette <robin@millette.info>
30  * @author    Zach Copley <zach@status.net>
31  * @copyright 2009 StatusNet, Inc.
32  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
33  * @link      http://status.net/
34  */
35
36 if (!defined('STATUSNET')) {
37     exit(1);
38 }
39
40 require_once INSTALLDIR . '/lib/apiprivateauth.php';
41
42 /**
43  * Returns the notice specified by id as a Twitter-style status and inline user
44  *
45  * @category API
46  * @package  StatusNet
47  * @author   Craig Andrews <candrews@integralblue.com>
48  * @author   Evan Prodromou <evan@status.net>
49  * @author   Jeffery To <jeffery.to@gmail.com>
50  * @author   Tom Blankenship <mac65@mac65.com>
51  * @author   Mike Cochrane <mikec@mikenz.geek.nz>
52  * @author   Robin Millette <robin@millette.info>
53  * @author   Zach Copley <zach@status.net>
54  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
55  * @link     http://status.net/
56  */
57
58 class ApiStatusesShowAction extends ApiPrivateAuthAction
59 {
60
61     var $notice_id = null;
62     var $notice    = null;
63
64     /**
65      * Take arguments for running
66      *
67      * @param array $args $_REQUEST args
68      *
69      * @return boolean success flag
70      *
71      */
72
73     function prepare($args)
74     {
75         parent::prepare($args);
76
77         // 'id' is an undocumented parameter in Twitter's API. Several
78         // clients make use of it, so we support it too.
79
80         // show.json?id=12345 takes precedence over /show/12345.json
81
82         $this->notice_id = (int)$this->trimmed('id');
83
84         if (empty($notice_id)) {
85             $this->notice_id = (int)$this->arg('id');
86         }
87
88         $this->notice = Notice::staticGet((int)$this->notice_id);
89
90         return true;
91     }
92
93     /**
94      * Handle the request
95      *
96      * Check the format and show the notice
97      *
98      * @param array $args $_REQUEST data (unused)
99      *
100      * @return void
101      */
102
103     function handle($args)
104     {
105         parent::handle($args);
106
107         if (!in_array($this->format, array('xml', 'json'))) {
108             $this->clientError(_('API method not found.'), $code = 404);
109             return;
110         }
111
112         $this->showNotice();
113     }
114
115     /**
116      * Show the notice
117      *
118      * @return void
119      */
120
121     function showNotice()
122     {
123         if (!empty($this->notice)) {
124             if ($this->format == 'xml') {
125                 $this->showSingleXmlStatus($this->notice);
126             } elseif ($this->format == 'json') {
127                 $this->show_single_json_status($this->notice);
128             }
129         } else {
130
131             // XXX: Twitter just sets a 404 header and doens't bother
132             // to return an err msg
133
134             $deleted = Deleted_notice::staticGet($this->notice_id);
135
136             if (!empty($deleted)) {
137                 $this->clientError(
138                     _('Status deleted.'),
139                     410,
140                     $this->format
141                 );
142             } else {
143                 $this->clientError(
144                     _('No status with that ID found.'),
145                     404,
146                     $this->format
147                 );
148             }
149         }
150     }
151
152     /**
153      * Is this action read only?
154      *
155      * @param array $args other arguments
156      *
157      * @return boolean true
158      */
159
160     function isReadOnly($args)
161     {
162         return true;
163     }
164
165     /**
166      * When was this notice last modified?
167      *
168      * @return string datestamp of the latest notice in the stream
169      */
170
171     function lastModified()
172     {
173         if (!empty($this->notice)) {
174             return strtotime($this->notice->created);
175         }
176
177         return null;
178     }
179
180     /**
181      * An entity tag for this notice
182      *
183      * Returns an Etag based on the action name, language, and
184      * timestamps of the notice
185      *
186      * @return string etag
187      */
188
189     function etag()
190     {
191         if (!empty($this->notice)) {
192
193             return '"' . implode(
194                 ':',
195                 array($this->arg('action'),
196                       common_language(),
197                       $this->notice->id,
198                       strtotime($this->notice->created))
199             )
200             . '"';
201         }
202
203         return null;
204     }
205
206 }