diff --git a/.gitignore b/.gitignore index 36ccc906..0d32de00 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ report/ #ignore OSX .DS_Store files .DS_Store -/nbproject/private/ +/nbproject/ #ignore smarty cache /view/smarty3/compiled/ diff --git a/cookienotice/README b/cookienotice/README new file mode 100644 index 00000000..74edd44a --- /dev/null +++ b/cookienotice/README @@ -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 diff --git a/cookienotice/cookienotice.css b/cookienotice/cookienotice.css new file mode 100644 index 00000000..f2581432 --- /dev/null +++ b/cookienotice/cookienotice.css @@ -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; +} + diff --git a/cookienotice/cookienotice.js b/cookienotice/cookienotice.js new file mode 100644 index 00000000..0ab06c66 --- /dev/null +++ b/cookienotice/cookienotice.js @@ -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 ""; + } + +}); diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php new file mode 100644 index 00000000..376de1ad --- /dev/null +++ b/cookienotice/cookienotice.php @@ -0,0 +1,143 @@ + + * + */ +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('Configure your cookie usage notice. 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 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; +} diff --git a/cookienotice/lang/C/messages.po b/cookienotice/lang/C/messages.po new file mode 100644 index 00000000..99b843c3 --- /dev/null +++ b/cookienotice/lang/C/messages.po @@ -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 \n" +"Language-Team: German cookienotice \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 "" +"Configure your cookie usage notice. 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 "" diff --git a/cookienotice/lang/de/messages.po b/cookienotice/lang/de/messages.po new file mode 100644 index 00000000..31b98188 --- /dev/null +++ b/cookienotice/lang/de/messages.po @@ -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 \n" +"Language-Team: cookienotice german \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 "" +"Configure your cookie usage notice. 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 "" +"Konfiguriere deinen Cookie Nutzungshinweis. 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" diff --git a/cookienotice/lang/de/strings.php b/cookienotice/lang/de/strings.php new file mode 100644 index 00000000..a96ff5ff --- /dev/null +++ b/cookienotice/lang/de/strings.php @@ -0,0 +1,11 @@ +strings["\"cookienotice\" Settings"] = "\"cookienotice\" Einstellungen"; +$a->strings["Configure your cookie usage notice. 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."] = "Konfiguriere deinen Cookie Nutzungshinweis. 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"; diff --git a/cookienotice/templates/cookienotice.tpl b/cookienotice/templates/cookienotice.tpl new file mode 100644 index 00000000..71e88c0f --- /dev/null +++ b/cookienotice/templates/cookienotice.tpl @@ -0,0 +1,2 @@ +

{{$text}}

+ diff --git a/cookienotice/templates/settings.tpl b/cookienotice/templates/settings.tpl new file mode 100644 index 00000000..68ca99c4 --- /dev/null +++ b/cookienotice/templates/settings.tpl @@ -0,0 +1,15 @@ + +

{{$title}}

+
+ +