summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-26 05:43:06 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-26 05:43:06 +0000
commitdee20ed6a2bd92a2e67c27ccc7d60303d66cdcde (patch)
tree0d3b432effb5ba4cc8e6eb2c8627c9661d52ebe8 /core
parent0bef37eb0b077863984eb70ec99c40b2f32840bf (diff)
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.
Diffstat (limited to 'core')
-rw-r--r--core/helpers/core_block.php6
-rw-r--r--core/helpers/core_installer.php9
-rw-r--r--core/helpers/graphics.php18
-rw-r--r--core/helpers/message.php79
-rw-r--r--core/models/message.php21
-rw-r--r--core/views/admin_block_messages.html.php33
6 files changed, 99 insertions, 67 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>
-
-
-
-