diff options
-rw-r--r-- | core/helpers/core_block.php | 6 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 9 | ||||
-rw-r--r-- | core/helpers/graphics.php | 18 | ||||
-rw-r--r-- | core/helpers/message.php | 79 | ||||
-rw-r--r-- | core/models/message.php | 21 | ||||
-rw-r--r-- | core/views/admin_block_messages.html.php | 33 | ||||
-rw-r--r-- | modules/watermark/controllers/admin_watermarks.php | 23 | ||||
-rw-r--r-- | modules/watermark/helpers/watermark_installer.php | 4 | ||||
-rw-r--r-- | modules/watermark/views/admin_watermarks.html.php | 2 |
9 files changed, 119 insertions, 76 deletions
diff --git a/core/helpers/core_block.php b/core/helpers/core_block.php index b7e4ad44..1bc70a13 100644 --- a/core/helpers/core_block.php +++ b/core/helpers/core_block.php @@ -41,12 +41,6 @@ class core_block_Core { $blocks[] = $block; $block = new Block(); - $block->id = "gMessages"; - $block->title = _("Status Messages"); - $block->content = new View("admin_block_messages.html"); - $blocks[] = $block; - - $block = new Block(); $block->id = "gPhotoStream"; $block->title = _("Photo Stream"); $block->content = new View("admin_block_photo_stream.html"); diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index ee40b07d..d3147a02 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -95,6 +95,15 @@ class core_installer { PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE `messages` ( + `id` int(9) NOT NULL auto_increment, + `key` varchar(255) default NULL, + `value` varchar(255) default NULL, + `severity` varchar(32) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`key`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE `modules` ( `id` int(9) NOT NULL auto_increment, `name` varchar(255) default NULL, diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index c695abb2..b0d5a08e 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -44,6 +44,8 @@ class graphics_Core { $rule->priority = $priority; $rule->args = serialize($args); $rule->save(); + + self::mark_all_dirty(); } /** @@ -52,7 +54,10 @@ class graphics_Core { */ public static function remove_rules($module_name) { $db = Database::instance(); - $db->query("DELETE FROM `graphics_rules` WHERE `module_name` = '$module_name'"); + $result = $db->query("DELETE FROM `graphics_rules` WHERE `module_name` = '$module_name'"); + if ($result->count()) { + self::mark_all_dirty(); + } } /** @@ -129,5 +134,16 @@ class graphics_Core { */ public static function mark_all_dirty() { Database::instance()->query("UPDATE `items` SET `thumb_dirty` = 1, `resize_dirty` = 1"); + + $count = ORM::factory("item") + ->where("thumb_dirty", 1) + ->orwhere("resize_dirty", 1) + ->count_all(); + if ($count) { + message::warning( + sprintf(_("%d of your photos are out of date. %sClick here to fix them%s"), + $count, "<a href=\"#\">", "</a>"), + "graphics_dirty"); + } } } diff --git a/core/helpers/message.php b/core/helpers/message.php index 4c4d1e0a..4860bea6 100644 --- a/core/helpers/message.php +++ b/core/helpers/message.php @@ -25,61 +25,86 @@ class message_Core { /** * Report a successful event. - * @param string $msg a detailed message + * @param string $msg a detailed message + * @param string $permanent_key make this message permanent and store it under this key */ - public static function success($msg) { - self::add($msg, self::SUCCESS); + public static function success($msg, $permanent_key=null) { + self::add($msg, self::SUCCESS, $permanent_key); } /** * Report an informational event. - * @param string $msg a detailed message + * @param string $msg a detailed message + * @param string $permanent_key make this message permanent and store it under this key */ - public static function info($msg) { - self::add($msg, self::INFO); + public static function info($msg, $permanent_key=null) { + self::add($msg, self::INFO, $permanent_key); } /** * Report that something went wrong, not fatal, but worth investigation. - * @param string $msg a detailed message + * @param string $msg a detailed message + * @param string $permanent_key make this message permanent and store it under this key */ - public static function warning($msg) { - self::add($msg, self::WARNING); + public static function warning($msg, $permanent_key=null) { + self::add($msg, self::WARNING, $permanent_key); } /** * Report that something went wrong that should be fixed. - * @param string $msg a detailed message + * @param string $msg a detailed message + * @param string $permanent_key make this message permanent and store it under this key */ - public static function error($msg) { - self::add($msg, self::ERROR); + public static function error($msg, $permanent_key=null) { + self::add($msg, self::ERROR, $permanent_key); } /** * Save a message in the session for our next page load. - * @param string $msg a detailed message - * @param integer $severity one of the severity constants + * @param string $msg a detailed message + * @param integer $severity one of the severity constants + * @param string $permanent_key make this message permanent and store it under this key */ - private function add($msg, $severity) { - $session = Session::instance(); - $status = $session->get("messages"); - $status[] = array($msg, $severity); - $session->set("messages", $status); + private function add($msg, $severity, $permanent_key=null) { + if ($permanent_key) { + $message = ORM::factory("message") + ->where("key", $permanent_key) + ->find(); + if (!$message->loaded) { + $message->key = $permanent_key; + } + $message->severity = $severity; + $message->value = $msg; + $message->save(); + } else { + $session = Session::instance(); + $status = $session->get("messages"); + $status[] = array($msg, $severity); + $session->set("messages", $status); + } } /** - * Get any pending messages. These must be displayed to the user since they can only be - * retrieved once. + * Get any pending messages. There are two types of messages, transient and permanent. + * Permanent messages are used to let the admin know that there are pending administrative + * issues that need to be resolved. Transient ones are only displayed once. * @return html text */ public function get() { - $msgs = Session::instance()->get_once("messages", array()); - if ($msgs) { - $buf = "<ul id=\"gMessages\">"; - foreach ($msgs as $msg) { - $buf .= "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>"; + $buf = array(); + + foreach (Session::instance()->get_once("messages", array()) as $msg) { + $buf[] = "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>"; + } + + if (user::active()->admin) { + foreach (ORM::factory("message")->find_all() as $msg) { + $buf[] = "<li class=\"" . self::severity_class($msg->severity) . "\">$msg->value</li>"; } - return $buf .= "</ul>"; + } + + if ($buf) { + return "<ul id=\"gMessages\">" . implode("", $buf) . "</ul>"; } } diff --git a/core/models/message.php b/core/models/message.php new file mode 100644 index 00000000..06997453 --- /dev/null +++ b/core/models/message.php @@ -0,0 +1,21 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Message_Model extends ORM { +} diff --git a/core/views/admin_block_messages.html.php b/core/views/admin_block_messages.html.php deleted file mode 100644 index ee97c2c1..00000000 --- a/core/views/admin_block_messages.html.php +++ /dev/null @@ -1,33 +0,0 @@ -<? defined("SYSPATH") or die("No direct script access."); ?> -<ul> - <li class="gWarning"> - <a href="#" title=""> - Gallery 3.1 is available, you're running Gallery 3.0. Update now! - </a> - </li> - <li class="gError"> - <a href="#" title=""> - Unable to write to /home/username/gallery3/var - </a> - </li> - <li class="gSuccess"> - <a href="#" title=""> - Permissions issues fixed - </a> - </li> - <li class="gInfo"> - <a href="#" title=""> - Just a plain information message - </a> - </li> - <li class="gHelp"> - <a href="#" title=""> - Contextual help or tip<br/> - And here's a second line - </a> - </li> -</ul> - - - - diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index 733e0589..9f87fed4 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -40,8 +40,9 @@ class Admin_Watermarks_Controller extends Admin_Controller { public function edit() { $form = watermark::get_edit_form(); if ($form->validate()) { - module::set_var("watermark", "position", $form->edit_watermark->position->value); - graphics::mark_all_dirty(); + $position = $form->edit_watermark->position->value; + module::set_var("watermark", "position", $position); + $this->_update_graphics_rules(module::get_var("watermark", "name"), $position); log::success("watermark", _("Watermark changed")); message::success(_("Watermark changed")); @@ -70,7 +71,7 @@ class Admin_Watermarks_Controller extends Admin_Controller { module::clear_var("watermark", "height"); module::clear_var("watermark", "mime_type"); module::clear_var("watermark", "position"); - graphics::mark_all_dirty(); + $this->_update_graphics_rules(); log::success("watermark", _("Watermark deleted")); message::success(_("Watermark deleted")); @@ -105,12 +106,13 @@ class Admin_Watermarks_Controller extends Admin_Controller { } rename($file, VARPATH . "modules/watermark/$name"); + $position = $form->add_watermark->position->value; module::set_var("watermark", "name", $name); module::set_var("watermark", "width", $image_info[0]); module::set_var("watermark", "height", $image_info[1]); module::set_var("watermark", "mime_type", $image_info["mime"]); - module::set_var("watermark", "position", $form->add_watermark->position->value); - graphics::mark_all_dirty(); + module::set_var("watermark", "position", $position); + $this->_update_graphics_rules(module::get_var("watermark", "name"), $position); @unlink($file); message::success(_("Watermark saved")); @@ -124,4 +126,15 @@ class Admin_Watermarks_Controller extends Admin_Controller { "form" => $form->__toString())); } } + + private function _update_graphics_rules($name=null, $position=null) { + graphics::remove_rules("watermark"); + if ($name) { + graphics::add_rule( + "watermark", "thumb", "compose", + array("overlay" => VARPATH . "modules/watermark/$name", + "position" => $position), + 1000); + } + } }
\ No newline at end of file diff --git a/modules/watermark/helpers/watermark_installer.php b/modules/watermark/helpers/watermark_installer.php index 52957273..01dfa40a 100644 --- a/modules/watermark/helpers/watermark_installer.php +++ b/modules/watermark/helpers/watermark_installer.php @@ -40,9 +40,7 @@ class watermark_installer { } public static function uninstall() { - if (module::get_var("watermark", "name")) { - graphics::mark_all_dirty(); - } + graphics::remove_rules("watermark"); module::delete("watermark"); Database::instance()->query("DROP TABLE `watermarks`"); dir::unlink(VARPATH . "modules/watermark"); diff --git a/modules/watermark/views/admin_watermarks.html.php b/modules/watermark/views/admin_watermarks.html.php index 214c673b..7ba8a844 100644 --- a/modules/watermark/views/admin_watermarks.html.php +++ b/modules/watermark/views/admin_watermarks.html.php @@ -12,7 +12,7 @@ <? else: ?> <h2> <?= _("Active Watermark") ?> </h2> <p> - <?= _("Note that changing this watermark will rebuild all of your thumbnails and resized images.") ?> + <?= _("Note that changing this watermark will require you to rebuild all of your thumbnails and resized images.") ?> </p> <p> <div class="image"> |