Google Translate Cookie.

manque : effacer les cookies internes à ga et gt
manque : bug lien footer inopérant page traduite auto
This commit is contained in:
Fred Tempez 2021-11-28 19:30:52 +01:00
parent 4c3e947ffa
commit df18c2441a
6 changed files with 75 additions and 45 deletions

View File

@ -223,17 +223,20 @@ core.start = function() {
var expires = "expires=" + e.toUTCString();
// Crée le cookie d'acceptation Google Analytics si l'ID a été saisie
var analytics = "<?php echo $this->getData(['config', 'seo', 'analyticsId']);?>";
// l'Id GA est défini dans la configuration, afficher la checkbox d'acceptation
if( analytics.length > 0){
// Traitement du retour de la checkbox
if ($("#googleAnalytics").is(":checked")) {
// L'URL du serveur faut TRUE
document.cookie = "ZWII_COOKIE_GA_CONSENT=" + "<?php echo $_SERVER['PHP_SELF']; ?>" + ";" + domain + ";" + path + ";" + samesite + ";" + expires;
} else {
document.cookie = "ZWII_COOKIE_GA_CONSENT=false;" + 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=" + "<?php echo $_SERVER['PHP_SELF']; ?>" + ";" + domain + ";" + path + ";" + samesite + ";" + expires;
} else {
document.cookie = "ZWII_COOKIE_GA_CONSENT=false;" + domain + ";" + path + ";" + samesite + ";" + expires;
}
// Traitement du retour de la checkbox
if ($("#googleTranslate").is(":checked")) {
// L'URL du serveur faut TRUE
document.cookie = "ZWII_COOKIE_GT_CONSENT=" + "<?php echo $_SERVER['PHP_SELF']; ?>" + ";" + domain + ";" + path + ";" + samesite + ";" + expires;
} else {
document.cookie = "ZWII_COOKIE_GT_CONSENT=false;" + domain + ";" + path + ";" + samesite + ";" + expires;
document.cookie = "googtrans=fr/fr;" + domain + ";" + path + ";" + samesite + ";" + expires;
}
// Stocke le cookie d'acceptation
@ -276,7 +279,7 @@ core.start = function() {
* Commande de gestion des cookies dans le footer
*/
$("#footerLinkCookie").on("click", function() {
$(".footerShowCookieConsent").on("click", function() {
$("#cookieConsent").removeClass("displayNone");
});

View File

@ -256,6 +256,7 @@ class common {
if ( $this->getData(['config', 'i18n', 'enable']) === true
AND $this->getData(['config', 'i18n','scriptGoogle']) === true
AND $this->getData(['config', 'i18n','autoDetect']) === true
AND $this->getInput('ZWII_COOKIE_GT_CONSENT') === $_SERVER['PHP_SELF']
AND $this->getInput('ZWII_I18N_SITE') !== ''
AND !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) )
{
@ -1187,15 +1188,15 @@ class common {
}
/**
* Affiche le consentement aux cookies
* Affiche le consentement des cookies
*/
public function showCookies() {
// Gestion des cookies intégrée
// Gestion des cookies interne active
if ($this->getData(['config', 'cookieConsent']) === true )
{
// Détermine si le bloc doit être affiché selon la validité du cookie
// L'URL du serveur faut TRUE
// Détermine si le bloc doit être affiché selon la validité du cookie : l'URL du serveur faut TRUE
// Pour éviter la propagation (à revoir avec Sylvain)
$item = '<div id="cookieConsent"';
$item .= $this->getInput('ZWII_COOKIE_CONSENT') !== $_SERVER['PHP_SELF'] ? '>' : ' class="displayNone">';
// Bouton de fermeture
@ -1207,6 +1208,7 @@ class common {
$item .= '<p>' . $this->getData(['locale', 'cookies', 'cookiesZwiiText']) . '</p>';
// Formulaire de réponse
$item .= '<form method="POST" action="" id="cookieForm">';
// Checkbox Google Analytics
$analytics = $this->getData(['config', 'seo', 'analyticsId']);
$stateCookieGA = $this->getInput('ZWII_COOKIE_GA_CONSENT') === $_SERVER['PHP_SELF'] ? 'checked="checked"' : '';
if( $analytics !== null AND $analytics !== '' ) {
@ -1214,10 +1216,18 @@ class common {
$item .= '<input type="checkbox" id="googleAnalytics" name="googleAnalytics" value="GA" ' . $stateCookieGA . '>';
$item .= '<label for="googleAnalytics">' . $this->getData(['locale', 'cookies', 'cookiesCheckboxGaText']) . '</label>';
}
// Traduction automatique active
if ( $this->getData(['config', 'i18n','scriptGoogle']) === true ) {
// Checkbox Google Translate
$stateCookieGT = $this->getInput('ZWII_COOKIE_GT_CONSENT') === $_SERVER['PHP_SELF'] ? 'checked="checked"' : '';
$item .= '<p>' . $this->getData(['locale', 'cookies', 'cookiesGtText']) . '</p>';
$item .= '<input type="checkbox" id="googleTranslate" name="googleTranslate" value="GT" ' . $stateCookieGT . '>';
$item .= '<label for="googleTranslate">' . $this->getData(['locale', 'cookies', 'cookiesCheckboxGtText']) . '</label>';
}
$item .= '<br><br>';
$item .= '<input type="submit" id="cookieConsentConfirm" value="' . $this->getData(['locale', 'cookies', 'cookiesButtonText']) . '">';
$item .= '</form>';
// mentions légales si la page est définie
// Mentions légales si une page est définie
$legalPage = $this->getData(['locale', 'legalPageId']);
if ($legalPage !== 'none') {
$item .= '<p><a href="' . helper::baseUrl() . $legalPage . '">' . $this->getData(['locale', 'cookies', 'cookiesLinkMlText']) . '</a></p>';
@ -1492,7 +1502,7 @@ class common {
$items .= '<span id="footerDisplayCookie"';
$items .= ($this->getData(['config', 'cookieConsent']) === false && $this->getData(['theme', 'footer', 'displayCookie']) === false)? ' class="displayNone" >' : '>';
$label = empty($this->getData(['locale', 'cookies', 'cookiesFooterText'])) ? 'Confidentialité' : $this->getData(['locale', 'cookies', 'cookiesFooterText']) ;
$items .= '<wbr>&nbsp;|&nbsp;<a href="javascript:void(0)" id="footerLinkCookie">'. $label .'</a>';
$items .= '<wbr>&nbsp;|&nbsp;<a href="javascript:void(0)" class="footerShowCookieConsent">'. $label .'</a>';
$items .= '</span>';
// Affichage du lien de connexion
if(
@ -1753,8 +1763,9 @@ class common {
}
// Retourne les items du menu
echo '<ul class="navMain" id="menuLeft">' . $itemsLeft . '</ul><ul class="navMain" id="menuRight">' . $itemsRight;
if ($this->getData(['config', 'i18n', 'enable']) === true) {
echo $this->showi18n();
if ($this->getData(['config', 'i18n', 'enable']) === true
) {
echo $this->showi18n();
}
echo '</ul>';
}
@ -2114,6 +2125,7 @@ class common {
OR (
$this->getData(['config', 'i18n','scriptGoogle']) === true
AND $this->getData(['config', 'i18n',$key]) === 'script'
AND $this->getInput('ZWII_COOKIE_GT_CONSENT') === $_SERVER['PHP_SELF']
)
) {
if (
@ -2791,33 +2803,34 @@ class core extends common {
}
// Chargement de la bibliothèque googtrans
// Le script de traduction est sélectionné
if ($this->getData(['config', 'i18n', 'enable']) === true) {
// Trad auto
if ( $this->getData(['config', 'i18n','scriptGoogle']) === true
// et la traduction de la langue courante est automatique
AND ( $this->getInput('ZWII_I18N_SCRIPT') !== ''
// Ou traduction automatique
OR $this->getData(['config', 'i18n','autoDetect']) === true
)
// Cas des pages d'administration
// Pas connecté
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUrl(1) !== 'login'
// Ou connecté avec option active
OR ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getData(['config', 'i18n','admin']) === true
)
AND ( $this->getInput('ZWII_I18N_SCRIPT') !== ''
// Ou traduction automatique
OR $this->getData(['config', 'i18n','autoDetect']) === true
)
// Le cookie est accepté par le client
AND $this->getInput('ZWII_COOKIE_GT_CONSENT') === $_SERVER['PHP_SELF']
// Cas des pages d'administration
// Pas connecté
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUrl(1) !== 'login'
// Ou connecté avec option active
OR ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getData(['config', 'i18n','admin']) === true
)
) {
) {
// Paramètre du script
setrawcookie("googtrans", '/fr/'. $this->getInput('ZWII_I18N_SCRIPT') , time() + 3600, helper::baseUrl());
// Chargement de la librairie
$this->addOutput([
'vendor' => array_merge($this->output['vendor'], ['i18n'])
]);
}
}
}
// Erreurs
if($access === 'login') {

View File

@ -707,6 +707,7 @@ if ($this->getData(['core', 'dataVersion']) < 11200) {
$this->setData(['locale', 'cookies', 'cookieTitleText', 'Gérer les cookies']);
$this->setData(['locale', 'cookies', 'cookieLinkMlText', 'Consulter les mentions légales']);
$this->setData(['locale', 'cookies', 'cookieCheckboxGaText', 'Autorisation des cookies Google Analytics']);
$this->setData(['locale', 'cookies', 'cookieCheckboxGtText', 'Autorisation des cookies Google Translate']);
$this->setData(['locale', 'cookies', 'cookiesButtonText', 'J\'ai compris']);
// Mise à jour

View File

@ -445,6 +445,7 @@ class config extends common {
'cookiesTitleText' => $this->getInput('localeCookiesTitleText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesLinkMlText' => $this->getInput('localeCookiesLinkMlText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesCheckboxGaText' => $this->getInput('localeCookiesCheckboxGaText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesCheckboxGtText' => $this->getInput('localeCookiesCheckboxGtText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesFooterText' => $this->getInput('localeCookiesFooterText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesButtonText' =>$this->getInput('localeCookiesButtonText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent']))
]

View File

@ -200,19 +200,30 @@
<div class="col8">
<?php echo template::textarea('localeCookiesGaText', [
'help' => 'Saisissez le message pour les cookies déposés par Google Analytics, le consentement est requis.',
'label' => 'Cookies Google Analytics',
'label' => 'Cookies Google Analytics et Translate',
'value' => $this->getData(['locale', 'cookies', 'cookiesGaText']),
'placeHolder' => '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.'
]); ?>
</div>
<div class="col4">
<?php echo template::text('localeCookiesCheckboxGaText', [
'help' => 'Saisissez le texte de la case à cocher Google Analytics.',
'label' => 'Checkbox Google Analytics',
'value' => $this->getData(['locale', 'cookies', 'cookiesCheckboxGaText']),
'placeHolder' => 'Autorisation des cookies Google Analytics'
]); ?>
<div class="row">
<div class="col12">
<?php echo template::text('localeCookiesCheckboxGaText', [
'help' => 'Saisissez le texte de la case à cocher Google Analytics.',
'label' => 'Checkbox Google Analytics',
'value' => $this->getData(['locale', 'cookies', 'cookiesCheckboxGaText']),
'placeHolder' => 'Autorisation des cookies Google Analytics'
]); ?>
</div>
<div class="col12">
<?php echo template::text('localeCookiesCheckboxGtText', [
'help' => 'Saisissez le texte de la case à cocher Google Translate.',
'label' => 'Checkbox Google Translate',
'value' => $this->getData(['locale', 'cookies', 'cookiesCheckboxGtText']),
'placeHolder' => 'Autorisation des cookies Google Translate'
]); ?>
</div>
</div>
</div>
</div>
<div class="row">

View File

@ -80,6 +80,7 @@ class init extends common {
'cookiesTitleText' => 'Gérer les cookies',
'cookiesLinkMlText' => 'Consulter les mentions légales',
'cookiesCheckboxGaText' => 'Autorisation des cookies Google Analytics',
'cookiesCheckboxGtText' => 'Autorisation des cookies Google Translate',
'cookiesFooterText' => 'Confidentialité',
'cookiesButtonText' => 'J\'ai compris'
]