summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-02-07 13:54:37 -0800
committerTim Almdal <tnalmdal@shaw.ca>2010-02-07 13:54:37 -0800
commit7df4d795e8c5d4b100637f0fea0ad8ef7f6aeabb (patch)
tree5fdb9d2a11f712cbff82a70e4aed19c77c5370ec /modules
parent6340d8caf2261199e029841baca66e302c861679 (diff)
parentadac97b5372322be5154996974a6496198105d16 (diff)
Merge branch 'master' of git@github.com:gallery/gallery3
Diffstat (limited to 'modules')
-rw-r--r--modules/g2_import/controllers/g2.php16
-rw-r--r--modules/g2_import/helpers/g2_import_task.php6
-rw-r--r--modules/gallery/helpers/movie.php14
-rw-r--r--modules/gallery/libraries/MY_Database.php9
-rw-r--r--modules/gallery/tests/Database_Test.php7
-rw-r--r--modules/gallery/views/user_profile.html.php3
-rw-r--r--modules/user/controllers/users.php70
7 files changed, 115 insertions, 10 deletions
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()) {
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();
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() {
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")
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 @@
<a class="g-button ui-icon-right ui-state-default ui-corner-all g-dialog-link" href="<?= url::site("users/form_change_password/{$user->id}") ?>">
<?= t("Change password") ?>
</a>
+ <a class="g-button ui-icon-right ui-state-default ui-corner-all g-dialog-link" href="<?= url::site("users/form_change_email/{$user->id}") ?>">
+ <?= t("Change email") ?>
+ </a>
<? endif ?>
<a id="g-profile-return" class="g-button ui-icon-right ui-state-default ui-corner-all" href="#">
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);