/** * Handle the request * * Make a new notice for the update, save it, and show it * * @return void */ protected function handle() { parent::handle(); // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. // TRANS: %s is the number of bytes of the CONTENT_LENGTH. $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)) { // TRANS: Client error displayed when the parameter "status" is missing. $this->clientError(_('Client must provide a \'status\' parameter with a value.')); } if (is_null($this->scoped)) { // TRANS: Client error displayed when updating a status for a non-existing user. $this->clientError(_('No such user.'), 404); } /* Do not call shortenlinks until the whole notice has been build */ // Check for commands $inter = new CommandInterpreter(); $cmd = $inter->handle_command($this->auth_user, $this->status); if ($cmd) { if ($this->supported($cmd)) { $cmd->execute(new Channel()); } // Cmd not supported? Twitter just returns your latest status. // And, it returns your last status whether the cmd was successful // or not! $this->notice = $this->auth_user->getCurrentNotice(); } else { $reply_to = null; if (!empty($this->in_reply_to_status_id)) { // Check whether notice actually exists $reply = Notice::getKV($this->in_reply_to_status_id); if ($reply) { $reply_to = $this->in_reply_to_status_id; } else { // TRANS: Client error displayed when replying to a non-existing notice. $this->clientError(_('Parent notice not found.'), 404); } } $upload = null; try { $upload = MediaFile::fromUpload('media', $this->scoped); } catch (NoUploadedMediaException $e) { // There was no uploaded media for us today. } if (isset($upload)) { $this->status .= ' ' . $upload->shortUrl(); /* Do not call shortenlinks until the whole notice has been build */ } // in Qvitter we shorten _before_ posting, so disble shortening here $status_shortened = $this->status; if (Notice::contentTooLong($status_shortened)) { if ($upload instanceof MediaFile) { $upload->delete(); } // TRANS: Client error displayed exceeding the maximum notice length. // TRANS: %d is the maximum lenth for a notice. $msg = _m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent()); /* Use HTTP 413 error code (Request Entity Too Large) * instead of basic 400 for better understanding */ $this->clientError(sprintf($msg, Notice::maxContent()), 413); } $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8'); $options = array('reply_to' => $reply_to); // ------------------------------------------------------------- // -------- Qvitter's post-to-the-right-group stuff! ----------- // ------------------------------------------------------------- // guess the groups by the content first, if we don't have group id:s as meta data $profile = Profile::getKV('id', $this->scoped->id); $guessed_groups = User_group::groupsFromText($content, $profile); // if the user has specified any group id:s, correct the guesswork if (strlen($this->post_to_groups) > 0) { // get the groups that the user wants to post to $group_ids = explode(':', $this->post_to_groups); $correct_groups = array(); foreach ($group_ids as $group_id) { $correct_groups[] = User_group::getKV('id', $group_id); } // correct the guesses $corrected_group_ids = array(); foreach ($guessed_groups as $guessed_group) { $id_to_keep = $guessed_group->id; foreach ($correct_groups as $k => $correct_group) { if ($correct_group->nickname == $guessed_group->nickname) { $id_to_keep = $correct_group->id; unset($correct_groups[$k]); break; } } $corrected_group_ids[$id_to_keep] = true; } // but we still want to post to all of the groups that the user specified by id // even if we couldn't use it to correct a bad guess foreach ($correct_groups as $correct_group) { $corrected_group_ids[$correct_group->id] = true; } $options['groups'] = array_keys($corrected_group_ids); } else { $guessed_ids = array(); foreach ($guessed_groups as $guessed_group) { $guessed_ids[$guessed_group->id] = true; } $options['groups'] = array_keys($guessed_ids); } // ------------------------------------------------------------- // ------ End of Qvitter's post-to-the-right-group stuff! ------ // ------------------------------------------------------------- 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(); }