From fd0051dab7258c817ff01877bd4324530ce79398 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Sun, 17 Feb 2013 23:19:35 +0100 Subject: #2006 - Add system::mark_file_for_delete API to delete files at shutdown. - added system::mark_file_for_delete to be called to mark a file - added system::delete_marked_files to be called at shutdown to delete the list - amended system::temp_filename to, by default, add the temp name to the list - updated a few other places in code where this should be used --- modules/watermark/controllers/admin_watermarks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/watermark') diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index b058d6a5..222279e8 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -67,7 +67,7 @@ class Admin_Watermarks_Controller extends Admin_Controller { $form = watermark::get_delete_form(); if ($form->validate()) { if ($name = basename(module::get_var("watermark", "name"))) { - @unlink(VARPATH . "modules/watermark/$name"); + system::delete_later(VARPATH . "modules/watermark/$name"); module::clear_var("watermark", "name"); module::clear_var("watermark", "width"); @@ -108,7 +108,7 @@ class Admin_Watermarks_Controller extends Admin_Controller { $name = legal_file::sanitize_filename($name, $extension, "photo"); } catch (Exception $e) { message::error(t("Invalid or unidentifiable image file")); - @unlink($file); + system::delete_later($file); return; } @@ -120,7 +120,7 @@ class Admin_Watermarks_Controller extends Admin_Controller { module::set_var("watermark", "position", $form->add_watermark->position->value); module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); $this->_update_graphics_rules(); - @unlink($file); + system::delete_later($file); message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); -- cgit v1.2.3 From 62035bdbe1f4e8173eff1d93a31bdb658686a926 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Mon, 18 Feb 2013 23:30:29 +0100 Subject: Follow-on to fd0051dab7258c817ff01877bd4324530ce79398 for #2006. - fix unit tests for watermarks, which check for deleted files. --- modules/watermark/tests/Admin_Watermarks_Controller_Test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules/watermark') diff --git a/modules/watermark/tests/Admin_Watermarks_Controller_Test.php b/modules/watermark/tests/Admin_Watermarks_Controller_Test.php index 0b4ba84b..6c6ecb15 100644 --- a/modules/watermark/tests/Admin_Watermarks_Controller_Test.php +++ b/modules/watermark/tests/Admin_Watermarks_Controller_Test.php @@ -68,6 +68,9 @@ class Admin_Watermarks_Controller_Test extends Gallery_Unit_Test_Case { $controller->add(); $results = ob_get_clean(); + // Delete all files marked using system::delete_later (from gallery_event::gallery_shutdown) + system::delete_marked_files(); + // Add should *not* be successful, and watermark should be deleted $this->assert_equal("", $results); $this->assert_false(file_exists($watermark_path)); @@ -115,6 +118,9 @@ class Admin_Watermarks_Controller_Test extends Gallery_Unit_Test_Case { $controller->add(); $results = ob_get_clean(); + // Delete all files marked using system::delete_later (from gallery_event::gallery_shutdown) + system::delete_marked_files(); + // Add should *not* be successful, and watermark should be deleted $this->assert_equal("", $results); $this->assert_false(file_exists($watermark_path)); -- cgit v1.2.3 From ea4622f72635900d8ca33f2ff48848d6a35e9894 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Wed, 27 Feb 2013 09:49:05 +0100 Subject: #2022 - Fix handling of watermark dialog errors. - admin_watermarks: changed header at end of form_add() from text/html to text/plain - admin_watermarks: added header at end of form_edit() and form_delete() just like form_add() (currently omitted) - admin_watermarks/gallery.dialog.js: removed unnecessary encode/decode workaround --- lib/gallery.dialog.js | 7 ------- modules/watermark/controllers/admin_watermarks.php | 18 +++++++----------- 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'modules/watermark') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index e9f4aa03..8fe85165 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -137,13 +137,6 @@ }, success: function(data) { if (data.html) { - if (data.result == "error") { - // This is an odd case that arises from the watermarks module. This is because we - // have a fake xhr, and we rawurlencode the results because the JS code that uploads - // the file buffers it in an iframe which entitizes the HTML and makes it difficult - // for the JS to process. See ticket #797. - data.html = unescape(data.html); - } $("#g-dialog").html(data.html); $("#g-dialog").dialog("option", "position", "center"); $("#g-dialog form :submit").removeClass("ui-state-disabled") diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index 222279e8..bbefcf01 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -55,6 +55,8 @@ class Admin_Watermarks_Controller extends Admin_Controller { } else { json::reply(array("result" => "error", "html" => (string)$form)); } + // Override the application/json mime type for iframe compatibility. See ticket #2022. + header("Content-Type: text/plain; charset=" . Kohana::CHARSET); } public function form_delete() { @@ -83,6 +85,8 @@ class Admin_Watermarks_Controller extends Admin_Controller { } else { json::reply(array("result" => "error", "html" => (string)$form)); } + // Override the application/json mime type for iframe compatibility. See ticket #2022. + header("Content-Type: text/plain; charset=" . Kohana::CHARSET); } public function form_add() { @@ -126,18 +130,10 @@ class Admin_Watermarks_Controller extends Admin_Controller { log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - // rawurlencode the results because the JS code that uploads the file buffers it in an - // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url - // encode it now, it passes through cleanly. See ticket #797. - json::reply(array("result" => "error", "html" => rawurlencode((string)$form))); + json::reply(array("result" => "error", "html" => (string)$form)); } - - // Override the application/json mime type. The dialog based HTML uploader uses an iframe to - // buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the - // JSON that it gets back so it puts up a dialog asking the user what to do with it. So force - // the encoding type back to HTML for the iframe. - // See: http://jquery.malsup.com/form/#file-upload - header("Content-Type: text/html; charset=" . Kohana::CHARSET); + // Override the application/json mime type for iframe compatibility. See ticket #2022. + header("Content-Type: text/plain; charset=" . Kohana::CHARSET); } private function _update_graphics_rules() { -- cgit v1.2.3