diff options
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/album.php | 5 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 33 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_error.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_graphics.php | 54 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 17 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 21 | ||||
-rw-r--r-- | modules/gallery/helpers/graphics.php | 95 | ||||
-rw-r--r-- | modules/gallery/helpers/movie.php | 30 | ||||
-rw-r--r-- | modules/gallery/helpers/photo.php | 5 |
9 files changed, 151 insertions, 111 deletions
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 9cd746d7..65868cf2 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -123,14 +123,15 @@ class album_Core { if ($parent->id != 1) { $group->input("dirname")->label(t("Directory Name"))->value($parent->name) ->rules("required") - ->error_messages("name_conflict", t("There is already a photo or album with this name")) + ->error_messages( + "name_conflict", t("There is already a movie, photo or album with this name")) ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The directory name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") ->error_messages("no_trailing_period", t("The directory name can't end in \".\"")); $group->input("slug")->label(t("Internet Address"))->value($parent->slug) ->error_messages( - "slug_conflict", t("There is already a photo or album with this internet address")) + "slug_conflict", t("There is already a movie, photo or album with this internet address")) ->callback("item::validate_url_safe") ->error_messages( "not_url_safe", diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 80ae65bd..d4f733e4 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -79,6 +79,20 @@ class gallery_Core { return date(module::get_var("gallery", "time_format", "H:i:s"), $timestamp); } + /** + * Provide a wrapper function for Kohana::find_file, that first strips the extension and + * then calls the Kohana::find_file supply that extension + * @param string directory to search in + * @param string filename to look for (without extension) + * @param boolean file required + * @return the file relative to the DOCROOT + */ + static function find_file($directory, $file, $required=false) { + $file_name = substr($file, 0, -strlen($ext = strrchr($file, '.'))); + $file_name = Kohana::find_file($directory, $file_name, $required, substr($ext, 1)); + return substr($file_name, strlen(DOCROOT)); + } + static function site_menu($menu, $theme) { if ($theme->page_type != "login") { $menu->append(Menu::factory("link") @@ -114,19 +128,32 @@ class gallery_Core { } } + switch ($item->type) { + case "album": + $option_text = t("Album options"); + $edit_text = t("Edit album"); + break; + case "movie": + $option_text = t("Movie options"); + $edit_text = t("Edit movie"); + break; + default: + $option_text = t("Photo options"); + $edit_text = t("Edit photo"); + } + $menu->append($options_menu = Menu::factory("submenu") ->id("options_menu") - ->label(t("Photo options"))); + ->label($option_text)); if ($item && ($can_edit || $can_add)) { if ($can_edit) { $options_menu->append(Menu::factory("dialog") ->id("edit_item") - ->label($item->is_album() ? t("Edit album") : t("Edit photo")) + ->label($edit_text) ->url(url::site("form/edit/{$item->type}s/$item->id"))); } if ($item->is_album()) { - $options_menu->label(t("Album options")); if ($can_edit) { $options_menu->append(Menu::factory("dialog") ->id("edit_permissions") diff --git a/modules/gallery/helpers/gallery_error.php b/modules/gallery/helpers/gallery_error.php index 91e05407..39568c93 100644 --- a/modules/gallery/helpers/gallery_error.php +++ b/modules/gallery/helpers/gallery_error.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_error_Core { - function error_handler($severity, $message, $filename, $lineno) { + static function error_handler($severity, $message, $filename, $lineno) { if (error_reporting() == 0) { return; } diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php new file mode 100644 index 00000000..f62fbf97 --- /dev/null +++ b/modules/gallery/helpers/gallery_graphics.php @@ -0,0 +1,54 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 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 gallery_graphics_Core { + /** + * Resize an image. Valid options are width, height and master. Master is one of the Image + * master dimension constants. + * + * @param string $input_file + * @param string $output_file + * @param array $options + */ + static function resize($input_file, $output_file, $options) { + graphics::init_toolkit(); + + module::event("graphics_resize", $input_file, $output_file, $options); + + if (@filesize($input_file) == 0) { + throw new Exception("@todo EMPTY_INPUT_FILE"); + } + + $dims = getimagesize($input_file); + if (max($dims[0], $dims[1]) < min($options["width"], $options["height"])) { + // Image would get upscaled; do nothing + copy($input_file, $output_file); + } else { + $image = Image::factory($input_file) + ->resize($options["width"], $options["height"], $options["master"]) + ->quality(module::get_var("gallery", "image_quality")); + if (graphics::can("sharpen")) { + $image->sharpen(module::get_var("gallery", "image_sharpen")); + } + $image->save($output_file); + } + + module::event("graphics_resize_completed", $input_file, $output_file, $options); + } +} diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 6500482b..ee605b27 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -224,8 +224,8 @@ class gallery_installer { $root->save(); access::add_item($root); - module::set_var("gallery", "active_site_theme", "default"); - module::set_var("gallery", "active_admin_theme", "admin_default"); + module::set_var("gallery", "active_site_theme", "wind"); + module::set_var("gallery", "active_admin_theme", "admin_wind"); module::set_var("gallery", "page_size", 9); module::set_var("gallery", "thumb_size", 200); module::set_var("gallery", "resize_size", 640); @@ -268,7 +268,7 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>"); - module::set_version("gallery", 12); + module::set_version("gallery", 13); } static function upgrade($version) { @@ -364,6 +364,17 @@ class gallery_installer { $db->query("UPDATE {items} SET `relative_url_cache` = NULL, `relative_path_cache` = NULL"); module::set_version("gallery", $version = 12); } + + if ($version == 12) { + if (module::get_var("gallery", "active_site_theme") == "default") { + module::set_var("gallery", "active_site_theme", "wind"); + } + if (module::get_var("gallery", "active_admin_theme") == "admin_default") { + module::set_var("gallery", "active_admin_theme", "admin_wind"); + } + module::set_version("gallery", $version = 13); + } + } static function uninstall() { diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 1b56ab97..3d0476a8 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -48,9 +48,13 @@ class gallery_task_Core { $errors = array(); try { $result = graphics::find_dirty_images_query(); + $total_count = $task->get("total_count", -1); + if ($total_count < 0) { + $total_count = $result->count(); + $task->set("total_count", $total_count); + } $completed = $task->get("completed", 0); $ignored = $task->get("ignored", array()); - $remaining = $result->count() - count($ignored); $i = 0; foreach ($result as $row) { @@ -62,19 +66,18 @@ class gallery_task_Core { if ($item->loaded) { try { graphics::generate($item); - $ignored[$item->id] = 1; + $completed++; + $errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title))); } catch (Exception $e) { $errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title))); $errors[] = $e->__toString(); + $ignored[$item->id] = 1; } } - $completed++; - $remaining--; - if (++$i == 2) { break; } @@ -83,17 +86,17 @@ class gallery_task_Core { $task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, - array("total_count" => ($remaining + $completed))); + array("total_count" => $total_count)); - if ($completed + $remaining > 0) { - $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + if ($completed < $total_count) { + $task->percent_complete = (int)(100 * ($completed + count($ignored)) / $total_count); } else { $task->percent_complete = 100; } $task->set("completed", $completed); $task->set("ignored", $ignored); - if ($remaining == 0) { + if ($task->percent_complete == 100) { $task->done = true; $task->state = "success"; site_status::clear("graphics_dirty"); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 78812794..6705652f 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -152,7 +152,7 @@ class graphics_Core { ->orderby("priority", "asc") ->find_all() as $rule) { $args = array($working_file, $output_file, unserialize($rule->args)); - call_user_func_array(array("graphics", $rule->operation), $args); + call_user_func_array(array("{$rule->module_name}_graphics", $rule->operation), $args); $working_file = $output_file; } } @@ -181,42 +181,6 @@ class graphics_Core { } /** - * Resize an image. Valid options are width, height and master. Master is one of the Image - * master dimension constants. - * - * @param string $input_file - * @param string $output_file - * @param array $options - */ - static function resize($input_file, $output_file, $options) { - if (!self::$init) { - self::init_toolkit(); - } - - module::event("graphics_resize", $input_file, $output_file, $options); - - if (@filesize($input_file) == 0) { - throw new Exception("@todo EMPTY_INPUT_FILE"); - } - - $dims = getimagesize($input_file); - if (max($dims[0], $dims[1]) < min($options["width"], $options["height"])) { - // Image would get upscaled; do nothing - copy($input_file, $output_file); - } else { - $image = Image::factory($input_file) - ->resize($options["width"], $options["height"], $options["master"]) - ->quality(module::get_var("gallery", "image_quality")); - if (graphics::can("sharpen")) { - $image->sharpen(module::get_var("gallery", "image_sharpen")); - } - $image->save($output_file); - } - - module::event("graphics_resize_completed", $input_file, $output_file, $options); - } - - /** * Rotate an image. Valid options are degrees * * @param string $input_file @@ -239,60 +203,6 @@ class graphics_Core { } /** - * Overlay an image on top of the input file. - * - * Valid options are: file, mime_type, position, transparency_percent, padding - * - * Valid positions: northwest, north, northeast, - * west, center, east, - * southwest, south, southeast - * - * padding is in pixels - * - * @param string $input_file - * @param string $output_file - * @param array $options - */ - static function composite($input_file, $output_file, $options) { - if (!self::$init) { - self::init_toolkit(); - } - - module::event("graphics_composite", $input_file, $output_file, $options); - - list ($width, $height) = getimagesize($input_file); - list ($w_width, $w_height) = getimagesize($options["file"]); - - $pad = isset($options["padding"]) ? $options["padding"] : 10; - $top = $pad; - $left = $pad; - $y_center = max($height / 2 - $w_height / 2, $pad); - $x_center = max($width / 2 - $w_width / 2, $pad); - $bottom = max($height - $w_height - $pad, $pad); - $right = max($width - $w_width - $pad, $pad); - - switch ($options["position"]) { - case "northwest": $x = $left; $y = $top; break; - case "north": $x = $x_center; $y = $top; break; - case "northeast": $x = $right; $y = $top; break; - case "west": $x = $left; $y = $y_center; break; - case "center": $x = $x_center; $y = $y_center; break; - case "east": $x = $right; $y = $y_center; break; - case "southwest": $x = $left; $y = $bottom; break; - case "south": $x = $x_center; $y = $bottom; break; - case "southeast": $x = $right; $y = $bottom; break; - } - - Image::factory($input_file) - ->composite($options["file"], $x, $y, $options["transparency"]) - ->quality(module::get_var("gallery", "image_quality")) - ->save($output_file); - - - module::event("graphics_composite_completed", $input_file, $output_file, $options); - } - - /** * Return a query result that locates all items with dirty images. * @return Database_Result Query result */ @@ -463,6 +373,9 @@ class graphics_Core { * Choose which driver the Kohana Image library uses. */ static function init_toolkit() { + if (self::$init) { + return; + } switch(module::get_var("gallery", "graphics_toolkit")) { case "gd": Kohana::config_set("image.driver", "GD"); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 59bf5c19..6c8c6c88 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -128,6 +128,36 @@ class movie_Core { return $movie; } + static function get_edit_form($movie) { + $form = new Forge("movies/$movie->id", "", "post", array("id" => "gEditMovieForm")); + $form->hidden("_method")->value("put"); + $group = $form->group("edit_item")->label(t("Edit Movie")); + $group->input("title")->label(t("Title"))->value($movie->title); + $group->textarea("description")->label(t("Description"))->value($movie->description); + $group->input("filename")->label(t("Filename"))->value($movie->name) + ->error_messages( + "name_conflict", t("There is already a movie, photo or album with this name")) + ->callback("item::validate_no_slashes") + ->error_messages("no_slashes", t("The movie name can't contain a \"/\"")) + ->callback("item::validate_no_trailing_period") + ->error_messages("no_trailing_period", t("The movie name can't end in \".\"")); + $group->input("slug")->label(t("Internet Address"))->value($movie->slug) + ->callback("item::validate_url_safe") + ->error_messages( + "slug_conflict", t("There is already a movie, photo or album with this internet address")) + ->error_messages( + "not_url_safe", + t("The internet address should contain only letters, numbers, hyphens and underscores")); + + module::event("item_edit_form", $movie, $form); + + $group = $form->group("buttons")->label(""); + $group->submit("")->value(t("Modify")); + $form->add_rules_from(ORM::factory("item")); + return $form; + } + + static function getmoviesize($filename) { $ffmpeg = self::find_ffmpeg(); if (empty($ffmpeg)) { diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 3d9fbe69..065d2d31 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -163,7 +163,8 @@ class photo_Core { $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); $group->input("filename")->label(t("Filename"))->value($photo->name) - ->error_messages("name_conflict", t("There is already a photo or album with this name")) + ->error_messages( + "name_conflict", t("There is already a movie, photo or album with this name")) ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The photo name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") @@ -171,7 +172,7 @@ class photo_Core { $group->input("slug")->label(t("Internet Address"))->value($photo->slug) ->callback("item::validate_url_safe") ->error_messages( - "slug_conflict", t("There is already a photo or album with this internet address")) + "slug_conflict", t("There is already a movie, photo or album with this internet address")) ->error_messages( "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")); |