From 75e7b21e9459391e5785427ca2aa24b63ae2e35c Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 7 May 2010 17:46:10 +0200 Subject: [PATCH] Refactor alarm handlers. They have been split out into separate classes, are unit tested, and new handlers can be dropped in. --- framework/Alarm/lib/Horde/Alarm.php | 141 ++++++--------------- framework/Alarm/lib/Horde/Alarm/Handler.php | 64 ++++++++++ framework/Alarm/lib/Horde/Alarm/Handler/Mail.php | 137 ++++++++++++++++++++ framework/Alarm/lib/Horde/Alarm/Handler/Notify.php | 102 +++++++++++++++ framework/Alarm/package.xml | 77 +++++++++-- framework/Alarm/test/Horde/Alarm/HandlerTest.php | 106 ++++++++++++++++ framework/Core/lib/Horde/Core/Binder/Alarm.php | 18 ++- framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php | 106 +++++++--------- horde/admin/alarms.php | 16 +-- kronolith/index.php | 10 +- 10 files changed, 589 insertions(+), 188 deletions(-) create mode 100644 framework/Alarm/lib/Horde/Alarm/Handler.php create mode 100644 framework/Alarm/lib/Horde/Alarm/Handler/Mail.php create mode 100644 framework/Alarm/lib/Horde/Alarm/Handler/Notify.php create mode 100644 framework/Alarm/test/Horde/Alarm/HandlerTest.php diff --git a/framework/Alarm/lib/Horde/Alarm.php b/framework/Alarm/lib/Horde/Alarm.php index e7d95187a..eac253321 100644 --- a/framework/Alarm/lib/Horde/Alarm.php +++ b/framework/Alarm/lib/Horde/Alarm.php @@ -34,6 +34,20 @@ abstract class Horde_Alarm ); /** + * All registered notification handlers. + * + * @var array + */ + protected $_handlers = array(); + + /** + * Whether handler classes have been dynamically loaded already. + * + * @var boolean + */ + protected $_handlersLoaded = false; + + /** * Attempts to return a concrete instance based on $driver. * * @param string $driver The type of concrete subclass to @@ -444,91 +458,31 @@ abstract class Horde_Alarm return; } - $methods = array_keys($this->notificationMethods()); + $handlers = $this->handlers(); foreach ($alarms as $alarm) { foreach ($alarm['methods'] as $alarm_method) { - if (in_array($alarm_method, $methods) && + if (isset($handlers[$alarm_method]) && !in_array($alarm_method, $exclude)) { - try { - $this->{'_' . $alarm_method}($alarm); - } catch (Horde_Alarm_Exception $e) { - if ($this->_logger) { - $this->_logger->log($e, 'ERR'); - } - } + $handlers[$alarm_method]->notify($alarm); } } } } /** - * Notifies about an alarm through Horde_Notification. + * Registers a notification handler. * - * @param array $alarm An alarm hash. + * @param string $name A handler name. + * @param Horde_Alarm_Handler $handler A notification handler. */ - protected function _notify(array $alarm) + public function addHandler($name, Horde_Alarm_Handler $handler) { - static $sound_played; - - $GLOBALS['notification']->push($alarm['title'], 'horde.alarm', array('alarm' => $alarm)); - if (!empty($alarm['params']['notify']['sound']) && - !isset($sound_played[$alarm['params']['notify']['sound']])) { - $GLOBALS['notification']->attach('audio'); - $GLOBALS['notification']->push($alarm['params']['notify']['sound'], 'audio'); - $sound_played[$alarm['params']['notify']['sound']] = true; - } + $this->_handlers[$name] = $handler; + $handler->alarm = $this; } /** - * Notifies about an alarm by email. - * - * @param array $alarm An alarm hash. - * - * @throws Horde_Mime_Exception - * @throws Horde_Alarm_Exception - */ - protected function _mail(array $alarm) - { - if (!empty($alarm['internal']['mail']['sent'])) { - return; - } - - if (empty($alarm['params']['mail']['email'])) { - if (empty($alarm['user'])) { - return; - } - $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity($alarm['user']); - $email = $identity->getDefaultFromAddress(true); - } else { - $email = $alarm['params']['mail']['email']; - } - - $mail = new Horde_Mime_Mail(array( - 'subject' => $alarm['title'], - 'body' => empty($alarm['params']['mail']['body']) ? $alarm['text'] : $alarm['params']['mail']['body'], - 'to' => $email, - 'from' => $email, - 'charset' => Horde_Nls::getCharset() - )); - $mail->addHeader('Auto-Submitted', 'auto-generated'); - $mail->addHeader('X-Horde-Alarm', $alarm['title'], Horde_Nls::getCharset()); - $mail->send($GLOBALS['injector']->getInstance('Mail')); - - $alarm['internal']['mail']['sent'] = true; - $this->_internal($alarm['id'], $alarm['user'], $alarm['internal']); - } - - /** - * Notifies about an alarm with an SMS through the sms/send API method. - * - * @param array $alarm An alarm hash. - */ - protected function _sms(array $alarm) - { - } - - /** - * Returns a list of available notification methods and method parameters. + * Returns a list of available notification handlers and parameters. * * The returned list is a hash with method names as the keys and * optionally associated parameters as values. The parameters are hashes @@ -539,40 +493,27 @@ abstract class Horde_Alarm * * @return array List of methods and parameters. */ - public function notificationMethods() + public function handlers() { - static $methods; - - if (!isset($methods)) { - $methods = array( - 'notify' => array( - '__desc' => _("Inline"), - 'sound' => array( - 'type' => 'sound', - 'desc' => _("Play a sound?"), - 'required' => false - ) - ), - 'mail' => array( - '__desc' => _("Email"), - 'email' => array( - 'type' => 'text', - 'desc' => _("Email address (optional)"), - 'required' => false - ) - ) - ); - /* - if ($GLOBALS['registry']->hasMethod('sms/send')) { - $methods['sms'] = array( - 'phone' => array('type' => 'text', - 'desc' => _("Cell phone number"), - 'required' => true)); + if (!$this->_handlersLoaded) { + foreach (new GlobIterator(dirname(__FILE__) . '/Alarm/Handler/*.php') as $file) { + if (!$file->isFile()) { + continue; + } + $handler = Horde_String::lower($file->getBasename('.php')); + if (isset($this->_handlers[$handler])) { + continue; + } + require_once $file->getPathname(); + $class = 'Horde_Alarm_Handler_' . $file->getBasename('.php'); + if (class_exists($class, false)) { + $this->addHandler($handler, new $class()); + } } - */ + $this->_handlerLoaded = true; } - return $methods; + return $this->_handlers; } /** diff --git a/framework/Alarm/lib/Horde/Alarm/Handler.php b/framework/Alarm/lib/Horde/Alarm/Handler.php new file mode 100644 index 000000000..ecf52c1a4 --- /dev/null +++ b/framework/Alarm/lib/Horde/Alarm/Handler.php @@ -0,0 +1,64 @@ + + * @package Horde_Alarm + */ +abstract class Horde_Alarm_Handler +{ + /** + * The alarm object to that this handler is attached. + * + * Horde_Alarm + */ + public $alarm; + + /** + * Constructor. + * + * @param array $params Any parameters that the handler might need. + */ + abstract public function __construct(array $params = null); + + /** + * Notifies about an alarm. + * + * @param array $alarm An alarm hash. + */ + abstract public function notify(array $alarm); + + /** + * Returns a human readable description of the handler. + * + * @return string + */ + abstract public function getDescription(); + + /** + * Returns a hash of user-configurable parameters for the handler. + * + * The parameters are hashes with parameter names as keys and parameter + * information as values. The parameter information is a hash with the + * following keys: + * - type: the parameter type as a preference type. + * - desc: a parameter description. + * - required: whether this parameter is required. + * + * @return array + */ + public function getParameters() + { + return array(); + } +} diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php b/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php new file mode 100644 index 000000000..bff6ef80d --- /dev/null +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php @@ -0,0 +1,137 @@ + + * @package Horde_Alarm + */ +class Horde_Alarm_Handler_Mail extends Horde_Alarm_Handler +{ + /** + * An identity factory. + * + * @var Horde_Core_Factory_Identity + */ + protected $_identity; + + /** + * A Mail object. + * + * @var Mail + */ + protected $_mail; + + /** + * The message charset. + * + * @var string + */ + protected $_charset; + + /** + * Constructor. + * + * @param array $params Any parameters that the handler might need. + * Required parameter: + * - identity: An identity factory that implements + * getIdentity(). + * - mail: A PEAR Mail instance. + * - charset: The charset of the messages. + */ + public function __construct(array $params = null) + { + foreach (array('identity', 'mail', 'charset') as $param) { + if (!isset($params[$param])) { + throw new Horde_Alarm_Exception('Parameter \'' . $param . '\' missing.'); + } + } + if (!method_exists($params['identity'], 'getIdentity')) { + throw new Horde_Alarm_Exception('Parameter \'identity\' does not implement getIdentity().'); + } + $r = new ReflectionObject($params['mail']); + if (!($params['mail'] instanceof Mail)) { + throw new Horde_Alarm_Exception('Parameter \'mail\' is not a Mail object.'); + } + $this->_identity = $params['identity']; + $this->_mail = $params['mail']; + $this->_charset = $params['charset']; + } + + /** + * Notifies about an alarm by e-mail. + * + * @param array $alarm An alarm hash. + */ + public function notify(array $alarm) + { + if (!empty($alarm['internal']['mail']['sent'])) { + return; + } + + if (empty($alarm['params']['mail']['email'])) { + if (empty($alarm['user'])) { + return; + } + $email = $this->_identity + ->getIdentity($alarm['user']) + ->getDefaultFromAddress(true); + } else { + $email = $alarm['params']['mail']['email']; + } + + $mail = new Horde_Mime_Mail(array( + 'subject' => $alarm['title'], + 'body' => empty($alarm['params']['mail']['body']) ? $alarm['text'] : $alarm['params']['mail']['body'], + 'to' => $email, + 'from' => $email, + 'charset' => $this->_charset + )); + $mail->addHeader('Auto-Submitted', 'auto-generated'); + $mail->addHeader('X-Horde-Alarm', $alarm['title'], $this->_charset); + $mail->send($this->_mail); + + $alarm['internal']['mail']['sent'] = true; + $this->alarm->internal($alarm['id'], $alarm['user'], $alarm['internal']); + } + + /** + * Returns a human readable description of the handler. + * + * @return string + */ + public function getDescription() + { + return _("Email"); + } + + /** + * Returns a hash of user-configurable parameters for the handler. + * + * The parameters are hashes with parameter names as keys and parameter + * information as values. The parameter information is a hash with the + * following keys: + * - type: the parameter type as a preference type. + * - desc: a parameter description. + * - required: whether this parameter is required. + * + * @return array + */ + public function getParameters() + { + return array( + 'email' => array( + 'type' => 'text', + 'desc' => _("Email address (optional)"), + 'required' => false)); + } +} diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php b/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php new file mode 100644 index 000000000..d2470ad25 --- /dev/null +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php @@ -0,0 +1,102 @@ + + * @package Horde_Alarm + */ +class Horde_Alarm_Handler_Notify extends Horde_Alarm_Handler +{ + /** + * A notification handler. + * + * @var Horde_Notification_Handler + */ + protected $_notification; + + /** + * Whether a sound already had been played during the page request. + * + * @var boolean + */ + protected $_soundPlayed = false; + + /** + * Constructor. + * + * @param array $params Any parameters that the handler might need. + * Required parameter: + * - notification: A Horde_Notification_Handler + * instance. + */ + public function __construct(array $params = null) + { + /* + if (!isset($params['notification'])) { + throw new Horde_Alarm_Exception('Parameter \'notification\' missing.'); + } + if (!($params['notification'] instanceof Horde_Notification_Handler)) { + throw new Horde_Alarm_Exception('Parameter \'notification\' is not a Horde_Notification_Handler object.'); + } + $this->_notification = $params['notification']; + */ + $this->_notification = $GLOBALS['injector']->getInstance('Horde_Notification'); + } + + /** + * Notifies about an alarm through Horde_Notification. + * + * @param array $alarm An alarm hash. + */ + public function notify(array $alarm) + { + $this->_notification->push($alarm['title'], 'horde.alarm', array('alarm' => $alarm)); + if (!empty($alarm['params']['notify']['sound']) && + !isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) { + $this->_notification->attach('audio'); + $this->_notification->push($alarm['params']['notify']['sound'], 'audio'); + $this->_soundPlayed[$alarm['params']['notify']['sound']] = true; + } + } + + /** + * Returns a human readable description of the handler. + * + * @return string + */ + public function getDescription() + { + return _("Inline"); + } + + /** + * Returns a hash of user-configurable parameters for the handler. + * + * The parameters are hashes with parameter names as keys and parameter + * information as values. The parameter information is a hash with the + * following keys: + * - type: the parameter type as a preference type. + * - desc: a parameter description. + * - required: whether this parameter is required. + * + * @return array + */ + public function getParameters() + { + return array( + 'sound' => array( + 'type' => 'sound', + 'desc' => _("Play a sound?"), + 'required' => false)); + } +} diff --git a/framework/Alarm/package.xml b/framework/Alarm/package.xml index ad2bd3935..1f5d5b4f3 100644 --- a/framework/Alarm/package.xml +++ b/framework/Alarm/package.xml @@ -1,8 +1,5 @@ - + Alarm pear.horde.org Horde alarm libraries @@ -16,7 +13,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> jan@horde.org yes - 2009-02-11 + 2010-05-07 + 0.2.0 0.2.0 @@ -26,13 +24,20 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial Horde 4 package. + +* Initial Horde 4 package. + - + + + + + + @@ -40,12 +45,18 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + - + + + + @@ -74,18 +85,39 @@ http://pear.php.net/dtd/package-2.0.xsd"> + Mime + pear.horde.org + + + Notification + pear.horde.org + + Log pear.horde.org + + Prefs + pear.horde.org + - - - - - + + + + + + + + + + + + + + @@ -100,7 +132,24 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial release. + +* Initial release. + + + + + 0.2.0 + 0.2.0 + + + beta + beta + + 2010-05-07 + LGPL + +* Initial Horde 4 package. + diff --git a/framework/Alarm/test/Horde/Alarm/HandlerTest.php b/framework/Alarm/test/Horde/Alarm/HandlerTest.php new file mode 100644 index 000000000..979059290 --- /dev/null +++ b/framework/Alarm/test/Horde/Alarm/HandlerTest.php @@ -0,0 +1,106 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @category Horde + * @package Horde_Alarm + * @subpackage UnitTests + */ + +class Horde_Alarm_HandlerTest extends PHPUnit_Framework_TestCase +{ + protected static $alarm; + + public function setUp() + { + if (!class_exists('Horde_Notification')) { + $this->markTestSkipped('Horde_Notification not installed'); + return; + } + self::$alarm = Horde_Alarm::factory('Object'); + $now = time(); + $hash = array('id' => 'personalalarm', + 'user' => 'john', + 'start' => new Horde_Date($now), + 'end' => new Horde_Date($now + 3600), + 'methods' => array(), + 'params' => array(), + 'title' => 'This is a personal alarm.', + 'text' => 'Action is required.'); + self::$alarm->set($hash); + } + + public function testNotification() + { + $alarm = self::$alarm->get('personalalarm', 'john'); + $alarm['methods'] = array('notification'); + self::$alarm->set($alarm); + $storage = new Horde_Notification_Storage_Object(); + $handler = new Horde_Alarm_Handler_Notification(array('notification' => new Horde_Notification_Handler($storage))); + self::$alarm->addHandler('notification', $handler); + self::$alarm->notify('john', false); + + $this->assertEquals(1, count($storage->notifications['_unattached'])); + $this->assertEquals('This is a personal alarm.', $storage->notifications['_unattached'][0]->message); + $this->assertEquals('horde.alarm', $storage->notifications['_unattached'][0]->type); + } + + public function testMail() + { + $alarm = self::$alarm->get('personalalarm', 'john'); + $alarm['methods'] = array('mail'); + self::$alarm->set($alarm); + $mail = new Horde_Alarm_HandlerTest_Mail(); + $factory = new Horde_Alarm_HandlerTest_IdentityFactory(); + $handler = new Horde_Alarm_Handler_Mail(array('mail' => $mail, 'identity' => $factory, 'charset' => 'us-ascii')); + self::$alarm->addHandler('mail', $handler); + self::$alarm->notify('john', false); + $regexp = << +User-Agent: Horde Application Framework 4 +Date: \w{3}, \d\d \w{3} \d{4} \d\d:\d\d:\d\d [+-]\d{4} +Content-Type: text\/plain; charset=us-ascii; format=flowed; DelSp=Yes +MIME-Version: 1\.0 + +Action is required\. + +EOR; + + $this->assertRegExp('/' . trim(str_replace("\r\n", "\n", $regexp)) . '/', trim(str_replace("\r\n", "\n", $mail->sentOutput))); + $mail->sentOutput = null; + self::$alarm->notify('john', false); + $this->assertNull($mail->sentOutput); + } +} + +class Horde_Alarm_HandlerTest_IdentityFactory +{ + public function getIdentity() + { + return new Horde_Alarm_HandlerTest_Identity(); + } +} + +class Horde_Alarm_HandlerTest_Identity +{ + public function getDefaultFromAddress() + { + return 'john@example.com'; + } +} + +class Horde_Alarm_HandlerTest_Mail extends Mail +{ + public $sentOutput; + + public function send($recipients, $headers, $body) + { + list(, $textHeaders) = Mail::prepareHeaders($headers); + $this->sentOutput = $textHeaders . "\n\n" . $body; + } +} diff --git a/framework/Core/lib/Horde/Core/Binder/Alarm.php b/framework/Core/lib/Horde/Core/Binder/Alarm.php index 3e36c1d09..658cba8af 100644 --- a/framework/Core/lib/Horde/Core/Binder/Alarm.php +++ b/framework/Core/lib/Horde/Core/Binder/Alarm.php @@ -13,10 +13,24 @@ class Horde_Core_Binder_Alarm implements Horde_Injector_Binder $driver = $GLOBALS['conf']['alarms']['driver']; $params = Horde::getDriverConfig('alarms', $driver); } - $params['logger'] = $injector->getInstance('Horde_Log_Logger'); - return Horde_Alarm::factory($driver, $params); + $alarm = Horde_Alarm::factory($driver, $params); + + /* Add those handlers that need configuration and can't be auto-loaded + * through Horde_Alarms::handlers(). */ + /* + $handler_params = array( + 'notification' => $injector->getInstance('Horde_Notification')); + $alarm->addHandler('notify', new Horde_Alarm_Handler_Notification($handler_params)); + */ + $handler_params = array( + 'identity' => $injector->getInstance('Horde_Prefs_Identity'), + 'mail' => $injector->getInstance('Mail'), + 'charset' => Horde_Nls::getCharset()); + $alarm->addHandler('mail', new Horde_Alarm_Handler_Mail($handler_params)); + + return $alarm; } public function equals(Horde_Injector_Binder $binder) diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index 41f9203fe..bce7bb04f 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -294,68 +294,62 @@ class Horde_Core_Prefs_Ui_Widgets $param_list = $select_list = array(); - foreach (Horde_Alarm::notificationMethods() as $method => $params) { + foreach ($GLOBALS['injector']->getInstance('Horde_Alarm')->handlers() as $method => $handler) { $select_list[] = array( - 'l' => $params['__desc'], + 'l' => $handler->getDescription(), 's' => in_array($method, $selected), 'v' => $method ); - if (count($params > 1)) { - $tmp = array( - 'method' => $method, - 'param' => array() - ); - - foreach ($params as $name => $param) { - if (substr($name, 0, 2) == '__') { - continue; - } + $tmp = array( + 'method' => $method, + 'param' => array() + ); - switch ($param['type']) { - case 'text': - $tmp['param'][] = array( - 'label' => Horde::label($pref . '_' . $name, $param['desc']), - 'name' => $pref . '_' . $name, - 'text' => true, - 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name]) - ); - break; - - case 'bool': - $tmp['param'][] = array( - 'bool' => true, - 'checked' => !empty($alarm_pref[$method][$name]), - 'label' => Horde::label($pref . '_' . $name, $param['desc']), - 'name' => $pref . '_' . $name + foreach ($handler->getParameters() as $name => $param) { + switch ($param['type']) { + case 'text': + $tmp['param'][] = array( + 'label' => Horde::label($pref . '_' . $name, $param['desc']), + 'name' => $pref . '_' . $name, + 'text' => true, + 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name]) ); - break; - - case 'sound': - $current_sound = empty($alarm_pref[$method][$name]) - ? '' - : $alarm_pref[$method][$name]; - $sounds = array(); - foreach (Horde_Themes::soundList() as $key => $val) { - $sounds[] = array( - 'c' => ($current_sound == $key), - 'uri' => htmlspecialchars($val->uri), - 'val' => htmlspecialchars($key) - ); - } - $t->set('sounds', $sounds); - - $tmp['param'][] = array( - 'sound' => true, - 'checked' => !$current_sound, - 'name' => $pref . '_' . $name + break; + + case 'bool': + $tmp['param'][] = array( + 'bool' => true, + 'checked' => !empty($alarm_pref[$method][$name]), + 'label' => Horde::label($pref . '_' . $name, $param['desc']), + 'name' => $pref . '_' . $name + ); + break; + + case 'sound': + $current_sound = empty($alarm_pref[$method][$name]) + ? '' + : $alarm_pref[$method][$name]; + $sounds = array(); + foreach (Horde_Themes::soundList() as $key => $val) { + $sounds[] = array( + 'c' => ($current_sound == $key), + 'uri' => htmlspecialchars($val->uri), + 'val' => htmlspecialchars($key) ); - break; } + $t->set('sounds', $sounds); + + $tmp['param'][] = array( + 'sound' => true, + 'checked' => !$current_sound, + 'name' => $pref . '_' . $name + ); + break; } - - $param_list[] = $tmp; } + + $param_list[] = $tmp; } $t->set('desc', Horde::label($pref, $data['label'])); @@ -383,7 +377,7 @@ class Horde_Core_Prefs_Ui_Widgets static public function alarmUpdate($ui, $data) { $pref = $data['pref']; - $methods = Horde_Alarm::notificationMethods(); + $methods = $GLOBALS['injector']->getInstance('Horde_Alarm')->handlers(); $val = (isset($ui->vars->$pref) && is_array($ui->vars->$pref)) ? $ui->vars->$pref : array(); @@ -392,12 +386,10 @@ class Horde_Core_Prefs_Ui_Widgets foreach ($val as $method) { $value[$method] = array(); if (!empty($methods[$method])) { - foreach (array_keys($methods[$method]) as $param) { + foreach ($methods[$method]->getParameters() as $param => $info) { $value[$method][$param] = $ui->vars->get($pref . '_' . $param, ''); - if (is_array($methods[$method][$param]) && - $methods[$method][$param]['required'] && - ($value[$method][$param] === '')) { - $GLOBALS['notification']->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method][$param]['desc']), 'horde.error'); + if ($info['required'] && ($value[$method][$param] === '')) { + $GLOBALS['notification']->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method]->getDescription()), 'horde.error'); return null; } } diff --git a/horde/admin/alarms.php b/horde/admin/alarms.php index 865274d39..ebd5446b2 100644 --- a/horde/admin/alarms.php +++ b/horde/admin/alarms.php @@ -13,8 +13,8 @@ Horde_Registry::appInit('horde', array('admin' => true)); $horde_alarm = $injector->getInstance('Horde_Alarm'); $methods = array(); -foreach ($horde_alarm->notificationMethods() as $name => $method) { - $methods[$name] = $method['__desc']; +foreach ($horde_alarm->handlers() as $name => $method) { + $methods[$name] = $method->getDescription(); } $vars = Horde_Variables::getDefaultVariables(); @@ -26,15 +26,13 @@ $form->addVariable(_("Alarm start"), 'start', 'datetime', true); $form->addVariable(_("Alarm end"), 'end', 'datetime', false); $form->addVariable(_("Alarm text"), 'text', 'longtext', false); $form->addVariable(_("Alarm methods"), 'methods', 'multienum', true, false, null, array($methods, min(5, count($methods)))); -foreach ($horde_alarm->notificationMethods() as $name => $method) { - if (count($method) < 2) { +foreach ($horde_alarm->handlers() as $name => $method) { + $params = $method->getParameters(); + if (!count($params)) { continue; } - $form->addVariable($method['__desc'], '', 'header', false); - foreach ($method as $param => $param_info) { - if (substr($param, 0, 2) == '__') { - continue; - } + $form->addVariable($method->getDescription(), '', 'header', false); + foreach ($params as $param => $param_info) { $form->addVariable($param_info['desc'], $name . '_' . $param, $param_info['type'], false); } } diff --git a/kronolith/index.php b/kronolith/index.php index 7951b131a..4213a2fd2 100644 --- a/kronolith/index.php +++ b/kronolith/index.php @@ -37,16 +37,14 @@ $_SESSION['horde_notification']['override'] = array( ); $alarm_methods = $alarm_params = ''; -foreach (Horde_Alarm::notificationMethods() as $method => $params) { - $alarm_methods .= ' '; - if (count($params) < 2) { +foreach ($injector->getInstance('Horde_Alarm')->handlers() as $method => $handler) { + $alarm_methods .= ' '; + $params = $handler->getParameters(); + if (!count($params)) { continue; } $alarm_params .= '