aboutsummaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/delete.php13
-rw-r--r--actions/upload.php25
2 files changed, 35 insertions, 3 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);