From dee20ed6a2bd92a2e67c27ccc7d60303d66cdcde Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 26 Dec 2008 05:43:06 +0000 Subject: Added the concept of "permanent" messages that we show to admins. Use this to show a "your thumbs/resizes are out of date" message whenever we change the graphics rules. Tweak watermark module to add graphics rules whenever we make a change, which triggers the graphics module to add the permanent message. --- core/helpers/core_block.php | 6 -- core/helpers/core_installer.php | 9 +++ core/helpers/graphics.php | 18 ++++- core/helpers/message.php | 79 ++++++++++++++-------- core/models/message.php | 21 ++++++ core/views/admin_block_messages.html.php | 33 --------- modules/watermark/controllers/admin_watermarks.php | 23 +++++-- modules/watermark/helpers/watermark_installer.php | 4 +- modules/watermark/views/admin_watermarks.html.php | 2 +- 9 files changed, 119 insertions(+), 76 deletions(-) create mode 100644 core/models/message.php delete mode 100644 core/views/admin_block_messages.html.php 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 @@ -40,12 +40,6 @@ class core_block_Core { $block->content = new View("admin_block_welcome.html"); $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"); 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, "", ""), + "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 = ""; + } + + if ($buf) { + return ""; } } 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 @@ + - - - - - 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 @@

- +

-- cgit v1.2.3