From c7aafef85279114a8ae8855647394bb26400b3de Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 7 Jun 2009 17:48:42 -0700 Subject: Improve error handling support for corrupt images and report them appropriately in g2_import. --- modules/gallery/helpers/graphics.php | 7 +++---- modules/gallery/helpers/photo.php | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 4846fa8a..25eb0891 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -166,12 +166,11 @@ class graphics_Core { $item->resize_dirty = 0; } $item->save(); - } catch (Kohana_Exception $e) { + } catch (Exception $e) { // Something went wrong rebuilding the image. Leave it dirty and move on. // @todo we should handle this better. Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" . - $e->getMessage() . "\n" . - $e->getTraceAsString()); + $e->getMessage() . "\n" . $e->getTraceAsString()); return false; } @@ -192,7 +191,7 @@ class graphics_Core { } if (filesize($input_file) == 0) { - throw new Exception("@todo MALFORMED_INPUT_FILE"); + throw new Exception("@todo EMPTY_INPUT_FILE"); } $dims = getimagesize($input_file); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index c1c005f5..a4bc853b 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -53,6 +53,10 @@ class photo_Core { throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD"); } + if (filesize($filename) == 0) { + throw new Exception("@todo EMPTY_INPUT_FILE"); + } + $image_info = getimagesize($filename); // Force an extension onto the name -- cgit v1.2.3 From f0ea6d532cbbfd5a95e5b992bc62bb7ecb2c1c3b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 9 Jun 2009 21:35:35 +0800 Subject: Create a new method in MY_url.php "get_item_from_uri" which loads the item based on the uri. Then use this helper method in logout.php to insure that the guest user has access to the "continue" uri. If they don't redirect to the root album and let it deal with access issues. Signed-off-by: Tim Almdal --- modules/gallery/helpers/MY_url.php | 21 ++++++++++++++------- modules/user/controllers/logout.php | 7 ++++++- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index c8645c4d..e9a5f860 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -46,7 +46,19 @@ class url extends url_Core { return; } - $current_uri = html_entity_decode(Router::$current_uri, ENT_QUOTES); + $item = self:: get_item_from_uri(Router::$current_uri); + if ($item && $item->loaded) { + Router::$controller = "{$item->type}s"; + Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; + Router::$method = $item->id; + } + } + + /** + * Return the item that the uri is referencing + */ + static function get_item_from_uri($uri) { + $current_uri = html_entity_decode($uri); $item = ORM::factory("item")->where("relative_path_cache", $current_uri)->find(); if (!$item->loaded) { // It's possible that the relative path cache for the item we're looking for is out of date, @@ -61,12 +73,7 @@ class url extends url_Core { } } } - - if ($item && $item->loaded) { - Router::$controller = "{$item->type}s"; - Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; - Router::$method = $item->id; - } + return $item; } /** diff --git a/modules/user/controllers/logout.php b/modules/user/controllers/logout.php index 6ceb7192..a541ed9b 100644 --- a/modules/user/controllers/logout.php +++ b/modules/user/controllers/logout.php @@ -26,7 +26,12 @@ class Logout_Controller extends Controller { log::info("user", t("User %name logged out", array("name" => $user->name)), html::anchor("user/$user->id", $user->name)); if ($this->input->get("continue")) { - url::redirect($this->input->get("continue")); + $item = url::get_item_from_uri($this->input->get("continue")); + if (access::can("view", $item)) { + url::redirect($this->input->get("continue")); + } else { + url::redirect(""); + } } } } \ No newline at end of file -- cgit v1.2.3 From 8189c1fc6b655907990c7f005936a4758ab7e315 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 9 Jun 2009 21:44:08 +0800 Subject: Removed extra whitespace Signed-off-by: Tim Almdal --- modules/gallery/helpers/MY_url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index e9a5f860..7bee70ca 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -46,7 +46,7 @@ class url extends url_Core { return; } - $item = self:: get_item_from_uri(Router::$current_uri); + $item = self::get_item_from_uri(Router::$current_uri); if ($item && $item->loaded) { Router::$controller = "{$item->type}s"; Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; -- cgit v1.2.3 From d0b25445119274760af40722eaa95279c2942a89 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 9 Jun 2009 18:59:53 -0700 Subject: Check in /usr/local/bin for ffmpeg, and create the setting even if its empty (to make it easier for folks to change it in Admin > Settings > Advanced) --- modules/gallery/helpers/movie.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 3aa40dc9..986d5f62 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -142,10 +142,12 @@ class movie_Core { if (!$ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) { if (function_exists("exec")) { $ffmpeg_path = exec("which ffmpeg"); - if ($ffmpeg_path) { - module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); - } } + + if (empty($ffmpeg) && @file_exists("/usr/local/bin/ffmpeg")) { + $ffmpeg_path = "/usr/local/bin/ffmpeg"; + } + module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); } return $ffmpeg_path; } -- cgit v1.2.3 From 7ccb65ea9ebf10e35c09bbebf8ffe1118d3fb0fb Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Tue, 9 Jun 2009 19:49:06 -0700 Subject: Fix for fetching l10n plural messages. Need to cast from stdclass to array(), as I18n expects all messages to be either string or array. --- modules/gallery/helpers/l10n_client.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 33f23857..20f81ecc 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -123,7 +123,12 @@ class l10n_client_Core { $key = $message_data->key; $locale = $message_data->locale; $revision = $message_data->rev; - $translation = serialize(json_decode($message_data->translation)); + $translation = json_decode($message_data->translation); + if (!is_string($translation)) { + // Normalize stdclass to array + $translation = (array) $translation; + } + $translation = serialize($translation); // @todo Should we normalize the incoming_translations table into messages(id, key, message) // and incoming_translations(id, translation, locale, revision)? Or just allow -- cgit v1.2.3 From 5e6c8894e23239f2f34f3fb99ab76f43cbabe838 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 9 Jun 2009 20:08:48 -0700 Subject: Use a reference in available() to avoid crappy looking dereferencing. --- modules/gallery/helpers/module.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 2fd5be6c..0559ff04 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -78,10 +78,11 @@ class module_Core { foreach (glob(MODPATH . "*/module.info") as $file) { $module_name = basename(dirname($file)); $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $modules->$module_name->installed = self::is_installed($module_name); - $modules->$module_name->active = self::is_active($module_name); - $modules->$module_name->version = self::get_version($module_name); - $modules->$module_name->locked = false; + $m =& $modules->$module_name; + $m->installed = self::is_installed($module_name); + $m->active = self::is_active($module_name); + $m->version = self::get_version($module_name); + $m->locked = false; } // Lock certain modules -- cgit v1.2.3 From 00b528afac33cd4e99fd3e5e648288a9d646eb38 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 9 Jun 2009 20:32:37 -0700 Subject: Cache the available module list in module::$available. --- modules/gallery/helpers/module.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 0559ff04..58f9b20d 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -27,6 +27,7 @@ class module_Core { public static $active = array(); public static $modules = array(); public static $var_cache = null; + public static $available = array(); /** * Set the version of the corresponding Module_Model @@ -74,23 +75,27 @@ class module_Core { * Return the list of available modules, including uninstalled modules. */ static function available() { - $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (glob(MODPATH . "*/module.info") as $file) { - $module_name = basename(dirname($file)); - $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $m =& $modules->$module_name; - $m->installed = self::is_installed($module_name); - $m->active = self::is_active($module_name); - $m->version = self::get_version($module_name); - $m->locked = false; - } + if (empty(self::$available)) { + $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); + foreach (glob(MODPATH . "*/module.info") as $file) { + $module_name = basename(dirname($file)); + $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $m =& $modules->$module_name; + $m->installed = self::is_installed($module_name); + $m->active = self::is_active($module_name); + $m->code_version = $m->version; + $m->version = self::get_version($module_name); + $m->locked = false; + } - // Lock certain modules - $modules->gallery->locked = true; - $modules->user->locked = true; - $modules->ksort(); + // Lock certain modules + $modules->gallery->locked = true; + $modules->user->locked = true; + $modules->ksort(); + self::$available = $modules; + } - return $modules; + return self::$available; } /** -- cgit v1.2.3 From accce788d97d19663a4c39666de03a417b5837b6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 9 Jun 2009 21:26:28 -0700 Subject: Fix a bug in set_version() where we were always forcing the value to 1. Oops! --- modules/gallery/helpers/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 58f9b20d..dea8e22c 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -40,7 +40,7 @@ class module_Core { $module->name = $module_name; $module->active = $module_name == "gallery"; // only gallery is active by default } - $module->version = 1; + $module->version = $version; $module->save(); Kohana::log("debug", "$module_name: version is now $version"); } -- cgit v1.2.3