- * Handle input, produce output
- *
- * Switches based on GET or POST method. On GET, shows a form
- * for posting a notice. On POST, saves the results of that form.
- *
- * Results may be a full page, or just a single notice list item,
- * depending on whether AJAX was requested.
- *
- * @param array $args $_REQUEST contents
- *
- * @return void
- */
- function handle($args)
- {
- if (!common_logged_in()) {
- // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
- $this->clientError(_('Not logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // check for this before token since all POST and FILES data
- // is losts when size is exceeded
- if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
- // 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']));
- }
- parent::handle($args);
-
- // CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- // TRANS: Client error displayed when the session token does not match or is not given.
- $this->clientError(_('There was a problem with your session token. '.
- 'Try again, please.'));
- }
- try {
- $this->saveNewNotice();
- } catch (Exception $e) {
- $this->showForm($e->getMessage());
- return;
- }
- } else {
- $this->showForm();
- }
- }
-
- /**
- * Save a new notice, based on arguments