summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorRobin Millette <millette@controlyourself.ca>2009-05-31 21:03:55 -0400
committerRobin Millette <millette@controlyourself.ca>2009-05-31 21:03:55 -0400
commitf8dae2bbc9600a4ad474e924dc540491e29e2767 (patch)
treefbc334eb128716d064265458ee8a609f51ab1321 /classes
parentabe68f4318009ed839c1998d91459f26d09f76c8 (diff)
Refactored some attachment code and fixed upload bug in interface.
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/classes/File.php b/classes/File.php
index e5913115b..24ab11b8e 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -120,4 +120,30 @@ class File extends Memcached_DataObject
File_to_post::processNew($file_id, $notice_id);
return $x;
}
+
+ function isRespectsQuota($user) {
+ if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
+ return sprintf(_('No file may be larger than %d bytes ' .
+ 'and the file you sent was %d bytes. Try to upload a smaller version.'),
+ common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
+ }
+
+ $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
+ $this->query($query);
+ $this->fetch();
+ $total = $this->total + $_FILES['attach']['size'];
+ if ($total > common_config('attachments', 'user_quota')) {
+ return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'));
+ }
+
+ $query .= ' month(modified) = month(now()) and year(modified) = year(now())';
+ $this->query($query);
+ $this->fetch();
+ $total = $this->total + $_FILES['attach']['size'];
+ if ($total > common_config('attachments', 'monthly_quota')) {
+ return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'));
+ }
+ return true;
+ }
}
+