Consolidate the imp and dimp notification handler
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 16:43:41 +0000 (10:43 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 18:26:46 +0000 (12:26 -0600)
imp/lib/Notification/Listener/Status.php [new file with mode: 0644]
imp/lib/Notification/Listener/StatusDimp.php [deleted file]
imp/lib/Notification/Listener/StatusImp.php [deleted file]
imp/lib/base.php

diff --git a/imp/lib/Notification/Listener/Status.php b/imp/lib/Notification/Listener/Status.php
new file mode 100644 (file)
index 0000000..c5ee57f
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * The IMP_Notification_Listener_Status:: class extends the
+ * Horde_Notification_Listener_Status:: class to display the messages for
+ * IMP's special message types.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Notification
+ */
+class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Status
+{
+    /**
+     * The view mode.
+     *
+     * @var string
+     */
+    protected $_viewmode;
+
+    /**
+     * Constructor.
+     *
+     * @param array $options  One option required: 'viewmode'.
+     */
+    public function __construct($options)
+    {
+        parent::__construct();
+
+        $this->_viewmode = $options['viewmode'];
+
+        $image_dir = $GLOBALS['registry']->getImageDir();
+
+        $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"));
+    }
+
+    /**
+     * Handle every message of type dimp.*; otherwise delegate back to
+     * the parent.
+     *
+     * @param string $type  The message type in question.
+     *
+     * @return boolean  Whether this listener handles the type.
+     */
+    public function handles($type)
+    {
+        return (($this->_viewmode == 'dimp') &&
+                (substr($type, 0, 5) == 'dimp.')) ||
+                parent::handles($type);
+    }
+
+    /**
+     * 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())
+    {
+        /* For dimp, don't capture notification messages if we are logging
+         * out or accessing the options pages. */
+        if (($this->_viewmode == 'dimp') &&
+            Auth::getAuth() && !strstr($_SERVER['PHP_SELF'], '/prefs.php')) {
+            $options['store'] = true;
+        }
+        parent::notify($messageStack, $options);
+    }
+
+}
diff --git a/imp/lib/Notification/Listener/StatusDimp.php b/imp/lib/Notification/Listener/StatusDimp.php
deleted file mode 100644 (file)
index 954eda7..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-/**
- * The IMP_Notification_Listener_StatusDimp:: class extends the
- * 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/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Jan Schneider <jan@horde.org>
- * @package Horde_Notification
- */
-class IMP_Notification_Listener_StatusDimp extends IMP_Notification_Listener_StatusImp
-{
-    /**
-     * Handle every message of type dimp.*; otherwise delegate back to
-     * the parent.
-     *
-     * @param string $type  The message type in question.
-     *
-     * @return boolean  Whether this listener handles the type.
-     */
-    public function handles($type)
-    {
-        return (substr($type, 0, 5) == 'dimp.') || parent::handles($type);
-    }
-
-    /**
-     * 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())
-    {
-        /* 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;
-        }
-        parent::notify($messageStack, $options);
-    }
-
-}
diff --git a/imp/lib/Notification/Listener/StatusImp.php b/imp/lib/Notification/Listener/StatusImp.php
deleted file mode 100644 (file)
index 9ccd0bf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * The IMP_Notification_Listener_StatusImp:: class extends the
- * Notification_Listener_status:: class to display the messages for
- * IMP's special message types.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Notification
- */
-class IMP_Notification_Listener_StatusImp extends Horde_Notification_Listener_Status
-{
-    /**
-     * Constructor.
-     */
-    public function __construct()
-    {
-        parent::__construct();
-
-        $image_dir = $GLOBALS['registry']->getImageDir();
-
-        $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 f0f523c..1085379 100644 (file)
@@ -165,11 +165,11 @@ $notification = &Horde_Notification::singleton();
 if (($viewmode == 'mimp') ||
     (Horde_Util::nonInputVar('login_page') && $GLOBALS['browser']->isMobile())) {
     $GLOBALS['imp_notify'] = &$notification->attach('status', null, 'Horde_Notification_Listener_Mobile');
-} elseif ($viewmode == 'dimp') {
-    $GLOBALS['imp_notify'] = &$notification->attach('status', null, 'IMP_Notification_Listener_StatusDimp');
 } else {
-    $GLOBALS['imp_notify'] = &$notification->attach('status', null, 'IMP_Notification_Listener_StatusImp');
-    $notification->attach('audio');
+    $GLOBALS['imp_notify'] = &$notification->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status');
+    if ($viewmode == 'imp') {
+        $notification->attach('audio');
+    }
 }
 
 // Initialize global $imp_mbox array.