summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
committerAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
commit0733dc37fda27a5ba35f9020edf3c66aa41a95a0 (patch)
tree6877946232f1b01b1c8709054c689f6658cef34f /modules/gallery/helpers
parent218493c50be9362d4abed6900a816308fee5d978 (diff)
parent9379308f91a476f790fb8d444536719535c584e4 (diff)
Merge commit 'upstream/master'
Conflicts: modules/gallery/tests/xss_data.txt
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/access.php12
-rw-r--r--modules/gallery/helpers/album.php15
-rw-r--r--modules/gallery/helpers/auth.php56
-rw-r--r--modules/gallery/helpers/block_manager.php62
-rw-r--r--modules/gallery/helpers/gallery.php257
-rw-r--r--modules/gallery/helpers/gallery_block.php69
-rw-r--r--modules/gallery/helpers/gallery_error.php30
-rw-r--r--modules/gallery/helpers/gallery_event.php326
-rw-r--r--modules/gallery/helpers/gallery_graphics.php129
-rw-r--r--modules/gallery/helpers/gallery_installer.php86
-rw-r--r--modules/gallery/helpers/gallery_rss.php4
-rw-r--r--modules/gallery/helpers/gallery_task.php25
-rw-r--r--modules/gallery/helpers/gallery_theme.php10
-rw-r--r--modules/gallery/helpers/graphics.php144
-rw-r--r--modules/gallery/helpers/identity.php244
-rw-r--r--modules/gallery/helpers/item.php6
-rw-r--r--modules/gallery/helpers/locales.php34
-rw-r--r--modules/gallery/helpers/log.php10
-rw-r--r--modules/gallery/helpers/message.php10
-rw-r--r--modules/gallery/helpers/module.php76
-rw-r--r--modules/gallery/helpers/movie.php39
-rw-r--r--modules/gallery/helpers/photo.php17
-rw-r--r--modules/gallery/helpers/site_status.php12
-rw-r--r--modules/gallery/helpers/task.php2
-rw-r--r--modules/gallery/helpers/theme.php30
25 files changed, 1236 insertions, 469 deletions
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index 949aea84..c1c1f9d1 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -79,7 +79,7 @@ class access_Core {
* @return boolean
*/
static function can($perm_name, $item) {
- return self::user_can(user::active(), $perm_name, $item);
+ return self::user_can(identity::active_user(), $perm_name, $item);
}
/**
@@ -197,8 +197,8 @@ class access_Core {
* @param Item_Model $item
* @param boolean $value
*/
- private static function _set(Group_Model $group, $perm_name, $album, $value) {
- if (get_class($group) != "Group_Model") {
+ private static function _set(Group_Definition $group, $perm_name, $album, $value) {
+ if (!($group instanceof Group_Definition)) {
throw new Exception("@todo PERMISSIONS_ONLY_WORK_ON_GROUPS");
}
if (!$album->loaded) {
@@ -419,10 +419,10 @@ class access_Core {
* @return ORM_Iterator
*/
private static function _get_all_groups() {
- // When we build the gallery package, it's possible that the user module is not installed yet.
+ // When we build the gallery package, it's possible that there is no identity provider installed yet.
// This is ok at packaging time, so work around it.
- if (module::is_active("user")) {
- return ORM::factory("group")->find_all();
+ if (module::is_active(module::get_var("gallery", "identity_provider", "user"))) {
+ return identity::groups();
} else {
return array();
}
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index 9cd746d7..72a79a75 100644
--- a/modules/gallery/helpers/album.php
+++ b/modules/gallery/helpers/album.php
@@ -92,7 +92,7 @@ class album_Core {
}
static function get_add_form($parent) {
- $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddAlbumForm"));
+ $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-add-album-form"));
$group = $form->group("add_album")
->label(t("Add an album to %album_title", array("album_title" => $parent->title)));
$group->input("title")->label(t("Title"));
@@ -114,7 +114,7 @@ class album_Core {
}
static function get_edit_form($parent) {
- $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gEditAlbumForm"));
+ $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-edit-album-form"));
$form->hidden("_method")->value("put");
$group = $form->group("edit_item")->label(t("Edit Album"));
@@ -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",
@@ -140,14 +141,14 @@ class album_Core {
$group->hidden("slug")->value($parent->slug);
}
- $sort_order = $group->group("sort_order", array("id" => "gAlbumSortOrder"))
+ $sort_order = $group->group("sort_order", array("id" => "g-album-sort-order"))
->label(t("Sort Order"));
- $sort_order->dropdown("column", array("id" => "gAlbumSortColumn"))
+ $sort_order->dropdown("column", array("id" => "g-album-sort-column"))
->label(t("Sort by"))
->options(album::get_sort_order_options())
->selected($parent->sort_column);
- $sort_order->dropdown("direction", array("id" => "gAlbumSortDirection"))
+ $sort_order->dropdown("direction", array("id" => "g-album-sort-direction"))
->label(t("Order"))
->options(array("ASC" => t("Ascending"),
"DESC" => t("Descending")))
diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php
new file mode 100644
index 00000000..9c69cecd
--- /dev/null
+++ b/modules/gallery/helpers/auth.php
@@ -0,0 +1,56 @@
+<?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 auth_Core {
+ static function get_login_form($url) {
+ $form = new Forge($url, "", "post", array("id" => "g-login-form"));
+ $form->set_attr('class', "g-narrow");
+ $group = $form->group("login")->label(t("Login"));
+ $group->input("name")->label(t("Username"))->id("g-username")->class(null);
+ $group->password("password")->label(t("Password"))->id("g-password")->class(null);
+ $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password"));
+ $group->submit("")->value(t("Login"));
+ return $form;
+ }
+
+ static function login($user) {
+ if (identity::is_writable()) {
+ $user->login_count += 1;
+ $user->last_login = time();
+ $user->save();
+ }
+ identity::set_active_user($user);
+ log::info("user", t("User %name logged in", array("name" => $user->name)));
+ module::event("user_login", $user);
+ }
+
+ static function logout() {
+ $user = identity::active_user();
+ if (!$user->guest) {
+ try {
+ Session::instance()->destroy();
+ } catch (Exception $e) {
+ Kohana::log("error", $e);
+ }
+ module::event("user_logout", $user);
+ }
+ log::info("user", t("User %name logged out", array("name" => $user->name)),
+ html::anchor("user/$user->id", html::clean($user->name)));
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php
index 20b641d4..b003f1d8 100644
--- a/modules/gallery/helpers/block_manager.php
+++ b/modules/gallery/helpers/block_manager.php
@@ -29,22 +29,68 @@ class block_manager_Core {
static function add($location, $module_name, $block_id) {
$blocks = self::get_active($location);
$blocks[rand()] = array($module_name, $block_id);
+
self::set_active($location, $blocks);
}
+ static function activate_blocks($module_name) {
+ $block_class = "{$module_name}_block";
+ if (method_exists($block_class, "get_site_list")) {
+ $blocks = call_user_func(array($block_class, "get_site_list"));
+ foreach (array_keys($blocks) as $block_id) {
+ self::add("site_sidebar", $module_name, $block_id);
+ }
+ }
+ }
+
static function remove($location, $block_id) {
$blocks = self::get_active($location);
unset($blocks[$block_id]);
self::set_active($location, $blocks);
}
- static function get_available() {
+ static function remove_blocks_for_module($location, $module_name) {
+ $blocks = self::get_active($location);
+ foreach ($blocks as $key => $block) {
+ if ($block[0] == $module_name) {
+ unset($blocks[$key]);
+ }
+ }
+ self::set_active($location, $blocks);
+ }
+
+ static function deactivate_blocks($module_name) {
+ $block_class = "{$module_name}_block";
+ if (method_exists($block_class, "get_site_list")) {
+ $blocks = call_user_func(array($block_class, "get_site_list"));
+ foreach (array_keys($blocks) as $block_id) {
+ self::remove_blocks_for_module("site_sidebar", $module_name);
+ }
+ }
+
+ if (method_exists($block_class, "get_admin_list")) {
+ $blocks = call_user_func(array($block_class, "get_admin_list"));
+ foreach (array("dashboard_sidebar", "dashboard_center") as $location) {
+ self::remove_blocks_for_module($location, $module_name);
+ }
+ }
+ }
+
+ static function get_available_admin_blocks() {
+ return self::_get_blocks("get_admin_list");
+ }
+
+ static function get_available_site_blocks() {
+ return self::_get_blocks("get_site_list");
+ }
+
+ private static function _get_blocks($function) {
$blocks = array();
foreach (module::active() as $module) {
$class_name = "{$module->name}_block";
- if (method_exists($class_name, "get_list")) {
- foreach (call_user_func(array($class_name, "get_list")) as $id => $title) {
+ if (method_exists($class_name, $function)) {
+ foreach (call_user_func(array($class_name, $function)) as $id => $title) {
$blocks["{$module->name}:$id"] = $title;
}
}
@@ -52,14 +98,16 @@ class block_manager_Core {
return $blocks;
}
- static function get_html($location) {
+ static function get_html($location, $theme=null) {
$active = self::get_active($location);
$result = "";
foreach ($active as $id => $desc) {
if (method_exists("$desc[0]_block", "get")) {
- $block = call_user_func(array("$desc[0]_block", "get"), $desc[1]);
- $block->id = $id;
- $result .= $block;
+ $block = call_user_func(array("$desc[0]_block", "get"), $desc[1], $theme);
+ if (!empty($block)) {
+ $block->id = $id;
+ $result .= $block;
+ }
}
}
return $result;
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 80ae65bd..84f8a7fb 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -27,7 +27,7 @@ class gallery_Core {
static function maintenance_mode() {
$maintenance_mode = Kohana::config("core.maintenance_mode", false, false);
- if (Router::$controller != "login" && !empty($maintenance_mode) && !user::active()->admin) {
+ if (Router::$controller != "login" && !empty($maintenance_mode) && !identity::active_user()->admin) {
Router::$controller = "maintenance";
Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php";
Router::$method = "index";
@@ -79,238 +79,39 @@ class gallery_Core {
return date(module::get_var("gallery", "time_format", "H:i:s"), $timestamp);
}
- static function site_menu($menu, $theme) {
- if ($theme->page_type != "login") {
- $menu->append(Menu::factory("link")
- ->id("home")
- ->label(t("Home"))
- ->url(item::root()->url()));
-
- $item = $theme->item();
-
- $can_edit = $item && access::can("edit", $item);
- $can_add = $item && access::can("add", $item);
-
- if ($can_add) {
- $menu->append($add_menu = Menu::factory("submenu")
- ->id("add_menu")
- ->label(t("Add")));
- $is_album_writable =
- is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path());
- if ($is_album_writable) {
- $add_menu->append(Menu::factory("dialog")
- ->id("add_photos_item")
- ->label(t("Add photos"))
- ->url(url::site("simple_uploader/app/$item->id")));
- if ($item->is_album()) {
- $add_menu->append(Menu::factory("dialog")
- ->id("add_album_item")
- ->label(t("Add an album"))
- ->url(url::site("form/add/albums/$item->id?type=album")));
- }
- } else {
- message::warning(t("The album '%album_name' is not writable.",
- array("album_name" => $item->title)));
- }
- }
-
- $menu->append($options_menu = Menu::factory("submenu")
- ->id("options_menu")
- ->label(t("Photo options")));
- 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"))
- ->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")
- ->label(t("Edit permissions"))
- ->url(url::site("permissions/browse/$item->id")));
- }
- }
- }
-
- if (user::active()->admin) {
- $menu->append($admin_menu = Menu::factory("submenu")
- ->id("admin_menu")
- ->label(t("Admin")));
- gallery::admin_menu($admin_menu, $theme);
- module::event("admin_menu", $admin_menu, $theme);
+ /**
+ * Provide a wrapper function for Kohana::find_file that first strips the extension and
+ * then calls the Kohana::find_file and supplies the extension as the type.
+ * @param string directory to search in
+ * @param string filename to look for
+ * @param boolean file required (optional: default false)
+ * @return array if the extension is config, i18n or l10n
+ * @return string if the file is found (relative to the DOCROOT)
+ * @return false if the file is not found
+ */
+ 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));
+ if (!$file_name) {
+ if (file_exists(DOCROOT . "lib/$directory/$file")) {
+ return "lib/$directory/$file";
+ } else if (file_exists(DOCROOT . "lib/$file")) {
+ return "lib/$file";
}
-
- module::event("site_menu", $menu, $theme);
}
- }
-
- static function admin_menu($menu, $theme) {
- $menu
- ->append(Menu::factory("link")
- ->id("dashboard")
- ->label(t("Dashboard"))
- ->url(url::site("admin")))
- ->append(Menu::factory("submenu")
- ->id("settings_menu")
- ->label(t("Settings"))
- ->append(Menu::factory("link")
- ->id("graphics_toolkits")
- ->label(t("Graphics"))
- ->url(url::site("admin/graphics")))
- ->append(Menu::factory("link")
- ->id("languages")
- ->label(t("Languages"))
- ->url(url::site("admin/languages")))
- ->append(Menu::factory("link")
- ->id("advanced")
- ->label(t("Advanced"))
- ->url(url::site("admin/advanced_settings"))))
- ->append(Menu::factory("link")
- ->id("modules")
- ->label(t("Modules"))
- ->url(url::site("admin/modules")))
- ->append(Menu::factory("submenu")
- ->id("content_menu")
- ->label(t("Content")))
- ->append(Menu::factory("submenu")
- ->id("appearance_menu")
- ->label(t("Appearance"))
- ->append(Menu::factory("link")
- ->id("themes")
- ->label(t("Theme Choice"))
- ->url(url::site("admin/themes")))
- ->append(Menu::factory("link")
- ->id("theme_options")
- ->label(t("Theme Options"))
- ->url(url::site("admin/theme_options"))))
- ->append(Menu::factory("submenu")
- ->id("statistics_menu")
- ->label(t("Statistics")))
- ->append(Menu::factory("link")
- ->id("maintenance")
- ->label(t("Maintenance"))
- ->url(url::site("admin/maintenance")));
- return $menu;
- }
- static function context_menu($menu, $theme, $item, $thumb_css_selector) {
- $menu->append($options_menu = Menu::factory("submenu")
- ->id("options_menu")
- ->label(t("Options"))
- ->css_class("ui-icon-carat-1-n"));
-
- if (access::can("edit", $item)) {
- $page_type = $theme->page_type();
- switch ($item->type) {
- case "movie":
- $edit_title = t("Edit this movie");
- $delete_title = t("Delete this movie");
- break;
-
- case "album":
- $edit_title = t("Edit this album");
- $delete_title = t("Delete this album");
- break;
-
- default:
- $edit_title = t("Edit this photo");
- $delete_title = t("Delete this photo");
- break;
- }
- $cover_title = t("Choose as the album cover");
- $move_title = t("Move to another album");
-
- $csrf = access::csrf_token();
-
- $options_menu->append(Menu::factory("dialog")
- ->id("edit")
- ->label($edit_title)
- ->css_class("ui-icon-pencil")
- ->url(url::site("quick/form_edit/$item->id?page_type=$page_type")));
-
-
- if ($item->is_photo() && graphics::can("rotate")) {
- $options_menu
- ->append(
- Menu::factory("ajax_link")
- ->id("rotate_ccw")
- ->label(t("Rotate 90&deg; counter clockwise"))
- ->css_class("ui-icon-rotate-ccw")
- ->ajax_handler("function(data) { " .
- "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
- ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")))
- ->append(
- Menu::factory("ajax_link")
- ->id("rotate_cw")
- ->label(t("Rotate 90&deg; clockwise"))
- ->css_class("ui-icon-rotate-cw")
- ->ajax_handler("function(data) { " .
- "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
- ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")));
- }
-
- // Don't move photos from the photo page; we don't yet have a good way of redirecting after
- // move
- if ($page_type == "album") {
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("move")
- ->label($move_title)
- ->css_class("ui-icon-folder-open")
- ->url(url::site("move/browse/$item->id")));
- }
-
- $parent = $item->parent();
- if (access::can("edit", $parent)) {
- // We can't make this item the highlight if it's an album with no album cover, or if it's
- // already the album cover.
- if (($item->type == "album" && empty($item->album_cover_item_id)) ||
- ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) ||
- $parent->album_cover_item_id == $item->id) {
- $disabledState = " ui-state-disabled";
- } else {
- $disabledState = " ";
+ if (is_string($file_name)) {
+ // make relative to DOCROOT
+ $parts = explode("/", $file_name);
+ foreach ($parts as $idx => $part) {
+ if (in_array($part, array("application", "modules", "themes", "lib"))) {
+ break;
}
- if ($item->parent()->id != 1) {
- $options_menu
- ->append(Menu::factory("ajax_link")
- ->id("make_album_cover")
- ->label($cover_title)
- ->css_class("ui-icon-star")
- ->ajax_handler("function(data) { window.location.reload() }")
- ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf")));
- }
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("delete")
- ->label($delete_title)
- ->css_class("ui-icon-trash")
- ->css_id("gQuickDelete")
- ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")));
- }
-
- if ($item->is_album()) {
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("add_item")
- ->label(t("Add a photo"))
- ->css_class("ui-icon-plus")
- ->url(url::site("simple_uploader/app/$item->id")))
- ->append(Menu::factory("dialog")
- ->id("add_album")
- ->label(t("Add an album"))
- ->css_class("ui-icon-note")
- ->url(url::site("form/add/albums/$item->id?type=album")))
- ->append(Menu::factory("dialog")
- ->id("edit_permissions")
- ->label(t("Edit permissions"))
- ->css_class("ui-icon-key")
- ->url(url::site("permissions/browse/$item->id")));
+ unset($parts[$idx]);
}
+ $file_name = implode("/", $parts);
}
+ return $file_name;
}
+
} \ No newline at end of file
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index b7816954..b5c32ad2 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -18,44 +18,48 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_block_Core {
- static function get_list() {
+ static function get_admin_list() {
return array(
"welcome" => t("Welcome to Gallery 3!"),
- "photo_stream" => t("Photo Stream"),
- "log_entries" => t("Log Entries"),
- "stats" => t("Gallery Stats"),
- "platform_info" => t("Platform Information"),
- "project_news" => t("Gallery Project News"));
+ "photo_stream" => t("Photo stream"),
+ "log_entries" => t("Log entries"),
+ "stats" => t("Gallery stats"),
+ "platform_info" => t("Platform information"),
+ "project_news" => t("Gallery project news"));
+ }
+
+ static function get_site_list() {
+ return array("language" => t("Language preference"));
}
static function get($block_id) {
$block = new Block();
switch($block_id) {
case "welcome":
- $block->css_id = "gWelcome";
+ $block->css_id = "g-welcome";
$block->title = t("Welcome to Gallery 3");
$block->content = new View("admin_block_welcome.html");
break;
case "photo_stream":
- $block->css_id = "gPhotoStream";
- $block->title = t("Photo Stream");
+ $block->css_id = "g-photo-stream";
+ $block->title = t("Photo stream");
$block->content = new View("admin_block_photo_stream.html");
$block->content->photos =
ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10);
break;
case "log_entries":
- $block->css_id = "gLogEntries";
- $block->title = t("Log Entries");
+ $block->css_id = "g-log-entries";
+ $block->title = t("Log entries");
$block->content = new View("admin_block_log_entries.html");
$block->content->entries = ORM::factory("log")
->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5);
break;
case "stats":
- $block->css_id = "gStats";
- $block->title = t("Gallery Stats");
+ $block->css_id = "g-stats";
+ $block->title = t("Gallery stats");
$block->content = new View("admin_block_stats.html");
$block->content->album_count =
ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all();
@@ -63,38 +67,57 @@ class gallery_block_Core {
break;
case "platform_info":
- $block->css_id = "gPlatform";
- $block->title = t("Platform Information");
+ $block->css_id = "g-platform";
+ $block->title = t("Platform information");
$block->content = new View("admin_block_platform.html");
if (is_readable("/proc/loadavg")) {
$block->content->load_average =
- join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3));
+ join(" ", array_slice(explode(" ", array_shift(file("/proc/loadavg"))), 0, 3));
} else {
$block->content->load_average = t("Unavailable");
}
break;
case "project_news":
- $block->css_id = "gProjectNews";
- $block->title = t("Gallery Project News");
+ $block->css_id = "g-project-news";
+ $block->title = t("Gallery project news");
$block->content = new View("admin_block_news.html");
$block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3);
break;
case "block_adder":
- $block->css_id = "gBlockAdder";
- $block->title = t("Dashboard Content");
+ $block->css_id = "g-block-adder";
+ $block->title = t("Dashboard content");
$block->content = self::get_add_block_form();
- }
+ break;
+ case "language":
+ $locales = locales::installed();
+ if (count($locales)) {
+ foreach ($locales as $locale => $display_name) {
+ $locales[$locale] = SafeString::of_safe_html($display_name);
+ }
+ $block = new Block();
+ $block->css_id = "g-user-language-block";
+ $block->title = t("Language preference");
+ $block->content = new View("user_languages_block.html");
+ $block->content->installed_locales =
+ array_merge(array("" => t("« none »")), $locales);
+ $block->content->selected = (string) locales::cookie_locale();
+ } else {
+ $block = "";
+ }
+ break;
+ }
return $block;
}
static function get_add_block_form() {
$form = new Forge("admin/dashboard/add_block", "", "post",
- array("id" => "gAddDashboardBlockForm"));
+ 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());
+ $group->dropdown("id")->label(t("Available Blocks"))
+ ->options(block_manager::get_available_admin_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_error.php b/modules/gallery/helpers/gallery_error.php
new file mode 100644
index 00000000..551f8c63
--- /dev/null
+++ b/modules/gallery/helpers/gallery_error.php
@@ -0,0 +1,30 @@
+<?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_error_Core {
+ static function error_handler($severity, $message, $filename, $lineno) {
+ if (error_reporting() == 0) {
+ return;
+ }
+
+ if (error_reporting() & $severity) {
+ throw new ErrorException($message, 0, $severity, $filename, $lineno);
+ }
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 64f2a9ff..cd72d01e 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -19,6 +19,49 @@
*/
class gallery_event_Core {
+ /**
+ * Initialization.
+ */
+ static function gallery_ready() {
+ identity::load_user();
+ theme::load_themes();
+ locales::set_request_locale();
+ }
+
+ static function user_deleted($user) {
+ $admin = identity::admin_user();
+ $db = Database::instance();
+ $db->from("tasks")
+ ->set(array("owner_id" => $admin->id))
+ ->where(array("owner_id" => $user->id))
+ ->update();
+ $db->from("items")
+ ->set(array("owner_id" => $admin->id))
+ ->where(array("owner_id" => $user->id))
+ ->update();
+ $db->from("logs")
+ ->set(array("user_id" => $admin->id))
+ ->where(array("user_id" => $user->id))
+ ->update();
+ }
+
+ static function identity_provider_changed($old_provider, $new_provider) {
+ $admin = identity::admin_user();
+ $db = Database::instance();
+ $db->from("tasks")
+ ->set(array("owner_id" => $admin->id))
+ ->where("1 = 1")
+ ->update();
+ $db->from("items")
+ ->set(array("owner_id" => $admin->id))
+ ->where("1 = 1")
+ ->update();
+ $db->from("logs")
+ ->set(array("user_id" => $admin->id))
+ ->where("1 = 1")
+ ->update();
+ }
+
static function group_created($group) {
access::add_group($group);
}
@@ -53,4 +96,287 @@ class gallery_event_Core {
$data[] = $item->name;
$data[] = $item->title;
}
+
+ static function user_menu($menu, $theme) {
+ if ($theme->page_type != "login") {
+ $user = identity::active_user();
+ if ($user->guest) {
+ $menu->append(Menu::factory("dialog")
+ ->id("user_menu_login")
+ ->css_id("g-login-link")
+ ->url(url::site("login/ajax"))
+ ->label(t("Login")));
+ } else {
+ $csrf = access::csrf_token();
+ $menu->append(Menu::factory("dialog")
+ ->id("user_menu_edit_profile")
+ ->css_id("g-user-profile-link")
+ ->view("login_current_user.html")
+ ->url(url::site("form/edit/users/{$user->id}"))
+ ->label($user->display_name()));
+ $menu->append(Menu::factory("link")
+ ->id("user_menu_logout")
+ ->css_id("g-logout-link")
+ ->url(url::site("logout?csrf=$csrf&amp;continue=" .
+ urlencode(url::current(true))))
+ ->label(t("Logout")));
+ }
+ }
+ }
+
+ static function site_menu($menu, $theme) {
+ if ($theme->page_type != "login") {
+ $menu->append(Menu::factory("link")
+ ->id("home")
+ ->label(t("Home"))
+ ->url(item::root()->url()));
+
+
+ $item = $theme->item();
+
+ if (!empty($item)) {
+ $can_edit = $item && access::can("edit", $item);
+ $can_add = $item && access::can("add", $item);
+
+ if ($can_add) {
+ $menu->append($add_menu = Menu::factory("submenu")
+ ->id("add_menu")
+ ->label(t("Add")));
+ $is_album_writable =
+ is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path());
+ if ($is_album_writable) {
+ $add_menu->append(Menu::factory("dialog")
+ ->id("add_photos_item")
+ ->label(t("Add photos"))
+ ->url(url::site("simple_uploader/app/$item->id")));
+ if ($item->is_album()) {
+ $add_menu->append(Menu::factory("dialog")
+ ->id("add_album_item")
+ ->label(t("Add an album"))
+ ->url(url::site("form/add/albums/$item->id?type=album")));
+ }
+ } else {
+ message::warning(t("The album '%album_name' is not writable.",
+ array("album_name" => $item->title)));
+ }
+ }
+
+ 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($option_text));
+ if ($item && ($can_edit || $can_add)) {
+ if ($can_edit) {
+ $options_menu->append(Menu::factory("dialog")
+ ->id("edit_item")
+ ->label($edit_text)
+ ->url(url::site("form/edit/{$item->type}s/$item->id")));
+ }
+
+ if ($item->is_album()) {
+ if ($can_edit) {
+ $options_menu->append(Menu::factory("dialog")
+ ->id("edit_permissions")
+ ->label(t("Edit permissions"))
+ ->url(url::site("permissions/browse/$item->id")));
+ }
+ }
+ }
+ }
+
+ if (identity::active_user()->admin) {
+ $menu->append($admin_menu = Menu::factory("submenu")
+ ->id("admin_menu")
+ ->label(t("Admin")));
+ module::event("admin_menu", $admin_menu, $theme);
+ }
+ }
+ }
+
+ static function admin_menu($menu, $theme) {
+ $menu
+ ->append(Menu::factory("link")
+ ->id("dashboard")
+ ->label(t("Dashboard"))
+ ->url(url::site("admin")))
+ ->append(Menu::factory("submenu")
+ ->id("settings_menu")
+ ->label(t("Settings"))
+ ->append(Menu::factory("link")
+ ->id("graphics_toolkits")
+ ->label(t("Graphics"))
+ ->url(url::site("admin/graphics")))
+ ->append(Menu::factory("link")
+ ->id("languages")
+ ->label(t("Languages"))
+ ->url(url::site("admin/languages")))
+ ->append(Menu::factory("link")
+ ->id("advanced")
+ ->label(t("Advanced"))
+ ->url(url::site("admin/advanced_settings")))
+ ->append(Menu::factory("link")
+ ->id("identity_drivers")
+ ->label(t("Identity drivers"))
+ ->url(url::site("admin/identity"))))
+ ->append(Menu::factory("link")
+ ->id("modules")
+ ->label(t("Modules"))
+ ->url(url::site("admin/modules")))
+ ->append(Menu::factory("submenu")
+ ->id("content_menu")
+ ->label(t("Content")))
+ ->append(Menu::factory("submenu")
+ ->id("appearance_menu")
+ ->label(t("Appearance"))
+ ->append(Menu::factory("link")
+ ->id("themes")
+ ->label(t("Theme choice"))
+ ->url(url::site("admin/themes")))
+ ->append(Menu::factory("link")
+ ->id("theme_options")
+ ->label(t("Theme options"))
+ ->url(url::site("admin/theme_options")))
+ ->append(Menu::factory("link")
+ ->id("sidebar")
+ ->label(t("Manage sidebar"))
+ ->url(url::site("admin/sidebar"))))
+ ->append(Menu::factory("submenu")
+ ->id("statistics_menu")
+ ->label(t("Statistics")))
+ ->append(Menu::factory("link")
+ ->id("maintenance")
+ ->label(t("Maintenance"))
+ ->url(url::site("admin/maintenance")));
+ return $menu;
+ }
+
+ static function context_menu($menu, $theme, $item, $thumb_css_selector) {
+ $menu->append($options_menu = Menu::factory("submenu")
+ ->id("options_menu")
+ ->label(t("Options"))
+ ->css_class("ui-icon-carat-1-n"));
+
+ if (access::can("edit", $item)) {
+ $page_type = $theme->page_type();
+ switch ($item->type) {
+ case "movie":
+ $edit_title = t("Edit this movie");
+ $delete_title = t("Delete this movie");
+ break;
+
+ case "album":
+ $edit_title = t("Edit this album");
+ $delete_title = t("Delete this album");
+ break;
+
+ default:
+ $edit_title = t("Edit this photo");
+ $delete_title = t("Delete this photo");
+ break;
+ }
+ $cover_title = t("Choose as the album cover");
+ $move_title = t("Move to another album");
+
+ $csrf = access::csrf_token();
+
+ $options_menu->append(Menu::factory("dialog")
+ ->id("edit")
+ ->label($edit_title)
+ ->css_class("ui-icon-pencil")
+ ->url(url::site("quick/form_edit/$item->id?page_type=$page_type")));
+
+
+ if ($item->is_photo() && graphics::can("rotate")) {
+ $options_menu
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_ccw")
+ ->label(t("Rotate 90&deg; counter clockwise"))
+ ->css_class("ui-icon-rotate-ccw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")))
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_cw")
+ ->label(t("Rotate 90&deg; clockwise"))
+ ->css_class("ui-icon-rotate-cw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")));
+ }
+
+ // @todo Don't move photos from the photo page; we don't yet have a good way of redirecting after
+ // move
+ if ($page_type == "album") {
+ $options_menu
+ ->append(Menu::factory("dialog")
+ ->id("move")
+ ->label($move_title)
+ ->css_class("ui-icon-folder-open")
+ ->url(url::site("move/browse/$item->id")));
+ }
+
+ $parent = $item->parent();
+ if (access::can("edit", $parent)) {
+ // We can't make this item the highlight if it's an album with no album cover, or if it's
+ // already the album cover.
+ if (($item->type == "album" && empty($item->album_cover_item_id)) ||
+ ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) ||
+ $parent->album_cover_item_id == $item->id) {
+ $disabledState = " ui-state-disabled";
+ } else {
+ $disabledState = " ";
+ }
+ if ($item->parent()->id != 1) {
+ $options_menu
+ ->append(Menu::factory("ajax_link")
+ ->id("make_album_cover")
+ ->label($cover_title)
+ ->css_class("ui-icon-star")
+ ->ajax_handler("function(data) { window.location.reload() }")
+ ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf")));
+ }
+ $options_menu
+ ->append(Menu::factory("dialog")
+ ->id("delete")
+ ->label($delete_title)
+ ->css_class("ui-icon-trash")
+ ->css_id("g-quick-delete")
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")));
+ }
+
+ if ($item->is_album()) {
+ $options_menu
+ ->append(Menu::factory("dialog")
+ ->id("add_item")
+ ->label(t("Add a photo"))
+ ->css_class("ui-icon-plus")
+ ->url(url::site("simple_uploader/app/$item->id")))
+ ->append(Menu::factory("dialog")
+ ->id("add_album")
+ ->label(t("Add an album"))
+ ->css_class("ui-icon-note")
+ ->url(url::site("form/add/albums/$item->id?type=album")))
+ ->append(Menu::factory("dialog")
+ ->id("edit_permissions")
+ ->label(t("Edit permissions"))
+ ->css_class("ui-icon-key")
+ ->url(url::site("permissions/browse/$item->id")));
+ }
+ }
+ }
}
diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php
new file mode 100644
index 00000000..c24d2bde
--- /dev/null
+++ b/modules/gallery/helpers/gallery_graphics.php
@@ -0,0 +1,129 @@
+<?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 {
+ /**
+ * Rotate an image. Valid options are degrees
+ *
+ * @param string $input_file
+ * @param string $output_file
+ * @param array $options
+ */
+ static function rotate($input_file, $output_file, $options) {
+ graphics::init_toolkit();
+
+ module::event("graphics_rotate", $input_file, $output_file, $options);
+
+ Image::factory($input_file)
+ ->quality(module::get_var("gallery", "image_quality"))
+ ->rotate($options["degrees"])
+ ->save($output_file);
+
+ module::event("graphics_rotate_completed", $input_file, $output_file, $options);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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) {
+ try {
+ graphics::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);
+ } catch (ErrorException $e) {
+ Kohana::log("error", $e->get_message());
+ }
+ }
+}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 6500482b..57a5ee9f 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -199,12 +199,12 @@ class gallery_installer {
}
access::register_permission("view", "View");
- access::register_permission("view_full", "View Full Size");
+ access::register_permission("view_full", "View full size");
access::register_permission("edit", "Edit");
access::register_permission("add", "Add");
// Mark for translation (must be the same strings as used above)
- t("View Full Size");
+ t("View full size");
t("View");
t("Edit");
t("Add");
@@ -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);
@@ -235,16 +235,16 @@ class gallery_installer {
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
- "gallery", "thumb", "resize",
+ "gallery", "thumb", "gallery_graphics::resize",
array("width" => 200, "height" => 200, "master" => Image::AUTO),
100);
graphics::add_rule(
- "gallery", "resize", "resize",
+ "gallery", "resize", "gallery_graphics::resize",
array("width" => 640, "height" => 480, "master" => Image::AUTO),
100);
// Instantiate default themes (site and admin)
- foreach (array("default", "admin_default") as $theme_name) {
+ foreach (array("wind", "admin_wind") as $theme_name) {
$theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"),
ArrayObject::ARRAY_AS_PROPS);
$theme = ORM::factory("theme");
@@ -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", 19);
}
static function upgrade($version) {
@@ -317,7 +317,7 @@ class gallery_installer {
}
if ($version == 7) {
- $groups = ORM::factory("group")->find_all();
+ $groups = identity::groups();
$permissions = ORM::factory("permission")->find_all();
foreach($groups as $group) {
foreach($permissions as $permission) {
@@ -364,6 +364,74 @@ 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);
+ }
+
+ if ($version == 13) {
+ // Add rules for generating our thumbnails and resizes
+ Database::instance()->query(
+ "UPDATE {graphics_rules} SET `operation` = CONCAT('gallery_graphics::', `operation`);");
+ module::set_version("gallery", $version = 14);
+ }
+
+ if ($version == 14) {
+ $sidebar_blocks = block_manager::get_active("site_sidebar");
+ if (empty($sidebar_blocks)) {
+ $available_blocks = block_manager::get_available_site_blocks();
+ foreach (array_keys(block_manager::get_available_site_blocks()) as $id) {
+ $sidebar_blocks[] = explode(":", $id);
+ }
+ block_manager::set_active("site_sidebar", $sidebar_blocks);
+ }
+ module::set_version("gallery", $version = 15);
+ }
+
+ if ($version == 15) {
+ module::set_var("gallery", "identity_provider", "user");
+ module::set_version("gallery", $version = 16);
+ }
+
+ // Convert block keys to an md5 hash of the module and block name
+ if ($version == 16) {
+ foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
+ $blocks = block_manager::get_active($location);
+ $new_blocks = array();
+ foreach ($blocks as $block) {
+ $new_blocks[md5("{$block[0]}:{$block[1]}")] = $block;
+ }
+ block_manager::set_active($location, $new_blocks);
+ }
+ module::set_version("gallery", $version = 17);
+ }
+
+ // We didn't like md5 hashes so convert block keys back to random keys to allow duplicates.
+ if ($version == 17) {
+ foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
+ $blocks = block_manager::get_active($location);
+ $new_blocks = array();
+ foreach ($blocks as $block) {
+ $new_blocks[rand()] = $block;
+ }
+ block_manager::set_active($location, $new_blocks);
+ }
+ module::set_version("gallery", $version = 18);
+ }
+
+ // Rename blocks_site.sidebar to blocks_site_sidebar
+ if ($version == 18) {
+ $blocks = block_manager::get_active("site.sidebar");
+ block_manager::set_active("site_sidebar", $blocks);
+ module::clear_var("gallery", "blocks_site.sidebar");
+ module::set_version("gallery", $version = 19);
+ }
}
static function uninstall() {
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index feeab88a..155edfb5 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -39,8 +39,8 @@ class gallery_rss_Core {
->orderby("created", "DESC");
$feed->max_pages = ceil($all_children->find_all()->count() / $limit);
- $feed->title = t("Recent Updates");
- $feed->description = t("Recent Updates");
+ $feed->title = t("Recent updates");
+ $feed->description = t("Recent updates");
return $feed;
case "album":
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 1b56ab97..95216cf0 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -48,9 +48,16 @@ class gallery_task_Core {
$errors = array();
try {
$result = graphics::find_dirty_images_query();
+ $total_count = $task->get("total_count", $result->count());
+ $mode = $task->get("mode", "init");
+ if ($mode == "init") {
+ $task->set("total_count", $total_count);
+ $task->set("mode", "process");
+ batch::start();
+ }
+
$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());
- $remaining = $result->count() - count($ignored);
$i = 0;
foreach ($result as $row) {
@@ -62,19 +69,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,19 +89,20 @@ 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";
+ batch::stop();
site_status::clear("graphics_dirty");
}
} catch (Exception $e) {
diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php
index 20dfeb04..0018fd9a 100644
--- a/modules/gallery/helpers/gallery_theme.php
+++ b/modules/gallery/helpers/gallery_theme.php
@@ -21,6 +21,7 @@ class gallery_theme_Core {
static function head($theme) {
$session = Session::instance();
$buf = "";
+ $theme->css("gallery.css");
if ($session->get("debug")) {
$theme->css("debug.css");
}
@@ -37,16 +38,23 @@ class gallery_theme_Core {
}
}
+ if (count(locales::installed())) {
+ // Needed by the languages block
+ $theme->script("jquery.cookie.js");
+ }
+
if ($session->get("l10n_mode", false)) {
$theme->css("l10n_client.css");
$theme->script("jquery.cookie.js");
$theme->script("l10n_client.js");
}
+ $theme->css("uploadify/uploadify.css");
return $buf;
}
static function admin_head($theme) {
+ $theme->css("gallery.css");
$theme->script("gallery.panel.js");
$session = Session::instance();
if ($session->get("debug")) {
@@ -88,7 +96,7 @@ class gallery_theme_Core {
}
static function credits() {
- return "<li class=\"first\">" .
+ return "<li class=\"g-first\">" .
t(module::get_var("gallery", "credits"),
array("url" => "http://gallery.menalto.com", "version" => gallery::VERSION)) .
"</li>";
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index 78812794..d6a2f00c 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -19,6 +19,7 @@
*/
class graphics_Core {
private static $init;
+ private static $_rules_cache = array();
/**
* Add a new graphics rule.
@@ -26,7 +27,7 @@ class graphics_Core {
* Rules are applied to targets (thumbnails and resizes) in priority order. Rules are functions
* in the graphics class. So for example, the following rule:
*
- * graphics::add_rule("gallery", "thumb", "resize",
+ * graphics::add_rule("gallery", "thumb", "gallery_graphics::resize",
* array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
*
* Specifies that "gallery" is adding a rule to resize thumbnails down to a max of 200px on
@@ -35,7 +36,7 @@ class graphics_Core {
*
* @param string $module_name the module that added the rule
* @param string $target the target for this operation ("thumb" or "resize")
- * @param string $operation the name of the operation
+ * @param string $operation the name of the operation (<defining class>::method)
* @param array $args arguments to the operation
* @param integer $priority the priority for this rule (lower priorities are run first)
*/
@@ -56,7 +57,7 @@ class graphics_Core {
* Remove any matching graphics rules
* @param string $module_name the module that added the rule
* @param string $target the target for this operation ("thumb" or "resize")
- * @param string $operation the name of the operation
+ * @param string $operation the name of the operation(<defining class>::method)
*/
static function remove_rule($module_name, $target, $operation) {
ORM::factory("graphics_rule")
@@ -146,13 +147,9 @@ class graphics_Core {
$working_file = $input_file;
}
- foreach (ORM::factory("graphics_rule")
- ->where("target", $target)
- ->where("active", true)
- ->orderby("priority", "asc")
- ->find_all() as $rule) {
+ foreach (self::_get_rules($target) as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args));
- call_user_func_array(array("graphics", $rule->operation), $args);
+ call_user_func_array($rule->operation, $args);
$working_file = $output_file;
}
}
@@ -180,116 +177,19 @@ 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"));
+ private static function _get_rules($target) {
+ if (empty(self::$_rules_cache[$target])) {
+ $rules = array();
+ foreach (ORM::factory("graphics_rule")
+ ->where("target", $target)
+ ->where("active", true)
+ ->orderby("priority", "asc")
+ ->find_all() as $rule) {
+ $rules[] = (object)$rule->as_array();
}
- $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
- * @param string $output_file
- * @param array $options
- */
- static function rotate($input_file, $output_file, $options) {
- if (!self::$init) {
- self::init_toolkit();
- }
-
- module::event("graphics_rotate", $input_file, $output_file, $options);
-
- Image::factory($input_file)
- ->quality(module::get_var("gallery", "image_quality"))
- ->rotate($options["degrees"])
- ->save($output_file);
-
- module::event("graphics_rotate_completed", $input_file, $output_file, $options);
- }
-
- /**
- * 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;
+ self::$_rules_cache[$target] = $rules;
}
-
- 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 self::$_rules_cache[$target];
}
/**
@@ -327,7 +227,7 @@ class graphics_Core {
"%count of your photos are out of date. <a %attrs>Click here to fix them</a>",
$count,
array("attrs" => html::mark_clean(sprintf(
- 'href="%s" class="gDialogLink"',
+ 'href="%s" class="g-dialog-link"',
url::site("admin/maintenance/start/gallery_task::rebuild_dirty_images?csrf=__CSRF__"))))),
"graphics_dirty");
}
@@ -378,7 +278,10 @@ class graphics_Core {
$toolkits->graphicsmagick->installed = false;
$toolkits->graphicsmagick->error = t("GraphicsMagick requires the <b>exec</b> function");
} else {
- putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
+ $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null);
+
+ putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") .
+ ":/usr/local/bin:/opt/local/bin:/opt/bin");
// @todo: consider refactoring the two segments below into a loop since they are so
// similar.
@@ -463,6 +366,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/identity.php b/modules/gallery/helpers/identity.php
new file mode 100644
index 00000000..72e3312d
--- /dev/null
+++ b/modules/gallery/helpers/identity.php
@@ -0,0 +1,244 @@
+<?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 identity_Core {
+ protected static $available;
+
+ /**
+ * Return a list of installed Identity Drivers.
+ *
+ * @return boolean true if the driver supports updates; false if read only
+ */
+ static function providers() {
+ if (empty(self::$available)) {
+ $drivers = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
+ foreach (module::available() as $module_name => $module) {
+ if (file_exists(MODPATH . "{$module_name}/config/identity.php")) {
+ $drivers->$module_name = $module->description;
+ }
+ }
+ self::$available = $drivers;
+ }
+ return self::$available;
+ }
+
+ /**
+ * Frees the current instance of the identity provider so the next call to instance will reload
+ *
+ * @param string configuration
+ * @return Identity_Core
+ */
+ static function reset() {
+ IdentityProvider::reset();
+ }
+
+ /**
+ * Make sure that we have a session and group_ids cached in the session.
+ */
+ static function load_user() {
+ try {
+ // Call IdentityProvider::instance() now to force the load of the user interface classes.
+ // We are about to load the active user from the session and which needs the user definition
+ // class, which can't be reached by Kohana's heiracrchical lookup.
+ IdentityProvider::instance();
+
+ $session = Session::instance();
+ if (!($user = $session->get("user"))) {
+ self::set_active_user($user = self::guest());
+ }
+
+ // The installer cannot set a user into the session, so it just sets an id which we should
+ // upconvert into a user.
+ // @todo set the user name into the session instead of 2 and then use it to get the user object
+ if ($user === 2) {
+ $user = IdentityProvider::instance()->admin_user();
+ self::set_active_user($user);
+ $session->set("user", $user);
+ }
+
+ if (!$session->get("group_ids")) {
+ $ids = array();
+ foreach ($user->groups as $group) {
+ $ids[] = $group->id;
+ }
+ $session->set("group_ids", $ids);
+ }
+ } catch (Exception $e) {
+ // Log it, so we at least have so notification that we swallowed the exception.
+ Kohana::log("error", "Load_user Exception: " . $e->__toString());
+ try {
+ Session::instance()->destroy();
+ } catch (Exception $e) {
+ // We don't care if there was a problem destroying the session.
+ }
+ url::redirect(item::root()->abs_url());
+ }
+ }
+
+ /**
+ * Return the array of group ids this user belongs to
+ *
+ * @return array
+ */
+ static function group_ids_for_active_user() {
+ return Session::instance()->get("group_ids", array(1));
+ }
+
+ /**
+ * Return the active user. If there's no active user, return the guest user.
+ *
+ * @return User_Definition
+ */
+ static function active_user() {
+ // @todo (maybe) cache this object so we're not always doing session lookups.
+ $user = Session::instance()->get("user", null);
+ if (!isset($user)) {
+ // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary
+ // work.
+ $user = identity::guest();
+ }
+ return $user;
+ }
+
+ /**
+ * Change the active user.
+ * @param User_Definition $user
+ */
+ static function set_active_user($user) {
+ $session = Session::instance();
+ $session->set("user", $user);
+ $session->delete("group_ids");
+ self::load_user();
+ }
+
+ /**
+ * Determine if if the current driver supports updates.
+ *
+ * @return boolean true if the driver supports updates; false if read only
+ */
+ static function is_writable() {
+ return IdentityProvider::instance()->is_writable();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::guest.
+ */
+ static function guest() {
+ return IdentityProvider::instance()->guest();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::admin_user.
+ */
+ static function admin_user() {
+ return IdentityProvider::instance()->admin_user();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_user.
+ */
+ static function create_user($name, $full_name, $password) {
+ return IdentityProvider::instance()->create_user($name, $full_name, $password);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::is_correct_password.
+ */
+ static function is_correct_password($user, $password) {
+ return IdentityProvider::instance()->is_correct_password($user, $password);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user.
+ */
+ static function lookup_user($id) {
+ return IdentityProvider::instance()->lookup_user($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user_by_name.
+ */
+ static function lookup_user_by_name($name) {
+ return IdentityProvider::instance()->lookup_user_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_group.
+ */
+ static function create_group($name) {
+ return IdentityProvider::instance()->create_group($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::everybody.
+ */
+ static function everybody() {
+ return IdentityProvider::instance()->everybody();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::registered_users.
+ */
+ static function registered_users() {
+ return IdentityProvider::instance()->registered_users();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group.
+ */
+ static function lookup_group($id) {
+ return IdentityProvider::instance()->lookup_group($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group_by_name.
+ */
+ static function lookup_group_by_name($name) {
+ return IdentityProvider::instance()->lookup_group_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::get_user_list.
+ */
+ static function get_user_list($ids) {
+ return IdentityProvider::instance()->get_user_list($ids);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::groups.
+ */
+ static function groups() {
+ return IdentityProvider::instance()->groups();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::add_user_to_group.
+ */
+ static function add_user_to_group($user, $group_id) {
+ return IdentityProvider::instance()->add_user_to_group($user, $group_id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::remove_user_to_group.
+ */
+ static function remove_user_from_group($user, $group_id) {
+ return IdentityProvider::instance()->remove_user_from_group($user, $group_id);
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 588c08d4..b3b6d0bb 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -130,7 +130,7 @@ class item_Core {
$page_type = "photo";
}
$form = new Forge(
- "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "gConfirmDelete"));
+ "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete"));
$form->hidden("_method")->value("put");
$group = $form->group("confirm_delete")->label(t("Confirm Deletion"));
$group->submit("")->value(t("Delete"));
@@ -158,8 +158,8 @@ class item_Core {
*/
static function viewable($model) {
$view_restrictions = array();
- if (!user::active()->admin) {
- foreach (user::group_ids() as $id) {
+ if (!identity::active_user()->admin) {
+ foreach (identity::group_ids_for_active_user() as $id) {
// Separate the first restriction from the rest to make it easier for us to formulate
// our where clause below
if (empty($view_restrictions)) {
diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php
index ab7f7526..2de029ff 100644
--- a/modules/gallery/helpers/locales.php
+++ b/modules/gallery/helpers/locales.php
@@ -219,4 +219,36 @@ class locales_Core {
}
return array(null, 0);
}
-} \ No newline at end of file
+
+ static function set_request_locale() {
+ // 1. Check the session specific preference (cookie)
+ $locale = self::cookie_locale();
+ // 2. Check the user's preference
+ if (!$locale) {
+ $locale = identity::active_user()->locale;
+ }
+ // 3. Check the browser's / OS' preference
+ if (!$locale) {
+ $locale = self::locale_from_http_request();
+ }
+ // If we have any preference, override the site's default locale
+ if ($locale) {
+ I18n::instance()->locale($locale);
+ }
+ }
+
+ static function cookie_locale() {
+ $cookie_data = Input::instance()->cookie("g_locale");
+ $locale = null;
+ if ($cookie_data) {
+ if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)$/", trim($cookie_data), $matches)) {
+ $requested_locale = $matches[1];
+ $installed_locales = locales::installed();
+ if (isset($installed_locales[$requested_locale])) {
+ $locale = $requested_locale;
+ }
+ }
+ }
+ return $locale;
+ }
+}
diff --git a/modules/gallery/helpers/log.php b/modules/gallery/helpers/log.php
index 451f985a..184b0b97 100644
--- a/modules/gallery/helpers/log.php
+++ b/modules/gallery/helpers/log.php
@@ -80,7 +80,7 @@ class log_Core {
$log->url = substr(url::abs_current(true), 0, 255);
$log->referer = request::referrer(null);
$log->timestamp = time();
- $log->user_id = user::active()->id;
+ $log->user_id = identity::active_user()->id;
$log->save();
}
@@ -93,16 +93,16 @@ class log_Core {
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
- return "gSuccess";
+ return "g-success";
case self::INFO:
- return "gInfo";
+ return "g-info";
case self::WARNING:
- return "gWarning";
+ return "g-warning";
case self::ERROR:
- return "gError";
+ return "g-error";
}
}
}
diff --git a/modules/gallery/helpers/message.php b/modules/gallery/helpers/message.php
index af3b96cc..02680655 100644
--- a/modules/gallery/helpers/message.php
+++ b/modules/gallery/helpers/message.php
@@ -81,7 +81,7 @@ class message_Core {
$buf[] = "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>";
}
if ($buf) {
- return "<ul id=\"gMessage\">" . implode("", $buf) . "</ul>";
+ return "<ul id=\"g-action-status\" class=\"g-message-block\">" . implode("", $buf) . "</ul>";
}
}
@@ -93,16 +93,16 @@ class message_Core {
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
- return "gSuccess";
+ return "g-success";
case self::INFO:
- return "gInfo";
+ return "g-info";
case self::WARNING:
- return "gWarning";
+ return "g-warning";
case self::ERROR:
- return "gError";
+ return "g-error";
}
}
}
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index a3088c38..e6c196ce 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -50,8 +50,20 @@ class module_Core {
* @param string $module_name
*/
static function get($module_name) {
- // @todo can't easily use model_cache here because it throw an exception on missing models.
- return ORM::factory("module", array("name" => $module_name));
+ if (empty(self::$modules[$module_name])) {
+ return ORM::factory("module", array("name" => $module_name));
+ }
+ return self::$modules[$module_name];
+ }
+
+ /**
+ * Get the information about a module
+ * @returns ArrayObject containing the module information from the module.info file or false if
+ * not found
+ */
+ static function info($module_name) {
+ $module_list = self::available();
+ return isset($module_list->$module_name) ? $module_list->$module_name : false;
}
/**
@@ -79,18 +91,20 @@ class module_Core {
$modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
foreach (glob(MODPATH . "*/module.info") as $file) {
$module_name = basename(dirname($file));
- $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS);
+ $modules->$module_name =
+ new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS);
$m =& $modules->$module_name;
$m->installed = self::is_installed($module_name);
$m->active = self::is_active($module_name);
$m->code_version = $m->version;
$m->version = self::get_version($module_name);
- $m->locked = false;
+ $m->locked = !empty($m->no_module_admin);
}
// Lock certain modules
$modules->gallery->locked = true;
- $modules->user->locked = true;
+ $identity_module = self::get_var("gallery", "identity_provider", "user");
+ $modules->$identity_module->locked = true;
$modules->ksort();
self::$available = $modules;
}
@@ -116,6 +130,8 @@ class module_Core {
array_unshift($kohana_modules, MODPATH . $module_name);
Kohana::config_set("core.modules", $kohana_modules);
+ // Rebuild the include path so the module installer can benefit from auto loading
+ Kohana::include_paths(true);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "install")) {
call_user_func_array(array($installer_class, "install"), array());
@@ -139,10 +155,6 @@ class module_Core {
* @param string $module_name
*/
static function upgrade($module_name) {
- $kohana_modules = Kohana::config("core.modules");
- array_unshift($kohana_modules, MODPATH . $module_name);
- Kohana::config_set("core.modules", $kohana_modules);
-
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "upgrade")) {
@@ -155,11 +167,14 @@ class module_Core {
throw new Exception("@todo UNKNOWN_MODULE");
}
}
- module::load_modules();
- // Now the module is upgraded but inactive, so don't leave it in the active path
- array_shift($kohana_modules);
- Kohana::config_set("core.modules", $kohana_modules);
+ // Now the module is upgraded so deactivate it, but we can'it deactivae gallery or the
+ // current identity provider.
+ $identity_provider = module::get_var("gallery", "identity_provider", "user");
+ if (!in_array($module_name, array("gallery", $identity_provider)) ) {
+ self::deactivate($module_name);
+ }
+ module::load_modules();
$version_after = module::get_version($module_name);
if ($version_before != $version_after) {
@@ -195,6 +210,9 @@ class module_Core {
module::load_modules();
graphics::activate_rules($module_name);
+
+ block_manager::activate_blocks($module_name);
+
log::success(
"module", t("Activated module %module_name", array("module_name" => $module_name)));
}
@@ -219,6 +237,9 @@ class module_Core {
module::load_modules();
graphics::deactivate_rules($module_name);
+
+ block_manager::deactivate_blocks($module_name);
+
log::success(
"module", t("Deactivated module %module_name", array("module_name" => $module_name)));
}
@@ -234,7 +255,7 @@ class module_Core {
call_user_func(array($installer_class, "uninstall"));
}
- graphics::remove_rule($module_name);
+ graphics::remove_rules($module_name);
$module = self::get($module_name);
if ($module->loaded) {
$module->delete();
@@ -283,9 +304,32 @@ class module_Core {
array_shift($args);
$function = str_replace(".", "_", $name);
- // @todo: consider calling gallery_event first, since for things menus we need it to do some
- // setup
+ if (method_exists("gallery_event", $function)) {
+ switch (count($args)) {
+ case 0:
+ gallery_event::$function();
+ break;
+ case 1:
+ gallery_event::$function($args[0]);
+ break;
+ case 2:
+ gallery_event::$function($args[0], $args[1]);
+ break;
+ case 3:
+ gallery_event::$function($args[0], $args[1], $args[2]);
+ break;
+ case 4: // Context menu events have 4 arguments so lets optimize them
+ gallery_event::$function($args[0], $args[1], $args[2], $args[3]);
+ break;
+ default:
+ call_user_func_array(array("gallery_event", $function), $args);
+ }
+ }
+
foreach (self::$active as $module) {
+ if ($module->name == "gallery") {
+ continue;
+ }
$class = "{$module->name}_event";
if (method_exists($class, $function)) {
call_user_func_array(array($class, $function), $args);
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 59bf5c19..e84e8ea6 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -77,7 +77,7 @@ class movie_Core {
$movie->title = $title;
$movie->description = $description;
$movie->name = $name;
- $movie->owner_id = $owner_id ? $owner_id : user::active();
+ $movie->owner_id = $owner_id ? $owner_id : identity::active_user()->id;
$movie->width = $movie_info[0];
$movie->height = $movie_info[1];
$movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
@@ -128,6 +128,38 @@ class movie_Core {
return $movie;
}
+ static function get_edit_form($movie) {
+ $form = new Forge("movies/$movie->id", "", "post", array("id" => "g-edit-movie-form"));
+ $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)
+ ->rules("required")
+ ->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 \".\""))
+ ->error_messages("illegal_extension", t("You cannot change the filename extension"));
+ $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)) {
@@ -158,7 +190,10 @@ class movie_Core {
static function find_ffmpeg() {
if (!$ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) {
- putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
+ $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null);
+
+ putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") .
+ ":/usr/local/bin:/opt/local/bin:/opt/bin");
if (function_exists("exec")) {
$ffmpeg_path = exec("which ffmpeg");
}
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index 3d9fbe69..01cf5278 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -26,7 +26,7 @@
class photo_Core {
/**
* Create a new photo.
- * @param integer $parent_id id of parent album
+ * @param integer $parent parent album
* @param string $filename path to the photo file on disk
* @param string $name the filename to use for this photo in the album
* @param integer $title the title of the new photo
@@ -76,7 +76,7 @@ class photo_Core {
$photo->title = $title;
$photo->description = $description;
$photo->name = $name;
- $photo->owner_id = $owner_id ? $owner_id : user::active();
+ $photo->owner_id = $owner_id ? $owner_id : identity::active_user()->id;
$photo->width = $image_info[0];
$photo->height = $image_info[1];
$photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime'];
@@ -138,7 +138,7 @@ class photo_Core {
}
static function get_add_form($parent) {
- $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddPhotoForm"));
+ $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-add-photo-form"));
$group = $form->group("add_photo")->label(
t("Add Photo to %album_title", array("album_title" => $parent->title)));
$group->input("title")->label(t("Title"));
@@ -157,21 +157,24 @@ class photo_Core {
}
static function get_edit_form($photo) {
- $form = new Forge("photos/$photo->id", "", "post", array("id" => "gEditPhotoForm"));
+ $form = new Forge("photos/$photo->id", "", "post", array("id" => "g-edit-photo-form"));
$form->hidden("_method")->value("put");
$group = $form->group("edit_item")->label(t("Edit Photo"));
$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"))
+ ->rules("required")
+ ->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")
- ->error_messages("no_trailing_period", t("The photo name can't end in \".\""));
+ ->error_messages("no_trailing_period", t("The photo name can't end in \".\""))
+ ->error_messages("illegal_extension", t("You cannot change the filename extension"));
$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"));
diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php
index 6d47e565..2b090776 100644
--- a/modules/gallery/helpers/site_status.php
+++ b/modules/gallery/helpers/site_status.php
@@ -95,7 +95,7 @@ class site_status_Core {
* @return html text
*/
static function get() {
- if (!user::active()->admin) {
+ if (!identity::active_user()->admin) {
return;
}
$buf = array();
@@ -105,7 +105,7 @@ class site_status_Core {
}
if ($buf) {
- return "<ul id=\"gSiteStatus\">" . implode("", $buf) . "</ul>";
+ return "<ul id=\"g-site-status\">" . implode("", $buf) . "</ul>";
}
}
@@ -117,16 +117,16 @@ class site_status_Core {
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
- return "gSuccess";
+ return "g-success";
case self::INFO:
- return "gInfo";
+ return "g-info";
case self::WARNING:
- return "gWarning";
+ return "g-warning";
case self::ERROR:
- return "gError";
+ return "g-error";
}
}
}
diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php
index 9fa04305..dac5f9d3 100644
--- a/modules/gallery/helpers/task.php
+++ b/modules/gallery/helpers/task.php
@@ -42,7 +42,7 @@ class task_Core {
$task->percent_complete = 0;
$task->status = "";
$task->state = "started";
- $task->owner_id = user::active()->id;
+ $task->owner_id = identity::active_user()->id;
$task->context = serialize($context);
$task->save();
diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php
index b46a2c14..da57a37e 100644
--- a/modules/gallery/helpers/theme.php
+++ b/modules/gallery/helpers/theme.php
@@ -29,33 +29,39 @@ class theme_Core {
* active for any given request.
*/
static function load_themes() {
- $modules = Kohana::config("core.modules");
- if (Router::$controller == "admin") {
- array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_admin_theme"));
- } else {
- array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_site_theme"));
+ $path = Input::instance()->server("PATH_INFO");
+ $input = Input::instance();
+ if (empty($path)) {
+ $path = "/" . $input->get("kohana_uri");
}
+ if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) {
+ $theme_name = module::get_var(
+ "gallery",
+ !strncmp($path, "/admin", 6) ? "active_admin_theme" : "active_site_theme");
+ }
+ $modules = Kohana::config("core.modules");
+ array_unshift($modules, THEMEPATH . $theme_name);
Kohana::config_set("core.modules", $modules);
}
static function get_edit_form_admin() {
- $form = new Forge("admin/theme_options/save/", "", null, array("id" =>"gThemeOptionsForm"));
+ $form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form"));
$group = $form->group("edit_theme");
- $group->input("page_size")->label(t("Items per page"))->id("gPageSize")
+ $group->input("page_size")->label(t("Items per page"))->id("g-page-size")
->rules("required|valid_digit")
->value(module::get_var("gallery", "page_size"));
- $group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("gThumbSize")
+ $group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("g-thumb-size")
->rules("required|valid_digit")
->value(module::get_var("gallery", "thumb_size"));
- $group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("gResizeSize")
+ $group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("g-resize-size")
->rules("required|valid_digit")
->value(module::get_var("gallery", "resize_size"));
- $group->textarea("header_text")->label(t("Header text"))->id("gHeaderText")
+ $group->textarea("header_text")->label(t("Header text"))->id("g-header-text")
->value(module::get_var("gallery", "header_text"));
- $group->textarea("footer_text")->label(t("Footer text"))->id("gFooterText")
+ $group->textarea("footer_text")->label(t("Footer text"))->id("g-footer-text")
->value(module::get_var("gallery", "footer_text"));
- $group->checkbox("show_credits")->label(t("Show site credits"))->id("gFooterText")
+ $group->checkbox("show_credits")->label(t("Show site credits"))->id("g-footer-text")
->checked(module::get_var("gallery", "show_credits"));
$group->submit("")->value(t("Save"));
return $form;