/usr/share/php/Horde/Alarm/Handler/Desktop.php is in php-horde-alarm 2.2.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | <?php
/**
* Copyright 2010-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Alarm
*/
/**
* The Horde_Alarm_Handler_Desktop class is a Horde_Alarm handler that notifies
* of active alarms by desktop notification through webkit browsers.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package 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 valid callback.');
}
$this->_jsNotify = $params['js_notify'];
if (isset($params['icon'])) {
$this->_icon = $params['icon'];
}
}
/**
* Notifies about an alarm through javascript.
*
* @param array $alarm An alarm hash.
*/
public function notify(array $alarm)
{
$js = sprintf('if(window.webkitNotifications)(function(){function show(){switch(window.webkitNotifications.checkPermission()){case 0:var notify=window.webkitNotifications.createNotification("%s",%s,%s);notify.show();(function(){notify.cancel()}).delay(5);break;case 1:window.webkitNotifications.requestPermission(function(){});break}}show()})()',
$this->_icon,
Horde_Serialize::serialize($alarm['title'], Horde_Serialize::JSON),
isset($alarm['text']) ? Horde_Serialize::serialize($alarm['text'], Horde_Serialize::JSON) : "''");
call_user_func($this->_jsNotify, $js);
}
/**
* Returns a human readable description of the handler.
*
* @return string
*/
public function getDescription()
{
return Horde_Alarm_Translation::t("Desktop notification (with certain browsers)");
}
}
|