diff options
Diffstat (limited to 'core/helpers')
-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 |
4 files changed, 78 insertions, 34 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>"; } } |