Another Notification rewrite.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Feb 2010 06:27:31 +0000 (23:27 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 18 Feb 2010 07:46:01 +0000 (00:46 -0700)
First, fix Bug #8870. Fixed by removing Nag specific event type
(nag.alarm).  However, this was just a symptom of a larger problem.

The problem: using application specific Notification handlers to handle
application specific event types.  The problem comes when switching
between applications.  Since these application handlers don't have any
knowledge of each other, events created by one handler may not be able
to be displayed when notify() was eventually called, because another
status handler had replaced the original handler.

The solution: all notifications need to be handled by a single,
centralized source - namely, the horde-level handlers.  Application
specific details are instead injected into the horde-level handler to
extend behavior.

While reworking the code, also provided opportunity to remove all
application-specific code from Notification.  Horde-specific
instantiation (i.e. adding Horde logging and Alarm decorators) is now
done in Horde_Core rather than in the base Notification object.

Additionally, rework some of the complexity added to the package.  I
believe the goal of the recent Notification changes was to make the
Notification package testable and/or usable outside of a base Horde
install.  But these changes also made the code unreadable, redundant,
and overly complex.

e.g. using interfaces where simple class extensions
make much more sense (IMHO - there are very few cases where an interface
makes more sense than an abstract class. Using interfaces for the
Handler class was simply overkill.  Out of the 10 methods defined, there
are only 2 methods useful for decorator purposes - push() and notify().
And any given decorator won't even use both of these.  Having to contort
code to do things like chaining handlers to achieve this in an interface
pattern was almost impossible to follow.  It is much simpler to simply
add decorators directly to the base handler object.

60 files changed:
framework/Ajax/lib/Horde/Ajax/Application/Base.php
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Core/Binder/Notification.php [new file with mode: 0644]
framework/Core/lib/Horde/Core/Notification/Status.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
framework/Notification/lib/Horde/Notification.php
framework/Notification/lib/Horde/Notification/Event.php
framework/Notification/lib/Horde/Notification/Event/Status.php [new file with mode: 0644]
framework/Notification/lib/Horde/Notification/Handler.php [new file with mode: 0644]
framework/Notification/lib/Horde/Notification/Handler/Base.php [deleted file]
framework/Notification/lib/Horde/Notification/Handler/Decorator/Alarm.php
framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php [new file with mode: 0644]
framework/Notification/lib/Horde/Notification/Handler/Decorator/Hordelog.php
framework/Notification/lib/Horde/Notification/Handler/Decorator/Log.php
framework/Notification/lib/Horde/Notification/Handler/Interface.php [deleted file]
framework/Notification/lib/Horde/Notification/Listener.php
framework/Notification/lib/Horde/Notification/Listener/Audio.php
framework/Notification/lib/Horde/Notification/Listener/Javascript.php
framework/Notification/lib/Horde/Notification/Listener/Mobile.php [deleted file]
framework/Notification/lib/Horde/Notification/Listener/Status.php
framework/Notification/package.xml
framework/Notification/test/Horde/Notification/Autoload.php
framework/Notification/test/Horde/Notification/Class/Notification/EventTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php [deleted file]
framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php
framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php [new file with mode: 0644]
framework/Notification/test/Horde/Notification/Class/Notification/Listener/AudioTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Listener/MobileTest.php [deleted file]
framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php
framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php
framework/Notification/test/Horde/Notification/Class/NotificationTest.php
framework/Prefs/lib/Horde/Prefs/Ui.php
horde/services/ajax.php
horde/services/prefs.php
imp/compose-dimp.php
imp/js/DimpCore.js
imp/lib/Ajax/Application.php
imp/lib/Application.php
imp/lib/Auth.php
imp/lib/Dimp.php
imp/lib/Notification/Event/Status.php [new file with mode: 0644]
imp/lib/Notification/Handler/Decorator/Imap.php [new file with mode: 0644]
imp/lib/Notification/Listener/AjaxStatus.php [new file with mode: 0644]
imp/lib/Notification/Listener/Status.php [deleted file]
imp/lib/Notification/Listener/StatusMobile.php [deleted file]
imp/message-dimp.php
imp/message-mimp.php
imp/templates/compose/compose-mimp.inc
imp/templates/compose/redirect-mimp.inc
imp/templates/folders/folders-mimp.inc
imp/templates/mailbox/mailbox-mimp.inc
imp/templates/mailbox/search-mimp.inc
kronolith/lib/Ajax/Application.php
nag/lib/Application.php
nag/lib/Nag.php
nag/lib/Notification/Listener/Status.php [deleted file]

index 6eda893..9acc00c 100644 (file)
 abstract class Horde_Ajax_Application_Base
 {
     /**
+     * Determines if notification information is sent in response.
+     *
+     * @var boolean
+     */
+    public $notify = false;
+
+    /**
      * The Horde application.
      *
      * @var string
@@ -88,17 +95,6 @@ abstract class Horde_Ajax_Application_Base
     }
 
     /**
-     * Returns a notification handler object to use to output any
-     * notification messages triggered by the AJAX action.
-     *
-     * @return Horde_Notification_Handler_Base  The notification handler.
-     */
-    public function notificationHandler()
-    {
-        return null;
-    }
-
-    /**
      * Determines the HTTP response output type.
      *
      * @see Horde::sendHTTPResponse().
index ebbc071..60d1445 100644 (file)
@@ -607,17 +607,16 @@ HTML;
     /**
      * Returns a stdClass response object with added notification information.
      *
-     * @param mixed $data                      The 'response' data.
-     * @param Notification_Listener $listener  If set, adds notification
-     *                                         information to object.
+     * @param mixed $data      The 'response' data.
+     * @param boolean $notify  If true, adds notification info to object.
      */
-    static public function prepareResponse($data = null, $listener = null)
+    static public function prepareResponse($data = null, $notify = false)
     {
         $response = new stdClass();
         $response->response = $data;
-        if ($listener) {
-            $GLOBALS['notification']->notify(array('listeners' => 'status', 'store' => true));
-            $stack = $listener->getStack();
+
+        if ($notify) {
+            $stack = $GLOBALS['notification']->notify(array('listeners' => 'status', 'raw' => true));
             if (!empty($stack)) {
                 $response->msgs = $stack;
             }
diff --git a/framework/Core/lib/Horde/Core/Binder/Notification.php b/framework/Core/lib/Horde/Core/Binder/Notification.php
new file mode 100644 (file)
index 0000000..780dda7
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+class Horde_Core_Binder_Notification implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        $notify = Horde_Notification::singleton();
+
+        $notify->addType('default', '*', 'Horde_Core_Notification_Status');
+        $notify->addType('status', 'horde.*', 'Horde_Core_Notification_Status');
+
+        $notify->addDecorator(new Horde_Notification_Handler_Decorator_Alarm(Horde_Alarm::factory(), Horde_Auth::getAuth()));
+        $notify->addDecorator(new Horde_Notification_Handler_Decorator_Hordelog());
+
+        return $notify;
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
diff --git a/framework/Core/lib/Horde/Core/Notification/Status.php b/framework/Core/lib/Horde/Core/Notification/Status.php
new file mode 100644 (file)
index 0000000..676e419
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+/**
+ * This class defines the base Horde status notification types.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@curecanti.org>
+ * @package Horde_Core
+ */
+class Horde_Core_Notification_Status extends Horde_Notification_Event_Status
+{
+    /**
+     * Constructor.
+     *
+     * @param mixed $data   Message: either a string or an Exception or
+     *                      PEAR_Error object.
+     * @param string $type  The event type.
+     * @param array $flags  The flag array.
+     */
+    public function __construct($data, $type = null, array $flags = array())
+    {
+        if (is_null($type)) {
+            $type = ($data instanceof PEAR_Error || $data instanceof Exception)
+                ? 'horde.error'
+                : (is_string($data) ? 'horde.message' : 'horde.error');
+        }
+
+        parent::__construct($data, $type, $flags);
+    }
+
+    /**
+     * String representation of this object.
+     *
+     * @return string  String representation.
+     */
+    public function __toString()
+    {
+        $text = null;
+
+        switch ($this->type) {
+        case 'horde.alarm':
+            $alarm = $this->flags['alarm'];
+            $text = $alarm['title'];
+
+            if (!empty($alarm['params']['notify']['show'])) {
+                $text = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $text . '</a>';
+            }
+
+            if (!empty($alarm['user']) &&
+                $GLOBALS['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']);
+                $text .= ' <small onmouseover="if(typeof ' . $id . '_t!=\'undefined\')clearTimeout(' . $id . '_t);Element.show(\'' . $id . '\')" onmouseout="' . $id . '_t=setTimeout(function(){Element.hide(\'' . $id . '\')},500)">[' . _("Snooze...") . '<span id="' . $id . '" style="display:none"> ';
+                $first = true;
+                foreach ($opts as $minutes => $desc) {
+                    if (!$first) {
+                        $text .= ', ';
+                    }
+                    $text .= Horde::link('#', '', '', '', 'new Ajax.Request(\'' . $url . '\',{parameters:{alarm:\'' . $alarm['id'] . '\',snooze:' . $minutes . '},onSuccess:function(){Element.remove(this);}.bind(this.parentNode.parentNode.parentNode)});return false;') . $desc . '</a>';
+                    $first = false;
+                }
+                $text .= '</span>]</small>';
+            }
+
+            $img = 'alerts/alarm.png';
+            $label = _("Alarm");
+            break;
+
+        case 'horde.error':
+            $img = 'alerts/error.png';
+            $label = _("Error");
+            $text = parent::__toString($this->message);
+            break;
+
+        case 'horde.message':
+            $img = 'alerts/message.png';
+            $label = _("Message");
+            $text = parent::__toString($this->message);
+            break;
+
+        case 'horde.success':
+            $img = 'alerts/success.png';
+            $label = _("Success");
+            $text = parent::__toString($this->message);
+            break;
+
+        case 'horde.warning':
+            $img = 'alerts/warning.png';
+            $label = _("Warning");
+            $text = parent::__toString($this->message);
+            break;
+        }
+
+        return Horde::img($img, $label, null, $GLOBALS['registry']->getImageDir('horde')) . $text;
+    }
+
+}
index 7c58e3a..f905cf9 100644 (file)
@@ -232,6 +232,7 @@ class Horde_Registry
         $injector->addBinder('Horde_Db_Adapter_Base', new Horde_Core_Binder_Db('reader'));
         $injector->addBinder('Horde_Log_Logger', new Horde_Core_Binder_Logger());
         $injector->addBinder('Horde_Memcache', new Horde_Core_Binder_Memcache());
+        $injector->addBinder('Horde_Notification', new Horde_Core_Binder_Notification());
         $injector->addBinder('Horde_Perms', new Horde_Core_Binder_Perms());
         $injector->addBinder('Horde_Template', new Horde_Core_Binder_Template());
         $injector->addBinder('Net_DNS_Resolver', new Horde_Core_Binder_Dns());
@@ -315,11 +316,15 @@ class Horde_Registry
         }
 
         /* Initialize notification object. Always attach status listener by
-         * default. */
-        $GLOBALS['notification'] = Horde_Notification::singleton();
-        $statusListener = $GLOBALS['notification']->attach('status');
-        $injector->setInstance('Horde_Notification', $GLOBALS['notification']);
-        $injector->setInstance('Horde_Notification_Listener', $statusListener);
+         * default. Default status listener can be overriden through the
+         * $_SESSION['horde_notification']['override'] variable. */
+        $GLOBALS['notification'] = $injector->getInstance('Horde_Notification');
+        if (isset($_SESSION['horde_notification']['override'])) {
+            require_once $_SESSION['horde_notification']['override'][0];
+            $GLOBALS['notification']->attach('status', null, $_SESSION['horde_notification']['override'][1]);
+        } else {
+            $GLOBALS['notification']->attach('status');
+        }
     }
 
     /**
index c7c8681..9e6ccbc 100644 (file)
@@ -66,9 +66,13 @@ Application Framework.
        <file name="Dns.php" role="php" />
        <file name="Logger.php" role="php" />
        <file name="Memcache.php" role="php" />
+       <file name="Notification.php" role="php" />
        <file name="Perms.php" role="php" />
        <file name="Template.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Binder -->
+      <dir name="Notification">
+       <file name="Status.php" role="php" />
+      </dir> <!-- /lib/Horde/Core/Notification -->
      </dir> <!-- /lib/Horde/Core -->
      <file name="ErrorHandler.php" role="php" />
      <dir name="Exception">
@@ -156,8 +160,10 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Dns.php" as="Horde/Core/Binder/Dns.php" />
    <install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
    <install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
+   <install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
    <install name="lib/Horde/Core/Binder/Perms.php" as="Horde/Core/Binder/Perms.php" />
    <install name="lib/Horde/Core/Binder/Template.php" as="Horde/Core/Binder/Template.php" />
+   <install name="lib/Horde/Core/Notification/Status.php" as="Horde/Core/Notification/Status.php" />
    <install name="lib/Horde/ErrorHandler.php" as="Horde/ErrorHandler.php" />
    <install name="lib/Horde/Exception/HookNotSet.php" as="Horde/Exception/HookNotSet.php" />
    <install name="lib/Horde/Help.php" as="Horde/Help.php" />
index 976a824..ecb2610 100644 (file)
@@ -35,13 +35,7 @@ class Horde_Notification
     static public function singleton($stack = 'horde_notification_stacks')
     {
         if (!isset(self::$_instances[$stack])) {
-            $storage = new Horde_Notification_Storage_Session($stack);
-
-            $handler = new Horde_Notification_Handler_Base($storage);
-            $handler = new Horde_Notification_Handler_Decorator_Hordelog($handler);
-            $handler = new Horde_Notification_Handler_Decorator_Alarm($handler, Horde_Alarm::factory());
-
-            self::$_instances[$stack] = $handler;
+            self::$_instances[$stack] = new Horde_Notification_Handler(new Horde_Notification_Storage_Session($stack));
         }
 
         return self::$_instances[$stack];
index eb09147..fa593ae 100644 (file)
@@ -45,6 +45,10 @@ class Horde_Notification_Event
     {
         $this->flags = $flags;
 
+        $this->type = empty($type)
+            ? 'status'
+            : $type;
+
         if ($data instanceof PEAR_Error) {
             // DEPRECATED
             if (($userinfo = $data->getUserInfo()) &&
@@ -66,25 +70,13 @@ class Horde_Notification_Event
             } else {
                 $this->message = $data->getMessage();
             }
-
-            if (is_null($type)) {
-                $type = 'horde.error';
-            }
         } elseif ($data instanceof Exception) {
             // Exception
             $this->message = $data->getMessage();
-            if (is_null($type)) {
-                $type = 'horde.error';
-            }
         } else {
             // String or object
             $this->message = strval($data);
-            if (is_null($type)) {
-                $type = is_string($data) ? 'horde.message' : 'horde.error';
-            }
         }
-
-        $this->type = $type;
     }
 
     /**
diff --git a/framework/Notification/lib/Horde/Notification/Event/Status.php b/framework/Notification/lib/Horde/Notification/Event/Status.php
new file mode 100644 (file)
index 0000000..f4fb39c
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+/**
+ * The Horde_Notification_Event_Status:: class defines a single status
+ * notification event.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@curecanti.org>
+ * @package Horde_Notification
+ */
+class Horde_Notification_Event_Status extends Horde_Notification_Event
+{
+    /**
+     * String representation of this object.
+     *
+     * @return string  String representation.
+     */
+    public function __toString()
+    {
+        $text = $this->message;
+
+        if (!in_array('content.raw', $this->flags)) {
+            $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset());
+        }
+
+        return $text;
+    }
+
+}
diff --git a/framework/Notification/lib/Horde/Notification/Handler.php b/framework/Notification/lib/Horde/Notification/Handler.php
new file mode 100644 (file)
index 0000000..ed93bfb
--- /dev/null
@@ -0,0 +1,400 @@
+<?php
+/**
+ * The Horde_Notification:: package provides a subject-observer pattern for
+ * raising and showing messages of different types and to different
+ * listeners.
+ *
+ * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Horde_Notification
+ */
+class Horde_Notification_Handler
+{
+    /**
+     * Hash containing all attached listener objects.
+     *
+     * @var array
+     */
+    protected $_listeners = array();
+
+    /**
+     * Decorators.
+     *
+     * @var array
+     */
+    protected $_decorators = array();
+
+    /**
+     * Additional handle definitions.
+     *
+     * @var array
+     */
+    protected $_handles = array(
+        'default' => array(
+            '*' => 'Horde_Notification_Event'
+        )
+    );
+
+    /**
+     * The storage location where we store the messages.
+     *
+     * @var Horde_Notification_Storage
+     */
+    protected $_storage;
+
+    /**
+     * Initialize the notification system.
+     *
+     * @param Horde_Notification_Storage $storage  The storage object to use.
+     */
+    public function __construct(Horde_Notification_Storage_Interface $storage)
+    {
+        $this->_storage = $storage;
+    }
+
+    /**
+     * Registers a listener with the notification object and includes
+     * the necessary library file dynamically.
+     *
+     * @param string $listener  The name of the listener to attach. These
+     *                          names must be unique; further listeners with
+     *                          the same name will be ignored.
+     * @param array $params     A hash containing any additional configuration
+     *                          or connection parameters a listener driver
+     *                          might need.
+     * @param string $class     The class name from which the driver was
+     *                          instantiated if not the default one. If given
+     *                          you have to include the library file
+     *                          containing this class yourself. This is useful
+     *                          if you want the listener driver to be
+     *                          overriden by an application's implementation
+     *
+     * @return Horde_Notification_Listener  The listener object.
+     * @throws Horde_Exception
+     */
+    public function attach($listener, $params = null, $class = null)
+    {
+        if ($ob = $this->getListener($listener)) {
+            return $ob;
+        }
+
+        if (is_null($class)) {
+            $class = 'Horde_Notification_Listener_' . Horde_String::ucfirst(Horde_String::lower($listener));
+        }
+
+        if (class_exists($class)) {
+            $this->_listeners[$listener] = new $class($params);
+            if (!$this->_storage->exists($listener)) {
+                $this->_storage->set($listener, array());
+            }
+            $this->_addTypes($listener);
+            return $this->_listeners[$listener];
+        }
+
+        throw new Horde_Exception(sprintf('Notification listener %s not found.', $class));
+    }
+
+    /**
+     * Remove a listener from the notification list.
+     *
+     * @param string $listner  The name of the listener to detach.
+     *
+     * @throws Horde_Exception
+     */
+    public function detach($listener)
+    {
+        if ($ob = $this->getListener($listener)) {
+            unset($this->_listeners[$ob->getName()]);
+            $this->_storage->clear($ob->getName());
+        } else {
+            throw new Horde_Exception(sprintf('Notification listener %s not found.', $listener));
+        }
+    }
+
+    /**
+     * Clear any notification events that may exist in a listener.
+     *
+     * @param string $listener  The name of the listener to flush. If null,
+     *                          clears all unattached events.
+     */
+    public function clear($listener = null)
+    {
+        if (is_null($listener)) {
+            $this->_storage->clear('_unattached');
+        } elseif ($ob = $this->getListener($listener)) {
+            $this->_storage->clear($ob->getName());
+        }
+    }
+
+    /**
+     * Returns the current Listener object for a given listener type.
+     *
+     * @param string $type  The listener type.
+     *
+     * @return mixed  A Horde_Notification_Listener object, or null if
+     *                $type listener is not attached.
+     */
+    public function get($type)
+    {
+        foreach ($this->_listeners as $listener) {
+            if ($listener->handles($type)) {
+                return $listener;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns a listener object given a listener name.
+     *
+     * @param string $listener  The listener name.
+     *
+     * @return mixed  Either a Horde_Notification_Listener or null.
+     */
+    public function getListener($listener)
+    {
+        $listener = Horde_String::lower(basename($listener));
+        return empty($this->_listeners[$listener])
+            ? null
+            : $this->_listeners[$listener];
+    }
+
+    /**
+     * Adds a type handler to a given Listener.
+     * To change the default listener, use the following:
+     * <pre>
+     *   $ob->addType('default', '*', $classname);
+     * </pre>
+     *
+     * @param string $listener  The listener name.
+     * @param string $type      The listener type.
+     * @param string $class     The Event class to use.
+     */
+    public function addType($listener, $type, $class)
+    {
+        $this->_handles[$listener][$type] = $class;
+
+        if (isset($this->_listeners[$listener])) {
+            $this->_addTypes($listener);
+        }
+    }
+
+    /**
+     * Adds any additional listener types to a given Listener.
+     *
+     * @param string $listener  The listener name.
+     */
+    protected function _addTypes($listener)
+    {
+        if (isset($this->_handles[$listener])) {
+            foreach ($this->_handles[$listener] as $type => $class) {
+                $this->_listeners[$listener]->addType($type, $class);
+            }
+        }
+    }
+
+    /**
+     * Add a decorator.
+     *
+     * @param Horde_Notification_Handler_Decorator_Base $decorator  The
+     *                                                              Decorator
+     *                                                              object.
+     */
+    public function addDecorator(Horde_Notification_Handler_Decorator_Base $decorator)
+    {
+        $this->_decorators[] = $decorator;
+    }
+
+    /**
+     * Add an event to the Horde message stack.
+     *
+     * @param mixed $event    Horde_Notification_Event object or message
+     *                        string.
+     * @param integer $type   The type of message.
+     * @param array $flags    Array of optional flags that will be passed to
+     *                        the registered listeners.
+     * @param array $options  Additional options:
+     * <pre>
+     * 'immediate' - (boolean) If true, immediately tries to attach to a
+     *               listener. If no listener exists for this type, the
+     *               message will be dropped.
+     *               DEFAULT: false (message will be attached to available
+     *               handler at the time notify() is called).
+     * </pre>
+     */
+    public function push($event, $type = null, array $flags = array(),
+                         $options = array())
+    {
+        if ($event instanceof Horde_Notification_Event) {
+            $event->flags = $flags;
+            $event->type = $type;
+        } else {
+            $class = (!is_null($type) && ($listener = $this->get($type)))
+                ? $listener->handles($type)
+                : $this->_handles['default']['*'];
+
+            /* Transparently create a Horde_Notification_Event object. */
+            $event = new $class($event, $type, $flags);
+        }
+
+        foreach ($this->_decorators as $decorator) {
+            $decorator->push($event, $options);
+        }
+
+        if (empty($options['immediate'])) {
+            $this->_storage->push('_unattached', $event);
+        } else {
+            if ($listener = $this->get($event->type)) {
+                $this->_storage->push($listener->getName(), $event);
+            }
+        }
+    }
+
+    /**
+     * Passes the message stack to all listeners and asks them to
+     * handle their messages.
+     *
+     * @param array $options  An array containing display options for the
+     *                        listeners. Any options not contained in this
+     *                        list will be passed to the listeners.
+     * <pre>
+     * 'listeners' - (array) The list of listeners to notify.
+     * 'raw' - (boolean) If true, does not call the listener's notify()
+     *         function.
+     * </pre>
+     */
+    public function notify(array $options = array())
+    {
+        $options = $this->setNotificationListeners($options);
+
+        foreach ($this->_decorators as $decorator) {
+            $decorator->notify($options);
+        }
+
+        return $this->notifyListeners($options);
+    }
+
+    /**
+     * Convert the 'listeners' option into the format expected by the
+     * notification handler.
+     *
+     * @param array $options  An array containing display options for the
+     *                        listeners. See self::notify() for the valid
+     *                        keys.
+     *
+     * @return array  The list of listeners to notify.
+     */
+    public function setNotificationListeners(array $options)
+    {
+        if (!isset($options['listeners'])) {
+            $options['listeners'] = array_keys($this->_listeners);
+        } elseif (!is_array($options['listeners'])) {
+            $options['listeners'] = array($options['listeners']);
+        }
+
+        $options['listeners'] = array_map(array('Horde_String', 'lower'), $options['listeners']);
+
+        return $options;
+    }
+
+    /**
+     * Passes the message stack to all listeners and asks them to handle
+     * their messages.
+     *
+     * @param array $options An array containing display options for the
+     *                       listeners. This array is required to contain the
+     *                       correct lowercased listener names as array in the
+     *                       entry 'listeners'. See self::notify() for the
+     *                       other valid keys.
+     *
+     * @return array  The list of events that were sent to the listeners.
+     */
+    public function notifyListeners(array $options)
+    {
+        $unattached = $this->_storage->exists('_unattached')
+            ? $this->_storage->get('_unattached')
+            : array();
+
+        $events = array();
+
+        foreach ($options['listeners'] as $listener) {
+            if (isset($this->_listeners[$listener])) {
+                $instance = $this->_listeners[$listener];
+                $name = $instance->getName();
+
+                foreach (array_keys($unattached) as $val) {
+                    if ($instance->handles($unattached[$val]->type)) {
+                        $this->_storage->push($name, $unattached[$val]);
+                        unset($unattached[$val]);
+                    }
+                }
+
+                if (!$this->_storage->exists($name)) {
+                    continue;
+                }
+
+                $tmp = $this->_storage->get($name);
+                if (empty($options['raw'])) {
+                    $instance->notify($tmp, $options);
+                }
+                $this->_storage->clear($name);
+
+                $events = array_merge($events, $tmp);
+            }
+        }
+
+        if (empty($unattached)) {
+            $this->_storage->clear('_unattached');
+        } else {
+            $this->_storage->set('_unattached', $unattached);
+        }
+
+        return $events;
+    }
+
+    /**
+     * Return the number of notification messages in the stack.
+     *
+     * @author David Ulevitch <davidu@everydns.net>
+     *
+     * @param string $my_listener  The name of the listener.
+     *
+     * @return integer  The number of messages in the stack.
+     */
+    public function count($my_listener = null)
+    {
+        $count = 0;
+
+        if (!is_null($my_listener)) {
+            if ($ob = $this->get($my_listener)) {
+                $count = count($this->_storage->get($ob->getName()));
+
+                if ($this->_storage->exists('_unattached')) {
+                    foreach ($this->_storage->get('_unattached') as $val) {
+                        if ($ob->handles($val->type)) {
+                            ++$count;
+                        }
+                    }
+                }
+            }
+        } else {
+            if ($this->_storage->exists('_unattached')) {
+                $count = count($this->_storage->get('_unattached'));
+            }
+
+            foreach ($this->_listeners as $val) {
+                if ($this->_storage->exists($val->getName())) {
+                    $count += count($this->_storage->get($val->getName()));
+                }
+            }
+        }
+
+        return $count;
+    }
+
+}
diff --git a/framework/Notification/lib/Horde/Notification/Handler/Base.php b/framework/Notification/lib/Horde/Notification/Handler/Base.php
deleted file mode 100644 (file)
index 2238137..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-<?php
-/**
- * The Horde_Notification:: package provides a subject-observer pattern for
- * raising and showing messages of different types and to different
- * listeners.
- *
- * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author  Jan Schneider <jan@horde.org>
- * @package Horde_Notification
- */
-class Horde_Notification_Handler_Base
-implements Horde_Notification_Handler_Interface
-{
-    /**
-     * Hash containing all attached listener objects.
-     *
-     * @var array
-     */
-    protected $_listeners = array();
-
-    /**
-     * The storage location where we store the messages.
-     *
-     * @var Horde_Notification_Storage
-     */
-    protected $_storage;
-
-    /**
-     * A Horde_Alarm instance.
-     *
-     * @var Horde_Alarm
-     */
-    protected $_alarm;
-
-    /**
-     * Initialize the notification system.
-     *
-     * @param Horde_Notification_Storage $storage  The storage location to
-     *                                             use.
-     */
-    public function __construct(Horde_Notification_Storage_Interface $storage)
-    {
-        $this->_storage = $storage;
-    }
-
-    /**
-     * Registers a listener with the notification object and includes
-     * the necessary library file dynamically.
-     *
-     * @param string $listener  The name of the listener to attach. These
-     *                          names must be unique; further listeners with
-     *                          the same name will be ignored.
-     * @param array $params     A hash containing any additional configuration
-     *                          or connection parameters a listener driver
-     *                          might need.
-     * @param string $class     The class name from which the driver was
-     *                          instantiated if not the default one. If given
-     *                          you have to include the library file
-     *                          containing this class yourself. This is useful
-     *                          if you want the listener driver to be
-     *                          overriden by an application's implementation.
-     *
-     * @return Horde_Notification_Listener  The listener object.
-     * @throws Horde_Exception
-     */
-    public function attach($listener, $params = null, $class = null)
-    {
-        $listener = Horde_String::lower(basename($listener));
-        if (!empty($this->_listeners[$listener])) {
-            return $this->_listeners[$listener];
-        }
-
-        if (is_null($class)) {
-            $class = 'Horde_Notification_Listener_' . Horde_String::ucfirst($listener);
-        }
-
-        if (class_exists($class)) {
-            $this->_listeners[$listener] = new $class($params);
-            if (!$this->_storage->exists($listener)) {
-                $this->_storage->set($listener, array());
-            }
-            return $this->_listeners[$listener];
-        }
-
-        throw new Horde_Exception(sprintf('Notification listener %s not found.', $class));
-    }
-
-    /**
-     * Remove a listener from the notification list.
-     *
-     * @param string $listner  The name of the listener to detach.
-     *
-     * @throws Horde_Exception
-     */
-    public function detach($listener)
-    {
-        $listener = Horde_String::lower(basename($listener));
-        if (isset($this->_listeners[$listener])) {
-            unset($this->_listeners[$listener]);
-        } else {
-            throw new Horde_Exception(sprintf('Notification listener %s not found.', $listener));
-        }
-    }
-
-    /**
-     * Replaces a listener in the notification list. If the listener does not
-     * exist, the new listener will be added automatically.
-     *
-     * @param string $listener  See attach().
-     * @param array $params     See attach().
-     * @param string $class     See attach().
-     *
-     * @return Horde_Notification_Listener  See attach().
-     */
-    public function replace($listener, array $params = array(), $class = null)
-    {
-        try {
-            $this->detach($listener);
-        } catch (Horde_Exception $e) {}
-
-        return $this->attach($listener, $params, $class);
-    }
-
-    /**
-     * Clear any notification events that may exist in a listener.
-     *
-     * @param string $listener  The name of the listener to flush. If null,
-     *                          clears all unattached events.
-     */
-    public function clear($listener = null)
-    {
-        if (is_null($listener)) {
-            $this->_storage->clear('_unattached');
-        } else {
-            $listener = Horde_String::lower(basename($listener));
-            if (isset($this->_listeners[$listener])) {
-                $this->_storage->clear($this->_listeners[$listener]->getName());
-            }
-        }
-    }
-
-    /**
-     * Add an event to the Horde message stack.
-     *
-     * The event type parameter should begin with 'horde.' unless the
-     * application defines its own Horde_Notification_Listener subclass that
-     * handles additional codes.
-     *
-     * @param mixed $event    Horde_Notification_Event object or message
-     *                        string.
-     * @param integer $type   The type of message.
-     * @param array $flags    Array of optional flags that will be passed to
-     *                        the registered listeners.
-     * @param array $options  Additional options:
-     * <pre>
-     * 'immediate' - (boolean) If true, immediately tries to attach to a
-     *               listener. If no listener exists for this type, the
-     *               message will be dropped.
-     *               DEFAULT: false (message will be attached to available
-     *               handler at the time notify() is called).
-     * </pre>
-     */
-    public function push($event, $type = null, array $flags = array(),
-                         $options = array())
-    {
-        if ($event instanceof Horde_Notification_Event) {
-            $event->flags = $flags;
-            $event->type = $type;
-        } else {
-            /* Transparently create a Horde_Notification_Event object. */
-            $event = new Horde_Notification_Event($event, $type, $flags);
-        }
-
-        if (empty($options['immediate'])) {
-            $this->_storage->push('_unattached', $event);
-        } else {
-            foreach ($this->_listeners as $listener) {
-                if ($listener->handles($event->type)) {
-                    $this->_storage->push($listener->getName(), $event);
-                }
-            }
-        }
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     * <pre>
-     * 'listeners' - The list of listeners to notify.
-     * </pre>
-     */
-    public function notify(array $options = array())
-    {
-        $options = $this->setNotificationListeners($options);
-        $this->notifyListeners($options);
-    }
-
-    /**
-     * Convert the 'listeners' option into the format expected by the
-     * notification handler.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     *
-     * @return array  The list of listeners to notify.
-     */
-    public function setNotificationListeners(array $options)
-    {
-        if (!isset($options['listeners'])) {
-            $options['listeners'] = array_keys($this->_listeners);
-        } elseif (!is_array($options['listeners'])) {
-            $options['listeners'] = array($options['listeners']);
-        }
-        $options['listeners'] = array_map(array('Horde_String', 'lower'), $options['listeners']);
-
-        return $options;
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to handle
-     * their messages.
-     *
-     * @param array $options An array containing display options for the
-     *                       listeners. This array is required to contain the
-     *                       correct lowercased listener names as array in the
-     *                       entry 'listeners'.
-     */
-    public function notifyListeners(array $options)
-    {
-        $unattached = $this->_storage->exists('_unattached')
-            ? $this->_storage->get('_unattached')
-            : array();
-
-        foreach ($options['listeners'] as $listener) {
-            if (isset($this->_listeners[$listener])) {
-                $instance = $this->_listeners[$listener];
-
-                foreach (array_keys($unattached) as $val) {
-                    if ($instance->handles($unattached[$val]->type)) {
-                        $this->_storage->push($instance->getName(), $unattached[$val]);
-                        unset($unattached[$val]);
-                    }
-                }
-
-                $instance->notify($this->_storage->get($instance->getName()), $options);
-            }
-        }
-
-        if (empty($unattached)) {
-            $this->_storage->clear('_unattached');
-        } else {
-            $this->_storage->set('_unattached', $unattached);
-        }
-    }
-
-    /**
-     * Return the number of notification messages in the stack.
-     *
-     * @author David Ulevitch <davidu@everydns.net>
-     *
-     * @param string $my_listener  The name of the listener.
-     *
-     * @return integer  The number of messages in the stack.
-     */
-    public function count($my_listener = null)
-    {
-        if (!is_null($my_listener)) {
-            return @count($this->_storage->get($this->_listeners[Horde_String::lower($my_listener)]->getName()));
-        }
-
-        $count = 0;
-        foreach (array_merge($this->_listeners, array('_unattached')) as $val) {
-            if ($this->_storage->exists($val->getName())) {
-                $count += count($this->_storage->get($val->getName()));
-            }
-        }
-
-        return $count;
-    }
-
-}
index efab2c2..0189abf 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
- * The Horde_Notification_Handler_Alarm notifies the alarm system if required.
+ * The Alarm Decorator notifies the alarm system to push its notifications on
+ * the stack.
  *
  * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
  *
  * @package Horde_Notification
  */
 class Horde_Notification_Handler_Decorator_Alarm
-implements Horde_Notification_Handler_Interface
+extends Horde_Notification_Handler_Decorator_Base
 {
     /**
-     * The notification handler decorated by this instance.
-     *
-     * @var Horde_Notification_Handler
-     */
-    private $_handler;
-
-    /**
      * A Horde_Alarm instance.
      *
      * @var Horde_Alarm
@@ -28,150 +22,37 @@ implements Horde_Notification_Handler_Interface
     protected $_alarm;
 
     /**
-     * Initialize the notification system, set up any needed session
-     * variables, etc.
-     *
-     * @param Horde_Notification_Handler $handler  The handler this instance
-     *                                             provides with logging.
-     * @param Horde_Alarm $alarm                   The alarm system to notify.
-     */
-    public function __construct(Horde_Notification_Handler_Interface $handler,
-                                Horde_Alarm $alarm)
-    {
-        $this->_handler = $handler;
-        $this->_alarm   = $alarm;
-    }
-
-    /**
-     * Registers a listener with the notification object and includes
-     * the necessary library file dynamically.
-     *
-     * @param string $listener  The name of the listener to attach. These
-     *                          names must be unique; further listeners with
-     *                          the same name will be ignored.
-     * @param array $params     A hash containing any additional configuration
-     *                          or connection parameters a listener driver
-     *                          might need.
-     * @param string $class     The class name from which the driver was
-     *                          instantiated if not the default one. If given
-     *                          you have to include the library file
-     *                          containing this class yourself. This is useful
-     *                          if you want the listener driver to be
-     *                          overriden by an application's implementation.
-     *
-     * @return Horde_Notification_Listener  The listener object.
-     * @throws Horde_Exception
-     */
-    public function attach($listener, $params = null, $class = null)
-    {
-        return $this->_handler->attach($listener, $params, $class);
-    }
-
-    /**
-     * Remove a listener from the notification list. This will discard any
-     * notifications in this listeners stack.
-     *
-     * @param string $listner  The name of the listener to detach.
+     * The current user.
      *
-     * @throws Horde_Exception
+     * @var string
      */
-    public function detach($listener)
-    {
-        $this->_handler->detach($listener);
-    }
+    protected $_user;
 
     /**
-     * Replaces a listener in the notification list. This preserves all
-     * notifications in this listeners stack. If the listener does not exist,
-     * the new listener will be added automatically.
-     *
-     * @param string $listener  See attach().
-     * @param array $params     See attach().
-     * @param string $class     See attach().
-     *
-     * @return Horde_Notification_Listener  See attach()
-     * @throws Horde_Exception
-     */
-    public function replace($listener, array $params = array(), $class = null)
-    {
-        return $this->_handler->replace($listener, $params, $class);
-    }
-
-    /**
-     * Add an event to the Horde message stack.
-     *
-     * The event type parameter should begin with 'horde.' unless the
-     * application defines its own Horde_Notification_Listener subclass that
-     * handles additional codes.
+     * Initialize the notification system, set up any needed session
+     * variables, etc.
      *
-     * @param mixed $event   Horde_Notification_Event object or message string.
-     * @param integer $type  The type of message: 'horde.error',
-     *                       'horde.warning', 'horde.success', or
-     *                       'horde.message'.
-     * @param array $flags   Array of optional flags that will be passed to the
-     *                       registered listeners.
+     * @param Horde_Alarm $alarm  The alarm system to notify.
+     * @param string $user        The current username.
      */
-    public function push($event, $type = null, array $flags = array())
+    public function __construct(Horde_Alarm $alarm, $user)
     {
-        $this->_handler->push($event, $type, $flags);
+        $this->_alarm = $alarm;
+        $this->_user = $user;
     }
 
     /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
+     * Listeners are handling their messages.
      *
      * @param array $options  An array containing display options for the
-     *                        listeners.
+     *                        listeners (see Horde_Notification_Handler for
+     *                        details).
      */
-    public function notify(array $options = array())
+    public function notify($options)
     {
-        $options = $this->_handler->setNotificationListeners($options);
-
         if (in_array('status', $options['listeners'])) {
-            $this->_alarm->notify(Horde_Auth::getAuth());
+            $this->_alarm->notify($this->_user);
         }
-
-        $this->_handler->notifyListeners($options);
-    }
-
-    /**
-     * Convert the 'listeners' option into the format expected by the
-     * notification handler.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function setNotificationListeners(array $options)
-    {
-        return $this->_handler->setNotificationListeners($options);
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options An array containing display options for the
-     *                       listeners. This array is required to contain the
-     *                       correct lowercased listener names as array in the
-     *                       entry 'listeners'.
-     */
-    public function notifyListeners(array $options)
-    {
-        $this->_handler->notifyListeners($options);
-    }
-
-    /**
-     * Return the number of notification messages in the stack.
-     *
-     * @author David Ulevitch <davidu@everydns.net>
-     *
-     * @param string $my_listener  The name of the listener.
-     *
-     * @return integer  The number of messages in the stack.
-     */
-    public function count($my_listener = null)
-    {
-        return $this->_handler->count($my_listener);
     }
 
 }
diff --git a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php
new file mode 100644 (file)
index 0000000..454127f
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Define the functions needed for a Decorator instance.
+ *
+ * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Notification
+ */
+class Horde_Notification_Handler_Decorator_Base
+{
+    /**
+     * Event is being added to the Horde message stack.
+     *
+     * @param Horde_Notification_Event $event  Event object.
+     * @param array $options                   Additional options (see
+     *                                         Horde_Notification_Handler for
+     *                                         details).
+     */
+    public function push(Horde_Notification_Event $event, $options)
+    {
+    }
+
+    /**
+     * Listeners are handling their messages.
+     *
+     * @param array $options  An array containing display options for the
+     *                        listeners (see Horde_Notification_Handler for
+     *                        details).
+     */
+    public function notify($options)
+    {
+    }
+
+}
index 506017c..380c3dd 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * The Horde_Notification_Handler_Hordelog logs error events via
- * Horde::logMessage().
+ * The Hordelog Decorator logs error events via Horde::logMessage().
  *
  * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
  *
  * @package Horde_Notification
  */
 class Horde_Notification_Handler_Decorator_Hordelog
-implements Horde_Notification_Handler_Interface
+extends Horde_Notification_Handler_Decorator_Base
 {
     /**
-     * The notification handler decorated by this instance.
+     * Event is being added to the Horde message stack.
      *
-     * @var Horde_Notification_Handler
+     * @param Horde_Notification_Event $event  Event object.
+     * @param array $options                   Additional options (see
+     *                                         Horde_Notification_Handler for
+     *                                         details).
      */
-    private $_handler;
-
-    /**
-     * Initialize the notification system, set up any needed session
-     * variables, etc.
-     *
-     * @param Horde_Notification_Handler $handler The handler this instance
-     *                                            provides with logging.
-     */
-    public function __construct(Horde_Notification_Handler_Interface $handler)
+    public function push(Horde_Notification_Event $event, $options)
     {
-        $this->_handler = $handler;
+        Horde::logMessage($event->message, __FILE__, __LINE__, PEAR_LOG_DEBUG);
     }
 
-    /**
-     * Registers a listener with the notification object and includes
-     * the necessary library file dynamically.
-     *
-     * @param string $listener  The name of the listener to attach. These
-     *                          names must be unique; further listeners with
-     *                          the same name will be ignored.
-     * @param array $params     A hash containing any additional configuration
-     *                          or connection parameters a listener driver
-     *                          might need.
-     * @param string $class     The class name from which the driver was
-     *                          instantiated if not the default one. If given
-     *                          you have to include the library file
-     *                          containing this class yourself. This is useful
-     *                          if you want the listener driver to be
-     *                          overriden by an application's implementation.
-     *
-     * @return Horde_Notification_Listener  The listener object.
-     * @throws Horde_Exception
-     */
-    public function attach($listener, $params = null, $class = null)
-    {
-        return $this->_handler->attach($listener, $params, $class);
-    }
-
-    /**
-     * Remove a listener from the notification list. This will discard any
-     * notifications in this listeners stack.
-     *
-     * @param string $listner  The name of the listener to detach.
-     *
-     * @throws Horde_Exception
-     */
-    public function detach($listener)
-    {
-        $this->_handler->detach($listener);
-    }
-
-    /**
-     * Replaces a listener in the notification list. This preserves all
-     * notifications in this listeners stack. If the listener does not exist,
-     * the new listener will be added automatically.
-     *
-     * @param string $listener  See attach().
-     * @param array $params     See attach().
-     * @param string $class     See attach().
-     *
-     * @return Horde_Notification_Listener  See attach()
-     * @throws Horde_Exception
-     */
-    public function replace($listener, array $params = array(), $class = null)
-    {
-        return $this->_handler->replace($listener, $params, $class);
-    }
-
-    /**
-     * Add an event to the Horde message stack.
-     *
-     * The event type parameter should begin with 'horde.' unless the
-     * application defines its own Horde_Notification_Listener subclass that
-     * handles additional codes.
-     *
-     * @param mixed $event   Horde_Notification_Event object or message string.
-     * @param integer $type  The type of message: 'horde.error',
-     *                       'horde.warning', 'horde.success', or
-     *                       'horde.message'.
-     * @param array $flags   Array of optional flags that will be passed to the
-     *                       registered listeners.
-     */
-    public function push($event, $type = null, array $flags = array())
-    {
-        if ($event instanceof PEAR_Error || $event instanceof Exception) {
-            Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_DEBUG);
-        }
-        $this->_handler->push($event, $type, $flags);
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function notify(array $options = array())
-    {
-        $this->_handler->notify($options);
-    }
-
-    /**
-     * Convert the 'listeners' option into the format expected by the
-     * notification handler.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function setNotificationListeners(array $options)
-    {
-        return $this->_handler->setNotificationListeners($options);
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options An array containing display options for the
-     *                       listeners. This array is required to contain the
-     *                       correct lowercased listener names as array in the
-     *                       entry 'listeners'.
-     */
-    public function notifyListeners(array $options)
-    {
-        $this->_handler->notifyListeners($options);
-    }
-
-    /**
-     * Return the number of notification messages in the stack.
-     *
-     * @author David Ulevitch <davidu@everydns.net>
-     *
-     * @param string $my_listener  The name of the listener.
-     *
-     * @return integer  The number of messages in the stack.
-     */
-    public function count($my_listener = null)
-    {
-        return $this->_handler->count($my_listener);
-    }
 }
index bd0c395..f7181a6 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * The Horde_Notification_Handler_Logged logs error events once they are pushed
- * to the stack.
+ * The Log Decorator logs error events when they are pushed on the stack.
  *
  * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
  *
  * @package Horde_Notification
  */
 class Horde_Notification_Handler_Decorator_Log
-implements Horde_Notification_Handler_Interface
+extends Horde_Notification_Handler_Decorator_Base
 {
     /**
-     * The notification handler decorated by this instance.
-     *
-     * @var Horde_Notification_Handler
-     */
-    private $_handler;
-
-    /**
      * The log handler.
      *
-     * @var mixed
+     * @var object
      */
     private $_logger;
 
     /**
-     * Initialize the notification system, set up any needed session
-     * variables, etc.
+     * Constructor.
      *
-     * @param Horde_Notification_Handler $handler  The handler this instance
-     *                                             provides with logging.
-     *
-     * @param mixed $logger                        The log handler. The
-     *                                             provided instance is
-     *                                             required to implement the
-     *                                             debug() function. You
-     *                                             should be able to use a
-     *                                             common Logger here (PEAR
-     *                                             Log, Horde_Log_Logger, or
-     *                                             Zend_Log).
+     * @param object $logger  The log handler. The provided instance is
+     *                        required to implement the debug() function. You
+     *                        should be able to use a common Logger here (PEAR
+     *                        Log, Horde_Log_Logger, or Zend_Log).
      */
-    public function __construct(Horde_Notification_Handler_Interface $handler,
-                                $logger)
+    public function __construct($logger)
     {
-        $this->_handler = $handler;
         $this->_logger  = $logger;
     }
 
     /**
-     * Registers a listener with the notification object and includes
-     * the necessary library file dynamically.
-     *
-     * @param string $listener  The name of the listener to attach. These
-     *                          names must be unique; further listeners with
-     *                          the same name will be ignored.
-     * @param array $params     A hash containing any additional configuration
-     *                          or connection parameters a listener driver
-     *                          might need.
-     * @param string $class     The class name from which the driver was
-     *                          instantiated if not the default one. If given
-     *                          you have to include the library file
-     *                          containing this class yourself. This is useful
-     *                          if you want the listener driver to be
-     *                          overriden by an application's implementation.
-     *
-     * @return Horde_Notification_Listener  The listener object.
-     * @throws Horde_Exception
-     */
-    public function attach($listener, $params = null, $class = null)
-    {
-        return $this->_handler->attach($listener, $params, $class);
-    }
-
-    /**
-     * Remove a listener from the notification list. This will discard any
-     * notifications in this listeners stack.
-     *
-     * @param string $listner  The name of the listener to detach.
-     *
-     * @throws Horde_Exception
-     */
-    public function detach($listener)
-    {
-        $this->_handler->detach($listener);
-    }
-
-    /**
-     * Replaces a listener in the notification list. This preserves all
-     * notifications in this listeners stack. If the listener does not exist,
-     * the new listener will be added automatically.
-     *
-     * @param string $listener  See attach().
-     * @param array $params     See attach().
-     * @param string $class     See attach().
-     *
-     * @return Horde_Notification_Listener  See attach()
-     * @throws Horde_Exception
-     */
-    public function replace($listener, array $params = array(), $class = null)
-    {
-        return $this->_handler->replace($listener, $params, $class);
-    }
-
-    /**
-     * Add an event to the Horde message stack.
-     *
-     * The event type parameter should begin with 'horde.' unless the
-     * application defines its own Horde_Notification_Listener subclass that
-     * handles additional codes.
-     *
-     * @param mixed $event   Horde_Notification_Event object or message string.
-     * @param integer $type  The type of message: 'horde.error',
-     *                       'horde.warning', 'horde.success', or
-     *                       'horde.message'.
-     * @param array $flags   Array of optional flags that will be passed to the
-     *                       registered listeners.
-     */
-    public function push($event, $type = null, array $flags = array())
-    {
-        if ($event instanceof PEAR_Error || $event instanceof Exception) {
-            /* Some loggers only accept string messages. As both PEAR_Error
-             * and Exception accept being casted into a string we can ensure
-             * that the logger receives a string here. */
-            $this->_logger->debug((string) $event);
-        }
-        $this->_handler->push($event, $type, $flags);
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function notify(array $options = array())
-    {
-        $this->_handler->notify($options);
-    }
-
-    /**
-     * Convert the 'listeners' option into the format expected by the
-     * notification handler.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function setNotificationListeners(array $options)
-    {
-        return $this->_handler->setNotificationListeners($options);
-    }
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options An array containing display options for the
-     *                       listeners. This array is required to contain the
-     *                       correct lowercased listener names as array in the
-     *                       entry 'listeners'.
-     */
-    public function notifyListeners(array $options)
-    {
-        $this->_handler->notifyListeners($options);
-    }
-
-    /**
-     * Return the number of notification messages in the stack.
-     *
-     * @author David Ulevitch <davidu@everydns.net>
-     *
-     * @param string $my_listener  The name of the listener.
+     * Event is being added to the Horde message stack.
      *
-     * @return integer  The number of messages in the stack.
+     * @param Horde_Notification_Event $event  Event object.
+     * @param array $options                   Additional options (see
+     *                                         Horde_Notification_Handler for
+     *                                         details).
      */
-    public function count($my_listener = null)
+    public function push(Horde_Notification_Event $event, $options)
     {
-        return $this->_handler->count($my_listener);
+        $this->_logger->debug($event->message);
     }
 
 }
diff --git a/framework/Notification/lib/Horde/Notification/Handler/Interface.php b/framework/Notification/lib/Horde/Notification/Handler/Interface.php
deleted file mode 100644 (file)
index b3bb26d..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-/**
- * The Horde_Notification_Handler:: interfaces describes the handlers that
- * notify the listeners.
- *
- * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author  Jan Schneider <jan@horde.org>
- * @package Horde_Notification
- */
-interface Horde_Notification_Handler_Interface
-{
-    /**
-     * Registers a listener with the notification object and includes
-     * the necessary library file dynamically.
-     *
-     * @param string $listener  The name of the listener to attach. These
-     *                          names must be unique; further listeners with
-     *                          the same name will be ignored.
-     * @param array $params     A hash containing any additional configuration
-     *                          or connection parameters a listener driver
-     *                          might need.
-     * @param string $class     The class name from which the driver was
-     *                          instantiated if not the default one. If given
-     *                          you have to include the library file
-     *                          containing this class yourself. This is useful
-     *                          if you want the listener driver to be
-     *                          overriden by an application's implementation.
-     *
-     * @return Horde_Notification_Listener  The listener object.
-     * @throws Horde_Exception
-     */
-    public function attach($listener, $params = null, $class = null);
-
-    /**
-     * Remove a listener from the notification list. This will discard any
-     * notifications in this listeners stack.
-     *
-     * @param string $listner  The name of the listener to detach.
-     *
-     * @throws Horde_Exception
-     */
-    public function detach($listener);
-
-    /**
-     * Replaces a listener in the notification list. This preserves all
-     * notifications in this listeners stack. If the listener does not exist,
-     * the new listener will be added automatically.
-     *
-     * @param string $listener  See attach().
-     * @param array $params     See attach().
-     * @param string $class     See attach().
-     *
-     * @return Horde_Notification_Listener  See attach()
-     * @throws Horde_Exception
-     */
-    public function replace($listener, array $params = array(), $class = null);
-
-    /**
-     * Add an event to the Horde message stack.
-     *
-     * The event type parameter should begin with 'horde.' unless the
-     * application defines its own Horde_Notification_Listener subclass that
-     * handles additional codes.
-     *
-     * @param mixed $event   Horde_Notification_Event object or message string.
-     * @param integer $type  The type of message: 'horde.error',
-     *                       'horde.warning', 'horde.success', or
-     *                       'horde.message'.
-     * @param array $flags   Array of optional flags that will be passed to the
-     *                       registered listeners.
-     */
-    public function push($event, $type = null, array $flags = array());
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function notify(array $options = array());
-
-    /**
-     * Convert the 'listeners' option into the format expected by the
-     * notification handler.
-     *
-     * @param array $options  An array containing display options for the
-     *                        listeners.
-     */
-    public function setNotificationListeners(array $options);
-
-    /**
-     * Passes the message stack to all listeners and asks them to
-     * handle their messages.
-     *
-     * @param array $options An array containing display options for the
-     *                       listeners. This array is required to contain the
-     *                       correct lowercased listener names as array in the
-     *                       entry 'listeners'.
-     */
-    public function notifyListeners(array $options);
-
-    /**
-     * Return the number of notification messages in the stack.
-     *
-     * @author David Ulevitch <davidu@everydns.net>
-     *
-     * @param string $my_listener  The name of the listener.
-     *
-     * @return integer  The number of messages in the stack.
-     */
-    public function count($my_listener = null);
-
-}
index 17fbfc4..e3bd2a3 100644 (file)
@@ -22,6 +22,8 @@ abstract class Horde_Notification_Listener
 
     /**
      * Array of message types that this listener handles.
+     * Key is the type, value is the default class name of the Event type to
+     * use.
      *
      * @var array
      */
@@ -32,11 +34,35 @@ abstract class Horde_Notification_Listener
      *
      * @param string $type  The message type in question.
      *
-     * @return boolean  Whether this listener handles the type.
+     * @return mixed  False if this listener does not handle, the default
+     *                event class if it does handle the type.
      */
     public function handles($type)
     {
-        return isset($this->_handles[$type]);
+        if (isset($this->_handles[$type])) {
+            return $this->_handles[$type];
+        }
+
+        /* Search for '*' entries. */
+        foreach (array_keys($this->_handles) as $key) {
+            if ((substr($key, -1) == '*') &&
+                (strpos($type, substr($key, 0, -1)) === 0)) {
+                return $this->_handles[$key];
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Adds message type handler.
+     *
+     * @param string $type   The type identifier.
+     * @param string $class  A classname.
+     */
+    public function addType($type, $class)
+    {
+        $this->_handles[$type] = $class;
     }
 
     /**
@@ -53,20 +79,9 @@ abstract class Horde_Notification_Listener
      * Outputs the status line, sends emails, pages, etc., if there
      * are any messages on this listener's message stack.
      *
-     * @param array &$messageStack  The stack of messages.
-     * @param array $options        An array of options.
-     */
-    abstract public function notify(&$messageStacks, $options = array());
-
-    /**
-     * Processes one message from the message stack.
-     *
-     * @param Horde_Notification_Event $event  One event object from the
-     *                                         stack.
-     * @param array $options                   An array of options.
-     *
-     * @return mixed  The formatted message.
+     * @param array $events   The list of events to handle.
+     * @param array $options  An array of options.
      */
-    abstract public function getMessage($event, $options = array());
+    abstract public function notify($events, $options = array());
 
 }
index 3aebf91..c6ff881 100644 (file)
@@ -18,9 +18,7 @@ class Horde_Notification_Listener_Audio extends Horde_Notification_Listener
      */
     public function __construct()
     {
-        $this->_handles = array(
-            'audio' => ''
-        );
+        $this->_handles['audio'] = 'Horde_Notification_Event';
         $this->_name = 'audio';
     }
 
@@ -28,29 +26,14 @@ class Horde_Notification_Listener_Audio extends Horde_Notification_Listener
      * Outputs the embedded audio code if there are any messages on the
      * 'audio' message stack.
      *
-     * @param array &$messageStack  The stack of messages.
-     * @param array $options        An array of options (not used).
+     * @param array $events   The list of events to handle.
+     * @param array $options  An array of options (not used).
      */
-    public function notify(&$messageStack, $options = array())
+    public function notify($events, $options = array())
     {
-        if (count($messageStack)) {
-            while ($message = array_shift($messageStack)) {
-                echo $this->getMessage($message);
-            }
+        foreach ($events as $event) {
+            echo '<embed src="' . htmlspecialchars(strval($event)) . '" width="0" height="0" autostart="true" />';
         }
     }
 
-    /**
-     * Processes one message from the message stack.
-     *
-     * @param Horde_Notification_Event $event  An event object.
-     * @param array $options                   An array of options (not used).
-     *
-     * @return mixed  The formatted message.
-     */
-    public function getMessage($event, $options = array())
-    {
-        return '<embed src="' . htmlspecialchars($event->message) . '" width="0" height="0" autostart="true" />';
-    }
-
 }
index edf4a23..2f653f2 100644 (file)
@@ -18,10 +18,8 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener
      */
     public function __construct()
     {
-        $this->_handles = array(
-            'javascript' => '',
-            'javascript-file' => ''
-        );
+        $this->_handles['javascript'] = 'Horde_Notification_Event';
+        $this->_handles['javascript-file'] = 'Horde_Notification_Event';
         $this->_name = 'javascript';
     }
 
@@ -29,26 +27,24 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener
      * Outputs the javascript code if there are any messages on the
      * 'javascript' message stack and if the 'notify_javascript' option is set.
      *
-     * @param array &$messageStack  The stack of messages.
-     * @param array $options        An array of options. Options: 'noscript'
+     * @param array $events   The list of events to handle.
+     * @param array $options  An array of options:
+     * <pre>
+     * 'noscript' - TODO
+     * </pre>
      */
-    public function notify(&$messageStack, $options = array())
+    public function notify($events, $options = array())
     {
-        if (!count($messageStack)) {
-            return;
-        }
-
         $files = $js_text = array();
 
-        while ($message = array_shift($messageStack)) {
-            $event = $this->getMessage($message);
+        foreach ($events as $event) {
             switch ($event->type) {
             case 'javascript':
-                $js_text[] = $event->message . "\n";
+                $js_text[] = strval($event);
                 break;
 
             case 'javascript-file':
-                $files[] = $event->message;
+                $files[] = strval($event);
                 break;
             }
         }
@@ -61,28 +57,13 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener
 
         if (empty($options['noscript'])) {
             if (!empty($js_text)) {
-                echo "//]]></script>\n";
+                echo "\n//]]></script>\n";
             }
 
-            if (count($files)) {
-                foreach ($files as $file) {
-                    echo '<script type="text/javascript" src="' . $file . '"></script>' . "\n";
-                }
+            foreach ($files as $file) {
+                echo '<script type="text/javascript" src="' . htmlspecialchars($file) . "\"></script>\n";
             }
         }
     }
 
-    /**
-     * Processes one message from the message stack.
-     *
-     * @param Horde_Notification_Event $event  An event object.
-     * @param array $options                   An array of options (not used).
-     *
-     * @return mixed  The formatted message.
-     */
-    public function getMessage($event, $options = array())
-    {
-        return $event->message;
-    }
-
 }
diff --git a/framework/Notification/lib/Horde/Notification/Listener/Mobile.php b/framework/Notification/lib/Horde/Notification/Listener/Mobile.php
deleted file mode 100644 (file)
index 610dc97..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * The Horde_Notification_Listener_Mobile:: class provides functionality for
- * displaying messages from the message stack on mobile devices.
- *
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Notification
- */
-class Horde_Notification_Listener_Mobile extends Horde_Notification_Listener_Status
-{
-    /**
-     * The Horde_Mobile:: object that status lines should be added to.
-     *
-     * @var Horde_Mobile
-     */
-    protected $_mobile;
-
-    /**
-     * Constructor.
-     */
-    public function __construct()
-    {
-        $this->_handles = array(
-            'horde.error'   => _("ERR"),
-            'horde.success' => _("SUCCESS"),
-            'horde.warning' => _("WARN"),
-            'horde.message' => _("MSG")
-        );
-        $this->_name = 'status';
-    }
-
-    /**
-     * Associate a Horde_Mobile:: object with the listener.
-     *
-     * @param Horde_Mobile  The Horde_Mobile:: object to send status lines to.
-     */
-    public function setMobileObject($mobile)
-    {
-        $this->_mobile = $mobile;
-    }
-
-    /**
-     * Outputs the status line if there are any messages on the 'mobile'
-     * message stack.
-     *
-     * @param array &$messageStack  The stack of messages.
-     * @param array $options        An array of options.
-     */
-    public function notify(&$messageStack, $options = array())
-    {
-        if (!$this->_mobile) {
-            $p = new Horde_Notification_Listener_Status();
-            return $p->notify($messageStack, $options);
-        }
-
-        if (count($messageStack)) {
-            while ($message = array_shift($messageStack)) {
-                $this->getMessage($message);
-            }
-        }
-    }
-
-    /**
-     * Processes one message from the message stack.
-     *
-     * @param Horde_Notification_Event $event  An event object.
-     * @param array $options                   An array of options (not used).
-     *
-     * @return mixed  The formatted message.
-     */
-    public function getMessage($event, $options = array())
-    {
-        if (!$this->_mobile) {
-            $p = new Horde_Notification_Listener_Status();
-            return $p->getMessage($event, $options);
-        }
-
-        $this->_mobile->add(new Horde_Mobile_text($this->_handles[$event->type] . ': ' . strip_tags($event->message)));
-    }
-
-}
index e91aa69..0178b9a 100644 (file)
 class Horde_Notification_Listener_Status extends Horde_Notification_Listener
 {
     /**
-     * The notified message stack.
-     *
-     * @var array
-     */
-    protected $_notifiedStack = array();
-
-    /**
      * Constructor.
      */
     public function __construct()
     {
-        $image_dir = $GLOBALS['registry']->getImageDir('horde');
-
-        $this->_handles = array(
-            'horde.error' => array($image_dir . '/alerts/error.png', _("Error")),
-            'horde.success' => array($image_dir . '/alerts/success.png', _("Success")),
-            'horde.warning' => array($image_dir . '/alerts/warning.png', _("Warning")),
-            'horde.message' => array($image_dir . '/alerts/message.png', _("Message")),
-            'horde.alarm' => array($image_dir . '/alerts/alarm.png', _("Alarm"))
-        );
+        $this->_handles['status'] = 'Horde_Notification_Event_Status';
         $this->_name = 'status';
     }
 
@@ -41,138 +26,32 @@ class Horde_Notification_Listener_Status extends Horde_Notification_Listener
      * Outputs the status line if there are any messages on the 'status'
      * message stack.
      *
-     * @param array &$messageStack  The stack of messages.
-     * @param array $options        An array of options.
+     * @param array $events   The list of events to handle.
+     * @param array $options  An array of options:
      * <pre>
-     * 'store' - (boolean) If false, outputs message stack to page. If true,
-     *                     stores the message stack for subsequent retrieval
-     *                     via getStack(). DEFAULT: false
+     * 'mobile' - (Horde_Mobile) The mobile object to send status lines to.
      * </pre>
      */
-    public function notify(&$messageStack, $options = array())
+    public function notify($events, $options = array())
     {
-        if (!count($messageStack)) {
+        if (!count($events)) {
             return;
         }
 
-        $store = !empty($options['store']);
-
-        if (!$store) {
-            echo '<ul class="notices">';
-        }
-
-        while ($message = array_shift($messageStack)) {
-            $message = $this->getMessage($message, array('data' => $store));
-            if ($store) {
-                $this->_notifiedStack[] = $message;
-            } else {
-                echo $message;
-            }
-        }
-
-        if (!$store) {
-            echo '</ul>';
-        }
-    }
-
-    /**
-     * Processes one message from the message stack.
-     *
-     * @param Horde_Notification_Event $event  An event object.
-     * @param array $options                   An array of options:
-     * <pre>
-     * 'data' - (boolean) If false, returns HTML code. If true, returns an
-     *                    array of message information. DEFAULT: false
-     * </pre>
-     *
-     * @return mixed  TODO
-     */
-    public function getMessage($event, $options = array())
-    {
-        $result = array('type' => $event->type);
-
-        if ($event->type == 'horde.alarm') {
-            if (empty($options['data'])) {
-                $text = $this->_getAlarm($event->flags['alarm']);
-            } else {
-                $result['alarm'] = $event->flags['alarm'];
-                if (!empty($result['alarm']['params']['notify']['ajax'])) {
-                    $result['alarm']['ajax'] = $result['alarm']['params']['notify']['ajax'];
-                } elseif (!empty($result['alarm']['params']['notify']['show'])) {
-                    $result['alarm']['url'] = (string)Horde::url($GLOBALS['registry']->linkByPackage($result['alarm']['params']['notify']['show']['__app'], 'show', $result['alarm']['params']['notify']['show']), true);
-                }
-                unset($result['alarm']['params']['notify'],
-                      $result['alarm']['methods']);
-            }
-        } else {
-            $text = $event->message;
-            if (!empty($options['data'])) {
-                $result['message'] = $text;
-            }
-            if (!in_array('content.raw', $event->flags)) {
-                $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset());
+        if (!empty($options['mobile'])) {
+            foreach ($events as $event) {
+                $options['mobile']->add(new Horde_Mobile_Text(strip_tags($event)));
             }
+            return;
         }
 
-        return empty($options['data'])
-            ? '<li>' . Horde::img($this->_handles[$event->type][0], $this->_handles[$event->type][1], '', '') . $text . '</li>'
-            : $result;
-    }
+        echo '<ul class="notices">';
 
-    /**
-     * 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 . '</a>';
+        foreach ($events as $event) {
+            echo '<li>' . $event . '</li>';
         }
 
-        if (!empty($alarm['user']) && $GLOBALS['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 .= ' <small onmouseover="if(typeof ' . $id . '_t!=\'undefined\')clearTimeout(' . $id . '_t);Element.show(\'' . $id . '\')" onmouseout="' . $id . '_t=setTimeout(function(){Element.hide(\'' . $id . '\')},500)">[' . _("Snooze...") . '<span id="' . $id . '" style="display:none"> ';
-            $first = true;
-            foreach ($opts as $minutes => $desc) {
-                if (!$first) {
-                    $message .= ', ';
-                }
-                $message .= Horde::link('#', '', '', '', 'new Ajax.Request(\'' . $url . '\',{parameters:{alarm:\'' . $alarm['id'] . '\',snooze:' . $minutes . '},onSuccess:function(){Element.remove(this);}.bind(this.parentNode.parentNode.parentNode)});return false;') . $desc . '</a>';
-                $first = false;
-            }
-            $message .= '</span>]</small>';
-        }
-
-        return $message;
-    }
-
-    /**
-     * Returns all status messages stored via the 'store' option to notify().
-     *
-     * @param boolean $clear  Clear the entries off the internal stack?
-     *
-     * @return array  An array of data items.
-     */
-    public function getStack($clear = true)
-    {
-        $info = $this->_notifiedStack;
-        if ($clear) {
-            $this->_notifiedStack = array();
-        }
-        return $info;
+        echo '</ul>';
     }
 
 }
index 58600fc..da34162 100644 (file)
@@ -33,27 +33,29 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <dir name="lib">
     <dir name="Horde">
      <dir name="Notification">
+      <dir name="Event">
+       <file name="Status.php" role="php" />
+      </dir> <!-- /lib/Horde/Notification/Event -->
       <dir name="Handler">
-       <file name="Base.php" role="php" />
        <dir name="Decorator">
         <file name="Alarm.php" role="php" />
+        <file name="Base.php" role="php" />
         <file name="Hordelog.php" role="php" />
         <file name="Log.php" role="php" />
        </dir> <!-- /lib/Horde/Notification/Handler/Decorator -->
-       <file name="Interface.php" role="php" />
       </dir> <!-- /lib/Horde/Notification/Handler -->
       <dir name="Listener">
        <file name="Audio.php" role="php" />
        <file name="Javascript.php" role="php" />
-       <file name="Mobile.php" role="php" />
        <file name="Status.php" role="php" />
       </dir> <!-- /lib/Horde/Notification/Listener -->
-      <file name="Event.php" role="php" />
-      <file name="Listener.php" role="php" />
       <dir name="Storage">
        <file name="Interface.php" role="php" />
        <file name="Session.php" role="php" />
       </dir> <!-- /lib/Horde/Notification/Storage -->
+      <file name="Event.php" role="php" />
+      <file name="Handler.php" role="php" />
+      <file name="Listener.php" role="php" />
      </dir> <!-- /lib/Horde/Notification -->
      <file name="Notification.php" role="php" />
     </dir> <!-- /lib/Horde -->
@@ -63,23 +65,23 @@ http://pear.php.net/dtd/package-2.0.xsd">
      <dir name="Notification">
       <file name="AllTests.php" role="test" />
       <file name="Autoload.php" role="test" />
+      <file name="phpunit.xml" role="test" />
       <dir name="Class">
        <file name="NotificationTest.php" role="test" />
        <dir name="Notification">
         <file name="EventTest.php" role="test" />
         <dir name="Handler">
-         <file name="BaseTest.php" role="test" />
          <dir name="Decorator">
           <file name="AlarmTest.php" role="test" />
           <file name="HordelogTest.php" role="test" />
           <file name="LogTest.php" role="test" />
          </dir> <!-- /test/Horde/Notification/Class/Notification/Handler/Decorator -->
         </dir> <!-- /test/Horde/Notification/Class/Notification/Handler -->
+        <file name="HandlerTest.php" role="test" />
         <file name="ListenerTest.php" role="test" />
         <dir name="Listener">
          <file name="AudioTest.php" role="test" />
          <file name="JavascriptTest.php" role="test" />
-         <file name="MobileTest.php" role="test" />
          <file name="StatusTest.php" role="test" />
         </dir> <!-- /test/Horde/Notification/Class/Notification/Listener -->
        </dir> <!-- /test/Horde/Notification/Class/Notification -->
@@ -110,40 +112,35 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <name>Alarm</name>
     <channel>pear.horde.org</channel>
    </package>
-   <package>
-    <name>Auth</name>
-    <channel>pear.horde.org</channel>
-   </package>
   </optional>
  </dependencies>
  <phprelease>
   <filelist>
-   <install name="lib/Horde/Notification/Handler/Base.php" as="Horde/Notification/Handler/Base.php" />
+   <install name="lib/Horde/Notification/Event/Status.php" as="Horde/Notification/Event/Status.php" />
    <install name="lib/Horde/Notification/Handler/Decorator/Alarm.php" as="Horde/Notification/Handler/Decorator/Alarm.php" />
+   <install name="lib/Horde/Notification/Handler/Decorator/Base.php" as="Horde/Notification/Handler/Decorator/Base.php" />
    <install name="lib/Horde/Notification/Handler/Decorator/Hordelog.php" as="Horde/Notification/Handler/Decorator/Hordelog.php" />
    <install name="lib/Horde/Notification/Handler/Decorator/Log.php" as="Horde/Notification/Handler/Decorator/Log.php" />
-   <install name="lib/Horde/Notification/Handler/Interface.php" as="Horde/Notification/Handler/Interface.php" />
    <install name="lib/Horde/Notification/Listener/Audio.php" as="Horde/Notification/Listener/Audio.php" />
    <install name="lib/Horde/Notification/Listener/Javascript.php" as="Horde/Notification/Listener/Javascript.php" />
-   <install name="lib/Horde/Notification/Listener/Mobile.php" as="Horde/Notification/Listener/Mobile.php" />
    <install name="lib/Horde/Notification/Listener/Status.php" as="Horde/Notification/Listener/Status.php" />
-   <install name="lib/Horde/Notification/Event.php" as="Horde/Notification/Event.php" />
-   <install name="lib/Horde/Notification/Listener.php" as="Horde/Notification/Listener.php" />
    <install name="lib/Horde/Notification/Storage/Interface.php" as="Horde/Notification/Storage/Interface.php" />
    <install name="lib/Horde/Notification/Storage/Session.php" as="Horde/Notification/Storage/Session.php" />
+   <install name="lib/Horde/Notification/Event.php" as="Horde/Notification/Event.php" />
+   <install name="lib/Horde/Notification/Handler.php" as="Horde/Notification/Handler.php" />
+   <install name="lib/Horde/Notification/Listener.php" as="Horde/Notification/Listener.php" />
    <install name="lib/Horde/Notification.php" as="Horde/Notification.php" />
    <install name="test/Horde/Notification/AllTests.php" as="Horde/Notification/AllTests.php" />
    <install name="test/Horde/Notification/Autoload.php" as="Horde/Notification/Autoload.php" />
    <install name="test/Horde/Notification/Class/NotificationTest.php" as="Horde/Notification/Class/NotificationTest.php" />
+   <install name="test/Horde/Notification/Class/Notification/HandlerTest.php" as="Horde/Notification/Class/Notification/HandlerTest.php" />
    <install name="test/Horde/Notification/Class/Notification/EventTest.php" as="Horde/Notification/Class/Notification/EventTest.php" />
-   <install name="test/Horde/Notification/Class/Notification/Handler/BaseTest.php" as="Horde/Notification/Class/Notification/Handler/BaseTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php" as="Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php" as="Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php" as="Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php" />
    <install name="test/Horde/Notification/Class/Notification/ListenerTest.php" as="Horde/Notification/Class/Notification/ListenerTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Listener/AudioTest.php" as="Horde/Notification/Class/Notification/Listener/AudioTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php" as="Horde/Notification/Class/Notification/Listener/JavascriptTest.php" />
-   <install name="test/Horde/Notification/Class/Notification/Listener/MobileTest.php" as="Horde/Notification/Class/Notification/Listener/MobileTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Listener/StatusTest.php" as="Horde/Notification/Class/Notification/Listener/StatusTest.php" />
   </filelist>
  </phprelease>
index f7390db..89d906a 100644 (file)
@@ -24,3 +24,6 @@ if (!spl_autoload_functions()) {
 
 /** Catch strict standards */
 error_reporting(E_ALL | E_STRICT);
+
+/** Needed for PEAR_Error. */
+@require_once 'PEAR.php';
index 9d394cd..b488060 100644 (file)
@@ -38,14 +38,14 @@ class Horde_Notification_Class_Notification_EventTest extends PHPUnit_Framework_
 
     public function testMethodGetmessageHasResultStringTheStoredMessage()
     {
-        $event = new Horde_Notification_Event();
-        $event->message = test;
+        $event = new Horde_Notification_Event('');
+        $event->message = 'test';
         $this->assertEquals('test', $event->message);
     }
 
     public function testMethodGetmessageHasResultStringEmptyIfNoMessageWasStored()
     {
-        $event = new Horde_Notification_Event();
+        $event = new Horde_Notification_Event('');
         $this->assertEquals('', $event->message);
     }
 }
diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php
deleted file mode 100644 (file)
index 93323e6..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-<?php
-/**
- * Test the basic notification handler class.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-
-/**
- * Prepare the test setup.
- */
-require_once dirname(__FILE__) . '/../../../Autoload.php';
-
-/**
- * Test the basic notification handler class.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-
-class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Framework_TestCase
-{
-    public function setUp()
-    {
-        $this->storage = new Horde_Notification_Storage_Session('test');
-        $this->handler = new Horde_Notification_Handler_Base($this->storage);
-    }
-
-    public function testMethodAttachHasResultNotificationlistener()
-    {
-        $this->assertType(
-            'Horde_Notification_Listener_Audio',
-            $this->handler->attach('audio')
-        );
-    }
-
-    public function testMethodAttachHasResultNotificationlistenerTheSameListenerAsBeforeIfThisListenerHasAlreadyBeenAttached()
-    {
-        $listener = $this->handler->attach('audio');
-        $this->assertSame($listener, $this->handler->attach('audio'));
-    }
-
-    public function testMethodAttachHasResultNotificationlistenerClassAsSpecifiedInParameterClass()
-    {
-        $this->assertType(
-            'Horde_Notification_Listener_Audio',
-            $this->handler->attach(
-                'MyAudio', array(), 'Horde_Notification_Listener_Audio'
-            )
-        );
-    }
-
-    public function testMethodAttachHasPostconditionThatTheListenerGotInitializedWithTheProvidedParmeters()
-    {
-        $listener = $this->handler->attach('dummy', array('test'));
-        $this->assertEquals(array('test'), $listener->params);
-    }
-
-    public function testMethodAttachHasPostconditionThatTheListenerStackGotInitializedAsArray()
-    {
-        $this->handler->attach('audio');
-        $this->assertEquals(array(), $_SESSION['test']['audio']);
-    }
-
-    public function testMethodAttachThrowsExceptionIfTheListenerTypeIsUnkown()
-    {
-        try {
-            $this->handler->attach('MyAudio');
-            $this->fail('No exception!');
-        } catch (Horde_Exception $e) {
-            $this->assertEquals(
-                'Notification listener Horde_Notification_Listener_Myaudio not found.',
-                $e->getMessage()
-            );
-        }
-    }
-
-    public function testMethodReplaceHasResultNotificationlistener()
-    {
-        $this->handler->attach(
-            'test', array(), 'Horde_Notification_Listener_Audio'
-        );
-        $this->assertType(
-            'Horde_Notification_Listener_Dummy',
-            $this->handler->replace(
-                'test', array(), 'Horde_Notification_Listener_Dummy'
-            )
-        );
-    }
-
-    public function testMethodDetachHasPostconditionThatTheListenerStackGotUnset()
-    {
-        $this->handler->attach('audio');
-        $this->handler->detach('audio');
-        $this->assertFalse(isset($_SESSION['test']['audio']));
-    }
-
-    public function testMethodDetachThrowsExceptionIfTheListenerIsUnset()
-    {
-        try {
-            $this->handler->detach('MyAudio');
-            $this->fail('No exception!');
-        } catch (Horde_Exception $e) {
-            $this->assertEquals(
-                'Notification listener myaudio not found.',
-                $e->getMessage()
-            );
-        }
-    }
-
-    public function testMethodPushHasPostconditionThatTheEventGotSavedInAllAttachedListenerStacksHandlingTheEvent()
-    {
-        $event = new Horde_Notification_Event('test');
-        $flags= array();
-        $this->handler->attach('audio');
-        $this->handler->push('test', 'audio');
-        $result = array_shift($_SESSION['test']['audio']);
-        $this->assertEquals('Horde_Notification_Event', $result['class']);
-        $this->assertEquals(serialize($event), $result['event']);
-        $this->assertEquals(serialize($flags), $result['flags']);
-        $this->assertEquals('audio', $result['type']);
-    }
-
-    public function testMethodPushHasPostconditionThatAnExceptionGetsMarkedAsTypeErrorIfTheTypeWasUnset()
-    {
-        $this->handler->attach('dummy');
-        $this->handler->push(new Exception('test'));
-        $result = array_shift($_SESSION['test']['dummy']);
-        $this->assertEquals('horde.error', $result['type']);
-    }
-
-    public function testMethodPushHasPostconditionThatEventsWithoutTypeGetMarkedAsTypeMessage()
-    {
-        $this->handler->attach('dummy');
-        $this->handler->push('test');
-        $result = array_shift($_SESSION['test']['dummy']);
-        $this->assertEquals('horde.message', $result['type']);
-    }
-
-    public function testMethodNotifyHasPostconditionThatAllListenersWereNotified()
-    {
-        $event = new Horde_Notification_Event('test');
-        $dummy = $this->handler->attach('dummy');
-        $flags= array();
-        $this->handler->push('test');
-        $this->handler->notify();
-        $result = array_shift($dummy->notifications);
-        $this->assertEquals('Horde_Notification_Event', $result['class']);
-        $this->assertEquals(serialize($event), $result['event']);
-        $this->assertEquals(serialize($flags), $result['flags']);
-        $this->assertEquals('horde.message', $result['type']);
-    }
-
-    public function testMethodNotifyHasPostconditionThatTheSpecifiedListenersWereNotified()
-    {
-        $event = new Horde_Notification_Event('test');
-        $dummy = $this->handler->attach('dummy');
-        $flags= array();
-        $this->handler->push('test');
-        $this->handler->notify(array('listeners' => 'dummy'));
-        $result = array_shift($dummy->notifications);
-        $this->assertEquals(serialize($event), $result['event']);
-    }
-
-    public function testMethodCountHasResultTheTotalNumberOfEventsInTheStack()
-    {
-        $this->handler->attach('audio');
-        $this->handler->attach('dummy');
-        $this->handler->push('test', 'audio');
-        $this->assertEquals(2, $this->handler->count());
-    }
-
-    public function testMethodCountHasResultTheEventNumberForASpecificListenerIfTheListenerHasBeenSpecified()
-    {
-        $this->handler->attach('audio');
-        $this->handler->attach('dummy');
-        $this->handler->push('test', 'audio');
-        $this->assertEquals(1, $this->handler->count('audio'));
-    }
-
-}
-
-class Horde_Notification_Listener_Dummy extends Horde_Notification_Listener
-{
-    public $params;
-
-    public $notifications;
-
-    public function __construct($params)
-    {
-        $this->params = $params;
-        $this->_name = 'dummy';
-        $this->_handles = array(
-            'audio' => '',
-            'horde.error' => '',
-            'horde.message' => '',
-        );
-    }
-
-    public function notify(&$messageStacks, $options = array())
-    {
-        $this->notifications = $messageStacks;
-    }
-
-    public function getMessage($message, $options = array())
-    {
-    }
-}
index 7037488..c103718 100644 (file)
@@ -38,12 +38,9 @@ extends PHPUnit_Framework_TestCase
             $this->markTestSkipped('The Horde_Alarm package is not installed!');
         }
 
-        $this->handler = $this->getMock(
-            'Horde_Notification_Handler_Base', array(), array(), '', false, false
-        );
-        $this->alarm   = $this->getMock('Horde_Alarm');
+        $this->alarm = $this->getMock('Horde_Alarm');
         $this->alarm_handler = new Horde_Notification_Handler_Decorator_Alarm(
-            $this->handler, $this->alarm
+            $this->alarm, null
         );
     }
 
@@ -52,92 +49,7 @@ extends PHPUnit_Framework_TestCase
         $this->alarm->expects($this->once())
             ->method('notify')
             ->with('');
-        $this->handler->expects($this->once())
-            ->method('setNotificationListeners')
-            ->with(array('listeners' => array('status')))
-            ->will($this->returnValue(array('listeners' => array('status'))));
-        $this->handler->expects($this->once())
-            ->method('notifyListeners')
-            ->with(array('listeners' => array('status')));
         $this->alarm_handler->notify(array('listeners' => array('status')));
     }
 
-    public function testMethodAttachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('attach')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->alarm_handler->attach('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodDetachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('detach')
-            ->with('listener');
-        $this->alarm_handler->detach('listener');
-    }
-
-    public function testMethodReplaceGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('replace')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->alarm_handler->replace('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodPushGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('push')
-            ->with('event', 'type', array());
-        $this->alarm_handler->push('event', 'type', array());
-    }
-
-    public function testMethodNotifyGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('setNotificationListeners')
-            ->with(array('listeners' => array('test')))
-            ->will($this->returnValue(array('listeners' => array('test'))));
-        $this->handler->expects($this->once())
-            ->method('notifyListeners')
-            ->with(array('listeners' => array('test')));
-        $this->alarm_handler->notify(array('listeners' => array('test')));
-    }
-
-    public function testMethodSetnotificationlistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('setNotificationListeners')
-            ->with(array());
-        $array = array();
-        $this->alarm_handler->setNotificationListeners($array);
-    }
-
-    public function testMethodNotifylistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('notifyListeners')
-            ->with(array());
-        $this->alarm_handler->notifyListeners(array());
-    }
-
-    public function testMethodCountGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('count')
-            ->with('listener')
-            ->will($this->returnValue(1));
-        $this->assertEquals(1, $this->alarm_handler->count('listener'));
-    }
-
 }
index bf4750c..98fdf2c 100644 (file)
@@ -32,106 +32,9 @@ require_once dirname(__FILE__) . '/../../../../Autoload.php';
 class Horde_Notification_Class_Notification_Handler_Decorator_HordelogTest
 extends PHPUnit_Framework_TestCase
 {
-    public function setUp()
+    public function testNoneAvailable()
     {
-        if (!class_exists('Log')) {
-            $this->markTestSkipped('The PEAR Log package is not installed!');
-        }
-
-        @include_once 'Log.php';
-        if (!defined('PEAR_LOG_DEBUG')) {
-            $this->markTestSkipped('The PEAR_LOG_DEBUG constant is not available!');
-        }
-
-        $this->handler = $this->getMock(
-            'Horde_Notification_Handler_Base', array(), array(), '', false, false
-        );
-        $this->logged_handler = new Horde_Notification_Handler_Decorator_Hordelog(
-            $this->handler
-        );
-    }
-
-    public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError()
-    {
-        $exception = new Exception('test');
-        $this->handler->expects($this->once())
-            ->method('push')
-            ->with($exception);
-        $this->logged_handler->push($exception);
-    }
-
-    public function testMethodAttachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('attach')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->logged_handler->attach('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodDetachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('detach')
-            ->with('listener');
-        $this->logged_handler->detach('listener');
-    }
-
-    public function testMethodReplaceGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('replace')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->logged_handler->replace('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodPushGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('push')
-            ->with('event', 'type', array());
-        $this->logged_handler->push('event', 'type', array());
-    }
-
-    public function testMethodNotifyGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('notify')
-            ->with(array('listeners' => array('test')));
-        $this->logged_handler->notify(array('listeners' => array('test')));
-    }
-
-    public function testMethodSetnotificationlistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('setNotificationListeners')
-            ->with(array());
-        $array = array();
-        $this->logged_handler->setNotificationListeners($array);
+        // No tests
+        $this->markTestIncomplete('No tests available.');
     }
-
-    public function testMethodNotifylistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('notifyListeners')
-            ->with(array());
-        $this->logged_handler->notifyListeners(array());
-    }
-
-    public function testMethodCountGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('count')
-            ->with('listener')
-            ->will($this->returnValue(1));
-        $this->assertEquals(1, $this->logged_handler->count('listener'));
-    }
-
 }
index 056abfb..933b512 100644 (file)
@@ -38,99 +38,19 @@ extends PHPUnit_Framework_TestCase
             $this->markTestSkipped('The Horde_Log package is not installed!');
         }
 
-        $this->handler = $this->getMock(
-            'Horde_Notification_Handler_Base', array(), array(), '', false, false
-        );
-        $this->logger   = $this->getMock('Horde_Log_Logger');
-        $this->logged_handler = new Horde_Notification_Handler_Decorator_Log(
-            $this->handler, $this->logger
+        $this->logger = $this->getMock('Horde_Log_Logger');
+        $this->log = new Horde_Notification_Handler_Decorator_Log(
+            $this->logger
         );
     }
 
     public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError()
     {
-        $exception = new Exception('test');
+        $exception = new Horde_Notification_Event(new Exception('test'));
         $this->logger->expects($this->once())
             ->method('__call')
             ->with('debug', $this->isType('array'));
-        $this->handler->expects($this->once())
-            ->method('push')
-            ->with($exception);
-        $this->logged_handler->push($exception);
-    }
-
-    public function testMethodAttachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('attach')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->logged_handler->attach('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodDetachGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('detach')
-            ->with('listener');
-        $this->logged_handler->detach('listener');
-    }
-
-    public function testMethodReplaceGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('replace')
-            ->with('listener', array(), 'class')
-            ->will($this->returnValue('instance'));
-        $this->assertEquals(
-            'instance',
-            $this->logged_handler->replace('listener', array(), 'class')
-        );
-    }
-
-    public function testMethodPushGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('push')
-            ->with('event', 'type', array());
-        $this->logged_handler->push('event', 'type', array());
-    }
-
-    public function testMethodNotifyGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('notify')
-            ->with(array('listeners' => array('test')));
-        $this->logged_handler->notify(array('listeners' => array('test')));
-    }
-
-    public function testMethodSetnotificationlistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('setNotificationListeners')
-            ->with(array());
-        $array = array();
-        $this->logged_handler->setNotificationListeners($array);
-    }
-
-    public function testMethodNotifylistenersGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('notifyListeners')
-            ->with(array());
-        $this->logged_handler->notifyListeners(array());
-    }
-
-    public function testMethodCountGetsDelegated()
-    {
-        $this->handler->expects($this->once())
-            ->method('count')
-            ->with('listener')
-            ->will($this->returnValue(1));
-        $this->assertEquals(1, $this->logged_handler->count('listener'));
+        $this->log->push($exception, array());
     }
 
 }
diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php
new file mode 100644 (file)
index 0000000..66854e4
--- /dev/null
@@ -0,0 +1,206 @@
+<?php
+/**
+ * Test the basic notification handler class.
+ *
+ * @category Horde
+ * @package  Notification
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Notification
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the basic notification handler class.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package  Notification
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Notification
+ */
+
+class Horde_Notification_Class_Notification_HandlerTest extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->storage = new Horde_Notification_Storage_Session('test');
+        $this->handler = new Horde_Notification_Handler($this->storage);
+    }
+
+    public function testMethodAttachHasResultNotificationlistener()
+    {
+        $this->assertType(
+            'Horde_Notification_Listener_Audio',
+            $this->handler->attach('audio')
+        );
+    }
+
+    public function testMethodAttachHasResultNotificationlistenerTheSameListenerAsBeforeIfThisListenerHasAlreadyBeenAttached()
+    {
+        $listener = $this->handler->attach('audio');
+        $this->assertSame($listener, $this->handler->attach('audio'));
+    }
+
+    public function testMethodAttachHasResultNotificationlistenerClassAsSpecifiedInParameterClass()
+    {
+        $this->assertType(
+            'Horde_Notification_Listener_Audio',
+            $this->handler->attach(
+                'MyAudio', array(), 'Horde_Notification_Listener_Audio'
+            )
+        );
+    }
+
+    public function testMethodAttachHasPostconditionThatTheListenerGotInitializedWithTheProvidedParmeters()
+    {
+        $listener = $this->handler->attach('dummy', array('test'));
+        $this->assertEquals(array('test'), $listener->params);
+    }
+
+    public function testMethodAttachHasPostconditionThatTheListenerStackGotInitializedAsArray()
+    {
+        $this->handler->attach('audio');
+        $this->assertEquals(array(), $_SESSION['test']['audio']);
+    }
+
+    public function testMethodAttachThrowsExceptionIfTheListenerTypeIsUnknown()
+    {
+        try {
+            $this->handler->attach('MyAudio');
+            $this->fail('No exception!');
+        } catch (Horde_Exception $e) {
+            $this->assertEquals(
+                'Notification listener Horde_Notification_Listener_Myaudio not found.',
+                $e->getMessage()
+            );
+        }
+    }
+
+    public function testMethodDetachHasPostconditionThatTheListenerStackGotUnset()
+    {
+        $this->handler->attach('audio');
+        $this->handler->detach('audio');
+        $this->assertFalse(isset($_SESSION['test']['audio']));
+    }
+
+    public function testMethodDetachThrowsExceptionIfTheListenerIsUnset()
+    {
+        try {
+            $this->handler->detach('MyAudio');
+            $this->fail('No exception!');
+        } catch (Horde_Exception $e) {
+            $this->assertEquals(
+                'Notification listener MyAudio not found.',
+                $e->getMessage()
+            );
+        }
+    }
+
+    public function testMethodPushHasPostconditionThatTheEventGotSavedInAllAttachedListenerStacksHandlingTheEvent()
+    {
+        $event = new Horde_Notification_Event('test');
+        $this->handler->attach('audio');
+        $this->handler->push('test', 'audio', array(), array('immediate' => true));
+        $result = array_shift($_SESSION['test']['audio']);
+        $this->assertNotNull($result);
+        $this->assertType('Horde_Notification_Event', $result);
+        $this->assertEquals(array(), $result->flags);
+        $this->assertEquals('audio', $result->type);
+    }
+
+    public function testMethodPushHasPostconditionThatAnExceptionGetsMarkedAsTypeStatusIfTheTypeWasUnset()
+    {
+        $this->handler->attach('dummy');
+        $this->handler->push(new Exception('test'), null, array(), array('immediate' => true));
+        $result = array_shift($_SESSION['test']['dummy']);
+        $this->assertNotNull($result);
+        $this->assertType('Horde_Notification_Event', $result);
+        $this->assertEquals(array(), $result->flags);
+        $this->assertEquals('status', $result->type);
+    }
+
+    public function testMethodPushHasPostconditionThatEventsWithoutTypeGetMarkedAsTypeStatus()
+    {
+        $this->handler->attach('dummy');
+        $this->handler->push('test', null, array(), array('immediate' => true));
+        $result = array_shift($_SESSION['test']['dummy']);
+        $this->assertNotNull($result);
+        $this->assertType('Horde_Notification_Event', $result);
+        $this->assertEquals(array(), $result->flags);
+        $this->assertEquals('status', $result->type);
+    }
+
+    public function testMethodNotifyHasPostconditionThatAllListenersWereNotified()
+    {
+        $dummy = $this->handler->attach('dummy');
+        $this->handler->push('test', 'dummy');
+        $this->handler->notify();
+        $result = array_shift($dummy->events);
+        $this->assertNotNull($result);
+        $this->assertType('Horde_Notification_Event', $result);
+        $this->assertEquals(array(), $result->flags);
+        $this->assertEquals('dummy', $result->type);
+    }
+
+    public function testMethodNotifyHasPostconditionThatTheSpecifiedListenersWereNotified()
+    {
+        $dummy = $this->handler->attach('dummy');
+        $this->handler->push('test', 'dummy');
+        $this->handler->notify(array('listeners' => 'dummy'));
+        $result = array_shift($dummy->events);
+        $this->assertNotNull($result);
+        $this->assertType('Horde_Notification_Event', $result);
+        $this->assertEquals(array(), $result->flags);
+        $this->assertEquals('dummy', $result->type);
+    }
+
+    public function testMethodCountHasResultTheTotalNumberOfEventsInTheStack()
+    {
+        $this->handler->attach('audio');
+        $this->handler->attach('dummy');
+        $this->handler->push('test', 'audio');
+        $this->handler->push('test', 'dummy');
+        $this->assertEquals(2, $this->handler->count());
+    }
+
+    public function testMethodCountHasResultTheEventNumberForASpecificListenerIfTheListenerHasBeenSpecified()
+    {
+        $this->handler->attach('audio');
+        $this->handler->attach('dummy');
+        $this->handler->push('test', 'audio');
+        $this->assertEquals(1, $this->handler->count('audio'));
+    }
+
+}
+
+class Horde_Notification_Listener_Dummy extends Horde_Notification_Listener
+{
+    public $events;
+    public $params;
+
+    public function __construct($params)
+    {
+        $this->params = $params;
+        $this->_name = 'dummy';
+        $this->_handles = array(
+            'dummy' => 'Horde_Notification_Event',
+            'status' => 'Horde_Notification_Event'
+        );
+    }
+
+    public function notify($events, $options = array())
+    {
+        $this->events = $events;
+    }
+
+}
index d5efc65..ee7bec1 100644 (file)
@@ -30,10 +30,10 @@ require_once dirname(__FILE__) . '/../../../Autoload.php';
  */
 class Horde_Notification_Class_Notification_Listener_AudioTest extends PHPUnit_Extensions_OutputTestCase
 {
-    public function testMethodHandleHasResultBooleanTrueForAudioMessages()
+    public function testMethodHandleHasEventClassForAudioMessages()
     {
         $listener = new Horde_Notification_Listener_Audio();
-        $this->assertTrue($listener->handles('audio'));
+        $this->assertEquals('Horde_Notification_Event', $listener->handles('audio'));
     }
 
     public function testMethodGetnameHasResultStringAudio()
index 2761bba..3f11306 100644 (file)
@@ -30,10 +30,10 @@ require_once dirname(__FILE__) . '/../../../Autoload.php';
  */
 class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPUnit_Extensions_OutputTestCase
 {
-    public function testMethodHandleHasResultBooleanTrueForjavascriptMessages()
+    public function testMethodHandleHasEventClassForjavascriptMessages()
     {
         $listener = new Horde_Notification_Listener_Javascript();
-        $this->assertTrue($listener->handles('javascript'));
+        $this->assertEquals('Horde_Notification_Event', $listener->handles('javascript'));
     }
 
     public function testMethodGetnameHasResultStringJavascript()
@@ -52,7 +52,7 @@ class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPU
     public function testMethodNotifyHasOutputEventMessageEmbeddedInScriptElement()
     {
         $listener = new Horde_Notification_Listener_Javascript();
-        $event = new Horde_Notification_Event('test');
+        $event = new Horde_Notification_Event('test', 'javascript');
         $messages = array($event);
         $this->expectOutputString(
             '<script type="text/javascript">//<![CDATA['
@@ -64,9 +64,9 @@ class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPU
     public function testMethodNotifyHasOutputEventMessageNotEmbeddedIfEmbeddingIsDeactivated()
     {
         $listener = new Horde_Notification_Listener_Javascript();
-        $event = new Horde_Notification_Event('test');
+        $event = new Horde_Notification_Event('test', 'javascript');
         $messages = array($event);
-        $this->expectOutputString('test' . "\n");
+        $this->expectOutputString('test');
         $listener->notify($messages, array('noscript' => true));
     }
 
diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/MobileTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/MobileTest.php
deleted file mode 100644 (file)
index ce3a152..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-/**
- * Test the mobile listener class.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-
-/**
- * Prepare the test setup.
- */
-require_once dirname(__FILE__) . '/../../../Autoload.php';
-
-/**
- * Test the mobile listener class.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-class Horde_Notification_Class_Notification_Listener_MobileTest extends PHPUnit_Extensions_OutputTestCase
-{
-    public function setUp()
-    {
-        if (!class_exists('Horde_Perms')) {
-            $this->markTestSkipped('The Horde_Perms package is not installed!');
-        }
-
-        if (!class_exists('Horde_Mobile')) {
-            $this->markTestSkipped('The Horde_Mobile package is not installed!');
-        }
-
-        /**
-         * The listener pulls the registry from global scope to get the image
-         * directory.
-         */
-        $GLOBALS['registry'] = $this->getMock(
-            'Horde_Registry', array(), array(), '', false, false
-        );
-
-        $this->mobile = $this->getMock(
-            'Horde_Mobile', array(), array(), '', false, false
-        );
-    }
-
-    public function testMethodHandleHasResultBooleanTrueForHordeMessages()
-    {
-        $listener = new Horde_Notification_Listener_Mobile();
-        $this->assertTrue($listener->handles('horde.message'));
-    }
-
-    public function testMethodGetnameHasResultStringStatus()
-    {
-        $listener = new Horde_Notification_Listener_Mobile();
-        $this->assertEquals('status', $listener->getName());
-    }
-
-    public function testMethodNotifyHasNoOutputIfTheMessageStackIsEmpty()
-    {
-        $listener = new Horde_Notification_Listener_Mobile();
-        $messages = array();
-        $listener->setMobileObject($this->mobile);
-        $listener->notify($messages);
-    }
-
-    public function testMethodNotifyHasSameOutputAsTheStatusListenerIfNoMobileObjectWasSet()
-    {
-        $this->markTestIncomplete('This is untestable without mocking half of the Horde framework.');
-        $listener = new Horde_Notification_Listener_Mobile();
-        $event = new Horde_Notification_Event('test');
-        $messages = array($event);
-        $this->expectOutputString(
-            '<ul class="notices"><li>test</li></ul>'
-        );
-        $listener->notify($messages);
-    }
-
-    public function testMethodNotifyHasPostconditionThatTheMobileObjectReceivedTheNotifications()
-    {
-        $element = $this->getMock('Horde_Mobile_element');
-        $this->mobile->expects($this->exactly(2))
-            ->method('add')
-            ->with(
-                $this->logicalOr(
-                    $this->logicalAnd(
-                        $this->isInstanceOf('Horde_Mobile_Text'),
-                        $this->attributeEqualTo('_text', 'MSG: test')
-                    ),
-                    $this->logicalAnd(
-                        $this->isInstanceOf('Horde_Mobile_Text'),
-                        $this->attributeEqualTo('_text', "\n")
-                    )
-                )
-            )
-            ->will($this->returnValue($element));
-        $listener = new Horde_Notification_Listener_Mobile();
-        $listener->setMobileObject($this->mobile);
-        $event = new Horde_Notification_Event('test');
-        $messages = array($event);
-        $listener->notify($messages);
-    }
-
-    public function testMethodGetmessageHasSameOutputAsTheStatusListenerIfNoMobileObjectWasSet()
-    {
-        $listener = new Horde_Notification_Listener_Mobile();
-        $event = new Horde_Notification_Event('test');
-        $event->flags = array('content.raw' => true);
-        $messages = array($event);
-        $listener->getMessage($messages, array('data' => true));
-    }
-
-}
index 53a3b38..6a21776 100644 (file)
@@ -30,25 +30,10 @@ require_once dirname(__FILE__) . '/../../../Autoload.php';
  */
 class Horde_Notification_Class_Notification_Listener_StatusTest extends PHPUnit_Extensions_OutputTestCase
 {
-    public function setUp()
-    {
-        if (!class_exists('Horde_Perms')) {
-            $this->markTestSkipped('The Horde_Perms package is not installed!');
-        }
-
-        /**
-         * The listener pulls the registry from global scope to get the image
-         * directory.
-         */
-        $GLOBALS['registry'] = $this->getMock(
-            'Horde_Registry', array(), array(), '', false, false
-        );
-    }
-
-    public function testMethodHandleHasResultBooleanTrueForHordeMessages()
+    public function testMethodHandleHasEventClassForHordeMessages()
     {
         $listener = new Horde_Notification_Listener_Status();
-        $this->assertTrue($listener->handles('horde.message'));
+        $this->assertEquals('Horde_Notification_Event_Status', $listener->handles('status'));
     }
 
     public function testMethodGetnameHasResultStringStatus()
@@ -66,7 +51,6 @@ class Horde_Notification_Class_Notification_Listener_StatusTest extends PHPUnit_
 
     public function testMethodNotifyHasOutputEventMessagesEmbeddedInUlElement()
     {
-        $this->markTestIncomplete('This is untestable without mocking half of the Horde framework.');
         $listener = new Horde_Notification_Listener_Status();
         $event = new Horde_Notification_Event('test');
         $messages = array($event);
@@ -76,26 +60,4 @@ class Horde_Notification_Class_Notification_Listener_StatusTest extends PHPUnit_
         $listener->notify($messages);
     }
 
-    public function testMethodGetstackHasNoOutputIfNotifyWasAskedToAvoidDirectOutput()
-    {
-        $listener = new Horde_Notification_Listener_Status();
-        $event = new Horde_Notification_Event('test');
-        $event->flags = array('content.raw' => true);
-        $messages = array($event);
-        $listener->notify($messages, array('store' => true));
-        $this->expectOutputString('');
-    }
-
-    public function testMethodGetstackHasOutputEventMessagesIfNotifyWasAskedToAvoidDirectOutput()
-    {
-        $listener = new Horde_Notification_Listener_Status();
-        $event = new Horde_Notification_Event('test');
-        $event->flags = array('content.raw' => true);
-        $messages = array($event);
-        $listener->notify($messages, array('store' => true));
-        $this->assertEquals(
-            $event,
-            $listener->getStack()
-        );
-    }
 }
index ae7b72c..4e42094 100644 (file)
@@ -43,160 +43,26 @@ class Horde_Notification_Class_Notification_ListenerTest extends PHPUnit_Framewo
         $this->assertFalse($listener->handles('test'));
     }
 
-    public function testMethodGetnameHasResultStringTheNameOfTheListener()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $this->assertEquals('mock', $listener->getName());
-    }
-
-    public function testMethodGeteventHasResultNotificationeventTheUnserializedMessageEvent()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $event = new Horde_Notification_Event('test');
-        $message = array(
-            'class' => 'Horde_Notification_Event',
-            'event' => serialize($event)
-        );
-        $this->assertType(
-            'Horde_Notification_Event',
-            $listener->getEvent($message)
-        );
-    }
-
-    public function testMethodGeteventHasResultNotificationeventTheUnserializedMessageEventIfTheClassInformationInTheMessageIsInvalid()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $event = new Horde_Notification_Event('test');
-        $message = array(
-            'class' => 'Does_Not_Exist',
-            'event' => serialize($event)
-        );
-        $this->assertType(
-            'Horde_Notification_Event',
-            $listener->getEvent($message)
-        );
-    }
-
-    public function testMethodGeteventHasResultNotificationeventTheUnserializedMessageIfTheUnserializedObjectHasAnAttributeMessage()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $event = new stdClass;
-        $event->_message = 'test';
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $this->assertType(
-            'Horde_Notification_Event',
-            $listener->getEvent($message)
-        );
-    }
-
-    public function testMethodGeteventHasResultPearerrorIfTheMessageCouldNotBeUnserialized()
-    {
-        $this->markTestIncomplete('Fails because of strict standards (PEAR::raiseError()).');
-        $listener = new Horde_Notification_Listener_Mock();
-        $message = array(
-            'class' => '',
-            'event' => 'unserializable'
-        );
-        $this->assertType(
-            'PEAR_Error',
-            $listener->getEvent($message)
-        );
-    }
-
-    public function testMethodGeteventHasResultPearerrorIfTheMessageContainedAPearerror()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $event = new PEAR_Error();
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $this->assertType(
-            'PEAR_Error',
-            $listener->getEvent($message)
-        );
-    }
-
-    public function testMethodGeteventHasResultPearerrorWithHiddenAttributeMessageIfTheMessageContainedAPearerrorWithUserInfo()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $event = new PEAR_Error('message', null, null, null, 'test');
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $result = $listener->getEvent($message);
-        $this->assertEquals('message : test', $result->_message);
-    }
-
-    public function testMethodGeteventHasResultPearerrorWithHiddenAttributeMessageComposedOfArrayElementsIfTheMessageContainedAPearerrorWithAnArrayOfUserInfo()
+    public function testMethodHandleHasEventClassName()
     {
         $listener = new Horde_Notification_Listener_Mock();
-        $user_info = array('1', '2');
-        $event = new PEAR_Error('message', null, null, null, $user_info);
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $result = $listener->getEvent($message);
-        $this->assertEquals('message : 1, 2', $result->_message);
+        $this->assertEquals('Horde_Notification_Event', $listener->handles('mock'));
     }
 
-    public function testMethodGeteventHasResultPearerrorWithHiddenAttributeMessageComposedOfArrayElementsIfTheMessageContainedAPearerrorWithAnArrayOfUserInfoErrors()
-    {
-        $listener = new Horde_Notification_Listener_Mock();
-        $user_info = array(new PEAR_Error('a'), new PEAR_Error('b'));
-        $event = new PEAR_Error('message', null, null, null, $user_info);
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $result = $listener->getEvent($message);
-        $this->assertEquals('message : a, b', $result->_message);
-    }
-
-    public function testMethodGeteventHasResultPearerrorWithHiddenAttributeMessageComposedOfArrayElementsIfTheMessageContainedAPearerrorWithAnArrayOfUserInfoObjectThatImplementGetmessageButNotTostring()
+    public function testMethodGetnameHasResultStringTheNameOfTheListener()
     {
         $listener = new Horde_Notification_Listener_Mock();
-        $user_info = array(new Message('a'), new Message('b'));
-        $event = new PEAR_Error('message', null, null, null, $user_info);
-        $message = array(
-            'class' => '',
-            'event' => serialize($event)
-        );
-        $result = $listener->getEvent($message);
-        $this->assertEquals('message : a, b', $result->_message);
+        $this->assertEquals('mock', $listener->getName());
     }
 
 }
 
 class Horde_Notification_Listener_Mock extends Horde_Notification_Listener
 {
+    protected $_handles = array('mock' => 'Horde_Notification_Event');
     protected $_name = 'mock';
 
-    public function notify(&$messageStacks, $options = array())
-    {
-    }
-
-    public function getMessage($message, $options = array())
-    {
-    }
-}
-
-class Message
-{
-    private $_message;
-
-    public function __construct($message)
-    {
-        $this->_message = $message;
-    }
-
-    public function getMessage()
+    public function notify($events, $options = array())
     {
-        return $this->_message;
     }
 }
index b036cc4..432f9b9 100644 (file)
@@ -38,20 +38,6 @@ class Horde_Notification_Class_NotificationTest extends PHPUnit_Framework_TestCa
         $this->assertSame($notification1, $notification2);
     }
 
-    public function testMethodSingletonReturnsAlarmhandlerIfTheAlarmSystemisConfigured()
-    {
-        if (!class_exists('Horde_Alarm')) {
-            $this->markTestSkipped('The Horde_Alarm package is not installed!');
-        }
-
-        $GLOBALS['conf']['alarms']['driver'] = 'Mock';
-
-        $this->assertType(
-            'Horde_Notification_Handler_Decorator_Alarm',
-            Horde_Notification::singleton('alarm')
-        );
-    }
-
     public function testMethodConstructHasPostconditionThatTheSessionStackGotInitializedAsArray()
     {
         $notification = Horde_Notification_Instance::newInstance('test');
@@ -64,6 +50,6 @@ class Horde_Notification_Instance extends Horde_Notification
     static public function newInstance($stack)
     {
         $storage = new Horde_Notification_Storage_Session($stack);
-        return new Horde_Notification_Handler_Base($storage);
+        return new Horde_Notification_Handler($storage);
     }
 }
index 7597271..2531da0 100644 (file)
@@ -15,7 +15,6 @@
  * prefsMenu() - TODO
  * prefsSpecial($pref, $updated) - TODO
  * prefsSpecialGenerate($pref) - TODO
- * prefsStatus() - TODO
  *
  * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
  *
index 5d47f7d..cb5877a 100644 (file)
@@ -39,7 +39,7 @@ try {
         ($action != 'LogOut')) {
         $ajax = Horde_Ajax::getInstance($app);
         $GLOBALS['notification']->push(str_replace('&amp;', '&', Horde_Auth::getLogoutUrl(array('reason' => Horde_Auth::REASON_SESSION))), 'horde.ajaxtimeout', array('content.raw'));
-        Horde::sendHTTPResponse(Horde::prepareResponse(null, $ajax->notificationHandler()), $ajax->responseType());
+        Horde::sendHTTPResponse(Horde::prepareResponse(null, $ajax->notify), $ajax->responseType());
         exit;
     }
 
@@ -65,4 +65,4 @@ if (ob_get_length()) {
 }
 
 // Send the final result.
-Horde::sendHTTPResponse(Horde::prepareResponse($result, $ajax->notificationHandler()), $ajax->responseType());
+Horde::sendHTTPResponse(Horde::prepareResponse($result, $ajax->notify), $ajax->responseType());
index 422d091..c28ea1e 100644 (file)
@@ -28,11 +28,6 @@ $chunk = Horde_Util::nonInputVar('chunk');
 /* Load $app's base environment. */
 $registry->pushApp($app);
 
-/* If a prefs notification status handler is set, activate it now. */
-if (!empty($_SESSION['horde_prefs']['status'])) {
-    $registry->callAppMethod($_SESSION['horde_prefs']['status'], 'prefsStatus');
-}
-
 /* Set title. */
 $title = sprintf(_("Options for %s"), $registry->get('name'));
 
index 4a13615..51d8ecb 100644 (file)
@@ -191,10 +191,6 @@ if ($vars->popup) {
 }
 Horde::addInlineScript(array_merge($compose_result['js'], $js));
 
-/* Some actions, like adding forwards, may return error messages so explicitly
- * display those messages now. */
-Horde::addInlineScript(array(IMP_Dimp::notify()), 'dom');
-
 /* Javascript to be run on window load. */
 $fillform_opts['focus'] = ($vars->type == 'new' || $vars->type == 'forward') ? 'to' : 'composeMessage';
 $compose_result['js_onload'][] = 'DimpCompose.fillForm(' . Horde_Serialize::serialize($msg, Horde_Serialize::JSON) . ',' . Horde_Serialize::serialize($header, Horde_Serialize::JSON) . ',' . Horde_Serialize::serialize($fillform_opts, Horde_Serialize::JSON) . ')';
@@ -205,6 +201,7 @@ $scripts = array(
     array('md5.js', 'horde')
 );
 
+IMP::status();
 IMP_Dimp::header(_("Message Composition"), $scripts);
 echo $t->fetch(IMP_TEMPLATES . '/imp/compose.html');
 Horde::includeScriptFiles();
index 9fdb6e7..3de45e2 100644 (file)
@@ -212,13 +212,13 @@ var DimpCore = {
                 return true;
 
             case 'horde.alarm':
-                if (!this.alarms[m.alarm.id]) {
-                    this.Growler.growl(m.alarm.title + ': ' + m.alarm.text, {
+                if (!this.alarms[m.flags.alarm.id]) {
+                    this.Growler.growl(m.flags.alarm.title + ': ' + m.flags.alarm.text, {
                         className: 'horde-alarm',
                         sticky: 1,
                         log: 1
                     });
-                    this.alarms[m.alarm.id] = 1;
+                    this.alarms[m.flags.alarm.id] = 1;
                 }
                 break;
 
index 25b37eb..14bec7a 100644 (file)
 class IMP_Ajax_Application extends Horde_Ajax_Application_Base
 {
     /**
+     * Determines if notification information is sent in response.
+     *
+     * @var boolean
+     */
+    public $notify = true;
+
+    /**
      * The list of actions that require readonly access to the session.
      *
      * @var array
@@ -22,17 +29,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     );
 
     /**
-     * Returns a notification handler object to use to output any
-     * notification messages triggered by the AJAX action.
-     *
-     * @return Horde_Notification_Handler_Base  The notification handler.
-     */
-    public function notificationHandler()
-    {
-        return $GLOBALS['imp_notify'];
-    }
-
-    /**
      * Determines the HTTP response output type.
      *
      * @see Horde::sendHTTPResponse().
index 259fd1c..8faae81 100644 (file)
@@ -94,7 +94,6 @@ class IMP_Application extends Horde_Registry_Application
      * Global variables defined:
      *   $imp_imap     - An IMP_Imap object
      *   $imp_mbox     - Current mailbox information
-     *   $imp_notify   - A Horde_Notification_Listener object
      *   $imp_search   - An IMP_Search object
      */
     protected function _init()
@@ -115,26 +114,31 @@ class IMP_Application extends Horde_Registry_Application
         // IMP_Search object.
         IMP::setCurrentMailboxInfo();
 
-        $impmode = empty($this->initParams['impmode'])
-            ? 'imp'
-            : $this->initParams['impmode'];
-        $viewmode = IMP::getViewMode();
+        $GLOBALS['notification']->addDecorator(new IMP_Notification_Handler_Decorator_Imap());
+        $GLOBALS['notification']->addType('status', 'imp.*', 'IMP_Notification_Event_Status');
 
-        if ($viewmode == 'mimp') {
-            if ($impmode != 'mimp') {
+        switch (IMP::getViewMode()) {
+        case 'dimp':
+            $GLOBALS['notification']->addType('status', 'dimp.*', 'IMP_Notification_Event_Status');
+            break;
+
+        case 'mimp':
+            if (empty($this->initParams['impmode']) ||
+                ($this->initParams['impmode'] != 'mimp')) {
                 header('Location: ' . IMP_Auth::getInitialPage(true)->setRaw(true));
                 exit;
             }
-            $GLOBALS['imp_notify'] = $GLOBALS['notification']->replace('status', array(), 'IMP_Notification_Listener_StatusMobile');
-        } else {
-            if ($viewmode == 'imp') {
-                $GLOBALS['notification']->attach('audio');
-                if ($impmode == 'dimp') {
-                    header('Location: ' . IMP_Auth::getInitialPage(true)->setRaw(true));
-                    exit;
-                }
+            break;
+
+        case 'imp':
+            if (!empty($this->initParams['impmode']) &&
+                ($this->initParams['impmode'] == 'dimp')) {
+                header('Location: ' . IMP_Auth::getInitialPage(true)->setRaw(true));
+                exit;
             }
-            $GLOBALS['imp_notify'] = $GLOBALS['notification']->replace('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status');
+
+            $GLOBALS['notification']->attach('audio');
+            break;
         }
     }
 
@@ -632,15 +636,6 @@ class IMP_Application extends Horde_Registry_Application
     }
 
     /**
-     * Setup notifications handler for the preferences page. This will only
-     * be called if in dimp view mode.
-     */
-    public function prefsStatus()
-    {
-        $GLOBALS['notification']->replace('status', array('prefs' => true, 'viewmode' => 'dimp'), 'IMP_Notification_Listener_Status');
-    }
-
-    /**
      * TODO
      */
     protected function _prefsSentmailSelect($updated)
index ac40ecd..05effd6 100644 (file)
@@ -474,11 +474,14 @@ class IMP_Auth
                   $conf['cookie']['path'],
                   $conf['cookie']['domain']);
 
-        /* Suppress menus in options screen, and indicate that it should
-         * use the IMP notification listener. */
+        /* Suppress menus in options screen and indicate that notifications
+         * should use the ajax mode. */
         if ($sess['view'] == 'dimp') {
             $_SESSION['horde_prefs']['nomenu'] = true;
-            $_SESSION['horde_prefs']['status'] = 'imp';
+            $_SESSION['horde_notification']['override'] = array(
+                IMP_BASE . '/lib/Notification/Listener/AjaxStatus.php',
+                'IMP_Notification_Listener_AjaxStatus'
+            );
         }
 
         /* Set up search information for the session. */
index 0e97556..176ac22 100644 (file)
@@ -83,21 +83,6 @@ class IMP_Dimp
     }
 
     /**
-     * Return the javascript code necessary to display notification popups.
-     *
-     * @return string  The notification JS code.
-     */
-    static public function notify()
-    {
-        $GLOBALS['notification']->notify(array('listeners' => 'status', 'store' => true));
-        $msgs = $GLOBALS['imp_notify']->getStack();
-
-        return count($msgs)
-            ? 'DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')'
-            : '';
-    }
-
-    /**
      * Return information about the current attachments for a message
      *
      * @param IMP_Compose $imp_compose  An IMP_Compose object.
diff --git a/imp/lib/Notification/Event/Status.php b/imp/lib/Notification/Event/Status.php
new file mode 100644 (file)
index 0000000..2f39cf5
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * This class defines the base IMP status notification types.
+ *
+ * Copyright 2010 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  Michael Slusarz <slusarz@curecanti.org>
+ * @package IMP
+ */
+class IMP_Notification_Event_Status extends Horde_Core_Notification_Status
+{
+    /**
+     * String representation of this object.
+     *
+     * @return string  String representation.
+     */
+    public function __toString()
+    {
+        switch ($this->type) {
+        case 'imp.forward':
+            $img = 'mail_forwarded.png';
+            $label = _("Forward");
+            break;
+
+        case 'imp.redirect':
+            $img = 'mail_forwarded.png';
+            $label = _("Redirect");
+            break;
+
+        case 'imp.reply':
+            $img = 'mail_answered.png';
+            $label = _("Reply");
+            break;
+
+        default:
+            return parent::toString();
+        }
+
+        return Horde::img($img, $label, null, $GLOBALS['registry']->getImageDir('horde')) . parent::toString();
+    }
+
+}
diff --git a/imp/lib/Notification/Handler/Decorator/Imap.php b/imp/lib/Notification/Handler/Decorator/Imap.php
new file mode 100644 (file)
index 0000000..565b257
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * The Imap Decorator adds IMAP alert notifications to the stack.
+ *
+ * Copyright 2010 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  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Notification_Handler_Decorator_Imap
+extends Horde_Notification_Handler_Decorator_Base
+{
+    /**
+     * Listeners are handling their messages.
+     *
+     * @param array $options  An array containing display options for the
+     *                        listeners (see Horde_Notification_Handler for
+     *                        details).
+     */
+    public function notify($options)
+    {
+        if (in_array('status', $options['listeners']) &&
+            ($ob = $GLOBALS['imp_imap']->ob())) {
+            /* Display IMAP alerts. */
+            foreach ($ob->alerts() as $alert) {
+                $GLOBALS['notification']->push($alert, 'horde.warning');
+            }
+        }
+    }
+
+}
diff --git a/imp/lib/Notification/Listener/AjaxStatus.php b/imp/lib/Notification/Listener/AjaxStatus.php
new file mode 100644 (file)
index 0000000..c57d56f
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * The Ajax status class provides a method to display Growler messages using
+ * the DimpCore javascript notification framework.
+ *
+ * Copyright 2010 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  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Notification_Listener_AjaxStatus extends Horde_Notification_Listener_Status
+{
+    /**
+     * Outputs the status line if there are any messages on the 'status'
+     * message stack.
+     *
+     * @param array $events   The list of events to handle.
+     * @param array $options  An array of options:
+     * <pre>
+     * 'mobile' - (Horde_Mobile) The mobile object to send status lines to.
+     * </pre>
+     */
+    public function notify($events, $options = array())
+    {
+        Horde::addInlineScript(array(
+            'var ajax_dc = window.DimpCore || parent.DimpCore',
+            'if (ajax_dc) { ajax_dc.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . ') }'
+        ), 'dom');
+    }
+
+}
diff --git a/imp/lib/Notification/Listener/Status.php b/imp/lib/Notification/Listener/Status.php
deleted file mode 100644 (file)
index 6fa80d7..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?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 IMP
- */
-class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Status
-{
-    /**
-     * Is this the prefs screen?
-     *
-     * @var boolean
-     */
-    protected $_isPrefs = false;
-
-    /**
-     * The view mode.
-     *
-     * @var string
-     */
-    protected $_viewmode;
-
-    /**
-     * Constructor.
-     *
-     * @param array $options  Optional: 'prefs', 'viewmode'.
-     */
-    public function __construct($options = array())
-    {
-        parent::__construct();
-
-        $this->_isPrefs = !empty($options['prefs']);
-        $this->_viewmode = empty($options['viewmode'])
-            ? IMP::getViewMode()
-            : $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())
-    {
-        if ($this->_viewmode == 'dimp') {
-            $options['store'] = true;
-        }
-
-        /* Display IMAP alerts. */
-        if (isset($GLOBALS['imp_imap']->ob)) {
-            foreach ($GLOBALS['imp_imap']->ob()->alerts() as $alert) {
-                $GLOBALS['notification']->push($alert, 'horde.warning');
-            }
-        }
-
-        parent::notify($messageStack, $options);
-
-        /* Preferences display. */
-        if ($this->_isPrefs && ($msgs = $this->getStack())) {
-            Horde::addInlineScript(array(
-                'parent.DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')'
-            ), 'dom');
-        }
-    }
-
-}
diff --git a/imp/lib/Notification/Listener/StatusMobile.php b/imp/lib/Notification/Listener/StatusMobile.php
deleted file mode 100644 (file)
index 24d8638..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * The IMP_Notification_Listener_StatusMobile:: class extends the
- * Horde_Notification_Listener_Mobile:: class to display IMAP alert
- * notifications.
- *
- * Copyright 1999-2010 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  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_Notification_Listener_StatusMobile extends Horde_Notification_Listener_Mobile
-{
-    /**
-     * 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())
-    {
-        /* Display IMAP alerts. */
-        foreach ($GLOBALS['imp_imap']->ob()->alerts() as $alert) {
-            $GLOBALS['notification']->push($alert, 'horde.warning');
-        }
-
-        parent::notify($messageStack, $options);
-    }
-
-}
index b585054..d1d4476 100644 (file)
@@ -32,8 +32,8 @@ $args = array(
 $show_msg = new IMP_Views_ShowMessage();
 $show_msg_result = $show_msg->showMessage($args);
 if (isset($show_msg_result['error'])) {
+    IMP::status();
     echo Horde::wrapInlineScript(array(
-        IMP_Dimp::notify(),
         'parent.close()'
     ));
     exit;
@@ -79,7 +79,6 @@ if (!$disable_compose) {
     $js_onload = $compose_result['jsonload'];
 }
 
-$js_onload[] = IMP_Dimp::notify();
 if (isset($show_msg_result['js'])) {
     $js_onload = array_merge($js_onload, $show_msg_result['js']);
 }
@@ -87,6 +86,7 @@ if (isset($show_msg_result['js'])) {
 Horde::addInlineScript($js_out);
 Horde::addInlineScript(array_filter($js_onload), 'load');
 
+IMP::status();
 IMP_Dimp::header($show_msg_result['title'], $scripts);
 echo "<body>\n";
 require IMP_TEMPLATES . '/chunks/message.php';
index a243971..27fd707 100644 (file)
@@ -367,8 +367,7 @@ $mimp_render->set('title', $display_headers['subject']);
 $c = $mimp_render->add(new Horde_Mobile_card('m', ($status ? $status . ' | ' : '') . $display_headers['subject'] . ' ' . sprintf(_("(%d of %d)"), $msgindex, $msgcount)));
 $c->softkey('#o', _("Menu"));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 $null = null;
 $hb = $c->add(new Horde_Mobile_block($null));
index df9a385..1c93bfb 100644 (file)
@@ -3,8 +3,7 @@
 $c = $mimp_render->add(new Horde_Mobile_card('m', $title));
 $c->softkey('#o', _("Menu"));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 $f = $c->add(new Horde_Mobile_form('compose-mimp.php'));
 
index 0d7ee68..d0eb6b2 100644 (file)
@@ -3,8 +3,7 @@
 $c = &$mimp_render->add(new Horde_Mobile_card('m', $title));
 $c->softkey('#o', _("Menu"));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 $f = &$c->add(new Horde_Mobile_form('compose.php'));
 
index 6cc7265..c8809e6 100644 (file)
@@ -5,8 +5,7 @@ $mimp_render->set('title', $title);
 $c = &$mimp_render->add(new Horde_Mobile_card('m', $title));
 $c->softkey('#o', _("Menu"));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 $null = null;
 $fb = &$c->add(new Horde_Mobile_block($null));
index af7af16..de40e68 100644 (file)
@@ -15,8 +15,7 @@ $mimp_render = new Horde_Mobile();
 $c = &$mimp_render->add(new Horde_Mobile_card('m', $title));
 $c->softkey('#o', _("Menu"));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 if (!empty($pageOb['end'])) {
     $elts = null;
index a7c71a4..775c7d5 100644 (file)
@@ -3,8 +3,7 @@
 $mimp_render = new Horde_Mobile();
 $c = $mimp_render->add(new Horde_Mobile_card('m', sprintf(_("Search %s"), $imp_mbox['mailbox'])));
 
-$imp_notify->setMobileObject($c);
-$notification->notify(array('listeners' => 'status'));
+$notification->notify(array('listeners' => 'status', 'mobile' => $c));
 
 $f = $c->add(new Horde_Mobile_form('mailbox-mimp.php'));
 
index 99ace7c..a978306 100644 (file)
 class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
 {
     /**
-     * Returns a notification handler object to use to output any
-     * notification messages triggered by the action.
+     * Determines if notification information is sent in response.
      *
-     * @return Horde_Notification_Handler_Base   The notification handler.
+     * @var boolean
      */
-    public function notificationHandler()
-    {
-        return $GLOBALS['injector']->getInstance('Horde_Notification_Listener');
-    }
+    public $notify = true;
 
     /**
      * TODO
index 4a5690c..f05ce13 100644 (file)
@@ -54,8 +54,6 @@ class Nag_Application extends Horde_Registry_Application
         $GLOBALS['nag_shares'] = Horde_Share::singleton($GLOBALS['registry']->getApp());
 
         Nag::initialize();
-
-        $GLOBALS['notification']->replace('status', array(), 'Nag_Notification_Listener_Status');
     }
 
     /**
index d40e7a8..89a1abb 100644 (file)
@@ -787,10 +787,10 @@ class Nag
                         $key++;
                     }
                     if ($differential >= -60 && $differential < 60) {
-                        $messages[$key] = array(sprintf(_("%s is due now."), $task->name), 'nag.alarm');
+                        $messages[$key] = array(sprintf(_("%s is due now."), $task->name), 'horde.alarm');
                     } elseif ($differential >= 60) {
                         $messages[$key] = array(sprintf(_("%s is due in %s"), $task->name,
-                                                        Nag::secondsToString($differential)), 'nag.alarm');
+                                                        Nag::secondsToString($differential)), 'horde.alarm');
                     }
                 }
 
diff --git a/nag/lib/Notification/Listener/Status.php b/nag/lib/Notification/Listener/Status.php
deleted file mode 100644 (file)
index 77f707b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * The Nag_Notification_Listener_Status:: class extends the
- * Horde_Notification_Listener_Status:: class to display the messages for
- * Nag's special message type 'nag.alarm'.
- *
- * 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  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Notification
- */
-class Nag_Notification_Listener_Status extends Horde_Notification_Listener_Status
-{
-    /**
-     * Constructor.
-     */
-    public function __construct()
-    {
-        parent::__construct();
-
-        $this->_handles['nag.alarm'] = array($GLOBALS['registry']->getImageDir() . '/alarm.png', _("Alarm"));
-    }
-
-}