Merge branch '11200_cookies_clean' into 11200_cookies_fusion

This commit is contained in:
Fred Tempez 2021-11-22 19:35:00 +01:00
commit 39aaa035b4
3 changed files with 49 additions and 41 deletions

View File

@ -219,28 +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";
// Crée le cookie d'acceptation Google Analytics si nécessaire var e = new Date();
<?php $analytics = $this->getData(['config', 'seo', 'analyticsId']);?> e.setFullYear(e.getFullYear() + 1);
<?php if( $analytics !== null AND $analytics !=='' ){ var expires = "expires=" + e.toUTCString();
$path = str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF']));?>
if(ga.checked){ // Crée le cookie d'acceptation Google Analytics si nécessaire
document.cookie = "ZWII_COOKIE_GA_CONSENT=true_<?php echo $path;?>;" + expires +";"+ samesite; var analytics = "<?php echo $this->getData(['config', 'seo', 'analyticsId']);?>";
} if( analytics.length > 0){
else{ document.cookie = "ZWII_COOKIE_CONSENT_GA=" + $("#googleAnalytics").prop("checked") + ";" + domain + ";" + path + ";" + samesite + ";" + expires;
document.cookie = "ZWII_COOKIE_GA_CONSENT=false_<?php echo $path;?>;" + expires +";"+ samesite; }
} //document.cookie = "ZWII_COOKIE_CONSENT=true;" + domain + ";" + path + ";" + samesite + ";" + expires;
<?php } ?> document.cookie = "ZWII_COOKIE_CONSENT=<?php echo str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])); ?>;" + domain + ";" + path + ";" + samesite + ";" + expires;
document.cookie = "ZWII_COOKIE_CONSENT=true_<?php echo str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])); ?>;" + expires +";"+ samesite;
}); });
$("#cookieConsent .cookieClose").on("click", function() { $("#cookieConsent .cookieClose").on("click", function() {
$(this).parents("#cookieConsent").fadeOut(); $(this).parents("#cookieConsent").fadeOut();
}); });

View File

@ -1189,26 +1189,34 @@ class common {
* Affiche le consentement aux cookies * Affiche le consentement aux cookies
*/ */
public function showCookies() { public function showCookies() {
if($this->getInput('ZWII_COOKIE_CONSENT') !== 'true_'.str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])) AND $this->getData(['config','cookieConsent']) === true){ ?>
<div id="cookieConsent"> if( $this->getInput('ZWII_COOKIE_CONSENT') !== str_replace('index.php','',str_replace( '/','',$_SERVER['PHP_SELF'])) AND
<div class="cookieClose">X</div> $this->getData(['config','cookieConsent']) === true
<h3><?php echo $this->getData(['config', 'cookies', 'cookiesTitleText']); ?></h3> ){
<?php $analytics = $this->getData(['config', 'seo', 'analyticsId']);?>
<p><?php echo $this->getData(['config', 'cookies', 'cookiesZwiiText']); ?></p> $analytics = $this->getData(['config', 'seo', 'analyticsId']);
<?php $legalPage = $this->getData(['locale','legalPageId']) ==='none'? 'mentions-legales' : $this->getData(['locale','legalPageId']); ?> $legalPage = $this->getData(['locale','legalPageId']) ==='none'? 'mentions-legales' : $this->getData(['locale','legalPageId']);
<p><a href=" <?php echo helper::baseUrl() . $legalPage ?> "><?php echo $this->getData(['config', 'cookies', 'cookiesLinkMlText']); ?></a></p> $item = '<div id="cookieConsent">';
<?php if( $analytics !== null AND $analytics !=='' ){ ?> $item .= '<div class="cookieClose">';
<p><?php echo $this->getData(['config', 'cookies', 'cookiesGaText']); ?></p> $item .= template::ico('cancel');
<?php } ?> $item .= '</div>';
<form method="POST" action="" id="cookieForm"> $item .= '<h3>'. $this->getData(['config', 'cookies', 'cookiesTitleText']) . '</h3>';
<?php if( $analytics !== null AND $analytics !=='' ){ ?> $item .= '<p>' . $this->getData(['config', 'cookies', 'cookiesZwiiText']) . '</p>';
<input type="checkbox" id="googleAnalytics" name="googleAnalytics" value="GA"> $item .= '<p><a href="' . helper::baseUrl() . $legalPage . '">' . $this->getData(['config', 'cookies', 'cookiesLinkMlText']) . '</a></p>';
<label for="googleAnalytics"><?php echo $this->getData(['config', 'cookies', 'cookiesCheckboxGaText']); ?></label> <?php } ?><br><br> if( $analytics !== null AND $analytics !=='' ){
<input type="submit" id="cookieConsentConfirm" value="Valider"> $item .= '<p>' . $this->getData(['config', 'cookies', 'cookiesGaText']) . '</p>';
</form> }
</div> $item .= '<form method="POST" action="" id="cookieForm">';
<?php if( $analytics !== null AND $analytics !=='' ) {
$item .= '<input type="checkbox" id="googleAnalytics" name="googleAnalytics" value="GA">';
$item .= '<label for="googleAnalytics">' . $this->getData(['config', 'cookies', 'cookiesCheckboxGaText']) . '</label>';
}
$item .= '<br><br>';
$item .= '<input type="submit" id="cookieConsentConfirm" value="Valider">';
$item .= '</form></div>';
echo $item;
} }
} }
/** /**

View File

@ -174,7 +174,7 @@
<!-- Corps de page --> <!-- Corps de page -->
<?php $this->showSection();?> <?php $this->showSection();?>
<!-- footer --> <!-- footer -->
<?php $this->showFooter();?> <?php $this->showFooter();?>
@ -183,7 +183,7 @@
<!-- Lien remonter en haut --> <!-- Lien remonter en haut -->
<div id="backToTop"><?php echo template::ico('up'); ?></div> <div id="backToTop"><?php echo template::ico('up'); ?></div>
<!-- Affichage du consentement aux cookies--> <!-- Affichage du consentement aux cookies-->
<?php $this->showCookies(); ?> <?php $this->showCookies(); ?>
<!-- Les scripts --> <!-- Les scripts -->
<?php $this->showScript();?> <?php $this->showScript();?>