Offload much of the notification work to the base drivers
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 01:02:59 +0000 (19:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 02:06:33 +0000 (20:06 -0600)
imp/lib/DIMP.php
imp/lib/Notification/Listener/StatusDimp.php
imp/lib/Notification/Listener/StatusImp.php
kronolith/lib/Notification/Listener/Status.php

index a7ce633..7efba55 100644 (file)
@@ -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) . ')'
index fc57882..954eda7 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 /**
  * The IMP_Notification_Listener_StatusDimp:: class extends the
- * IMP_Notification_Listener_StatusImp:: class to return all messages instead
- * of printing them.
+ * IMP_Notification_Listener_StatusImp:: class to return all dimp specific
+ * messages instead of printing them.
  *
  * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
  *
 class IMP_Notification_Listener_StatusDimp extends IMP_Notification_Listener_StatusImp
 {
     /**
-     * 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.
      *
@@ -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);
     }
 
 }
index 052d595..9ccd0bf 100644 (file)
@@ -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 <chuck@horde.org>
  * @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 '<p class="notice">' . Horde::img('mail_answered.png') . '&nbsp;&nbsp;' . $event->getMessage() . '</p>';
 
-        case 'imp.forward':
-        case 'imp.redirect':
-            return '<p class="notice">' . Horde::img('mail_forwarded.png') . '&nbsp;&nbsp;' . $event->getMessage() . '</p>';
-        }
+        $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"));
     }
 
 }
index 91958a3..f22bcc8 100644 (file)
@@ -1,47 +1,20 @@
 <?php
 /**
  * The Kronolith_Notification_Listener_Status:: class extends the
- * Horde_Notification_Listener_Status:: class to return all messages instead
- * of printing them.
+ * Horde_Notification_Listener_Status:: class to return all kronolith messages
+ * instead of printing them.
  *
  * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
- * @todo    Move this into Notification core functionality
  * @author  Jan Schneider <jan@horde.org>
  * @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);
     }
 
 }