-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue: No update notification for comfort update users
- Loading branch information
1 parent
c2bd269
commit 7804ea5
Showing
7 changed files
with
211 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
application/core/plugins/ComfortUpdateChecker/ComfortUpdateChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
/* | ||
* Update Checker for Comfort Update users | ||
* Copyright (C) LimeSurvey GmbH | ||
* License: GNU/GPL License v2 http://www.gnu.org/licenses/gpl-2.0.html | ||
* A plugin of LimeSurvey, a free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
* other free or open source software licenses. | ||
*/ | ||
|
||
define('ROOT_FOLDER', __DIR__ . '/'); | ||
|
||
//loads libraries | ||
require_once(ROOT_FOLDER . 'helpers/CUCMenuClass.php'); | ||
|
||
|
||
class ComfortUpdateChecker extends PluginBase | ||
{ | ||
|
||
protected $storage = 'DbStorage'; | ||
|
||
static protected $description = 'Update Checker for Comfort Update users'; | ||
|
||
static protected $name = 'ComfortUpdateChecker'; | ||
|
||
protected $settings = [ | ||
|
||
'only_security_update' => array( | ||
'type' => 'checkbox', | ||
'label' => 'Notification only for security updates', | ||
'default' => false, | ||
), | ||
|
||
'animate_icon' => array( | ||
'type' => 'checkbox', | ||
'label' => 'Animate update icon', | ||
'default' => false, | ||
), | ||
|
||
]; | ||
|
||
|
||
public function init() | ||
{ | ||
|
||
$this->subscribe('beforeAdminMenuRender'); | ||
} | ||
|
||
/** | ||
* Append new menu item to the admin topbar | ||
* | ||
* @return void | ||
*/ | ||
public function beforeAdminMenuRender() | ||
{ | ||
$oEvent = $this->getEvent(); | ||
|
||
//Register css and js script | ||
$this->registerAssets(); | ||
|
||
$update = (array)$this->getUpdate(); | ||
|
||
if ($update['result']) { | ||
|
||
//Default icon class | ||
$iconClass = ""; | ||
$NotificationText = gT("Update available"); | ||
|
||
if ($update[key($update)]->security_update) { | ||
$NotificationText = gT("Security update available"); | ||
} | ||
//Append cu-checker class to icon when animate option is true in plugin settings | ||
if ($this->get('animate_icon', null, null, false)) { | ||
$iconClass = "cu-checker"; | ||
} | ||
|
||
//Display update notification only for superadmin user | ||
if (Permission::model()->hasGlobalPermission('superadmin')) { | ||
$aMenuItemAdminOptions = [ | ||
'isDivider' => false, | ||
'isSmallText' => false, | ||
'label' => '<strong class="text-warning">' . $NotificationText . '</strong>', | ||
'href' => $this->api->createUrl('admin/update', []), | ||
'iconClass' => 'icon-shield text-warning ' . $iconClass, | ||
]; | ||
|
||
$aMenuItems[] = (new \LimeSurvey\Menu\MenuItem($aMenuItemAdminOptions)); | ||
|
||
$oNewMenu = new CUCMenuClass($aMenuItemAdminOptions); | ||
|
||
//Check if display only for security update is true in plugin settings and display it otherwhise display all | ||
if ($this->get('only_security_update', null, null, false) && $update[key($update)]->security_update) { | ||
$oEvent->append('extraMenus', [$oNewMenu]); | ||
} elseif (!$this->get('only_security_update', null, null, false)) { | ||
$oEvent->append('extraMenus', [$oNewMenu]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This function check if update is available from the comfort update server | ||
* | ||
* @return void | ||
*/ | ||
private function getUpdate() | ||
{ | ||
$buttons = 1; | ||
$updateModel = new UpdateForm(); | ||
$serverAnswer = $updateModel->getUpdateInfo($buttons); | ||
return $serverAnswer; | ||
} | ||
|
||
/** | ||
* Register css and js file | ||
* @return void | ||
*/ | ||
protected function registerAssets() | ||
{ | ||
$assetsUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets'); | ||
Yii::app()->clientScript->registerScriptFile($assetsUrl . '/script.js'); | ||
Yii::app()->clientScript->registerCssFile($assetsUrl . '/style.css'); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
application/core/plugins/ComfortUpdateChecker/assets/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$(document).ready(function () { | ||
|
||
}); |
30 changes: 30 additions & 0 deletions
30
application/core/plugins/ComfortUpdateChecker/assets/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.cu-checker { | ||
animation: shake 1.25s cubic-bezier(.36, .07, .19, .97) both infinite; | ||
transform: translate3d(0, 0, 0); | ||
backface-visibility: hidden; | ||
perspective: 1000px; | ||
} | ||
|
||
@keyframes shake { | ||
|
||
10%, | ||
90% { | ||
transform: translate3d(-1px, 0, 0); | ||
} | ||
|
||
20%, | ||
80% { | ||
transform: translate3d(1px, 0, 0); | ||
} | ||
|
||
30%, | ||
50%, | ||
70% { | ||
transform: translate3d(-4px, 0, 0); | ||
} | ||
|
||
40%, | ||
60% { | ||
transform: translate3d(4px, 0, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config> | ||
<metadata> | ||
<name>ComfortUpdateChecker</name> | ||
<type>plugin</type> | ||
<creationDate>2020-10-12</creationDate> | ||
<lastUpdate>2020-10-12</lastUpdate> | ||
<author>Eddy Lackmann | LimeSurvey Team</author> | ||
<authorUrl>https://limesurvey.org</authorUrl> | ||
<email>support@limesurvey.org</email> | ||
<version>1.0.0</version> | ||
<license>GNU General Public License version 2 or later</license> | ||
<description><![CDATA[Checks if new update is available for comfort update users]]></description> | ||
<supportUrl>https://www.limesurvey.org</supportUrl> | ||
</metadata> | ||
<compatibility> | ||
<version>4.0</version> | ||
<version>3.0</version> | ||
</compatibility> | ||
<updaters disabled="disabled"> | ||
|
||
</updaters> | ||
</config> |
12 changes: 12 additions & 0 deletions
12
application/core/plugins/ComfortUpdateChecker/helpers/CUCMenuClass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/** | ||
* Extending the basic menu class with an icon in front of the label | ||
*/ | ||
class CUCMenuClass extends \LimeSurvey\Menu\Menu | ||
{ | ||
public function getLabel() | ||
{ | ||
return "<i class='" . $this->iconClass . "'></i> " . $this->label; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters