X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fnewnotice.php;h=23ec2a1b5827c3aca92ecb4f20d36c7e6da10718;hb=a68663588ee95915153ad1f927cf510e3d41a299;hp=15caff6eaab0042783314c8cc1e6d80e7f9977cc;hpb=801aa9165ec47c11c6f7c687d70f627bbd87f566;p=quix0rs-gnu-social.git diff --git a/actions/newnotice.php b/actions/newnotice.php index 15caff6eaa..23ec2a1b58 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); } @@ -39,12 +39,12 @@ require_once INSTALLDIR.'/lib/noticelist.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 @@ -91,8 +91,8 @@ class NewnoticeAction extends Action // 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'])); + 'that much POST data (%s bytes) due to its current configuration.'), + $_SERVER['CONTENT_LENGTH'])); } parent::handle($args); @@ -130,12 +130,12 @@ class NewnoticeAction extends Action $hint = ''; } $this->clientError(sprintf( - _('%s is not a supported filetype on this server.'), $filetype) . $hint); + _('%s is not a supported filetype on this server.'), $filetype) . $hint); } function isRespectsQuota($user) { $file = new File; - $ret = $file->isRespectsQuota($user); + $ret = $file->isRespectsQuota($user,$_FILES['attach']['size']); if (true === $ret) return true; $this->clientError($ret); } @@ -162,9 +162,10 @@ class NewnoticeAction extends Action $this->clientError(_('No content!')); } else { $content_shortened = common_shorten_links($content); - if (mb_strlen($content_shortened) > 140) { - $this->clientError(_('That\'s too long. '. - 'Max notice size is 140 chars.')); + if (Notice::contentTooLong($content_shortened)) { + $this->clientError(sprintf(_('That\'s too long. '. + 'Max notice size is %d chars.'), + Notice::maxContent())); } } @@ -190,37 +191,37 @@ class NewnoticeAction extends Action if (isset($_FILES['attach']['error'])) { switch ($_FILES['attach']['error']) { - case UPLOAD_ERR_NO_FILE: - // no file uploaded, nothing to do - break; + case UPLOAD_ERR_NO_FILE: + // no file uploaded, nothing to do + break; - case UPLOAD_ERR_OK: - $mimetype = $this->getUploadedFileType(); - if (!$this->isRespectsQuota($user)) { - die('clientError() should trigger an exception before reaching here.'); - } - break; + case UPLOAD_ERR_OK: + $mimetype = $this->getUploadedFileType(); + if (!$this->isRespectsQuota($user)) { + die('clientError() should trigger an exception before reaching here.'); + } + break; - case UPLOAD_ERR_INI_SIZE: - $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.')); + case UPLOAD_ERR_INI_SIZE: + $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.')); - case UPLOAD_ERR_FORM_SIZE: - $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.')); + case UPLOAD_ERR_FORM_SIZE: + $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.')); - case UPLOAD_ERR_PARTIAL: - $this->clientError(_('The uploaded file was only partially uploaded.')); + case UPLOAD_ERR_PARTIAL: + $this->clientError(_('The uploaded file was only partially uploaded.')); - case UPLOAD_ERR_NO_TMP_DIR: - $this->clientError(_('Missing a temporary folder.')); + case UPLOAD_ERR_NO_TMP_DIR: + $this->clientError(_('Missing a temporary folder.')); - case UPLOAD_ERR_CANT_WRITE: - $this->clientError(_('Failed to write file to disk.')); + case UPLOAD_ERR_CANT_WRITE: + $this->clientError(_('Failed to write file to disk.')); - case UPLOAD_ERR_EXTENSION: - $this->clientError(_('File upload stopped by extension.')); + case UPLOAD_ERR_EXTENSION: + $this->clientError(_('File upload stopped by extension.')); - default: - die('Should never reach here.'); + default: + die('Should never reach here.'); } } @@ -229,14 +230,26 @@ class NewnoticeAction extends Action if (empty($filename)) { $this->clientError(_('Couldn\'t save file.')); } - $fileurl = File::url($filename); + + $fileRecord = $this->storeFile($filename, $mimetype); + + $fileurl = common_local_url('attachment', + array('attachment' => $fileRecord->id)); + + // not sure this is necessary -- Zach + $this->maybeAddRedir($fileRecord->id, $fileurl); + $short_fileurl = common_shorten_url($fileurl); $content_shortened .= ' ' . $short_fileurl; - if (mb_strlen($content_shortened) > 140) { + + if (Notice::contentTooLong($content_shortened)) { $this->deleteFile($filename); - $this->clientError(_('Max notice size is 140 chars, including attachment URL.')); + $this->clientError(sprintf(_('Max notice size is %d chars, including attachment URL.'), + Notice::maxContent())); } - $fileRecord = $this->rememberFile($filename, $mimetype, $short_fileurl); + + // Also, not sure this is necessary -- Zach + $this->maybeAddRedir($fileRecord->id, $short_fileurl); } $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, @@ -305,8 +318,8 @@ class NewnoticeAction extends Action @unlink($filepath); } - function rememberFile($filename, $mimetype, $short) - { + function storeFile($filename, $mimetype) { + $file = new File; $file->filename = $filename; @@ -325,11 +338,14 @@ class NewnoticeAction extends Action $this->clientError(_('There was a database error while saving your file. Please try again.')); } - $this->maybeAddRedir($file_id, $short); - return $file; } + function rememberFile($file, $short) + { + $this->maybeAddRedir($file->id, $short); + } + function maybeAddRedir($file_id, $url) { $file_redir = File_redirection::staticGet('url', $url); @@ -353,7 +369,7 @@ class NewnoticeAction extends Action File_to_post::processNew($filerec->id, $notice->id); $this->maybeAddRedir($filerec->id, - common_local_url('file', array('notice' => $notice->id))); + common_local_url('file', array('notice' => $notice->id))); } /** @@ -417,13 +433,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(); }