Cookie law support

This commit is contained in:
Silvan Calarco 2015-07-11 21:50:33 +02:00
parent 7efe291816
commit ece1d83bd2
7 changed files with 266 additions and 22 deletions

View File

@ -233,3 +233,22 @@ return $args;
} }
load_plugin_textdomain('theme-my-login' , get_site_url() . 'wp-content/plugins/theme-my-login/languages/'); load_plugin_textdomain('theme-my-login' , get_site_url() . 'wp-content/plugins/theme-my-login/languages/');
add_action('wp_head','hook_cookielaw');
function hook_cookielaw()
{
$outputlang = get_bloginfo("language");
$outputlang = substr($outputlang,0,2);
$message = __("This website uses cookies to improve user experience.",responsive);
$accepttext = __("I Understand",responsive);
$policytext = __("Cookie policy",responsive);
$policyurl = "/" . $outputlang . "/info/policy/";
$output = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . get_stylesheet_directory_uri() . "/styles/jquery.cookiebar.css\" />\n";
$output .= "<script type=\"text/javascript\" src=\"" . get_stylesheet_directory_uri() . "/scripts/jquery.js\"></script>\n";
$output .= "<script type=\"text/javascript\" src=\"" . get_stylesheet_directory_uri() . "/scripts/jquery.cookiebar.js\"></script>\n";
$output .= "<script type=\"text/javascript\">$(document).ready(function(){ $.cookieBar({" .
"message: \"" . $message . "\",acceptText: '" . $accepttext . "',".
"policyText: '" . $policytext . "',policyURL: '" . $policyurl . "' }); });</script>\n";
echo $output;
}

View File

@ -4,7 +4,7 @@ Translation management:
xgettext --default-domain=responsive --language=PHP --keyword=__ --keyword=_e --keyword=esc_attr_e --sort-by-file --copyright-holder="Silvan Calarco" --package-name=openmamba --package-version=1.0 --msgid-bugs-address="bugs@openmamba.org" ../*.php xgettext --default-domain=responsive --language=PHP --keyword=__ --keyword=_e --keyword=esc_attr_e --sort-by-file --copyright-holder="Silvan Calarco" --package-name=openmamba --package-version=1.0 --msgid-bugs-address="bugs@openmamba.org" ../*.php
2) 2)
msgmerge it.po responsive.po -o it.po msgmerge it_IT.po responsive.po -o it_IT.po
3) 3)
msgcat it.po | msgfmt -o it.mo - msgcat it_IT.po | msgfmt -o it_IT.mo -

Binary file not shown.

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Responsive Theme\n" "Project-Id-Version: Responsive Theme\n"
"Report-Msgid-Bugs-To: bugs@openmamba.org\n" "Report-Msgid-Bugs-To: bugs@openmamba.org\n"
"POT-Creation-Date: 2015-04-16 11:32+0200\n" "POT-Creation-Date: 2015-07-11 21:11+0200\n"
"PO-Revision-Date: 2014-12-08 16:25+0100\n" "PO-Revision-Date: 2014-12-08 16:25+0100\n"
"Last-Translator: Silvan Calarco <silvan.calarco@mambasoft.it>\n" "Last-Translator: Silvan Calarco <silvan.calarco@mambasoft.it>\n"
"Language-Team: Italian, Italy\n" "Language-Team: Italian, Italy\n"
@ -46,19 +46,19 @@ msgstr "Sito web fornito da"
msgid "WordPress" msgid "WordPress"
msgstr "WordPress" msgstr "WordPress"
#: ../functions.php:53 ../functions.php:64 #: ../functions.php:58 ../functions.php:69
msgid "for" msgid "for"
msgstr "per" msgstr "per"
#: ../functions.php:55 #: ../functions.php:60
msgid "File size:" msgid "File size:"
msgstr "Dimensione file:" msgstr "Dimensione file:"
#: ../functions.php:56 #: ../functions.php:61
msgid "Date" msgid "Date"
msgstr "Data" msgstr "Data"
#: ../functions.php:66 #: ../functions.php:71
msgid "" msgid ""
"Sorry, download is temporary unavailable. If the problem persists please " "Sorry, download is temporary unavailable. If the problem persists please "
"report the problem." "report the problem."
@ -66,23 +66,35 @@ msgstr ""
"Il download non è temporaneamente disponibile. Se il problema persiste ti " "Il download non è temporaneamente disponibile. Se il problema persiste ti "
"ringraziamo se ci puoi segnalare il problema." "ringraziamo se ci puoi segnalare il problema."
#: ../functions.php:146 #: ../functions.php:152
msgid "More languages..." msgid "More languages..."
msgstr "Altre lingue..." msgstr "Altre lingue..."
#: ../functions.php:149 #: ../functions.php:155
msgid "Features" msgid "Features"
msgstr "Caratteristiche" msgstr "Caratteristiche"
#: ../functions.php:153 #: ../functions.php:159
msgid "Requirements" msgid "Requirements"
msgstr "Requisiti" msgstr "Requisiti"
#: ../functions.php:157 #: ../functions.php:163
msgid "Preparation" msgid "Preparation"
msgstr "Preparazione" msgstr "Preparazione"
#: ../header-webbuild.php:89 #: ../functions.php:243
msgid "This website uses cookies to improve user experience."
msgstr "Questo sito utilizza i cookie per migliorare l'esperienza dell'utente."
#: ../functions.php:244
msgid "I Understand"
msgstr "Ho capito"
#: ../functions.php:245
msgid "Cookie policy"
msgstr "Informativa sui cookie"
#: ../header-webbuild.php:101
msgid "&darr; Skip to Main Content" msgid "&darr; Skip to Main Content"
msgstr "&darr; Salta al contenuto principale" msgstr "&darr; Salta al contenuto principale"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: openmamba 1.0\n" "Project-Id-Version: openmamba 1.0\n"
"Report-Msgid-Bugs-To: bugs@openmamba.org\n" "Report-Msgid-Bugs-To: bugs@openmamba.org\n"
"POT-Creation-Date: 2015-04-16 11:32+0200\n" "POT-Creation-Date: 2015-07-11 21:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -47,41 +47,53 @@ msgstr ""
msgid "WordPress" msgid "WordPress"
msgstr "" msgstr ""
#: ../functions.php:53 ../functions.php:64 #: ../functions.php:58 ../functions.php:69
msgid "for" msgid "for"
msgstr "" msgstr ""
#: ../functions.php:55 #: ../functions.php:60
msgid "File size:" msgid "File size:"
msgstr "" msgstr ""
#: ../functions.php:56 #: ../functions.php:61
msgid "Date" msgid "Date"
msgstr "" msgstr ""
#: ../functions.php:66 #: ../functions.php:71
msgid "" msgid ""
"Sorry, download is temporary unavailable. If the problem persists please " "Sorry, download is temporary unavailable. If the problem persists please "
"report the problem." "report the problem."
msgstr "" msgstr ""
#: ../functions.php:146 #: ../functions.php:152
msgid "More languages..." msgid "More languages..."
msgstr "" msgstr ""
#: ../functions.php:149 #: ../functions.php:155
msgid "Features" msgid "Features"
msgstr "" msgstr ""
#: ../functions.php:153 #: ../functions.php:159
msgid "Requirements" msgid "Requirements"
msgstr "" msgstr ""
#: ../functions.php:157 #: ../functions.php:163
msgid "Preparation" msgid "Preparation"
msgstr "" msgstr ""
#: ../header-webbuild.php:89 #: ../functions.php:243
msgid "This website uses cookies to improve user experience."
msgstr ""
#: ../functions.php:244
msgid "I Understand"
msgstr ""
#: ../functions.php:245
msgid "Cookie policy"
msgstr ""
#: ../header-webbuild.php:101
msgid "&darr; Skip to Main Content" msgid "&darr; Skip to Main Content"
msgstr "" msgstr ""

190
scripts/jquery.cookiebar.js Normal file
View File

@ -0,0 +1,190 @@
/*
* Copyright (C) 2012 PrimeBox (info@primebox.co.uk)
*
* This work is licensed under the Creative Commons
* Attribution 3.0 Unported License. To view a copy
* of this license, visit
* http://creativecommons.org/licenses/by/3.0/.
*
* Documentation available at:
* http://www.primebox.co.uk/projects/cookie-bar/
*
* When using this software you use it at your own risk. We hold
* no responsibility for any damage caused by using this plugin
* or the documentation provided.
*/
(function($){
$.cookieBar = function(options,val){
if(options=='cookies'){
var doReturn = 'cookies';
}else if(options=='set'){
var doReturn = 'set';
}else{
var doReturn = false;
}
var defaults = {
message: 'We use cookies to track usage and preferences.', //Message displayed on bar
acceptButton: true, //Set to true to show accept/enable button
acceptText: 'I Understand', //Text on accept/enable button
acceptFunction: function(cookieValue){if(cookieValue!='enabled' && cookieValue!='accepted') window.location = window.location.href;}, //Function to run after accept
declineButton: false, //Set to true to show decline/disable button
declineText: 'Disable Cookies', //Text on decline/disable button
declineFunction: function(cookieValue){if(cookieValue=='enabled' || cookieValue=='accepted') window.location = window.location.href;}, //Function to run after decline
policyButton: true, //Set to true to show Privacy Policy button
policyText: 'Privacy Policy', //Text on Privacy Policy button
policyURL: '/en/info/policy/', //URL of Privacy Policy
autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows
acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page
acceptOnScroll: false, //Set to true to silently accept cookies when visitor scrolls X pixels up or down
expireDays: 365, //Number of days for cookieBar cookie to be stored for
renewOnVisit: false, //Renew the cookie upon revisit to website
forceShow: false, //Force cookieBar to show regardless of user cookie preference
effect: 'slide', //Options: slide, fade, hide
element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id.
append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS
fixed: true, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position
bottom: true, //Force CSS when fixed, so bar appears at bottom of website
zindex: '10', //Can be set in CSS, although some may prefer to set here
domain: String(window.location.hostname), //Location of privacy policy
referrer: String(document.referrer) //Where visitor has come from
};
var options = $.extend(defaults,options);
//Sets expiration date for cookie
var expireDate = new Date();
expireDate.setTime(expireDate.getTime()+(options.expireDays*86400000));
expireDate = expireDate.toGMTString();
var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/';
//Retrieves current cookie preference
var i,cookieValue='',aCookie,aCookies=document.cookie.split('; ');
for (i=0;i<aCookies.length;i++){
aCookie = aCookies[i].split('=');
if(aCookie[0]=='cb-enabled'){
cookieValue = aCookie[1];
}
}
//Sets up default cookie preference if not already set
if(cookieValue=='' && doReturn!='cookies' && options.autoEnable){
cookieValue = 'enabled';
document.cookie = cookieEntry.replace('{value}','enabled');
}else if((cookieValue=='accepted' || cookieValue=='declined') && doReturn!='cookies' && options.renewOnVisit){
document.cookie = cookieEntry.replace('{value}',cookieValue);
}
if(options.acceptOnContinue){
if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){
doReturn = 'set';
val = 'accepted';
}
}
if(doReturn=='cookies'){
//Returns true if cookies are enabled, false otherwise
if(cookieValue=='enabled' || cookieValue=='accepted'){
return true;
}else{
return false;
}
}else if(doReturn=='set' && (val=='accepted' || val=='declined')){
//Sets value of cookie to 'accepted' or 'declined'
document.cookie = cookieEntry.replace('{value}',val);
if(val=='accepted'){
return true;
}else{
return false;
}
}else{
//Sets up enable/accept button if required
var message = options.message.replace('{policy_url}',options.policyURL);
if(options.acceptButton){
var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>';
}else{
var acceptButton = '';
}
//Sets up disable/decline button if required
if(options.declineButton){
var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>';
}else{
var declineButton = '';
}
//Sets up privacy policy button if required
if(options.policyButton){
var policyButton = '<a href="'+options.policyURL+'" class="cb-policy">'+options.policyText+'</a>';
}else{
var policyButton = '';
}
//Whether to add "fixed" class to cookie bar
if(options.fixed){
if(options.bottom){
var fixed = ' class="fixed bottom"';
}else{
var fixed = ' class="fixed"';
}
}else{
var fixed = '';
}
if(options.zindex!=''){
var zindex = ' style="z-index:'+options.zindex+';"';
}else{
var zindex = '';
}
//Displays the cookie bar if arguments met
if(options.forceShow || cookieValue=='enabled' || cookieValue==''){
if(options.append){
$(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
}else{
$(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
}
}
var removeBar = function(func){
if(options.acceptOnScroll) $(document).off('scroll');
if(typeof(func)==='function') func(cookieValue);
if(options.effect=='slide'){
$('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();});
}else if(options.effect=='fade'){
$('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();});
}else{
$('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();});
}
};
var cookieAccept = function(){
document.cookie = cookieEntry.replace('{value}','accepted');
removeBar(options.acceptFunction);
};
var cookieDecline = function(){
var deleteDate = new Date();
deleteDate.setTime(deleteDate.getTime()-(864000000));
deleteDate = deleteDate.toGMTString();
aCookies=document.cookie.split('; ');
for (i=0;i<aCookies.length;i++){
aCookie = aCookies[i].split('=');
if(aCookie[0].indexOf('_')>=0){
document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/';
}else{
document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/';
}
}
document.cookie = cookieEntry.replace('{value}','declined');
removeBar(options.declineFunction);
};
$('#cookie-bar .cb-enable').click(function(){cookieAccept();return false;});
$('#cookie-bar .cb-disable').click(function(){cookieDecline();return false;});
if(options.acceptOnScroll){
var scrollStart = $(document).scrollTop(),scrollNew,scrollDiff;
$(document).on('scroll',function(){
scrollNew = $(document).scrollTop();
if(scrollNew>scrollStart){
scrollDiff = scrollNew - scrollStart;
}else{
scrollDiff = scrollStart - scrollNew;
}
if(scrollDiff>=Math.round(options.acceptOnScroll)) cookieAccept();
});
}
}
};
})(jQuery);

View File

@ -0,0 +1,11 @@
#cookie-bar {background:#111111; height:auto; line-height:24px; color:#eeeeee; text-align:center; padding:3px 0;}
#cookie-bar.fixed {position:fixed; top:0; left:0; width:100%;}
#cookie-bar.fixed.bottom {bottom:0; top:auto;}
#cookie-bar p {margin:0; padding:0;}
#cookie-bar a {color:#ffffff; display:inline-block; border-radius:3px; text-decoration:none; padding:0 6px; margin-left:8px;}
#cookie-bar .cb-enable {background:#007700;}
#cookie-bar .cb-enable:hover {background:#009900;}
#cookie-bar .cb-disable {background:#990000;}
#cookie-bar .cb-disable:hover {background:#bb0000;}
#cookie-bar .cb-policy {background:#0033bb;}
#cookie-bar .cb-policy:hover {background:#0055dd;}