From: Jan Schneider Date: Thu, 4 Nov 2010 13:12:41 +0000 (+0100) Subject: Revert "The Desktop handler is not production ready yet." X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a333ae254864f2305b5acc46a7f03f814f2d13bf;p=horde.git Revert "The Desktop handler is not production ready yet." This reverts commit d6c70f7046855dbd3a082ba6f00503d7aed0733e. --- diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php new file mode 100644 index 000000000..e5a867d2b --- /dev/null +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php @@ -0,0 +1,87 @@ + + * @package Horde_Alarm + */ +class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler +{ + /** + * A notification callback. + * + * @var callback + */ + protected $_jsNotify; + + /** + * An icon URL. + * + * @var string + */ + protected $_icon; + + /** + * Constructor. + * + * @param array $params Any parameters that the handler might need. + * Required parameter: + * - js_notify: A Horde_Notification_Handler + * instance. + * Optional parameter: + * - icon: URL of an icon to display. + */ + public function __construct(array $params = null) + { + /* + if (!isset($params['js_notify'])) { + throw new InvalidArgumentException('Parameter \'js_notify\' missing.'); + } + if (!is_callable($params['js_notify'])) { + throw new Horde_Alarm_Exception('Parameter \'js_notify\' is not a Horde_Notification_Handler object.'); + } + $this->_jsNotify = $params['jsNotify']; + if (isset($params['icon'])) { + $this->_icon = $params['icon']; + } + */ + $this->_jsNotify = isset($params['js_notify']) + ? $params['js_notify'] + : array('Horde', 'addInlineScript'); + $this->_icon = isset($params['icon']) ? $params['icon'] : (string)Horde_Themes::img('alerts/alarm.png'); + } + + /** + * Notifies about an alarm through javscript. + * + * @param array $alarm An alarm hash. + */ + public function notify(array $alarm) + { + $js = sprintf('if(window.webkitNotifications&&!window.webkitNotifications.checkPermission())(function(){var notify=window.webkitNotifications.createNotification(\'%s\',\'%s\',\'%s\');notify.show();(function(){notify.cancel()}).delay(5)})()', + $this->_icon, + addslashes($alarm['title']), + isset($alarm['text']) ? addslashes($alarm['text']) : ''); + call_user_func($this->_jsNotify($js)); + } + + /** + * Returns a human readable description of the handler. + * + * @return string + */ + public function getDescription() + { + return _("Desktop notification (with certain browsers)"); + } +}