This commit is contained in:
Diego Najar 2018-03-28 23:34:36 +02:00
parent 2439c68ff0
commit b75288e362
5 changed files with 148 additions and 0 deletions

View File

@ -240,6 +240,9 @@ $WHERE_AM_I = $Url->whereAmI();
// --- Objects shortcuts --- // --- Objects shortcuts ---
$L = $language; $L = $language;
// GDPR
Cookie::set('BLUDIT_GDPR_ALLOW_TRACKING', true, 7);
// DEBUG: Print constants // DEBUG: Print constants
// $arr = array_filter(get_defined_constants(), 'is_string'); // $arr = array_filter(get_defined_constants(), 'is_string');
// echo json_encode($arr); // echo json_encode($arr);

View File

@ -68,4 +68,29 @@ function sanitizeHTML(text) {
return text.replace(/[&<>"']/g, function(m) { return map[m]; }); return text.replace(/[&<>"']/g, function(m) { return map[m]; });
} }
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return false;
}
function deleteCookie(name) {
document.cookie = name+'=; Max-Age=-999;';
}
</script> </script>

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "GDPR Cookie",
"description": "General Data Protection Cookie Concent"
}
}

View File

@ -0,0 +1,10 @@
{
"author": "Bludit",
"email": "",
"website": "https://plugins.bludit.com",
"version": "2.3",
"releaseDate": "2018-01-23",
"license": "MIT",
"compatible": "2.3",
"notes": ""
}

View File

@ -0,0 +1,103 @@
<?php
class pluginGDPRCookie extends Plugin {
public function init()
{
$this->dbFields = array(
'enabled'=>true,
'message'=>'Allow to Google Analytics tracking you?'
);
}
public function form()
{
global $Language;
$html = '<div>';
$html .= '<label>Show concent to the user</label>';
$html .= '<select name="enabled">';
$html .= '<option value="true" '.($this->getValue('enabled')===true?'selected':'').'>'.$Language->get('Enabled').'</option>';
$html .= '<option value="false" '.($this->getValue('enabled')===false?'selected':'').'>'.$Language->get('Disabled').'</option>';
$html .= '</select>';
$html .= '<span class="tip">Show the consent to the user before loading the script of Google Analytics. The user can reject be tracked for Google Analytics.</span>';
$html .= '</div>';
return $html;
}
public function siteHead()
{
$html = '<style>
#pluginGDPRCookie {
display: block;
position: fixed;
top: 0;
background: #eee;
padding: 2px 10px;
font-size: 1em;
color: #555;
z-index: 2000;
width: 100%;
padding: 30px;
text-align: center;
border-bottom: 1px solid #999;
}
#pluginGDPRCookie div.buttons {
margin-top: 10px;
}
#pluginGDPRCookie button {
margin-right: 10px;
}
}
</style>';
return $html;
}
public function siteBodyBegin()
{
$script = <<<EOT
<script>
function pluginGDPRCookie_allowTracking() {
setCookie("BLUDIT_GDPR_ALLOW_TRACKING", true, 7);
pluginGDPRCookie_hideModal();
}
function pluginGDPRCookie_disableTracking() {
setCookie("BLUDIT_GDPR_ALLOW_TRACKING", false, 7);
pluginGDPRCookie_hideModal();
}
function pluginGDPRCookie_hideModal() {
document.getElementById("pluginGDPRCookie").style.display = "none";
}
</script>
EOT;
if ($this->getValue('enabled')) {
$html = '<div id="pluginGDPRCookie">';
$html .= '<div>Allow to Google Analytics tracking you?</div>';
$html .= '<div class="buttons">';
$html .= '<button id="pluginGDPRCookie_allowButton">Allow</button>';
$html .= '<button id="pluginGDPRCookie_denyButton">Deny</button>';
$html .= '</div>';
$html .= '</div>';
} else {
$html = '<script> window.onload=function() { allowTracking(); }</script>';
}
$script .= '
<script>
window.onload=function() {
document.getElementById("pluginGDPRCookie_allowButton").addEventListener("click", pluginGDPRCookie_allowTracking);
document.getElementById("pluginGDPRCookie_denyButton").addEventListener("click", pluginGDPRCookie_disableTracking);
}
</script>
';
return $script.$html;
}
}