]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
maildaemon correctly checks max notice length
[quix0rs-gnu-social.git] / actions / newnotice.php
index 15caff6eaab0042783314c8cc1e6d80e7f9977cc..f773fc880e5328ae1f232252c84e8d79d6703eb9 100644 (file)
@@ -135,7 +135,7 @@ class NewnoticeAction extends Action
 
     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()));
             }
         }
 
@@ -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);