summaryrefslogtreecommitdiff
path: root/core/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-29 00:35:31 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-29 00:35:31 +0000
commitb46bfdd4921e27ed472aabfd06ab7c95f30e7e62 (patch)
treee522d493e45bf30514566e8da4f0f1d268f706e1 /core/helpers
parented8689f768f81d2c3ed8bee70c43d4f7c71c108e (diff)
Separate permanent messages out of the message helper and put them
into site_status. Show site status in the header in the admin theme.
Diffstat (limited to 'core/helpers')
-rw-r--r--core/helpers/graphics.php7
-rw-r--r--core/helpers/message.php60
-rw-r--r--core/helpers/site_status.php129
3 files changed, 146 insertions, 50 deletions
diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php
index 62bde88a..8f0bb6a3 100644
--- a/core/helpers/graphics.php
+++ b/core/helpers/graphics.php
@@ -156,10 +156,11 @@ class graphics_Core {
$count = self::find_dirty_images_query()->count();
if ($count) {
- message::warning(
+ site_status::warning(
sprintf(_("%d of your photos are out of date. %sClick here to fix them%s"),
$count, "<a href=\"" .
- url::site("admin/maintenance/start/rebuild_images?csrf=" . access::csrf_token()) .
+ url::site("admin/maintenance/start/graphics::rebuild_dirty_images?csrf=" .
+ access::csrf_token()) .
"\" class=\"gDialogLink\">", "</a>"),
"graphics_dirty");
}
@@ -204,7 +205,7 @@ class graphics_Core {
if ($remaining == 0) {
$task->done = true;
$task->state = "success";
- message::clear_permanent("graphics_dirty");
+ site_status::clear("graphics_dirty");
}
}
}
diff --git a/core/helpers/message.php b/core/helpers/message.php
index 25d7c150..206ba212 100644
--- a/core/helpers/message.php
+++ b/core/helpers/message.php
@@ -26,36 +26,32 @@ class message_Core {
/**
* Report a successful event.
* @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, $permanent_key=null) {
- self::add($msg, self::SUCCESS, $permanent_key);
+ public static function success($msg) {
+ self::add($msg, self::SUCCESS);
}
/**
* Report an informational event.
* @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, $permanent_key=null) {
+ public static function info($msg) {
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 $permanent_key make this message permanent and store it under this key
*/
- public static function warning($msg, $permanent_key=null) {
+ public static function warning($msg) {
self::add($msg, self::WARNING, $permanent_key);
}
/**
* Report that something went wrong that should be fixed.
* @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, $permanent_key=null) {
+ public static function error($msg) {
self::add($msg, self::ERROR, $permanent_key);
}
@@ -63,36 +59,12 @@ class message_Core {
* 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 $permanent_key make this message permanent and store it under this key
*/
- 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);
- }
- }
-
- /**
- * Remove any permanent message by key.
- * @param string $permanent_key
- */
- public function clear_permanent($permanent_key) {
- $message = ORM::factory("message")->where("key", $permanent_key)->find();
- if ($message->loaded) {
- $message->delete();
- }
+ private function add($msg, $severity) {
+ $session = Session::instance();
+ $status = $session->get("messages");
+ $status[] = array($msg, $severity);
+ $session->set("messages", $status);
}
/**
@@ -104,18 +76,12 @@ class message_Core {
public function get() {
$buf = array();
- foreach (Session::instance()->get_once("messages", array()) as $msg) {
+ $messages = Session::instance()->get_once("messages", array());
+ foreach ($messages 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>";
- }
- }
-
if ($buf) {
- return "<ul id=\"gMessages\">" . implode("", $buf) . "</ul>";
+ return "<ul id=\"gMessage\">" . implode("", $buf) . "</ul>";
}
}
diff --git a/core/helpers/site_status.php b/core/helpers/site_status.php
new file mode 100644
index 00000000..ccddd3fb
--- /dev/null
+++ b/core/helpers/site_status.php
@@ -0,0 +1,129 @@
+<?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 site_status_Core {
+ const SUCCESS = 1;
+ const INFO = 2;
+ const WARNING = 3;
+ const ERROR = 4;
+
+ /**
+ * Report a successful event.
+ * @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, $permanent_key) {
+ self::add($msg, self::SUCCESS, $permanent_key);
+ }
+
+ /**
+ * Report an informational event.
+ * @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, $permanent_key) {
+ 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 $permanent_key make this message permanent and store it under this key
+ */
+ public static function warning($msg, $permanent_key) {
+ self::add($msg, self::WARNING, $permanent_key);
+ }
+
+ /**
+ * Report that something went wrong that should be fixed.
+ * @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, $permanent_key) {
+ 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 $permanent_key make this message permanent and store it under this key
+ */
+ private function add($msg, $severity, $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();
+ }
+
+ /**
+ * Remove any permanent message by key.
+ * @param string $permanent_key
+ */
+ public function clear($permanent_key) {
+ $message = ORM::factory("message")->where("key", $permanent_key)->find();
+ if ($message->loaded) {
+ $message->delete();
+ }
+ }
+
+ /**
+ * 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() {
+ $buf = array();
+
+ foreach (ORM::factory("message")->find_all() as $msg) {
+ $buf[] = "<li class=\"" . self::severity_class($msg->severity) . "\">$msg->value</li>";
+ }
+
+ if ($buf) {
+ return "<ul id=\"gSiteStatus\">" . implode("", $buf) . "</ul>";
+ }
+ }
+
+ /**
+ * Convert a message severity to a CSS class
+ * @param integer $severity
+ * @return string
+ */
+ public function severity_class($severity) {
+ switch($severity) {
+ case self::SUCCESS:
+ return "gSuccess";
+
+ case self::INFO:
+ return "gInfo";
+
+ case self::WARNING:
+ return "gWarning";
+
+ case self::ERROR:
+ return "gError";
+ }
+ }
+}