Nom du cookie + nettoyage

This commit is contained in:
fredtempez 2021-11-22 13:46:16 +01:00
parent bf9e887c00
commit 84b4023e19
2 changed files with 20 additions and 22 deletions

View File

@ -219,30 +219,28 @@ core.start = function() {
} }
}); });
/** /**
* Traitement du formulaire cookies * Traitement du formulaire cookies
*/ */
$("#cookieForm").submit(function(event){ $("#cookieForm").submit(function(event){
const ga = document.getElementById('googleAnalytics'); var samesite = "samesite=lax";
var samesite = "samesite=lax"; var getUrl = window.location;
var expires = new Date(); var domain = "domain=" + getUrl.host;
expires.setFullYear(expires.getFullYear() + 1); var path = "path=" + getUrl.pathname.split('/')[1];
expires = "expires=" + expires.toUTCString(); var samesite = "samesite=lax";
var e = new Date();
e.setFullYear(e.getFullYear() + 1);
var expires = "expires=" + e.toUTCString();
// Crée le cookie d'acceptation Google Analytics si nécessaire // Crée le cookie d'acceptation Google Analytics si nécessaire
<?php $analytics = $this->getData(['config', 'seo', 'analyticsId']);?> var analytics = "<?php echo $this->getData(['config', 'seo', 'analyticsId']);?>";
<?php if( $analytics !== null AND $analytics !=='' ){ console.log(analytics.length );
$cookieName = 'ZWII_COOKIE_GA_CONSENT'.str_replace('_index.php','',str_replace( '/','_',$_SERVER['PHP_SELF']));?> if( analytics.length > 0){
if(ga.checked){ document.cookie = "ZWII_COOKIE_CONSENT_GA=" + $("#googleAnalytics").prop("checked") + ";" + domain + ";" + path + ";" + samesite + ";" + expires;
document.cookie = "<?php echo $cookieName; ?>=true;" + expires +";"+ samesite; }
} document.cookie = "ZWII_COOKIE_CONSENT=true;" + domain + ";" + path + ";" + samesite + ";" + expires;
else{
document.cookie = "<?php echo $cookieName; ?>=false;" + expires +";"+ samesite;
}
<?php }
$cookieName = 'ZWII_COOKIE_CONSENT'.str_replace('_index.php','',str_replace( '/','_',$_SERVER['PHP_SELF']));
?>
document.cookie = "<?php echo $cookieName; ?>=true;" + expires +";"+ samesite;
}); });
$("#cookieConsent .cookieClose").on("click", function() { $("#cookieConsent .cookieClose").on("click", function() {
$(this).parents("#cookieConsent").fadeOut(); $(this).parents("#cookieConsent").fadeOut();
}); });

View File

@ -1190,8 +1190,8 @@ class common {
* Affiche le consentement aux cookies * Affiche le consentement aux cookies
*/ */
public function showCookies() { public function showCookies() {
$cookieName = 'ZWII_COOKIE_CONSENT'.str_replace('_index.php','',str_replace( '/','_',$_SERVER['PHP_SELF'])); //$cookieName = 'ZWII_COOKIE_CONSENT'.str_replace('_index.php','',str_replace( '/','_',$_SERVER['PHP_SELF']));
if($this->getInput($cookieName) !== 'true' AND $this->getData(['config','cookieConsent']) === true){ ?> if($this->getInput('ZWII_COOKIE_CONSENT') !== 'true' AND $this->getData(['config','cookieConsent']) === true){ ?>
<div id="cookieConsent"> <div id="cookieConsent">
<div class="cookieClose">X</div> <div class="cookieClose">X</div>
<h3><?php echo $this->getData(['config', 'cookies', 'cookiesTitleText']); ?></h3> <h3><?php echo $this->getData(['config', 'cookies', 'cookiesTitleText']); ?></h3>