X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fnewnotice.php;h=fc06e5c986f6461e52ba6d4ae288ac16a98187e8;hb=5ab709b73977131813884558bf56d97172a7aa26;hp=572adbb23978edd12113aa8a889a4e8a2b07439b;hpb=a7c85bebd5be9ea019a8c80d74730d7eb28d4651;p=quix0rs-gnu-social.git diff --git a/actions/newnotice.php b/actions/newnotice.php index 572adbb239..fc06e5c986 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -1,6 +1,6 @@ . * * @category Personal - * @package Laconica - * @author Evan Prodromou - * @author Zach Copley - * @author Sarven Capadisli - * @copyright 2008-2009 Control Yourself, Inc. + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @copyright 2008-2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR . '/lib/noticelist.php'; +require_once INSTALLDIR . '/lib/mediafile.php'; /** * Action for posting new notices * * @category Personal - * @package Laconica - * @author Evan Prodromou - * @author Zach Copley - * @author Sarven Capadisli + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ class NewnoticeAction extends Action @@ -58,7 +59,7 @@ class NewnoticeAction extends Action /** * Title of the page * - * Note that this usually doesn't get called unless something went wrong + * Note that this usually does not get called unless something went wrong * * @return string page title */ @@ -84,21 +85,30 @@ class NewnoticeAction extends Action function handle($args) { - parent::handle($args); - if (!common_logged_in()) { $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']) { + $this->clientError(sprintf(_('The server was unable to handle ' . + 'that much POST data (%s bytes) due to its current configuration.'), + $_SERVER['CONTENT_LENGTH'])); + } + parent::handle($args); - // CSRF protection - token set in common_notice_form() + // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->clientError(_('There was a problem with your session token. '. 'Try again, please.')); + } + try { + $this->saveNewNotice(); + } catch (Exception $e) { + $this->showForm($e->getMessage()); return; } - - $this->saveNewNotice(); } else { $this->showForm(); } @@ -123,45 +133,68 @@ class NewnoticeAction extends Action $content = $this->trimmed('status_textarea'); if (!$content) { - $this->showForm(_('No content!')); + $this->clientError(_('No content!')); return; - } else { - $content_shortened = common_shorten_links($content); - - if (mb_strlen($content_shortened) > 140) { - $this->showForm(_('That\'s too long. '. - 'Max notice size is 140 chars.')); - return; - } } $inter = new CommandInterpreter(); - $cmd = $inter->handle_command($user, $content_shortened); + $cmd = $inter->handle_command($user, $content); if ($cmd) { if ($this->boolean('ajax')) { - $cmd->execute(new AjaxWebChannel()); + $cmd->execute(new AjaxWebChannel($this)); } else { - $cmd->execute(new WebChannel()); + $cmd->execute(new WebChannel($this)); } return; } + $content_shortened = common_shorten_links($content); + if (Notice::contentTooLong($content_shortened)) { + $this->clientError(sprintf(_('That\'s too long. '. + 'Max notice size is %d chars.'), + Notice::maxContent())); + } + $replyto = $this->trimmed('inreplyto'); + #If an ID of 0 is wrongly passed here, it will cause a database error, + #so override it... + if ($replyto == 0) { + $replyto = 'false'; + } + + $upload = null; + $upload = MediaFile::fromUpload('attach'); + + if (isset($upload)) { - $notice = Notice::saveNew($user->id, $content, 'web', 1, + $content_shortened .= ' ' . $upload->shortUrl(); + + if (Notice::contentTooLong($content_shortened)) { + $upload->delete(); + $this->clientError( + sprintf( + _('Max notice size is %d chars, including attachment URL.'), + Notice::maxContent() + ) + ); + } + } + + $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); - if (is_string($notice)) { - $this->showForm($notice); - return; + if (isset($upload)) { + $upload->attachToNotice($notice); } common_broadcast_notice($notice); if ($this->boolean('ajax')) { - $this->startHTML('text/xml;charset=utf-8', true); + header('Content-Type: text/xml;charset=utf-8'); + $this->xw->startDocument('1.0', 'UTF-8'); + $this->elementStart('html'); $this->elementStart('head'); $this->element('title', null, _('Notice posted')); $this->elementEnd('head'); @@ -195,7 +228,7 @@ class NewnoticeAction extends Action function ajaxErrorMsg($msg) { - common_start_html('text/xml;charset=utf-8', true); + $this->startHTML('text/xml;charset=utf-8', true); $this->elementStart('head'); $this->element('title', null, _('Ajax Error')); $this->elementEnd('head'); @@ -244,13 +277,14 @@ class NewnoticeAction extends Action $content = $this->trimmed('status_textarea'); if (!$content) { $replyto = $this->trimmed('replyto'); + $inreplyto = $this->trimmed('inreplyto'); $profile = Profile::staticGet('nickname', $replyto); if ($profile) { $content = '@' . $profile->nickname . ' '; } } - $notice_form = new NoticeForm($this, $content); + $notice_form = new NoticeForm($this, '', $content, null, $inreplyto); $notice_form->show(); } @@ -287,3 +321,4 @@ class NewnoticeAction extends Action $nli->show(); } } +