summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/controllers/admin_modules.php4
-rw-r--r--core/controllers/albums.php12
-rw-r--r--core/controllers/photos.php4
-rw-r--r--core/controllers/welcome.php8
-rw-r--r--core/helpers/log.php71
-rw-r--r--core/helpers/message.php69
-rw-r--r--core/helpers/module.php4
-rw-r--r--core/views/admin_block_log_entries.html.php2
8 files changed, 146 insertions, 28 deletions
diff --git a/core/controllers/admin_modules.php b/core/controllers/admin_modules.php
index 152e49c3..c416a699 100644
--- a/core/controllers/admin_modules.php
+++ b/core/controllers/admin_modules.php
@@ -34,10 +34,10 @@ class Admin_Modules_Controller extends Admin_Controller {
$desired = $this->input->post($module_name) == 1;
if ($info->installed && !$desired) {
module::uninstall($module_name);
- message::add(sprintf(_("Uninstalled %s module"), $info->name));
+ message::success(sprintf(_("Uninstalled %s module"), $info->name));
} else if (!$info->installed && $desired) {
module::install($module_name);
- message::add(sprintf(_("Installed %s module"), $info->name));
+ message::success(sprintf(_("Installed %s module"), $info->name));
}
}
url::redirect("admin/modules");
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index 47412dfc..61d6ad22 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -79,9 +79,9 @@ class Albums_Controller extends Items_Controller {
$this->input->post("description"),
user::active()->id);
- log::add("content", "Created an album", log::INFO,
+ log::success("content", "Created an album",
html::anchor("albums/$new_album->id", "view album"));
- message::add(_("Successfully created album"));
+ message::success(sprintf(_("Created album %s"), $new_album->title));
print json_encode(
array("result" => "success",
@@ -107,9 +107,9 @@ class Albums_Controller extends Items_Controller {
$this->input->post("description"),
user::active()->id);
- log::add("content", "Added a photo", log::INFO,
+ log::success("content", "Added a photo",
html::anchor("photos/$photo->id", "view photo"));
- message::add(_("Successfully added photo"));
+ message::add(sprintf(_("Added photo %s"), $photo->title));
print json_encode(
array("result" => "success",
@@ -139,8 +139,8 @@ class Albums_Controller extends Items_Controller {
module::event("album_changed", $album);
- log::add("content", "Updated album", log::INFO, "<a href=\"albums/$album->id\">view</a>");
- message::add(_("Successfully saved album"));
+ log::success("content", "Updated album", "<a href=\"albums/$album->id\">view</a>");
+ message::success(sprintf(_("Saved album %s"), $album->title));
print json_encode(
array("result" => "success",
diff --git a/core/controllers/photos.php b/core/controllers/photos.php
index 04553bd1..13185283 100644
--- a/core/controllers/photos.php
+++ b/core/controllers/photos.php
@@ -56,8 +56,8 @@ class Photos_Controller extends Items_Controller {
module::event("photo_changed", $photo);
- log::add("content", "Updated photo", log::INFO, "<a href=\"photos/$photo->id\">view</a>");
- message::add(_("Successfully saved photo"));
+ log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
+ message::success(sprintf(_("Saved photo %s"), $photo->title));
print json_encode(
array("result" => "success",
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index a5c8c9d6..637ab642 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -206,8 +206,8 @@ class Welcome_Controller extends Template_Controller {
}
if ($photo_count > 0) {
- log::add("content", "(scaffold) Added $photo_count photos", log::INFO,
- html::anchor("albums/$parent_id", "View album"));
+ log::success("content", "(scaffold) Added $photo_count photos"
+ html::anchor("albums/$parent_id", "View album"));
}
url::redirect("welcome");
@@ -245,11 +245,11 @@ class Welcome_Controller extends Template_Controller {
}
if ($photo_count > 0) {
- log::add("content", "(scaffold) Added $photo_count photos");
+ log::success("content", "(scaffold) Added $photo_count photos");
}
if ($album_count > 0) {
- log::add("content", "(scaffold) Added $album_count albums");
+ log::success("content", "(scaffold) Added $album_count albums");
}
url::redirect("welcome");
}
diff --git a/core/helpers/log.php b/core/helpers/log.php
index 43e2b8f8..4b135465 100644
--- a/core/helpers/log.php
+++ b/core/helpers/log.php
@@ -18,9 +18,50 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class log_Core {
- const INFO = 1;
- const WARNING = 2;
- const ERROR = 3;
+ const SUCCESS = 1;
+ const INFO = 2;
+ const WARNING = 3;
+ const ERROR = 4;
+
+ /**
+ * Report a successful event.
+ * @param string $category an arbitrary category we can use to filter log messages
+ * @param string $message a detailed log message
+ * @param string $html an html snippet presented alongside the log message to aid the admin
+ */
+ public static function success($category, $message, $html="") {
+ self::add($category, $message, $html, self::SUCCESS);
+ }
+
+ /**
+ * Report an informational event.
+ * @param string $category an arbitrary category we can use to filter log messages
+ * @param string $message a detailed log message
+ * @param string $html an html snippet presented alongside the log message to aid the admin
+ */
+ public static function info($category, $message, $html="") {
+ self::add($category, $message, $html, self::INFO);
+ }
+
+ /**
+ * Report that something went wrong, not fatal, but worth investigation.
+ * @param string $category an arbitrary category we can use to filter log messages
+ * @param string $message a detailed log message
+ * @param string $html an html snippet presented alongside the log message to aid the admin
+ */
+ public static function warning($category, $message, $html="") {
+ self::add($category, $message, $html, self::WARNING);
+ }
+
+ /**
+ * Report that something went wrong that should be fixed.
+ * @param string $category an arbitrary category we can use to filter log messages
+ * @param string $message a detailed log message
+ * @param string $html an html snippet presented alongside the log message to aid the admin
+ */
+ public static function error($category, $message, $html="") {
+ self::add($category, $message, $html, self::ERROR);
+ }
/**
* Add a log entry.
@@ -30,7 +71,7 @@ class log_Core {
* @param integer $severity INFO, WARNING or ERROR
* @param string $html an html snippet presented alongside the log message to aid the admin
*/
- function add($category, $message, $severity=log::INFO, $html="") {
+ private static function add($category, $message, $html, $severity) {
$log = ORM::factory("log");
$log->category = $category;
$log->message = $message;
@@ -44,4 +85,26 @@ class log_Core {
}
$log->save();
}
+
+
+ /**
+ * 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";
+ }
+ }
}
diff --git a/core/helpers/message.php b/core/helpers/message.php
index 1aa09e49..4c4d1e0a 100644
--- a/core/helpers/message.php
+++ b/core/helpers/message.php
@@ -18,33 +18,88 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class message_Core {
- public function add($msg, $severity=log::INFO) {
+ const SUCCESS = 1;
+ const INFO = 2;
+ const WARNING = 3;
+ const ERROR = 4;
+
+ /**
+ * Report a successful event.
+ * @param string $msg a detailed message
+ */
+ public static function success($msg) {
+ self::add($msg, self::SUCCESS);
+ }
+
+ /**
+ * Report an informational event.
+ * @param string $msg a detailed message
+ */
+ public static function info($msg) {
+ self::add($msg, self::INFO);
+ }
+
+ /**
+ * Report that something went wrong, not fatal, but worth investigation.
+ * @param string $msg a detailed message
+ */
+ public static function warning($msg) {
+ self::add($msg, self::WARNING);
+ }
+
+ /**
+ * Report that something went wrong that should be fixed.
+ * @param string $msg a detailed message
+ */
+ public static function error($msg) {
+ self::add($msg, self::ERROR);
+ }
+
+ /**
+ * 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
+ */
+ private function add($msg, $severity) {
$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.
+ * @return html text
+ */
public function get() {
- $messages = Session::instance()->get_once("messages", array());
- if ($messages) {
+ $msgs = Session::instance()->get_once("messages", array());
+ if ($msgs) {
$buf = "<ul id=\"gMessages\">";
- foreach ($messages as $msg) {
+ foreach ($msgs as $msg) {
$buf .= "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>";
}
return $buf .= "</ul>";
}
}
+ /**
+ * Convert a message severity to a CSS class
+ * @param integer $severity
+ * @return string
+ */
public function severity_class($severity) {
switch($severity) {
- case log::INFO:
+ case self::SUCCESS:
+ return "gSuccess";
+
+ case self::INFO:
return "gInfo";
- case log::WARNING:
+ case self::WARNING:
return "gWarning";
- case log::ERROR:
+ case self::ERROR:
return "gError";
}
}
diff --git a/core/helpers/module.php b/core/helpers/module.php
index 5dddfa61..415ecf4b 100644
--- a/core/helpers/module.php
+++ b/core/helpers/module.php
@@ -127,7 +127,7 @@ class module_Core {
}
self::load_modules();
- log::add("module", sprintf(_("Installed module %s"), $module_name));
+ log::success("module", sprintf(_("Installed module %s"), $module_name));
}
/**
@@ -137,7 +137,7 @@ class module_Core {
$installer_class = "{$module_name}_installer";
Kohana::log("debug", "$installer_class uninstall");
call_user_func(array($installer_class, "uninstall"));
- log::add("module", sprintf(_("Uninstalled module %s"), $module_name));
+ log::success("module", sprintf(_("Uninstalled module %s"), $module_name));
}
/**
diff --git a/core/views/admin_block_log_entries.html.php b/core/views/admin_block_log_entries.html.php
index 7b25d3fc..c0d9729d 100644
--- a/core/views/admin_block_log_entries.html.php
+++ b/core/views/admin_block_log_entries.html.php
@@ -1,7 +1,7 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
<ul>
<? foreach ($entries as $entry): ?>
- <li class="<?= message::severity_class($entry->severity) ?>">
+ <li class="<?= log::severity_class($entry->severity) ?>">
<a href="<?= url::site("user/$entry->user_id") ?>"><?= $entry->user->name ?></a>
<?= date("Y-M-d H:i:s", $entry->timestamp) ?>
<?= $entry->message ?>