mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-21 21:03:42 +00:00
Merge pull request #794 from Ixiter/develop
new addon - cookienotice - configure, show and handle a simple cookie…
This commit is contained in:
commit
74f89673cb
10 changed files with 373 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -18,7 +18,7 @@ report/
|
|||
#ignore OSX .DS_Store files
|
||||
.DS_Store
|
||||
|
||||
/nbproject/private/
|
||||
/nbproject/
|
||||
|
||||
#ignore smarty cache
|
||||
/view/smarty3/compiled/
|
||||
|
|
7
cookienotice/README
Normal file
7
cookienotice/README
Normal file
|
@ -0,0 +1,7 @@
|
|||
Cookie Notice
|
||||
|
||||
For server admins only.
|
||||
|
||||
Configure, show and handle a simple cookie usage notice. This absolute annoying but eventually necessary notification about the usage of cookies. This kind of things you klick ok on but don't read.
|
||||
|
||||
Author: Peter liebetrau <https://socivitas.com/profile/peerteer>
|
49
cookienotice/cookienotice.css
Normal file
49
cookienotice/cookienotice.css
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Admin css */
|
||||
#cookienotice-label {
|
||||
float: left;
|
||||
width: 300px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#cookienotice-text {
|
||||
float: left;
|
||||
margin-top: 10px;
|
||||
width: 400px;
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
#cookienotice-submit {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.cookienotice {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin-top: 25px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
/* Frontend css */
|
||||
#cookienotice-box {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 10000;
|
||||
bottom: 0px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background-color: #101010;
|
||||
color: #f0f0f0;
|
||||
padding: 2em 1em;
|
||||
text-align: center;
|
||||
}
|
||||
#cookienotice-box p {
|
||||
max-width: 100%;
|
||||
}
|
||||
#cookienotice-ok-button {
|
||||
border: 1px solid darkgoldenrod;
|
||||
background-color: gold;
|
||||
color: #101010;
|
||||
min-width: 80px;
|
||||
padding: .5em .1em;
|
||||
}
|
||||
|
36
cookienotice/cookienotice.js
Normal file
36
cookienotice/cookienotice.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
window.addEventListener("load", function () {
|
||||
var cookiename = 'cncookiesaccepted'
|
||||
var cookie = getCookie(cookiename);
|
||||
|
||||
if (cookie == "") {
|
||||
document.getElementById('cookienotice-box').style.display = 'block';
|
||||
document.getElementById('cookienotice-ok-button').onclick = function () {
|
||||
setCookie(cookiename, 1, 365);
|
||||
document.getElementById('cookienotice-box').style.display = 'none';
|
||||
};
|
||||
}
|
||||
|
||||
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 + ";path=/";
|
||||
}
|
||||
|
||||
function getCookie(cname) {
|
||||
var name = cname + "=";
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var ca = decodedCookie.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 "";
|
||||
}
|
||||
|
||||
});
|
143
cookienotice/cookienotice.php
Normal file
143
cookienotice/cookienotice.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Name: Cookie Notice
|
||||
* Description: Configure, show and handle a simple cookie notice
|
||||
* Version: 1.0
|
||||
* Author: Peter Liebetrau <https://socivitas/profile/peerteer>
|
||||
*
|
||||
*/
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
|
||||
/**
|
||||
* cookienotice_install
|
||||
* registers hooks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_install()
|
||||
{
|
||||
Hook::register('page_content_top', __FILE__, 'cookienotice_page_content_top');
|
||||
Hook::register('page_end', __FILE__, 'cookienotice_page_end');
|
||||
Hook::register('addon_settings', __FILE__, 'cookienotice_addon_settings');
|
||||
Hook::register('addon_settings_post', __FILE__, 'cookienotice_addon_settings_post');
|
||||
}
|
||||
|
||||
/**
|
||||
* cookienotice_uninstall
|
||||
* unregisters hooks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_uninstall()
|
||||
{
|
||||
Hook::unregister('page_content_top', __FILE__, 'cookienotice_page_content_top');
|
||||
Hook::unregister('page_end', __FILE__, 'cookienotice_page_end');
|
||||
Hook::unregister('addon_settings', __FILE__, 'cookienotice_addon_settings');
|
||||
Hook::unregister('addon_settings_post', __FILE__, 'cookienotice_addon_settings_post');
|
||||
}
|
||||
|
||||
/**
|
||||
* cookienotice_addon_settings
|
||||
* addon_settings hook
|
||||
* creates the admins config panel
|
||||
*
|
||||
* @param \Friendica\App $a
|
||||
* @param string $s The existing config panel html so far
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_addon_settings(\Friendica\App $a, &$s)
|
||||
{
|
||||
if (!is_site_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add our stylesheet to the page so we can make our settings look nice */
|
||||
$stylesheetPath = 'addon/cookienotice/cookienotice.css';
|
||||
$a->registerStylesheet($stylesheetPath);
|
||||
|
||||
$text = Config::get('cookienotice', 'text', L10n::t('This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.'));
|
||||
$oktext = Config::get('cookienotice', 'oktext', L10n::t('OK'));
|
||||
|
||||
$t = Renderer::getMarkupTemplate("settings.tpl", "addon/cookienotice/");
|
||||
$s .= Renderer::replaceMacros($t, [
|
||||
'$title' => L10n::t('"cookienotice" Settings'),
|
||||
'$description' => L10n::t('<b>Configure your cookie usage notice.</b> It should just be a notice, saying that the website uses cookies. It is shown as long as a user didnt confirm clicking the OK button.'),
|
||||
'$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text, L10n::t('The cookie usage notice')],
|
||||
'$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext, L10n::t('The OK Button text')],
|
||||
'$submit' => L10n::t('Save Settings')
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookienotice_addon_settings_post
|
||||
* addon_settings_post hook
|
||||
* handles the post request from the admin panel
|
||||
*
|
||||
* @param \Friendica\App $a
|
||||
* @param string $b
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_addon_settings_post(\Friendica\App $a, &$b)
|
||||
{
|
||||
if (!is_site_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($_POST['cookienotice-submit']) {
|
||||
Config::set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text'])));
|
||||
Config::set('cookienotice', 'oktext', trim(strip_tags($_POST['cookienotice-oktext'])));
|
||||
info(L10n::t('cookienotice Settings saved.') . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cookienotice_page_content_top
|
||||
* page_content_top hook
|
||||
* adds css and scripts to the <head> section of the html
|
||||
*
|
||||
* @param \Friendica\App $a
|
||||
* @param string $b unnused - the header html incl. nav
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_page_content_top(\Friendica\App $a, &$b)
|
||||
{
|
||||
$stylesheetPath = 'addon/cookienotice/cookienotice.css';
|
||||
$footerscriptPath = 'addon/cookienotice/cookienotice.js';
|
||||
|
||||
$a->registerStylesheet($stylesheetPath);
|
||||
$a->registerFooterScript($footerscriptPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* cookienotice_page_end
|
||||
* page_end hook
|
||||
* ads our cookienotice box to the end of the html
|
||||
*
|
||||
* @param \Friendica\App $a
|
||||
* @param string $b the page html
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cookienotice_page_end(\Friendica\App $a, &$b)
|
||||
{
|
||||
$text = (string) Config::get('cookienotice', 'text', L10n::t('This website uses cookies to recognize revisiting and logged in users. You accept the usage of these cookies by continue browsing this website.'));
|
||||
$oktext = (string) Config::get('cookienotice', 'oktext', L10n::t('OK'));
|
||||
|
||||
$page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/");
|
||||
|
||||
$page_end = Renderer::replaceMacros($page_end_tpl, [
|
||||
'$text' => $text,
|
||||
'$oktext' => $oktext,
|
||||
]);
|
||||
|
||||
$b .= $page_end;
|
||||
}
|
53
cookienotice/lang/C/messages.po
Normal file
53
cookienotice/lang/C/messages.po
Normal file
|
@ -0,0 +1,53 @@
|
|||
# ADDON cookienotice
|
||||
# Copyright (C)
|
||||
# This file is distributed under the same license as the Friendica cookienotice addon package.
|
||||
#
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-01-20 14:51+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: Peter Liebetrau <peter.liebetrau@peterliebetrau.de>\n"
|
||||
"Language-Team: German cookienotice <LL@li.org>\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: cookienotice.php:53
|
||||
msgid "\"cookienotice\" Settings"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:54
|
||||
msgid ""
|
||||
"<b>Configure your cookie usage notice.</b> It should just be a notice, "
|
||||
"saying that the website uses cookies. It is shown as long as a user didnt "
|
||||
"confirm clicking the OK button."
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:55
|
||||
msgid "Cookie Usage Notice"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:55
|
||||
msgid "The cookie usage notice"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:56
|
||||
msgid "OK Button Text"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:56
|
||||
msgid "The OK Button text"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:57
|
||||
msgid "Save Settings"
|
||||
msgstr ""
|
||||
|
||||
#: cookienotice.php:72
|
||||
msgid "cookienotice Settings saved."
|
||||
msgstr ""
|
56
cookienotice/lang/de/messages.po
Normal file
56
cookienotice/lang/de/messages.po
Normal file
|
@ -0,0 +1,56 @@
|
|||
# ADDON cookienotice
|
||||
# Copyright (C)
|
||||
# This file is distributed under the same license as the Friendica cookienotice addon package.
|
||||
#
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-01-20 14:51+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: Peter Liebetrau <peter.liebetrau@peterliebetrau.de>\n"
|
||||
"Language-Team: cookienotice german <LL@li.org>\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: cookienotice.php:53
|
||||
msgid "\"cookienotice\" Settings"
|
||||
msgstr "\"cookienotice\" Einstellungen"
|
||||
|
||||
#: cookienotice.php:54
|
||||
msgid ""
|
||||
"<b>Configure your cookie usage notice.</b> It should just be a notice, "
|
||||
"saying that the website uses cookies. It is shown as long as a user didnt "
|
||||
"confirm clicking the OK button."
|
||||
msgstr ""
|
||||
"<b>Konfiguriere deinen Cookie Nutzungshinweis.</b> Es sollte ein Hinweis sein, "
|
||||
"der sagt dass die Webseite Cookies benutzt. Er wird solange angezeigt, "
|
||||
"bis der User den Hinweis mit klicken des OK Buttons bestätigt."
|
||||
|
||||
#: cookienotice.php:55
|
||||
msgid "Cookie Usage Notice"
|
||||
msgstr "Cookie Nutzungshinweis"
|
||||
|
||||
#: cookienotice.php:55
|
||||
msgid "The cookie usage notice"
|
||||
msgstr "Der Cookie Nutzungshinweis"
|
||||
|
||||
#: cookienotice.php:56
|
||||
msgid "OK Button Text"
|
||||
msgstr "OK Button Text"
|
||||
|
||||
#: cookienotice.php:56
|
||||
msgid "The OK Button text"
|
||||
msgstr "Der OK Button Text"
|
||||
|
||||
#: cookienotice.php:57
|
||||
msgid "Save Settings"
|
||||
msgstr "Einstellungen speichern"
|
||||
|
||||
#: cookienotice.php:72
|
||||
msgid "cookienotice Settings saved."
|
||||
msgstr "cookienotice Einstellungen wurden gespeichert"
|
11
cookienotice/lang/de/strings.php
Normal file
11
cookienotice/lang/de/strings.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
;
|
||||
$a->strings["\"cookienotice\" Settings"] = "\"cookienotice\" Einstellungen";
|
||||
$a->strings["<b>Configure your cookie usage notice.</b> It should just be a notice, saying that the website uses cookies. It is shown as long as a user didnt confirm clicking the OK button."] = "<b>Konfiguriere deinen Cookie Nutzungshinweis.</b> Es sollte ein Hinweis sein, der sagt dass die Webseite Cookies benutzt. Er wird solange angezeigt, bis der User den Hinweis mit klicken des OK Buttons bestätigt.";
|
||||
$a->strings["Cookie Usage Notice"] = "Cookie Nutzungshinweis";
|
||||
$a->strings["The cookie usage notice"] = "Der Cookie Nutzungshinweis";
|
||||
$a->strings["OK Button Text"] = "OK Button Text";
|
||||
$a->strings["The OK Button text"] = "Der OK Button Text";
|
||||
$a->strings["Save Settings"] = "Einstellungen speichern";
|
||||
$a->strings["cookienotice Settings saved."] = "cookienotice Einstellungen wurden gespeichert";
|
2
cookienotice/templates/cookienotice.tpl
Normal file
2
cookienotice/templates/cookienotice.tpl
Normal file
|
@ -0,0 +1,2 @@
|
|||
<div id="cookienotice-box"><p>{{$text}}</p><button id="cookienotice-ok-button">{{$oktext}}</button></div>
|
||||
|
15
cookienotice/templates/settings.tpl
Normal file
15
cookienotice/templates/settings.tpl
Normal file
|
@ -0,0 +1,15 @@
|
|||
<span id="settings_cookienotice_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_cookienotice_expanded'); openClose('settings_cookienotice_inflated');">
|
||||
<h3>{{$title}}</h3>
|
||||
</span>
|
||||
<div id="settings_cookienotice_expanded" class="settings-block" style="display: none;">
|
||||
<span class="fakelink" onclick="openClose('settings_cookienotice_expanded'); openClose('settings_cookienotice_inflated');">
|
||||
<h3>{{$title}}</h3>
|
||||
</span>
|
||||
<p>{{$description}}</p>
|
||||
{{include file="field_textarea.tpl" field=$text}}
|
||||
{{include file="field_input.tpl" field=$oktext}}
|
||||
<div class="settings-submit-wrapper" >
|
||||
<input type="submit" id="cookienotice-submit" name="cookienotice-submit" class="settings-submit" value="{{$submit}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear"></div>
|
Loading…
Reference in a new issue