From 6a239668430f902f81548bf08fec5c16124756cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tempez?= Date: Sun, 28 Nov 2021 12:07:07 +0100 Subject: [PATCH] Cookie OKay ! --- core/core.js.php | 36 ++++++++++-- core/core.php | 55 +++++++++--------- core/include/update.inc.php | 2 +- core/layout/common.css | 11 ++-- core/module/config/config.php | 3 +- core/module/config/view/locale/locale.php | 57 +++++++++++-------- core/module/install/ressource/defaultdata.php | 2 +- core/module/theme/view/footer/footer.php | 2 +- 8 files changed, 105 insertions(+), 63 deletions(-) diff --git a/core/core.js.php b/core/core.js.php index ac429c36..c8ce0f0a 100644 --- a/core/core.js.php +++ b/core/core.js.php @@ -224,18 +224,27 @@ core.start = function() { // Crée le cookie d'acceptation Google Analytics si l'ID a été saisie var analytics = "getData(['config', 'seo', 'analyticsId']);?>"; + // l'Id GA est défini dans la configuration, afficher la checkbox d'acceptation if( analytics.length > 0){ - document.cookie = "ZWII_COOKIE_GA_CONSENT=" + $("#googleAnalytics").prop("checked") + "" +";" + domain + ";" + path + ";" + samesite + ";" + expires; + // Traitement du retour de la checkbox + if ($("#googleAnalytics").is(":checked")) { + // L'URL du serveur faut TRUE + document.cookie = "ZWII_COOKIE_GA_CONSENT=" + "" + ";" + domain + ";" + path + ";" + samesite + ";" + expires; + } else { + document.cookie = "ZWII_COOKIE_GA_CONSENT=false;" + domain + ";" + path + ";" + samesite + ";" + expires; + } + } - // Stocke lz cookie d'acceptation + // Stocke le cookie d'acceptation document.cookie = "ZWII_COOKIE_CONSENT=;" + domain + ";" + path + ";" + samesite + ";" + expires; }); /** * Suppression du cookie de consentement - */ - $('#footerCookies').bind('click', function(event) { + + $('#cookieConsentRefused').on('click', function() { + var samesite = "samesite=lax"; var getUrl = window.location; var domain = "domain=" + getUrl.host; @@ -244,8 +253,17 @@ core.start = function() { var e = new Date(); e.setFullYear(e.getFullYear() - 1); var expires = "expires=" + e.toUTCString(); - document.cookie = "ZWII_COOKIE_CONSENT=;" + domain + ";" + path + ";" + samesite + ";" + expires; + document.cookie = "ZWII_COOKIE_CONSENT=false;" + domain + ";" + path + ";" + samesite + ";" + expires; + + // Désactiver le cookie GA + document.cookie = "ZWII_COOKIE_GA_CONSENT=false;" + domain + ";" + path + ";" + samesite + ";" + expires; + + + + // fermer la fenêtre + $("#cookieConsent").fadeOut(); }); + */ /** * Fermeture de la popup des cookies @@ -254,6 +272,14 @@ core.start = function() { $(this).parents("#cookieConsent").fadeOut(); }); + /** + * Commande de gestion des cookies dans le footer + */ + + $("footer #footerCookies").on("click", function() { + $("#cookieConsent").removeClass("displayNone"); + }); + /** * Affiche / Cache le menu en mode responsive */ diff --git a/core/core.php b/core/core.php index e217235d..bbe2c319 100644 --- a/core/core.php +++ b/core/core.php @@ -1174,7 +1174,7 @@ class common { */ public function showAnalytics() { if( !empty($code = $this->getData(['config', 'seo', 'analyticsId'])) && - $this->getInput('ZWII_COOKIE_GA_CONSENT') === 'true'.$_SERVER['PHP_SELF']) { + $this->getInput('ZWII_COOKIE_GA_CONSENT') === $_SERVER['PHP_SELF'] ) { echo '