Skip to content

Commit

Permalink
[mms] Refactor alarm code to prevent the need from accessing the them…
Browse files Browse the repository at this point in the history
…es cache on every server access.
  • Loading branch information
slusarz committed Jan 22, 2014
1 parent 3803a8e commit 94230bf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
8 changes: 6 additions & 2 deletions framework/Core/lib/Horde/Core/Alarm/Handler/Desktop.php
Expand Up @@ -40,6 +40,8 @@ class Horde_Core_Alarm_Handler_Desktop extends Horde_Alarm_Handler
* instance.
* Optional parameter:
* - icon: URL of an icon to display.
* @todo Change this to be dynamically generated
* when needed.
*/
public function __construct(array $params = null)
{
Expand Down Expand Up @@ -67,14 +69,16 @@ public function notify(array $alarm)
{
global $notification;

$icon = strval($this->_icon);

if ($GLOBALS['registry']->getView() == Horde_Registry::VIEW_DYNAMIC) {
$alarm['params']['desktop']['icon'] = $this->_icon;
$alarm['params']['desktop']['icon'] = $icon;
$notification->push($alarm['title'], 'horde.alarm', array(
'alarm' => $alarm
));
} else {
$js = sprintf('if(window.Notification){if (window.Notification.permission != "granted") {window.Notification.requestPermission(function(){if (window.Notification.permission == "granted") { new window.Notification("%s", {body: "%s", icon: "%s" }); } }) } else { new window.Notification("%s", {body: "%s", icon: "%s" }); } };',
$alarm['title'], $alarm['params']['desktop']['subtitle'], $this->_icon, $alarm['title'], $alarm['params']['desktop']['subtitle'], $this->_icon);
$alarm['title'], $alarm['params']['desktop']['subtitle'], $icon, $alarm['title'], $alarm['params']['desktop']['subtitle'], $icon);
call_user_func($this->_jsNotify, $js);
}
}
Expand Down
51 changes: 51 additions & 0 deletions framework/Core/lib/Horde/Core/Alarm/Handler/Desktop/Icon.php
@@ -0,0 +1,51 @@
<?php
/**
* Copyright 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.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/

/**
* Hack to prevent the need to access the theme cache on every server access.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @internal
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
* @todo Refactor Horde_Core_Alarm_Handler_Desktop to avoid this
*/
class Horde_Core_Alarm_Handler_Desktop_Icon
{
/**
* Icon path.
*
* @var string
*/
protected $_path;

/**
* Constructor.
*
* @param string $path Icon path.
*/
public function __construct($path)
{
$this->_path = $path;
}

/**
*/
public function __toString()
{
return strval(Horde_Themes::img($this->_path)->fulluri);
}

}
2 changes: 1 addition & 1 deletion framework/Core/lib/Horde/Core/Factory/Alarm.php
Expand Up @@ -88,7 +88,7 @@ public function create()
$this->_alarm->addHandler(
'desktop',
new Horde_Core_Alarm_Handler_Desktop(array(
'icon' => strval(Horde_Themes::img('alerts/alarm.png')->fulluri),
'icon' => new Horde_Core_Alarm_Handler_Desktop_Icon('alerts/alarm.png'),
'js_notify' => array(
$this->_injector->getInstance('Horde_PageOutput'),
'addInlineScript'
Expand Down
10 changes: 8 additions & 2 deletions framework/Core/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>mrubinsk@horde.org</email>
<active>yes</active>
</developer>
<date>2013-12-07</date>
<date>2014-01-22</date>
<version>
<release>2.12.0</release>
<api>2.12.0</api>
Expand All @@ -39,6 +39,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Refactor alarm code to prevent the need from accessing the themes cache on every server access.
* [mms] Prevent avalanche effect from occurring when re-creating cached JS files.
* [mms] Use Horde_JavascriptMinify package to compress javascript.
* [mms] Combine all javscript to compress into a single string.
Expand Down Expand Up @@ -363,6 +364,9 @@
</dir> <!-- /lib/Horde/Core/Ajax -->
<dir name="Alarm">
<dir name="Handler">
<dir name="Desktop">
<file name="Icon.php" role="php" />
</dir> <!-- /lib/Horde/Core/Alarm/Handler/Desktop -->
<file name="Desktop.php" role="php" />
<file name="Notify.php" role="php" />
</dir> <!-- /lib/Horde/Core/Alarm/Handler -->
Expand Down Expand Up @@ -1737,6 +1741,7 @@
<install as="Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php" name="lib/Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php" />
<install as="Horde/Core/Alarm/Handler/Desktop.php" name="lib/Horde/Core/Alarm/Handler/Desktop.php" />
<install as="Horde/Core/Alarm/Handler/Notify.php" name="lib/Horde/Core/Alarm/Handler/Notify.php" />
<install as="Horde/Core/Alarm/Handler/Desktop/Icon.php" name="lib/Horde/Core/Alarm/Handler/Desktop/Icon.php" />
<install as="Horde/Core/Auth/Application.php" name="lib/Horde/Core/Auth/Application.php" />
<install as="Horde/Core/Auth/Composite.php" name="lib/Horde/Core/Auth/Composite.php" />
<install as="Horde/Core/Auth/Imsp.php" name="lib/Horde/Core/Auth/Imsp.php" />
Expand Down Expand Up @@ -3283,9 +3288,10 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2013-12-07</date>
<date>2014-01-22</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Refactor alarm code to prevent the need from accessing the themes cache on every server access.
* [mms] Prevent avalanche effect from occurring when re-creating cached JS files.
* [mms] Use Horde_JavascriptMinify package to compress javascript.
* [mms] Combine all javscript to compress into a single string.
Expand Down

0 comments on commit 94230bf

Please sign in to comment.