From 2878babdb2c4e3714f0ce57b12f8580740f7a032 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Mon, 19 Mar 2007 07:52:29 +0000 Subject: [PATCH] merged fix for MDL-8942, can't delete blog images --- blog/edit.php | 4 +++- blog/lib.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/blog/edit.php b/blog/edit.php index b14f3f3846..5743b66bc5 100755 --- a/blog/edit.php +++ b/blog/edit.php @@ -244,7 +244,9 @@ function do_delete($post) { $status = delete_records('post', 'id', $post->id); $status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status; - + + blog_delete_old_attachments($post); + add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $post->userid, 'deleted blog entry with entry id# '. $post->id); if (!$status) { diff --git a/blog/lib.php b/blog/lib.php index a986cb06c1..431d0b5689 100755 --- a/blog/lib.php +++ b/blog/lib.php @@ -263,6 +263,24 @@ return make_upload_directory( blog_file_area_name($blogentry) ); } + function blog_delete_old_attachments($post, $exception="") { + // Deletes all the user files in the attachments area for a post + // EXCEPT for any file named $exception + + if ($basedir = blog_file_area($post)) { + if ($files = get_directory_list($basedir)) { + foreach ($files as $file) { + if ($file != $exception) { + unlink("$basedir/$file"); + notify("Existing file '$file' has been deleted!"); + } + } + } + if (!$exception) { // Delete directory as well, if empty + rmdir("$basedir"); + } + } + } function blog_print_attachments($blogentry, $return=NULL) { // if return=html, then return a html string. -- 2.39.5