Refactor Toggle Dark mode 0.2

This commit is contained in:
Jokob-sk
2023-01-17 19:17:23 +11:00
parent aac35294b5
commit b9d65ea0e2
4 changed files with 20 additions and 14 deletions

View File

@@ -22,7 +22,9 @@
ini_set ('max_execution_time','15');
$skipCache = FALSE;
$expireMinutes = 5;
$defaultValue = '';
if (isset ($_REQUEST['skipcache'])) {
$skipCache = TRUE;
@@ -32,12 +34,16 @@
$defaultValue = $_REQUEST['defaultValue'];
}
if (isset ($_REQUEST['expireMinutes'])) {
$expireMinutes = $_REQUEST['expireMinutes'];
}
// Action functions
if (isset ($_REQUEST['action']) && !empty ($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case 'get': getParameter($skipCache, $defaultValue); break;
case 'set': setParameter(); break;
case 'get': getParameter($skipCache, $defaultValue, $expireMinutes); break;
case 'set': setParameter($expireMinutes); break;
default: logServerConsole ('Action: '. $action); break;
}
}
@@ -46,7 +52,7 @@
//------------------------------------------------------------------------------
// Get Parameter Value
//------------------------------------------------------------------------------
function getParameter($skipCache, $defaultValue) {
function getParameter($skipCache, $defaultValue, $expireMinutes) {
$parameter = $_REQUEST['parameter'];
$value = "";
@@ -77,7 +83,7 @@ function getParameter($skipCache, $defaultValue) {
}
// update cache
setCache($parameter, $value);
setCache($parameter, $value, $expireMinutes);
}
// return value
echo (json_encode ($value));
@@ -87,10 +93,10 @@ function getParameter($skipCache, $defaultValue) {
//------------------------------------------------------------------------------
// Set Parameter Value
//------------------------------------------------------------------------------
function setParameter() {
function setParameter($expireMinutes) {
$parameter = $_REQUEST['parameter'];
$value = $_REQUEST['value'];
$value = $_REQUEST['value'];
global $db;
@@ -119,7 +125,7 @@ function setParameter() {
}
// update cache
setCache($parameter, $value);
setCache($parameter, $value, $expireMinutes);
echo 'OK';
}

View File

@@ -391,8 +391,8 @@ function getCache($key) {
}
}
// -------------------------------------------------------------------------------------------
function setCache($key, $value) {
setcookie($key, $value, time()+300, "/","", 0); // 5min cache
function setCache($key, $value, $expireMinutes = 5) {
setcookie($key, $value, time()+$expireMinutes*60, "/","", 0);
}