diff options
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/MY_num.php | 14 | ||||
-rw-r--r-- | modules/gallery/helpers/encoding.php | 35 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 16 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 26 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 17 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_rss.php | 8 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/graphics.php | 38 | ||||
-rw-r--r-- | modules/gallery/helpers/item.php | 29 | ||||
-rw-r--r-- | modules/gallery/helpers/legal_file.php | 83 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/random.php | 10 | ||||
-rw-r--r-- | modules/gallery/helpers/system.php | 21 | ||||
-rw-r--r-- | modules/gallery/helpers/theme.php | 23 |
15 files changed, 300 insertions, 30 deletions
diff --git a/modules/gallery/helpers/MY_num.php b/modules/gallery/helpers/MY_num.php index 9787044c..842a2ee3 100644 --- a/modules/gallery/helpers/MY_num.php +++ b/modules/gallery/helpers/MY_num.php @@ -37,4 +37,18 @@ class num extends num_Core { return $val; } + + /** + * Convert a size value as accepted by PHP's shorthand to bytes. + * ref: http://us2.php.net/manual/en/function.ini-get.php + * ref: http://us2.php.net/manual/en/faq.using.php#faq.using.shorthandbytes + */ + static function convert_to_human_readable($num) { + foreach (array("G" => 1e9, "M" => 1e6, "K" => 1e3) as $k => $v) { + if ($num > $v) { + $num = round($num / $v) . $k; + } + } + return $num; + } } diff --git a/modules/gallery/helpers/encoding.php b/modules/gallery/helpers/encoding.php new file mode 100644 index 00000000..7d5add34 --- /dev/null +++ b/modules/gallery/helpers/encoding.php @@ -0,0 +1,35 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2011 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 encoding_Core { + static function convert_to_utf8($value) { + if (function_exists("mb_detect_encoding")) { + // Rely on mb_detect_encoding()'s strict mode + $src_encoding = mb_detect_encoding($value, mb_detect_order(), true); + if ($src_encoding != "UTF-8") { + if (function_exists("mb_convert_encoding") && $src_encoding) { + $value = mb_convert_encoding($value, "UTF-8", $src_encoding); + } else { + $value = utf8_encode($value); + } + } + } + return $value; + } +}
\ No newline at end of file diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 1fafdef7..cbd9b33c 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -193,19 +193,25 @@ class gallery_Core { */ static function version_string() { if (gallery::RELEASE_CHANNEL == "git") { + $build_number = gallery::build_number(); return sprintf( - "%s (branch %s build %s)", gallery::VERSION, gallery::RELEASE_BRANCH, - gallery::build_number()); + "%s (branch %s, %s)", gallery::VERSION, gallery::RELEASE_BRANCH, + $build_number ? " build $build_number" : "unknown build number"); } else { return sprintf("%s (%s)", gallery::VERSION, gallery::CODE_NAME); } } /** - * Return the contents of the .build_number file, which should be a single integer. + * Return the contents of the .build_number file, which should be a single integer + * or return null if the .build_number file is missing. */ static function build_number() { - $result = parse_ini_file(DOCROOT . ".build_number"); - return $result["build_number"]; + $build_file = DOCROOT . ".build_number"; + if (file_exists($build_file)) { + $result = parse_ini_file(DOCROOT . ".build_number"); + return $result["build_number"]; + } + return null; } }
\ No newline at end of file diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index b9ccf25b..49d16246 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -82,9 +82,13 @@ class gallery_block_Core { break; case "block_adder": - $block->css_id = "g-block-adder"; - $block->title = t("Dashboard content"); - $block->content = gallery_block::get_add_block_form(); + if ($form = gallery_block::get_add_block_form()) { + $block->css_id = "g-block-adder"; + $block->title = t("Dashboard content"); + $block->content = $form; + } else { + $block = ""; + } break; case "language": @@ -112,16 +116,28 @@ class gallery_block_Core { $block->content->version_info = upgrade_checker::version_info(); $block->content->auto_check_enabled = upgrade_checker::auto_check_enabled(); $block->content->new_version = upgrade_checker::get_upgrade_message(); + $block->content->build_number = gallery::build_number(); } return $block; } static function get_add_block_form() { + $available_blocks = block_manager::get_available_admin_blocks(); + + $active = array(); + foreach (array_merge(block_manager::get_active("dashboard_sidebar"), + block_manager::get_active("dashboard_center")) as $b) { + unset($available_blocks[implode(":", $b)]); + } + + if (!$available_blocks) { + return; + } + $form = new Forge("admin/dashboard/add_block", "", "post", array("id" => "g-add-dashboard-block-form")); $group = $form->group("add_block")->label(t("Add Block")); - $group->dropdown("id")->label(t("Available Blocks")) - ->options(block_manager::get_available_admin_blocks()); + $group->dropdown("id")->label(t("Available blocks"))->options($available_blocks); $group->submit("center")->value(t("Add to center")); $group->submit("sidebar")->value(t("Add to sidebar")); return $form; diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 07817187..fbdb4ad5 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -539,9 +539,9 @@ class gallery_event_Core { $v = new View("user_profile_info.html"); $fields = array("name" => t("Name"), "locale" => t("Language Preference"), - "email" => t("Email"), "full_name" => t("Full name"), "url" => "Web site"); + "email" => t("Email"), "full_name" => t("Full name"), "url" => t("Web site")); if (!$data->user->guest) { - $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => "Web site"); + $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => t("Web site")); } $v->user_profile_data = array(); foreach ($fields as $field => $label) { @@ -549,6 +549,8 @@ class gallery_event_Core { $value = $data->user->$field; if ($field == "locale") { $value = locales::display_name($value); + } elseif ($field == "url") { + $value = html::mark_clean(html::anchor($data->user->$field)); } $v->user_profile_data[(string) $label] = $value; } diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 01c59eaa..7a9af402 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -304,14 +304,16 @@ class gallery_installer { module::set_var("gallery", "maintenance_mode", 0); module::set_var("gallery", "visible_title_length", 15); module::set_var("gallery", "favicon_url", "lib/images/favicon.ico"); + module::set_var("gallery", "apple_touch_icon_url", "lib/images/apple-touch-icon.png"); module::set_var("gallery", "email_from", ""); module::set_var("gallery", "email_reply_to", ""); module::set_var("gallery", "email_line_length", 70); module::set_var("gallery", "email_header_separator", serialize("\n")); module::set_var("gallery", "show_user_profiles_to", "registered_users"); module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); + module::set_var("gallery", "timezone", null); - module::set_version("gallery", 46); + module::set_version("gallery", 49); } static function upgrade($version) { @@ -677,6 +679,19 @@ class gallery_installer { module::set_var("gallery", "upgrade_checker_auto_enabled", true); module::set_version("gallery", $version = 46); } + + if ($version == 46) { + module::set_var("gallery", "apple_touch_icon_url", "lib/images/apple-touch-icon.png"); + module::set_version("gallery", $version = 47); + } + + if ($version == 47 || $version == 48) { + // Add configuration variable to set timezone. Defaults to the currently + // used timezone (from PHP configuration). Note that in v48 we werew + // setting this value incorrectly, so we're going to stomp this value for v49. + module::set_var("gallery", "timezone", null); + module::set_version("gallery", $version = 49); + } } static function uninstall() { diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 612872e6..9af67118 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -21,6 +21,14 @@ class gallery_rss_Core { static function available_feeds($item, $tag) { $feeds["gallery/latest"] = t("Latest photos and movies"); + + if ($item) { + $feed_item = $item -> is_album() ? $item : $item->parent(); + + $feeds["gallery/album/{$feed_item->id}"] = + t("%title photos and movies", array("title" => $feed_item->title)); + } + return $feeds; } diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index c4a82390..e07839d9 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -64,7 +64,7 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= $theme->css("l10n_client.css"); $buf .= $theme->script("jquery.cookie.js"); - $buf .=$theme->script("l10n_client.js"); + $buf .= $theme->script("l10n_client.js"); } return $buf; } diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 04501132..3548faa1 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -176,17 +176,25 @@ class graphics_Core { } if (!empty($ops["thumb"])) { + if (file_exists($item->thumb_path())) { + $item->thumb_dirty = 0; + } else { + copy(MODPATH . "gallery/images/missing_photo.png", $item->thumb_path()); + } $dims = getimagesize($item->thumb_path()); $item->thumb_width = $dims[0]; $item->thumb_height = $dims[1]; - $item->thumb_dirty = 0; } if (!empty($ops["resize"])) { + if (file_exists($item->resize_path())) { + $item->resize_dirty = 0; + } else { + copy(MODPATH . "gallery/images/missing_photo.png", $item->resize_path()); + } $dims = getimagesize($item->resize_path()); $item->resize_width = $dims[0]; $item->resize_height = $dims[1]; - $item->resize_dirty = 0; } $item->save(); } catch (Exception $e) { @@ -316,10 +324,10 @@ class graphics_Core { // ImageMagick & GraphicsMagick $magick_kits = array( "imagemagick" => array( - "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v", + "name" => "ImageMagick", "binary" => "convert", "version_arg" => "-v", "version_regex" => "/Version: \S+ (\S+)/"), "graphicsmagick" => array( - "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version", + "name" => "GraphicsMagick", "binary" => "gm", "version_arg" => "version", "version_regex" => "/\S+ (\S+)/")); // Loop through the kits foreach ($magick_kits as $index => $settings) { @@ -328,7 +336,8 @@ class graphics_Core { $toolkits->$index->name = $settings["name"]; if ($path) { if (@is_file($path) && - preg_match($settings["version_regex"], shell_exec($settings["version"]), $matches)) { + preg_match( + $settings["version_regex"], shell_exec($path . " " . $settings["version_arg"]), $matches)) { $version = $matches[1]; $toolkits->$index->installed = true; @@ -423,4 +432,23 @@ class graphics_Core { return true; } + + /** + * Return the max file size that this graphics toolkit can handle. + */ + static function max_filesize() { + if (module::get_var("gallery", "graphics_toolkit") == "gd") { + $memory_limit = trim(ini_get("memory_limit")); + $memory_limit_bytes = num::convert_to_bytes($memory_limit); + + // GD expands images in memory and uses 4 bytes of RAM for every byte + // in the file. + $max_filesize = $memory_limit_bytes / 4; + $max_filesize_human_readable = num::convert_to_human_readable($max_filesize); + return array($max_filesize, $max_filesize_human_readable); + } + + // Some arbitrarily large size + return array(1000000000, "1G"); + } } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 1a5c631e..494c6db4 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -152,8 +152,18 @@ class item_Core { * @param string $filename */ static function convert_filename_to_slug($filename) { - $result = pathinfo($filename, PATHINFO_FILENAME); + $result = str_replace("&", "-and-", $filename); + $result = str_replace(" ", "-", $result); + + // It's not easy to extend the text helper since it's called by the Input class which is + // referenced in hooks/init_gallery, so it's + if (class_exists("transliterate")) { + $result = transliterate::utf8_to_ascii($result); + } else { + $result = text::transliterate_to_ascii($result); + } $result = preg_replace("/[^A-Za-z0-9-_]+/", "-", $result); + $result = preg_replace("/-+/", "-", $result); return trim($result, "-"); } @@ -392,4 +402,21 @@ class item_Core { return $position; } + + /** + * Set the display context callback for any future item renders. + */ + static function set_display_context_callback() { + Cache::instance()->set("display_context_" . $sid = Session::instance()->id(), func_get_args()); + } + + /** + * Call the display context callback for the given item + */ + static function get_display_context($item) { + $args = Cache::instance()->get("display_context_" . $sid = Session::instance()->id()); + $callback = $args[0]; + $args[0] = $item; + return call_user_func_array($callback, $args); + } }
\ No newline at end of file diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php new file mode 100644 index 00000000..6f66c85c --- /dev/null +++ b/modules/gallery/helpers/legal_file.php @@ -0,0 +1,83 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2011 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 legal_file_Core { + /** + * Create a default list of allowed photo extensions and then let modules modify it. + */ + static function get_photo_extensions() { + $extensions_wrapper = new stdClass(); + $extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png"); + module::event("legal_photo_extensions", $extensions_wrapper); + return $extensions_wrapper->extensions; + } + + /** + * Create a default list of allowed movie extensions and then let modules modify it. + */ + static function get_movie_extensions() { + $extensions_wrapper = new stdClass(); + $extensions_wrapper->extensions = array("flv", "mp4", "m4v"); + module::event("legal_movie_extensions", $extensions_wrapper); + return $extensions_wrapper->extensions; + } + + /** + * Create a merged list of all allowed photo and movie extensions. + */ + static function get_extensions() { + $extensions = legal_file::get_photo_extensions(); + if (movie::find_ffmpeg()) { + $extensions = array_merge($extensions, legal_file::get_movie_extensions()); + } + return $extensions; + } + + /** + * Create a merged list of all photo and movie filename filters, + * (e.g. "*.gif"), based on allowed extensions. + */ + static function get_filters() { + $filters = array(); + foreach (legal_file::get_extensions() as $extension) { + array_push($filters, "*." . $extension, "*." . strtoupper($extension)); + } + return $filters; + } + + /** + * Create a default list of allowed photo MIME types and then let modules modify it. + */ + static function get_photo_types() { + $types_wrapper = new stdClass(); + $types_wrapper->types = array("image/jpeg", "image/gif", "image/png"); + module::event("legal_photo_types", $types_wrapper); + return $types_wrapper->types; + } + + /** + * Create a default list of allowed movie MIME types and then let modules modify it. + */ + static function get_movie_types() { + $types_wrapper = new stdClass(); + $types_wrapper->types = array("video/flv", "video/x-flv", "video/mp4"); + module::event("legal_movie_types", $types_wrapper); + return $types_wrapper->types; + } +} diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 37f7f68a..4b7d4a5f 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -101,7 +101,7 @@ class module_Core { $m->locked = false; if ($m->active && $m->version != $m->code_version) { - site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::site("upgrader"))), "upgrade_now"); + site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::abs_site("upgrader"))), "upgrade_now"); } } diff --git a/modules/gallery/helpers/random.php b/modules/gallery/helpers/random.php index 6016df7b..06542e8c 100644 --- a/modules/gallery/helpers/random.php +++ b/modules/gallery/helpers/random.php @@ -19,7 +19,7 @@ */ class random_Core { /** - * Return a random 32 bit hash value. + * Return a random 32 byte hash value. * @param string extra entropy data */ static function hash($entropy="") { @@ -27,14 +27,6 @@ class random_Core { } /** - * Return a random hexadecimal string of the given length. - * @param int the desired length of the string - */ - static function string($length) { - return substr(random::hash(), 0, $length); - } - - /** * Return a random floating point number between 0 and 1 */ static function percent() { diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php index c39c7227..4110b4ed 100644 --- a/modules/gallery/helpers/system.php +++ b/modules/gallery/helpers/system.php @@ -40,4 +40,25 @@ class system_Core { } return null; } + + /** + * Create a file with a unique file name. + * This helper is similar to the built-in tempnam. + * It allows the caller to specify a prefix and an extension. + * It always places the file in TMPPATH. + */ + static function temp_filename($prefix="", $extension="") { + do { + $basename = tempnam(TMPPATH, $prefix); + if (!$basename) { + return false; + } + $filename = "$basename.$extension"; + $success = !file_exists($filename) && @rename($basename, $filename); + if (!$success) { + @unlink($basename); + } + } while (!$success); + return $filename; + } }
\ No newline at end of file diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index f285834c..37707f28 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -41,11 +41,34 @@ class theme_Core { $config = Kohana_Config::instance(); $modules = $config->get("core.modules"); + + // Normally Router::find_uri() strips off the url suffix for us, but we're working off of the + // PATH_INFO here so we need to strip it off manually + if ($suffix = Kohana::config("core.url_suffix")) { + $path = preg_replace("#" . preg_quote($suffix) . "$#u", "", $path); + } + self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); self::$site_theme_name = module::get_var("gallery", "active_site_theme"); + + // If the site theme doesn't exist, fall back to wind. + if (!file_exists(THEMEPATH . self::$site_theme_name . "/theme.info")) { + site_status::error(t("Theme '%name' is missing. Falling back to the Wind theme.", + array("name" => self::$site_theme_name)), "missing_site_theme"); + module::set_var("gallery", "active_site_theme", self::$site_theme_name = "wind"); + } + if (self::$is_admin) { // Load the admin theme self::$admin_theme_name = module::get_var("gallery", "active_admin_theme"); + + // If the admin theme doesn't exist, fall back to admin_wind. + if (!file_exists(THEMEPATH . self::$admin_theme_name . "/theme.info")) { + site_status::error(t("Admin theme '%name' is missing! Falling back to the Wind theme.", + array("name" => self::$admin_theme_name)), "missing_admin_theme"); + module::set_var("gallery", "active_admin_theme", self::$admin_theme_name = "admin_wind"); + } + array_unshift($modules, THEMEPATH . self::$admin_theme_name); // If the site theme has an admin subdir, load that as a module so that |