Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2015-02-26 16:32:44

MartinS
Member
From: Netherlands
Registered: 2012-10-29
Posts: 73
Website

Easy cookie warning popup?

Having noticed the session cookie placed by the cart on my computer and only too aware of all the obligatory cookie warnings that one gets on all European commercial and other websites, and of the fact that my CE4 site does not provide this, I searched this forum and found Tom Owens' and other posts in 2014.

Those posts are too technical for me. I do not use WordPress, or TTG's shared resources, which had been causing problems for me. I just need an obligatory cookie warning with dismiss option to pop up when the cart is opened, or at whatever moment it is that the cookie needs to be placed on the user's computer. Such a friendly popup would need to say that the cookie is needed to serve the cart and that it will be deleted when the browser is closed. Or suchlike.

Is there a simple way to achieve this? I would be able to edit a css or php file in a specific directory if someone can tell me which file(s) and what text I would need to put where. Thanks in advance.

Offline

#2 2015-02-26 23:48:03

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Easy cookie warning popup?

a pop up is going to require javascript or jQuery conditionally inserted via phplugins

A simple solution is to use the text sidebar in your galleries to place your notice.

If you're using Publisher, you can place the text in the template's sidebar and then just include that template sidebar text when you create your albums.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2015-02-27 00:28:34

MartinS
Member
From: Netherlands
Registered: 2012-10-29
Posts: 73
Website

Re: Easy cookie warning popup?

I would be curious to know how other commercial CE4 users within the EU have dealt with this. It is becoming virtually impossible to open any commercial, insurance, local government or whatever website (other than a purely private site) without the visitor being notified on the home page of the fact that cookies are required for normal operation (or as the case may be) and giving the visitor the option to accept this fact by clicking "I agree" or declining it by "I do not accept this", which is fine, but the website will not work and in fact in many cases will not proceed further than the home page.

This is a huge problem for the small commercial CE4 user, most of whom may not be aware of the requirements or may choose to ignore them until some authority catches up with them. I am keen to be seen by my clients to adhere to legal requirements concerning my website, however small and insignificant the site may be.

So whilst a sidebar is a simple solution, it would be intrusive in so far as it is unnecessarily permanently visible, and takes up real estate too. I have not delved into the legal aspects but if I am not mistaken, I believe such a passive statement does not go far enough and some form of interaction by the site visitor is required.  Having had such interaction, the site then operates as normal without the client being bothered any more.

I hope other users will give their ideas/experience and/or solutions.

Offline

#4 2015-02-27 00:42:09

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Easy cookie warning popup?

It will be interesting to see what others are doing.

I searched around looking at numerous jQuery and javascript solutions. But there are so many that it gets confusing real fast.

The simplest thing I saw was a javascript confirm() function.
http://www.w3schools.com/js/js_popup.asp
But it would have to pop up in every gallery. Plus I don't know that it prevents the cart from working if the user doesn't agree.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2015-02-27 03:34:06

MartinS
Member
From: Netherlands
Registered: 2012-10-29
Posts: 73
Website

Re: Easy cookie warning popup?

I like things as simple as possible so will work on this; thanks for the link, which is really useful. I am not going to try to stop the cart working; the main thing is to wake people up to the fact that that cookies are going to be used, and at least one of those w3schools scripts would appear to be just what is needed for now. Thanks, Rod.

Offline

#6 2015-02-27 06:09:26

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Easy cookie warning popup?

The cart JS has its own hooks mechanism that we had previously used to adapt the code for various types of galleries, in particular Highslide.  This is handled via a file within your template or gallery at lib/js/ttgcart.hooks.js.  This is a good spot to add page functionality.

I've written a bit of code that pops up an alert when the customer clicks on a buy button.  If the customer clicks 'cancel' then the page reloads.  This isn't particularly graceful but the cart hooks don't provide a mechanism to prevent further actions.

The extra code includes two functions to handle cookies so that the browser can remember that a customer has allowed cookies, and code within the ttgCart.pre_open_modal function.  ttgCart.post_populate_buy_buttons  would be a more ideal location, except that the use of page reloading as an exit mechanism would continually bombard the user with the popup until choosing 'ok'.

To use this code, copy and paste it into lib/js/ttgcart.hooks.js in your gallery or template.  You may want to change the message.

/*
    Functions do not need to exist here - jquery.ttgcart.js checks for functions before trying to call them.
    However this file should exist, as the browser will get a 404 otherwise.
 */

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    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);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

if ("ttgCart" in window) {
    ttgCart.post_populate_buy_buttons = function() {}

    ttgCart.post_get_pricing = function() {}

    ttgCart.pre_open_modal = function() {
        var message = "We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies from this website. \n\nIf you would like to change your preferences you may do so by following the instructions at http://www.aboutcookies.org/Default.aspx?page=1";
        
        var cookiesAllowed = getCookie("cookiesAllowed");
        
        if (cookiesAllowed == undefined || !cookiesAllowed) {
            if (confirm(message)) {
                 setCookie("cookiesAllowed", 1, 7);
            } else {
                 location.reload();
            }        
        }
    }

    ttgCart.post_open_modal = function() {}

    ttgCart.add_success = function() {}

    ttgCart.add_error = function() {}

    ttgCart.post_cancel_modal = function() {}

    ttgCart.pre_load_widget = function() {}

    ttgCart.post_load_widget = function() {}

    ttgCart.post_click_add_button = function() {}
}

Offline

#7 2015-02-27 08:37:50

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Easy cookie warning popup?

Somewhere in the back of my mental closet, I've been meaning to write a tutorial on how to implement an EU cookie warning via PHPlugins. If that every actually happens, it will probably use this:
https://github.com/creativeaura/eu-cookie-opt-in


Matt

The Turning Gate, http://theturninggate.net

Offline

#8 2015-02-27 11:28:20

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Easy cookie warning popup?

That somehow needs to integrate with the cart functionality to disable it if the user opts out.

Offline

#9 2015-03-01 04:07:44

MartinS
Member
From: Netherlands
Registered: 2012-10-29
Posts: 73
Website

Re: Easy cookie warning popup?

I have implemented Ben's script in my gallery template's ttgcart.hooks.js and it generates the desired message in a modest way as soon as the viewer clicks on the cart icon on a thumbnail. It goes away nicely if one accepts cookies. The page reloads as expected if one clicks on "cancel".

However by following the moment of cookie placement in Firefox I have now noticed the new cookie appearing at an earlier stage than when using the cart, namely even when the gallery template is first opened or perhaps even on entering the site (I use Stage). I am fairly sure about this since I have removed the cookie from the folder before closing and restarting Firefox. I tried to follow the cookie in IE but could not even find it in the list of cookies, so confess ignorance as far as IE is concerned. The opt-in message works anyway in the same way whether I view the page in IE or in Firefox.

I think the most user-friendly interface would be the moment at which the user clicks the (in my case) "Enter site" button bottom right of the home Stage flip page. This is then the moment at which, at least on my site, the user first accesses the contents of the /galleries/ folder. A cookie opt-in at this moment would appear to me the least intrusive alert for the user before he gets down to business in the site proper.

My question is therefore: can I use a similar hook in some other .js file to provoke the cookie opt-in message into action at an earlier stage?

Offline

#10 2015-03-01 06:42:13

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Easy cookie warning popup?

Hi Martin, 

I'm not aware of a more general way of doing this that would interrupt the page loading prior to TTG pages creating a session (and hence creating a cookie).  You could say that the solution I provided works in 'the spirit' of the law.  The cookie may exist but it's not matched to any data.

A robust solution would be to interrupt the page flow before any TTG PHP pages have even begun to load.  Thinking aloud here, one idea I had:

1) Create an .htaccess file that checks for the existence of a cookie (call it the 'AllowCookies' cookie)
2) If the cookie doesn't exist, redirect to a new page that prompts the user to proceed with cookies or not
3) If proceeding, add the AllowCookies cookie and take the user back to the page at 1)
4) The .htaccess would see that the AllowCookies cookie is there and not interrupt the flow to the originally requested page

The .htaccess could be added to whichever directory makes sense as an entry point, for example galleries/ in your case.

Such a system would consist of two files:

An .htaccess file
A php file to prompt the customer and redirect to the originally requested page or not

These two files would not interfere with any TTG code.

Offline

Board footer

Powered by FluxBB