summaryrefslogtreecommitdiff
path: root/modules/gallery/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r--modules/gallery/controllers/admin.php6
-rw-r--r--modules/gallery/controllers/admin_advanced_settings.php2
-rw-r--r--modules/gallery/controllers/admin_languages.php4
-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/albums.php10
-rw-r--r--modules/gallery/controllers/file_proxy.php11
-rw-r--r--modules/gallery/controllers/l10n_client.php2
-rw-r--r--modules/gallery/controllers/login.php7
-rw-r--r--modules/gallery/controllers/maintenance.php24
-rw-r--r--modules/gallery/controllers/move.php4
-rw-r--r--modules/gallery/controllers/movies.php6
-rw-r--r--modules/gallery/controllers/photos.php10
-rw-r--r--modules/gallery/controllers/quick.php56
-rw-r--r--modules/gallery/controllers/reauthenticate.php41
-rw-r--r--modules/gallery/controllers/uploader.php (renamed from modules/gallery/controllers/flash_uploader.php)12
-rw-r--r--modules/gallery/controllers/user_profile.php4
18 files changed, 120 insertions, 111 deletions
diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php
index 40dd260b..8fc5432d 100644
--- a/modules/gallery/controllers/admin.php
+++ b/modules/gallery/controllers/admin.php
@@ -78,14 +78,16 @@ 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) {
- if (request::method() == "get" && !request::is_ajax()) {
+ if (request::method() == "get") {
// 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 6f4e9403..cf197743 100644
--- a/modules/gallery/controllers/admin_advanced_settings.php
+++ b/modules/gallery/controllers/admin_advanced_settings.php
@@ -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 0f134fcd..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() {
@@ -109,7 +109,7 @@ class Admin_Languages_Controller extends Admin_Controller {
private function _share_translations_form() {
$form = new Forge("admin/languages/share", "", "post", array("id" => "g-share-translations-form"));
$group = $form->group("sharing")
- ->label(t("Sharing your own translations with the Gallery community is easy. Please do!"));
+ ->label("Translations API Key");
$api_key = l10n_client::api_key();
$server_link = l10n_client::server_api_key_url();
$group->input("api_key")
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php
index d6a2d191..a9cc933c 100644
--- a/modules/gallery/controllers/admin_maintenance.php
+++ b/modules/gallery/controllers/admin_maintenance.php
@@ -211,19 +211,25 @@ 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)));
}
}
+
+ public function maintenance_mode($value) {
+ access::verify_csrf();
+ module::set_var("gallery", "maintenance_mode", $value);
+ url::redirect("admin/maintenance");
+ }
}
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/albums.php b/modules/gallery/controllers/albums.php
index eaa09be5..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));
}
}
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 32690fc0..15b4279f 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -72,10 +72,10 @@ class File_Proxy_Controller extends Controller {
// necessary, it's easily resurrected.
// If we're looking for a .jpg then it's it's possible that we're requesting the thumbnail
- // for a movie. In that case, the .flv or .mp4 file would have been converted to a .jpg.
- // So try some alternate types:
+ // for a movie. In that case, the .flv, .mp4 or .m4v file would have been converted to a
+ // .jpg. So try some alternate types:
if (preg_match('/.jpg$/', $path)) {
- foreach (array("flv", "mp4") as $ext) {
+ foreach (array("flv", "mp4", "m4v") as $ext) {
$movie_path = preg_replace('/.jpg$/', ".$ext", $encoded_path);
$item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find();
if ($item->loaded()) {
@@ -131,10 +131,7 @@ class File_Proxy_Controller extends Controller {
} else {
header("Content-Type: $item->mime_type");
}
-
Kohana::close_buffers(false);
- $fd = fopen($file, "rb");
- fpassthru($fd);
- fclose($fd);
+ readfile($file);
}
}
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 2b60316b..62d33345 100644
--- a/modules/gallery/controllers/login.php
+++ b/modules/gallery/controllers/login.php
@@ -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/maintenance.php b/modules/gallery/controllers/maintenance.php
deleted file mode 100644
index 27673ff0..00000000
--- a/modules/gallery/controllers/maintenance.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?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 Maintenance_Controller extends Controller {
- function index() {
- print new View("maintenance.html");
- }
-} \ No newline at end of file
diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php
index f8b85b6f..7b2d6165 100644
--- a/modules/gallery/controllers/move.php
+++ b/modules/gallery/controllers/move.php
@@ -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 16d22d90..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));
}
}
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index f336d07c..8377e6c7 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -24,9 +24,9 @@ class Photos_Controller extends Items_Controller {
// sure that we're actually receiving an object
throw new Kohana_404_Exception();
}
-
+
access::required("view", $photo);
-
+
$where = array(array("type", "!=", "album"));
$position = $photo->parent()->get_position($photo, $where);
if ($position > 1) {
@@ -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));
}
}
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 6cfbbc62..fee601d9 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -46,23 +46,24 @@ class Quick_Controller extends Controller {
graphics::generate($item);
- $parent = $item->parent();
- // @todo: this is an inadequate way to regenerate the parent's thumbnail after rotation.
- if ($parent->album_cover_item_id == $item->id) {
- copy($item->thumb_path(), $parent->thumb_path());
- $parent->thumb_width = $item->thumb_width;
- $parent->thumb_height = $item->thumb_height;
- $parent->save();
+ // @todo: this is an inadequate way to regenerate album cover thumbnails after rotation.
+ foreach (ORM::factory("item")
+ ->where("album_cover_item_id", "=", $item->id)
+ ->find_all() as $target) {
+ copy($item->thumb_path(), $target->thumb_path());
+ $target->thumb_width = $item->thumb_width;
+ $target->thumb_height = $item->thumb_height;
+ $target->save();
}
}
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));
@@ -82,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) {
@@ -90,17 +91,10 @@ class Quick_Controller extends Controller {
access::required("view", $item);
access::required("edit", $item);
- if ($item->is_album()) {
- print t(
- "Delete the album <b>%title</b>? All photos and movies in the album will also be deleted.",
- array("title" => html::purify($item->title)));
- } else {
- print t("Are you sure you want to delete <b>%title</b>?",
- array("title" => html::purify($item->title)));
- }
-
- $form = item::get_delete_form($item);
- print $form;
+ $v = new View("quick_delete_confirm.html");
+ $v->item = $item;
+ $v->form = item::get_delete_form($item);
+ print $v;
}
public function delete($id) {
@@ -116,14 +110,24 @@ class Quick_Controller extends Controller {
}
$parent = $item->parent();
- $item->delete();
+
+ if ($item->is_album()) {
+ // Album delete will trigger deletes for all children. Do this in a batch so that we can be
+ // smart about notifications, album cover updates, etc.
+ batch::start();
+ $item->delete();
+ batch::stop();
+ } else {
+ $item->delete();
+ }
message::success($msg);
- if (Input::instance()->get("page_type") == "collection") {
- print json_encode(array("result" => "success", "reload" => 1));
+ $from_id = Input::instance()->get("from_id");
+ if (Input::instance()->get("page_type") == "collection" &&
+ $from_id != $id /* deleted the item we were viewing */) {
+ 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()));
}
}
diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php
index acb27f6a..0486c0fe 100644
--- a/modules/gallery/controllers/reauthenticate.php
+++ b/modules/gallery/controllers/reauthenticate.php
@@ -18,11 +18,21 @@
* 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();
}
- return self::_show_form(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());
+ }
}
public function auth() {
@@ -35,14 +45,23 @@ class Reauthenticate_Controller extends Controller {
$valid = $form->validate();
$user = identity::active_user();
if ($valid) {
- message::success(t("Successfully re-authenticated!"));
module::event("user_auth", $user);
- url::redirect($form->continue_url->value);
+ if (!request::is_ajax()) {
+ message::success(t("Successfully re-authenticated!"));
+ }
+ url::redirect(Session::instance()->get_once("continue_url"));
} else {
$name = $user->name;
log::warning("user", t("Failed re-authentication for %name", array("name" => $name)));
module::event("user_auth_failed", $name);
- return 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 {
+ self::_show_form($form);
+ }
}
}
@@ -52,17 +71,17 @@ class Reauthenticate_Controller extends Controller {
$view->content = new View("reauthenticate.html");
$view->content->form = $form;
$view->content->user_name = identity::active_user()->name;
+
print $view;
}
private static function _form() {
$form = new Forge("reauthenticate/auth", "", "post", array("id" => "g-reauthenticate-form"));
- $form->set_attr('class', "g-narrow");
- $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin"));
+ $form->set_attr("class", "g-narrow");
$group = $form->group("reauthenticate")->label(t("Re-authenticate"));
$group->password("password")->label(t("Password"))->id("g-password")->class(null)
->callback("auth::validate_too_many_failed_auth_attempts")
- ->callback("user::valid_password")
+ ->callback("Reauthenticate_Controller::valid_password")
->error_messages("invalid_password", t("Incorrect password"))
->error_messages(
"too_many_failed_auth_attempts",
@@ -70,4 +89,10 @@ class Reauthenticate_Controller extends Controller {
$group->submit("")->value(t("Submit"));
return $form;
}
+
+ static function valid_password($password_input) {
+ if (!identity::is_correct_password(identity::active_user(), $password_input->value)) {
+ $password_input->add_error("invalid_password", 1);
+ }
+ }
}
diff --git a/modules/gallery/controllers/flash_uploader.php b/modules/gallery/controllers/uploader.php
index f7da5124..87520032 100644
--- a/modules/gallery/controllers/flash_uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -17,8 +17,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Flash_Uploader_Controller extends Controller {
- public function app($id) {
+class Uploader_Controller extends Controller {
+ public function index($id) {
$item = ORM::factory("item", $id);
access::required("view", $item);
access::required("add", $item);
@@ -50,7 +50,7 @@ class Flash_Uploader_Controller extends Controller {
// Uploadify adds its own field to the form, so validate that separately.
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
- "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
+ "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4,m4v]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
@@ -63,7 +63,7 @@ class Flash_Uploader_Controller extends Controller {
$path_info = @pathinfo($temp_filename);
if (array_key_exists("extension", $path_info) &&
- in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
+ in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v"))) {
$item->type = "movie";
$item->save();
log::success("content", t("Added a movie"),
@@ -105,11 +105,11 @@ class Flash_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) {
- $form = new Forge("flash_uploader/finish", "", "post", array("id" => "g-add-photos-form"));
+ $form = new Forge("uploader/finish", "", "post", array("id" => "g-add-photos-form"));
$group = $form->group("add_photos")
->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title))));
$group->uploadify("uploadify")->album($album);
diff --git a/modules/gallery/controllers/user_profile.php b/modules/gallery/controllers/user_profile.php
index c064e791..726d3e51 100644
--- a/modules/gallery/controllers/user_profile.php
+++ b/modules/gallery/controllers/user_profile.php
@@ -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));
}
}
}