From 5c0998c4ac9ad7572df68f5c2cc351f0d03a7bd2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 21 Jul 2010 07:20:24 -0700 Subject: [PATCH 01/12] Partial fix for #1225. Change the dialog and panel handling to look at the mime type returned to determine the content type. --- lib/gallery.dialog.js | 45 ++++++++++++++++++++++++++++++++----------- lib/gallery.panel.js | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index cc35f5cd44..7b9d4b94a3 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -27,19 +27,42 @@ $("#g-dialog").gallery_show_loading(); - $.getJSON(sHref, function(data) { - $("#g-dialog").html(unescape(data.form)).gallery_show_loading(); + $.ajax({ + url: sHref, + type: "GET", + beforeSend: function(xhr) { + // Until we convert to jquery 1.4, we need to save the + // XMLHttpRequest object + this.xhrData = xhr; + }, + success: function(data, textStatus, xhr) { + // Pre jquery 1.4, get the saved XMLHttpRequest object + if (xhr == undefined) { + xhr = this.xhrData; + } + var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type")); + + var content = ""; + if (mimeType[1] == "application/json") { + data = JSON.parse(data); + content = unescape(data.form); + } else { + content = data; + } - if ($("#g-dialog form").length) { - self.form_loaded(null, $("#g-dialog form")); - } - self._layout(); + $("#g-dialog").html(content).gallery_show_loading(); - $("#g-dialog").dialog("open"); - self._set_title(); + if ($("#g-dialog form").length) { + self.form_loaded(null, $("#g-dialog form")); + } + self._layout(); + + $("#g-dialog").dialog("open"); + self._set_title(); - if ($("#g-dialog form").length) { - self._ajaxify_dialog(); + if ($("#g-dialog form").length) { + self._ajaxify_dialog(); + } } }); $("#g-dialog").dialog("option", "self", self); @@ -108,7 +131,7 @@ }, success: function(data) { if (data.form) { - var formData = unescape(data.form); + var formData = unescape(data.content); $("#g-dialog form").replaceWith(formData); $("#g-dialog").dialog("option", "position", "center"); $("#g-dialog form :submit").removeClass("ui-state-disabled") diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js index b94df2238c..e219f3d647 100644 --- a/lib/gallery.panel.js +++ b/lib/gallery.panel.js @@ -31,15 +31,37 @@ if (should_open) { $(parent).after(ePanel); $("#g-panel td").html(sHref); - $.getJSON(sHref, function(data) { - $("#g-panel td").html(unescape(data.form)); - self._ajaxify_panel(); - if ($(element).attr("open_text")) { - $(element).attr("orig_text", $(element).children(".g-button-text").text()); - $(element).children(".g-button-text").text($(element).attr("open_text")); + $.ajax({ + url: sHref, + type: "GET", + beforeSend: function(xhr) { + // Until we convert to jquery 1.4, we need to save the + // XMLHttpRequest object + this.xhrData = xhr; + }, + success: function(data, textStatus, xhr) { + // Pre jquery 1.4, get the saved XMLHttpRequest object + if (xhr == undefined) { + xhr = this.xhrData; + } + var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type")); + var content = ""; + if (mimeType[1] == "application/json") { + data = JSON.parse(data); + content = unescape(data.form); + } else { + content = data; + } + + $("#g-panel td").html(content); + self._ajaxify_panel(); + if ($(element).attr("open_text")) { + $(element).attr("orig_text", $(element).children(".g-button-text").text()); + $(element).children(".g-button-text").text($(element).attr("open_text")); + } + $("#g-panel").addClass(parentClass).show().slideDown("slow"); } - $("#g-panel").addClass(parentClass).show().slideDown("slow"); - }); + }); } return false; From bb04015149f35d7ef5ef1e98e53a1659679d83d7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 21 Jul 2010 08:15:21 -0700 Subject: [PATCH 02/12] Partial fix for #1225. Create a json reply helper that sets the content type to application/json and then json encodes the reply. --- modules/gallery/helpers/json.php | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/gallery/helpers/json.php diff --git a/modules/gallery/helpers/json.php b/modules/gallery/helpers/json.php new file mode 100644 index 0000000000..5fcdc268d6 --- /dev/null +++ b/modules/gallery/helpers/json.php @@ -0,0 +1,34 @@ + Date: Wed, 21 Jul 2010 08:46:53 -0700 Subject: [PATCH 03/12] Partial fix for #1225 addresses the issues with the user edit forms. --- modules/user/controllers/admin_users.php | 36 ++++++++++++------------ modules/user/controllers/users.php | 27 ++++++++---------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 2d50de9243..64365f2b9a 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -54,14 +54,14 @@ public function add_user() { $user->save(); module::event("user_add_form_admin_completed", $user, $form); message::success(t("Created user %user_name", array("user_name" => $user->name))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } public function add_user_form() { - print json_encode(array("form" => (string) $this->_get_user_add_form_admin())); + json::reply(array("form" => (string) $this->_get_user_add_form_admin())); } public function delete_user($id) { @@ -81,13 +81,13 @@ public function delete_user($id) { $name = $user->name; $user->delete(); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } $message = t("Deleted user %user_name", array("user_name" => $name)); log::success("user", $message); message::success($message); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } public function delete_user_form($id) { @@ -95,7 +95,7 @@ public function delete_user_form($id) { if (empty($user)) { throw new Kohana_404_Exception(); } - print json_encode(array("form" => (string) $this->_get_user_delete_form_admin($user))); + json::reply(array("form" => (string) $this->_get_user_delete_form_admin($user))); } public function edit_user($id) { @@ -134,9 +134,9 @@ public function edit_user($id) { $user->save(); module::event("user_edit_form_admin_completed", $user, $form); message::success(t("Changed user %user_name", array("user_name" => $user->name))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -146,7 +146,7 @@ public function edit_user_form($id) { throw new Kohana_404_Exception(); } - print json_encode(array("form" => (string) $this->_get_user_edit_form_admin($user))); + json::reply(array("form" => (string) $this->_get_user_edit_form_admin($user))); } public function add_user_to_group($user_id, $group_id) { @@ -192,14 +192,14 @@ public function add_group() { $group->save(); message::success( t("Created group %group_name", array("group_name" => $group->name))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } public function add_group_form() { - print json_encode(array("form" => (string) $this->_get_group_add_form_admin())); + json::reply(array("form" => (string) $this->_get_group_add_form_admin())); } public function delete_group($id) { @@ -215,13 +215,13 @@ public function delete_group($id) { $name = $group->name; $group->delete(); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } $message = t("Deleted group %group_name", array("group_name" => $name)); log::success("group", $message); message::success($message); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } public function delete_group_form($id) { @@ -230,7 +230,7 @@ public function delete_group_form($id) { throw new Kohana_404_Exception(); } - print json_encode(array("form" => (string) $this->_get_group_delete_form_admin($group))); + json::reply(array("form" => (string) $this->_get_group_delete_form_admin($group))); } public function edit_group($id) { @@ -258,12 +258,12 @@ public function edit_group($id) { $group->save(); message::success( t("Changed group %group_name", array("group_name" => $group->name))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } else { $group->reload(); message::error( t("Failed to change group %group_name", array("group_name" => $group->name))); - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -273,7 +273,7 @@ public function edit_group_form($id) { throw new Kohana_404_Exception(); } - print json_encode(array("form" => (string) $this->_get_group_edit_form_admin($group))); + json::reply(array("form" => (string) $this->_get_group_edit_form_admin($group))); } /* User Form Definitions */ diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 4ddfb47c40..e98ab3412c 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -54,11 +54,10 @@ public function update($id) { $user->save(); module::event("user_edit_form_completed", $user, $form); message::success(t("User information updated")); - print json_encode( - array("result" => "success", - "resource" => url::site("users/{$user->id}"))); + json::reply(array("result" => "success", + "resource" => url::site("users/{$user->id}"))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -87,14 +86,13 @@ public function change_password($id) { message::success(t("Password changed")); module::event("user_auth", $user); module::event("user_password_change", $user); - print json_encode( - array("result" => "success", - "resource" => url::site("users/{$user->id}"))); + json::reply(array("result" => "success", + "resource" => url::site("users/{$user->id}"))); } else { log::warning("user", t("Failed password change for %name", array("name" => $user->name))); $name = $user->name; module::event("user_auth_failed", $name); - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -122,14 +120,13 @@ public function change_email($id) { module::event("user_change_email_form_completed", $user, $form); message::success(t("Email address changed")); module::event("user_auth", $user); - print json_encode( - array("result" => "success", - "resource" => url::site("users/{$user->id}"))); + json::reply(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_auth_failed", $name); - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -139,7 +136,7 @@ public function form_edit($id) { access::forbidden(); } - print json_encode(array("form" => (string) $this->_get_edit_form($user))); + json::reply(array("form" => (string) $this->_get_edit_form($user))); } public function form_change_password($id) { @@ -148,7 +145,7 @@ public function form_change_password($id) { access::forbidden(); } - print json_encode(array("form" => (string) $this->_get_change_password_form($user))); + json::reply(array("form" => (string) $this->_get_change_password_form($user))); } public function form_change_email($id) { @@ -157,7 +154,7 @@ public function form_change_email($id) { access::forbidden(); } - print json_encode(array("form" => (string) $this->_get_change_email_form($user))); + json::reply(array("form" => (string) $this->_get_change_email_form($user))); } private function _get_change_password_form($user) { From 91a2c04a24c320df37ea980f11245eb4e086879e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 21 Jul 2010 21:30:13 -0700 Subject: [PATCH 04/12] More patches as part of #1225. Change the 'core' modules to use the json::reply method to set the content type header and encode the response as a json object --- .../controllers/admin_manage_comments.php | 8 +++---- modules/comment/controllers/comments.php | 9 ++++---- modules/exif/controllers/exif.php | 2 +- modules/gallery/controllers/admin.php | 2 +- .../controllers/admin_advanced_settings.php | 4 ++-- .../gallery/controllers/admin_languages.php | 2 +- .../gallery/controllers/admin_maintenance.php | 10 ++++----- modules/gallery/controllers/admin_modules.php | 2 +- modules/gallery/controllers/admin_sidebar.php | 2 +- modules/gallery/controllers/albums.php | 14 ++++++------ modules/gallery/controllers/l10n_client.php | 2 +- modules/gallery/controllers/login.php | 7 +++--- modules/gallery/controllers/move.php | 6 ++--- modules/gallery/controllers/movies.php | 8 +++---- modules/gallery/controllers/permissions.php | 2 +- modules/gallery/controllers/photos.php | 8 +++---- modules/gallery/controllers/quick.php | 14 ++++++------ .../gallery/controllers/reauthenticate.php | 4 ++-- modules/gallery/controllers/uploader.php | 4 ++-- modules/gallery/controllers/user_profile.php | 6 ++--- modules/organize/controllers/organize.php | 10 ++++----- modules/rest/helpers/rest.php | 3 +-- modules/server_add/controllers/server_add.php | 6 ++--- modules/tag/controllers/admin_tags.php | 13 +++++------ modules/tag/controllers/tags.php | 6 ++--- modules/user/controllers/password.php | 8 +++---- .../controllers/admin_watermarks.php | 22 ++++++++----------- 27 files changed, 84 insertions(+), 100 deletions(-) diff --git a/modules/comment/controllers/admin_manage_comments.php b/modules/comment/controllers/admin_manage_comments.php index bc1c9e6414..e451791f1a 100644 --- a/modules/comment/controllers/admin_manage_comments.php +++ b/modules/comment/controllers/admin_manage_comments.php @@ -34,10 +34,10 @@ public function index() { public function menu_labels() { $menu = $this->_menu($this->_counts()); - print json_encode(array((string) $menu->get("unpublished")->label, - (string) $menu->get("published")->label, - (string) $menu->get("spam")->label, - (string) $menu->get("deleted")->label)); + json::reply(array((string) $menu->get("unpublished")->label, + (string) $menu->get("published")->label, + (string) $menu->get("spam")->label, + (string) $menu->get("deleted")->label)); } public function queue($state) { diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index c42ad24ebb..8826469da7 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -56,13 +56,12 @@ public function create($id) { $view = new Theme_View("comment.html", "other", "comment-fragment"); $view->comment = $comment; - print json_encode( - array("result" => "success", - "view" => (string) $view, - "form" => (string) comment::get_add_form($item))); + json::reply(array("result" => "success", + "view" => (string) $view, + "form" => (string) comment::get_add_form($item))); } else { $form = comment::prefill_add_form($form); - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } diff --git a/modules/exif/controllers/exif.php b/modules/exif/controllers/exif.php index fe5b2ff4bb..51e330813f 100644 --- a/modules/exif/controllers/exif.php +++ b/modules/exif/controllers/exif.php @@ -28,6 +28,6 @@ public function show($item_id) { $view = new View("exif_dialog.html"); $view->details = exif::get($item); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } } diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index eacacb28ad..7ea15d3d4f 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -78,7 +78,7 @@ private static function _reauth_check() { $result->location = url::abs_site(""); } - print json_encode($result); + json::reply($result); } private static function _prompt_for_reauth($controller_name, $args) { diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 2bbbdf505c..086f7603a3 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -39,7 +39,7 @@ public function edit($module_name, $var_name) { $group->input("var_name")->label(t("Setting"))->value($var_name)->disabled(1); $group->textarea("value")->label(t("Value"))->value($value); $group->submit("")->value(t("Save")); - print json_encode(array("form" => (string) $form)); + json::reply(array("form" => (string) $form)); } public function save($module_name, $var_name) { @@ -50,6 +50,6 @@ public function save($module_name, $var_name) { t("Saved value for %var (%module_name)", array("var" => $var_name, "module_name" => $module_name))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } } diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index 2e993816e6..573ededf18 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -51,7 +51,7 @@ public function save() { } module::set_var("gallery", "default_locale", $new_default_locale); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } public function share() { diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 489f5d54c0..5d06d224d2 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -64,7 +64,7 @@ public function start($task_callback) { log::info("tasks", t("Task %task_name started (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } /** @@ -86,7 +86,7 @@ public function resume($task_id) { log::info("tasks", t("Task %task_name resumed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } /** @@ -103,7 +103,7 @@ public function show_log($task_id) { $view = new View("admin_maintenance_show_log.html"); $view->task = $task; - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } /** @@ -211,7 +211,7 @@ public function run($task_id) { break; } // Using sprintf("%F") to avoid comma as decimal separator. - print json_encode(array("result" => "success", + json::reply(array("result" => "success", "task" => array( "percent_complete" => sprintf("%F", $task->percent_complete), "status" => (string) $task->status, @@ -219,7 +219,7 @@ public function run($task_id) { "location" => url::site("admin/maintenance"))); } else { - print json_encode(array("result" => "in_progress", + json::reply(array("result" => "in_progress", "task" => array( "percent_complete" => sprintf("%F", $task->percent_complete), "status" => (string) $task->status, diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index bf638a3791..f5af9a5a7f 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -57,7 +57,7 @@ public function confirm() { $result["dialog"] = (string)$v; $result["allow_continue"] = empty($messages["error"]); } - print json_encode($result); + json::reply($result); } public function save() { diff --git a/modules/gallery/controllers/admin_sidebar.php b/modules/gallery/controllers/admin_sidebar.php index fb857e4ede..2e49097a79 100644 --- a/modules/gallery/controllers/admin_sidebar.php +++ b/modules/gallery/controllers/admin_sidebar.php @@ -50,7 +50,7 @@ public function update() { $result["active"] = $v->render(); $message = t("Updated sidebar blocks"); $result["message"] = (string) $message; - print json_encode($result); + json::reply($result); } private function _get_blocks() { diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 8aed1341a8..584e4f1531 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -113,9 +113,9 @@ public function create($parent_id) { message::success(t("Created album %album_title", array("album_title" => html::purify($album->title)))); - print json_encode(array("result" => "success", "location" => $album->url())); + json::reply(array("result" => "success", "location" => $album->url())); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -153,13 +153,13 @@ public function update($album_id) { if ($form->from_id->value == $album->id) { // Use the new url; it might have changed. - print json_encode(array("result" => "success", "location" => $album->url())); + json::reply(array("result" => "success", "location" => $album->url())); } else { // Stay on the same page - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -168,7 +168,7 @@ public function form_add($album_id) { access::required("view", $album); access::required("add", $album); - print json_encode(array("form" => (string) album::get_add_form($album))); + json::reply(array("form" => (string) album::get_add_form($album))); } public function form_edit($album_id) { @@ -176,6 +176,6 @@ public function form_edit($album_id) { access::required("view", $album); access::required("edit", $album); - print json_encode(array("form" => (string) album::get_edit_form($album))); + json::reply(array("form" => (string) album::get_edit_form($album))); } } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index d5b322ef68..6833a9ae11 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -91,7 +91,7 @@ public function save() { Gallery_I18n::clear_cache($locale); - print json_encode(new stdClass()); + json::reply(new stdClass()); } public function toggle_l10n_mode() { diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index b823504b78..3454a245eb 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -22,7 +22,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); $view->form = auth::get_login_form("login/auth_ajax"); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } public function auth_ajax() { @@ -30,10 +30,9 @@ public function auth_ajax() { list ($valid, $form) = $this->_auth("login/auth_ajax"); if ($valid) { - print json_encode( - array("result" => "success")); + json::reply(array("result" => "success")); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index a99ef34194..c47cdd955c 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -26,7 +26,7 @@ public function browse($source_id) { $view = new View("move_browse.html"); $view->source = $source; $view->tree = $this->_get_tree_html($source, ORM::factory("item", 1)); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } public function save($source_id) { @@ -41,9 +41,7 @@ public function save($source_id) { item::move($source, $target); - print json_encode( - array("result" => "success", - "location" => $target->url())); + json::reply(array("result" => "success", "location" => $target->url())); } public function show_sub_tree($source_id, $target_id) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index c18dbcde67..fe6669e626 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -87,13 +87,13 @@ public function update($movie_id) { if ($form->from_id->value == $movie->id) { // Use the new url; it might have changed. - print json_encode(array("result" => "success", "location" => $movie->url())); + json::reply(array("result" => "success", "location" => $movie->url())); } else { // Stay on the same page - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -102,6 +102,6 @@ public function form_edit($movie_id) { access::required("view", $movie); access::required("edit", $movie); - print json_encode(array("form" => (string) movie::get_edit_form($movie))); + json::reply(array("form" => (string) movie::get_edit_form($movie))); } } diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 8fdda7b2d7..57f5ccb6b0 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -33,7 +33,7 @@ function browse($id) { $view->parents = $item->parents(); $view->form = $this->_get_form($item); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } function form($id) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 9f17cebbcd..7c834e6425 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -87,13 +87,13 @@ public function update($photo_id) { if ($form->from_id->value == $photo->id) { // Use the new url; it might have changed. - print json_encode(array("result" => "success", "location" => $photo->url())); + json::reply(array("result" => "success", "location" => $photo->url())); } else { // Stay on the same page - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -102,6 +102,6 @@ public function form_edit($photo_id) { access::required("view", $photo); access::required("edit", $photo); - print json_encode(array("form" => (string) photo::get_edit_form($photo))); + json::reply(array("form" => (string) photo::get_edit_form($photo))); } } diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 253a279b72..1d9194c7bd 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -58,12 +58,12 @@ public function rotate($id, $dir) { } if (Input::instance()->get("page_type") == "collection") { - print json_encode( + json::reply( array("src" => $item->thumb_url(), "width" => $item->thumb_width, "height" => $item->thumb_height)); } else { - print json_encode( + json::reply( array("src" => $item->resize_url(), "width" => $item->resize_width, "height" => $item->resize_height)); @@ -83,7 +83,7 @@ public function make_album_cover($id) { item::make_album_cover($item); message::success($msg); - print json_encode(array("result" => "success", "reload" => 1)); + json::reply(array("result" => "success", "reload" => 1)); } public function form_delete($id) { @@ -94,7 +94,7 @@ public function form_delete($id) { $v = new View("quick_delete_confirm.html"); $v->item = $item; $v->form = item::get_delete_form($item); - print json_encode(array("form" => (string) $v)); + json::reply(array("form" => (string) $v)); } public function delete($id) { @@ -125,9 +125,9 @@ public function delete($id) { $from_id = Input::instance()->get("from_id"); if (Input::instance()->get("page_type") == "collection" && $from_id != $id /* deleted the item we were viewing */) { - print json_encode(array("result" => "success", "reload" => 1)); + json::reply(array("result" => "success", "reload" => 1)); } else { - print json_encode(array("result" => "success", + json::reply(array("result" => "success", "location" => $parent->url())); } } @@ -154,6 +154,6 @@ public function form_edit($id) { // Pass on the source item where this form was generated, so we have an idea where to return to. $form->hidden("from_id")->value((int)Input::instance()->get("from_id", 0)); - print json_encode(array("form" => (string) $form)); + json::reply(array("form" => (string) $form)); } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 3cff2b6ad7..2b1f6d144d 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -23,7 +23,7 @@ public function index($share_translations_form=null) { access::forbidden(); } if (request::is_ajax()) { - print json_encode(array("form" => (string) self::_form())); + json::reply(array("form" => (string) self::_form())); } else { self::_show_form(self::_form()); } @@ -51,7 +51,7 @@ public function auth() { if (empty($reauthenticate["in_dialog"])) { self::_show_form($form); } else { - print json_encode(array("form" => (string) $form)); + json::reply(array("form" => (string) $form)); } } } diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php index 38e22ceec2..c686c787ff 100644 --- a/modules/gallery/controllers/uploader.php +++ b/modules/gallery/controllers/uploader.php @@ -26,7 +26,7 @@ public function index($id) { $item = $item->parent(); } - print json_encode(array("form" => (string)$this->_get_add_form($item))); + json::reply(array("form" => (string)$this->_get_add_form($item))); //print $this->_get_add_form($item); } @@ -106,7 +106,7 @@ public function finish() { access::verify_csrf(); batch::stop(); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } private function _get_add_form($album) { diff --git a/modules/gallery/controllers/user_profile.php b/modules/gallery/controllers/user_profile.php index 431918ff38..113be1faef 100644 --- a/modules/gallery/controllers/user_profile.php +++ b/modules/gallery/controllers/user_profile.php @@ -44,7 +44,7 @@ public function show($id) { public function contact($id) { $user = identity::lookup_user($id); - print json_encode(array("form" => (string) user_profile::get_contact_form($user))); + json::reply(array("form" => (string) user_profile::get_contact_form($user))); } public function send($id) { @@ -61,9 +61,9 @@ public function send($id) { ->message(html::purify($form->message->message->value)) ->send(); message::success(t("Sent message to %user_name", array("user_name" => $user->display_name()))); - print json_encode(array("result" => "success")); + json::reply(array("result" => "success")); } else { - print json_encode(array("result" => "error", "form" => (string)$form)); + json::reply(array("result" => "error", "form" => (string)$form)); } } } diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 0e647e0923..99933c7e0d 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -47,14 +47,14 @@ function dialog($album_id) { $v->controller_uri = url::site("organize") . "/"; $v->swf_uri = url::file("modules/organize/lib/Gallery3WebClient.swf?") . filemtime(MODPATH . "organize/lib/Gallery3WebClient.swf"); - print json_encode(array("form" => (string) $v)); + json::reply(array("form" => (string) $v)); } function add_album_fields() { - print json_encode(array("title" => (string)t("Title"), - "description" => (string)t("Description"), - "name" => (string)t("Directory name"), - "slug" => (string)t("Internet Address"))); + json::reply(array("title" => (string)t("Title"), + "description" => (string)t("Description"), + "name" => (string)t("Directory name"), + "slug" => (string)t("Internet Address"))); } } diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index bcb12d5884..644779dad5 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -35,8 +35,7 @@ static function reply($data=array()) { } print "
$html
"; } else { - header("Content-type: application/json"); - print json_encode($data); + json::reply($data); } } diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index e91d9dd990..afa1f8629c 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -30,7 +30,7 @@ public function browse($id) { $view->tree = new View("server_add_tree.html"); $view->tree->files = $files; $view->tree->parents = array(); - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } public function children() { @@ -91,7 +91,7 @@ public function start() { ->name(t("Add from server")); $task = task::create($task_def, array("item_id" => $item->id, "queue" => $paths)); - print json_encode( + json::reply( array("result" => "started", "status" => (string)$task->status, "url" => url::site("server_add/run/$task->id?csrf=" . access::csrf_token()))); @@ -111,7 +111,7 @@ function run($task_id) { $task = task::run($task_id); // Prevent the JavaScript code from breaking by forcing a period as // decimal separator for all locales with sprintf("%F", $value). - print json_encode(array("done" => (bool)$task->done, + json::reply(array("done" => (bool)$task->done, "status" => (string)$task->status, "percent_complete" => sprintf("%F", $task->percent_complete))); } diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index c2da7bc3b7..32c5494522 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -37,7 +37,7 @@ public function index() { public function form_delete($id) { $tag = ORM::factory("tag", $id); if ($tag->loaded()) { - print json_encode(array("form" => (string) tag::get_delete_form($tag))); + json::reply(array("form" => (string) tag::get_delete_form($tag))); } } @@ -57,11 +57,9 @@ public function delete($id) { message::success(t("Deleted tag %tag_name", array("tag_name" => $name))); log::success("tags", t("Deleted tag %tag_name", array("tag_name" => $name))); - print json_encode( - array("result" => "success", - "location" => url::site("admin/tags"))); + json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } @@ -98,10 +96,9 @@ public function rename($id) { message::success($message); log::success("tags", $message); - print json_encode(array("result" => "success", - "location" => url::site("admin/tags"))); + json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - print json_encode(array("result" => "error", "form" => $in_place_edit->render())); + json::reply(array("result" => "error", "form" => $in_place_edit->render())); } } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index f3d456d383..7fa8534c9b 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -67,11 +67,9 @@ public function create($item_id) { } } - print json_encode( - array("result" => "success", - "cloud" => (string)tag::cloud(30))); + json::reply(array("result" => "success", "cloud" => (string)tag::cloud(30))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index 522b6b3563..4058ef5033 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -27,11 +27,10 @@ public function reset() { if ($form->validate()) { $this->_send_reset($form); } else { - print json_encode(array("result" => "error", - "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } else { - print $form; + json::reply(array("form" => (string) $form)); } } @@ -83,8 +82,7 @@ private function _send_reset($form) { // Always pretend that an email has been sent to avoid leaking // information on what user names are actually real. message::success(t("Password reset email sent")); - print json_encode( - array("result" => "success")); + json::reply(array("result" => "success")); } private static function _reset_form() { diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index 8b217b4ab6..922b050bd7 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -35,7 +35,7 @@ public function index() { } public function form_edit() { - print json_encode(array("form" => (string) watermark::get_edit_form())); + json::reply(array("form" => (string) watermark::get_edit_form())); } public function edit() { @@ -49,16 +49,16 @@ public function edit() { log::success("watermark", t("Watermark changed")); message::success(t("Watermark changed")); - print json_encode( + json::reply( array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } public function form_delete() { - print json_encode(array("form" => (string) watermark::get_delete_form())); + json::reply(array("form" => (string) watermark::get_delete_form())); } public function delete() { @@ -79,16 +79,14 @@ public function delete() { log::success("watermark", t("Watermark deleted")); message::success(t("Watermark deleted")); } - print json_encode( - array("result" => "success", - "location" => url::site("admin/watermarks"))); + json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string) $form)); } } public function form_add() { - print json_encode(array("form" => (string) watermark::get_add_form())); + json::reply(array("form" => (string) watermark::get_add_form())); } public function add() { @@ -120,11 +118,9 @@ public function add() { message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); - print json_encode( - array("result" => "success", - "location" => url::site("admin/watermarks"))); + json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - print json_encode(array("result" => "error", "form" => rawurlencode((string) $form))); + json::reply(array("result" => "error", "form" => rawurlencode((string) $form))); } } From 09dfe1a91b3e663917fe53516148fe5d74c099fa Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 23 Jul 2010 23:00:27 -0700 Subject: [PATCH 05/12] Convert the admin_theme controller to use the json::reply method --- modules/gallery/controllers/admin_themes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index b1bd438f5e..18a4d2ae3a 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -52,7 +52,7 @@ public function preview($type, $theme_name) { } else { $view->url = item::root()->url("theme=$theme_name"); } - print json_encode(array("form" => (string) $view)); + json::reply(array("form" => (string) $view)); } public function choose($type, $theme_name) { From 0cca2fdf9bc0e77e1015975efdb9fe7c07a75b5f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 26 Jul 2010 07:57:49 -0700 Subject: [PATCH 06/12] Correct the name of the JSON member that contains the form data. --- lib/gallery.dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 7b9d4b94a3..f47c6d56cd 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -131,7 +131,7 @@ }, success: function(data) { if (data.form) { - var formData = unescape(data.content); + var formData = unescape(data.form); $("#g-dialog form").replaceWith(formData); $("#g-dialog").dialog("option", "position", "center"); $("#g-dialog form :submit").removeClass("ui-state-disabled") From 29f29d2261c96c30eb3e63a8066e80ade5497081 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 28 Jul 2010 07:57:27 -0700 Subject: [PATCH 07/12] When the admin controller redirects to the reauthenticate controller, the value of request::is_ajax() from the original request is lost. This patch stores its value in the session so the reauthenticate controller knows whether its in a dialog/panel or not. --- modules/gallery/controllers/admin.php | 3 ++- modules/gallery/controllers/reauthenticate.php | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 7ea15d3d4f..8fc5432da4 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -86,7 +86,8 @@ private static function _prompt_for_reauth($controller_name, $args) { // Avoid anti-phishing protection by passing the url as session variable. Session::instance()->set("continue_url", url::abs_current(true)); } - + // Save the is_ajax value as we lose it, if set, when we redirect + Session::instance()->set("is_ajax_request", request::is_ajax()); url::redirect("reauthenticate"); } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 2b1f6d144d..5ea2f22924 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -22,8 +22,13 @@ public function index($share_translations_form=null) { if (!identity::active_user()->admin) { access::forbidden(); } - if (request::is_ajax()) { - json::reply(array("form" => (string) self::_form())); + // On redirects from the admin controller, the ajax request indicator is lost, + // so we store it in the session. + $is_ajax = Session::instance()->get_once("is_ajax_request", request::is_ajax()); + if ($is_ajax) { + $v = new View("reauthenticate.html"); + $v->form = self::_form(); + json::reply(array("form" => (string) $v)); } else { self::_show_form(self::_form()); } From 0c535c85ed7eb5d852ff18715287dd63f85903ac Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 29 Jul 2010 08:57:21 -0700 Subject: [PATCH 08/12] Missing the user name on the reauthenticate form. --- modules/gallery/controllers/reauthenticate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 5ea2f22924..393f97cbc4 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -28,6 +28,7 @@ public function index($share_translations_form=null) { if ($is_ajax) { $v = new View("reauthenticate.html"); $v->form = self::_form(); + $v->user_name = identity::active_user()->name; json::reply(array("form" => (string) $v)); } else { self::_show_form(self::_form()); From a6ceb927e602dd693b011a17e625cc9c87d57d69 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 29 Jul 2010 08:59:10 -0700 Subject: [PATCH 09/12] Sometimes in dialogs, the form is wrapped in a view to provide additional information. We need to replace the contents of the entire dialog, not just the form, otherwise, there could be text floating around that doesn't make sense. --- lib/gallery.dialog.js | 2 +- lib/gallery.panel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index f47c6d56cd..555e6f47f6 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -132,7 +132,7 @@ success: function(data) { if (data.form) { var formData = unescape(data.form); - $("#g-dialog form").replaceWith(formData); + $("#g-dialog").html(formData); $("#g-dialog").dialog("option", "position", "center"); $("#g-dialog form :submit").removeClass("ui-state-disabled") .attr("disabled", null); diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js index e219f3d647..aee7185d33 100644 --- a/lib/gallery.panel.js +++ b/lib/gallery.panel.js @@ -80,7 +80,7 @@ }, success: function(data) { if (data.form) { - $("#g-panel td form").replaceWith(data.form); + $("#g-panel td").html(data.form); self._ajaxify_panel(); } if (data.result == "success") { From a6280641f53391dd57b3760ac882c3219e0cee6e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 29 Jul 2010 09:22:32 -0700 Subject: [PATCH 10/12] Resend the entire dialog content (including the wrapping view) instead of just the form. --- modules/gallery/controllers/login.php | 4 +++- modules/gallery/controllers/reauthenticate.php | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 3454a245eb..d7ab399f2d 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -32,7 +32,9 @@ public function auth_ajax() { if ($valid) { json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + $view = new View("login_ajax.html"); + $view->form = $form; + json::reply(array("result" => "error", "form" => (string) $view)); } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 393f97cbc4..7f9e5edc12 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -54,10 +54,13 @@ public function auth() { $name = $user->name; log::warning("user", t("Failed re-authentication for %name", array("name" => $name))); module::event("user_auth_failed", $name); - if (empty($reauthenticate["in_dialog"])) { - self::_show_form($form); + if (request::is_ajax()) { + $v = new View("reauthenticate.html"); + $v->form = $form; + $v->user_name = identity::active_user()->name; + json::reply(array("form" => (string) $v)); } else { - json::reply(array("form" => (string) $form)); + self::_show_form($form); } } } From be4ad8e96d53f04a8f975aedde625a1f3e17dafd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 31 Jul 2010 16:47:14 -0700 Subject: [PATCH 11/12] "Save" -> "Download" for clarity. --- modules/gallery/views/admin_maintenance_show_log.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gallery/views/admin_maintenance_show_log.html.php b/modules/gallery/views/admin_maintenance_show_log.html.php index d2472fdc53..ecf882f081 100644 --- a/modules/gallery/views/admin_maintenance_show_log.html.php +++ b/modules/gallery/views/admin_maintenance_show_log.html.php @@ -15,5 +15,5 @@
get_log()) ?>
- + From 7607e1f932dda53144792d0b7e8674a34fbc7f9a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 31 Jul 2010 21:16:17 -0700 Subject: [PATCH 12/12] Full pass over all the JSON encoding and JS dialog code. We now abide by the following rules: 1) An initial dialog or panel load can take either HTML or JSON, but the mime type must accurately reflect its payload. 2) dialog form submits can handle a pure HTML response, but the mime type must also be correct. This properly resolves the problem where the reauth code gets a JSON response first from the reauth code, and then an HTML response when you reauth and continue on to a given form -- try it out with Admin > Settings > Advanced. 3) All JSON replies must set the mime type correctly. The json::reply convenience function does this for us. 4) By default, any HTML content sent back in the JSON response should be in the "html" field, no longer the "form" field. The combination of these allows us to stop doing boilerplate code like this in our controllers: // Print our view, JSON encoded json::reply(array("form" => (string) $view)); instead, controllers can just return HTML, eg: // Print our view print $view; That's much more intuitive for developers. --- lib/gallery.dialog.js | 37 ++++++++++++++++--- lib/gallery.panel.js | 6 +-- modules/comment/controllers/comments.php | 6 +-- modules/exif/controllers/exif.php | 2 +- .../controllers/admin_advanced_settings.php | 2 +- .../gallery/controllers/admin_maintenance.php | 24 ++++++------ modules/gallery/controllers/admin_themes.php | 2 +- modules/gallery/controllers/albums.php | 8 ++-- modules/gallery/controllers/login.php | 4 +- modules/gallery/controllers/move.php | 2 +- modules/gallery/controllers/movies.php | 4 +- modules/gallery/controllers/permissions.php | 2 +- modules/gallery/controllers/photos.php | 4 +- modules/gallery/controllers/quick.php | 7 ++-- .../gallery/controllers/reauthenticate.php | 6 +-- modules/gallery/controllers/uploader.php | 3 +- modules/gallery/controllers/user_profile.php | 4 +- modules/organize/controllers/organize.php | 2 +- modules/server_add/controllers/server_add.php | 6 +-- modules/tag/controllers/admin_tags.php | 8 ++-- modules/tag/controllers/tags.php | 2 +- modules/user/controllers/admin_users.php | 28 +++++++------- modules/user/controllers/password.php | 4 +- modules/user/controllers/users.php | 14 +++---- .../controllers/admin_watermarks.php | 15 +++++--- 25 files changed, 114 insertions(+), 88 deletions(-) diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 555e6f47f6..f1d146ab7b 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -31,8 +31,8 @@ url: sHref, type: "GET", beforeSend: function(xhr) { - // Until we convert to jquery 1.4, we need to save the - // XMLHttpRequest object + // Until we convert to jquery 1.4, we need to save the XMLHttpRequest object so that we + // can detect the mime type of the reply this.xhrData = xhr; }, success: function(data, textStatus, xhr) { @@ -122,17 +122,42 @@ _ajaxify_dialog: function() { var self = this; $("#g-dialog form").ajaxForm({ - dataType: "json", beforeSubmit: function(formData, form, options) { form.find(":submit") .addClass("ui-state-disabled") .attr("disabled", "disabled"); return true; }, + beforeSend: function(xhr) { + // Until we convert to jquery 1.4, we need to save the XMLHttpRequest object so that we + // can detect the mime type of the reply + this.xhrData = xhr; + }, success: function(data) { - if (data.form) { - var formData = unescape(data.form); - $("#g-dialog").html(formData); + // Pre jquery 1.4, get the saved XMLHttpRequest object + xhr = this.xhrData; + if (xhr) { + var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type")); + + var content = ""; + if (mimeType[1] == "application/json") { + data = JSON.parse(data); + } else { + data = {"html": escape(data)}; + } + } else { + // Uploading files (eg: watermark) uses a fake xhr in jquery.form.js so + // all we have is in the data field, which should be some very simple JSON. + // Weirdly enough in Chrome the result gets wrapped in a
 element and
+	     // looks like this:
+	     //   
{"result":"success",
+	     //   "location":"\/~bharat\/gallery3\/index.php\/admin\/watermarks"}
+ // bizarre. Strip that off before parsing. + data = JSON.parse(data.match("({.*})")[0]); + } + + if (data.html) { + $("#g-dialog").html(unescape(data.html)); $("#g-dialog").dialog("option", "position", "center"); $("#g-dialog form :submit").removeClass("ui-state-disabled") .attr("disabled", null); diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js index aee7185d33..e0605ca31c 100644 --- a/lib/gallery.panel.js +++ b/lib/gallery.panel.js @@ -48,7 +48,7 @@ var content = ""; if (mimeType[1] == "application/json") { data = JSON.parse(data); - content = unescape(data.form); + content = unescape(data.html); } else { content = data; } @@ -79,8 +79,8 @@ return true; }, success: function(data) { - if (data.form) { - $("#g-panel td").html(data.form); + if (data.html) { + $("#g-panel td").html(data.html); self._ajaxify_panel(); } if (data.result == "success") { diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 8826469da7..6ec4132b62 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -57,11 +57,11 @@ public function create($id) { $view->comment = $comment; json::reply(array("result" => "success", - "view" => (string) $view, - "form" => (string) comment::get_add_form($item))); + "view" => (string)$view, + "form" => (string)comment::get_add_form($item))); } else { $form = comment::prefill_add_form($form); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "form" => (string)$form)); } } diff --git a/modules/exif/controllers/exif.php b/modules/exif/controllers/exif.php index 51e330813f..2fe875e38c 100644 --- a/modules/exif/controllers/exif.php +++ b/modules/exif/controllers/exif.php @@ -28,6 +28,6 @@ public function show($item_id) { $view = new View("exif_dialog.html"); $view->details = exif::get($item); - json::reply(array("form" => (string) $view)); + print $view; } } diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 086f7603a3..cf197743e6 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -39,7 +39,7 @@ public function edit($module_name, $var_name) { $group->input("var_name")->label(t("Setting"))->value($var_name)->disabled(1); $group->textarea("value")->label(t("Value"))->value($value); $group->submit("")->value(t("Save")); - json::reply(array("form" => (string) $form)); + print $form; } public function save($module_name, $var_name) { diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 5d06d224d2..3567b4f0b5 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -64,7 +64,7 @@ public function start($task_callback) { log::info("tasks", t("Task %task_name started (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -86,7 +86,7 @@ public function resume($task_id) { log::info("tasks", t("Task %task_name resumed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -103,7 +103,7 @@ public function show_log($task_id) { $view = new View("admin_maintenance_show_log.html"); $view->task = $task; - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -212,18 +212,18 @@ public function run($task_id) { } // Using sprintf("%F") to avoid comma as decimal separator. json::reply(array("result" => "success", - "task" => array( - "percent_complete" => sprintf("%F", $task->percent_complete), - "status" => (string) $task->status, - "done" => (bool) $task->done), - "location" => url::site("admin/maintenance"))); + "task" => array( + "percent_complete" => sprintf("%F", $task->percent_complete), + "status" => (string) $task->status, + "done" => (bool) $task->done), + "location" => url::site("admin/maintenance"))); } else { json::reply(array("result" => "in_progress", - "task" => array( - "percent_complete" => sprintf("%F", $task->percent_complete), - "status" => (string) $task->status, - "done" => (bool) $task->done))); + "task" => array( + "percent_complete" => sprintf("%F", $task->percent_complete), + "status" => (string) $task->status, + "done" => (bool) $task->done))); } } } diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 18a4d2ae3a..e59eadaf45 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -52,7 +52,7 @@ public function preview($type, $theme_name) { } else { $view->url = item::root()->url("theme=$theme_name"); } - json::reply(array("form" => (string) $view)); + print $view; } public function choose($type, $theme_name) { diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 584e4f1531..f3f5dee334 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -115,7 +115,7 @@ public function create($parent_id) { json::reply(array("result" => "success", "location" => $album->url())); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print $form; } } @@ -159,7 +159,7 @@ public function update($album_id) { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -168,7 +168,7 @@ public function form_add($album_id) { access::required("view", $album); access::required("add", $album); - json::reply(array("form" => (string) album::get_add_form($album))); + print album::get_add_form($album); } public function form_edit($album_id) { @@ -176,6 +176,6 @@ public function form_edit($album_id) { access::required("view", $album); access::required("edit", $album); - json::reply(array("form" => (string) album::get_edit_form($album))); + print album::get_edit_form($album); } } diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index d7ab399f2d..62d33345c2 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -22,7 +22,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); $view->form = auth::get_login_form("login/auth_ajax"); - json::reply(array("form" => (string) $view)); + print $view; } public function auth_ajax() { @@ -34,7 +34,7 @@ public function auth_ajax() { } else { $view = new View("login_ajax.html"); $view->form = $form; - json::reply(array("result" => "error", "form" => (string) $view)); + json::reply(array("result" => "error", "html" => (string)$view)); } } diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index c47cdd955c..7b2d61650e 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -26,7 +26,7 @@ public function browse($source_id) { $view = new View("move_browse.html"); $view->source = $source; $view->tree = $this->_get_tree_html($source, ORM::factory("item", 1)); - json::reply(array("form" => (string) $view)); + print $view; } public function save($source_id) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index fe6669e626..02d2a49753 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -93,7 +93,7 @@ public function update($movie_id) { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -102,6 +102,6 @@ public function form_edit($movie_id) { access::required("view", $movie); access::required("edit", $movie); - json::reply(array("form" => (string) movie::get_edit_form($movie))); + print movie::get_edit_form($movie); } } diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 57f5ccb6b0..fc06cb44cf 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -33,7 +33,7 @@ function browse($id) { $view->parents = $item->parents(); $view->form = $this->_get_form($item); - json::reply(array("form" => (string) $view)); + print $view; } function form($id) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 7c834e6425..8377e6c7a5 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -93,7 +93,7 @@ public function update($photo_id) { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -102,6 +102,6 @@ public function form_edit($photo_id) { access::required("view", $photo); access::required("edit", $photo); - json::reply(array("form" => (string) photo::get_edit_form($photo))); + print photo::get_edit_form($photo); } } diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 1d9194c7bd..fee601d940 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -94,7 +94,7 @@ public function form_delete($id) { $v = new View("quick_delete_confirm.html"); $v->item = $item; $v->form = item::get_delete_form($item); - json::reply(array("form" => (string) $v)); + print $v; } public function delete($id) { @@ -127,8 +127,7 @@ public function delete($id) { $from_id != $id /* deleted the item we were viewing */) { json::reply(array("result" => "success", "reload" => 1)); } else { - json::reply(array("result" => "success", - "location" => $parent->url())); + json::reply(array("result" => "success", "location" => $parent->url())); } } @@ -154,6 +153,6 @@ public function form_edit($id) { // Pass on the source item where this form was generated, so we have an idea where to return to. $form->hidden("from_id")->value((int)Input::instance()->get("from_id", 0)); - json::reply(array("form" => (string) $form)); + print $form; } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 7f9e5edc12..0486c0fe74 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Reauthenticate_Controller extends Controller { - public function index($share_translations_form=null) { + public function index() { if (!identity::active_user()->admin) { access::forbidden(); } @@ -29,7 +29,7 @@ public function index($share_translations_form=null) { $v = new View("reauthenticate.html"); $v->form = self::_form(); $v->user_name = identity::active_user()->name; - json::reply(array("form" => (string) $v)); + print $v; } else { self::_show_form(self::_form()); } @@ -58,7 +58,7 @@ public function auth() { $v = new View("reauthenticate.html"); $v->form = $form; $v->user_name = identity::active_user()->name; - json::reply(array("form" => (string) $v)); + json::reply(array("html" => (string)$v)); } else { self::_show_form($form); } diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php index c686c787ff..875200320f 100644 --- a/modules/gallery/controllers/uploader.php +++ b/modules/gallery/controllers/uploader.php @@ -26,8 +26,7 @@ public function index($id) { $item = $item->parent(); } - json::reply(array("form" => (string)$this->_get_add_form($item))); - //print $this->_get_add_form($item); + print $this->_get_add_form($item); } public function start() { diff --git a/modules/gallery/controllers/user_profile.php b/modules/gallery/controllers/user_profile.php index 113be1faef..726d3e51ab 100644 --- a/modules/gallery/controllers/user_profile.php +++ b/modules/gallery/controllers/user_profile.php @@ -44,7 +44,7 @@ public function show($id) { public function contact($id) { $user = identity::lookup_user($id); - json::reply(array("form" => (string) user_profile::get_contact_form($user))); + print user_profile::get_contact_form($user); } public function send($id) { @@ -63,7 +63,7 @@ public function send($id) { message::success(t("Sent message to %user_name", array("user_name" => $user->display_name()))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string)$form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } } diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 99933c7e0d..3005eb67d8 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -47,7 +47,7 @@ function dialog($album_id) { $v->controller_uri = url::site("organize") . "/"; $v->swf_uri = url::file("modules/organize/lib/Gallery3WebClient.swf?") . filemtime(MODPATH . "organize/lib/Gallery3WebClient.swf"); - json::reply(array("form" => (string) $v)); + print $v; } function add_album_fields() { diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index afa1f8629c..e4c3e69c2f 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -30,7 +30,7 @@ public function browse($id) { $view->tree = new View("server_add_tree.html"); $view->tree->files = $files; $view->tree->parents = array(); - json::reply(array("form" => (string) $view)); + print $view; } public function children() { @@ -112,8 +112,8 @@ function run($task_id) { // Prevent the JavaScript code from breaking by forcing a period as // decimal separator for all locales with sprintf("%F", $value). json::reply(array("done" => (bool)$task->done, - "status" => (string)$task->status, - "percent_complete" => sprintf("%F", $task->percent_complete))); + "status" => (string)$task->status, + "percent_complete" => sprintf("%F", $task->percent_complete))); } /** diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 32c5494522..0c82579bc3 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -37,7 +37,7 @@ public function index() { public function form_delete($id) { $tag = ORM::factory("tag", $id); if ($tag->loaded()) { - json::reply(array("form" => (string) tag::get_delete_form($tag))); + print tag::get_delete_form($tag); } } @@ -59,7 +59,7 @@ public function delete($id) { json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print $form; } } @@ -91,14 +91,14 @@ public function rename($id) { $tag->name = $in_place_edit->value(); $tag->save(); - $message = t("Renamed tag %old_name to %new_name", + $message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name)); message::success($message); log::success("tags", $message); json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - json::reply(array("result" => "error", "form" => $in_place_edit->render())); + json::reply(array("result" => "error", "form" => (string)$in_place_edit->render())); } } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 7fa8534c9b..bc657644a6 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -69,7 +69,7 @@ public function create($item_id) { json::reply(array("result" => "success", "cloud" => (string)tag::cloud(30))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 64365f2b9a..b8487e0143 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -56,12 +56,12 @@ public function add_user() { message::success(t("Created user %user_name", array("user_name" => $user->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print json::reply(array("result" => "error", "html" => (string)$form)); } } public function add_user_form() { - json::reply(array("form" => (string) $this->_get_user_add_form_admin())); + print $this->_get_user_add_form_admin(); } public function delete_user($id) { @@ -81,7 +81,7 @@ public function delete_user($id) { $name = $user->name; $user->delete(); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } $message = t("Deleted user %user_name", array("user_name" => $name)); @@ -95,7 +95,7 @@ public function delete_user_form($id) { if (empty($user)) { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_user_delete_form_admin($user))); + print $this->_get_user_delete_form_admin($user); } public function edit_user($id) { @@ -136,7 +136,7 @@ public function edit_user($id) { message::success(t("Changed user %user_name", array("user_name" => $user->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -146,7 +146,7 @@ public function edit_user_form($id) { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_user_edit_form_admin($user))); + print $this->_get_user_edit_form_admin($user); } public function add_user_to_group($user_id, $group_id) { @@ -194,12 +194,12 @@ public function add_group() { t("Created group %group_name", array("group_name" => $group->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function add_group_form() { - json::reply(array("form" => (string) $this->_get_group_add_form_admin())); + print $this->_get_group_add_form_admin(); } public function delete_group($id) { @@ -215,7 +215,7 @@ public function delete_group($id) { $name = $group->name; $group->delete(); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } $message = t("Deleted group %group_name", array("group_name" => $name)); @@ -230,7 +230,7 @@ public function delete_group_form($id) { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_group_delete_form_admin($group))); + print $this->_get_group_delete_form_admin($group); } public function edit_group($id) { @@ -263,7 +263,7 @@ public function edit_group($id) { $group->reload(); message::error( t("Failed to change group %group_name", array("group_name" => $group->name))); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -273,7 +273,7 @@ public function edit_group_form($id) { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_group_edit_form_admin($group))); + print $this->_get_group_edit_form_admin($group); } /* User Form Definitions */ @@ -309,7 +309,7 @@ static function _get_user_edit_form_admin($user) { } module::event("user_edit_form_admin", $user, $form); - $group->submit("")->value(t("Modify User")); + $group->submit("")->value(t("Modify user")); return $form; } @@ -354,7 +354,7 @@ private static function _add_locale_dropdown(&$form, $user=null) { $locales = array_merge(array("" => t("« none »")), $locales); $selected_locale = ($user && $user->locale) ? $user->locale : ""; $form->dropdown("locale") - ->label(t("Language Preference")) + ->label(t("Language preference")) ->options($locales) ->selected($selected_locale); } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index 4058ef5033..575720a8f8 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -27,10 +27,10 @@ public function reset() { if ($form->validate()) { $this->_send_reset($form); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } else { - json::reply(array("form" => (string) $form)); + print $form; } } diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index e98ab3412c..d13cccb29a 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -57,7 +57,7 @@ public function update($id) { json::reply(array("result" => "success", "resource" => url::site("users/{$user->id}"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -92,7 +92,7 @@ public function change_password($id) { log::warning("user", t("Failed password change for %name", array("name" => $user->name))); $name = $user->name; module::event("user_auth_failed", $name); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -126,7 +126,7 @@ public function change_email($id) { log::warning("user", t("Failed email change for %name", array("name" => $user->name))); $name = $user->name; module::event("user_auth_failed", $name); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -136,7 +136,7 @@ public function form_edit($id) { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_edit_form($user))); + print $this->_get_edit_form($user); } public function form_change_password($id) { @@ -145,7 +145,7 @@ public function form_change_password($id) { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_change_password_form($user))); + print $this->_get_change_password_form($user); } public function form_change_email($id) { @@ -154,7 +154,7 @@ public function form_change_email($id) { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_change_email_form($user))); + print $this->_get_change_email_form($user); } private function _get_change_password_form($user) { @@ -231,7 +231,7 @@ private function _add_locale_dropdown(&$form, $user=null) { $locales = array_merge(array("" => t("« none »")), $locales); $selected_locale = ($user && $user->locale) ? $user->locale : ""; $form->dropdown("locale") - ->label(t("Language Preference")) + ->label(t("Language preference")) ->options($locales) ->selected($selected_locale); } diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index 922b050bd7..0652b13c1b 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -35,7 +35,7 @@ public function index() { } public function form_edit() { - json::reply(array("form" => (string) watermark::get_edit_form())); + print watermark::get_edit_form(); } public function edit() { @@ -53,12 +53,12 @@ public function edit() { array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function form_delete() { - json::reply(array("form" => (string) watermark::get_delete_form())); + print watermark::get_delete_form(); } public function delete() { @@ -81,12 +81,12 @@ public function delete() { } json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function form_add() { - json::reply(array("form" => (string) watermark::get_add_form())); + print watermark::get_add_form(); } public function add() { @@ -120,7 +120,10 @@ public function add() { log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => rawurlencode((string) $form))); + // rawurlencode the results because the JS code that uploads the file buffers it in an + // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url + // encode it now, it passes through cleanly. See ticket #797. + json::reply(array("result" => "error", "html" => rawurlencode((string)$form))); } }