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
|
// Simple session cache withe expiration managed via cookies
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function getCache(key)
|
function getCache(key, noCookie = false)
|
||||||
{
|
{
|
||||||
// check cache
|
// check cache
|
||||||
if(sessionStorage.getItem(key))
|
if(sessionStorage.getItem(key))
|
||||||
{
|
{
|
||||||
// check if not expired
|
// check if not expired
|
||||||
if(getCookie(key + '_session_expiry') != "")
|
if(noCookie || getCookie(key + '_session_expiry') != "")
|
||||||
{
|
{
|
||||||
return sessionStorage.getItem(key);
|
return sessionStorage.getItem(key);
|
||||||
}
|
}
|
||||||
@@ -38,8 +38,12 @@ function getCache(key)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function setCache(key, data, expirationMinutes='')
|
function setCache(key, data, expirationMinutes='')
|
||||||
{
|
{
|
||||||
sessionStorage.setItem(key, data);
|
sessionStorage.setItem(key, data);
|
||||||
setCookie (key + '_session_expiry', 'OK', expirationMinutes='')
|
|
||||||
|
if (expirationMinutes != '')
|
||||||
|
{
|
||||||
|
setCookie (key + '_session_expiry', 'OK', expirationMinutes='')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,15 +111,29 @@ function cacheStrings()
|
|||||||
|
|
||||||
data.forEach((langString) => {
|
data.forEach((langString) => {
|
||||||
// console.log(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) {
|
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__).'/de_de.php';
|
||||||
require dirname(__FILE__).'/es_es.php';
|
require dirname(__FILE__).'/es_es.php';
|
||||||
|
|
||||||
|
|
||||||
function lang($key)
|
function lang($key)
|
||||||
{
|
{
|
||||||
global $pia_lang_selected, $lang, $defaultLang, $strings;
|
global $pia_lang_selected, $lang, $defaultLang, $strings;
|
||||||
@@ -72,4 +73,6 @@ function lang($key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $temp;
|
return $temp;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user