From 75b34c55dd810e37570815070788563c2499a6fe Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 20 Nov 2009 17:44:50 +0100 Subject: [PATCH] Move the alarm UI generation from Horde_Alarm to Horde_Notification. --- .../lib/Horde/Notification/Listener/Status.php | 53 ++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/framework/Notification/lib/Horde/Notification/Listener/Status.php b/framework/Notification/lib/Horde/Notification/Listener/Status.php index 7332a5bfa..30d4df766 100644 --- a/framework/Notification/lib/Horde/Notification/Listener/Status.php +++ b/framework/Notification/lib/Horde/Notification/Listener/Status.php @@ -90,10 +90,16 @@ class Horde_Notification_Listener_Status extends Horde_Notification_Listener public function getMessage($message, $options = array()) { $event = $this->getEvent($message); - $text = $event->getMessage(); + $flags = $this->getFlags($message); - if (!in_array('content.raw', $this->getFlags($message))) { - $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset()); + if ($event instanceof Horde_Notification_Event && + $message['type'] == 'horde.alarm') { + $text = $this->_getAlarm($flags['alarm']); + } else { + $text = $event->getMessage(); + if (!in_array('content.raw', $this->getFlags($message))) { + $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset()); + } } return empty($options['data']) @@ -102,6 +108,47 @@ class Horde_Notification_Listener_Status extends Horde_Notification_Listener } /** + * Renders the interface for an alarm notification. + * + * @param array $alarm An alarm hash. + * + * @return string The generated HTML code for the alarm notification. + */ + protected function _getAlarm(array $alarm) + { + $message = htmlspecialchars($alarm['title']); + + if (!empty($alarm['params']['notify']['show'])) { + $message = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $message . ''; + } + + $browser = Horde_Browser::singleton(); + if (!empty($alarm['user']) && $browser->hasFeature('xmlhttpreq')) { + Horde::addScriptFile('prototype.js', 'horde'); + $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/snooze.php', true); + $opts = array('-1' => _("Dismiss"), + '5' => _("5 minutes"), + '15' => _("15 minutes"), + '60' => _("1 hour"), + '360' => _("6 hours"), + '1440' => _("1 day")); + $id = 'snooze_' . md5($alarm['id']); + $message .= ' [' . _("Snooze...") . ']'; + } + + return $message; + } + + /** * Returns all status messages stored via the 'store' option to notify(). * * @param boolean $clear Clear the entries off the internal stack? -- 2.11.0