From ec25cc3f1c1959d0ddc0c3ec4c52b32bcbd02399 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 24 Jun 2009 19:02:59 -0600 Subject: [PATCH] Offload much of the notification work to the base drivers --- imp/lib/DIMP.php | 2 +- imp/lib/Notification/Listener/StatusDimp.php | 57 ++++++------------------- imp/lib/Notification/Listener/StatusImp.php | 28 +++---------- kronolith/lib/Notification/Listener/Status.php | 58 ++++++-------------------- 4 files changed, 30 insertions(+), 115 deletions(-) diff --git a/imp/lib/DIMP.php b/imp/lib/DIMP.php index a7ce633a7..7efba5592 100644 --- a/imp/lib/DIMP.php +++ b/imp/lib/DIMP.php @@ -129,7 +129,7 @@ class DIMP static public function notify() { $GLOBALS['notification']->notify(array('listeners' => 'status')); - $msgs = $GLOBALS['imp_notify']->getStack(true); + $msgs = $GLOBALS['imp_notify']->getStack(); return count($msgs) ? 'DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')' diff --git a/imp/lib/Notification/Listener/StatusDimp.php b/imp/lib/Notification/Listener/StatusDimp.php index fc578827c..954eda709 100644 --- a/imp/lib/Notification/Listener/StatusDimp.php +++ b/imp/lib/Notification/Listener/StatusDimp.php @@ -1,8 +1,8 @@ _messageStack[] = array('type' => $message['type'], - 'flags' => $message['flags'], - 'message' => is_object($event) - ? $event->getMessage() - : null); - } - } - - /** * Handle every message of type dimp.*; otherwise delegate back to * the parent. * @@ -54,27 +28,20 @@ class IMP_Notification_Listener_StatusDimp extends IMP_Notification_Listener_Sta } /** - * Returns the message stack. - * To return something useful, notify() needs to be called first. - * - * @param boolean $encode Encode HTML entities? + * Returns all status message if there are any on the 'status' message + * stack. * - * @return array List of message hashes. + * @param array &$messageStack The stack of messages. + * @param array $options An array of options. */ - public function getStack($encode = false) + public function notify(&$messageStack, $options = array()) { - $msgs = $this->_messageStack; - if (!$encode) { - return $msgs; + /* Don't capture notification messages if we are logging out are + * accessing the options pages. */ + if (Auth::getAuth() && !strstr($_SERVER['PHP_SELF'], '/prefs.php')) { + $options['store'] = true; } - - for ($i = 0, $mcount = count($msgs); $i < $mcount; ++$i) { - if (!in_array('content.raw', $this->getFlags($msgs[$i]))) { - $msgs[$i]['message'] = htmlspecialchars($msgs[$i]['message'], ENT_COMPAT, NLS::getCharset()); - } - } - - return $msgs; + parent::notify($messageStack, $options); } } diff --git a/imp/lib/Notification/Listener/StatusImp.php b/imp/lib/Notification/Listener/StatusImp.php index 052d595e1..9ccd0bf19 100644 --- a/imp/lib/Notification/Listener/StatusImp.php +++ b/imp/lib/Notification/Listener/StatusImp.php @@ -2,7 +2,7 @@ /** * The IMP_Notification_Listener_StatusImp:: class extends the * Notification_Listener_status:: class to display the messages for - * IMP's special message types 'imp.forward' and 'imp.reply'. + * IMP's special message types. * * @author Chuck Hagenbuch * @package Horde_Notification @@ -15,30 +15,12 @@ class IMP_Notification_Listener_StatusImp extends Horde_Notification_Listener_St public function __construct() { parent::__construct(); - $this->_handles['imp.reply'] = true; - $this->_handles['imp.forward'] = true; - $this->_handles['imp.redirect'] = true; - } - - /** - * Outputs one message if it's an IMP message or calls the parent - * method otherwise. - * - * @param array $message One message hash from the stack. - */ - public function getMessage($message) - { - $event = $this->getEvent($message); - switch ($message['type']) { - case 'imp.reply': - return '

' . Horde::img('mail_answered.png') . '  ' . $event->getMessage() . '

'; - case 'imp.forward': - case 'imp.redirect': - return '

' . Horde::img('mail_forwarded.png') . '  ' . $event->getMessage() . '

'; - } + $image_dir = $GLOBALS['registry']->getImageDir(); - return parent::getMessage($message); + $this->_handles['imp.reply'] = array($image_dir . '/mail_answered.png', _("Reply")); + $this->_handles['imp.forward'] = array($image_dir . '/mail_forwarded.png', _("Reply")); + $this->_handles['imp.redirect'] = array($image_dir . '/mail_forwarded.png', _("Redirect")); } } diff --git a/kronolith/lib/Notification/Listener/Status.php b/kronolith/lib/Notification/Listener/Status.php index 91958a30f..f22bcc810 100644 --- a/kronolith/lib/Notification/Listener/Status.php +++ b/kronolith/lib/Notification/Listener/Status.php @@ -1,47 +1,20 @@ * @package Horde_Notification */ class Kronolith_Notification_Listener_Status extends Horde_Notification_Listener_Status { /** - * The notified message stack. - * - * @var array - */ - protected $_messageStack = array(); - - /** - * Returns all status message if there are any on the 'status' message - * stack. - * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options. - */ - public function notify(&$messageStack, $options = array()) - { - while ($message = array_shift($messageStack)) { - $event = @unserialize($message['event']); - $this->_messageStack[] = array('type' => $message['type'], - 'flags' => $message['flags'], - 'message' => is_object($event) - ? $event->getMessage() - : null); - } - } - - /** * Handle every message of type dimp.*; otherwise delegate back to * the parent. * @@ -55,27 +28,20 @@ class Kronolith_Notification_Listener_Status extends Horde_Notification_Listener } /** - * Returns the message stack. - * To return something useful, notify() needs to be called first. - * - * @param boolean $encode Encode HTML entities? + * Returns all status message if there are any on the 'status' message + * stack. * - * @return array List of message hashes. + * @param array &$messageStack The stack of messages. + * @param array $options An array of options. */ - public function getStack($encode = false) + public function notify(&$messageStack, $options = array()) { - $msgs = $this->_messageStack; - if (!$encode) { - return $msgs; + /* Don't capture notification messages if we are logging out are + * accessing the options pages. */ + if (Auth::getAuth() && !strstr($_SERVER['PHP_SELF'], '/prefs.php')) { + $options['store'] = true; } - - for ($i = 0, $mcount = count($msgs); $i < $mcount; ++$i) { - if (!in_array('content.raw', $this->getFlags($msgs[$i]))) { - $msgs[$i]['message'] = htmlspecialchars($msgs[$i]['message'], ENT_COMPAT, NLS::getCharset()); - } - } - - return $msgs; + parent::notify($messageStack, $options); } } -- 2.11.0