summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin.php5
-rw-r--r--modules/gallery/controllers/admin_advanced_settings.php4
-rw-r--r--modules/gallery/controllers/admin_languages.php2
-rw-r--r--modules/gallery/controllers/admin_maintenance.php28
-rw-r--r--modules/gallery/controllers/admin_modules.php2
-rw-r--r--modules/gallery/controllers/admin_sidebar.php2
-rw-r--r--modules/gallery/controllers/admin_themes.php2
-rw-r--r--modules/gallery/controllers/albums.php14
-rw-r--r--modules/gallery/controllers/l10n_client.php2
-rw-r--r--modules/gallery/controllers/login.php9
-rw-r--r--modules/gallery/controllers/move.php6
-rw-r--r--modules/gallery/controllers/movies.php8
-rw-r--r--modules/gallery/controllers/permissions.php2
-rw-r--r--modules/gallery/controllers/photos.php8
-rw-r--r--modules/gallery/controllers/quick.php15
-rw-r--r--modules/gallery/controllers/reauthenticate.php21
-rw-r--r--modules/gallery/controllers/uploader.php5
-rw-r--r--modules/gallery/controllers/user_profile.php6
-rw-r--r--modules/gallery/helpers/json.php33
19 files changed, 107 insertions, 67 deletions
diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php
index eacacb28..8fc5432d 100644
--- a/modules/gallery/controllers/admin.php
+++ b/modules/gallery/controllers/admin.php
@@ -78,7 +78,7 @@ class Admin_Controller extends Controller {
$result->location = url::abs_site("");
}
- print json_encode($result);
+ json::reply($result);
}
private static function _prompt_for_reauth($controller_name, $args) {
@@ -86,7 +86,8 @@ class Admin_Controller extends Controller {
// 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/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php
index 2bbbdf50..cf197743 100644
--- a/modules/gallery/controllers/admin_advanced_settings.php
+++ b/modules/gallery/controllers/admin_advanced_settings.php
@@ -39,7 +39,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller {
$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));
+ print $form;
}
public function save($module_name, $var_name) {
@@ -50,6 +50,6 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller {
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 2e993816..573ededf 100644
--- a/modules/gallery/controllers/admin_languages.php
+++ b/modules/gallery/controllers/admin_languages.php
@@ -51,7 +51,7 @@ class Admin_Languages_Controller extends Admin_Controller {
}
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 489f5d54..3567b4f0 100644
--- a/modules/gallery/controllers/admin_maintenance.php
+++ b/modules/gallery/controllers/admin_maintenance.php
@@ -64,7 +64,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
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));
+ print $view;
}
/**
@@ -86,7 +86,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
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));
+ print $view;
}
/**
@@ -103,7 +103,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
$view = new View("admin_maintenance_show_log.html");
$view->task = $task;
- print json_encode(array("form" => (string) $view));
+ print $view;
}
/**
@@ -211,19 +211,19 @@ class Admin_Maintenance_Controller extends Admin_Controller {
break;
}
// Using sprintf("%F") to avoid comma as decimal separator.
- print json_encode(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")));
+ 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")));
} else {
- print json_encode(array("result" => "in_progress",
- "task" => array(
- "percent_complete" => sprintf("%F", $task->percent_complete),
- "status" => (string) $task->status,
- "done" => (bool) $task->done)));
+ json::reply(array("result" => "in_progress",
+ "task" => array(
+ "percent_complete" => sprintf("%F", $task->percent_complete),
+ "status" => (string) $task->status,
+ "done" => (bool) $task->done)));
}
}
}
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index bf638a37..f5af9a5a 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -57,7 +57,7 @@ class Admin_Modules_Controller extends Admin_Controller {
$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 fb857e4e..2e49097a 100644
--- a/modules/gallery/controllers/admin_sidebar.php
+++ b/modules/gallery/controllers/admin_sidebar.php
@@ -50,7 +50,7 @@ class Admin_Sidebar_Controller extends Admin_Controller {
$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/admin_themes.php b/modules/gallery/controllers/admin_themes.php
index b1bd438f..e59eadaf 100644
--- a/modules/gallery/controllers/admin_themes.php
+++ b/modules/gallery/controllers/admin_themes.php
@@ -52,7 +52,7 @@ class Admin_Themes_Controller extends Admin_Controller {
} else {
$view->url = item::root()->url("theme=$theme_name");
}
- print json_encode(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 8aed1341..f3f5dee3 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -113,9 +113,9 @@ class Albums_Controller extends Items_Controller {
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));
+ print $form;
}
}
@@ -153,13 +153,13 @@ class Albums_Controller extends Items_Controller {
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", "html" => (string)$form));
}
}
@@ -168,7 +168,7 @@ class Albums_Controller extends Items_Controller {
access::required("view", $album);
access::required("add", $album);
- print json_encode(array("form" => (string) album::get_add_form($album)));
+ print album::get_add_form($album);
}
public function form_edit($album_id) {
@@ -176,6 +176,6 @@ class Albums_Controller extends Items_Controller {
access::required("view", $album);
access::required("edit", $album);
- print json_encode(array("form" => (string) album::get_edit_form($album)));
+ print album::get_edit_form($album);
}
}
diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php
index d5b322ef..6833a9ae 100644
--- a/modules/gallery/controllers/l10n_client.php
+++ b/modules/gallery/controllers/l10n_client.php
@@ -91,7 +91,7 @@ class L10n_Client_Controller extends Controller {
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 b823504b..62d33345 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));
+ print $view;
}
public function auth_ajax() {
@@ -30,10 +30,11 @@ class Login_Controller extends Controller {
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));
+ $view = new View("login_ajax.html");
+ $view->form = $form;
+ json::reply(array("result" => "error", "html" => (string)$view));
}
}
diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php
index a99ef341..7b2d6165 100644
--- a/modules/gallery/controllers/move.php
+++ b/modules/gallery/controllers/move.php
@@ -26,7 +26,7 @@ class Move_Controller extends Controller {
$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));
+ print $view;
}
public function save($source_id) {
@@ -41,9 +41,7 @@ class Move_Controller extends Controller {
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 c18dbcde..02d2a497 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -87,13 +87,13 @@ class Movies_Controller extends Items_Controller {
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", "html" => (string) $form));
}
}
@@ -102,6 +102,6 @@ class Movies_Controller extends Items_Controller {
access::required("view", $movie);
access::required("edit", $movie);
- print json_encode(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 8fdda7b2..fc06cb44 100644
--- a/modules/gallery/controllers/permissions.php
+++ b/modules/gallery/controllers/permissions.php
@@ -33,7 +33,7 @@ class Permissions_Controller extends Controller {
$view->parents = $item->parents();
$view->form = $this->_get_form($item);
- print json_encode(array("form" => (string) $view));
+ print $view;
}
function form($id) {
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 9f17cebb..8377e6c7 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -87,13 +87,13 @@ class Photos_Controller extends Items_Controller {
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", "html" => (string)$form));
}
}
@@ -102,6 +102,6 @@ class Photos_Controller extends Items_Controller {
access::required("view", $photo);
access::required("edit", $photo);
- print json_encode(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 253a279b..fee601d9 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -58,12 +58,12 @@ class Quick_Controller extends Controller {
}
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 @@ class Quick_Controller extends Controller {
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 @@ class Quick_Controller extends Controller {
$v = new View("quick_delete_confirm.html");
$v->item = $item;
$v->form = item::get_delete_form($item);
- print json_encode(array("form" => (string) $v));
+ print $v;
}
public function delete($id) {
@@ -125,10 +125,9 @@ class Quick_Controller extends Controller {
$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",
- "location" => $parent->url()));
+ json::reply(array("result" => "success", "location" => $parent->url()));
}
}
@@ -154,6 +153,6 @@ class Quick_Controller extends Controller {
// 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));
+ print $form;
}
}
diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php
index 3cff2b6a..0486c0fe 100644
--- a/modules/gallery/controllers/reauthenticate.php
+++ b/modules/gallery/controllers/reauthenticate.php
@@ -18,12 +18,18 @@
* 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();
}
- if (request::is_ajax()) {
- print json_encode(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();
+ $v->user_name = identity::active_user()->name;
+ print $v;
} else {
self::_show_form(self::_form());
}
@@ -48,10 +54,13 @@ class Reauthenticate_Controller extends Controller {
$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("html" => (string)$v));
} else {
- print json_encode(array("form" => (string) $form));
+ self::_show_form($form);
}
}
}
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 38e22cee..87520032 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -26,8 +26,7 @@ class Uploader_Controller extends Controller {
$item = $item->parent();
}
- print json_encode(array("form" => (string)$this->_get_add_form($item)));
- //print $this->_get_add_form($item);
+ print $this->_get_add_form($item);
}
public function start() {
@@ -106,7 +105,7 @@ class Uploader_Controller extends Controller {
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 431918ff..726d3e51 100644
--- a/modules/gallery/controllers/user_profile.php
+++ b/modules/gallery/controllers/user_profile.php
@@ -44,7 +44,7 @@ class User_Profile_Controller extends Controller {
public function contact($id) {
$user = identity::lookup_user($id);
- print json_encode(array("form" => (string) user_profile::get_contact_form($user)));
+ print user_profile::get_contact_form($user);
}
public function send($id) {
@@ -61,9 +61,9 @@ class User_Profile_Controller extends Controller {
->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", "html" => (string)$form));
}
}
}
diff --git a/modules/gallery/helpers/json.php b/modules/gallery/helpers/json.php
new file mode 100644
index 00000000..a39db27a
--- /dev/null
+++ b/modules/gallery/helpers/json.php
@@ -0,0 +1,33 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2010 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class json_Core {
+ /**
+ * JSON Encode a reply to the browser and set the content type to specify that it's a JSON
+ * payload.
+ *
+ * @param mixed $message string or object to json encode and print
+ */
+ static function reply($message) {
+ if (!headers_sent()) {
+ header("Content-Type: application/json; charset=" . Kohana::CHARSET);
+ }
+ print json_encode($message);
+ }
+} \ No newline at end of file