summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/album.php23
-rw-r--r--modules/gallery/helpers/gallery.php179
-rw-r--r--modules/gallery/helpers/gallery_installer.php32
-rw-r--r--modules/gallery/helpers/gallery_quick.php152
-rw-r--r--modules/gallery/helpers/gallery_rss.php5
-rw-r--r--modules/gallery/helpers/gallery_theme.php32
-rw-r--r--modules/gallery/helpers/graphics.php92
-rw-r--r--modules/gallery/helpers/item.php53
-rw-r--r--modules/gallery/helpers/module.php8
-rw-r--r--modules/gallery/helpers/photo.php8
-rw-r--r--modules/gallery/helpers/task.php1
11 files changed, 324 insertions, 261 deletions
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index 8a7c9951..d46f21ac 100644
--- a/modules/gallery/helpers/album.php
+++ b/modules/gallery/helpers/album.php
@@ -56,7 +56,7 @@ class album_Core {
$album->thumb_dirty = 1;
$album->resize_dirty = 1;
$album->rand_key = ((float)mt_rand()) / (float)mt_getrandmax();
- $album->sort_column = "weight";
+ $album->sort_column = "created";
$album->sort_order = "ASC";
while (ORM::factory("item")
@@ -116,13 +116,7 @@ class album_Core {
$sort_order->dropdown("column", array("id" => "gAlbumSortColumn"))
->label(t("Sort by"))
- ->options(array("weight" => t("Order Added"),
- "captured" => t("Capture Date"),
- "created" => t("Creation Date"),
- "title" => t("Title"),
- "updated" => t("Updated Date"),
- "view_count" => t("Number of views"),
- "rand_key" => t("Random")))
+ ->options(album::get_sort_order_options())
->selected($parent->sort_column);
$sort_order->dropdown("direction", array("id" => "gAlbumSortDirection"))
->label(t("Order"))
@@ -137,4 +131,17 @@ class album_Core {
$form->add_rules_from(ORM::factory("item"));
return $form;
}
+
+ /**
+ * Return a structured set of all the possible sort orders.
+ */
+ static function get_sort_order_options() {
+ return array("weight" => t("Manual"),
+ "captured" => t("Date captured"),
+ "created" => t("Date uploaded"),
+ "title" => t("Title"),
+ "updated" => t("Date modified"),
+ "view_count" => t("Number of views"),
+ "rand_key" => t("Random"));
+ }
}
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 476e9cbe..122227fc 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -82,9 +82,9 @@ class gallery_Core {
static function site_menu($menu, $theme) {
if ($theme->page_type != "login") {
$menu->append(Menu::factory("link")
- ->id("home")
- ->label(t("Home"))
- ->url(url::site("albums/1")));
+ ->id("home")
+ ->label(t("Home"))
+ ->url(url::site("albums/1")));
$item = $theme->item();
@@ -92,48 +92,47 @@ class gallery_Core {
$can_add = $item && access::can("add", $item);
if ($can_add) {
- $menu->append(Menu::factory("dialog")
- ->id("add_photos_item")
- ->label(t("Add photos"))
- ->url(url::site("simple_uploader/app/$item->id")));
+ $menu->append($add_menu = Menu::factory("submenu")
+ ->id("add_menu")
+ ->label(t("Add")));
+ $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")));
+ }
}
$menu->append($options_menu = Menu::factory("submenu")
- ->id("options_menu")
- ->label(t("Options")));
+ ->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")));
+ $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")));
}
- // @todo Move album options menu to the album quick edit pane
if ($item->is_album()) {
- if ($can_add) {
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("add_album")
- ->label(t("Add an album"))
- ->url(url::site("form/add/albums/$item->id?type=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")));
+ $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")));
+ ->id("admin_menu")
+ ->label(t("Admin")));
gallery::admin_menu($admin_menu, $theme);
module::event("admin_menu", $admin_menu, $theme);
}
@@ -160,12 +159,6 @@ class gallery_Core {
->label(t("Languages"))
->url(url::site("admin/languages")))
->append(Menu::factory("link")
- ->id("l10n_mode")
- ->label(Session::instance()->get("l10n_mode", false)
- ? t("Stop translating") : t("Start translating"))
- ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" .
- access::csrf_token())))
- ->append(Menu::factory("link")
->id("advanced")
->label(t("Advanced"))
->url(url::site("admin/advanced_settings"))))
@@ -196,4 +189,118 @@ class gallery_Core {
->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° 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° 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 = " ";
+ }
+ $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")))
+ ->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("add_item")
+ ->url(url::site("simple_uploader/app/$item->id")))
+ ->append(Menu::factory("dialog")
+ ->id("add_album")
+ ->label(t("Add an album"))
+ ->css_class("add_album")
+ ->url(url::site("form/add/albums/$item->id?type=album")))
+ ->append(Menu::factory("dialog")
+ ->id("edit_permissions")
+ ->label(t("Edit permissions"))
+ ->css_class("permissions")
+ ->url(url::site("permissions/browse/$item->id")));
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index d12dad70..a212ef85 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -24,13 +24,13 @@ class gallery_installer {
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {access_intents} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {caches} (
`id` int(9) NOT NULL auto_increment,
@@ -40,7 +40,7 @@ class gallery_installer {
`cache` longblob,
PRIMARY KEY (`id`),
KEY (`tags`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {graphics_rules} (
`id` int(9) NOT NULL auto_increment,
@@ -51,7 +51,7 @@ class gallery_installer {
`priority` int(9) NOT NULL,
`target` varchar(32) NOT NULL,
PRIMARY KEY (`id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {incoming_translations} (
`id` int(9) NOT NULL auto_increment,
@@ -63,7 +63,7 @@ class gallery_installer {
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {items} (
`id` int(9) NOT NULL auto_increment,
@@ -100,7 +100,7 @@ class gallery_installer {
KEY `type` (`type`),
KEY `random` (`rand_key`),
KEY `weight` (`weight` DESC))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {logs} (
`id` int(9) NOT NULL auto_increment,
@@ -113,7 +113,7 @@ class gallery_installer {
`url` varchar(255) default NULL,
`user_id` int(9) default 0,
PRIMARY KEY (`id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {messages} (
`id` int(9) NOT NULL auto_increment,
@@ -122,7 +122,7 @@ class gallery_installer {
`value` varchar(255) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {modules} (
`id` int(9) NOT NULL auto_increment,
@@ -131,7 +131,7 @@ class gallery_installer {
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {outgoing_translations} (
`id` int(9) NOT NULL auto_increment,
@@ -143,7 +143,7 @@ class gallery_installer {
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {permissions} (
`id` int(9) NOT NULL auto_increment,
@@ -151,14 +151,14 @@ class gallery_installer {
`name` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {sessions} (
`session_id` varchar(127) NOT NULL,
`data` text NOT NULL,
`last_activity` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`session_id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {tasks} (
`id` int(9) NOT NULL auto_increment,
@@ -173,7 +173,7 @@ class gallery_installer {
`updated` int(9) default NULL,
PRIMARY KEY (`id`),
KEY (`owner_id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {themes} (
`id` int(9) NOT NULL auto_increment,
@@ -181,7 +181,7 @@ class gallery_installer {
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {vars} (
`id` int(9) NOT NULL auto_increment,
@@ -190,7 +190,7 @@ class gallery_installer {
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`module_name`, `name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) {
@mkdir(VARPATH . $dir);
@@ -284,7 +284,7 @@ class gallery_installer {
`cache` text,
PRIMARY KEY (`id`),
KEY (`tags`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
module::set_version("gallery", $version = 4);
}
diff --git a/modules/gallery/helpers/gallery_quick.php b/modules/gallery/helpers/gallery_quick.php
deleted file mode 100644
index 8a92890b..00000000
--- a/modules/gallery/helpers/gallery_quick.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?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_quick_Core {
- static function get_quick_buttons($item, $page_type) {
- $buttons = self::buttons($item, $page_type);
- foreach (module::active() as $module) {
- if ($module->name == "gallery") {
- continue;
- }
- $class_name = "{$module->name}_quick";
- if (method_exists($class_name, "buttons")) {
- $module_buttons = call_user_func(array($class_name, "buttons"), $item, $page_type);
- foreach (array("left", "center", "right", "additional") as $position) {
- if (!empty($module_buttons[$position])) {
- $buttons[$position] = array_merge($buttons[$position], $module_buttons[$position]);
- }
- }
- }
- }
-
- $sorted_buttons->main = array();
- foreach (array("left", "center", "right") as $position) {
- $sorted_buttons->main = array_merge($sorted_buttons->main, $buttons[$position]);
- }
-
- $sorted_buttons->additional = $buttons["additional"];
- $max_display = empty($sorted_buttons->additional) ? 6 : 5;
- if (count($sorted_buttons->main) >= $max_display) {
- $to_move = array_slice($sorted_buttons->main, 5);
- $sorted_buttons->additional = array_merge($to_move, $sorted_buttons->additional);
- for ($i = count($sorted_buttons->main); $i >= 5; $i--) {
- unset($sorted_buttons->main[$i]);
- }
- }
-
- return $sorted_buttons;
- }
-
- static function buttons($item, $page_type) {
- $elements = array("left" => array(), "center" => array(), "right" => array(),
- "additional" => array());
- switch ($item->type) {
- case "movie":
- $edit_title = t("Edit this movie");
- $move_title = t("Move this movie to another album");
- $cover_title = t("Choose this movie as the album cover");
- $delete_title = t("Delete this movie");
- break;
- case "album":
- $edit_title = t("Edit this album");
- $move_title = t("Move this album to another album");
- $cover_title = t("Choose this album as the album cover");
- $delete_title = t("Delete this album");
- break;
- default:
- $edit_title = t("Edit this photo");
- $move_title = t("Move this photo to another album");
- $cover_title = t("Choose this photo as the album cover");
- $delete_title = t("Delete this photo");
- break;
- }
-
- $csrf = access::csrf_token();
- $elements["left"][] = (object)array(
- "title" => $edit_title,
- "class" => "gDialogLink gButtonLink",
- "icon" => "ui-icon-pencil",
- "href" => url::site("quick/form_edit/$item->id?page_type=$page_type"));
-
- if ($item->is_photo() && graphics::can("rotate")) {
- $elements["left"][] =
- (object)array(
- "title" => t("Rotate 90 degrees counter clockwise"),
- "class" => "gButtonLink",
- "icon" => "ui-icon-rotate-ccw",
- "href" => url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type"));
- $elements["left"][] =
- (object)array(
- "title" => t("Rotate 90 degrees clockwise"),
- "class" => "gButtonLink",
- "icon" => "ui-icon-rotate-cw",
- "href" => 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") {
- $elements["left"][] = (object)array(
- "title" => $move_title,
- "class" => "gDialogLink gButtonLink",
- "icon" => "ui-icon-folder-open",
- "href" => 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 = " ";
- }
- $elements["right"][] = (object)array(
- "title" => $cover_title,
- "class" => "gButtonLink$disabledState",
- "icon" => "ui-icon-star",
- "href" => url::site("quick/make_album_cover/$item->id?csrf=$csrf&page_type=$page_type"));
-
- $elements["right"][] = (object)array(
- "title" => $delete_title,
- "class" => "gDialogLink gButtonLink",
- "icon" => "ui-icon-trash",
- "id" => "gQuickDelete",
- "href" => url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type"));
- }
-
- if ($item->is_album()) {
- $elements["additional"][] = (object)array(
- "title" => t("Add a photo"),
- "class" => "add_item gDialogLink",
- "href" => url::site("simple_uploader/app/$item->id"));
- $elements["additional"][] = (object)array(
- "title" => t("Add an album"),
- "class" => "add_album gDialogLink",
- "href" => url::site("form/add/albums/$item->id?type=album"));
- $elements["additional"][] = (object)array(
- "title" => t("Edit permissions"),
- "class" => "permissions gDialogLink",
- "href" => url::site("permissions/browse/$item->id"));
- }
- return $elements;
- }
-}
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index be555296..affb3101 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -50,8 +50,9 @@ class gallery_rss_Core {
$feed->children = $item
->viewable()
- ->descendants($limit, $offset, "photo");
- $feed->max_pages = ceil($item->viewable()->descendants_count("photo") / $limit);
+ ->descendants($limit, $offset, array("type" => "photo"));
+ $feed->max_pages = ceil(
+ $item->viewable()->descendants_count(array("type" => "photo")) / $limit);
$feed->title = SafeString::purify($item->title);
$feed->link = url::abs_site("albums/{$item->id}");
$feed->description = nl2br(SafeString::purify($item->description));
diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php
index d3751b80..69c5a091 100644
--- a/modules/gallery/helpers/gallery_theme.php
+++ b/modules/gallery/helpers/gallery_theme.php
@@ -24,11 +24,6 @@ class gallery_theme_Core {
if ($session->get("debug")) {
$theme->css("debug.css");
}
- if (($theme->page_type == "album" || $theme->page_type == "photo")
- && access::can("edit", $theme->item())) {
- $theme->css("quick.css");
- $theme->script("quick.js");
- }
if (module::is_active("rss")) {
if ($item = $theme->item()) {
@@ -51,33 +46,8 @@ class gallery_theme_Core {
return $buf;
}
- static function resize_top($theme, $item) {
- if (access::can("edit", $item)) {
- $edit_link = url::site("quick/pane/$item->id?page_type=photo");
- return "<div class=\"gQuick\" href=\"$edit_link\">";
- }
- }
-
- static function resize_bottom($theme, $item) {
- if (access::can("edit", $item)) {
- return "</div>";
- }
- }
-
- static function thumb_top($theme, $child) {
- if (access::can("edit", $child)) {
- $edit_link = url::site("quick/pane/$child->id?page_type=album");
- return "<div class=\"gQuick\" href=\"$edit_link\">";
- }
- }
-
- static function thumb_bottom($theme, $child) {
- if (access::can("edit", $child)) {
- return "</div>";
- }
- }
-
static function admin_head($theme) {
+ $theme->script("gallery.panel.js");
$session = Session::instance();
if ($session->get("debug")) {
$theme->css("debug.css");
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index d506a982..7dc46eeb 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -339,15 +339,90 @@ class graphics_Core {
* GraphicsMagick we return the path to the directory containing the appropriate binaries.
*/
static function detect_toolkits() {
+ $toolkits = new stdClass();
+
+ // GD is special, it doesn't use exec()
$gd = function_exists("gd_info") ? gd_info() : array();
- $exec = function_exists("exec");
+ $toolkits->gd->name = "GD";
if (!isset($gd["GD Version"])) {
- $gd["GD Version"] = false;
+ $toolkits->gd->installed = false;
+ $toolkits->gd->error = t("GD is not installed");
+ } else {
+ $toolkits->gd->installed = true;
+ $toolkits->gd->version = $gd["GD Version"];
+ $toolkits->gd->rotate = function_exists("imagerotate");
+ $toolkits->gd->binary = "";
+ $toolkits->gd->dir = "";
+
+ if (!$toolkits->gd->rotate) {
+ $toolkits->gd->error =
+ t("You have GD version %version, but it lacks image rotation.",
+ array("version" => $gd["GD Version"]));
+ }
+ }
+
+ if (!function_exists("exec")) {
+ $toolkits->imagemagick->installed = false;
+ $toolkits->imagemagick->error = t("ImageMagick requires the <b>exec</b> function");
+
+ $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");
+
+ // @todo: consider refactoring the two segments below into a loop since they are so
+ // similar.
+
+ // ImageMagick
+ $path = exec("which convert");
+ $toolkits->imagemagick->name = "ImageMagick";
+ if ($path) {
+ if (@is_file($path)) {
+ preg_match('/Version: \S+ (\S+)/', `convert -v`, $matches);
+ $version = $matches[1];
+
+ $toolkits->imagemagick->installed = true;
+ $toolkits->imagemagick->version = $version;
+ $toolkits->imagemagick->binary = $path;
+ $toolkits->imagemagick->dir = dirname($path);
+ $toolkits->imagemagick->rotate = true;
+ } else {
+ $toolkits->imagemagick->installed = false;
+ $toolkits->imagemagick->error =
+ t("ImageMagick is installed, but PHP's open_basedir restriction " .
+ "prevents Gallery from using it.");
+ }
+ } else {
+ $toolkits->imagemagick->installed = false;
+ $toolkits->imagemagick->error = t("We could not locate ImageMagick on your system.");
+ }
+
+ // GraphicsMagick
+ $path = exec("which gm");
+ $toolkits->graphicsmagick->name = "GraphicsMagick";
+ if ($path) {
+ if (@is_file($path)) {
+ preg_match('/\S+ (\S+)/', `gm version`, $matches);
+ $version = $matches[1];
+
+ $toolkits->graphicsmagick->installed = true;
+ $toolkits->graphicsmagick->version = $version;
+ $toolkits->graphicsmagick->binary = $path;
+ $toolkits->graphicsmagick->dir = dirname($path);
+ $toolkits->graphicsmagick->rotate = true;
+ } else {
+ $toolkits->graphicsmagick->installed = false;
+ $toolkits->graphicsmagick->error =
+ t("GraphicsMagick is installed, but PHP's open_basedir restriction " .
+ "prevents Gallery from using it.");
+ }
+ } else {
+ $toolkits->graphicsmagick->installed = false;
+ $toolkits->graphicsmagick->error = t("We could not locate GraphicsMagick on your system.");
+ }
}
- putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
- return array("gd" => $gd,
- "imagemagick" => $exec ? dirname(exec("which convert")) : false,
- "graphicsmagick" => $exec ? dirname(exec("which gm")) : false);
+
+ return $toolkits;
}
/**
@@ -357,12 +432,13 @@ class graphics_Core {
// Detect a graphics toolkit
$toolkits = graphics::detect_toolkits();
foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) {
- if ($toolkits[$tk]) {
+ if ($toolkits->$tk->installed) {
module::set_var("gallery", "graphics_toolkit", $tk);
- module::set_var("gallery", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]);
+ module::set_var("gallery", "graphics_toolkit_path", $toolkits->$tk->dir);
break;
}
}
+
if (!module::get_var("gallery", "graphics_toolkit")) {
site_status::warning(
t("Graphics toolkit missing! Please <a href=\"%url\">choose a toolkit</a>",
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 80c25862..8839861f 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -129,7 +129,7 @@ class item_Core {
if (Input::instance()->get("page_type") == "album") {
$page_type = "album";
} else {
- $page_type = "item";
+ $page_type = "photo";
}
$form = new Forge("quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "gConfirmDelete"));
$form->hidden("_method")->value("put");
@@ -137,4 +137,55 @@ class item_Core {
$group->submit("")->value(t("Delete"));
return $form;
}
+
+ /**
+ * Get the next weight value
+ */
+ static function get_max_weight() {
+ // Guard against an empty result when we create the first item. It's unfortunate that we
+ // have to check this every time.
+ // @todo: figure out a better way to bootstrap the weight.
+ $result = Database::instance()
+ ->select("weight")->from("items")
+ ->orderby("weight", "desc")->limit(1)
+ ->get()->current();
+ return ($result ? $result->weight : 0) + 1;
+ }
+
+ /**
+ * Add a set of restrictions to any following queries to restrict access only to items
+ * viewable by the active user.
+ * @chainable
+ */
+ static function viewable($model) {
+ $view_restrictions = array();
+ if (!user::active()->admin) {
+ foreach (user::group_ids() 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)) {
+ $view_restrictions[0] = "items.view_$id";
+ } else {
+ $view_restrictions[1]["items.view_$id"] = access::ALLOW;
+ }
+ }
+ }
+ switch (count($view_restrictions)) {
+ case 0:
+ break;
+
+ case 1:
+ $model->where($view_restrictions[0], access::ALLOW);
+ break;
+
+ default:
+ $model->open_paren();
+ $model->where($view_restrictions[0], access::ALLOW);
+ $model->orwhere($view_restrictions[1]);
+ $model->close_paren();
+ break;
+ }
+
+ return $model;
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 0d483206..03d538a9 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -274,11 +274,9 @@ class module_Core {
array_shift($args);
$function = str_replace(".", "_", $name);
- foreach (self::$modules as $module) {
- if (!$module->active) {
- continue;
- }
-
+ // @todo: consider calling gallery_event first, since for things menus we need it to do some
+ // setup
+ foreach (self::$active as $module) {
$class = "{$module->name}_event";
if (method_exists($class, $function)) {
call_user_func_array(array($class, $function), $args);
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index 5cf37de1..96a66d29 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -109,8 +109,12 @@ class photo_Core {
// there's only one save() happening here.
module::event("item_created", $photo);
- // Build our thumbnail/resizes
- graphics::generate($photo);
+ // Build our thumbnail/resizes. If we fail to build thumbnail/resize we assume that the image
+ // is bad in some way and discard it.
+ if (!graphics::generate($photo)) {
+ $photo->delete();
+ throw new Exception("@todo BAD_IMAGE_FILE");
+ }
// If the parent has no cover item, make this it.
if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php
index 352fe522..9fa04305 100644
--- a/modules/gallery/helpers/task.php
+++ b/modules/gallery/helpers/task.php
@@ -84,6 +84,7 @@ class task_Core {
}
$task->save();
} catch (Exception $e) {
+ Kohana::log("error", $e->__toString());
$task->log($e->__toString());
$task->state = "error";
$task->done = true;