Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
oui_cookie - Set, read, reset or delete cookies
Examples
Manual cookie setting
<txp:oui_cookie name="favourite_fruit" value="apricot" />
<txp:oui_cookie name="favourite_fruit">
My favourite fruit is the apricot.
</txp:oui_cookie>
Cookie setting through a fruits HTTP variable
<txp:oui_cookie name="fruits" values="apple, pear, apricot" />
Then call an url like http://my-website.com/?fruits=apricot
.
You can also add a default
value here.
Reading
<txp:oui_cookie name="favourite_fruit" />
Deletion
<txp:oui_cookie name="favourite_fruit" delete="1" />
Cookie checking
<txp:oui_if_cookie name="favourite_fruit">
My favourite fruit is the <txp:oui_cookie name="favourite_fruit" />.
<txp:else />
I don't have any favourite fruit.
</txp:oui_cookie>
You can also add a value
to check against the cookie value here.
Last edited by NicolasGraph (2016-06-22 06:34:31)
Offline
Re: oui_cookie - Set, read, reset or delete cookies
I updated the github documentation for clarity. Updates will be included in the next release.
Offline
Re: oui_cookie - Set, read, reset or delete cookies
oui_cookie v.0.1.3 is ready to go…
Offline
Re: oui_cookie - Set, read, reset or delete cookies
oui_cookie v.0.2.3 includes important changes; please, check the first post of this thread or the plugin documentation.
Offline
Re: oui_cookie - Set, read, reset or delete cookies
Hi Nicolas,
I am making heavy use of your plugin (v: 1.0.0-beta2) which has become indispensable following the EU laws but I have a a couple of questions.
- Could you please let us know how the
duration
attribute should be used? ie is this the right format?duration="+1 year"
- Is there a way to make this plugin compatible for Textpattern version: 4.4.1 running on PHP version: 5.4.45? I have edited the first part by adding
if(class_exists('\Textpattern\Tag\Registry')) {
which prevents txp from crashing but clicking theAccept
link in the front end, the cookie warning does not disappear and the analytics do not load. Sample url: news.neme.org/1824/state-machines.
Many thanks
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: oui_cookie - Set, read, reset or delete cookies
colak wrote #312487:
Hi Yiannis,
Could you please let us know how the
duration
attribute should be used? ie is this the right format?duration="+1 year"
It will accept anything the php function strtotime accepts – see the docs – so it should accept #1 year
.
but clicking the
Accept
link in the front end, the cookie warning does not disappear and the analytics do not load. Sample url: news.neme.org/1824/state-machines.
When I load that page the first time, the inspector shows only the piwik cookie to start with. If I click accept I see the accept cookie and the google analytics cookies. But, as you say, the banner doesn’t disappear.
But If I don’t click accept but refresh the page I still get the google analytics cookies, which if you’re doing explicit opt-in, I shouldn’t get until I really click accept.
Is there a way to make this plugin compatible for Textpattern version: 4.4.1 running on PHP version: 5.4.45? I have edited the first part by adding
if(class_exists('\Textpattern\Tag\Registry')) {
which prevents txp from crashing
Good catch. You might also want to put in some debug values into your code to check what the cookie state is so you can see if the tests are working. It is weird that you are getting both the message and google analytics. As far as I can tell from your cookies form code, it should be one or the other, but I haven’t looked in detail.
TXP Builders – finely-crafted code, design and txp
Online
Re: oui_cookie - Set, read, reset or delete cookies
Hi Julian
Debugging is a good idea! This is what I basically have:
<txp:oui_cookie name="accept_cookies" duration="+1 year" values="yes" />
<txp:oui_if_cookie name="accept_cookies">
<txp:rvm_if_privileged>
<txp:else />
analytics js scripts
</txp:rvm_if_privileged>
<txp:else />
disclaimer <a rel="nofollow" href="?accept_cookies=yes">Accept</a>
</txp:oui_if_cookie>
and this is the tag trace in debug mode!
<txp:output_form form="google_anal" />
[SQL (0.00018095970153809): select Form from txp_form where name='google_anal']
[Form: google_anal]
<txp:oui_cookie name="accept_cookies" duration="+1 year" values="yes" />
<txp:oui_if_cookie name="accept_cookies">
<txp:rvm_if_privileged>
[<txp:rvm_if_privileged>: true]
</txp:rvm_if_privileged>
<txp:else />
Tag error: <txp:else /> -> Textpattern Warning: tag does not exist while parsing form <strong>google_anal</strong> on page <strong>default</strong> (edit: this is where the cookie disclaimer goes)
</txp:oui_if_cookie>
This is the tag trace on the page when I am not logged in
<txp:output_form form="google_anal" />
[SQL (0.00022101402282715): select Form from txp_form where name='google_anal']
[Form: google_anal]
<txp:oui_cookie name="accept_cookies" duration="+1 year" values="yes" />
<txp:oui_if_cookie name="accept_cookies">
<txp:else />
Tag error: <txp:else /> -> Textpattern Warning: tag does not exist while parsing form <strong>google_anal</strong> on page <strong>default</strong>
</txp:oui_if_cookie>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline
Re: oui_cookie - Set, read, reset or delete cookies
colak, I can’t make Txp 4.4.1 work for now but I know that there is at least one more thing that should be changed in oui_cookie to make it work with lower versions than v4.6. It is about the parser here. Could you try to add evalelse
like so return parse(evalelse($thing, $out));
and let me know how does it help?
Offline
Re: oui_cookie - Set, read, reset or delete cookies
Hi Nicolas,
The evalelse
seems to have done the trick! Now the boxes appear as they should and hide on accept. I’ll also be checking if anything loads this afternoon and let you know. Many many thanks!!!
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline
Re: oui_cookie - Set, read, reset or delete cookies
NicolasGraph wrote #312506:
Glad it helped; I hope everything will be alright now.
Indeed it is. I checked it in 3 browsers and all is working as intended.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline