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

View File

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

View File

@ -445,6 +445,7 @@ class config extends common {
'cookiesTitleText' => $this->getInput('localeCookiesTitleText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), 'cookiesTitleText' => $this->getInput('localeCookiesTitleText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesLinkMlText' => $this->getInput('localeCookiesLinkMlText', 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'])), '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'])), 'cookiesFooterText' => $this->getInput('localeCookiesFooterText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])),
'cookiesButtonText' =>$this->getInput('localeCookiesButtonText', 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"> <div class="col8">
<?php echo template::textarea('localeCookiesGaText', [ <?php echo template::textarea('localeCookiesGaText', [
'help' => 'Saisissez le message pour les cookies déposés par Google Analytics, le consentement est requis.', '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']), '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.' '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>
<div class="col4"> <div class="col4">
<?php echo template::text('localeCookiesCheckboxGaText', [ <div class="row">
'help' => 'Saisissez le texte de la case à cocher Google Analytics.', <div class="col12">
'label' => 'Checkbox Google Analytics', <?php echo template::text('localeCookiesCheckboxGaText', [
'value' => $this->getData(['locale', 'cookies', 'cookiesCheckboxGaText']), 'help' => 'Saisissez le texte de la case à cocher Google Analytics.',
'placeHolder' => 'Autorisation des cookies 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> </div>
<div class="row"> <div class="row">

View File

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