]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
change Controlez-Vous to Control Yourself
[quix0rs-gnu-social.git] / classes / File.php
index e5913115b7a3ed5a47bf473a30464b66dcfa3d69..971f813acfaaeaaee728d2ce46a3c679574679ff 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * Copyright (C) 2008, Control Yourself, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -79,7 +79,6 @@ class File extends Memcached_DataObject
             && ('text/html' === substr($redir_data['type'], 0, 9))
             && ($oembed_data = File_oembed::_getOembed($given_url))
             && isset($oembed_data['json'])) {
-
             File_oembed::saveNew($oembed_data['json'], $file_id);
         }
         return $x;
@@ -98,7 +97,6 @@ class File extends Memcached_DataObject
                 if ($redir_url === $given_url) {
                     $x = File::saveNew($redir_data, $given_url);
                     $file_id = $x->id;
-
                 } else {
                     $x = File::processNew($redir_url, $notice_id);
                     $file_id = $x->id;
@@ -120,4 +118,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;
+    }
 }
+