Modification gestion des cookies

This commit is contained in:
SylvainLelievre 2021-11-24 07:18:29 +01:00
parent 39aaa035b4
commit 020da0f9e3
2 changed files with 26 additions and 27 deletions

View File

@ -219,31 +219,30 @@ core.start = function() {
} }
}); });
/** /**
* Traitement du formulaire cookies * Traitement du formulaire cookies
*/ */
$("#cookieForm").submit(function(event){ $("#cookieForm").submit(function(event){
var samesite = "samesite=lax"; var samesite = "samesite=lax";
var getUrl = window.location; var getUrl = window.location;
var domain = "domain=" + getUrl.host; var domain = "domain=" + getUrl.host;
var path = "path=" + getUrl.pathname.split('/')[1]; var path = "path=" + getUrl.pathname.split('/')[1];
var samesite = "samesite=lax"; var samesite = "samesite=lax";
var e = new Date(); var e = new Date();
e.setFullYear(e.getFullYear() + 1); e.setFullYear(e.getFullYear() + 1);
var expires = "expires=" + e.toUTCString(); 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
var analytics = "<?php echo $this->getData(['config', 'seo', 'analyticsId']);?>"; var analytics = "<?php echo $this->getData(['config', 'seo', 'analyticsId']);?>";
if( analytics.length > 0){ if( analytics.length > 0){
document.cookie = "ZWII_COOKIE_CONSENT_GA=" + $("#googleAnalytics").prop("checked") + ";" + domain + ";" + path + ";" + samesite + ";" + expires; document.cookie = "ZWII_COOKIE_GA_CONSENT=" + $("#googleAnalytics").prop("checked") + "<?php echo $_SERVER['PHP_SELF']; ?>" +";" + domain + ";" + path + ";" + samesite + ";" + expires;
} }
//document.cookie = "ZWII_COOKIE_CONSENT=true;" + domain + ";" + path + ";" + samesite + ";" + expires; document.cookie = "ZWII_COOKIE_CONSENT=<?php echo $_SERVER['PHP_SELF']; ?>;" + domain + ";" + path + ";" + samesite + ";" + expires;
document.cookie = "ZWII_COOKIE_CONSENT=<?php echo str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])); ?>;" + domain + ";" + path + ";" + samesite + ";" + expires; });
});
$("#cookieConsent .cookieClose").on("click", function() { $("#cookieConsent .cookieClose").on("click", function() {
$(this).parents("#cookieConsent").fadeOut(); $(this).parents("#cookieConsent").fadeOut();
}); });
/** /**
* Choix de page dans la barre de membre * Choix de page dans la barre de membre

View File

@ -1173,7 +1173,7 @@ class common {
*/ */
public function showAnalytics() { public function showAnalytics() {
if( !empty($code = $this->getData(['config', 'seo', 'analyticsId'])) && if( !empty($code = $this->getData(['config', 'seo', 'analyticsId'])) &&
$this->getInput('ZWII_COOKIE_GA_CONSENT') === 'true_'.str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF']))) { $this->getInput('ZWII_COOKIE_GA_CONSENT') === 'true'.$_SERVER['PHP_SELF']) {
echo '<!-- Global site tag (gtag.js) - Google Analytics --> echo '<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id='. $code .'"></script> <script async src="https://www.googletagmanager.com/gtag/js?id='. $code .'"></script>
<script> <script>
@ -1189,8 +1189,8 @@ class common {
* Affiche le consentement aux cookies * Affiche le consentement aux cookies
*/ */
public function showCookies() { public function showCookies() {
if( $this->getInput('ZWII_COOKIE_CONSENT') !== str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])) AND if( $this->getInput('ZWII_COOKIE_CONSENT') !== $_SERVER['PHP_SELF'] AND
$this->getData(['config','cookieConsent']) === true $this->getData(['config','cookieConsent']) === true
){ ){
@ -1213,10 +1213,10 @@ class common {
} }
$item .= '<br><br>'; $item .= '<br><br>';
$item .= '<input type="submit" id="cookieConsentConfirm" value="Valider">'; $item .= '<input type="submit" id="cookieConsentConfirm" value="Valider">';
$item .= '</form></div>'; $item .= '</form></div>';
echo $item; echo $item;
} }
} }
/** /**