summaryrefslogtreecommitdiff
path: root/modules/watermark/controllers
diff options
context:
space:
mode:
authorshadlaws <shad@shadlaws.com>2013-01-26 00:04:55 +0100
committershadlaws <shad@shadlaws.com>2013-01-26 00:04:55 +0100
commit212944e1eae2ffb9a3e27ea7d1c6813160cce1ed (patch)
treea3fc95e0acb8818454fa1a6e5a98558650bcd140 /modules/watermark/controllers
parent776fe75ceb93f8eb729d13d58fb411d6ceeb9270 (diff)
#1951 - Make metadata generation more flexible (photo and movie helpers).
- added photo_get_file_metadata and movie_get_file_metadata events - modified photo::get_file_metadata and movie::get_file_metadata to use them - ensure that non-readable files throw exceptions - redirected other photo metadata calls in core to photo::get_file_metadata (the helper function already exists, but in many places getimagesize is still called directly) - added some unit tests (neither of the functions above had one)
Diffstat (limited to 'modules/watermark/controllers')
-rw-r--r--modules/watermark/controllers/admin_watermarks.php32
1 files changed, 12 insertions, 20 deletions
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php
index 0e6e214b..14c2b394 100644
--- a/modules/watermark/controllers/admin_watermarks.php
+++ b/modules/watermark/controllers/admin_watermarks.php
@@ -100,32 +100,24 @@ class Admin_Watermarks_Controller extends Admin_Controller {
$name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', $pathinfo["basename"]);
$name = legal_file::smash_extensions($name);
- if (!($image_info = getimagesize($file)) ||
- !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
- message::error(t("Unable to identify this image file"));
+ list ($width, $height, $mime_type, $extension) = photo::get_file_metadata($file);
+ if (!legal_file::get_photo_extensions($extension)) {
+ message::error(t("Invalid or unidentifiable image file"));
@unlink($file);
return;
- }
-
- if (!in_array($pathinfo["extension"], legal_file::get_photo_extensions())) {
- switch ($image_info[2]) {
- case IMAGETYPE_GIF:
- $name = legal_file::change_extension($name, "gif");
- break;
- case IMAGETYPE_JPEG:
- $name = legal_file::change_extension($name, "jpg");
- break;
- case IMAGETYPE_PNG:
- $name = legal_file::change_extension($name, "png");
- break;
- }
+ } else {
+ // Force correct, legal extension type on file, which will be of our canonical type
+ // (i.e. all lowercase, jpg instead of jpeg, etc.). This renaming prevents the issues
+ // addressed in ticket #1855, where an image that looked valid (header said jpg) with a
+ // php extension was previously accepted without changing its extension.
+ $name = legal_file::change_extension($name, $extension);
}
rename($file, VARPATH . "modules/watermark/$name");
module::set_var("watermark", "name", $name);
- module::set_var("watermark", "width", $image_info[0]);
- module::set_var("watermark", "height", $image_info[1]);
- module::set_var("watermark", "mime_type", $image_info["mime"]);
+ module::set_var("watermark", "width", $width);
+ module::set_var("watermark", "height", $height);
+ module::set_var("watermark", "mime_type", $mime_type);
module::set_var("watermark", "position", $form->add_watermark->position->value);
module::set_var("watermark", "transparency", $form->add_watermark->transparency->value);
$this->_update_graphics_rules();