summaryrefslogtreecommitdiff
path: root/modules/gallery/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r--modules/gallery/controllers/admin_graphics.php39
-rw-r--r--modules/gallery/controllers/admin_languages.php8
-rw-r--r--modules/gallery/controllers/albums.php27
-rw-r--r--modules/gallery/controllers/combined.php5
-rw-r--r--modules/gallery/controllers/file_proxy.php43
-rw-r--r--modules/gallery/controllers/movies.php14
-rw-r--r--modules/gallery/controllers/packager.php8
-rw-r--r--modules/gallery/controllers/photos.php16
-rw-r--r--modules/gallery/controllers/quick.php15
-rw-r--r--modules/gallery/controllers/simple_uploader.php26
10 files changed, 89 insertions, 112 deletions
diff --git a/modules/gallery/controllers/admin_graphics.php b/modules/gallery/controllers/admin_graphics.php
index 72f8d8e1..c59dd38e 100644
--- a/modules/gallery/controllers/admin_graphics.php
+++ b/modules/gallery/controllers/admin_graphics.php
@@ -21,41 +21,24 @@ class Admin_Graphics_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
$view->content = new View("admin_graphics.html");
- $view->content->available = "";
-
- $tk = new ArrayObject(graphics::detect_toolkits(), ArrayObject::ARRAY_AS_PROPS);
- $active = module::get_var("gallery", "graphics_toolkit", "none");
- foreach (array("gd", "imagemagick", "graphicsmagick", "none") as $id) {
- if ($id == $active) {
- $view->content->active = new View("admin_graphics_$id.html");
- $view->content->active->tk = $tk;
- $view->content->active->is_active = true;
- } else if ($id != "none") {
- $v = new View("admin_graphics_$id.html");
- $v->tk = $tk;
- $v->is_active = false;
- $view->content->available .= $v;
- }
- }
-
+ $view->content->tk = graphics::detect_toolkits();
+ $view->content->active = module::get_var("gallery", "graphics_toolkit", "none");
print $view;
}
- public function choose($toolkit) {
+ public function choose($toolkit_id) {
access::verify_csrf();
- if ($toolkit != module::get_var("gallery", "graphics_toolkit")) {
- module::set_var("gallery", "graphics_toolkit", $toolkit);
-
- $toolkit_info = graphics::detect_toolkits();
- if ($toolkit == "graphicsmagick" || $toolkit == "imagemagick") {
- module::set_var("gallery", "graphics_toolkit_path", $toolkit_info[$toolkit]);
- }
+ if ($toolkit_id != module::get_var("gallery", "graphics_toolkit")) {
+ $tk = graphics::detect_toolkits();
+ module::set_var("gallery", "graphics_toolkit", $toolkit_id);
+ module::set_var("gallery", "graphics_toolkit_path", $tk->$toolkit_id->dir);
site_status::clear("missing_graphics_toolkit");
- message::success(t("Updated Graphics Toolkit"));
- log::success("graphics", t("Changed graphics toolkit to: %toolkit",
- array("toolkit" => $toolkit)));
+
+ $msg = t("Changed graphics toolkit to: %toolkit", array("toolkit" => $tk->$toolkit_id->name));
+ message::success($msg);
+ log::success("graphics", $msg);
}
url::redirect("admin/graphics");
diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php
index 4639de89..ae90ad07 100644
--- a/modules/gallery/controllers/admin_languages.php
+++ b/modules/gallery/controllers/admin_languages.php
@@ -36,7 +36,7 @@ class Admin_Languages_Controller extends Admin_Controller {
$form = $this->_languages_form();
if ($form->validate()) {
module::set_var("gallery", "default_locale", $form->choose_language->locale->value);
- locale::update_installed($form->choose_language->installed_locales->value);
+ locales::update_installed($form->choose_language->installed_locales->value);
message::success(t("Settings saved"));
}
url::redirect("admin/languages");
@@ -89,8 +89,8 @@ class Admin_Languages_Controller extends Admin_Controller {
}
private function _languages_form() {
- $all_locales = locale::available();
- $installed_locales = locale::installed();
+ $all_locales = locales::available();
+ $installed_locales = locales::installed();
$form = new Forge("admin/languages/save", "", "post", array("id" => "gLanguageSettingsForm"));
$group = $form->group("choose_language")
->label(t("Language settings"));
@@ -119,7 +119,7 @@ class Admin_Languages_Controller extends Admin_Controller {
private function _share_translations_form() {
$form = new Forge("admin/languages/share", "", "post", array("id" => "gShareTranslationsForm"));
$group = $form->group("sharing")
- ->label(t("Sharing you own translations with the Gallery community is easy. Please do!"));
+ ->label(t("Sharing your own translations with the Gallery community is easy. Please do!"));
$api_key = l10n_client::api_key();
$server_link = l10n_client::server_api_key_url();
$group->input("api_key")
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index d141d157..cdfa823d 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -122,7 +122,7 @@ class Albums_Controller extends Items_Controller {
print json_encode(
array(
"result" => "error",
- "form" => $form->__toString() . html::script("modules/gallery/js/albums_form_add.js")));
+ "form" => $form->__toString()));
}
}
@@ -174,29 +174,23 @@ class Albums_Controller extends Items_Controller {
->from("items")
->where("parent_id", $album->parent_id)
->where("id <>", $album->id)
- ->where("name", $form->edit_album->dirname->value)
+ ->where("name", $form->edit_item->dirname->value)
->count_records()) {
- $form->edit_album->dirname->add_error("conflict", 1);
+ $form->edit_item->dirname->add_error("conflict", 1);
$valid = false;
}
}
- // @todo
- // @todo we need to make sure that filename / dirname components can't contain a /
- // @todo
-
if ($valid) {
- $orig = clone $album;
- $album->title = $form->edit_album->title->value;
- $album->description = $form->edit_album->description->value;
- $album->sort_column = $form->edit_album->sort_order->column->value;
- $album->sort_order = $form->edit_album->sort_order->direction->value;
+ $album->title = $form->edit_item->title->value;
+ $album->description = $form->edit_item->description->value;
+ $album->sort_column = $form->edit_item->sort_order->column->value;
+ $album->sort_order = $form->edit_item->sort_order->direction->value;
if ($album->id != 1) {
- $album->rename($form->edit_album->dirname->value);
+ $album->rename($form->edit_item->dirname->value);
}
$album->save();
-
- module::event("item_updated", $orig, $album);
+ module::event("item_edit_form_completed", $album, $form);
log::success("content", "Updated album", "<a href=\"albums/$album->id\">view</a>");
message::success(
@@ -222,8 +216,7 @@ class Albums_Controller extends Items_Controller {
switch ($this->input->get("type")) {
case "album":
- print album::get_add_form($album) .
- html::script("modules/gallery/js/albums_form_add.js");
+ print album::get_add_form($album);
break;
case "photo":
diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php
index 925d052d..9a790fdf 100644
--- a/modules/gallery/controllers/combined.php
+++ b/modules/gallery/controllers/combined.php
@@ -60,14 +60,15 @@ class Combined_Controller extends Controller {
$cache = Cache::instance();
$use_gzip = function_exists("gzencode") &&
- (strpos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false);
+ stripos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false &&
+ (int) ini_get("zlib.output_compression") === 0;
+
if ($use_gzip && $content = $cache->get("{$key}_gz")) {
header("Content-Encoding: gzip");
} else {
// Fall back to non-gzipped if we have to
$content = $cache->get($key);
}
-
if (empty($content)) {
Kohana::show_404();
}
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 0d64bcd9..8cb90c50 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -32,8 +32,9 @@ class File_Proxy_Controller extends Controller {
$request_uri = $this->input->server("REQUEST_URI");
$request_uri = preg_replace("/\?.*/", "", $request_uri);
- // Unescape %7E ("~") and %20 (" ")
- $request_uri = str_replace(array("%7E", "%20"), array("~", " "), $request_uri);
+ // Unescape %7E (~), %20 ( ) and %27 (')
+ // @todo: figure out why we have to do this and unescape everything appropriate
+ $request_uri = str_replace(array("%7E", "%20", "%27"), array("~", " ", "'"), $request_uri);
// var_uri: http://example.com/gallery3/var/
$var_uri = url::file("var/");
@@ -62,21 +63,20 @@ class File_Proxy_Controller extends Controller {
// We now have the relative path to the item. Search for it in the path cache
$item = ORM::factory("item")->where("relative_path_cache", $path)->find();
if (!$item->loaded) {
- // We didn't turn it up. This may mean that the path cache is out of date, so look it up
- // the hard way.
- //
- // Find all items that match the level and name, then iterate over those to find a match.
- // In most cases we'll get it in one. Note that for the level calculation, we just count the
- // size of $paths.
- $paths = explode("/", $path);
- $count = count($paths);
- foreach (ORM::factory("item")
- ->where("name", $paths[$count - 1])
- ->where("level", $count + 1)
- ->find_all() as $match) {
- if ($match->relative_path() == $path) {
- $item = $match;
- break;
+ // We didn't turn it up. It's possible that the relative_path_cache is out of date here.
+ // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be
+ // 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:
+ if (preg_match('/.jpg$/', $path)) {
+ foreach (array("flv", "mp4") as $ext) {
+ $movie_path = preg_replace('/.jpg$/', ".$ext", $path);
+ $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find();
+ if ($item->loaded) {
+ break;
+ }
}
}
}
@@ -115,8 +115,13 @@ class File_Proxy_Controller extends Controller {
// We don't need to save the session for this request
Session::abort_save();
- // Dump out the image
- header("Content-Type: $item->mime_type");
+ // Dump out the image. If the item is a movie, then its thumbnail will be a JPG.
+ if (in_array($item->mime_type, array("video/x-flv", "video/mp4"))) {
+ header("Content-type: image/jpeg");
+ } else {
+ header("Content-Type: $item->mime_type");
+ }
+
Kohana::close_buffers(false);
$fd = fopen($file, "rb");
fpassthru($fd);
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 30a5d78c..c8227d74 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -77,21 +77,19 @@ class Movies_Controller extends Items_Controller {
->from("items")
->where("parent_id", $photo->parent_id)
->where("id <>", $photo->id)
- ->where("name", $form->edit_photo->filename->value)
+ ->where("name", $form->edit_item->filename->value)
->count_records()) {
- $form->edit_photo->filename->add_error("conflict", 1);
+ $form->edit_item->filename->add_error("conflict", 1);
$valid = false;
}
}
if ($valid) {
- $orig = clone $photo;
- $photo->title = $form->edit_photo->title->value;
- $photo->description = $form->edit_photo->description->value;
- $photo->rename($form->edit_photo->filename->value);
+ $photo->title = $form->edit_item->title->value;
+ $photo->description = $form->edit_item->description->value;
+ $photo->rename($form->edit_item->filename->value);
$photo->save();
-
- module::event("item_updated", $orig, $photo);
+ module::event("item_edit_form_completed", $photo, $form);
log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
message::success(
diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php
index da0a7983..fbb1d07d 100644
--- a/modules/gallery/controllers/packager.php
+++ b/modules/gallery/controllers/packager.php
@@ -98,7 +98,7 @@ class Packager_Controller extends Controller {
print "$sql_file is not writeable";
return;
}
- $command = "mysqldump --compact --add-drop-table -h{$conn['host']} " .
+ $command = "mysqldump --compact --skip-extended-insert --add-drop-table -h{$conn['host']} " .
"-u{$conn['user']} $pass {$conn['database']} > $sql_file";
exec($command, $output, $status);
if ($status) {
@@ -123,6 +123,10 @@ class Packager_Controller extends Controller {
// Normalize dates
$line = preg_replace("/,$root_created_timestamp,/", ",UNIX_TIMESTAMP(),", $line);
$line = preg_replace("/,$root_updated_timestamp,/", ",UNIX_TIMESTAMP(),", $line);
+
+ // Remove ENGINE= specifications
+ $line = preg_replace("/ENGINE=\S+ /", "", $line);
+
$buf .= $line;
}
$fd = fopen($sql_file, "wb");
@@ -153,7 +157,7 @@ class Packager_Controller extends Controller {
$paths[] = "VARPATH . \"" . substr($name, strlen(VARPATH)) . "\"";
} else {
// @todo: serialize non-directories
- print "Unknown file: $name";
+ print "IGNORING FILE: $name\n";
return;
}
}
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 6a62e859..8ee24da8 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -63,28 +63,26 @@ class Photos_Controller extends Items_Controller {
$form = photo::get_edit_form($photo);
if ($valid = $form->validate()) {
- if ($form->edit_photo->filename->value != $photo->name) {
+ if ($form->edit_item->filename->value != $photo->name) {
// Make sure that there's not a conflict
if (Database::instance()
->from("items")
->where("parent_id", $photo->parent_id)
->where("id <>", $photo->id)
- ->where("name", $form->edit_photo->filename->value)
+ ->where("name", $form->edit_item->filename->value)
->count_records()) {
- $form->edit_photo->filename->add_error("conflict", 1);
+ $form->edit_item->filename->add_error("conflict", 1);
$valid = false;
}
}
}
if ($valid) {
- $orig = clone $photo;
- $photo->title = $form->edit_photo->title->value;
- $photo->description = $form->edit_photo->description->value;
- $photo->rename($form->edit_photo->filename->value);
+ $photo->title = $form->edit_item->title->value;
+ $photo->description = $form->edit_item->description->value;
+ $photo->rename($form->edit_item->filename->value);
$photo->save();
-
- module::event("item_updated", $orig, $photo);
+ module::event("item_edit_form_completed", $photo, $form);
log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
message::success(
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 53af2ba6..82176e02 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -18,20 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Quick_Controller extends Controller {
- public function pane($id) {
- $item = model_cache::get("item", $id);
- if (!access::can("view", $item) || !access::can("edit", $item)) {
- return "";
- }
-
- $view = new View("quick_pane.html");
- $page_type = Input::instance()->get("page_type");
- $view->button_list = gallery_quick::get_quick_buttons($item, $page_type);
- $view->item = $item;
- $view->page_type = $page_type;
- print $view;
- }
-
public function rotate($id, $dir) {
access::verify_csrf();
$item = model_cache::get("item", $id);
@@ -127,6 +113,7 @@ class Quick_Controller extends Controller {
$msg = t("Deleted photo <b>%title</b>", array("title" => p::purify($item->title)));
}
+ $parent = $item->parent();
$item->delete();
message::success($msg);
diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php
index 713e30af..e7c0bd6f 100644
--- a/modules/gallery/controllers/simple_uploader.php
+++ b/modules/gallery/controllers/simple_uploader.php
@@ -43,7 +43,7 @@ class Simple_Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
- "Filedata", "upload::valid", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
+ "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
if ($file_validation->validate()) {
// SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
if (!batch::in_progress()) {
@@ -54,24 +54,32 @@ class Simple_Uploader_Controller extends Controller {
try {
$name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
$title = item::convert_filename_to_title($name);
- $path_info = pathinfo($temp_filename);
+ $path_info = @pathinfo($temp_filename);
if (array_key_exists("extension", $path_info) &&
in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
- $movie = movie::create($album, $temp_filename, $name, $title);
+ $item = movie::create($album, $temp_filename, $name, $title);
log::success("content", t("Added a movie"),
- html::anchor("movies/$movie->id", t("view movie")));
+ html::anchor("movies/$item->id", t("view movie")));
} else {
- $photo = photo::create($album, $temp_filename, $name, $title);
+ $item = photo::create($album, $temp_filename, $name, $title);
log::success("content", t("Added a photo"),
- html::anchor("photos/$photo->id", t("view photo")));
+ html::anchor("photos/$item->id", t("view photo")));
}
} catch (Exception $e) {
- unlink($temp_filename);
- throw $e;
+ Kohana::log("alert", $e->__toString());
+ if (file_exists($temp_filename)) {
+ unlink($temp_filename);
+ }
+ header("HTTP/1.1 500 Internal Server Error");
+ print "ERROR:" . $e->getMessage();
+ return;
}
unlink($temp_filename);
+ print "FILEID: $item->id";
+ } else {
+ header("HTTP/1.1 400 Bad Request");
+ print "ERROR: Invalid Upload";
}
- print "File Received";
}
public function finish() {