From 6f080b1275bc8da4ab8dd2692df92893b750f0c4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Nov 2022 20:31:17 +0100 Subject: [PATCH] refs #3971 Version cookie fixes --- app.js | 5 ++-- debian/changelog | 2 +- index.js | 60 -------------------------------------- js/vn/locale.js | 68 ++++++++++++++++++-------------------------- js/vn/vn.js | 4 +++ package.json | 2 +- web/html-service.php | 8 ------ 7 files changed, 37 insertions(+), 112 deletions(-) delete mode 100644 index.js diff --git a/app.js b/app.js index aa8a23f4..bd9c9fa9 100644 --- a/app.js +++ b/app.js @@ -1,14 +1,15 @@ __webpack_public_path__ = _PUBLIC_PATH; require('hedera/hedera'); +const packageJson = require('./package.json'); window.onload = function() { loadLocale(main); } function main(req) { - if (req) - onLocaleLoad(req); + if (req) onLocaleLoad(req); + Vn.setVersion(packageJson.version); hederaWeb = new Hedera.App(); hederaWeb.run(); diff --git a/debian/changelog b/debian/changelog index 04a95bb1..71b8fe32 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (22.44.8) stable; urgency=low +hedera-web (22.44.9) stable; urgency=low * Initial Release. diff --git a/index.js b/index.js deleted file mode 100644 index aa8a23f4..00000000 --- a/index.js +++ /dev/null @@ -1,60 +0,0 @@ -__webpack_public_path__ = _PUBLIC_PATH; - -require('hedera/hedera'); - -window.onload = function() { - loadLocale(main); -} - -function main(req) { - if (req) - onLocaleLoad(req); - - hederaWeb = new Hedera.App(); - hederaWeb.run(); -} - -function loadLocale(cb) { - Vn.Locale.init(); - var lang = Vn.Locale.language; - - var req = require.context('js', true, /locale\/en.yml$/); - onLocaleLoad(req); - - switch (lang) { - case 'ca': - require([], function() { - cb(require.context('js', true, /locale\/ca.yml$/)); - }); - break; - case 'es': - require([], function() { - cb(require.context('js', true, /locale\/es.yml$/)); - }); - break; - case 'fr': - require([], function() { - cb(require.context('js', true, /locale\/fr.yml$/)); - }); - break; - case 'mn': - require([], function() { - cb(require.context('js', true, /locale\/mn.yml$/)); - }); - break; - case 'pt': - require([], function() { - cb(require.context('js', true, /locale\/pt.yml$/)); - }); - break; - default: - cb(); - } -} - -function onLocaleLoad(req) { - var keys = req.keys(); - - for (var i = 0; i < keys.length; i++) - Vn.Locale.add(req(keys[i])); -} diff --git a/js/vn/locale.js b/js/vn/locale.js index 2ee50062..56d46250 100644 --- a/js/vn/locale.js +++ b/js/vn/locale.js @@ -9,8 +9,7 @@ module.exports = language: null ,defaultLang: 'en' - ,init: function () - { + ,init: function() { if (this.language) return; @@ -22,12 +21,11 @@ module.exports = else if (navigator.language) language = navigator.language; - this.language = language.substr (0, 2); + this.language = language.substr(0, 2); } - ,load: function (path, callback) - { - this.init (); + ,load: function(path, callback) { + this.init(); var data = { path: path, @@ -36,77 +34,67 @@ module.exports = orgOk: this.defaultLang === this.language }; - data.def = this.createRequest (data, true, this.defaultLang); + data.def = this.createRequest(data, true, this.defaultLang); if (!data.orgOk) - data.org = this.createRequest (data, false, this.language); + data.org = this.createRequest(data, false, this.language); } - ,createRequest: function (data, isDef, lang) - { - var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion (); + ,createRequest: function(data, isDef, lang) { + var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion(); - var request = new XMLHttpRequest (); - request.open ('get', langFile, true); + var request = new XMLHttpRequest(); + request.open('get', langFile, true); request.onreadystatechange = - this.onRequestReady.bind (this, request, data, isDef); - request.send (); + this.onRequestReady.bind(this, request, data, isDef); + request.send(); return request; } - ,onRequestReady: function (request, data, isDef) - { + ,onRequestReady: function(request, data, isDef) { if (request.readyState != 4) return; - if (isDef) - { - this.loadFromRequest (request); + if (isDef) { + this.loadFromRequest(request); data.defOk = true; - } - else + } else data.orgOk = true; - if (data.orgOk && data.defOk) - { + if (data.orgOk && data.defOk) { if (data.org != null) - this.loadFromRequest (data.org) + this.loadFromRequest(data.org) if (data.callback) - data.callback (); + data.callback(); } } - ,loadFromRequest: function (request) - { + ,loadFromRequest: function(request) { if (request.status !== 200) return false; try { - this.add (yaml.safeLoad (request.responseText)); + this.add(yaml.safeLoad(request.responseText)); return true; - } - catch (e) { - console.error (e); + } catch (e) { + console.error(e); } return false } - ,loadScript: function (path, callback) - { - this.init (); - Vn.includeJs (path +'/locale/'+ this.language, callback); + ,loadScript: function(path, callback) { + this.init(); + Vn.includeJs(path +'/locale/'+ this.language, callback); } - ,add: function (translations) - { + ,add: function(translations) { for (var str in translations) vnLocaleStrings[str] = translations[str]; } } -window._ = function (stringId) -{ +window._ = function(stringId) { var string = vnLocaleStrings[stringId]; return string ? string : stringId; } diff --git a/js/vn/vn.js b/js/vn/vn.js index 5e272e9d..b64fd0d6 100644 --- a/js/vn/vn.js +++ b/js/vn/vn.js @@ -50,6 +50,10 @@ Vn = module.exports = { return this._version; } + ,setVersion(version) { + document.cookie = `vnVersion=${version}; SameSite=Lax;`; + } + /** * Includes a new CSS stylesheet in the current document, if the stylesheet * is already included, does nothing. diff --git a/package.json b/package.json index 4171328e..8afe3663 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "22.44.8", + "version": "22.44.9", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/web/html-service.php b/web/html-service.php index 495588aa..65179e9c 100644 --- a/web/html-service.php +++ b/web/html-service.php @@ -64,14 +64,6 @@ class HtmlService extends Service { header('Location: ?method=version-menu'); } - // Setting the version - - $domain = explode(':', $_SERVER['HTTP_HOST'])[0]; - setcookie('vnVersion', $this->getVersion()->toString(), [ - 'samesite' => 'Lax', - 'domain' => $domain - ]); - // Loading the requested page $basePath = "pages/$page";