Implement cookie consent management across various scripts
This commit introduces a comprehensive cookie consent management system by integrating the `fxCookiesAllowMarketing()` function across multiple files. It ensures that marketing-related scripts, such as Facebook Pixel and Google Analytics, are only executed if the user has consented to cookies. Additionally, it enhances the cookie consent UI in `inc_footer.php` and `inc_header.php`, improving user experience and compliance with privacy regulations. The changes also include refactoring of cookie handling functions for better maintainability.
This commit is contained in:
150
inc_footer.php
150
inc_footer.php
@ -114,9 +114,7 @@ if (isset($tabEvenement) && $tabEvenement['general']['eve_commanditaires'] == "1
|
||||
<div class="social">
|
||||
<a href="http://www.facebook.com/pages/Ms1timing/387594717971765" target="_blank"><i class="fa fa-facebook-square"></i></a>
|
||||
<a href="https://twitter.com/ms1timing" target="_blank"><i class="fa fa-twitter-square"></i></a>
|
||||
<!--
|
||||
<a href="/index.php?cookies" ><img style="border: none;" width="30" src="<?php echo $vDomaine; ?>/images/cookie.png" alt="cookies" /></a>
|
||||
-->
|
||||
<a href="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?><?php echo (strpos($_SERVER['REQUEST_URI'], '?') === false) ? '?' : '&'; ?>cookies=1" title="<?php echo ($strLangue === 'fr') ? 'Gérer les témoins' : 'Manage cookies'; ?>"><img style="border: none;" width="30" src="<?php echo $vDomaine; ?>/images/cookie.svg" alt="cookies" /></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -183,12 +181,25 @@ if (isset($tabEvenement) && $tabEvenement['general']['eve_commanditaires'] == "1
|
||||
}
|
||||
|
||||
.cookie-consent-container {
|
||||
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.cookie-consent-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cookie-consent-links {
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#acceptCookies, #rejectCookies {
|
||||
@ -219,112 +230,69 @@ if (isset($tabEvenement) && $tabEvenement['general']['eve_commanditaires'] == "1
|
||||
<!-- MSIN-3860 -->
|
||||
|
||||
<div id="cookieConsent" class="cookie-consent">
|
||||
<p><?php echo afficheTexte('experience_cookies', 0, 1, 1); ?></p>
|
||||
|
||||
<div class="cookie-consent-container">
|
||||
|
||||
|
||||
<button id="acceptCookies"><?php echo afficheTexte('bouton_acceper_cookies', 0, 1, 1); ?></button>
|
||||
|
||||
<button id="rejectCookies"><?php echo afficheTexte('bouton_refuser_cookies', 0, 1, 1); ?></button>
|
||||
|
||||
<p class="mb-2 mb-md-0"><?php echo fxCookieConsentText('experience_cookies', $strLangue); ?></p>
|
||||
<div class="cookie-consent-actions">
|
||||
<button type="button" id="acceptCookies"><?php echo fxCookieConsentText('bouton_acceper_cookies', $strLangue); ?></button>
|
||||
<button type="button" id="rejectCookies"><?php echo fxCookieConsentText('bouton_refuser_cookies', $strLangue); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cookie-consent-links">
|
||||
<a href="<?php echo $vDomaine; ?>/page/cookie/<?php echo $strLangue; ?>"><?php echo fxCookieConsentText('politique_cookie', $strLangue); ?></a>
|
||||
</div>
|
||||
</br>
|
||||
|
||||
<a href="/page/cookie/<?php if ($strLangue != 'fr') { echo ("/en"); }?> "><?php echo afficheTexte('politique_cookie', 0, 1, 1); ?></a>       
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
<?php require_once 'inc_footer_scripts.php'; ?>
|
||||
|
||||
<script>
|
||||
// Function to disable all clicks within a specific div
|
||||
function disableClicks(divId) {
|
||||
document.getElementById(divId).addEventListener('click', blockClicks, true);
|
||||
}
|
||||
|
||||
// Function to block the click event
|
||||
function blockClicks(event) {
|
||||
event.stopPropagation(); // Stop the event from reaching its target
|
||||
event.preventDefault(); // Prevent the default action (like navigating a link)
|
||||
}
|
||||
|
||||
// Function to re-enable clicks within a specific div
|
||||
function enableClicks(divId) {
|
||||
document.getElementById(divId).removeEventListener('click', blockClicks, true);
|
||||
}
|
||||
|
||||
//MSIN-3860
|
||||
|
||||
// if (!getCookie('cookiesAccepted') && !getCookie('cookiesRejected')) {
|
||||
|
||||
|
||||
// $('#cookieConsent').fadeIn();
|
||||
// }
|
||||
|
||||
// Handle the acceptance of cookies
|
||||
$('#acceptCookies').click(function() {
|
||||
setCookie('cookiesAccepted', 'true', 365);
|
||||
$('#cookieConsent').fadeOut();
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Handle the rejection of cookies
|
||||
$('#rejectCookies').click(function() {
|
||||
setCookie('cookiesRejected', 'true', 365);
|
||||
$('#cookieConsent').fadeOut();
|
||||
enableClicks('page');
|
||||
|
||||
});
|
||||
|
||||
// Function to set a cookie
|
||||
function setCookie(cname, cvalue, exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
||||
let expires = "expires="+ d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||
document.cookie = cname + "=" + cvalue + ";expires=" + d.toUTCString() + ";path=/;SameSite=Lax";
|
||||
}
|
||||
|
||||
function deleteCookie(cname) {
|
||||
document.cookie = cname + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;SameSite=Lax";
|
||||
}
|
||||
|
||||
// Function to get a cookie
|
||||
function getCookie(cname) {
|
||||
let name = cname + "=";
|
||||
let decodedCookie = decodeURIComponent(document.cookie);
|
||||
let ca = decodedCookie.split(';');
|
||||
for(let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
var name = cname + "=";
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var ca = decodedCookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
|
||||
if (c.indexOf(name) === 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
$(function () {
|
||||
if (!getCookie('cookiesAccepted') && !getCookie('cookiesRejected')) {
|
||||
$('#cookieConsent').fadeIn();
|
||||
}
|
||||
|
||||
$('#acceptCookies').on('click', function () {
|
||||
deleteCookie('cookiesRejected');
|
||||
setCookie('cookiesAccepted', 'true', 365);
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
$('#rejectCookies').on('click', function () {
|
||||
deleteCookie('cookiesAccepted');
|
||||
setCookie('cookiesRejected', 'true', 365);
|
||||
$('#cookieConsent').fadeOut();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
if ((isset($_GET['cookies']))){
|
||||
?>
|
||||
<script>
|
||||
setCookie('cookiesAccepted', '', { expires: -1 });
|
||||
setCookie('cookiesRejected', '', { expires: -1 });
|
||||
window.location = window.location.href.split("?")[0];
|
||||
</script>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
require_once 'inc_footer_scripts.php'; ?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -2,14 +2,14 @@
|
||||
<?php
|
||||
global $vPage, $strCode, $vDomaine, $tabEvenement, $strStep, $strLangue, $arrTermesModalButtons, $strValidationMembership;
|
||||
|
||||
if (isset($tabEvenement['general']) && trim($tabEvenement['general']['eve_plugins']) != '') {
|
||||
echo trim($tabEvenement['general']['eve_plugins']);
|
||||
if (fxCookiesAllowMarketing()) {
|
||||
if (isset($tabEvenement['general']) && trim($tabEvenement['general']['eve_plugins']) != '') {
|
||||
echo trim($tabEvenement['general']['eve_plugins']);
|
||||
}
|
||||
|
||||
echo $vGoogleAnalytics;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php echo $vGoogleAnalytics;
|
||||
|
||||
if ($strLangue == 'fr') {
|
||||
$mem_login = "compte";
|
||||
} else {
|
||||
@ -76,6 +76,7 @@ $message = str_replace('%url%', $mem_login, $message_login);
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php if (fxCookiesAllowMarketing()) { ?>
|
||||
<script>
|
||||
window.fbAsyncInit = function () {
|
||||
FB.init({
|
||||
@ -97,6 +98,7 @@ $message = str_replace('%url%', $mem_login, $message_login);
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
<?php } ?>
|
||||
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo RECAPTCHA_SITE_KEY; ?>&hl=<?php echo $strLangue;
|
||||
if ($strLangue == 'fr') {
|
||||
echo '-CA';
|
||||
@ -1673,7 +1675,7 @@ if ($strLangue == 'fr') {
|
||||
}
|
||||
break;
|
||||
case 'evenements.php':
|
||||
if (isset($blnPopup) && $blnPopup) {
|
||||
if (fxCookiesAllowMarketing() && isset($blnPopup) && $blnPopup) {
|
||||
?>
|
||||
var now, lastTimePopupShowed;
|
||||
now = +new Date();
|
||||
|
||||
@ -144,7 +144,9 @@ if (!isset($strOGDescription)) {
|
||||
|
||||
<script type="text/javascript" src="<?php echo $vDomaine; ?>/min/index.php?g=js&version=v<?php echo _VERSION_CODE; ?>"></script>
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT']."/php/inc_facebook_pixel.php");
|
||||
if (fxCookiesAllowMarketing()) {
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/php/inc_facebook_pixel.php");
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
87
php/inc_cookie_consent.php
Normal file
87
php/inc_cookie_consent.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
function fxCookiesConsentAccepted(): bool
|
||||
{
|
||||
return isset($_COOKIE['cookiesAccepted']) && $_COOKIE['cookiesAccepted'] === 'true';
|
||||
}
|
||||
|
||||
function fxCookiesConsentRejected(): bool
|
||||
{
|
||||
return isset($_COOKIE['cookiesRejected']) && $_COOKIE['cookiesRejected'] === 'true';
|
||||
}
|
||||
|
||||
function fxCookiesConsentPending(): bool
|
||||
{
|
||||
return !fxCookiesConsentAccepted() && !fxCookiesConsentRejected();
|
||||
}
|
||||
|
||||
function fxCookiesAllowMarketing(): bool
|
||||
{
|
||||
return fxCookiesConsentAccepted();
|
||||
}
|
||||
|
||||
function fxCookiesConsentResetIfRequested(): void
|
||||
{
|
||||
if (!isset($_GET['cookies'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$past = time() - 3600;
|
||||
setcookie('cookiesAccepted', '', $past, '/');
|
||||
setcookie('cookiesRejected', '', $past, '/');
|
||||
unset($_COOKIE['cookiesAccepted'], $_COOKIE['cookiesRejected']);
|
||||
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?: '/';
|
||||
$query = [];
|
||||
|
||||
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||
}
|
||||
|
||||
unset($query['cookies']);
|
||||
$location = $path;
|
||||
|
||||
if ($query) {
|
||||
$location .= '?' . http_build_query($query);
|
||||
}
|
||||
|
||||
header('Location: ' . $location);
|
||||
exit;
|
||||
}
|
||||
|
||||
function fxCookieConsentText(string $clef, string $strLangue): string
|
||||
{
|
||||
$defaults = [
|
||||
'experience_cookies' => [
|
||||
'fr' => 'Nous utilisons des témoins (cookies) pour assurer le bon fonctionnement du site et, avec votre consentement, mesurer l\'audience. Vous pouvez accepter ou refuser les témoins non essentiels sans affecter votre inscription.',
|
||||
'en' => 'We use cookies to ensure the site works properly and, with your consent, measure traffic. You may accept or refuse non-essential cookies without affecting your registration.',
|
||||
],
|
||||
'bouton_acceper_cookies' => [
|
||||
'fr' => 'Tout accepter',
|
||||
'en' => 'Accept all',
|
||||
],
|
||||
'bouton_refuser_cookies' => [
|
||||
'fr' => 'Tout refuser',
|
||||
'en' => 'Refuse all',
|
||||
],
|
||||
'politique_cookie' => [
|
||||
'fr' => 'Politique de témoins',
|
||||
'en' => 'Cookie policy',
|
||||
],
|
||||
];
|
||||
|
||||
$lang = ($strLangue === 'en') ? 'en' : 'fr';
|
||||
$fallback = $defaults[$clef][$lang] ?? $clef;
|
||||
|
||||
if (!function_exists('afficheTexte')) {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
$text = afficheTexte($clef, 0, 1, 1);
|
||||
|
||||
if ($text === '' || $text === $clef || $text === '*' . $clef . '*') {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
@ -13,6 +13,10 @@
|
||||
//
|
||||
// pixcel facebook
|
||||
|
||||
if (!fxCookiesAllowMarketing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Facebook Pixel Code
|
||||
$mem_facebook_pixel=0;
|
||||
//echo $tabEvenement['general']['eve_facebook_pixel'];
|
||||
|
||||
@ -7,6 +7,7 @@ define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..') . '/');
|
||||
include_once APPLICATION_PATH . 'php/inc_fonctions_sl.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_fx_doc.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_settings.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_cookie_consent.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_mysql.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_dates.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_mail.php';
|
||||
@ -156,6 +157,10 @@ if (isset($_GET['reloadlogin'])) {
|
||||
|
||||
function fxsessionpixelfacebook($memarray)
|
||||
{
|
||||
if (!fxCookiesAllowMarketing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_SESSION['pixcel'][] = $memarray;
|
||||
}
|
||||
function fxcount($memarray)
|
||||
@ -242,7 +247,7 @@ function fxListFieldsValues($tabData, $strKey, $strTable, $strBdd)
|
||||
// créé : 2012-09-18
|
||||
function tcheckevents($category, $action, $label)
|
||||
{
|
||||
if ($category == "")
|
||||
if ($category == "" || !fxCookiesAllowMarketing())
|
||||
return "";
|
||||
else {
|
||||
$param = "'_trackEvent', '" . $category . "', '" . $action . "', '" . $label . "', 1";
|
||||
|
||||
@ -114,7 +114,10 @@ if ($tabMaintenance != null) {
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<?php echo $vGoogleAnalytics; ?>
|
||||
<?php if (fxCookiesAllowMarketing()) {
|
||||
echo $vGoogleAnalytics;
|
||||
} ?>
|
||||
<?php if (fxCookiesAllowMarketing()) { ?>
|
||||
<script>
|
||||
window.fbAsyncInit = function() {
|
||||
FB.init({
|
||||
@ -133,6 +136,7 @@ if ($tabMaintenance != null) {
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
<?php } ?>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
var $preloader = $('#preloader');
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/inc_cookie_consent.php';
|
||||
fxCookiesConsentResetIfRequested();
|
||||
|
||||
// a faire trouver une solution
|
||||
//ini_set('session.cookie_domain', '.ms1inscriptiondev.interne.ca');
|
||||
//ini_set('session.cookie_domain', '.ms1inscription.com');
|
||||
|
||||
@ -194,7 +194,7 @@ require_once("inc_header.php");
|
||||
// * Time : 09:02
|
||||
// */
|
||||
// pixcel facebook
|
||||
if (isset($tabEvenement['general']['eve_facebook_pixel'])) {
|
||||
if (fxCookiesAllowMarketing() && isset($tabEvenement['general']['eve_facebook_pixel'])) {
|
||||
if ($tabEvenement['general']['eve_facebook_pixel'] <> '') {
|
||||
?>
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user