From 8500fba8a024ecb2e2803a0d605cc9d255ea37d6 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 21 Apr 2011 02:56:11 -0600 Subject: [PATCH 01/32] Add support for raw photo formats. --- .../rawphoto/controllers/admin_rawphoto.php | 63 +++++++++++++ .../rawphoto/helpers/rawphoto_event.php | 34 +++++++ .../rawphoto/helpers/rawphoto_graphics.php | 88 +++++++++++++++++++ .../rawphoto/helpers/rawphoto_installer.php | 36 ++++++++ 3.0/modules/rawphoto/module.info | 3 + .../rawphoto/views/admin_rawphoto.html.php | 42 +++++++++ 6 files changed, 266 insertions(+) create mode 100644 3.0/modules/rawphoto/controllers/admin_rawphoto.php create mode 100644 3.0/modules/rawphoto/helpers/rawphoto_event.php create mode 100644 3.0/modules/rawphoto/helpers/rawphoto_graphics.php create mode 100644 3.0/modules/rawphoto/helpers/rawphoto_installer.php create mode 100644 3.0/modules/rawphoto/module.info create mode 100644 3.0/modules/rawphoto/views/admin_rawphoto.html.php diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php new file mode 100644 index 00000000..f4460476 --- /dev/null +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -0,0 +1,63 @@ +_get_view(); + } + + private function _get_view($errors = array(), $icc_path = null) { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_rawphoto.html"); + $view->content->dcraw = rawphoto_graphics::detect_dcraw(); + $toolkit_names = array("imagemagick" => "ImageMagick", + "graphicsmagick" => "GraphicsMagick"); + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $view->content->toolkit_name = array_key_exists($toolkit_id, $toolkit_names) ? + $toolkit_names[$toolkit_id] : "none"; + $view->content->icc_path = isset($icc_path) ? + $icc_path : module::get_var("rawphoto", "icc_path"); + $view->content->errors = $errors; + return $view; + } + + public function saveprefs() { + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + $post = new Validation($_POST); + $post->add_callbacks("IccPath", array($this, "_validate_icc_path")); + $icc_path = Input::instance()->post("IccPath"); + if ($post->validate()) { + module::set_var("rawphoto", "icc_path", $icc_path); + message::success(t("Your preferences have been saved.")); + } else { + message::error(t("Your preferences are not valid.")); + } + + print $this->_get_view($post->errors(), $icc_path); + } + + public function _validate_icc_path(Validation $post, $field) { + if (!empty($post->$field) && !@is_file($post->$field)) { + $post->add_error($field, t("No ICC profile exists at the location %icc_path", + array("icc_path" => $post->$field))); + } + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php new file mode 100644 index 00000000..04d5cf78 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -0,0 +1,34 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("rawphoto") + ->label(t("Raw Photos")) + ->url(url::site("admin/rawphoto"))); + } + + static function upload_extensions($extensions_wrapper) { + array_push($extensions_wrapper->extensions, + "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", + "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php new file mode 100644 index 00000000..258ad17e --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -0,0 +1,88 @@ +installed = false; + $dcraw->error = t("The dcraw tool could not be located on your system."); + } else { + if (@is_file($path) && preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', + shell_exec($path), $matches)) { + $dcraw->installed = true; + $dcraw->path = $path; + $dcraw->version = $matches[1]; + } else { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, but PHP's open_basedir restriction " . + "prevents Gallery from using it."); + } + } + return $dcraw; + } + + static function convert($input_file, $output_file) { + $success = false; + $dcraw = rawphoto_graphics::detect_dcraw(); + if ($dcraw->installed) { + // Use dcraw to convert from a raw image to a standard pixmap. + $cmd = escapeshellcmd($dcraw->path) . " -c -w -W -t 0 "; + $icc_path = module::get_var("rawphoto", "icc_path"); + if (!empty($icc_path)) { + $cmd .= "-p " . escapeshellarg($icc_path) . " "; + } + $cmd .= escapeshellarg($input_file); + + // Then use the graphics toolkit to convert the stream to a JPEG. + $cmd .= "| "; + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $toolkit_path = module::get_var("gallery", "graphics_toolkit_path"); + $image_quality = module::get_var("gallery", "image_quality"); + $toolkit_compat = false; + switch ($toolkit_id) { + case 'imagemagick': + $cmd .= escapeshellcmd("$toolkit_path/convert"); + $cmd .= " -quality " . escapeshellarg($image_quality . "%"); + $cmd .= " - " . escapeshellarg($output_file); + $toolkit_compat = true; + break; + case 'graphicsmagick': + $cmd .= escapeshellcmd("$toolkit_path/gm"); + $cmd .= " convert -quality " . escapeshellarg($image_quality . "%"); + $cmd .= " - " . escapeshellarg($output_file); + $toolkit_compat = true; + break; + default: + log::warning("rawphoto", "Cannot convert raw photo with graphics toolkit: " . + $toolkit_id->active); + } + + if ($toolkit_compat) { + exec($cmd, $output, $return_var); + $success = ($return_var == 0); + } + } + if (!$success) { + // Make sure the unmodified output file exists where it's expected to be. + copy($input_file, $output_file); + } + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php new file mode 100644 index 00000000..54d80780 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -0,0 +1,36 @@ + +
+

+ + +

Raw photo processing depends on the ' . + 'dcraw tool, which must be installed separately. ' . + 'It also depends on either the ImageMagick or GraphicsMagick graphics toolkits.', + array("raw_url" => + "http://www.adamcoupe.com/whitepapers/photography_technique_benefits_of_shooting_in_raw.htm", + "dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")) ?>

+
+ + installed): ?> +

%path.", + array("path" => $dcraw->path)) ?>

+ +

error ?>

+ + +

+ activate either ImageMagick or GraphicsMagick.', + array("activate_url" => url::site("admin/graphics"))) ?> +

+ +

$toolkit_name)) ?>

+ + +

+ + ICC profile', array("icc_url" => + "http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?> + "IccPath", "id" => "IccPath"), $icc_path) ?> + + An ICC profile is optional. If you don't know what it is, then you don't need it. + +
+ + +
From 6013e96cf352309a45635e4759cfc8cbaf7c7ed0 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 21 Apr 2011 20:15:20 -0600 Subject: [PATCH 02/32] Report as a site status when the graphics toolkit doesn't support Raw Photos. --- .../rawphoto/controllers/admin_rawphoto.php | 1 + .../rawphoto/helpers/rawphoto_event.php | 4 ++++ .../rawphoto/helpers/rawphoto_graphics.php | 20 ++++++++++++++++++- .../rawphoto/helpers/rawphoto_installer.php | 3 +++ .../rawphoto/views/admin_rawphoto.html.php | 2 +- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php index f4460476..8935f1a5 100644 --- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -29,6 +29,7 @@ class Admin_RawPhoto_Controller extends Admin_Controller { $toolkit_names = array("imagemagick" => "ImageMagick", "graphicsmagick" => "GraphicsMagick"); $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $toolkit_names = rawphoto_graphics::get_supported_toolkits(); $view->content->toolkit_name = array_key_exists($toolkit_id, $toolkit_names) ? $toolkit_names[$toolkit_id] : "none"; $view->content->icc_path = isset($icc_path) ? diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index 04d5cf78..afcabc10 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -31,4 +31,8 @@ class rawphoto_event_Core { "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); } + + static function graphics_toolkit_change($toolkit_id) { + rawphoto_graphics::report_ppm_support($toolkit_id); + } } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 258ad17e..0a2f7349 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -39,6 +39,23 @@ class rawphoto_graphics { return $dcraw; } + static function get_supported_toolkits() { + return array("imagemagick" => "ImageMagick", + "graphicsmagick" => "GraphicsMagick"); + } + + static function report_ppm_support($toolkit_id) { + if (array_key_exists($toolkit_id, rawphoto_graphics::get_supported_toolkits())) { + site_status::clear("rawphoto_needs_ppm_support"); + } else { + site_status::warning( + t('The Raw Photos module requires a supporting graphics toolkit. ' . + 'Activate either ImageMagick or GraphicsMagick.', + array("activate_url" => url::site("admin/graphics"))), + "rawphoto_needs_ppm_support"); + } + } + static function convert($input_file, $output_file) { $success = false; $dcraw = rawphoto_graphics::detect_dcraw(); @@ -52,7 +69,7 @@ class rawphoto_graphics { $cmd .= escapeshellarg($input_file); // Then use the graphics toolkit to convert the stream to a JPEG. - $cmd .= "| "; + $cmd .= " | "; $toolkit_id = module::get_var("gallery", "graphics_toolkit"); $toolkit_path = module::get_var("gallery", "graphics_toolkit_path"); $image_quality = module::get_var("gallery", "image_quality"); @@ -77,6 +94,7 @@ class rawphoto_graphics { if ($toolkit_compat) { exec($cmd, $output, $return_var); + // Failure is common, because dcraw will abort unless the original image is a raw photo. $success = ($return_var == 0); } } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 54d80780..12709cfa 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -26,11 +26,14 @@ class rawphoto_installer { foreach (array("thumb", "resize") as $target) { graphics::add_rule("rawphoto", $target, "rawphoto_graphics::convert", array(), 10); } + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + rawphoto_graphics::report_ppm_support($toolkit_id); } static function deactivate() { foreach (array("thumb", "resize") as $target) { graphics::remove_rule("rawphoto", $target, "rawphoto_graphics::convert"); } + site_status::clear("rawphoto_needs_ppm_support"); } } diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index ac7e9727..71e2f699 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -20,7 +20,7 @@

activate either ImageMagick or GraphicsMagick.', + 'Activate either ImageMagick or GraphicsMagick.', array("activate_url" => url::site("admin/graphics"))) ?>

From b27680866507baccbd93d582ee437f3b3c4fcef1 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 21 Apr 2011 23:02:38 -0600 Subject: [PATCH 03/32] Use the "self" reference. --- 3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 0a2f7349..58387fd8 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -45,7 +45,7 @@ class rawphoto_graphics { } static function report_ppm_support($toolkit_id) { - if (array_key_exists($toolkit_id, rawphoto_graphics::get_supported_toolkits())) { + if (array_key_exists($toolkit_id, self::get_supported_toolkits())) { site_status::clear("rawphoto_needs_ppm_support"); } else { site_status::warning( @@ -58,7 +58,7 @@ class rawphoto_graphics { static function convert($input_file, $output_file) { $success = false; - $dcraw = rawphoto_graphics::detect_dcraw(); + $dcraw = self::detect_dcraw(); if ($dcraw->installed) { // Use dcraw to convert from a raw image to a standard pixmap. $cmd = escapeshellcmd($dcraw->path) . " -c -w -W -t 0 "; From 50d7febb6472d3b797928693f2d47f20913b6777 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Fri, 22 Apr 2011 14:43:47 -0600 Subject: [PATCH 04/32] Don't forget to escape unsafe characters in error messages. --- 3.0/modules/rawphoto/views/admin_rawphoto.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index 71e2f699..eadec8f9 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -15,7 +15,7 @@

%path.", array("path" => $dcraw->path)) ?>

-

error ?>

+

error) ?>

@@ -28,7 +28,7 @@ array("toolkit_name" => $toolkit_name)) ?>

-

+

ICC profile', array("icc_url" => "http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?> From 1347f0305e9e5b1a11e048fac32c8a67a637578f Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Fri, 22 Apr 2011 15:45:40 -0600 Subject: [PATCH 05/32] Error messages should be able to contain HTML. This reverts commit 50d7febb6472d3b797928693f2d47f20913b6777. --- 3.0/modules/rawphoto/views/admin_rawphoto.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index eadec8f9..71e2f699 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -15,7 +15,7 @@

%path.", array("path" => $dcraw->path)) ?>

-

error) ?>

+

error ?>

@@ -28,7 +28,7 @@ array("toolkit_name" => $toolkit_name)) ?>

-

+

ICC profile', array("icc_url" => "http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?> From 078d81a5f1acbe7ccdde996a7d7a65bf592eb874 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 23 Apr 2011 16:42:13 -0600 Subject: [PATCH 06/32] Convert raw photos during an item_created event rather than a graphics rule. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 13 +++++++++++++ 3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 8 ++++---- 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 6 ------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index afcabc10..d093804f 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -18,6 +18,19 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class rawphoto_event_Core { + static function item_created($item) { + if ($item->is_photo()) { + $input_file = $item->file_path(); + $output_file = tempnam(TMPPATH, "rawphoto-") . ".jpg"; + $success = rawphoto_graphics::convert($input_file, $output_file); + if ($success) { + $item->set_data_file($output_file); + $item->save(); + unlink($output_file); + } + } + } + static function admin_menu($menu, $theme) { $menu->get("settings_menu") ->append(Menu::factory("link") diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 58387fd8..550b3c36 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -96,11 +96,11 @@ class rawphoto_graphics { exec($cmd, $output, $return_var); // Failure is common, because dcraw will abort unless the original image is a raw photo. $success = ($return_var == 0); + if (!$success) { + @unlink($output_file); + } } } - if (!$success) { - // Make sure the unmodified output file exists where it's expected to be. - copy($input_file, $output_file); - } + return $success; } } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 12709cfa..73ab31f2 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -23,17 +23,11 @@ class rawphoto_installer { } static function activate() { - foreach (array("thumb", "resize") as $target) { - graphics::add_rule("rawphoto", $target, "rawphoto_graphics::convert", array(), 10); - } $toolkit_id = module::get_var("gallery", "graphics_toolkit"); rawphoto_graphics::report_ppm_support($toolkit_id); } static function deactivate() { - foreach (array("thumb", "resize") as $target) { - graphics::remove_rule("rawphoto", $target, "rawphoto_graphics::convert"); - } site_status::clear("rawphoto_needs_ppm_support"); } } From c39fc9a7ffedd6c0f9c14e71d11989ac1b491e58 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 23 Apr 2011 21:20:47 -0600 Subject: [PATCH 07/32] Use the system::tempnam substitute so that extensions are handled safely. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index d093804f..8c612bd0 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -21,7 +21,7 @@ class rawphoto_event_Core { static function item_created($item) { if ($item->is_photo()) { $input_file = $item->file_path(); - $output_file = tempnam(TMPPATH, "rawphoto-") . ".jpg"; + $output_file = system::tempnam(TMPPATH, "rawphoto-", ".jpg"); $success = rawphoto_graphics::convert($input_file, $output_file); if ($success) { $item->set_data_file($output_file); From dd6c9f2298cf5108e8226468322de8ef2a5d2c70 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 23 Apr 2011 22:52:43 -0600 Subject: [PATCH 08/32] Update a deprecated method and poor preg syntax so that the Keep Original module will work. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 8febcb35..a5c29d3f 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -26,7 +26,7 @@ class keeporiginal_event_Core { // Figure out where the original copy should be stashed at. $temp_path = str_replace(VARPATH . "albums/", "", $input_file); $original_image = VARPATH . "original/" . $temp_path; - $individual_dirs = split("[/\]", "original/" . $temp_path); + $individual_dirs = preg_split("|[/\\\\]|", "original/" . $temp_path); // If any original file does not already exist, then create a folder structure // similar to that found in VARPATH/albums/ and copy the photo over before // rotating it. From e3db324d20e0f2c2fc9e0692d404520062d50851 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 23 Apr 2011 23:12:35 -0600 Subject: [PATCH 09/32] Extend the Keep Original module so that it is triggered by updated data files. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index a5c29d3f..b026aee1 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -20,7 +20,10 @@ class keeporiginal_event_Core { static function graphics_rotate($input_file, $output_file, $options) { // Make a copy of the original fullsized image before rotating it. + self::preserve($input_file); + } + static function preserve($input_file) { // If $input_file is located in VARPATH/albums/ then assume its a fullsize photo. if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) { // Figure out where the original copy should be stashed at. @@ -71,6 +74,9 @@ class keeporiginal_event_Core { // VARPATH/original/ as well. if ($old->is_photo() || $old->is_album()) { + if (isset($new->data_file)) { + self::preserve($old->file_path()); + } if ($old->file_path() != $new->file_path()) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path()); $new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $new->file_path()); From 79f0bc872ec5ca7856cc6226b1c5b423887f68ba Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sun, 24 Apr 2011 08:10:22 -0600 Subject: [PATCH 10/32] Use the new get_data_file() helper instead of reaching inside the item. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index b026aee1..982eb808 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -74,8 +74,9 @@ class keeporiginal_event_Core { // VARPATH/original/ as well. if ($old->is_photo() || $old->is_album()) { - if (isset($new->data_file)) { - self::preserve($old->file_path()); + $data_file = $new->get_data_file(); + if (isset($data_file)) { + self::preserve($old->file_path()); } if ($old->file_path() != $new->file_path()) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path()); From ab93a47867ddcfa19de06b21008faaa4858f4cee Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sun, 24 Apr 2011 08:22:32 -0600 Subject: [PATCH 11/32] Mark an internal helper method as private. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 982eb808..5652bee6 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -20,10 +20,10 @@ class keeporiginal_event_Core { static function graphics_rotate($input_file, $output_file, $options) { // Make a copy of the original fullsized image before rotating it. - self::preserve($input_file); + self::_preserve($input_file); } - static function preserve($input_file) { + static function _preserve($input_file) { // If $input_file is located in VARPATH/albums/ then assume its a fullsize photo. if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) { // Figure out where the original copy should be stashed at. @@ -76,7 +76,7 @@ class keeporiginal_event_Core { if ($old->is_photo() || $old->is_album()) { $data_file = $new->get_data_file(); if (isset($data_file)) { - self::preserve($old->file_path()); + self::_preserve($old->file_path()); } if ($old->file_path() != $new->file_path()) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path()); From add2406b9b5004edfc5aa5203dc8c2997231599f Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sun, 24 Apr 2011 08:53:42 -0600 Subject: [PATCH 12/32] Add a TODO to point out that the original's extension shouldn't be changed. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 5652bee6..513cb606 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -112,6 +112,7 @@ class keeporiginal_event_Core { } // Move the file to its new location. + // TODO: If the files have different extensions, then the old extension should be preserved. @rename($old_original, $new_original); } } @@ -135,4 +136,4 @@ class keeporiginal_event_Core { } } } -} \ No newline at end of file +} From 7b8ceac55852ca51c1ba214ff9fd7059820e5336 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sun, 24 Apr 2011 10:00:37 -0600 Subject: [PATCH 13/32] Warn the user if they are using the Raw Photos module but not the Keep Original module. --- 3.0/modules/rawphoto/controllers/admin_rawphoto.php | 1 + 3.0/modules/rawphoto/views/admin_rawphoto.html.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php index 8935f1a5..c2e1bfb6 100644 --- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -25,6 +25,7 @@ class Admin_RawPhoto_Controller extends Admin_Controller { private function _get_view($errors = array(), $icc_path = null) { $view = new Admin_View("admin.html"); $view->content = new View("admin_rawphoto.html"); + $view->content->is_keeporiginal_active = module::is_active("keeporiginal"); $view->content->dcraw = rawphoto_graphics::detect_dcraw(); $toolkit_names = array("imagemagick" => "ImageMagick", "graphicsmagick" => "GraphicsMagick"); diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index 71e2f699..dc71d229 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -9,6 +9,13 @@ array("raw_url" => "http://www.adamcoupe.com/whitepapers/photography_technique_benefits_of_shooting_in_raw.htm", "dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")) ?>

+ +

+ activate the Keep Original module.', + array("modules_url" => url::site("admin/modules"))) ?> +

+
installed): ?> From e1a15fbff39a722bc6cc06fff365824e64782a4b Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Mon, 25 Apr 2011 20:19:18 -0600 Subject: [PATCH 14/32] Fill in the extra new fields for the module info. --- 3.0/modules/rawphoto/module.info | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/3.0/modules/rawphoto/module.info b/3.0/modules/rawphoto/module.info index 04d47d36..1bc8960c 100644 --- a/3.0/modules/rawphoto/module.info +++ b/3.0/modules/rawphoto/module.info @@ -1,3 +1,7 @@ name = "Raw Photos" description = "Use raw photos produced by a digital camera." version = 1 +author_name = "Chad Parry" +author_url = "http://codex.gallery2.org/User:Chadparry" +info_url = "http://codex.gallery2.org/Gallery3:Modules:rawphoto" +discuss_url = "http://gallery.menalto.com/node/101817" From 9796ea6ac832a3f51e29a940fc3ce0f969f86a87 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Mon, 25 Apr 2011 20:33:11 -0600 Subject: [PATCH 15/32] Add a site status warning for when dcraw is not installed. --- 3.0/modules/rawphoto/controllers/admin_rawphoto.php | 5 ++++- 3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 11 +++++++++++ 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php index c2e1bfb6..d5a315bf 100644 --- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -23,10 +23,13 @@ class Admin_RawPhoto_Controller extends Admin_Controller { } private function _get_view($errors = array(), $icc_path = null) { + $dcraw = rawphoto_graphics::detect_dcraw(); + rawphoto_graphics::report_dcraw_support($dcraw); + $view = new Admin_View("admin.html"); $view->content = new View("admin_rawphoto.html"); $view->content->is_keeporiginal_active = module::is_active("keeporiginal"); - $view->content->dcraw = rawphoto_graphics::detect_dcraw(); + $view->content->dcraw = $dcraw; $toolkit_names = array("imagemagick" => "ImageMagick", "graphicsmagick" => "GraphicsMagick"); $toolkit_id = module::get_var("gallery", "graphics_toolkit"); diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 550b3c36..2406e384 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -44,6 +44,17 @@ class rawphoto_graphics { "graphicsmagick" => "GraphicsMagick"); } + static function report_dcraw_support($dcraw) { + if ($dcraw->installed) { + site_status::clear("rawphoto_needs_dcraw"); + } else { + site_status::warning( + t('The Raw Photos module requires the dcraw tool to be installed.', + array("dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")), + "rawphoto_needs_dcraw"); + } + } + static function report_ppm_support($toolkit_id) { if (array_key_exists($toolkit_id, self::get_supported_toolkits())) { site_status::clear("rawphoto_needs_ppm_support"); diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 73ab31f2..f0e9d358 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -23,11 +23,14 @@ class rawphoto_installer { } static function activate() { + $dcraw = rawphoto_graphics::detect_dcraw() + rawphoto_graphics::report_dcraw_support($dcraw); $toolkit_id = module::get_var("gallery", "graphics_toolkit"); rawphoto_graphics::report_ppm_support($toolkit_id); } static function deactivate() { + site_status::clear("rawphoto_needs_dcraw"); site_status::clear("rawphoto_needs_ppm_support"); } } From dcc3fb9f59a136dd7f039864685667aa201f0f9a Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 27 Apr 2011 20:50:59 -0600 Subject: [PATCH 16/32] Remove a newline at the end of the file that I accidentally introduced. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 513cb606..8ea7b808 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -136,4 +136,4 @@ class keeporiginal_event_Core { } } } -} +} \ No newline at end of file From 89775a6774bd7707c5d62a930f107c491862e3b0 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 30 Apr 2011 16:09:29 -0600 Subject: [PATCH 17/32] Change the name of the extensions helper to legal_file. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index 8c612bd0..db0bf4e8 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -39,7 +39,7 @@ class rawphoto_event_Core { ->url(url::site("admin/rawphoto"))); } - static function upload_extensions($extensions_wrapper) { + static function legal_file_extensions($extensions_wrapper) { array_push($extensions_wrapper->extensions, "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); From 3a90b862fa5b7b8bbe0ad19be623d1daaaea2f9a Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 30 Apr 2011 16:41:43 -0600 Subject: [PATCH 18/32] The signature of system::tempname changed. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index db0bf4e8..84429858 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -21,7 +21,7 @@ class rawphoto_event_Core { static function item_created($item) { if ($item->is_photo()) { $input_file = $item->file_path(); - $output_file = system::tempnam(TMPPATH, "rawphoto-", ".jpg"); + $output_file = system::temp_filename("rawphoto-", "jpg"); $success = rawphoto_graphics::convert($input_file, $output_file); if ($success) { $item->set_data_file($output_file); From a7ab4452c714a22acd3f74a82d5fcf61efa9668d Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 30 Apr 2011 18:11:39 -0600 Subject: [PATCH 19/32] The data_file field is public, so we don't need to use an accessor method. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 8ea7b808..dcae2b83 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -74,7 +74,7 @@ class keeporiginal_event_Core { // VARPATH/original/ as well. if ($old->is_photo() || $old->is_album()) { - $data_file = $new->get_data_file(); + $data_file = $new->data_file; if (isset($data_file)) { self::_preserve($old->file_path()); } @@ -136,4 +136,4 @@ class keeporiginal_event_Core { } } } -} \ No newline at end of file +} From 4c4e4ef8f20d28d3a748bbe12a6b4849aba78c0b Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 4 May 2011 17:59:30 -0600 Subject: [PATCH 20/32] Avoid "self::" because Kohana can't override it. --- 3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 2406e384..f415cacd 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -56,7 +56,7 @@ class rawphoto_graphics { } static function report_ppm_support($toolkit_id) { - if (array_key_exists($toolkit_id, self::get_supported_toolkits())) { + if (array_key_exists($toolkit_id, rawphoto_graphics::get_supported_toolkits())) { site_status::clear("rawphoto_needs_ppm_support"); } else { site_status::warning( @@ -69,7 +69,7 @@ class rawphoto_graphics { static function convert($input_file, $output_file) { $success = false; - $dcraw = self::detect_dcraw(); + $dcraw = rawphoto_graphics::detect_dcraw(); if ($dcraw->installed) { // Use dcraw to convert from a raw image to a standard pixmap. $cmd = escapeshellcmd($dcraw->path) . " -c -w -W -t 0 "; From cf8e4656fccc34e1e2ab9fa384760d57aa8d679e Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 5 May 2011 21:27:39 -0600 Subject: [PATCH 21/32] Add a missing semicolon pointed out by @floridave. --- 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index f0e9d358..21d7b30b 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -23,7 +23,7 @@ class rawphoto_installer { } static function activate() { - $dcraw = rawphoto_graphics::detect_dcraw() + $dcraw = rawphoto_graphics::detect_dcraw(); rawphoto_graphics::report_dcraw_support($dcraw); $toolkit_id = module::get_var("gallery", "graphics_toolkit"); rawphoto_graphics::report_ppm_support($toolkit_id); From 5de3500fcf26cc1cce390ec338e3ab49a4b40afb Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 18 May 2011 20:31:14 -0600 Subject: [PATCH 22/32] Handle the new legal_file events. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index 84429858..a306e289 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -39,12 +39,16 @@ class rawphoto_event_Core { ->url(url::site("admin/rawphoto"))); } - static function legal_file_extensions($extensions_wrapper) { + static function legal_photo_extensions($extensions_wrapper) { array_push($extensions_wrapper->extensions, "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); } + static function legal_photo_types($types_wrapper) { + array_push($types_wrapper->types, "image/tiff"); + } + static function graphics_toolkit_change($toolkit_id) { rawphoto_graphics::report_ppm_support($toolkit_id); } From bb9715a293d5baa5d3fc78ee3fa63d3a9a77b65b Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 9 Jun 2011 21:00:28 -0600 Subject: [PATCH 23/32] Some versions of dcraw emit usage info to stderr instead of stdout. Also, italicize dcraw and module titles. --- .../rawphoto/helpers/rawphoto_graphics.php | 27 ++++++++++--------- .../rawphoto/views/admin_rawphoto.html.php | 6 ++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index f415cacd..121856e5 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -23,18 +23,19 @@ class rawphoto_graphics { $path = system::find_binary("dcraw"); if (empty($path)) { $dcraw->installed = false; - $dcraw->error = t("The dcraw tool could not be located on your system."); + $dcraw->error = t("The dcraw tool could not be located on your system."); + } else if (!@is_file($path)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, but PHP's " . + "open_basedir restriction prevents Gallery from using it."); + } else if (!preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', + shell_exec(escapeshellcmd($path) . " 2>&1"), $matches)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, but the version is not recognized."); } else { - if (@is_file($path) && preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', - shell_exec($path), $matches)) { - $dcraw->installed = true; - $dcraw->path = $path; - $dcraw->version = $matches[1]; - } else { - $dcraw->installed = false; - $dcraw->error = t("The dcraw tool is installed, but PHP's open_basedir restriction " . - "prevents Gallery from using it."); - } + $dcraw->installed = true; + $dcraw->path = $path; + $dcraw->version = $matches[1]; } return $dcraw; } @@ -49,7 +50,7 @@ class rawphoto_graphics { site_status::clear("rawphoto_needs_dcraw"); } else { site_status::warning( - t('The Raw Photos module requires the dcraw tool to be installed.', + t('The Raw Photos module requires the dcraw tool to be installed.', array("dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")), "rawphoto_needs_dcraw"); } @@ -60,7 +61,7 @@ class rawphoto_graphics { site_status::clear("rawphoto_needs_ppm_support"); } else { site_status::warning( - t('The Raw Photos module requires a supporting graphics toolkit. ' . + t('The Raw Photos module requires a supporting graphics toolkit. ' . 'Activate either ImageMagick or GraphicsMagick.', array("activate_url" => url::site("admin/graphics"))), "rawphoto_needs_ppm_support"); diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index dc71d229..86445d5d 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -4,7 +4,7 @@

Raw photo processing depends on the ' . - 'dcraw tool, which must be installed separately. ' . + 'dcraw tool, which must be installed separately. ' . 'It also depends on either the ImageMagick or GraphicsMagick graphics toolkits.', array("raw_url" => "http://www.adamcoupe.com/whitepapers/photography_technique_benefits_of_shooting_in_raw.htm", @@ -12,14 +12,14 @@

activate the Keep Original module.', + 'activate the Keep Original module.', array("modules_url" => url::site("admin/modules"))) ?>

installed): ?> -

%path.", +

dcraw tool was detected at %path.", array("path" => $dcraw->path)) ?>

error ?>

From 8ad55995aefbeae84c068f734ec9746d33312fc5 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 9 Jun 2011 22:10:53 -0600 Subject: [PATCH 24/32] Selectively omit dcraw options that would not be supported by the currently installed version. --- .../rawphoto/controllers/admin_rawphoto.php | 12 +++++-- .../rawphoto/helpers/rawphoto_graphics.php | 34 ++++++++++++------- .../rawphoto/views/admin_rawphoto.html.php | 5 +-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php index d5a315bf..0cf169f9 100644 --- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -60,9 +60,15 @@ class Admin_RawPhoto_Controller extends Admin_Controller { } public function _validate_icc_path(Validation $post, $field) { - if (!empty($post->$field) && !@is_file($post->$field)) { - $post->add_error($field, t("No ICC profile exists at the location %icc_path", - array("icc_path" => $post->$field))); + if (!empty($post->$field)) { + if (!@is_file($post->$field)) { + $post->add_error($field, t("No ICC profile exists at the location %icc_path", + array("icc_path" => $post->$field))); + } + $dcraw = rawphoto_graphics::detect_dcraw(); + if (version_compare($dcraw->version, "8.00", "<")) { + $post->add_error($field, t("Versions of dcraw before 8.00 do not support an ICC profile")); + } } } } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 121856e5..4a8da2ae 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -24,18 +24,22 @@ class rawphoto_graphics { if (empty($path)) { $dcraw->installed = false; $dcraw->error = t("The dcraw tool could not be located on your system."); - } else if (!@is_file($path)) { - $dcraw->installed = false; - $dcraw->error = t("The dcraw tool is installed, but PHP's " . - "open_basedir restriction prevents Gallery from using it."); - } else if (!preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', - shell_exec(escapeshellcmd($path) . " 2>&1"), $matches)) { - $dcraw->installed = false; - $dcraw->error = t("The dcraw tool is installed, but the version is not recognized."); } else { - $dcraw->installed = true; $dcraw->path = $path; - $dcraw->version = $matches[1]; + if (!@is_file($path)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, " . + "but PHP's open_basedir restriction " . + "prevents Gallery from using it."); + } else if (!preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', + shell_exec(escapeshellcmd($path) . " 2>&1"), $matches)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, " . + "but the version is not recognized."); + } else { + $dcraw->version = $matches[1]; + $dcraw->installed = true; + } } return $dcraw; } @@ -73,9 +77,15 @@ class rawphoto_graphics { $dcraw = rawphoto_graphics::detect_dcraw(); if ($dcraw->installed) { // Use dcraw to convert from a raw image to a standard pixmap. - $cmd = escapeshellcmd($dcraw->path) . " -c -w -W -t 0 "; + $cmd = escapeshellcmd($dcraw->path) . " -c -w "; + if (version_compare($dcraw->version, "6.00", ">=")) { + $cmd .= "-t 0 "; + } + if (version_compare($dcraw->version, "8.81", ">=")) { + $cmd .= "-W "; + } $icc_path = module::get_var("rawphoto", "icc_path"); - if (!empty($icc_path)) { + if (!empty($icc_path) && version_compare($dcraw->version, "8.00", ">=")) { $cmd .= "-p " . escapeshellarg($icc_path) . " "; } $cmd .= escapeshellarg($input_file); diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php index 86445d5d..93b92e0b 100644 --- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -19,8 +19,9 @@
installed): ?> -

dcraw tool was detected at %path.", - array("path" => $dcraw->path)) ?>

+

dcraw tool was detected at %path " . + "with version %version.", + array("path" => $dcraw->path, "version" => $dcraw->version)) ?>

error ?>

From 190b5e019f9b142e0018e906524988a68d90c018 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 9 Jun 2011 22:13:35 -0600 Subject: [PATCH 25/32] Upgrade to version 2, since older versions of dcraw are now supported. --- 3.0/modules/rawphoto/module.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/module.info b/3.0/modules/rawphoto/module.info index 1bc8960c..ecbcfb5a 100644 --- a/3.0/modules/rawphoto/module.info +++ b/3.0/modules/rawphoto/module.info @@ -1,6 +1,6 @@ name = "Raw Photos" description = "Use raw photos produced by a digital camera." -version = 1 +version = 2 author_name = "Chad Parry" author_url = "http://codex.gallery2.org/User:Chadparry" info_url = "http://codex.gallery2.org/Gallery3:Modules:rawphoto" From 9d0d193a5751e3061c625af984ff55623fdc846f Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 27 Jul 2011 17:48:50 -0600 Subject: [PATCH 26/32] Fix the module version to match module.info --- 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 21d7b30b..5fe00e79 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -19,7 +19,7 @@ */ class rawphoto_installer { static function install() { - module::set_version("rawphoto", 1); + module::set_version("rawphoto", 2); } static function activate() { From d0a90e46b6db6a2df01f7c35429cf75250498f40 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 27 Jul 2011 20:02:16 -0600 Subject: [PATCH 27/32] Require a version of the Gallery framework that supports the new item conversion features --- .../rawphoto/helpers/rawphoto_event.php | 4 ++ .../rawphoto/helpers/rawphoto_installer.php | 2 + .../rawphoto/helpers/rawphoto_version.php | 46 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 3.0/modules/rawphoto/helpers/rawphoto_version.php diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index a306e289..be407610 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -49,6 +49,10 @@ class rawphoto_event_Core { array_push($types_wrapper->types, "image/tiff"); } + static function module_change($changes) { + rawphoto_version::report_item_conversion_support(); + } + static function graphics_toolkit_change($toolkit_id) { rawphoto_graphics::report_ppm_support($toolkit_id); } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 5fe00e79..a7efcb2e 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -23,6 +23,7 @@ class rawphoto_installer { } static function activate() { + rawphoto_version::report_item_conversion_support(); $dcraw = rawphoto_graphics::detect_dcraw(); rawphoto_graphics::report_dcraw_support($dcraw); $toolkit_id = module::get_var("gallery", "graphics_toolkit"); @@ -30,6 +31,7 @@ class rawphoto_installer { } static function deactivate() { + site_status::clear("rawphoto_needs_item_conversion_support"); site_status::clear("rawphoto_needs_dcraw"); site_status::clear("rawphoto_needs_ppm_support"); } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_version.php b/3.0/modules/rawphoto/helpers/rawphoto_version.php new file mode 100644 index 00000000..b1975970 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_version.php @@ -0,0 +1,46 @@ +=")) { + site_status::clear("rawphoto_needs_item_conversion_support"); + } else { + site_status::warning( + t("The Raw Photos module requires Gallery %version or higher.", + array("version" => rawphoto_version::MIN_RELEASE_VERSION)), + "rawphoto_needs_item_conversion_support"); + } + } else { + if (version_compare(gallery::build_number(), rawphoto_version::MIN_BUILD_NUMBER, ">=")) { + site_status::clear("rawphoto_needs_item_conversion_support"); + } else { + site_status::warning( + t("The Raw Photos module requires Gallery %version, build %build_number or higher.", + array("version" => gallery::VERSION, + "build_number" => rawphoto_version::MIN_BUILD_NUMBER)), + "rawphoto_needs_item_conversion_support"); + } + } + } +} From 9e3e3c5c27839a8ba807ca18ac4ccdb552201dcb Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 27 Jul 2011 20:03:59 -0600 Subject: [PATCH 28/32] Bump the version number to 3 --- 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 2 +- 3.0/modules/rawphoto/module.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index a7efcb2e..466c41e3 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -19,7 +19,7 @@ */ class rawphoto_installer { static function install() { - module::set_version("rawphoto", 2); + module::set_version("rawphoto", 3); } static function activate() { diff --git a/3.0/modules/rawphoto/module.info b/3.0/modules/rawphoto/module.info index ecbcfb5a..c5cfc0eb 100644 --- a/3.0/modules/rawphoto/module.info +++ b/3.0/modules/rawphoto/module.info @@ -1,6 +1,6 @@ name = "Raw Photos" description = "Use raw photos produced by a digital camera." -version = 2 +version = 3 author_name = "Chad Parry" author_url = "http://codex.gallery2.org/User:Chadparry" info_url = "http://codex.gallery2.org/Gallery3:Modules:rawphoto" From 0ea4670a9621cb38aceaae3d059c49a45fe7d43b Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Wed, 27 Jul 2011 21:14:57 -0600 Subject: [PATCH 29/32] Improve handling for more raw image types from rawsamples.ch --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index be407610..7abcd02c 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -41,12 +41,19 @@ class rawphoto_event_Core { static function legal_photo_extensions($extensions_wrapper) { array_push($extensions_wrapper->extensions, - "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", - "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); + "3fr", "arw", "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "erf", + "fff", "k25", "kdc", "mef", "mos", "mrw", "nef", "orf", "pef", "raf", "raw", + "rdc", "rw2", "sr2", "srf", "x3f"); } static function legal_photo_types($types_wrapper) { - array_push($types_wrapper->types, "image/tiff"); + array_push($types_wrapper->types, + // Most raw photos are detected as TIFF. + "image/tiff", + // Minolta raw photos are mis-detected as wireless bitmap format. + "image/vnd.wap.wbmp", + // All other raw photos have unrecognized formats. + ""); } static function module_change($changes) { From d9e54442874391f3b402b56230a45e75e2855731 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 28 Jul 2011 00:20:23 -0600 Subject: [PATCH 30/32] Remove a newline at the end of the file that I accidentally introduced again! --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index dcae2b83..56a26bcb 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -136,4 +136,4 @@ class keeporiginal_event_Core { } } } -} +} \ No newline at end of file From 3a3c3944b8424499929c3320643a222590871ac9 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 28 Jul 2011 00:41:23 -0600 Subject: [PATCH 31/32] Avoid "self::" because Kohana can't override it. --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index 56a26bcb..aa7a0f0a 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -20,7 +20,7 @@ class keeporiginal_event_Core { static function graphics_rotate($input_file, $output_file, $options) { // Make a copy of the original fullsized image before rotating it. - self::_preserve($input_file); + keeporiginal_event_Core::_preserve($input_file); } static function _preserve($input_file) { @@ -76,7 +76,7 @@ class keeporiginal_event_Core { if ($old->is_photo() || $old->is_album()) { $data_file = $new->data_file; if (isset($data_file)) { - self::_preserve($old->file_path()); + keeporiginal_event_Core::_preserve($old->file_path()); } if ($old->file_path() != $new->file_path()) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path()); @@ -136,4 +136,4 @@ class keeporiginal_event_Core { } } } -} \ No newline at end of file +} From 5c5fc5697fc86d6becd7520a995081217cc68c2b Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Thu, 28 Jul 2011 00:51:00 -0600 Subject: [PATCH 32/32] Remove a trailing newline again! --- 3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php index aa7a0f0a..f9356571 100644 --- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php +++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php @@ -136,4 +136,4 @@ class keeporiginal_event_Core { } } } -} +} \ No newline at end of file