From 7232b6c026c3fe371b6846a8a4536a1b661804c4 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Sat, 6 Feb 2010 16:29:51 -0800 Subject: Fixing G2 url mapping for G2 default style URLs (where ShowItem and DownloadItem URLs aren't rewritten in G2). Note: For a perfect solution, we should add 2 map entries for each of G2's ShowItem and DownloadItem URLs, one for short and one for long style URLs. E.g. A G2 installation might have been using short style URLs not for its complete lifetime. And long style URLs are supposed to work in G2 even when short style URLs are enabled (and its used that way in bbcode / as a way to get permenant, id based URLs from G2). --- modules/g2_import/controllers/g2.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index 8260cf9f..347da649 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -35,15 +35,25 @@ class G2_Controller extends Controller { $id = $input->get("g2_itemId"); if ($id) { - $where = array("g2_id", "=", $id); + // Requests by id are either core.DownloadItem or + // core.ShowItem requests. + // Later versions of Gallery 2 don't specify g2_view if + // it's the default (core.ShowItem). + // And in some cases (bbcode, embedding) people are using + // the id style URLs although URL rewriting is enabled. + $where = array(array("g2_id", "=", $id)); + $view = $input->get("g2_view"); + if ($view) { + $where[] = array("g2_url", "like", "%g2_view=$view%"); + } // else: Assuming that the first search hit is sufficiently good. } else if ($path) { - $where = array("g2_url", "=", $path); + $where = array(array("g2_url", "=", $path)); } else { throw new Kohana_404_Exception(); } $g2_map = ORM::factory("g2_map") - ->merge_where(array($where)) + ->merge_where($where) ->find(); if (!$g2_map->loaded()) { -- cgit v1.2.3 From 163391ee391627f9c2b4eac359104809e2706a9b Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Sat, 6 Feb 2010 17:43:33 -0800 Subject: Partial fix for ticket 585: Require current password when changing an account's email address. Still leaving the user/group admin page wide open though. --- modules/gallery/views/user_profile.html.php | 3 ++ modules/user/controllers/users.php | 70 ++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/views/user_profile.html.php b/modules/gallery/views/user_profile.html.php index 78e1c579..1c3e4ea2 100644 --- a/modules/gallery/views/user_profile.html.php +++ b/modules/gallery/views/user_profile.html.php @@ -63,6 +63,9 @@ id}") ?>"> + id}") ?>"> + + diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 166ff8b2..83adc354 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -28,7 +28,6 @@ class Users_Controller extends Controller { try { $valid = $form->validate(); $user->full_name = $form->edit_user->full_name->value; - $user->email = $form->edit_user->email->value; $user->url = $form->edit_user->url->value; if ($user->locale != $form->edit_user->locale->value) { @@ -97,6 +96,41 @@ class Users_Controller extends Controller { } } + public function change_email($id) { + $user = user::lookup($id); + if ($user->guest || $user->id != identity::active_user()->id) { + access::forbidden(); + } + + $form = $this->_get_change_email_form($user); + try { + $valid = $form->validate(); + $user->email = $form->change_email->email->value; + $user->validate(); + } catch (ORM_Validation_Exception $e) { + // Translate ORM validation errors into form error messages + foreach ($e->validation->errors() as $key => $error) { + $form->change_email->inputs[$key]->add_error($error, 1); + } + $valid = false; + } + + if ($valid) { + $user->save(); + module::event("user_change_email_form_completed", $user, $form); + message::success(t("Email address changed")); + module::event("user_login", $user); // since there's no user_authenticated event + print json_encode( + array("result" => "success", + "resource" => url::site("users/{$user->id}"))); + } else { + log::warning("user", t("Failed email change for %name", array("name" => $user->name))); + $name = $user->name; + module::event("user_login_failed", $name); + print json_encode(array("result" => "error", "form" => (string) $form)); + } + } + public function form_edit($id) { $user = user::lookup($id); if ($user->guest || $user->id != identity::active_user()->id) { @@ -115,6 +149,15 @@ class Users_Controller extends Controller { print $this->_get_change_password_form($user); } + public function form_change_email($id) { + $user = user::lookup($id); + if ($user->guest || $user->id != identity::active_user()->id) { + access::forbidden(); + } + + print $this->_get_change_email_form($user); + } + private function _get_change_password_form($user) { $form = new Forge( "users/change_password/$user->id", "", "post", array("id" => "g-change-password-user-form")); @@ -140,16 +183,33 @@ class Users_Controller extends Controller { return $form; } + private function _get_change_email_form($user) { + $form = new Forge( + "users/change_email/$user->id", "", "post", array("id" => "g-change-email-user-form")); + $group = $form->group("change_email")->label(t("Change your email address")); + $group->password("password")->label(t("Current password"))->id("g-password") + ->callback("auth::validate_too_many_failed_password_changes") + ->callback("user::valid_password") + ->error_messages("invalid", t("Incorrect password")) + ->error_messages( + "too_many_failed_password_changes", + t("Too many incorrect passwords. Try again later")); + $group->input("email")->label(t("New email address"))->id("g-email")->value($user->email) + ->error_messages("email", t("You must enter a valid email address")) + ->error_messages("length", t("Your email address is too long")) + ->error_messages("required", t("You must enter a valid email address")); + + module::event("user_change_password_form", $user, $form); + $group->submit("")->value(t("Save")); + return $form; + } + private function _get_edit_form($user) { $form = new Forge("users/update/$user->id", "", "post", array("id" => "g-edit-user-form")); $group = $form->group("edit_user")->label(t("Edit your profile")); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name) ->error_messages("length", t("Your name is too long")); self::_add_locale_dropdown($group, $user); - $group->input("email")->label(t("Email"))->id("g-email")->value($user->email) - ->error_messages("email", t("You must enter a valid email address")) - ->error_messages("length", t("Your email address is too long")) - ->error_messages("required", t("You must enter a valid email address")); $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); module::event("user_edit_form", $user, $form); -- cgit v1.2.3 From a6170dc065856c6c4b6f69a4571fe19dee87d0ee Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Sat, 6 Feb 2010 18:37:25 -0800 Subject: Fix maintenance view for the case when g2_import is configured and the user replaced the original g2 directory with the .htaccess file only. --- modules/g2_import/helpers/g2_import_task.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 2e81adef..1ec6870e 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -23,7 +23,11 @@ class g2_import_task_Core { g2_import::lower_error_reporting(); if (g2_import::is_configured()) { g2_import::init(); - $version = g2_import::version(); + // Guard from common case where the import has been + // completed and the original files have been removed. + if (class_exists("GalleryCoreApi")) { + $version = g2_import::version(); + } } g2_import::restore_error_reporting(); -- cgit v1.2.3 From 2c3c126aafaa4d7ed86075927887636042117a1c Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Sat, 6 Feb 2010 20:07:58 -0800 Subject: Fix ticket 930: Use the first frame as video thumbnail if the video is shorter than 3 seconds. And fall back to the default thumbnail if that operation fails. Thanks to lsowen for providing a patch! --- modules/gallery/helpers/movie.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'modules') diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 7033b7da..3c494e96 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -84,6 +84,20 @@ class movie_Core { " -an -ss 00:00:03 -an -r 1 -vframes 1" . " -y -f mjpeg " . escapeshellarg($output_file) . " 2>&1"; exec($cmd); + + clearstatcache(); // use $filename parameter when PHP_version is 5.3+ + if (filesize($output_file) == 0) { + // Maybe the movie is shorter, fall back to the first frame. + $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($input_file) . + " -an -an -r 1 -vframes 1" . + " -y -f mjpeg " . escapeshellarg($output_file) . " 2>&1"; + exec($cmd); + + clearstatcache(); + if (filesize($output_file) == 0) { + throw new Exception("@todo FFMPEG_FAILED"); + } + } } static function find_ffmpeg() { -- cgit v1.2.3 From adac97b5372322be5154996974a6496198105d16 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 7 Feb 2010 08:28:32 -0800 Subject: Add prefix support for the target of RENAME TABLE. --- modules/gallery/libraries/MY_Database.php | 9 ++++++++- modules/gallery/tests/Database_Test.php | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index e2ef68cd..cb70104a 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -54,11 +54,18 @@ abstract class Database extends Database_Core { */ return $sql; } else if (strpos($sql, "CREATE TABLE") === 0) { - // Creating a new table add it to the table cache. + // Creating a new table; add it to the table cache. $open_brace = strpos($sql, "{") + 1; $close_brace = strpos($sql, "}", $open_brace); $name = substr($sql, $open_brace, $close_brace - $open_brace); $this->_table_names["{{$name}}"] = "{$prefix}$name"; + } else if (strpos($sql, "RENAME TABLE") === 0) { + // Renaming a table; add it to the table cache. + // You must use the form "TO {new_table_name}" exactly for this to work. + $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"; } if (!isset($this->_table_names)) { diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 861f7bba..730785e2 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -130,6 +130,13 @@ class Database_Test extends Gallery_Unit_Test_Case { $this->assert_same($expected, $sql); } + function prefix_replacement_for_rename_table_test() { + $db = Database::instance("mock"); + $this->assert_same( + "RENAME TABLE g_test TO g_new_test", + $db->add_table_prefixes("RENAME TABLE {test} TO {new_test}")); + } + function prefix_no_replacement_test() { $sql = db::build("mock") ->from("test_tables") -- cgit v1.2.3