125 lines
4.8 KiB
PHP
125 lines
4.8 KiB
PHP
<?php
|
||
// htdocs/includes/accepter_cookies.php — CookieConsent v3 (correctif)
|
||
// Si tu as des traductions dans lang/fr.php / lang/ru.php, on les lit (optionnel)
|
||
$lang = $_SESSION['lang'] ?? 'fr';
|
||
$langFile = __DIR__ . "/../lang/{$lang}.php";
|
||
if (is_file($langFile)) {include $langFile;}
|
||
$t = isset($translations) && is_array($translations) ? $translations : [];
|
||
function tt($k, $d = '')
|
||
{global $t;return htmlspecialchars($t[$k] ?? $d, ENT_QUOTES, 'UTF-8');}
|
||
?>
|
||
<!--<a id="cc-manage" href="#" style="display:none"><?php echo tt('cookies_manage_link', 'Paramètres cookies') ?></a>-->
|
||
|
||
<link id="cc-css" rel="stylesheet" href="/js/cookieconsent.css"
|
||
onerror="this.href='https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.1.0/dist/cookieconsent.css'">
|
||
|
||
<script>
|
||
(function(){
|
||
// Textes (prend ceux de tes fichiers de langue si présents)
|
||
const TXT = {
|
||
title: <?php echo json_encode($t['cookies_title'] ?? 'Cookies & confidentialité') ?>,
|
||
desc: <?php echo json_encode($t['cookies_desc'] ?? "Nous utilisons des cookies essentiels. Avec votre accord, nous activons aussi l'analyse et la personnalisation.") ?>,
|
||
acceptAll: <?php echo json_encode($t['cookies_accept_all'] ?? 'Tout accepter') ?>,
|
||
rejectAll: <?php echo json_encode($t['cookies_reject_all'] ?? 'Tout refuser') ?>,
|
||
settings: <?php echo json_encode($t['cookies_settings'] ?? 'Personnaliser') ?>,
|
||
necessary: <?php echo json_encode($t['cookies_necessary'] ?? 'Essentiels (toujours actifs)') ?>,
|
||
analytics: <?php echo json_encode($t['cookies_analytics'] ?? 'Mesure d’audience') ?>,
|
||
personalization: <?php echo json_encode($t['cookies_personalization'] ?? 'Personnalisation') ?>,
|
||
save: <?php echo json_encode($t['cookies_save'] ?? 'Enregistrer') ?>,
|
||
};
|
||
|
||
const SRCS = [
|
||
'/js/cookieconsent.umd.js', // local d'abord
|
||
'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.1.0/dist/cookieconsent.umd.js',
|
||
'https://unpkg.com/vanilla-cookieconsent@3.1.0/dist/cookieconsent.umd.js'
|
||
];
|
||
|
||
function loadScriptSequential(i){
|
||
if(i >= SRCS.length){ console.error('[CC] Impossible de charger la lib'); return; }
|
||
const s = document.createElement('script');
|
||
s.src = SRCS[i];
|
||
s.onload = function(){
|
||
// v3 => CookieConsent.run(...)
|
||
if (window.CookieConsent && typeof CookieConsent.run === 'function'){ initCC(); }
|
||
else { console.warn('[CC] Script chargé mais API v3 absente → essai suivant'); loadScriptSequential(i+1); }
|
||
};
|
||
s.onerror = function(){ console.warn('[CC] Échec chargement', SRCS[i]); loadScriptSequential(i+1); };
|
||
document.head.appendChild(s);
|
||
}
|
||
|
||
function initCC(){
|
||
// Sécurité
|
||
if (!(window.CookieConsent && typeof CookieConsent.run === 'function')){
|
||
console.error('[CC] CookieConsent.run indisponible'); return;
|
||
}
|
||
|
||
CookieConsent.run({
|
||
cookie: {
|
||
name: 'cc_consent_v3',
|
||
path: '/',
|
||
sameSite: 'Lax',
|
||
expiresAfterDays: 180
|
||
},
|
||
guiOptions: {
|
||
consentModal: { layout: 'cloud', position: 'bottom center', equalWeightButtons: false, flipButtons: false },
|
||
preferencesModal: { layout: 'box', equalWeightButtons: true, flipButtons: false }
|
||
},
|
||
// v3: définir "categories" + "language" (obligatoires)
|
||
categories: {
|
||
necessary: { enabled: true, readOnly: true },
|
||
analytics: {},
|
||
personalization: {}
|
||
},
|
||
language: {
|
||
default: 'xx',
|
||
translations: {
|
||
xx: {
|
||
consentModal: {
|
||
title: TXT.title,
|
||
description: TXT.desc,
|
||
acceptAllBtn: TXT.acceptAll,
|
||
acceptNecessaryBtn: TXT.rejectAll,
|
||
showPreferencesBtn: TXT.settings
|
||
},
|
||
preferencesModal: {
|
||
title: TXT.title,
|
||
acceptAllBtn: TXT.acceptAll,
|
||
acceptNecessaryBtn: TXT.rejectAll,
|
||
savePreferencesBtn: TXT.save,
|
||
sections: [
|
||
{ title: TXT.necessary, description: '' },
|
||
{ title: TXT.analytics, description: '', linkedCategory: 'analytics' },
|
||
{ title: TXT.personalization, description: '', linkedCategory: 'personalization' }
|
||
]
|
||
}
|
||
}
|
||
}
|
||
},
|
||
|
||
// Hooks
|
||
onConsent: ({cookie}) => {},
|
||
onChange: ({changedCategories}) => {}
|
||
});
|
||
|
||
// Lien pour rouvrir
|
||
const manage = document.getElementById('cc-manage');
|
||
if (manage) {
|
||
manage.style.display = 'inline';
|
||
manage.addEventListener('click', (e)=>{ e.preventDefault(); CookieConsent.showPreferences(); });
|
||
}
|
||
|
||
}
|
||
|
||
|
||
// Lance le chargement (local → CDN fallback)
|
||
loadScriptSequential(0);
|
||
})();
|
||
</script>
|
||
|
||
<style>
|
||
#cc--main .cm__btn, #cc--main .pm__btn { border-radius: 999px; }
|
||
#cc-manage { position: fixed; right: 12px; bottom: 12px; font-size: 12px; opacity: .7; z-index: 99999; }
|
||
|
||
|
||
</style>
|