3 * StatusNet, the distributed open-source microblogging tool
5 * Post a notice (update your status) through the API
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 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/
36 if (!defined('STATUSNET')) {
40 require_once INSTALLDIR . '/lib/apiauth.php';
43 * Updates the authenticating user's status (posts a notice).
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/
58 class ApiStatusesUpdateAction extends ApiAuthAction
62 var $in_reply_to_status_id = null;
64 static $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
67 * Take arguments for running
69 * @param array $args $_REQUEST args
71 * @return boolean success flag
75 function prepare($args)
77 parent::prepare($args);
79 $this->user = $this->auth_user;
81 if (empty($this->user)) {
82 $this->clientError(_('No such user!'), 404, $this->format);
86 $this->status = $this->trimmed('status');
88 if (empty($this->status)) {
90 'Client must provide a \'status\' parameter with a value.',
98 $this->source = $this->trimmed('source');
100 if (empty($this->source) || in_array($source, $this->reserved_sources)) {
101 $this->source = 'api';
104 $this->in_reply_to_status_id
105 = intval($this->trimmed('in_reply_to_status_id'));
113 * Make a new notice for the update, save it, and show it
115 * @param array $args $_REQUEST data (unused)
120 function handle($args)
122 parent::handle($args);
124 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
126 _('This method requires a POST.'),
132 $status_shortened = common_shorten_links($this->status);
134 if (Notice::contentTooLong($status_shortened)) {
136 // Note: Twitter truncates anything over 140, flags the status
141 _('That\'s too long. Max notice size is %d chars.'),
151 // Check for commands
153 $inter = new CommandInterpreter();
154 $cmd = $inter->handle_command($this->user, $status_shortened);
158 if ($this->supported($cmd)) {
159 $cmd->execute(new Channel());
162 // Cmd not supported? Twitter just returns your latest status.
163 // And, it returns your last status whether the cmd was successful
166 $this->notice = $this->user->getCurrentNotice();
172 if (!empty($this->in_reply_to_status_id)) {
174 // Check whether notice actually exists
176 $reply = Notice::staticGet($this->in_reply_to_status_id);
179 $reply_to = $this->in_reply_to_status_id;
190 $this->notice = Notice::saveNew(
192 html_entity_decode($this->status, ENT_NOQUOTES, 'UTF-8'),
198 common_broadcast_notice($this->notice);
205 * Show the resulting notice
210 function showNotice()
212 if (!empty($this->notice)) {
213 if ($this->format == 'xml') {
214 $this->showSingleXmlStatus($this->notice);
215 } elseif ($this->format == 'json') {
216 $this->show_single_json_status($this->notice);
222 * Is this command supported when doing an update from the API?
224 * @param string $cmd the command to check for
226 * @return boolean true or false
229 function supported($cmd)
231 static $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand',
232 'FavCommand', 'OnCommand', 'OffCommand');
234 if (in_array(get_class($cmd), $cmdlist)) {