aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2010-10-23 13:35:24 +0000
committerCash Costello <cash.costello@gmail.com>2010-10-23 13:35:24 +0000
commit18d83390fc4fe643a7747d212c491ab88418c1bb (patch)
treebba2811d54b2024a99b2b9497ca75e140c05fb88
parente0834b7d8b2b79ce230ca56601c7851aba4abe88 (diff)
downloadelgg-18d83390fc4fe643a7747d212c491ab88418c1bb.tar.gz
elgg-18d83390fc4fe643a7747d212c491ab88418c1bb.tar.bz2
cleaned up album deletion
-rw-r--r--actions/delete.php64
-rw-r--r--lib/album.php40
2 files changed, 53 insertions, 51 deletions
diff --git a/actions/delete.php b/actions/delete.php
index d9a65ce5f..dfe910666 100644
--- a/actions/delete.php
+++ b/actions/delete.php
@@ -13,12 +13,14 @@ $forward_url = 'pg/photos/world'; // by default forward to world photos
$guid = (int) get_input('guid');
$entity = get_entity($guid);
-if (!$entity) { // unable to get Elgg entity
+if (!$entity) {
+ // unable to get Elgg entity
register_error(elgg_echo("tidypics:deletefailed"));
forward($forward_url);
}
-if (!$entity->canEdit()) { // user doesn't have permissions
+if (!$entity->canEdit()) {
+ // user doesn't have permissions
register_error(elgg_echo("tidypics:deletefailed"));
forward($forward_url);
}
@@ -26,71 +28,31 @@ if (!$entity->canEdit()) { // user doesn't have permissions
$subtype = $entity->getSubtype();
$container = get_entity($entity->container_guid);
-if ($subtype != 'image' && $subtype != 'album') { // how did we even get here?
+if ($subtype != 'image' && $subtype != 'album') {
+ // how did we even get here?
register_error(elgg_echo("tidypics:deletefailed"));
forward($forward_url);
}
-$owner_guid = 0; // group or user
if ($subtype == 'image') {
//forward back to album after deleting pictures
$forward_url = $container->getURL();
// plugins can register to be told when a Tidypics image has been deleted
trigger_elgg_event('delete', 'tp_image', $entity);
-
- if ($entity->delete()) {
- system_message(elgg_echo("tidypics:deleted"));
- } else {
- register_error(elgg_echo("tidypics:deletefailed"));
- }
} else {
- //deleting an album
- $owner_guid = $entity->container_guid;
+ // forward to this person's albums
$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);
+
// plugins can register to be told when a Tidypics album has been deleted
trigger_elgg_event('delete', 'tp_album', $entity);
- //loop through all images and delete them
- foreach ($images as $im) {
- if ($im) {
-
-
- if (!$im->delete()) {
- register_error(elgg_echo("tidypics:deletefailed")); //unable to delete object
- } else {
- if ($subtype=='image') {
- system_message(elgg_echo("tidypics:deleted")); //successfully deleted object
- }
- }
- } //end delete actual image file
- } //end looping through each image to delete it
}
-//now that all images have been deleted, delete the album
-if ($subtype == 'album') {
- //delete the album's directory manually; first create a temp file to get the directory path
- $tmpfile = new ElggFile();
- $tmpfile->setFilename('image/' . $guid . '/._tmp_del_tidypics_album_');
- $tmpfile->subtype = 'image';
- $tmpfile->container_guid = $guid;
- $tmpfile->open("write");
- $tmpfile->write('');
- $tmpfile->close();
- $tmpfile->save();
- $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore());
- $tmpfile->delete();
- if (is_dir($albumdir)) {
- rmdir($albumdir);
- }
- //delete album object from database
- if (!$entity->delete()) {
- register_error(elgg_echo("tidypics:deletefailed")); //unable to delete object
- } else {
- system_message(elgg_echo("tidypics:deleted")); //successfully deleted object
- }
-} //end of delete album
+if ($entity->delete()) {
+ system_message(elgg_echo("tidypics:deleted"));
+} else {
+ register_error(elgg_echo("tidypics:deletefailed"));
+}
forward($forward_url);
diff --git a/lib/album.php b/lib/album.php
index 15450049a..472bf69d8 100644
--- a/lib/album.php
+++ b/lib/album.php
@@ -18,6 +18,19 @@ class TidypicsAlbum extends ElggObject {
}
/**
+ * Delete album
+ *
+ * @return bool
+ */
+ public function delete() {
+
+ $this->deleteImages();
+ $this->deleteAlbumDir();
+
+ return parent::delete();
+ }
+
+ /**
* Get an array of image objects
*
* @param int $limit
@@ -157,4 +170,31 @@ class TidypicsAlbum extends ElggObject {
return TRUE;
}
+
+ protected function deleteImages() {
+ // get all the images from this album as long as less than 999 images
+ $images = get_entities("object", "image", $this->guid, '', 999);
+ foreach ($images as $image) {
+ if ($image) {
+ $image->delete();
+ }
+ }
+ }
+
+ protected function deleteAlbumDir() {
+ $tmpfile = new ElggFile();
+ $tmpfile->setFilename('image/' . $this->guid . '/._tmp_del_tidypics_album_');
+ $tmpfile->subtype = 'image';
+ $tmpfile->owner_guid = $this->owner_guid;
+ $tmpfile->container_guid = $this->guid;
+ $tmpfile->open("write");
+ $tmpfile->write('');
+ $tmpfile->close();
+ $tmpfile->save();
+ $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore());
+ $tmpfile->delete();
+ if (is_dir($albumdir)) {
+ rmdir($albumdir);
+ }
+ }
}