1
0
Fork 0

added files

This commit is contained in:
mwalbeck 2016-06-10 15:03:45 +02:00
commit 3aea4905be
9 changed files with 303 additions and 0 deletions

21
LICENSE Executable file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Magnus Walbeck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

5
README.md Executable file
View file

@ -0,0 +1,5 @@
# Grav EU Cookie Policy Plugin
`EU Cookie Policy` is a [Grav](http://github.com/getgrav/grav) Plugin and allows to display a banner on the bottom of your page to comply with the EU cookie law.
This is a cut down fork of https://github.com/giansi/grav-plugin-cookies-policy.

34
assets/css/cookiechoices.css Executable file
View file

@ -0,0 +1,34 @@
#cookieChoiceInfo {
background-color: #FFF;
color: #000;
line-height: 1rem;
padding: 8px;
position: fixed;
text-align: center;
bottom: 0;
width: 100%;
z-index: 10000;
border-top: 3px solid #333;
}
#cookieChoiceInfo a{
padding: 5px;
border: 1px solid #333;
background-color: #555;
color: #fff;
display: inline-block;
margin-left: 24px;
}
@media screen and (max-width : 1280px) {
#cookieChoiceInfo span {
width: 100%;
}
#cookieChoiceInfo a{
min-width: 100px;
margin-top: 10px;
}
}

120
assets/js/cookiechoices.js Executable file
View file

@ -0,0 +1,120 @@
(function(window) {
if (!!window.cookieChoices) {
return window.cookieChoices;
}
var document = window.document;
// IE8 does not support textContent, so we should fallback to innerText.
var supportsTextContent;
var cookieChoices = (function() {
var cookieName = 'displayCookieConsent';
var cookieConsentId = 'cookieChoiceInfo';
var dismissLinkId = 'cookieChoiceDismiss';
function _createHeaderElement(cookieText, dismissText, linkText, linkHref) {
_checkForTextContentSupport();
//var butterBarStyles = '';
var cookieConsentElement = document.createElement('div');
cookieConsentElement.id = cookieConsentId;
//cookieConsentElement.style.cssText = butterBarStyles;
cookieConsentElement.appendChild(_createConsentText(cookieText));
if (!!linkText && !!linkHref) {
cookieConsentElement.appendChild(_createInformationLink(linkText, linkHref));
}
cookieConsentElement.appendChild(_createDismissLink(dismissText));
return cookieConsentElement;
}
function _setElementText(element, text) {
if (supportsTextContent) {
element.textContent = text;
} else {
element.innerText = text;
}
}
function _createConsentText(cookieText) {
var consentText = document.createElement('span');
_setElementText(consentText, cookieText);
return consentText;
}
function _createDismissLink(dismissText) {
var dismissLink = document.createElement('a');
_setElementText(dismissLink, dismissText);
dismissLink.id = dismissLinkId;
dismissLink.href = '#';
return dismissLink;
}
function _createInformationLink(linkText, linkHref) {
var infoLink = document.createElement('a');
_setElementText(infoLink, linkText);
infoLink.href = linkHref;
infoLink.target = '_blank';
return infoLink;
}
function _dismissLinkClick() {
_saveUserPreference();
_removeCookieConsent();
return false;
}
function _showCookieConsent(cookieText, dismissText, linkText, linkHref) {
if (_shouldDisplayConsent()) {
_removeCookieConsent();
var consentElement = _createHeaderElement(cookieText, dismissText, linkText, linkHref);
var fragment = document.createDocumentFragment();
fragment.appendChild(consentElement);
document.body.appendChild(fragment.cloneNode(true));
document.getElementById(dismissLinkId).onclick = _dismissLinkClick;
}
}
function showCookieConsentBar(cookieText, dismissText, linkText, linkHref) {
_showCookieConsent(cookieText, dismissText, linkText, linkHref, false);
}
function _removeCookieConsent() {
var cookieChoiceElement = document.getElementById(cookieConsentId);
if (cookieChoiceElement != null) {
cookieChoiceElement.parentNode.removeChild(cookieChoiceElement);
}
}
function _saveUserPreference() {
// Set the cookie expiry to one year after today.
var expiryDate = new Date();
expiryDate.setFullYear(expiryDate.getFullYear() + 1);
document.cookie = cookieName + '=y; expires=' + expiryDate.toGMTString();
}
function _shouldDisplayConsent() {
// Display the header only if the cookie has not been set.
return !document.cookie.match(new RegExp(cookieName + '=([^;]+)'));
}
function _checkForTextContentSupport() {
try{
supportsTextContent = 'textContent' in document.body;
} catch(e){
supportsTextContent = false;
}
}
var exports = {};
exports.showCookieConsentBar = showCookieConsentBar;
return exports;
})();
window.cookieChoices = cookieChoices;
return cookieChoices;
})(this);

43
blueprints.yaml Executable file
View file

@ -0,0 +1,43 @@
name: EU Cookie Policy
version: 1.0.1
description: ""
icon: gavel
author:
name: Magnus Walbeck
email: admin@walbeck.dk
url:
homepage:
demo:
keywords: plugin, cookie, policy, european, law
bugs:
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
type:
type: select
label: Type
size: small
default: Bar
options:
bar: Bar
help: Choose the displayed banner type
url:
type: text
label: Privacy route
size: medium
placeholder: http://example.com/privacy-url
help: Add here the route that points the full privacy page

53
eucookiepolicy.php Executable file
View file

@ -0,0 +1,53 @@
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
class EuCookiePolicyPlugin extends Plugin
{
public static function getSubscribedEvents() {
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
];
}
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
]);
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* if enabled on this page, load the JS + CSS theme.
*/
public function onTwigSiteVariables()
{
$type = strtolower($this->config->get('plugins.eucookiepolicy.type'));
$this->grav['assets']->addJs('plugin://eucookiepolicy/assets/js/cookiechoices.js');
$this->grav['assets']->addCss('plugin://eucookiepolicy/assets/css/cookiechoices.css', -999);
$twig = $this->grav['twig'];
$twig->twig_vars['eucookiepolicy_cookie_type'] = $type;
$twig->twig_vars['eucookiepolicy_url'] = $this->config->get('plugins.eucookiepolicy.url');
$twig->twig_vars['eucookiepolicy_markup'] = $twig->twig->render('partials/eucookiepolicy.html.twig', array(
'eucookiepolicy_cookie_type' => $twig->twig_vars['eucookiepolicy_cookie_type'],
'eucookiepolicy_url' => $twig->twig_vars['eucookiepolicy_url']
));
}
}

3
eucookiepolicy.yaml Executable file
View file

@ -0,0 +1,3 @@
enabled: true
type: bar
url: 'http://example.com/privacy-url'

19
languages.yaml Executable file
View file

@ -0,0 +1,19 @@
en:
PLUGINS:
EU_COOKIE_POLICY:
MESSAGE: "We use cookies to improve your experience on this site. By using walbeck.dk you accept our use of cookies"
PRIVACY: "Learn more"
CLOSE: "OK"
da:
PLUGINS:
EU_COOKIE_POLICY:
MESSAGE: "Vi bruger cookies for at forbedre din oplevelse på siden. Ved at benytte walbeck.dk accepterer du vores brug af cookies."
PRIVACY: "Læs mere"
CLOSE: "OK"

View file

@ -0,0 +1,5 @@
<script>
document.addEventListener('DOMContentLoaded', function(event) {
cookieChoices.showCookieConsent{{ eucookiepolicy_cookie_type|capitalize }}("{{ 'PLUGINS.EU_COOKIE_POLICY.MESSAGE'|t }}","{{ 'PLUGINS.EU_COOKIE_POLICY.CLOSE'|t }}","{{ 'PLUGINS.EU_COOKIE_POLICY.PRIVACY'|t }}","{{ eucookiepolicy_url }}");
});
</script>