123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiStatusesUpdateAction extends ApiAuthAction
- {
- protected $needPost = true;
- var $status = null;
- var $in_reply_to_status_id = null;
- var $lat = null;
- var $lon = null;
- var $media_ids = array();
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->status = $this->trimmed('status');
- $this->lat = $this->trimmed('lat');
- $this->lon = $this->trimmed('long');
- $matches = array();
- common_debug(get_called_class().': media_ids=='._ve($this->trimmed('media_ids')));
- if (preg_match_all('/\d+/', $this->trimmed('media_ids'), $matches) !== false) {
- foreach (array_unique($matches[0]) as $match) {
- try {
- $this->media_ids[$match] = File::getByID($match);
- } catch (EmptyPkeyValueException $e) {
-
- } catch (NoResultException $e) {
-
- }
- }
- }
- $this->in_reply_to_status_id
- = intval($this->trimmed('in_reply_to_status_id'));
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
-
-
- if (empty($_FILES)
- && empty($_POST)
- && ($_SERVER['CONTENT_LENGTH'] > 0)
- ) {
-
-
- $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
- 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
- intval($_SERVER['CONTENT_LENGTH']));
- $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
- }
- if (empty($this->status)) {
-
- $this->clientError(_('Client must provide a \'status\' parameter with a value.'));
- }
- if (is_null($this->scoped)) {
-
- $this->clientError(_('No such user.'), 404);
- }
-
-
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($this->auth_user, $this->status);
- if ($cmd) {
- if ($this->supported($cmd)) {
- $cmd->execute(new Channel());
- }
-
-
-
- $this->notice = $this->auth_user->getCurrentNotice();
- } else {
- $reply_to = null;
- if (!empty($this->in_reply_to_status_id)) {
-
- $reply = Notice::getKV($this->in_reply_to_status_id);
- if ($reply) {
- $reply_to = $this->in_reply_to_status_id;
- } else {
-
- $this->clientError(_('Parent notice not found.'), 404);
- }
- }
- foreach(array_keys($this->media_ids) as $media_id) {
-
-
-
- $this->status .= ' ' . common_local_url('attachment', array('attachment' => $media_id));
- }
- $upload = null;
- try {
- $upload = MediaFile::fromUpload('media', $this->scoped);
- $this->status .= ' ' . $upload->shortUrl();
-
- } catch (NoUploadedMediaException $e) {
-
- }
-
- $status_shortened = $this->auth_user->shortenLinks($this->status);
- if (Notice::contentTooLong($status_shortened)) {
- if ($upload instanceof MediaFile) {
- $upload->delete();
- }
-
-
- $msg = _m('Maximum notice size is %d character, including attachment URL.',
- 'Maximum notice size is %d characters, including attachment URL.',
- Notice::maxContent());
-
- $this->clientError(sprintf($msg, Notice::maxContent()), 413);
- }
- $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
- $options = array('reply_to' => $reply_to);
- if ($this->scoped->shareLocation()) {
- $locOptions = Notice::locationOptions($this->lat,
- $this->lon,
- null,
- null,
- $this->scoped);
- $options = array_merge($options, $locOptions);
- }
- try {
- $this->notice = Notice::saveNew(
- $this->scoped->id,
- $content,
- $this->source,
- $options
- );
- } catch (Exception $e) {
- $this->clientError($e->getMessage(), $e->getCode());
- }
- if (isset($upload)) {
- $upload->attachToNotice($this->notice);
- }
- }
- $this->showNotice();
- }
-
- function showNotice()
- {
- if (!empty($this->notice)) {
- if ($this->format == 'xml') {
- $this->showSingleXmlStatus($this->notice);
- } elseif ($this->format == 'json') {
- $this->show_single_json_status($this->notice);
- } elseif ($this->format == 'atom') {
- $this->showSingleAtomStatus($this->notice);
- }
- }
- }
-
- function supported($cmd)
- {
- static $cmdlist = array('SubCommand', 'UnsubCommand',
- 'OnCommand', 'OffCommand', 'JoinCommand', 'LeaveCommand');
- $supported = null;
- if (Event::handle('CommandSupportedAPI', array($cmd, &$supported))) {
- $supported = $supported || in_array(get_class($cmd), $cmdlist);
- }
- return $supported;
- }
- }
|