summaryrefslogtreecommitdiff
path: root/modules/gallery/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r--modules/gallery/controllers/admin.php2
-rw-r--r--modules/gallery/controllers/admin_dashboard.php1
-rw-r--r--modules/gallery/controllers/admin_maintenance.php1
-rw-r--r--modules/gallery/controllers/admin_modules.php1
-rw-r--r--modules/gallery/controllers/admin_movies.php72
-rw-r--r--modules/gallery/controllers/admin_theme_options.php2
-rw-r--r--modules/gallery/controllers/file_proxy.php21
-rw-r--r--modules/gallery/controllers/quick.php1
-rw-r--r--modules/gallery/controllers/upgrader.php1
-rw-r--r--modules/gallery/controllers/uploader.php156
10 files changed, 191 insertions, 67 deletions
diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php
index c9d944cc..b35a9299 100644
--- a/modules/gallery/controllers/admin.php
+++ b/modules/gallery/controllers/admin.php
@@ -55,7 +55,7 @@ class Admin_Controller extends Controller {
$method = "index";
}
- if (!method_exists($controller_name, $method)) {
+ if (!class_exists($controller_name) || !method_exists($controller_name, $method)) {
throw new Kohana_404_Exception();
}
diff --git a/modules/gallery/controllers/admin_dashboard.php b/modules/gallery/controllers/admin_dashboard.php
index 6bd36b07..53172109 100644
--- a/modules/gallery/controllers/admin_dashboard.php
+++ b/modules/gallery/controllers/admin_dashboard.php
@@ -26,6 +26,7 @@ class Admin_Dashboard_Controller extends Admin_Controller {
$view->sidebar = "<div id=\"g-admin-dashboard-sidebar\">" .
block_manager::get_html("dashboard_sidebar") .
"</div>";
+ $view->content->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php
index 23df33ee..32f20784 100644
--- a/modules/gallery/controllers/admin_maintenance.php
+++ b/modules/gallery/controllers/admin_maintenance.php
@@ -55,6 +55,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
->where("expiration", "<>", 0)
->where("expiration", "<=", time())
->execute();
+ module::deactivate_missing_modules();
}
/**
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index d13ec1c6..177a925d 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -26,6 +26,7 @@ class Admin_Modules_Controller extends Admin_Controller {
$view->page_title = t("Modules");
$view->content = new View("admin_modules.html");
$view->content->available = module::available();
+ $view->content->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/controllers/admin_movies.php b/modules/gallery/controllers/admin_movies.php
new file mode 100644
index 00000000..38fa44a5
--- /dev/null
+++ b/modules/gallery/controllers/admin_movies.php
@@ -0,0 +1,72 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2013 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 Admin_Movies_Controller extends Admin_Controller {
+ public function index() {
+ // Print screen from new form.
+ $form = $this->_get_admin_form();
+ $this->_print_view($form);
+ }
+
+ public function save() {
+ access::verify_csrf();
+ $form = $this->_get_admin_form();
+ if ($form->validate()) {
+ module::set_var("gallery", "movie_allow_uploads", $form->settings->allow_uploads->value);
+ if ($form->settings->rebuild_thumbs->value) {
+ graphics::mark_dirty(true, false, "movie");
+ }
+ // All done - redirect with message.
+ message::success(t("Movies settings updated successfully"));
+ url::redirect("admin/movies");
+ }
+ // Something went wrong - print view from existing form.
+ $this->_print_view($form);
+ }
+
+ private function _print_view($form) {
+ list ($ffmpeg_version, $ffmpeg_date) = movie::get_ffmpeg_version();
+ $ffmpeg_version = $ffmpeg_date ? "{$ffmpeg_version} ({$ffmpeg_date})" : $ffmpeg_version;
+ $ffmpeg_path = movie::find_ffmpeg();
+ $ffmpeg_dir = substr($ffmpeg_path, 0, strrpos($ffmpeg_path, "/"));
+
+ $view = new Admin_View("admin.html");
+ $view->page_title = t("Movies settings");
+ $view->content = new View("admin_movies.html");
+ $view->content->form = $form;
+ $view->content->ffmpeg_dir = $ffmpeg_dir;
+ $view->content->ffmpeg_version = $ffmpeg_version;
+ print $view;
+ }
+
+ private function _get_admin_form() {
+ $form = new Forge("admin/movies/save", "", "post", array("id" => "g-movies-admin-form"));
+ $group = $form->group("settings")->label(t("Settings"));
+ $group->dropdown("allow_uploads")
+ ->label(t("Allow movie uploads into Gallery (does not affect existing movies)"))
+ ->options(array("autodetect"=>t("only if FFmpeg is detected (default)"),
+ "always"=>t("always"), "never"=>t("never")))
+ ->selected(module::get_var("gallery", "movie_allow_uploads", "autodetect"));
+ $group->checkbox("rebuild_thumbs")
+ ->label(t("Rebuild all movie thumbnails (once FFmpeg is installed, use this to update existing movie thumbnails)"))
+ ->checked(false); // always set as false
+ $form->submit("save")->value(t("Save"));
+ return $form;
+ }
+}
diff --git a/modules/gallery/controllers/admin_theme_options.php b/modules/gallery/controllers/admin_theme_options.php
index aead8bae..38d2b0a8 100644
--- a/modules/gallery/controllers/admin_theme_options.php
+++ b/modules/gallery/controllers/admin_theme_options.php
@@ -34,7 +34,6 @@ class Admin_Theme_Options_Controller extends Admin_Controller {
module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);
$thumb_size = $form->edit_theme->thumb_size->value;
- $thumb_dirty = false;
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule(
@@ -45,7 +44,6 @@ class Admin_Theme_Options_Controller extends Admin_Controller {
}
$resize_size = $form->edit_theme->resize_size->value;
- $resize_dirty = false;
if (module::get_var("gallery", "resize_size") != $resize_size) {
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule(
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 7e5d0038..50f1aa26 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -66,24 +66,8 @@ class File_Proxy_Controller extends Controller {
throw $e;
}
- // If the last element is .album.jpg, pop that off since it's not a real item
- $path = preg_replace("|/.album.jpg$|", "", $path);
-
- $item = item::find_by_path($path);
- if (!$item->loaded()) {
- // We didn't turn it up. 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 movie file would
- // have been converted to a .jpg. So try some alternate types:
- if (preg_match('/.jpg$/', $path)) {
- foreach (legal_file::get_movie_extensions() as $ext) {
- $movie_path = preg_replace('/.jpg$/', ".$ext", $path);
- $item = item::find_by_path($movie_path);
- if ($item->loaded()) {
- break;
- }
- }
- }
- }
+ // Get the item model using the path and type (which corresponds to a var subdir)
+ $item = item::find_by_path($path, $type);
if (!$item->loaded()) {
$e = new Kohana_404_Exception();
@@ -162,7 +146,6 @@ class File_Proxy_Controller extends Controller {
// going to buffer up whatever file we're proxying (and it may be very large). This may
// affect embedding or systems with PHP's output_buffering enabled.
while (ob_get_level()) {
- Kohana_Log::add("error","".print_r(ob_get_level(),1));
if (!@ob_end_clean()) {
// ob_end_clean() can return false if the buffer can't be removed for some reason
// (zlib output compression buffers sometimes cause problems).
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 2ddf2a4b..4b21d9ee 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -41,7 +41,6 @@ class Quick_Controller extends Controller {
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
- unlink($tmpfile);
}
if (Input::instance()->get("page_type") == "collection") {
diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php
index d3c6e2ec..6b3a9ef6 100644
--- a/modules/gallery/controllers/upgrader.php
+++ b/modules/gallery/controllers/upgrader.php
@@ -46,6 +46,7 @@ class Upgrader_Controller extends Controller {
$view->available = module::available();
$view->failed = $failed ? explode(",", $failed) : array();
$view->done = $available_upgrades == 0;
+ $view->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 78437071..54e1476b 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -47,52 +47,25 @@ class Uploader_Controller extends Controller {
$form = $this->_get_add_form($album);
- // 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[" . implode(",", legal_file::get_extensions()) . "]");
-
- if ($form->validate() && $file_validation->validate()) {
- $temp_filename = upload::save("Filedata");
- Event::add("system.shutdown", create_function("", "unlink(\"$temp_filename\");"));
+ if ($form->validate()) {
+ // Uploadify puts the result in $_FILES["Filedata"] - process it.
try {
- $item = ORM::factory("item");
- $item->name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
- $item->title = item::convert_filename_to_title($item->name);
- $item->parent_id = $album->id;
- $item->set_data_file($temp_filename);
-
- $path_info = @pathinfo($temp_filename);
- if (array_key_exists("extension", $path_info) &&
- legal_file::get_movie_extensions($path_info["extension"])) {
- $item->type = "movie";
- $item->save();
- log::success("content", t("Added a movie"),
- html::anchor("movies/$item->id", t("view movie")));
- } else {
- $item->type = "photo";
- $item->save();
- log::success("content", t("Added a photo"),
- html::anchor("photos/$item->id", t("view photo")));
- }
+ list ($tmp_name, $name) = $this->_process_upload("Filedata");
+ } catch (Exception $e) {
+ header("HTTP/1.1 400 Bad Request");
+ print "ERROR: " . $e->getMessage();
+ return;
+ }
+ // We have a valid upload file (of unknown type) - build an item from it.
+ try {
+ $item = $this->_add_item($id, $tmp_name, $name);
module::event("add_photos_form_completed", $item, $form);
+ print "FILEID: $item->id";
} catch (Exception $e) {
- // The Flash uploader has no good way of reporting complex errors, so just keep it simple.
- Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
-
- // Ugh. I hate to use instanceof, But this beats catching the exception separately since
- // we mostly want to treat it the same way as all other exceptions
- if ($e instanceof ORM_Validation_Exception) {
- Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
- }
-
header("HTTP/1.1 500 Internal Server Error");
print "ERROR: " . $e->getMessage();
- return;
}
- print "FILEID: $item->id";
} else {
header("HTTP/1.1 400 Bad Request");
print "ERROR: " . t("Invalid upload");
@@ -107,27 +80,122 @@ class Uploader_Controller extends Controller {
(int)$success_count,
array("error" => (int)$error_count));
} else {
- print t2("Uploaded %count photo", "Uploaded %count photos", $success_count);}
+ print t2("Uploaded %count photo", "Uploaded %count photos", $success_count);
+ }
}
public function finish() {
access::verify_csrf();
-
batch::stop();
json::reply(array("result" => "success"));
}
- private function _get_add_form($album) {
+ private function _get_add_form($album) {
$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);
- $group = $form->group("actions");
- $group->uploadify_buttons("");
+ $group_actions = $form->group("actions");
+ $group_actions->uploadify_buttons("");
+ $inputs_before_event = array_keys($form->add_photos->inputs);
module::event("add_photos_form", $album, $form);
+ $inputs_after_event = array_keys($form->add_photos->inputs);
+
+ // For each new input in add_photos, attach JS to make uploadify update its value.
+ foreach (array_diff($inputs_after_event, $inputs_before_event) as $input) {
+ if (!$input) {
+ // Likely a script input - don't do anything with it.
+ continue;
+ }
+ $group->uploadify->script_data($input, $group->{$input}->value);
+ $group->script("")
+ ->text("$('input[name=\"$input\"]').change(function (event) {
+ $('#g-uploadify').uploadifySettings('scriptData', {'$input': $(this).val()});
+ });");
+ }
return $form;
}
+
+ /**
+ * Process the uploaded file. This handles the interface with Kohana's upload and validation
+ * code, and marks the new temp file for deletion on shutdown. It returns the temp file path
+ * (tmp_name) and filename (name), analogous to their respective $_FILES elements.
+ * If the upload is invalid, it will throw an exception. Note that no type-checking (e.g. jpg,
+ * mp4,...) is performed here.
+ * @TODO: consider moving this to a common controller which is extended by various uploaders.
+ *
+ * @param string name of $_FILES input
+ * @return array array($tmp_name, $name)
+ */
+ private function _process_upload($file) {
+ // Validate file data. At this point, any file extension is still valid.
+ $file_validation = new Validation($_FILES);
+ $file_validation->add_rules($file, "upload::valid", "upload::required");
+ if (!$file_validation->validate()) {
+ throw new Exception(t("Invalid upload"));
+ }
+
+ // Save temp file and mark for deletion when done.
+ $tmp_name = upload::save($file);
+ system::delete_later($tmp_name);
+
+ // Get uploaded filename. This is different than tmp_name since it hasn't been uniquified.
+ $name = $_FILES[$file]["name"];
+
+ return array($tmp_name, $name);
+ }
+
+ /**
+ * Add photo or movie from upload. Once we have a valid file, this generates an item model
+ * from it. It returns the item model on success, and throws an exception and adds log entries
+ * on failure.
+ * @TODO: consider moving this to a common controller which is extended by various uploaders.
+ *
+ * @param int parent album id
+ * @param string temp file path (analogous to $_FILES[...]["tmp_name"])
+ * @param string filename (analogous to $_FILES[...]["name"])
+ * @return object new item model
+ */
+ private function _add_item($album_id, $tmp_name, $name) {
+ $extension = pathinfo($name, PATHINFO_EXTENSION);
+
+ try {
+ $item = ORM::factory("item");
+ $item->name = $name;
+ $item->title = item::convert_filename_to_title($name);
+ $item->parent_id = $album_id;
+ $item->set_data_file($tmp_name);
+
+ if (!$extension) {
+ throw new Exception(t("Uploaded file has no extension"));
+ } else if (legal_file::get_photo_extensions($extension)) {
+ $item->type = "photo";
+ $item->save();
+ log::success("content", t("Added a photo"),
+ html::anchor("photos/$item->id", t("view photo")));
+ } else if (movie::allow_uploads() && legal_file::get_movie_extensions($extension)) {
+ $item->type = "movie";
+ $item->save();
+ log::success("content", t("Added a movie"),
+ html::anchor("movies/$item->id", t("view movie")));
+ } else {
+ throw new Exception(t("Uploaded file has illegal extension"));
+ }
+ } catch (Exception $e) {
+ // Log errors then re-throw exception.
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+
+ // If we have a validation error, add an additional log entry.
+ if ($e instanceof ORM_Validation_Exception) {
+ Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
+ }
+
+ throw $e;
+ }
+
+ return $item;
+ }
}