diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/album.php | 40 |
1 files changed, 40 insertions, 0 deletions
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); + } + } } |