aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/delete.php13
-rw-r--r--actions/upload.php25
-rw-r--r--languages/en.php3
-rw-r--r--views/default/tidypics/forms/admin.php6
4 files changed, 43 insertions, 4 deletions
diff --git a/actions/delete.php b/actions/delete.php
index f6b677c55..3deb69c5b 100644
--- a/actions/delete.php
+++ b/actions/delete.php
@@ -30,13 +30,17 @@
register_error(elgg_echo("file:deletefailed"));
forward($forward_url);
}
-
+
+ $owner_guid = 0; // group or user
if ($subtype == 'image') { //deleting an image
+ $album = get_entity($entity->container_guid);
+ $owner_guid = $album->container_guid;
$forward_url = $container->getURL(); //forward back to album after deleting pictures
$images = array($entity);
// plugins can register to be told when a Tidypics image has been deleted
trigger_elgg_event('upload', 'tp_album', $entity);
} else { //deleting an album
+ $owner_guid = $entity->container_guid;
$forward_url = 'pg/photos/owned/' . $container->username;
//get all the images from this album as long as less than 999 images
$images = get_entities("object", "image", $guid, '', 999);
@@ -44,6 +48,10 @@
trigger_elgg_event('upload', 'tp_album', $entity);
}
+ // make sure we decrease the repo size for the size quota
+ $image_repo_size_md = get_metadata_byname($owner_guid, "image_repo_size");
+ $image_repo_size = (int)$image_repo_size_md->value;
+
//loop through all images and delete them
foreach($images as $im) {
$thumbnail = $im->thumbnail;
@@ -72,6 +80,8 @@
$delfile = new ElggFile($im->getGUID());
$delfile->owner_guid = $im->getOwner();
//$delfile->setFilename($im->originalfilename);
+ $image_repo_size -= $delfile->size();
+
if (!$delfile->delete()) {
if ($subtype=='image') register_error(elgg_echo("file:deletefailed")); //unable to delete object
} else {
@@ -104,6 +114,7 @@
}
} //end of delete album
+ create_metadata($owner_guid, "image_repo_size", $image_repo_size, 'integer', $owner_guid);
forward($forward_url);
diff --git a/actions/upload.php b/actions/upload.php
index 5dacd5fec..e7c78c178 100644
--- a/actions/upload.php
+++ b/actions/upload.php
@@ -16,11 +16,18 @@
if (!$container_guid)
$container_guid == $_SESSION['user']->getGUID();
+ $album = get_entity($container_guid);
+
$maxfilesize = get_plugin_setting('maxfilesize','tidypics');
if (!$maxfilesize)
$maxfilesize = 5; // default to 5 MB if not set
$maxfilesize = 1024 * 1024 * $maxfilesize; // convert to bytes from MBs
+ $quota = get_plugin_setting('quota','tidypics');
+ $quota = 1024 * 1024 * $quota;
+ $image_repo_size_md = get_metadata_byname($album->container_guid, "image_repo_size");
+ $image_repo_size = (int)$image_repo_size_md->value;
+
$image_lib = get_plugin_setting('image_lib', 'tidypics');
if (!$image_lib)
$image_lib = 'GD';
@@ -87,6 +94,15 @@
continue;
}
+ // check quota
+ if ($quota) {
+ if ($image_repo_size + $sent_file['size'] > $quota) {
+ array_push($not_uploaded, $sent_file['name']);
+ array_push($error_msgs, elgg_echo('tidypics:exceed_quota'));
+ continue;
+ }
+ }
+
// make sure file does not exceed memory limit
if ($sent_file['size'] > $maxfilesize) {
array_push($not_uploaded, $sent_file['name']);
@@ -178,6 +194,9 @@
td_get_exif($file);
array_push($uploaded_images, $file->guid);
+ // update user/group size for checking quota
+ $image_repo_size += $sent_file['size'];
+
if($river_view == "all") {
add_to_river('river/object/image/create', 'create', $file->getObjectOwnerGUID(), $file->getGUID());
}
@@ -207,7 +226,6 @@
}
// successful upload so check if this is a new album and throw river event if so
- $album = get_entity($container_guid);
if ($album->new_album == TP_NEW_ALBUM) {
if (function_exists('add_to_river'))
add_to_river('river/object/album/create', 'create', $album->owner_guid, $album->guid);
@@ -219,7 +237,10 @@
add_to_river('river/object/image/create', 'create', $file_for_river->getObjectOwnerGUID(), $file_for_river->getGUID());
}
}
-
+
+ // update image repo size
+ create_metadata($album->container_guid, "image_repo_size", $image_repo_size, 'integer', $album->container_guid);
+
// plugins can register to be told when a Tidypics album has had images added
trigger_elgg_event('upload', 'tp_album', $album);
diff --git a/languages/en.php b/languages/en.php
index bbeb9a634..c5f4dd99f 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -50,6 +50,7 @@
'tidypics:settings:exif' => "Show EXIF data",
'tidypics:settings:grp_perm_override' => "Allow group members full access to group albums",
'tidypics:settings:maxfilesize' => "Maximum image size in megabytes (MB):",
+ 'tidypics:settings:quota' => "User/Group Quota (MB) - 0 equals no quota",
'tidypics:settings:watermark' => "Enter text to appear in the watermark - ImageMagick Cmdline must be selected for the image library",
'tidypics:settings:im_path' => "Enter the path to your ImageMagick commands",
'tidypics:settings:river_view' => "How many entries in river for each batch of uploaded images",
@@ -153,7 +154,7 @@
'image:deletefailed' => "Your image could not be deleted at this time.",
'image:downloadfailed' => "Sorry; this image is not available at this time.",
'tidypics:nosettings' => "Admin of this site has not set photo album settings.",
-
+ 'tidypics:exceed_quota' => "You have exceeded the quota set by the administrator",
'images:notedited' => "Not all images were successfully updated",
'album:none' => "No albums have been created yet.",
diff --git a/views/default/tidypics/forms/admin.php b/views/default/tidypics/forms/admin.php
index c5d71409c..d2d676290 100644
--- a/views/default/tidypics/forms/admin.php
+++ b/views/default/tidypics/forms/admin.php
@@ -65,6 +65,12 @@
$form_body .= "<p>" . elgg_echo('tidypics:settings:maxfilesize') . "<br />";
$form_body .= elgg_view("input/text",array('internalname' => 'params[maxfilesize]', 'value' => $maxfilesize)) . "</p>";
+ // Quota Size
+ $quota = $plugin->quota;
+ if (!$quota) $quota = 0;
+ $form_body .= "<p>" . elgg_echo('tidypics:settings:quota') . "<br />";
+ $form_body .= elgg_view("input/text",array('internalname' => 'params[quota]', 'value' => $quota)) . "</p>";
+
// River options
$river_view = $plugin->river_view;
if (!$river_view) $river_view = '1';