mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
setings improvements/JS rewrite
This commit is contained in:
@@ -20,13 +20,13 @@ var emptyArr = ['undefined', "", undefined, null, 'null'];
|
||||
// -----------------------------------------------------------------------------
|
||||
// Simple session cache withe expiration managed via cookies
|
||||
// -----------------------------------------------------------------------------
|
||||
function getCache(key)
|
||||
function getCache(key, noCookie = false)
|
||||
{
|
||||
// check cache
|
||||
if(sessionStorage.getItem(key))
|
||||
{
|
||||
// check if not expired
|
||||
if(getCookie(key + '_session_expiry') != "")
|
||||
if(noCookie || getCookie(key + '_session_expiry') != "")
|
||||
{
|
||||
return sessionStorage.getItem(key);
|
||||
}
|
||||
@@ -38,8 +38,12 @@ function getCache(key)
|
||||
// -----------------------------------------------------------------------------
|
||||
function setCache(key, data, expirationMinutes='')
|
||||
{
|
||||
sessionStorage.setItem(key, data);
|
||||
setCookie (key + '_session_expiry', 'OK', expirationMinutes='')
|
||||
sessionStorage.setItem(key, data);
|
||||
|
||||
if (expirationMinutes != '')
|
||||
{
|
||||
setCookie (key + '_session_expiry', 'OK', expirationMinutes='')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,15 +111,29 @@ function cacheStrings()
|
||||
|
||||
data.forEach((langString) => {
|
||||
// console.log(langString)
|
||||
setCache(`pia_lang_${langString.String_Key}`, langString.String_Value, expirationMinutes='1440') // expire in a day
|
||||
setCache(`pia_lang_${langString.String_Key}`, langString.String_Value)
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function getString (key) {
|
||||
return getCache(`pia_lang_${key}`)
|
||||
// todo
|
||||
// php/server/utilDB.php?key=Gen_Okay
|
||||
// need to initilaize session storage
|
||||
|
||||
result = getCache(`pia_lang_${key}`, true);
|
||||
|
||||
if (result == "")
|
||||
{
|
||||
getCache(`pia_lang_${key}`, true)
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is async can't do that
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
0
front/php/server/get
Normal file
0
front/php/server/get
Normal file
13
front/php/server/utilDB.php
Normal file
13
front/php/server/utilDB.php
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
require dirname(__FILE__).'/init.php';
|
||||
|
||||
// Action functions
|
||||
if (isset ($_REQUEST['key']))
|
||||
{
|
||||
echo lang($_REQUEST['key']);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -37,6 +37,7 @@ require dirname(__FILE__).'/en_us.php';
|
||||
require dirname(__FILE__).'/de_de.php';
|
||||
require dirname(__FILE__).'/es_es.php';
|
||||
|
||||
|
||||
function lang($key)
|
||||
{
|
||||
global $pia_lang_selected, $lang, $defaultLang, $strings;
|
||||
@@ -72,4 +73,6 @@ function lang($key)
|
||||
}
|
||||
|
||||
return $temp;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user