setings improvements/JS rewrite

This commit is contained in:
Jokob-sk
2023-07-26 07:14:09 +10:00
parent 35a0a91a02
commit 46e4857a35
4 changed files with 42 additions and 8 deletions

View File

@@ -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
View File

View File

@@ -0,0 +1,13 @@
<?php
require dirname(__FILE__).'/init.php';
// Action functions
if (isset ($_REQUEST['key']))
{
echo lang($_REQUEST['key']);
}
?>

View File

@@ -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;
}
};