From ffbaa7bf82750814b6b31c8c83ee11ad25a41196 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 May 2012 21:09:26 -0700 Subject: Follow on for #1845 - handle paths with dots in them properly. --- modules/gallery/helpers/legal_file.php | 2 +- modules/gallery/tests/Legal_File_Helper_Test.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php index af6472ca..075de9cd 100644 --- a/modules/gallery/helpers/legal_file.php +++ b/modules/gallery/helpers/legal_file.php @@ -89,7 +89,7 @@ class legal_file_Core { if (strpos($filename, ".") === false) { return "{$filename}.{$new_ext}"; } else { - return preg_replace("/\..*?$/", ".{$new_ext}", $filename); + return preg_replace("/\.[^\.]*?$/", ".{$new_ext}", $filename); } } } diff --git a/modules/gallery/tests/Legal_File_Helper_Test.php b/modules/gallery/tests/Legal_File_Helper_Test.php index c101de10..6f94c9cd 100644 --- a/modules/gallery/tests/Legal_File_Helper_Test.php +++ b/modules/gallery/tests/Legal_File_Helper_Test.php @@ -29,4 +29,10 @@ class Legal_File_Helper_Test extends Gallery_Unit_Test_Case { public function change_extension_with_no_extension_test() { $this->assert_equal("foo.flv", legal_file::change_extension("foo", "flv")); } + + public function change_extension_path_containing_dots_test() { + $this->assert_equal( + "/website/foo.com/VID_20120513_105421.jpg", + legal_file::change_extension("/website/foo.com/VID_20120513_105421.mp4", "jpg")); + } } \ No newline at end of file -- cgit v1.2.3 From 1531c3898fde620abfa9e306dc6efc73e520bd1c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 14 May 2012 20:50:36 -0700 Subject: Force uploader status messages to be integers. Fixes #1863. --- modules/gallery/controllers/uploader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php index 20c10b3a..906373b6 100644 --- a/modules/gallery/controllers/uploader.php +++ b/modules/gallery/controllers/uploader.php @@ -104,8 +104,8 @@ class Uploader_Controller extends Controller { // The "errors" won't be properly pluralized :-/ print t2("Uploaded %count photo (%error errors)", "Uploaded %count photos (%error errors)", - $success_count, - array("error" => $error_count)); + (int)$success_count, + array("error" => (int)$error_count)); } else { print t2("Uploaded %count photo", "Uploaded %count photos", $success_count);} } -- cgit v1.2.3 From e3d50dd8be9cd4bdefb42f41aa6ed96b6fece676 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 14 May 2012 20:51:27 -0700 Subject: Simplify dialog title for editing advanced settings. Fixes #1864. --- modules/gallery/controllers/admin_advanced_settings.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index fd03b275..3fc48b1d 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -32,9 +32,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { public function edit($module_name, $var_name) { $value = module::get_var($module_name, $var_name); $form = new Forge("admin/advanced_settings/save/$module_name/$var_name", "", "post"); - $group = $form->group("edit_var")->label( - t("Edit %var (%module_name)", - array("module_name" => $module_name, "var" => $var_name))); + $group = $form->group("edit_var")->label(t("Edit setting")) $group->input("module_name")->label(t("Module"))->value($module_name)->disabled(1); $group->input("var_name")->label(t("Setting"))->value($var_name)->disabled(1); $group->textarea("value")->label(t("Value"))->value($value); -- cgit v1.2.3 From 6a6b3f90f36293a40cba091c3ac387abb64f3c1a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 14 May 2012 21:54:41 -0700 Subject: Verify that where() clauses are well formed. Fixes #1865. --- modules/kohana23_compat/libraries/MY_Database_Builder.php | 6 ++++++ system/libraries/Database_Builder.php | 8 ++++++++ 2 files changed, 14 insertions(+) (limited to 'modules') diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 0b9dbe28..54429ab1 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -25,6 +25,9 @@ class Database_Builder extends Database_Builder_Core { public function merge_where($tuples) { if ($tuples) { foreach ($tuples as $tuple) { + if (count($tuple) != 3) { + throw new Database_Exception("Column triplets require a column, op and value"); + } $this->where($tuple[0], $tuple[1], $tuple[2]); } } @@ -38,6 +41,9 @@ class Database_Builder extends Database_Builder_Core { public function merge_or_where($tuples) { if ($tuples) { foreach ($tuples as $tuple) { + if (count($tuple) != 3) { + throw new Database_Exception("Column triplets require a column, op and value"); + } $this->or_where($tuple[0], $tuple[1], $tuple[2]); } } diff --git a/system/libraries/Database_Builder.php b/system/libraries/Database_Builder.php index e86ce379..553ffd98 100644 --- a/system/libraries/Database_Builder.php +++ b/system/libraries/Database_Builder.php @@ -190,6 +190,8 @@ class Database_Builder_Core { { foreach ($columns as $column) { + if (count($column) != 3) + throw new Database_Exception('Column triplets require a column, op and value'); $this->where[] = array('AND' => $column); } } @@ -216,6 +218,8 @@ class Database_Builder_Core { { foreach ($columns as $column) { + if (count($column) != 3) + throw new Database_Exception('Column triplets require a column, op and value'); $this->where[] = array('OR' => $column); } } @@ -422,6 +426,8 @@ class Database_Builder_Core { { foreach ($columns as $column) { + if (count($column) != 3) + throw new Database_Exception('Column triplets require a column, op and value'); $this->having[] = array('AND' => $column); } } @@ -447,6 +453,8 @@ class Database_Builder_Core { { foreach ($columns as $column) { + if (count($column) != 3) + throw new Database_Exception('Column triplets require a column, op and value'); $this->having[] = array('OR' => $column); } } -- cgit v1.2.3 From f06c2275052f638ffaf671dda4604d3fb35dfe8c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 09:26:13 -0700 Subject: Oops dropped a semicolon in e3d50dd8be9cd4bdefb42f41aa6ed96b6fece676 --- modules/gallery/controllers/admin_advanced_settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 3fc48b1d..1ce47529 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -32,7 +32,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { public function edit($module_name, $var_name) { $value = module::get_var($module_name, $var_name); $form = new Forge("admin/advanced_settings/save/$module_name/$var_name", "", "post"); - $group = $form->group("edit_var")->label(t("Edit setting")) + $group = $form->group("edit_var")->label(t("Edit setting")); $group->input("module_name")->label(t("Module"))->value($module_name)->disabled(1); $group->input("var_name")->label(t("Setting"))->value($var_name)->disabled(1); $group->textarea("value")->label(t("Value"))->value($value); -- cgit v1.2.3 From 0d5187eadf3e19729c6aa25c3bf30d2787fd66a3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 09:33:43 -0700 Subject: Revert "Verify that where() clauses are well formed. Fixes #1865." This reverts commit 6a6b3f90f36293a40cba091c3ac387abb64f3c1a. --- modules/kohana23_compat/libraries/MY_Database_Builder.php | 6 ------ system/libraries/Database_Builder.php | 8 -------- 2 files changed, 14 deletions(-) (limited to 'modules') diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 54429ab1..0b9dbe28 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -25,9 +25,6 @@ class Database_Builder extends Database_Builder_Core { public function merge_where($tuples) { if ($tuples) { foreach ($tuples as $tuple) { - if (count($tuple) != 3) { - throw new Database_Exception("Column triplets require a column, op and value"); - } $this->where($tuple[0], $tuple[1], $tuple[2]); } } @@ -41,9 +38,6 @@ class Database_Builder extends Database_Builder_Core { public function merge_or_where($tuples) { if ($tuples) { foreach ($tuples as $tuple) { - if (count($tuple) != 3) { - throw new Database_Exception("Column triplets require a column, op and value"); - } $this->or_where($tuple[0], $tuple[1], $tuple[2]); } } diff --git a/system/libraries/Database_Builder.php b/system/libraries/Database_Builder.php index 553ffd98..e86ce379 100644 --- a/system/libraries/Database_Builder.php +++ b/system/libraries/Database_Builder.php @@ -190,8 +190,6 @@ class Database_Builder_Core { { foreach ($columns as $column) { - if (count($column) != 3) - throw new Database_Exception('Column triplets require a column, op and value'); $this->where[] = array('AND' => $column); } } @@ -218,8 +216,6 @@ class Database_Builder_Core { { foreach ($columns as $column) { - if (count($column) != 3) - throw new Database_Exception('Column triplets require a column, op and value'); $this->where[] = array('OR' => $column); } } @@ -426,8 +422,6 @@ class Database_Builder_Core { { foreach ($columns as $column) { - if (count($column) != 3) - throw new Database_Exception('Column triplets require a column, op and value'); $this->having[] = array('AND' => $column); } } @@ -453,8 +447,6 @@ class Database_Builder_Core { { foreach ($columns as $column) { - if (count($column) != 3) - throw new Database_Exception('Column triplets require a column, op and value'); $this->having[] = array('OR' => $column); } } -- cgit v1.2.3 From ce34e89c899a3fca6d647e99742c39b8b7a4f3e0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 09:50:57 -0700 Subject: Different approach to resolving #1865, this replaces 6a6b3f90f36293a40cba091c3ac387abb64f3c1a which was rolled back. --- modules/gallery/libraries/MY_ORM.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index d4cdedb8..ac61e75b 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -18,6 +18,17 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class ORM extends ORM_Core { + + /** + * Make sure that we're only using integer ids. + */ + static function factory($model, $id=null) { + if ($id && !is_int($id)) { + throw new Exception("@todo ORM::factory requires integer ids"); + } + return ORM_Core::factory($model, $id); + } + public function save() { model_cache::clear(); return parent::save(); -- cgit v1.2.3 From 3d03ea697f18d6e779ac88024f5e6a12bff6788f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 10:50:21 -0700 Subject: Follow-on to ce34e89c899a3fca6d647e99742c39b8b7a4f3e0 for #1865 - allow strings and coerce them to integers. It might be easier to just cast whatever comes in, but I'm worried that we'll accidentally cast an array to an int(1) without realizing it. --- modules/gallery/libraries/MY_ORM.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index ac61e75b..4194162b 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -23,10 +23,10 @@ class ORM extends ORM_Core { * Make sure that we're only using integer ids. */ static function factory($model, $id=null) { - if ($id && !is_int($id)) { + if ($id && !is_int($id) && !is_string($id)) { throw new Exception("@todo ORM::factory requires integer ids"); } - return ORM_Core::factory($model, $id); + return ORM_Core::factory($model, (int) $id); } public function save() { -- cgit v1.2.3 From 3caf3cc323cd25b002aa8e44d871d4677da7a029 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 10:54:18 -0700 Subject: Harden installer against bad characters in the database name or prefix. Fixes #1866. --- installer/database_config.php | 2 +- installer/installer.php | 2 +- installer/web.php | 7 +++++++ modules/gallery/libraries/MY_Database.php | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/installer/database_config.php b/installer/database_config.php index a5dc8865..fb7dd112 100644 --- a/installer/database_config.php +++ b/installer/database_config.php @@ -31,7 +31,7 @@ $config['default'] = array( 'connection' => array( 'type' => '', 'user' => '', - 'pass' => '', + 'pass' => '', 'host' => '', 'port' => '' false, 'socket' => false, diff --git a/installer/installer.php b/installer/installer.php index decc5629..339a02fd 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -183,7 +183,7 @@ class installer { } static function prepend_prefix($prefix, $sql) { - return preg_replace("#{([a-zA-Z0-9_]+)}#", "{$prefix}$1", $sql); + return preg_replace("#{([a-zA-Z0-9_]+)}#", "`{$prefix}$1`", $sql); } static function check_environment() { diff --git a/installer/web.php b/installer/web.php index 6102f0e0..12f42d02 100644 --- a/installer/web.php +++ b/installer/web.php @@ -39,6 +39,13 @@ if (installer::already_installed()) { "prefix" => $_POST["prefix"], "type" => function_exists("mysqli_set_charset") ? "mysqli" : "mysql"); list ($config["host"], $config["port"]) = explode(":", $config["host"] . ":"); + foreach ($config as $k => $v) { + if ($k == "password") { + $config[$k] = str_replace("'", "\\'", $v); + } else { + $config[$k] = strtr($v, "'`", "__"); + } + } if (!installer::connect($config)) { $content = render("invalid_db_info.html.php"); diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index f3cace4d..fb54bfcd 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -65,14 +65,14 @@ abstract class Database extends Database_Core { $open_brace = strpos($sql, "TO {") + 4; $close_brace = strpos($sql, "}", $open_brace); $name = substr($sql, $open_brace, $close_brace - $open_brace); - $this->_table_names["{{$name}}"] = "{$prefix}$name"; + $this->_table_names["{{$name}}"] = "`{$prefix}$name`"; } if (!isset($this->_table_names)) { // This should only run once on the first query $this->_table_names = array(); foreach($this->list_tables() as $table_name) { - $this->_table_names["{{$table_name}}"] = $prefix . $table_name; + $this->_table_names["{{$table_name}}"] = "`{$prefix}{$table_name}`"; } } -- cgit v1.2.3 From aac18ef8339054e134fa3e52788a80e6907dfba5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 15:53:38 -0700 Subject: Don't allow new albums with a slug that matches a controller - put up a message telling the user that it's a reserved address. Partial fix for #95. --- modules/gallery/helpers/album.php | 4 ++++ modules/gallery/models/item.php | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'modules') diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 23d59eea..0945e4d9 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -39,6 +39,8 @@ class album_Core { ->error_messages("length", t("Your directory name is too long")) ->error_messages("conflict", t("There is already a movie, photo or album with this name")); $group->input("slug")->label(t("Internet Address")) + ->error_messages( + "reserved", t("This address is reserved and can't be used.")) ->error_messages( "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")) @@ -75,6 +77,8 @@ class album_Core { $group->input("slug")->label(t("Internet Address"))->value($parent->slug) ->error_messages( "conflict", t("There is already a movie, photo or album with this internet address")) + ->error_messages( + "reserved", t("This address is reserved and can't be used.")) ->error_messages( "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")) diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 98a2c4df..992af0cc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -833,6 +833,11 @@ class Item_Model_Core extends ORM_MPTT { $v->add_error("name", "conflict"); return; } + + if ($this->parent_id == 1 && Kohana::auto_load("{$this->slug}_Controller")) { + $v->add_error("slug", "reserved"); + return; + } } /** -- cgit v1.2.3 From 891652b233df120464d8fe7d3ca80c5091681dea Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 16:00:46 -0700 Subject: Send back form errors wrapped in JSON. Fixes #1867. --- modules/gallery/controllers/albums.php | 2 +- modules/tag/controllers/admin_tags.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index b2ec0700..9b968871 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -133,7 +133,7 @@ class Albums_Controller extends Items_Controller { json::reply(array("result" => "success", "location" => $album->url())); } else { - print $form; + json::reply(array("result" => "error", "html" => (string)$form)); } } diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index ff69ad94..515b6891 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -58,7 +58,7 @@ class Admin_Tags_Controller extends Admin_Controller { json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - print $form; + json::reply(array("result" => "error", "html" => (string)$form)); } } -- cgit v1.2.3 From ce209b9eaac301b8494d7d6faa72d013ed1c6cb9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 May 2012 16:10:49 -0700 Subject: Fix a typo leading to notification module not sending any text. Fixes #1862. --- modules/notification/helpers/notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 0d66e6db..8ece698e 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -174,7 +174,7 @@ class notification { ->subject($pending->subject) ->header("Mime-Version", "1.0") ->header("Content-Type", "text/html; charset=UTF-8") - ->message($pending->body) + ->message($pending->text) ->send(); $pending->delete(); } else { -- cgit v1.2.3 From 99af395a01edac438cef4e42af1f4c26a3532acc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 May 2012 11:07:26 -0700 Subject: Force the error page to UTF-8. Fixes #1868. --- modules/gallery/views/error_admin.html.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules') diff --git a/modules/gallery/views/error_admin.html.php b/modules/gallery/views/error_admin.html.php index a391746e..96e7bf51 100644 --- a/modules/gallery/views/error_admin.html.php +++ b/modules/gallery/views/error_admin.html.php @@ -3,6 +3,7 @@ +