1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419:
<?php
$plugin_is_filter = 5 | THEME_PLUGIN;
$plugin_description = gettext("A plugin to add a cookie notify dialog to comply with the EU cookie law and Google's request regarding usages of Google Adwords, Analytics and more. Based on <a href='https://cookieconsent.osano.com/'>https://cookieconsent.osano.com/</a>");
$plugin_author = "Malte Müller (acrylian), Fred Sondaar (fretzl), Vincent Bourganel (vincent3569)";
$plugin_notice = gettext('Note: This plugin cannot block or delete cookies by itself without proper configuration that also may require customisations to your site.');
$option_interface = 'cookieConsent';
$plugin_category = gettext('Misc');
if (!zp_loggedin()) {
zp_register_filter('theme_head', 'cookieConsent::getCSS');
zp_register_filter('theme_head', 'cookieConsent::getJS');
}
class cookieConsent {
function __construct() {
setOptionDefault('zpcookieconsent_expirydays', 365);
setOptionDefault('zpcookieconsent_theme', 'block');
setOptionDefault('zpcookieconsent_position', 'bottom');
setOptionDefault('zpcookieconsent_colorpopup', '#000');
setOptionDefault('zpcookieconsent_colorbutton', '#f1d600');
setOptionDefault('zpcookieconsent_compliancetype', 'info');
setOptionDefault('zpcookieconsent_consentrevokable', 0);
setOptionDefault('zpcookieconsent_layout', 'basic');
}
function getOptionsSupported() {
$options = array(
gettext('Button: Agree') => array(
'key' => 'zpcookieconsent_buttonagree',
'type' => OPTION_TYPE_TEXTBOX,
'multilingual' => 1,
'desc' => gettext('Text used for the dismiss button in info complicance. Leave empty to use the default text.')),
gettext('Button: Allow cookies') => array(
'key' => 'zpcookieconsent_buttonallow',
'type' => OPTION_TYPE_TEXTBOX,
'multilingual' => 1,
'desc' => gettext('Text used for the button to allow cookies in opt-in and opt-out complicance. Leave empty to use the default text.')),
gettext('Button: Decline cookies') => array(
'key' => 'zpcookieconsent_buttondecline',
'type' => OPTION_TYPE_TEXTBOX,
'multilingual' => 1,
'desc' => gettext('Text used for the button to decline cookies in opt-in and opt-out complicance. Leave empty to use the default text.')),
gettext('Button: Learn more') => array(
'key' => 'zpcookieconsent_buttonlearnmore',
'type' => OPTION_TYPE_TEXTBOX,
'multilingual' => 1,
'desc' => gettext('Text used for the learn more info button. Leave empty to use the default text.')),
gettext('Button: Learn more - URL') => array(
'key' => 'zpcookieconsent_buttonlearnmorelink',
'type' => OPTION_TYPE_TEXTBOX,
'desc' => gettext('URL to your cookie policy / privacy info page.')),
gettext('Message') => array(
'key' => 'zpcookieconsent_message',
'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => 1,
'desc' => gettext('The message shown by the plugin. Leave empty to use the default text.')),
gettext('Cookie Policy') => array(
'key' => 'zpcookieconsent_policy',
'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => 1,
'desc' => gettext('The policy headline for the message text on some layout/theme settings.')),
gettext('Header') => array(
'key' => 'zpcookieconsent_header',
'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => 1,
'desc' => gettext('The header shown on some layout/theme settings.')),
gettext('Domain') => array(
'key' => 'zpcookieconsent_domain',
'type' => OPTION_TYPE_TEXTBOX,
'desc' => gettext('The domain for the consent cookie that Cookie Consent uses, to remember that users have consented to cookies. Useful if your website uses multiple subdomains, e.g. if your script is hosted at <code>www.example.com</code> you might override this to <code>example.com</code>, thereby allowing the same consent cookie to be read by subdomains like <code>foo.example.com</code>.')),
gettext('Expire') => array(
'key' => 'zpcookieconsent_expirydays',
'type' => OPTION_TYPE_TEXTBOX,
'desc' => gettext('The number of days Cookie Consent should store the user’s consent information for. Use -1 for no expiry.')),
gettext('Theme') => array(
'key' => 'zpcookieconsent_theme',
'type' => OPTION_TYPE_SELECTOR,
'selections' => array(
'block' => 'block',
'edgeless' => 'edgeless',
'classic' => 'classic',
gettext('custom') => 'custom'
),
'desc' => gettext('These are the included default themes. The chosen theme is added to the popup container as a CSS class in the form of .cc-style-THEME_NAME. Users can create their own themes.')),
gettext('Layout') => array(
'key' => 'zpcookieconsent_layout',
'type' => OPTION_TYPE_SELECTOR,
'selections' => array(
'basic' => 'basic',
'basic-close' => 'basic-close',
'basic-header' => 'basic-header'
),
'desc' => gettext('The layout style of the chosen theme.')),
gettext('Position') => array(
'key' => 'zpcookieconsent_position',
'type' => OPTION_TYPE_SELECTOR,
'selections' => array(
gettext('Top') => 'top',
gettext('Top left') => 'top-left',
gettext('Top right') => 'top-right',
gettext('Bottom') => 'bottom',
gettext('Bottom left') => 'bottom-left',
gettext('Bottom right') => 'bottom-right',
),
'desc' => gettext('Choose the position of the popup. Top and Bottom = banner, Top left/right, Bottom left/right = floating')),
gettext('Dismiss on Scroll') => array(
'key' => 'zpcookieconsent_dismissonscroll',
'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('Check to dismiss when users scroll a page [other than <em>Learn more</em> page].')),
gettext('Color - Popup') => array(
'key' => 'zpcookieconsent_colorpopup',
'type' => OPTION_TYPE_COLOR_PICKER,
'desc' => gettext('Choose the color of the popup background.')),
gettext('Color - Button') => array(
'key' => 'zpcookieconsent_colorbutton',
'type' => OPTION_TYPE_COLOR_PICKER,
'desc' => gettext('Choose the color of the button.')),
gettext('Compliance type') => array(
'key' => 'zpcookieconsent_compliancetype',
'type' => OPTION_TYPE_SELECTOR,
'selections' => array(
gettext('Info: Cookies are always allowed') => 'info',
gettext('Opt-in: Cookies are allowed after consent') => 'opt-in',
gettext('Opt-out: Cookies are allowed unless declined') => 'opt-out'
),
'desc' => gettext('Choose the compliance type required for your jurisdiction. Note that your site may require modification to properly apply this to your cookies. Also see the scripts option below.')),
gettext('Consent revokable') => array(
'key' => 'zpcookieconsent_consentrevokable',
'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('Check to allow revoking the consent as required in some jurisdictions.')),
gettext('Scripts to allow or block') => array(
'key' => 'zpcookieconsent_scripts',
'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('Add privacy related executional JS code (ad trackers statistics etc.) here to allow or block opt-in/opt-out compliances (without the script wrapper). As we cannot safely delete cookies set by third party scripts, we block their execution so they can neither set nor fetch their cookies.')),
gettext('External Scripts to allow or block') => array(
'key' => 'zpcookieconsent_externalscripts',
'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('Add URLs to privacy related external JS scripts as a comma separated list (ad trackers statistics etc.) here to allow or block opt-in/opt-out compliances (without the script wrapper). As we cannot safely delete cookies set by third party scripts, we block their execution so they can neither set nor fetch their cookies.'))
);
return $options;
}
static function getCSS() {
?>
<link rel="stylesheet" type="text/css" href="<?php echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/cookieconsent/cookieconsent.min.css" />
<?php
}
static function getJS() {
$message = gettext('This website uses cookies. By continuing to browse the site, you agree to our use of cookies.');
if (getOption('zpcookieconsent_message')) {
$message = get_language_string(getOption('zpcookieconsent_message'));
}
$dismiss = gettext('Agree');
if (getOption('zpcookieconsent_buttonagree')) {
$dismiss = get_language_string(getOption('zpcookieconsent_buttonagree'));
}
$allow = gettext('Allow cookies');
if (getOption('zpcookieconsent_buttonallow')) {
$allow = get_language_string(getOption('zpcookieconsent_buttonallow'));
}
$decline = gettext('Decline');
if (getOption('zpcookieconsent_buttondecline')) {
$decline = get_language_string(getOption('zpcookieconsent_buttondecline'));
}
$policy = gettext('Cookie Policy');
if (getOption('zpcookieconsent_policy')) {
$policy = get_language_string(getOption('zpcookieconsent_policy'));
}
$header = gettext('Cookies used on the website!');
if (getOption('zpcookieconsent_header')) {
$header = get_language_string(getOption('zpcookieconsent_header'));
}
$dataprivacy_info = getDataUsageNotice();
if (getOption('zpcookieconsent_buttonlearnmore')) {
$learnmore = get_language_string(getOption('zpcookieconsent_buttonlearnmore'));
} else {
$learnmore = $dataprivacy_info['linktext'];
}
if (getOption('zpcookieconsent_buttonlearnmorelink')) {
$link = getOption('zpcookieconsent_buttonlearnmorelink');
} else {
$link = $dataprivacy_info['url'];
}
$theme = 'block';
if (getOption('zpcookieconsent_theme')) {
$theme = getOption('zpcookieconsent_theme');
if (!in_array($theme, array('block', 'edgeless', 'classic', 'custom'))) {
$theme = 'block';
setOption('zpcookieconsent_theme', $theme, true);
}
}
$layout = 'basic';
if (getOption('zpcookieconsent_layout')) {
$layout = getOption('zpcookieconsent_layout');
}
$domain = '';
if (getOption('zpcookieconsent_domain')) {
$domain = getOption('zpcookieconsent_domain');
}
$position = getOption('zpcookieconsent_position');
$cookie_expiry = getOption('zpcookieconsent_expirydays');
$dismiss_on_scroll = "false";
if (getOption('zpcookieconsent_dismissonscroll') && strpos(sanitize($_SERVER['REQUEST_URI']), $link) === false) {
$dismiss_on_scroll = 100;
}
$color_popup = getOption('zpcookieconsent_colorpopup');
$color_button = getOption('zpcookieconsent_colorbutton');
$complicance_type = getOption('zpcookieconsent_compliancetype');
$consentrevokable = getOption('zpcookieconsent_consentrevokable');
if ($consentrevokable) {
$consentrevokable = 'true';
} else {
$consentrevokable = 'false';
}
?>
<script src="<?php echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/cookieconsent/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function () {
var cookieconsent_allowed = false;
window.cookieconsent.initialise({
palette: {
popup: {
background: "<?php echo $color_popup; ?>"
},
button: {
background: "<?php echo $color_button; ?>"
}
},
position: "<?php echo js_encode($position); ?>",
theme: "<?php echo js_encode($theme); ?>",
layout: "<?php echo js_encode($layout); ?>",
dismissOnScroll: <?php echo js_encode($dismiss_on_scroll); ?>,
type: '<?php echo $complicance_type; ?>',
revokable: <?php echo $consentrevokable; ?>,
cookie: {
domain: "<?php echo js_encode($domain); ?>",
expiryDays: <?php echo js_encode($cookie_expiry); ?>
},
content: {
href: "<?php echo html_encode($link); ?>",
header: '<?php echo js_encode($header); ?>',
message: "<?php echo js_encode($message); ?>",
dismiss: "<?php echo js_encode($dismiss); ?>",
allow: '<?php echo js_encode($allow); ?>',
deny: '<?php echo js_encode($decline); ?>',
link: "<?php echo js_encode($learnmore); ?>",
policy: "<?php echo js_encode($policy); ?>"
},
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
cookieconsent_allowed = true;
}
if (type == 'opt-out' && !didConsent) {
cookieconsent_allowed = false;
}
},
onStatusChange: function (status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
cookieconsent_allowed = true;
}
if (type == 'opt-out' && !didConsent) {
cookieconsent_allowed = false;
}
},
onRevokeChoice: function () {
var type = this.options.type;
if (type == 'opt-in') {
cookieconsent_allowed = false;
}
if (type == 'opt-out') {
cookieconsent_allowed = true;
}
}
});
if(cookieconsent_allowed) {
<?php
cookieConsent::printExternalConsentJS();
cookieConsent::printConsentJS();
?>
}
});
</script>
<?php
}
static function checkConsent() {
$complicance = getOption('zpcookieconsent_compliancetype');
$consent = zp_getCookie('cookieconsent_status');
switch ($complicance) {
case 'info':
return true;
case 'opt-in':
if ($consent && $consent == 'allow') {
return true;
} else {
return false;
}
case 'opt-out':
if (!$consent || $consent == 'allow') {
return true;
} else {
return false;
}
break;
}
return false;
}
static function printConsentJS() {
$scripts = getOption('zpcookieconsent_scripts');
echo zp_apply_filter('cookieconsent_consentscripts', $scripts, cookieconsent::checkConsent());
}
static function printExternalConsentJS() {
$option = trim(getOption('zpcookieconsent_externalscripts'));
$scripts = zp_apply_filter('cookieconsent_externalconsentscripts', $option, cookieconsent::checkConsent());
if(!empty($scripts)) {
$array = explode(',', $scripts);
$externaljs = '';
$total = count($array);
$count = '';
foreach($array as $url) {
$count++;
$externaljs .= '"' . $url . '"';
if($count != $total) {
$externaljs .= ',';
}
}
?>
var externalconsentjs = [<?php echo $externaljs; ?>];
$.each( externalconsentjs, function( key, value ) {
$.getScript( value, function( data, textStatus, jqxhr ) {
console.log( data );
console.log( textStatus );
console.log( jqxhr.status );
console.log( "Load was performed." );
});
});
<?php
}
}
}