From 3ec0ba956dced01a97f2ee7bd943d326c42350e3 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sat, 8 Jan 2011 19:39:23 +0100 Subject: Refactored graphics::detect_toolkits() so ImageMagick and GraphicsMagick shares the same loop. Just as premarked as todo. Will make https://sourceforge.net/apps/trac/gallery/ticket/1555#comment:3 an even quicker task --- modules/gallery/helpers/graphics.php | 76 ++++++++++++++---------------------- 1 file changed, 29 insertions(+), 47 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index edba6b76..cb48ce82 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -318,55 +318,37 @@ class graphics_Core { getenv("PATH"), module::get_var("gallery", "extra_binary_paths"))); - // @todo: consider refactoring the two segments below into a loop since they are so - // similar. - - // ImageMagick - $path = exec("which convert"); - $toolkits->imagemagick->name = "ImageMagick"; - if ($path) { - if (@is_file($path)) { - preg_match('/Version: \S+ (\S+)/', `convert -v`, $matches); - $version = $matches[1]; - - $toolkits->imagemagick->installed = true; - $toolkits->imagemagick->version = $version; - $toolkits->imagemagick->binary = $path; - $toolkits->imagemagick->dir = dirname($path); - $toolkits->imagemagick->rotate = true; - $toolkits->imagemagick->sharpen = true; - } else { - $toolkits->imagemagick->installed = false; - $toolkits->imagemagick->error = - t("ImageMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it."); - } - } else { - $toolkits->imagemagick->installed = false; - $toolkits->imagemagick->error = t("We could not locate ImageMagick on your system."); - } - - // GraphicsMagick - $path = exec("which gm"); - $toolkits->graphicsmagick->name = "GraphicsMagick"; - if ($path) { - if (@is_file($path)) { - preg_match('/\S+ (\S+)/', `gm version`, $matches); - $version = $matches[1]; - - $toolkits->graphicsmagick->installed = true; - $toolkits->graphicsmagick->version = $version; - $toolkits->graphicsmagick->binary = $path; - $toolkits->graphicsmagick->dir = dirname($path); - $toolkits->graphicsmagick->rotate = true; - $toolkits->graphicsmagick->sharpen = true; + // ImageMagick & GraphicsMagick + $magick_kits = array( + "imagemagick" => array( + "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v"), + "graphicsmagick" => array( + "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version")); + // Loop through the kits + foreach ( $magick_kits as $index => $settings ) { + $path = exec("which " . $settings["binary"]); + $toolkits->$index->name = $settings["name"]; + if ($path) { + if (@is_file($path)) { + preg_match('/Version: \S+ (\S+)/', shell_exec($settings["version"]), $matches); + $version = $matches[1]; + + $toolkits->$index->installed = true; + $toolkits->$index->version = $version; + $toolkits->$index->binary = $path; + $toolkits->$index->dir = dirname($path); + $toolkits->$index->rotate = true; + $toolkits->$index->sharpen = true; + } else { + $toolkits->$index->installed = false; + $toolkits->$index->error = + t($settings["name"] . " is installed, but PHP's open_basedir restriction prevents Gallery from using it."); + } } else { - $toolkits->graphicsmagick->installed = false; - $toolkits->graphicsmagick->error = - t("GraphicsMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it."); + $toolkits->$index->installed = false; + $toolkits->$index->error = + t("We could not locate " . $settings["name"] . " on your system."); } - } else { - $toolkits->graphicsmagick->installed = false; - $toolkits->graphicsmagick->error = t("We could not locate GraphicsMagick on your system."); } } -- cgit v1.2.3 From 7dd63630d8f7fc46847388c307ecf160a729aafb Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sat, 8 Jan 2011 19:44:46 +0100 Subject: Minor coding style fix --- modules/gallery/helpers/graphics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index cb48ce82..96a6ceba 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -325,7 +325,7 @@ class graphics_Core { "graphicsmagick" => array( "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version")); // Loop through the kits - foreach ( $magick_kits as $index => $settings ) { + foreach ($magick_kits as $index => $settings) { $path = exec("which " . $settings["binary"]); $toolkits->$index->name = $settings["name"]; if ($path) { -- cgit v1.2.3 From eecb24429115b5f1883971befe0de18ac718fc2a Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sun, 9 Jan 2011 02:06:35 +0100 Subject: Made t() calls parsable by localization scanner --- modules/gallery/helpers/graphics.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 96a6ceba..a30699e8 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -342,12 +342,14 @@ class graphics_Core { } else { $toolkits->$index->installed = false; $toolkits->$index->error = - t($settings["name"] . " is installed, but PHP's open_basedir restriction prevents Gallery from using it."); + t("%toolkit_name is installed, but PHP's open_basedir restriction prevents Gallery from using it.", + array("toolkit_name" => $settings["name"])); } } else { $toolkits->$index->installed = false; $toolkits->$index->error = - t("We could not locate " . $settings["name"] . " on your system."); + t("We could not locate %toolkit_name on your system.", + array("toolkit_name" => $settings["name"])); } } } -- cgit v1.2.3 From 0d7e951aa5f7329edb25e821de95051668789bcd Mon Sep 17 00:00:00 2001 From: Jérémy Subtil Date: Sat, 8 Jan 2011 22:57:09 +0100 Subject: Moved item_Model::get_position() method to the Item helper. It now calls the viewable() method on every query. --- modules/gallery/helpers/item.php | 85 ++++++++++++++++++++++++++++++++++++++++ modules/gallery/models/item.php | 79 ++----------------------------------- 2 files changed, 89 insertions(+), 75 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 29dd8603..a2d5f74d 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -304,4 +304,89 @@ class item_Core { ->where("rand_key", "<", random::percent()) ->order_by("rand_key", "DESC"); } + + /** + * Find the position of the given item in its parent album. The resulting + * value is 1-indexed, so the first child in the album is at position 1. + */ + static function get_position($item, $where=array()) { + $album = $item->parent(); + + if (!strcasecmp($album->sort_order, "DESC")) { + $comp = ">"; + } else { + $comp = "<"; + } + $query_model = ORM::factory("item"); + + // If the comparison column has NULLs in it, we can't use comparators on it + // and will have to deal with it the hard way. + $count = $query_model->viewable() + ->where("parent_id", "=", $album->id) + ->where($album->sort_column, "IS", null) + ->merge_where($where) + ->count_all(); + + if (empty($count)) { + // There are no NULLs in the sort column, so we can just use it directly. + $sort_column = $album->sort_column; + + $position = $query_model->viewable() + ->where("parent_id", "=", $album->id) + ->where($sort_column, $comp, $item->$sort_column) + ->merge_where($where) + ->count_all(); + + // We stopped short of our target value in the sort (notice that we're + // using a < comparator above) because it's possible that we have + // duplicate values in the sort column. An equality check would just + // arbitrarily pick one of those multiple possible equivalent columns, + // which would mean that if you choose a sort order that has duplicates, + // it'd pick any one of them as the child's "position". + // + // Fix this by doing a 2nd query where we iterate over the equivalent + // columns and add them to our base value. + foreach ($query_model->viewable() + ->select("id") + ->where("parent_id", "=", $album->id) + ->where($sort_column, "=", $item->$sort_column) + ->merge_where($where) + ->order_by(array("id" => "ASC")) + ->find_all() as $row) { + $position++; + if ($row->id == $item->id) { + break; + } + } + } else { + // There are NULLs in the sort column, so we can't use MySQL comparators. + // Fall back to iterating over every child row to get to the current one. + // This can be wildly inefficient for really large albums, but it should + // be a rare case that the user is sorting an album with null values in + // the sort column. + // + // Reproduce the children() functionality here using Database directly to + // avoid loading the whole ORM for each row. + $order_by = array($album->sort_column => $album->sort_order); + // Use id as a tie breaker + if ($album->sort_column != "id") { + $order_by["id"] = "ASC"; + } + + $position = 0; + foreach ($query_model->viewable() + ->select("id") + ->where("parent_id", "=", $album->id) + ->merge_where($where) + ->order_by($order_by) + ->find_all() as $row) { + $position++; + if ($row->id == $item->id) { + break; + } + } + } + + return $position; + } } \ No newline at end of file diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 88a444b4..47b062b8 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -546,83 +546,12 @@ class Item_Model_Core extends ORM_MPTT { /** * Find the position of the given child id in this album. The resulting value is 1-indexed, so * the first child in the album is at position 1. + * + * This method stands as a backward compatibility for gallery 3.0, and will + * be deprecated in version 3.1. */ public function get_position($child, $where=array()) { - if (!strcasecmp($this->sort_order, "DESC")) { - $comp = ">"; - } else { - $comp = "<"; - } - $db = db::build(); - - // If the comparison column has NULLs in it, we can't use comparators on it and will have to - // deal with it the hard way. - $count = $db->from("items") - ->where("parent_id", "=", $this->id) - ->where($this->sort_column, "IS", null) - ->merge_where($where) - ->count_records(); - - if (empty($count)) { - // There are no NULLs in the sort column, so we can just use it directly. - $sort_column = $this->sort_column; - - $position = $db->from("items") - ->where("parent_id", "=", $this->id) - ->where($sort_column, $comp, $child->$sort_column) - ->merge_where($where) - ->count_records(); - - // We stopped short of our target value in the sort (notice that we're using a < comparator - // above) because it's possible that we have duplicate values in the sort column. An - // equality check would just arbitrarily pick one of those multiple possible equivalent - // columns, which would mean that if you choose a sort order that has duplicates, it'd pick - // any one of them as the child's "position". - // - // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to - // our base value. - foreach ($db - ->select("id") - ->from("items") - ->where("parent_id", "=", $this->id) - ->where($sort_column, "=", $child->$sort_column) - ->merge_where($where) - ->order_by(array("id" => "ASC")) - ->execute() as $row) { - $position++; - if ($row->id == $child->id) { - break; - } - } - } else { - // There are NULLs in the sort column, so we can't use MySQL comparators. Fall back to - // iterating over every child row to get to the current one. This can be wildly inefficient - // for really large albums, but it should be a rare case that the user is sorting an album - // with null values in the sort column. - // - // Reproduce the children() functionality here using Database directly to avoid loading the - // whole ORM for each row. - $order_by = array($this->sort_column => $this->sort_order); - // Use id as a tie breaker - if ($this->sort_column != "id") { - $order_by["id"] = "ASC"; - } - - $position = 0; - foreach ($db->select("id") - ->from("items") - ->where("parent_id", "=", $this->id) - ->merge_where($where) - ->order_by($order_by) - ->execute() as $row) { - $position++; - if ($row->id == $child->id) { - break; - } - } - } - - return $position; + return item::get_position($child, $where); } /** -- cgit v1.2.3 From bd6bd029a7c2e0247d4da931c49f3731498cd303 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 10 Jan 2011 14:04:15 -0800 Subject: Fix up the version detecting regex for GraphicsMagick and don't crash if the regex doesn't return properly. Follow on to 3ec0ba956dced01a97f2ee7bd943d326c42350e3 for ticket #1595. --- modules/gallery/helpers/graphics.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index a30699e8..29527705 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -321,16 +321,18 @@ class graphics_Core { // ImageMagick & GraphicsMagick $magick_kits = array( "imagemagick" => array( - "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v"), + "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v", + "version_regex" => "/Version: \S+ (\S+)/"), "graphicsmagick" => array( - "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version")); + "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version", + "version_regex" => "/\S+ (\S+)/")); // Loop through the kits foreach ($magick_kits as $index => $settings) { $path = exec("which " . $settings["binary"]); $toolkits->$index->name = $settings["name"]; if ($path) { - if (@is_file($path)) { - preg_match('/Version: \S+ (\S+)/', shell_exec($settings["version"]), $matches); + if (@is_file($path) && + preg_match($settings["version_regex"], shell_exec($settings["version"]), $matches)) { $version = $matches[1]; $toolkits->$index->installed = true; -- cgit v1.2.3 From 23eaec7063b81d4dae04ec3f5c311a0a2f228a05 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 10 Jan 2011 15:49:15 -0800 Subject: Stop using "which" to find binaries. Create system::find_binary() which traverses the $PATH and returns any executable binary of the appropriate name that it can find. Fixes #1555. --- modules/gallery/helpers/graphics.php | 8 ++----- modules/gallery/helpers/movie.php | 14 +++++------- modules/gallery/helpers/system.php | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 modules/gallery/helpers/system.php (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 29527705..18820ed7 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -313,11 +313,6 @@ class graphics_Core { $toolkits->graphicsmagick->installed = false; $toolkits->graphicsmagick->error = t("GraphicsMagick requires the exec function"); } else { - gallery::set_path_env( - array(module::get_var("gallery", "graphics_toolkit_path"), - getenv("PATH"), - module::get_var("gallery", "extra_binary_paths"))); - // ImageMagick & GraphicsMagick $magick_kits = array( "imagemagick" => array( @@ -328,7 +323,8 @@ class graphics_Core { "version_regex" => "/\S+ (\S+)/")); // Loop through the kits foreach ($magick_kits as $index => $settings) { - $path = exec("which " . $settings["binary"]); + $path = system::find_binary( + $settings["binary"], module::get_var("gallery", "graphics_toolkit_path")); $toolkits->$index->name = $settings["name"]; if ($path) { if (@is_file($path) && diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 0895c5f4..dd0b437e 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -83,22 +83,18 @@ class movie_Core { } } + /** + * Return the path to the ffmpeg binary if one exists and is executable, or null. + */ static function find_ffmpeg() { if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) { - gallery::set_path_env( - array(module::get_var("gallery", "graphics_toolkit_path"), - getenv("PATH"), - module::get_var("gallery", "extra_binary_paths"))); - if (function_exists("exec")) { - $ffmpeg_path = exec("which ffmpeg"); - } - + $ffmpeg_path = system::find_binary( + "ffmpeg", module::get_var("gallery", "graphics_toolkit_path")); module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); } return $ffmpeg_path; } - /** * Return the width, height, mime_type and extension of the given movie file. */ diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php new file mode 100644 index 00000000..4a6a3c0f --- /dev/null +++ b/modules/gallery/helpers/system.php @@ -0,0 +1,43 @@ + Date: Tue, 11 Jan 2011 01:04:10 -0800 Subject: Don't resize if the target size is the same as the original. Fixes #1602. --- modules/gallery/helpers/gallery_graphics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php index fca18076..4cd7143e 100644 --- a/modules/gallery/helpers/gallery_graphics.php +++ b/modules/gallery/helpers/gallery_graphics.php @@ -56,7 +56,7 @@ class gallery_graphics_Core { } $dims = getimagesize($input_file); - if (max($dims[0], $dims[1]) < min($options["width"], $options["height"])) { + if (max($dims[0], $dims[1]) <= min($options["width"], $options["height"])) { // Image would get upscaled; do nothing copy($input_file, $output_file); } else { -- cgit v1.2.3 From 049f2af1c982bb12fee6e5512e4830f63d06d343 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Wed, 12 Jan 2011 00:05:11 +0100 Subject: Returning 2 flags from l10n_client::validate_api_key(), 1 to reflect if connection was built up properly (just a boolean, not distuingishing between reasons in case of a failure), the other to reflect API validating success status. Using this presenting a slightly more meaningfull error msg to user in case the connection would fail. Fixes Ticket #1504 --- modules/gallery/controllers/admin_languages.php | 11 +++++++---- modules/gallery/helpers/l10n_client.php | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index 573ededf..e9be2a88 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -74,9 +74,11 @@ class Admin_Languages_Controller extends Admin_Controller { private function _save_api_key($form) { $new_key = $form->sharing->api_key->value; - if ($new_key && !l10n_client::validate_api_key($new_key)) { - $form->sharing->api_key->add_error("invalid", 1); - $valid = false; + if ($new_key) { + list($connected, $valid) = l10n_client::validate_api_key($new_key); + if (!$valid) { + $form->sharing->api_key->add_error($connected ? "invalid" : "noconn", 1); + } } else { $valid = true; } @@ -119,7 +121,8 @@ class Admin_Languages_Controller extends Admin_Controller { array("server-link" => html::mark_clean(html::anchor($server_link)))) : t("API key")) ->value($api_key) - ->error_messages("invalid", t("The API key you provided is invalid.")); + ->error_messages("invalid", t("The API key you provided is invalid.")) + ->error_messages("noconn", t("Could not connect to remote server to validate the API key.")); $group->submit("save")->value(t("Save settings")); if ($api_key && $this->_outgoing_translations_count()) { // TODO: UI improvement: hide API key / save button when API key is set. diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 8c2685a8..2af5c8d0 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -60,10 +60,14 @@ class l10n_client_Core { "client_token" => l10n_client::client_token(), "signature" => $signature, "uid" => l10n_client::server_uid($api_key))); + if (!isset($response_data) && !isset($response_status)) { + return array(false, false); + } + if (!remote::success($response_status)) { - return false; + return array(true, false); } - return true; + return array(true, true); } /** -- cgit v1.2.3 From 92db7f42181f6582763e7b5c56b18b989b061e21 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 11 Jan 2011 15:23:20 -0800 Subject: Update some comments. --- modules/gallery/helpers/item.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index a2d5f74d..8aa14934 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -308,6 +308,9 @@ class item_Core { /** * Find the position of the given item in its parent album. The resulting * value is 1-indexed, so the first child in the album is at position 1. + * + * @param Item_Model $item + * @param array $where an array of arrays, each compatible with ORM::where() */ static function get_position($item, $where=array()) { $album = $item->parent(); @@ -338,14 +341,14 @@ class item_Core { ->count_all(); // We stopped short of our target value in the sort (notice that we're - // using a < comparator above) because it's possible that we have + // using a inequality comparator above) because it's possible that we have // duplicate values in the sort column. An equality check would just // arbitrarily pick one of those multiple possible equivalent columns, // which would mean that if you choose a sort order that has duplicates, // it'd pick any one of them as the child's "position". // // Fix this by doing a 2nd query where we iterate over the equivalent - // columns and add them to our base value. + // columns and add them to our position count. foreach ($query_model->viewable() ->select("id") ->where("parent_id", "=", $album->id) -- cgit v1.2.3 From ee53744aa73b06f262122b6236014618fe6d742c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 11 Jan 2011 16:59:57 -0800 Subject: Two improvements to Joe's fix for #1504: 1) Trap all exceptions, eg dns or connectivity issues and report back in the form (but put the stack trace in the logs) 2) Rename "noconn" to "no_connection" --- modules/gallery/controllers/admin_languages.php | 5 +++-- modules/gallery/helpers/l10n_client.php | 15 ++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index e9be2a88..f96a0eb7 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -77,7 +77,7 @@ class Admin_Languages_Controller extends Admin_Controller { if ($new_key) { list($connected, $valid) = l10n_client::validate_api_key($new_key); if (!$valid) { - $form->sharing->api_key->add_error($connected ? "invalid" : "noconn", 1); + $form->sharing->api_key->add_error($connected ? "invalid" : "no_connection", 1); } } else { $valid = true; @@ -122,7 +122,8 @@ class Admin_Languages_Controller extends Admin_Controller { : t("API key")) ->value($api_key) ->error_messages("invalid", t("The API key you provided is invalid.")) - ->error_messages("noconn", t("Could not connect to remote server to validate the API key.")); + ->error_messages( + "no_connection", t("Could not connect to remote server to validate the API key.")); $group->submit("save")->value(t("Save settings")); if ($api_key && $this->_outgoing_translations_count()) { // TODO: UI improvement: hide API key / save button when API key is set. diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 2af5c8d0..8fc66b68 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -55,11 +55,16 @@ class l10n_client_Core { $url = self::_server_url("status"); $signature = self::_sign($version, $api_key); - list ($response_data, $response_status) = remote::post( - $url, array("version" => $version, - "client_token" => l10n_client::client_token(), - "signature" => $signature, - "uid" => l10n_client::server_uid($api_key))); + try { + list ($response_data, $response_status) = remote::post( + $url, array("version" => $version, + "client_token" => l10n_client::client_token(), + "signature" => $signature, + "uid" => l10n_client::server_uid($api_key))); + } catch (ErrorException $e) { + // Log the error, but then return a "can't make connection" error + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + } if (!isset($response_data) && !isset($response_status)) { return array(false, false); } -- cgit v1.2.3 From ee13b934f46d67982e5eeea21f81ac58f166741c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 13:14:43 -0800 Subject: Fix all the head() and admin_head() theme callbacks to return the results of the $theme->css() and $theme->script() calls. This handles the case where combining scripts/css returns HTML instead of putting it in the queue for combination. Fixes #1611. --- modules/comment/helpers/comment_theme.php | 8 +++----- modules/digibug/helpers/digibug_theme.php | 2 +- modules/gallery/helpers/gallery_theme.php | 27 +++++++++++++------------ modules/recaptcha/helpers/recaptcha_theme.php | 4 ++-- modules/server_add/helpers/server_add_theme.php | 18 ++++++++--------- modules/tag/helpers/tag_theme.php | 10 ++++----- modules/user/helpers/user_theme.php | 8 ++++---- 7 files changed, 38 insertions(+), 39 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index b993cdae..9cc93fa1 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -19,14 +19,12 @@ */ class comment_theme_Core { static function head($theme) { - $theme->css("comment.css"); - $theme->script("comment.js"); - return ""; + return $theme->css("comment.css") + . $theme->script("comment.js"); } static function admin_head($theme) { - $theme->css("comment.css"); - return ""; + return $theme->css("comment.css"); } static function photo_bottom($theme) { diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index d146e17d..1106910e 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -19,6 +19,6 @@ */ class digibug_theme_Core { static function head($theme) { - $theme->script("digibug.js"); + return $theme->script("digibug.js"); } } diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 978c69a6..ebf8f38e 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,9 +21,9 @@ class gallery_theme_Core { static function head($theme) { $session = Session::instance(); $buf = ""; - $theme->css("gallery.css"); + $buf .= $theme->css("gallery.css"); if ($session->get("debug")) { - $theme->css("debug.css"); + $buf .= $theme->css("debug.css"); } if (module::is_active("rss")) { @@ -40,32 +40,33 @@ class gallery_theme_Core { if (count(locales::installed())) { // Needed by the languages block - $theme->script("jquery.cookie.js"); + $buf .= $theme->script("jquery.cookie.js"); } if ($session->get("l10n_mode", false)) { - $theme->css("l10n_client.css"); - $theme->script("jquery.cookie.js"); - $theme->script("l10n_client.js"); + $buf .= $theme->css("l10n_client.css") + . $theme->script("jquery.cookie.js") + . $theme->script("l10n_client.js"); } - $theme->css("uploadify/uploadify.css"); + $buf .= $theme->css("uploadify/uploadify.css"); return $buf; } static function admin_head($theme) { - $theme->css("gallery.css"); - $theme->script("gallery.panel.js"); + $buf = $theme->css("gallery.css"); + $buf .= $theme->script("gallery.panel.js"); $session = Session::instance(); if ($session->get("debug")) { - $theme->css("debug.css"); + $buf .= $theme->css("debug.css"); } if ($session->get("l10n_mode", false)) { - $theme->css("l10n_client.css"); - $theme->script("jquery.cookie.js"); - $theme->script("l10n_client.js"); + $buf .= $theme->css("l10n_client.css"); + $buf .= $theme->script("jquery.cookie.js"); + $buf .=$theme->script("l10n_client.js"); } + return $buf; } static function page_bottom($theme) { diff --git a/modules/recaptcha/helpers/recaptcha_theme.php b/modules/recaptcha/helpers/recaptcha_theme.php index ee880986..3677a7c7 100644 --- a/modules/recaptcha/helpers/recaptcha_theme.php +++ b/modules/recaptcha/helpers/recaptcha_theme.php @@ -19,10 +19,10 @@ */ class recaptcha_theme_Core { static function head($theme) { - $theme->css("recaptcha.css"); + return $theme->css("recaptcha.css"); } static function admin_head($theme) { - $theme->css("recaptcha.css"); + return $theme->css("recaptcha.css"); } } \ No newline at end of file diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index 53f78772..6395c2f0 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -20,24 +20,24 @@ class server_add_theme_Core { static function head($theme) { if (identity::active_user()->admin) { - $theme->css("server_add.css"); - $theme->script("server_add.js"); + return $theme->css("server_add.css") + . $theme->script("server_add.js"); } } static function admin_head($theme) { - $head = array(); + $buf = ""; if (strpos(Router::$current_uri, "admin/server_add") !== false) { - $theme->css("server_add.css"); - $theme->css("jquery.autocomplete.css"); + $buf .= $theme->css("server_add.css") + . $theme->css("jquery.autocomplete.css"); $base = url::site("__ARGS__"); $csrf = access::csrf_token(); - $head[] = ""; + $buf .= ""; - $theme->script("jquery.autocomplete.js"); - $theme->script("admin.js"); + $buf .= $theme->script("jquery.autocomplete.js") + . $theme->script("admin.js"); } - return implode("\n", $head); + return $buf; } } \ No newline at end of file diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index f731dbb7..3325a832 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -19,13 +19,13 @@ */ class tag_theme_Core { static function head($theme) { - $theme->css("jquery.autocomplete.css"); - $theme->script("jquery.autocomplete.js"); - $theme->css("tag.css"); + return $theme->css("jquery.autocomplete.css") + . $theme->script("jquery.autocomplete.js") + . $theme->css("tag.css"); } static function admin_head($theme) { - $theme->css("tag.css"); - $theme->script("gallery.in_place_edit.js"); + return $theme->css("tag.css") + . $theme->script("gallery.in_place_edit.js"); } } \ No newline at end of file diff --git a/modules/user/helpers/user_theme.php b/modules/user/helpers/user_theme.php index 5a7161ed..70e96f70 100644 --- a/modules/user/helpers/user_theme.php +++ b/modules/user/helpers/user_theme.php @@ -19,12 +19,12 @@ */ class user_theme_Core { static function head($theme) { - $theme->css("user.css"); - $theme->script("password_strength.js"); + return $theme->css("user.css") + . $theme->script("password_strength.js"); } static function admin_head($theme) { - $theme->css("user.css"); - $theme->script("password_strength.js"); + return $theme->css("user.css") + . $theme->script("password_strength.js"); } } \ No newline at end of file -- cgit v1.2.3 From 0020f87d6a23ce00200074b678a9293d055e27a3 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sat, 15 Jan 2011 21:49:22 +0100 Subject: Fixed paging for albums ordered by random. MySql has problems when comparing float values against -seemingly same- float input, see http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html for details. Fixes #1610 --- installer/install.sql | 4 ++-- modules/gallery/helpers/gallery_installer.php | 9 +++++++-- modules/gallery/module.info | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/installer/install.sql b/installer/install.sql index 0ed7f2f3..07aae36d 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -160,7 +160,7 @@ CREATE TABLE {items} ( `name` varchar(255) DEFAULT NULL, `owner_id` int(9) DEFAULT NULL, `parent_id` int(9) NOT NULL, - `rand_key` float DEFAULT NULL, + `rand_key` decimal(11,10) DEFAULT NULL, `relative_path_cache` varchar(255) DEFAULT NULL, `relative_url_cache` varchar(255) DEFAULT NULL, `resize_dirty` tinyint(1) DEFAULT '1', @@ -244,7 +244,7 @@ CREATE TABLE {modules} ( KEY `weight` (`weight`) ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -INSERT INTO {modules} VALUES (1,1,'gallery',43,1); +INSERT INTO {modules} VALUES (1,1,'gallery',44,1); INSERT INTO {modules} VALUES (2,1,'user',3,2); INSERT INTO {modules} VALUES (3,1,'comment',3,3); INSERT INTO {modules} VALUES (4,1,'organize',3,4); diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index f7b8da5f..3c7b1c84 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -92,7 +92,7 @@ class gallery_installer { `name` varchar(255) default NULL, `owner_id` int(9) default NULL, `parent_id` int(9) NOT NULL, - `rand_key` float default NULL, + `rand_key` decimal(11,10) default NULL, `relative_path_cache` varchar(255) default NULL, `relative_url_cache` varchar(255) default NULL, `resize_dirty` boolean default 1, @@ -309,7 +309,7 @@ class gallery_installer { module::set_var("gallery", "show_user_profiles_to", "registered_users"); module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); - module::set_version("gallery", 43); + module::set_version("gallery", 44); } static function upgrade($version) { @@ -653,6 +653,11 @@ class gallery_installer { $db->query("ALTER TABLE {items} CHANGE `description` `description` text DEFAULT NULL"); module::set_version("gallery", $version = 43); } + + if ($version == 43) { + $db->query("ALTER TABLE {items} CHANGE `rand_key` `rand_key` DECIMAL(11, 10)"); + module::set_version("gallery", $version = 44); + } } static function uninstall() { diff --git a/modules/gallery/module.info b/modules/gallery/module.info index eb579ab6..4c4e63a1 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 43 +version = 44 -- cgit v1.2.3 From ac44e9c930ec83545b37e1e31381919fbd849d26 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 16 Jan 2011 15:49:34 -0800 Subject: First step in setting up version checking. We now have two types of packages (release, git). Instead of using constants, we now have gallery::version_string() which returns the current version string. If you're on a release package, then the version string looks like: 3.0 (Santa Fe) If you're on a git package, then the version string looks like this: 3.0.1 (branch 3.0.x build 3) We track the build number in a new file in the gallery3 root called BUILD_NUMBER which we will update periodically with the latest build number for each branch. --- BUILD_NUMBER | 1 + modules/gallery/helpers/gallery.php | 25 +++++++++++++++++++++++- modules/gallery/helpers/gallery_theme.php | 2 +- modules/gallery/views/admin_block_stats.html.php | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 BUILD_NUMBER (limited to 'modules/gallery/helpers') diff --git a/BUILD_NUMBER b/BUILD_NUMBER new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/BUILD_NUMBER @@ -0,0 +1 @@ +1 diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 282289b5..c4a6286c 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,7 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { - const VERSION = "3.0+ (git)"; + const VERSION = "3.0+"; + const CODE_NAME = ""; + const RELEASE_CHANNEL = "git"; + const RELEASE_BRANCH = "master"; /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is @@ -184,4 +187,24 @@ class gallery_Core { } putenv("PATH=" . implode(":", $path_env)); } + + /** + * Return a string describing this version of Gallery and the type of release. + */ + static function version_string() { + if (gallery::RELEASE_CHANNEL == "git") { + return sprintf( + "%s (branch %s build %s)", gallery::VERSION, gallery::RELEASE_BRANCH, gallery::build_number()); + } else { + return sprintf("%s (%s)", gallery::VERSION, gallery::CODE_NAME); + } + } + + /** + * Return the contents of the BUILD_NUMBER file, which should be a single integer. + */ + static function build_number() { + $lines = file(DOCROOT . "BUILD_NUMBER", FILE_IGNORE_NEW_LINES); + return $lines[0]; + } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index ebf8f38e..d75c6fc6 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -115,7 +115,7 @@ class gallery_theme_Core { static function credits() { $version_string = SafeString::of_safe_html( - 'Gallery ' . gallery::VERSION . ''); + 'Gallery ' . gallery::version_string() . ''); return "
  • " . t(module::get_var("gallery", "credits"), array("url" => "http://gallery.menalto.com", diff --git a/modules/gallery/views/admin_block_stats.html.php b/modules/gallery/views/admin_block_stats.html.php index 1dec8ccd..c8c54765 100644 --- a/modules/gallery/views/admin_block_stats.html.php +++ b/modules/gallery/views/admin_block_stats.html.php @@ -1,7 +1,7 @@