diff --git a/assets/consent_manager_frontend.js b/assets/consent_manager_frontend.js index e3586f8..827741e 100644 --- a/assets/consent_manager_frontend.js +++ b/assets/consent_manager_frontend.js @@ -129,10 +129,12 @@ const cmCookieAPI = Cookies.withAttributes({ expires: cmCookieExpires, path: '/' cookieUids.forEach(function (uid) { consents.push(uid); addScript(consent_managerBox.querySelector('[data-uid="script-' + uid + '"]')); + removeScript(consent_managerBox.querySelector('[data-uid="script-unselect-' + uid + '"]')); }); } else { cookieUids.forEach(function (uid) { removeScript(consent_managerBox.querySelector('[data-uid="script-' + uid + '"]')); + addScript(consent_managerBox.querySelector('[data-uid="script-unselect-' + uid + '"]')); }); } }); @@ -144,11 +146,13 @@ const cmCookieAPI = Cookies.withAttributes({ expires: cmCookieExpires, path: '/' cookieUids.forEach(function (uid) { consents.push(uid); addScript(consent_managerBox.querySelector('[data-uid="script-' + uid + '"]')); + removeScript(consent_managerBox.querySelector('[data-uid="script-unselect-' + uid + '"]')); }); } else { el.checked = false; cookieUids.forEach(function (uid) { removeScript(consent_managerBox.querySelector('[data-uid="script-' + uid + '"]')); + addScript(consent_managerBox.querySelector('[data-uid="script-unselect-' + uid + '"]')); }); } }); diff --git a/assets/consent_manager_frontend.min.js b/assets/consent_manager_frontend.min.js index 6beb886..7077f12 100644 --- a/assets/consent_manager_frontend.min.js +++ b/assets/consent_manager_frontend.min.js @@ -1 +1 @@ -const cmCookieAPI = Cookies.withAttributes({ expires: cmCookieExpires, path: "/", domain: consent_manager_parameters.domain, sameSite: "Lax", secure: !1 }); function consent_manager_showBox() { var o = []; void 0 !== cmCookieAPI.get("consent_manager") && (cookieData = JSON.parse(cmCookieAPI.get("consent_manager")), cookieData.hasOwnProperty("version") && (o = cookieData.consents)), consent_managerBox = document.getElementById("consent_manager-background"), consent_managerBox.querySelectorAll("[data-cookie-uids]").forEach(function (e) { var n = !0; JSON.parse(e.getAttribute("data-cookie-uids")).forEach(function (e) { -1 === o.indexOf(e) && (n = !1) }), n && (e.checked = !0) }), consent_manager_parameters.hidebodyscrollbar && (document.querySelector("body").style.overflow = "hidden"), document.getElementById("consent_manager-background").classList.remove("consent_manager-hidden"); var e = consent_managerBox.querySelectorAll('input[type="checkbox"]')[0]; consent_managerBox.focus(), e && e.focus() } function consent_manager_hasconsent(e) { return void 0 !== cmCookieAPI.get("consent_manager") && -1 !== JSON.parse(cmCookieAPI.get("consent_manager")).consents.indexOf(e) } !function () { "use strict"; var a, e, r, n = 0, c = {}, s = [], o = -1, t = -1; function i(o) { var n, e, t; s = [], c = { consents: [], version: a, consentid: consent_manager_parameters.consentid, cachelogid: consent_manager_parameters.cachelogid }, "none" !== o ? r.querySelectorAll("[data-cookie-uids]").forEach(function (e) { var n = JSON.parse(e.getAttribute("data-cookie-uids")); e.checked || "all" === o ? n.forEach(function (e) { s.push(e), d(r.querySelector('[data-uid="script-' + e + '"]')) }) : n.forEach(function (e) { l(r.querySelector('[data-uid="script-' + e + '"]')) }) }) : r.querySelectorAll("[data-cookie-uids]").forEach(function (e) { var n = JSON.parse(e.getAttribute("data-cookie-uids")); e.disabled ? n.forEach(function (e) { s.push(e), d(r.querySelector('[data-uid="script-' + e + '"]')) }) : (e.checked = !1, n.forEach(function (e) { l(r.querySelector('[data-uid="script-' + e + '"]')) })) }), c.consents = s, cmCookieAPI.set("consent_manager", JSON.stringify(c)), void 0 === cmCookieAPI.get("consent_manager") ? (consent_manager_parameters.no_cookie_set = !0, console.warn("Addon consent_manager: Es konnte kein Cookie für die Domain " + consent_manager_parameters.domain + " gesetzt werden!")) : (n = new XMLHttpRequest, e = consent_manager_parameters.fe_controller + "?rex-api-call=consent_manager&buster=" + (new Date).getTime(), t = "domain=" + document.domain + "&consentid=" + consent_manager_parameters.consentid + "&buster=" + (new Date).getTime(), n.onerror = e => { console.error("Addon consent_manager: Fehler beim speichern des Consent! " + n.statusText) }, n.open("POST", e, !1), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"), n.setRequestHeader("Expires", "Thu, 1 Jan 1970 00:00:00 GMT"), n.setRequestHeader("Pragma", "no-cache"), n.send(t)), document.querySelectorAll(".consent_manager-show-box-reload").length || 1 === consent_manager_parameters.forcereload ? location.reload() : document.dispatchEvent(new CustomEvent("consent_manager-saved", { detail: JSON.stringify(s) })) } function m() { var e, n = consent_manager_parameters.domain; for (e in cmCookieAPI.get()) cmCookieAPI.remove(encodeURIComponent(e)), cmCookieAPI.remove(encodeURIComponent(e), { domain: n }), cmCookieAPI.remove(encodeURIComponent(e), { path: "/" }), cmCookieAPI.remove(encodeURIComponent(e), { domain: n, path: "/" }), cmCookieAPI.remove(encodeURIComponent(e), { domain: "." + n }), cmCookieAPI.remove(encodeURIComponent(e), { domain: "." + n, path: "/" }), Cookies.remove(encodeURIComponent(e), { domain: window.location.hostname }), Cookies.remove(encodeURIComponent(e), { path: "/" }), Cookies.remove(encodeURIComponent(e), { domain: window.location.hostname, path: "/" }) } function d(e) { var n; if (e && !e.children.length) { n = (new DOMParser).parseFromString(window.atob(e.getAttribute("data-script")), "text/html"); for (var o = 0; o < n.scripts.length; o++) { var t = document.createElement("script"); n.scripts[o].src ? t.src = n.scripts[o].src : t.innerHTML = n.scripts[o].innerHTML, e.appendChild(t) } } } function l(e) { e && (e.innerHTML = "") } function g() { r.querySelectorAll("[data-cookie-uids]").forEach(function (e) { var n = !0; JSON.parse(e.getAttribute("data-cookie-uids")).forEach(function (e) { -1 === s.indexOf(e) && (n = !1) }), n && (e.checked = !0) }), consent_manager_parameters.hidebodyscrollbar && (document.querySelector("body").style.overflow = "hidden"), document.getElementById("consent_manager-background").classList.remove("consent_manager-hidden"); var e = r.querySelectorAll('input[type="checkbox"]')[0]; r.focus(), e && e.focus() } consent_manager_parameters.no_cookie_set = !1, void 0 === cmCookieAPI.get("consent_manager") ? (cmCookieAPI.set("consent_manager_test", "test"), void 0 === cmCookieAPI.get("consent_manager_test") ? (n = 0, consent_manager_parameters.no_cookie_set = !0, console.warn("Addon consent_manager: Es konnte kein Cookie für die Domain " + consent_manager_parameters.domain + " gesetzt werden!")) : (cmCookieAPI.remove("consent_manager_test"), n = 1)) : (c = JSON.parse(cmCookieAPI.get("consent_manager"))).hasOwnProperty("version") && (s = c.consents, o = parseInt(c.version), t = parseInt(c.cachelogid)), "" !== consent_manager_box_template ? (r = (r = (new DOMParser).parseFromString(consent_manager_box_template, "text/html")).getElementById("consent_manager-background"), document.querySelectorAll("body")[0].appendChild(r), a = parseInt(consent_manager_parameters.version), e = parseInt(consent_manager_parameters.cachelogid), a === o && e === t || (n = 1, s = [], m()), s.forEach(function (e) { d(r.querySelector('[data-uid="script-' + e + '"]')) }), (consent_manager_parameters.initially_hidden || consent_manager_parameters.no_cookie_set) && (n = 0), n && g(), r.querySelectorAll(".consent_manager-close").forEach(function (e) { e.addEventListener("click", function () { return e.classList.contains("consent_manager-save-selection") ? (m(), i("selection")) : e.classList.contains("consent_manager-accept-all") ? (m(), i("all")) : e.classList.contains("consent_manager-accept-none") ? (m(), i("none")) : e.classList.contains("consent_manager-close") && (document.getElementById("consent_manager-detail").classList.contains("consent_manager-hidden") || document.getElementById("consent_manager-detail").classList.toggle("consent_manager-hidden")), consent_manager_parameters.hidebodyscrollbar && (document.querySelector("body").style.overflow = "auto"), document.getElementById("consent_manager-background").classList.add("consent_manager-hidden"), !1 }) }), document.getElementById("consent_manager-toggle-details") && document.getElementById("consent_manager-toggle-details").addEventListener("click", function () { return document.getElementById("consent_manager-detail").classList.toggle("consent_manager-hidden"), !1 }), document.getElementById("consent_manager-toggle-details") && document.getElementById("consent_manager-toggle-details").addEventListener("keydown", function (e) { if ("Enter" == e.key) return document.getElementById("consent_manager-detail").classList.toggle("consent_manager-hidden"), !1 }), document.querySelectorAll(".consent_manager-show-box, .consent_manager-show-box-reload").forEach(function (e) { e.addEventListener("click", function () { return g(), !1 }) })) : console.warn("Addon consent_manager: Keine Cookie-Gruppen / Cookies ausgewählt bzw. keine Domain zugewiesen! (" + location.hostname + ")") }(); +const cmCookieAPI=Cookies.withAttributes({expires:cmCookieExpires,path:"/",domain:consent_manager_parameters.domain,sameSite:"Lax",secure:!1});function consent_manager_showBox(){var e=[];void 0!==cmCookieAPI.get("consent_manager")&&(cookieData=JSON.parse(cmCookieAPI.get("consent_manager"))).hasOwnProperty("version")&&(e=cookieData.consents),(consent_managerBox=document.getElementById("consent_manager-background")).querySelectorAll("[data-cookie-uids]").forEach(function(n){var t=!0;JSON.parse(n.getAttribute("data-cookie-uids")).forEach(function(n){-1===e.indexOf(n)&&(t=!1)}),t&&(n.checked=!0)}),consent_manager_parameters.hidebodyscrollbar&&(document.querySelector("body").style.overflow="hidden"),document.getElementById("consent_manager-background").classList.remove("consent_manager-hidden");var n=consent_managerBox.querySelectorAll('input[type="checkbox"]')[0];consent_managerBox.focus(),n&&n.focus()}function consent_manager_hasconsent(e){return void 0!==cmCookieAPI.get("consent_manager")&&-1!==JSON.parse(cmCookieAPI.get("consent_manager")).consents.indexOf(e)}!function(){"use strict";var e,n=0,t={},o=[],a=-1,r=-1,c=-1,s=-1;if(consent_manager_parameters.no_cookie_set=!1,void 0===cmCookieAPI.get("consent_manager")?(cmCookieAPI.set("consent_manager_test","test"),void 0===cmCookieAPI.get("consent_manager_test")?(n=0,consent_manager_parameters.no_cookie_set=!0,console.warn("Addon consent_manager: Es konnte kein Cookie f\xfcr die Domain "+consent_manager_parameters.domain+" gesetzt werden!")):(cmCookieAPI.remove("consent_manager_test"),n=1)):(t=JSON.parse(cmCookieAPI.get("consent_manager"))).hasOwnProperty("version")&&(o=t.consents,c=parseInt(t.version),s=parseInt(t.cachelogid)),""===consent_manager_box_template){console.warn("Addon consent_manager: Keine Cookie-Gruppen / Cookies ausgew\xe4hlt bzw. keine Domain zugewiesen! ("+location.hostname+")");return}function i(n){if(o=[],t={consents:[],version:a,consentid:consent_manager_parameters.consentid,cachelogid:consent_manager_parameters.cachelogid},"none"!==n?e.querySelectorAll("[data-cookie-uids]").forEach(function(t){var a=JSON.parse(t.getAttribute("data-cookie-uids"));t.checked||"all"===n?a.forEach(function(n){o.push(n),l(e.querySelector('[data-uid="script-'+n+'"]')),m(e.querySelector('[data-uid="script-unselect-'+n+'"]'))}):a.forEach(function(n){m(e.querySelector('[data-uid="script-'+n+'"]')),l(e.querySelector('[data-uid="script-unselect-'+n+'"]'))})}):e.querySelectorAll("[data-cookie-uids]").forEach(function(n){var t=JSON.parse(n.getAttribute("data-cookie-uids"));n.disabled?t.forEach(function(n){o.push(n),l(e.querySelector('[data-uid="script-'+n+'"]')),m(e.querySelector('[data-uid="script-unselect-'+n+'"]'))}):(n.checked=!1,t.forEach(function(n){m(e.querySelector('[data-uid="script-'+n+'"]')),l(e.querySelector('[data-uid="script-unselect-'+n+'"]'))}))}),t.consents=o,cmCookieAPI.set("consent_manager",JSON.stringify(t)),void 0===cmCookieAPI.get("consent_manager"))consent_manager_parameters.no_cookie_set=!0,console.warn("Addon consent_manager: Es konnte kein Cookie f\xfcr die Domain "+document.domain+" gesetzt werden!");else{var r=new XMLHttpRequest,c=consent_manager_parameters.fe_controller+"?rex-api-call=consent_manager&buster="+new Date().getTime(),s="domain="+document.domain+"&consentid="+consent_manager_parameters.consentid+"&buster="+new Date().getTime();r.onerror=e=>{console.error("Addon consent_manager: Fehler beim speichern des Consent! "+r.statusText)},r.open("POST",c,!1),r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),r.setRequestHeader("Expires","Thu, 1 Jan 1970 00:00:00 GMT"),r.setRequestHeader("Pragma","no-cache"),r.send(s)}document.querySelectorAll(".consent_manager-show-box-reload").length||1===consent_manager_parameters.forcereload?location.reload():document.dispatchEvent(new CustomEvent("consent_manager-saved",{detail:JSON.stringify(o)}))}function d(){var e=consent_manager_parameters.domain;for(var n in cmCookieAPI.get())cmCookieAPI.remove(encodeURIComponent(n)),cmCookieAPI.remove(encodeURIComponent(n),{domain:e}),cmCookieAPI.remove(encodeURIComponent(n),{path:"/"}),cmCookieAPI.remove(encodeURIComponent(n),{domain:e,path:"/"}),cmCookieAPI.remove(encodeURIComponent(n),{domain:"."+e}),cmCookieAPI.remove(encodeURIComponent(n),{domain:"."+e,path:"/"}),Cookies.remove(encodeURIComponent(n),{domain:window.location.hostname}),Cookies.remove(encodeURIComponent(n),{path:"/"}),Cookies.remove(encodeURIComponent(n),{domain:window.location.hostname,path:"/"})}function l(e){var n;if(e&&!e.children.length){n=new DOMParser().parseFromString(window.atob(e.getAttribute("data-script")),"text/html");for(var t=0;tscripts as $uid => $script) { echo ''; } + foreach ($consent_manager->scriptsUnselect as $uid => $script) { + echo ''; + } ?> diff --git a/install.php b/install.php index 7ecc9bc..cf36d65 100644 --- a/install.php +++ b/install.php @@ -34,6 +34,7 @@ ->ensureColumn(new rex_sql_column('provider_link_privacy', 'varchar(255)')) ->ensureColumn(new rex_sql_column('definition', 'text')) ->ensureColumn(new rex_sql_column('script', 'text')) + ->ensureColumn(new rex_sql_column('script_unselect', 'text')) ->ensureColumn(new rex_sql_column('placeholder_text', 'text')) ->ensureColumn(new rex_sql_column('placeholder_image', 'varchar(255)')) ->ensureColumn(new rex_sql_column('createuser', 'varchar(255)')) diff --git a/lang/de_de.lang b/lang/de_de.lang index 63cef8c..c3fbaf3 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -30,6 +30,7 @@ consent_manager_cookiegroup_add = Gruppe erstellen consent_manager_cookiegroup_edit = Gruppe bearbeiten consent_manager_cookiegroup_required = diese Gruppe enthält die technisch notwendigen Dienste und Cookies consent_manager_cookiegroup_scripts = Skripte, die nach Einverständnis geladen werden +consent_manager_cookiegroup_scripts_unselect = Skripte, die nach Widerrufen des Einverständnisses geladen werden consent_manager_cookiegroup_scripts_notice = Skripte inklusive eingeben consent_manager_cookiegroup_nodomain_notice = Es wurde noch keine Domain oder keine Dienste zugeordnet! Im Frontent wird evtl. keine Consent-Box angezeigt. diff --git a/lang/en_gb.lang b/lang/en_gb.lang index 0d8b649..17fc8e1 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -27,7 +27,8 @@ consent_manager_cookiegroups = Services consent_manager_cookiegroup_add = Create service consent_manager_cookiegroup_edit = Edit service consent_manager_cookiegroup_required = this group contains required services and cookies -consent_manager_cookiegroup_scripts = Scripts which will be loaded once cookies are approved +consent_manager_cookiegroup_scripts = Scripts which will be loaded once consent is set +consent_manager_cookiegroup_scripts_unselect = Scripts will be loaded once consent is withdrawn consent_manager_cookiegroup_scripts_notice = Enter scripts including consent_manager_texts = Texts diff --git a/lang/sv_se.lang b/lang/sv_se.lang index 0893f0c..cf209c7 100644 --- a/lang/sv_se.lang +++ b/lang/sv_se.lang @@ -28,6 +28,7 @@ consent_manager_cookiegroup_add = Skapa cookie grupp consent_manager_cookiegroup_edit = Bearbeta cookie grupp consent_manager_cookiegroup_required = denna cookie-grupp innehåller de tekniskt nödvändiga cookies consent_manager_cookiegroup_scripts = Skript som laddas efter godkännande +consent_manager_cookiegroup_scripts_unselect = Skript som laddas efter att samtycket har återkallats consent_manager_cookiegroup_scripts_notice = Ange skript inklusive consent_manager_texts = Cookie texter diff --git a/lib/consent_manager_cache.php b/lib/consent_manager_cache.php index ad8ef9a..adf7e84 100644 --- a/lib/consent_manager_cache.php +++ b/lib/consent_manager_cache.php @@ -117,6 +117,7 @@ private function prepareCookie($clangId) } $cookie['definition'] = $defs; $cookie['script'] = base64_encode($cookie['script']); + $cookie['script_unselect'] = base64_encode($cookie['script_unselect']); $this->cookies[$clangId][$uid] = $cookie; /** @phpstan-ignore-line */ } } diff --git a/lib/consent_manager_frontend.php b/lib/consent_manager_frontend.php index 6f4bc89..2241267 100644 --- a/lib/consent_manager_frontend.php +++ b/lib/consent_manager_frontend.php @@ -14,6 +14,7 @@ class consent_manager_frontend public $domainName = ''; /** @phpstan-ignore-line */ public $links = []; /** @phpstan-ignore-line */ public $scripts = []; /** @phpstan-ignore-line */ + public $scriptsUnselect = []; /** @phpstan-ignore-line */ public $boxClass = ''; /** @phpstan-ignore-line */ public $cache = []; /** @phpstan-ignore-line */ public $version = ''; /** @phpstan-ignore-line */ @@ -95,10 +96,12 @@ public function setDomain($domain) if (isset($this->cache['cookies'][$clang][$uid])) { $this->cookies[$uid] = $this->cache['cookies'][$clang][$uid]; $this->scripts[$uid] = $this->cache['cookies'][$clang][$uid]['script']; + $this->scriptsUnselect[$uid] = $this->cache['cookies'][$clang][$uid]['script_unselect']; } } } $this->scripts = array_filter($this->scripts); + $this->scriptsUnselect = array_filter($this->scriptsUnselect); } if (isset($this->cache['texts'][$clang])) { $this->texts = $this->cache['texts'][$clang]; diff --git a/pages/cookie.php b/pages/cookie.php index 67e903d..8860261 100644 --- a/pages/cookie.php +++ b/pages/cookie.php @@ -56,8 +56,14 @@ $field->setAttributes(['class' => 'form-control codemirror', 'name' => $field->getAttribute('name'), 'data-codemirror-mode' => 'text/html']); $field->setLabel($addon->i18n('consent_manager_cookiegroup_scripts')); $field->setNotice($addon->i18n('consent_manager_cookiegroup_scripts_notice')); + + $field = $form->addTextAreaField('script_unselect'); + $field->setAttributes(['class' => 'form-control codemirror', 'name' => $field->getAttribute('name'), 'data-codemirror-mode' => 'text/html']); + $field->setLabel($addon->i18n('consent_manager_cookiegroup_scripts_unselect')); + $field->setNotice($addon->i18n('consent_manager_cookiegroup_scripts_notice')); } else { $form->addRawField(consent_manager_rex_form::getFakeTextarea($addon->i18n('consent_manager_cookiegroup_scripts'), $form->getSql()->getValue('script'))); + $form->addRawField(consent_manager_rex_form::getFakeTextarea($addon->i18n('consent_manager_cookiegroup_scripts_unselect'), $form->getSql()->getValue('script_unselect'))); } } if ('add' === $func) { @@ -66,6 +72,11 @@ $field->setAttributes(['class' => 'form-control codemirror', 'name' => $field->getAttribute('name'), 'data-codemirror-mode' => 'text/html']); $field->setLabel($addon->i18n('consent_manager_cookiegroup_scripts')); $field->setNotice($addon->i18n('consent_manager_cookiegroup_scripts_notice')); + + $field = $form->addTextAreaField('script_unselect'); + $field->setAttributes(['class' => 'form-control codemirror', 'name' => $field->getAttribute('name'), 'data-codemirror-mode' => 'text/html']); + $field->setLabel($addon->i18n('consent_manager_cookiegroup_scripts_unselect')); + $field->setNotice($addon->i18n('consent_manager_cookiegroup_scripts_notice')); } }