From: Jan Schneider Date: Fri, 7 May 2010 17:20:55 +0000 (+0200) Subject: Add basic alarm handler for webkit notifications. Doesn't really work yet X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e202756fcca5d9e6773e20419a48d7c27c5e4151;p=horde.git Add basic alarm handler for webkit notifications. Doesn't really work yet because: - javascript notifications are broken - permission dialogs are only displayed after onclick events. --- 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..d7a7f247f --- /dev/null +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php @@ -0,0 +1,85 @@ + + * @package Horde_Alarm + */ +class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler +{ + /** + * A notification handler. + * + * @var Horde_Notification_Handler + */ + protected $_notification; + + /** + * An icon URL. + * + * @var string + */ + protected $_icon; + + /** + * Constructor. + * + * @param array $params Any parameters that the handler might need. + * Required parameter: + * - notification: A Horde_Notification_Handler + * instance. + * Optional parameter: + * - icon: URL of an icon to display. + */ + 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']; + if (isset($params['icon'])) { + $this->_icon = $param['icon']; + } + */ + $this->_notification = $GLOBALS['injector']->getInstance('Horde_Notification'); + $this->_icon = (string)Horde_Themes::img('alerts/alarm.png'); + } + + /** + * Notifies about an alarm through Horde_Notification. + * + * @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']) : ''); + $this->_notification->push($js, 'javascript'); + } + + /** + * Returns a human readable description of the handler. + * + * @return string + */ + public function getDescription() + { + return _("Desktop notification (with certain browsers)"); + } +}