Oui cookie - Cookie management plugin for @Textpattern

Overview

oui_cookie

Introduction

Set, check, read, reset or delete cookies manually or through GET/POST parameters.

. According to the EU legislation, some cookies need the user consent before to be set.

Plugin requirements

oui_cookie’s minimum requirements:

Plugin management

Installation

From the admin interface

  1. Download the compiled plugin file or the source to compile a customized file.
  2. Paste the content of the compiled plugin file under the “Admin > Plugins”:?event=plugin tab and click the Upload button.
  3. Confirm the plugin install by clicking the Install button on the plugin preview page.
  4. Enable the plugin.

Via Composer

After installing Composer

  1. Target your project directory:
    $ cd /path/to/your/textpattern/installation/dir
  2. If it’s not already done, lock your version of Txp:
    $ composer require textpattern/lock:4.6.2, where 4.6.2 is the Txp version in use.
  3. Install oui_cookie:
    $ composer require oui/oui_cookie

Update

From the admin interface

  1. Follow the installation instruction above.

Via Composer

$ composer update oui/oui_cookie

Uninstall

From the admin interface

  1. Check the box on the left of the plugin row under the “Admin > Plugins”:?event=plugin.
  2. open the select list at the bottom of the plugins table and choose Delete.
  3. confirm the plugin deletion.

Via Composer

$ composer remove oui/oui_cookie

Tags

<txp:oui_cookie name="…" />

or

<txp:oui_cookie name="…">
    […]
</txp:oui_cookie>

Attributes

Required
name

Value: string; none by default.
The cookie (and GET/POST parmater) name you want to use. If no other attibutes are defined, the tag will read and display the related value.

Manually set a cookie
value

Value: string; none by default.
A value to manually set the named cookie.
You can also set the cookie value by using a continer tag like you would for a variable.

Set a cookie through a GET/POST parameter
values

Value: comma separated list of strings; none by default.
A comma separated list of accepted values for the GET/POST parameter and its cookie.

default

Value: string; none by default.
A default value.
If set, the plugin conditional tag will always be true if not check against a defined value.

delete

Value: string; none by default.
An GET/POST parameter value used to delete the cookie.

Optional cookie settings
duration

Value: strtotime value, +1 day by default.
The duration of the cookie.

Delete a cookie
delete

Value: 0 or 1; 0 by default.
If set to 1 this attribute will delete the named cookie.

<txp:oui_if_cookie name="…">
    […]
<txp:else />
    […]
</txp:oui_if_cookie>

This tag checks the status or the value of the cookie (and/or the related GET/POST parameter) defined by the name attribute.

Attributes

Required
name

Value: string; none by default.
The cookie (and GET/POST parameter) name you want to use.

Optional
value

Value: string; none by default.
A value to check against the cookie (and/or the GET/POST parameter) value.

Examples

Front-end articles sorting

List the sort options you want to use:

<form action="#" method="post">
    <select name="sort_by">
        <option value="custom_1"<txp:oui_if_cookie name="sort_by" value="custom_1"> disabled selected</txp:oui_if_cookie>>Size</option>
        <option value="custom_2"<txp:oui_if_cookie name="sort_by" value="custom_2"> disabled selected</txp:oui_if_cookie>>Weight</option>
    </select>
    <input type="submit" value="Sort">
</form>

Then, catch the GET/POST parameter sent by this list to store it (useful to keep the sort order pages after pages).

<txp:oui_cookie name="sort_by" values="custom_1, custom_2" default="custom_1" />

Now use the new value as the value of the sort attribute of your article tag.

<txp:article sort='<txp:oui_cookie name="sort_by" />' />

Last viewed article

Store the current article id in a cookie:

<txp:if_individual_article>
    <txp:oui_cookie name="last_article" value='<txp:article_id />' />
</txp:if_individual_article>

Now, use the following code anywhere you want to display the last viewed article.

<txp:if_cookie name="last_article">
    <txp:article_custom id='<txp:oui_cookie name="last_article" />' />
</txp:if_cookie>

EU cookies Warning

<txp:oui_cookie name="accept_cookies" values="yes" />

<txp:oui_if_cookie name="accept_cookies">
<txp:else />
    <div id="cookies-warning">
        <p>This website uses cookies. <a id="accept_cookies" href="?accept_cookies=yes">I agree, remove this message!</a></p>
    </div>
</txp:oui_if_cookie>

Now, you can add some progressive enhancement to avoid to refresh the page if javascript is on.
However, note that it wouldn’t instantaneously display a potential alternative content placed before the <txp:else /> tag if the cookie is not set/setting.

<script>
    (function() {
        // Get the link which should remove the warning.
        var accept = document.getElementById('accept_cookies');

        // If it exists, listen it…
        if (accept) {
            accept.addEventListener('click', removeWarning);
        }

        // It is clicked!
        function removeWarning(e){
            document.cookie = 'accept_cookies=yes;path=/;expires=864e2'; // Set the cookie for the whole domain for 1 day.
            var warning = document.getElementById('cookies-warning'); // Get the warning message to remove.
            warning.remove(); // Remove the message.
            e.preventDefault(); // Do not follow the link; everything's already done!
        };
    }());
</script>

Credits

Author

Nicolas Morand
Thank you to the Textpattern community and the core team.

License

This plugin is distributed under GPL v2.0.

oui_cookie version 1.0.0-BETA3, Copyright © 2018 Nicolas Morand
This Textpattern plugin comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions.

Changelog

  • 1.0.0-beta3 (2018-07-06)
  • 0.2.3 (2016-06-21)
    • Code rewrite;
    • manual cookie setting added;
    • display attribute removed (setting and reading are now separated);
    • deletion process changed.
  • 0.1.3 (2016-05-29)
    • improves conditional tag results;
    • delete attribute unset by default (but any none valid value for a defined GET/POST parameter will delete the related cookie).
  • 0.1.2 (2016-05-26)
You might also like...
Unicode-url-for-Textpattern - Plugin for using unicode urls instead of transliterations to ASCII characters

Unicode-url-for-Textpattern Summary textpattern plugin wcz_utf8_url – uses UTF-8 permlinks instead of transliterated ones for SEO Features automatical

Arc meta - Textpattern plugin for meta tags to improve site SEO and social marketing.

arc_meta A Textpattern plugin for meta tags to improve site SEO and social marketing. arc_meta adds meta fields to your article, section and category

Rah cache minify - HTML compressor module for rah cache Textpattern CMS plugin

Minify module for rah_cache This is a minify module for rah_cache, a full-page caching solution for Textpattern CMS. Rah_cache_minify will minify HTML

Etc cache - Cache plugin for Textpattern CMS

etc_cache Download | Packagist This Textpattern plugin provides an events-driven cache solution for Textpattern CMS. Textpattern is fast, but when you

Asy jpcache - jpcache plugin for Textpattern

asy_jpcache is Full Page Caching for Textpattern1.0 rev.300 and up (including RC5). Install asy_jpcache.txt in the Admin-Panel, and click on _help_ t

Etc pagination - Pagination plugin for Textpattern CMS.

etc_pagination Download | Packagist This Textpattern plugin creates a paginated navigation bar on listings. It has a wide variety of attributes – so y

Smd imagery - A Textpattern CMS plugin for managing images in the Write panel.

smd_imagery Insert images into your Write panel. Very handy for people who run photoblog or image-heavy sites, or those who categorise images for incl

Zem contact reborn - An extensible HTML form mailer plugin for Textpattern CMS.

com_connect Contents Introduction Installing and upgrading Migrating from zem_contact_reborn Usage Tags com_connect tag com_connect_text tag com_conne

Arc youtube - Youtube plugin for Textpattern

arc_youtube A Textpattern plugin for easily embedding Youtube videos in pages using a customisable player. This plugin works well with arc_vimeo and o

Releases(1.0.0-beta4)
Owner
Nicolas Morand
@drupal/@symfony developer @maetva
Nicolas Morand
Oui embed - (o)Embed plugin for @Textpattern

oui_embed Embed everything… Get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It’s compatible with

Nicolas Morand 2 Jun 21, 2018
Oui player - Manage configurable media players in @Textpattern CMS

oui_player Introduction An extendable plugin to easily embed customized audio and video players. . This plugin does not use oembed, it builds iframe e

Nicolas Morand 3 Aug 15, 2018
Pat eu cookies law - 🌝 EU Cookie Law Compliance: A Textpattern plugin (or standalone script) for Third-Party Cookies (RGPD compliance)

pat_eu_cookies_law EU Cookie Law Compliance: A Textpattern plugin (or a standalone script) for Third-Party Cookies. A simple solution that respects th

Patrick LEFEVRE 3 Aug 16, 2020
Textpattern-installer - Textpattern plugin and theme installer for Composer

Textpattern Installer for Composer Package directory | Issues Install plugins and themes to Textpattern CMS with Composer. $ composer require rah/rah_

Jukka Svahn 7 Apr 14, 2022
Textpattern-for-Panic-Coda - A Textpattern CMS mode for Panic Coda

Textpattern elements for Panic Coda 2 Handy elements for use with Panic Coda 2 on a Mac when authoring files for the Textpattern CMS. This repository

Phil Wareham 8 Jun 26, 2017
Spf js - a JavaScript management plugin for Textpattern

spf_js I’m no longer able to develop this plugin due to ill health. If anyone would like to take over, message me, and I’ll transfer the source. JavaS

Simon Finch 4 May 21, 2019
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Stef Dawson 8 Oct 3, 2020
MassPlugCompiler - Textpattern CMS plugin compiler

mtxpc mtxpc compiles Textpattern CMS plugin sources into installer packages. Supports multi-file structure and a JSON manifest file. Install Using Com

Jukka Svahn 5 Apr 15, 2022
Pat if amp - ⚡ A Textpattern Conditional Plugin for Google's Accelerated Mobile Pages Project (AMP)

pat_if_amp Download | Packagist AMP pages for Textpattern CMS. This conditional tag examines the URL of the current page and determines if the URL end

Patrick LEFEVRE 4 Dec 15, 2019
Arc social share - A Social Bookmarking Plugin for Textpattern

arc_social_share A Social Bookmarking Plugin for Textpattern; easily add links for sharing content with numerous social networks. arc_social_share 1.4

Andy Carter 5 Nov 15, 2022