Gestion des cookies

This commit is contained in:
SylvainLelievre 2021-11-18 11:34:19 +01:00
parent 860ff8c35a
commit 9485c2ba5a
4 changed files with 89 additions and 65 deletions

View File

@ -219,46 +219,31 @@ core.start = function() {
} }
}); });
/** /**
* Message sur l'utilisation des cookies * Traitement du formulaire cookies
*/ */
var analytics = ""; $("#cookieForm").submit(function(event){
if (<?php echo json_encode($this->getData(['config', 'seo', 'analyticsId'])); ?>) { const ga = document.getElementById('googleAnalytics');
analytics = ' grâce au cookie Google Analytics' var samesite = "samesite=lax";
} var expires = new Date();
if(<?php echo json_encode($this->getData(['config', 'cookieConsent'])); ?>) { expires.setFullYear(expires.getFullYear() + 1);
if(document.cookie.indexOf("ZWII_COOKIE_CONSENT") === -1) { expires = "expires=" + expires.toUTCString();
$("body").append( // Crée le cookie d'acceptation Google Analytics si nécessaire
$("<div>").attr("id", "cookieConsent").append( <?php $analytics = $this->getData(['config', 'seo', 'analyticsId']);?>
$("<span>").html("<p>Ce site utilise des cookies pour assurer l'authentification, améliorer l'expérience utilisateur"+analytics+". <br/>En cliquant sur ”Jaccepte”, vous acceptez lutilisation de ces cookies.</p>"), <?php if( $analytics !== null AND $analytics !=='' ){ ?>
$("<span>") if(ga.checked){
.attr("id", "cookieConsentConfirm") document.cookie = "ZWII_COOKIE_GA_CONSENT=true;" + expires +";"+ samesite;
.text("Accepter") }
.on("click", function() { else{
// Créé le cookie d'acceptation document.cookie = "ZWII_COOKIE_GA_CONSENT=false;" + expires +";"+ samesite;
var expires = new Date(); }
expires.setFullYear(expires.getFullYear() + 1); <?php } ?>
expires = "expires=" + expires.toUTCString(); document.cookie = "ZWII_COOKIE_CONSENT=true;" + expires +";"+ samesite;
document.cookie = "ZWII_COOKIE_CONSENT=true;" + expires; });
// Ferme le message $(".cookieBox .cookieClose").on("click", function() {
$(this).parents("#cookieConsent").fadeOut(); $(this).parents("#cookieConsent").fadeOut();
}), });
$("<span>")
.attr("id", "cookieConsentRefuse")
.text("Refuser")
.on("click", function() {
// Créé le cookie d'acceptation
var expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);
expires = "expires=" + expires.toUTCString();
document.cookie = "ZWII_COOKIE_CONSENT=false;" + expires;
// Ferme le message
$(this).parents("#cookieConsent").fadeOut();
}),
)
);
}
}
/** /**
* Choix de page dans la barre de membre * Choix de page dans la barre de membre
*/ */

View File

@ -473,7 +473,7 @@ class common {
*/ */
public function getPage($page, $lang) { public function getPage($page, $lang) {
// Le nom de la ressource et le fichier de contenu sont définis : // Le nom de la ressource et le fichier de contenu sont définis :
if ( if (
$this->getData(['page', $page, 'content']) !== '' $this->getData(['page', $page, 'content']) !== ''
&& file_exists(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content'])) && file_exists(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']))
@ -482,14 +482,14 @@ class common {
return file_get_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content'])); return file_get_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']));
} else { } else {
return 'Aucun contenu trouvé.'; return 'Aucun contenu trouvé.';
} }
} }
/** /**
* Ecrire les données de la page * Ecrire les données de la page
* @param string pageId * @param string pageId
* @param string contenu de la page * @param string contenu de la page
* @param return nombre d'octets écrits ou erreur * @param return nombre d'octets écrits ou erreur
*/ */
public function setPage($page, $value, $lang) { public function setPage($page, $value, $lang) {
@ -953,7 +953,7 @@ class common {
} else { } else {
file_put_contents('robots.txt','User-agent: *' . PHP_EOL . 'Disallow: /'); file_put_contents('robots.txt','User-agent: *' . PHP_EOL . 'Disallow: /');
} }
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com // Submit your sitemaps to Google, Yahoo, Bing and Ask.com
if (empty ($this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort'])) ) { if (empty ($this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort'])) ) {
$sitemap->submitSitemap(); $sitemap->submitSitemap();
@ -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_CONSENT') === 'true') { $this->getInput('ZWII_COOKIE_GA_CONSENT') === 'true') {
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>
@ -1185,6 +1185,33 @@ class common {
} }
} }
/**
* Affiche le consentement aux cookies
*/
public function showCookies() {
if($this->getInput('ZWII_COOKIE_CONSENT') !== 'true' AND $this->getData(['config','cookieConsent']) === true){ ?>
<div id="cookieConsent">
<div class="cookieBox"><div class="cookieClose">X</div></div>
<?php $analytics = $this->getData(['config', 'seo', 'analyticsId']);?>
<p>Ce site <?php echo helper::baseUrl(false); ?> utilise des cookies nécessaires à son fonctionnement,
ils permettent de fluidifier son fonctionnement par exemple en mémorisant les données de connexion, la langue que vous avez choisie
ou la validation de ce message.
<?php $legalPage = $this->getData(['locale','legalPageId']) ==='none'? 'mentions-legales' : $this->getData(['locale','legalPageId']); ?>
<a href=" <?php echo helper::baseUrl() . $legalPage ?> ">Plus d'informations</a></p>
<?php if( $analytics !== null AND $analytics !=='' ){ ?>
<p>Il utilise également des cookies permettant de réaliser des statistiques de visites pour améliorer votre expérience utilisateur, ces cookies déposés par Google Analytics ont besoin de votre consentement.</p>
<?php } ?>
<form method="POST" action="" id="cookieForm">
<?php if( $analytics !== null AND $analytics !=='' ){ ?>
<input type="checkbox" id="googleAnalytics" name="googleAnalytics" value="GA">
<label for="googleAnalytics"> J'accepte les cookies Google Analytics</label> <?php } ?><br><br>
<input type="submit" id="cookieConsentConfirm" value="Valider">
</form>
</div>
<?php
}
}
/** /**
* Formate le contenu de la page selon les gabarits * Formate le contenu de la page selon les gabarits
* @param Page par defaut * @param Page par defaut
@ -1259,7 +1286,7 @@ class common {
* Barre droite * Barre droite
*/ */
if ($blockright !== "") { if ($blockright !== "") {
echo '<div class="' . $blockright . '" id="contentRight"><aside>'; echo '<div class="' . $blockright . '" id="contentRight"><aside>';
// Détermine si le menu est présent // Détermine si le menu est présent
if ($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'displayMenu']) === 'none') { if ($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'displayMenu']) === 'none') {
// Pas de menu // Pas de menu
@ -1332,7 +1359,7 @@ class common {
$this->getData(['theme', 'footer', 'position']) === 'hide' $this->getData(['theme', 'footer', 'position']) === 'hide'
AND $this->getUrl(0) === 'theme' AND $this->getUrl(0) === 'theme'
) )
) { ) {
$position = 'site'; $position = 'site';
} else { } else {
$position = 'body'; $position = 'body';
@ -1342,7 +1369,7 @@ class common {
// Sortir de la division précédente // Sortir de la division précédente
echo '</div>'; echo '</div>';
} }
echo $this->getData(['theme', 'footer', 'position']) === 'hide' ? '<footer class="displayNone">' : '<footer>'; echo $this->getData(['theme', 'footer', 'position']) === 'hide' ? '<footer class="displayNone">' : '<footer>';
echo ($position === 'site') ? '<div class="container"><div class="row" id="footersite">' : '<div class="container-large'. $positionFixed . '"><div class="row" id="footerbody">'; echo ($position === 'site') ? '<div class="container"><div class="row" id="footersite">' : '<div class="container-large'. $positionFixed . '"><div class="row" id="footerbody">';
/** /**
@ -2245,21 +2272,21 @@ class core extends common {
$colors = helper::colorVariants($this->getData(['theme', 'header', 'backgroundColor'])); $colors = helper::colorVariants($this->getData(['theme', 'header', 'backgroundColor']));
$css .= 'header{background-size:' . $this->getData(['theme','header','imageContainer']).'}'; $css .= 'header{background-size:' . $this->getData(['theme','header','imageContainer']).'}';
$css .= 'header{background-color:' . $colors['normal']; $css .= 'header{background-color:' . $colors['normal'];
// Valeur de hauteur traditionnelle // Valeur de hauteur traditionnelle
$css .= ';height:' . $this->getData(['theme', 'header', 'height']) . ';line-height:' . $this->getData(['theme', 'header', 'height']) ; $css .= ';height:' . $this->getData(['theme', 'header', 'height']) . ';line-height:' . $this->getData(['theme', 'header', 'height']) ;
$css .= ';text-align:' . $this->getData(['theme', 'header', 'textAlign']) . '}'; $css .= ';text-align:' . $this->getData(['theme', 'header', 'textAlign']) . '}';
if($themeHeaderImage = $this->getData(['theme', 'header', 'image'])) { if($themeHeaderImage = $this->getData(['theme', 'header', 'image'])) {
$css .= 'header{background-image:url("../file/source/' . $themeHeaderImage . '");background-position:' . $this->getData(['theme', 'header', 'imagePosition']) . ';background-repeat:' . $this->getData(['theme', 'header', 'imageRepeat']) . '}'; $css .= 'header{background-image:url("../file/source/' . $themeHeaderImage . '");background-position:' . $this->getData(['theme', 'header', 'imagePosition']) . ';background-repeat:' . $this->getData(['theme', 'header', 'imageRepeat']) . '}';
} }
$colors = helper::colorVariants($this->getData(['theme', 'header', 'textColor'])); $colors = helper::colorVariants($this->getData(['theme', 'header', 'textColor']));
$css .= 'header span{color:' . $colors['normal'] . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'header', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'header', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'header', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'header', 'textTransform']) . '}'; $css .= 'header span{color:' . $colors['normal'] . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'header', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'header', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'header', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'header', 'textTransform']) . '}';
} }
if ($this->getData(['theme','header','feature']) === 'feature' ) { if ($this->getData(['theme','header','feature']) === 'feature' ) {
// Hauteur de la taille du contenu perso // Hauteur de la taille du contenu perso
$css .= 'header #featureContent{height:' . $this->getData(['theme', 'header', 'height']) . '; }'; $css .= 'header #featureContent{height:' . $this->getData(['theme', 'header', 'height']) . '; }';
} }
// Menu // Menu

View File

@ -498,7 +498,7 @@ header .container {
height: 100%; height: 100%;
} }
/* Marges au cotenu de la bannière personnalisée /* Marges au cotenu de la bannière personnalisée
header:not(.container) #featureContent { header:not(.container) #featureContent {
margin: 0 10px; margin: 0 10px;
}*/ }*/
@ -1012,7 +1012,18 @@ footer #footerSocials .zwiico-github:hover {
background: #777; background: #777;
} }
.cookieBox {
position: relative;
width: 15px;
height: 15px;
border: 1px solid blue;
}
.cookieBox .cookieClose {
position: absolute;
right: 2px;
top: -2px;
cursor: pointer;
}
/* Bloc */ /* Bloc */
.block { .block {

View File

@ -34,7 +34,7 @@
<?php $this->showNotification(); ?> <?php $this->showNotification(); ?>
<!-- Menu dans le fond du site avant la bannière --> <!-- Menu dans le fond du site avant la bannière -->
<?php if($this->getData(['theme', 'menu', 'position']) === 'body-first' || $this->getData(['theme', 'menu', 'position']) === 'top' ): ?> <?php if($this->getData(['theme', 'menu', 'position']) === 'body-first' || $this->getData(['theme', 'menu', 'position']) === 'top' ): ?>
<!-- Détermine si le menu est fixe en haut de page lorsque l'utilisateur n'est pas connecté --> <!-- Détermine si le menu est fixe en haut de page lorsque l'utilisateur n'est pas connecté -->
<?php <?php
if ( $this->getData(['theme', 'menu', 'position']) === 'top' if ( $this->getData(['theme', 'menu', 'position']) === 'top'
@ -52,9 +52,9 @@
<?php echo $this->getData(['theme','menu','burgerContent']) === 'logo' ? '<div class="notranslate" id="burgerLogo"><img src="'.helper::baseUrl(false).self::FILE_DIR.'source/'. $this->getData(['theme', 'menu', 'burgerLogo']) .'"></div>' : '' ;?> <?php echo $this->getData(['theme','menu','burgerContent']) === 'logo' ? '<div class="notranslate" id="burgerLogo"><img src="'.helper::baseUrl(false).self::FILE_DIR.'source/'. $this->getData(['theme', 'menu', 'burgerLogo']) .'"></div>' : '' ;?>
<?php echo template::ico('menu',null,null,'2em'); ?></div> <?php echo template::ico('menu',null,null,'2em'); ?></div>
<!-- fin du menu burger --> <!-- fin du menu burger -->
<?php <?php
$menuClass = $this->getData(['theme', 'menu', 'position']) === 'top' ? 'class="container-large"' : 'class="container"'; $menuClass = $this->getData(['theme', 'menu', 'position']) === 'top' ? 'class="container-large"' : 'class="container"';
$menuClass = $this->getData(['theme', 'menu', 'wide']) === 'none' ? 'class="container-large"' : 'class="container"'; $menuClass = $this->getData(['theme', 'menu', 'wide']) === 'none' ? 'class="container-large"' : 'class="container"';
?> ?>
<div id="menu" <?php echo $menuClass; ?> > <div id="menu" <?php echo $menuClass; ?> >
<?php $this->showMenu(); ?> <?php $this->showMenu(); ?>
@ -63,8 +63,8 @@
<?php endif; ?> <?php endif; ?>
<!-- Bannière dans le fond du site --> <!-- Bannière dans le fond du site -->
<?php if($this->getData(['theme', 'header', 'position']) === 'body'): ?> <?php if($this->getData(['theme', 'header', 'position']) === 'body'): ?>
<?php <?php
$headerClass = $this->getData(['theme', 'header', 'position']) === 'hide' ? 'displayNone' : ''; $headerClass = $this->getData(['theme', 'header', 'position']) === 'hide' ? 'displayNone' : '';
$headerClass .= $this->getData(['theme', 'header', 'tinyHidden']) ? ' bannerDisplay ' : ''; $headerClass .= $this->getData(['theme', 'header', 'tinyHidden']) ? ' bannerDisplay ' : '';
$headerClass .= $this->getData(['theme', 'header', 'wide']) === 'none' ? '' : 'container'; $headerClass .= $this->getData(['theme', 'header', 'wide']) === 'none' ? '' : 'container';
@ -92,7 +92,7 @@
<!-- Menu dans le fond du site après la bannière --> <!-- Menu dans le fond du site après la bannière -->
<?php if($this->getData(['theme', 'menu', 'position']) === 'body-second'): ?> <?php if($this->getData(['theme', 'menu', 'position']) === 'body-second'): ?>
<nav> <nav>
<!-- Menu burger --> <!-- Menu burger -->
<div id="toggle"> <div id="toggle">
@ -100,8 +100,8 @@
<?php echo $this->getData(['theme','menu','burgerContent']) === 'logo' ? '<div class="notranslate" id="burgerLogo"><img src="'.helper::baseUrl(false).self::FILE_DIR.'source/'. $this->getData(['theme', 'menu', 'burgerLogo']) .'"></div>' : '' ;?> <?php echo $this->getData(['theme','menu','burgerContent']) === 'logo' ? '<div class="notranslate" id="burgerLogo"><img src="'.helper::baseUrl(false).self::FILE_DIR.'source/'. $this->getData(['theme', 'menu', 'burgerLogo']) .'"></div>' : '' ;?>
<?php echo template::ico('menu',null,null,'2em'); ?></div> <?php echo template::ico('menu',null,null,'2em'); ?></div>
<!-- fin du menu burger --> <!-- fin du menu burger -->
<?php <?php
$menuClass = $this->getData(['theme', 'menu', 'wide']) === 'none' ? 'class="container-large"' : 'class="container"'; $menuClass = $this->getData(['theme', 'menu', 'wide']) === 'none' ? 'class="container-large"' : 'class="container"';
?> ?>
<div id="menu" <?php echo $menuClass; ?> > <div id="menu" <?php echo $menuClass; ?> >
<?php $this->showMenu(); ?></div> <?php $this->showMenu(); ?></div>
@ -130,7 +130,7 @@
): ?> ): ?>
<!-- Bannière dans le site --> <!-- Bannière dans le site -->
<?php echo ( $this->getData(['theme','header','linkHomePage']) && $this->getData(['theme','header','feature']) === 'wallpaper' ) ? '<a href="' . helper::baseUrl(false) . '">' : ''; ?> <?php echo ( $this->getData(['theme','header','linkHomePage']) && $this->getData(['theme','header','feature']) === 'wallpaper' ) ? '<a href="' . helper::baseUrl(false) . '">' : ''; ?>
<?php <?php
$headerClass = $this->getData(['theme', 'header', 'position']) === 'hide' ? 'displayNone' : ''; $headerClass = $this->getData(['theme', 'header', 'position']) === 'hide' ? 'displayNone' : '';
$headerClass .= $this->getData(['theme', 'header', 'tinyHidden']) ? ' bannerDisplay ' : ''; $headerClass .= $this->getData(['theme', 'header', 'tinyHidden']) ? ' bannerDisplay ' : '';
?> ?>
@ -183,9 +183,10 @@
<!-- 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-->
<?php $this->showCookies(); ?>
<!-- Les scripts --> <!-- Les scripts -->
<?php $this->showScript();?> <?php $this->showScript();?>
</body> </body>
</html> </html>