flatpress/fp-plugins/cookiebanner/plugin.cookiebanner.php
Fraenkiman 57851cdebb Closes #325
- Adds the CookieBanner plugin
Features:
- Simple discrete CookieBanner, localized
- Font and color depend on the style used
- When activated, a link to the privacy policy is provided in the contact form and in the comment function.
- The static page is provided during setup. The FlatPress admin only has to insert the content.

This encourages the FlatPress admin to at least familiarize himself with the legal requirements of his region and to protect himself from possible legal consequences with this plugin.
2024-02-15 01:13:37 +01:00

84 lines
2.6 KiB
PHP

<?php
/*
* Plugin Name: CookieBanner
* Plugin URI: https://flatpress.org
* Description: Displays a discreet banner that informs the visitor about the use of cookies and provides a link to the <a href="./admin.php?p=static&action=write&page=privacy-policy" title="Edit me!" >privacy policy</a>. Part of the standard distribution. <a href="#" id="DeleteCookie" title="Reset CookieBanner">[Reset]</a>
* Author: FlatPress
* Version: 1.0.1
* Author URI: http://flatpress.org
*/
function plugin_cookiebanner_head() {
$pdir = plugin_geturl('cookiebanner');
echo '
<!-- BOF CookieBanner CSS -->
<link rel="stylesheet" type="text/css" href="' . $pdir . 'res/cookiebanner.css">
<!-- EOF Cookiebanner CSS -->
';
}
add_action('wp_head', 'plugin_cookiebanner_head', 0);
function plugin_cookiebanner_footer() {
global $lang;
lang_load('plugin:cookiebanner');
$bannertext = $lang ['plugin'] ['cookiebanner'] ['bannertext'];
$more = $lang ['plugin'] ['cookiebanner'] ['more'];
$more_url = $lang ['plugin'] ['cookiebanner'] ['more_url'];
$more_url_title = $lang ['plugin'] ['cookiebanner'] ['more_url_title'];
$ok = $lang ['plugin'] ['cookiebanner'] ['ok'];
echo '
<!-- BOF Cookie-Banner HTML -->
<div id="cookie_banner">
<div class="buttonbar">
' . $bannertext . '
<input type="submit" value="' . $ok . '" class="btn btn-primary btn-sm " onclick="cookie_ok()"></input>
</div>
</div>
<!-- EOF Cookie-Banner HTML -->
<!-- BOF Cookie-Banner JS -->
<script>
/**
* Initializes the CookieBanner plugin.
*/
if( document.cookie.indexOf(\'cookiebanner=1\') != -1 ){ // if cookie exists
jQuery(\'#cookie_banner\').hide(); // then hide banner
} else {
jQuery(\'#cookie_banner\').prependTo(\'body\'); // to the body and display
}
// OK button - sets cookie
function cookie_ok() {
document.cookie = \'cookiebanner=1;path=/\';
jQuery(\'#cookie_banner\').slideUp();
}
// Reset button - deletes the cookie and displays the banner again
$(\'#DeleteCookie\').click(()=>{
document.cookie = \'cookiebanner\' + \'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;\'; // delete CookieBanner -Cookie
jQuery(\'#cookie_banner\').show(); // shows banner
})
</script>
<!-- EOF Cookie-Banner JS -->
';
}
add_action('wp_footer', 'plugin_cookiebanner_footer', 0);
function plugin_cookiebanner_privacypolicy() {
global $lang;
$lang = lang_load('plugin:cookiebanner');
$notice_text = $lang ['plugin'] ['cookiebanner'] ['notice_text'];
echo '<p><em>' . $notice_text . '</em></p>';
}
add_action('comment_form', 'plugin_cookiebanner_privacypolicy', 0);
?>