From fa08109830cd14bb4459341b8c75263a135d827f Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Sun, 20 Jan 2019 10:04:25 +0100 Subject: [PATCH 1/9] new addon - cookienotice - configure, show and handle a simple cookie usage notice --- cookienotice/README | 7 ++ cookienotice/cookienotice.css | 23 +++++ cookienotice/cookienotice.php | 109 ++++++++++++++++++++++++ cookienotice/templates/cookienotice.tpl | 23 +++++ cookienotice/templates/head.tpl | 40 +++++++++ cookienotice/templates/settings.tpl | 15 ++++ nbproject/project.properties | 7 ++ nbproject/project.xml | 9 ++ 8 files changed, 233 insertions(+) create mode 100644 cookienotice/README create mode 100644 cookienotice/cookienotice.css create mode 100644 cookienotice/cookienotice.php create mode 100644 cookienotice/templates/cookienotice.tpl create mode 100644 cookienotice/templates/head.tpl create mode 100644 cookienotice/templates/settings.tpl create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/cookienotice/README b/cookienotice/README new file mode 100644 index 000000000..2eebff665 --- /dev/null +++ b/cookienotice/README @@ -0,0 +1,7 @@ +Cookie Notice + +For server admins only. + +Configure, show and handle a simple cookie usage notice. + +Author: Peter liebetrau diff --git a/cookienotice/cookienotice.css b/cookienotice/cookienotice.css new file mode 100644 index 000000000..9c8cf5397 --- /dev/null +++ b/cookienotice/cookienotice.css @@ -0,0 +1,23 @@ +#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; +} diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php new file mode 100644 index 000000000..e8c573ee6 --- /dev/null +++ b/cookienotice/cookienotice.php @@ -0,0 +1,109 @@ + + * + */ +use Friendica\Core\Addon; +use Friendica\Core\Config; +use Friendica\Core\L10n; + +function cookienotice_install() +{ + $file = 'addon/cookienotice/cookienotice.php'; + Addon::registerHook('page_content_top', $file, 'cookienotice_page_content_top'); + Addon::registerHook('page_end', $file, 'cookienotice_page_end'); + Addon::registerHook('addon_settings', $file, 'cookienotice_addon_settings'); + Addon::registerHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); +} + +function cookienotice_uninstall() +{ + $file = 'addon/cookienotice/cookienotice.php'; + Addon::unregisterHook('page_content_top', $file, 'cookienotice_page_content_top'); + Addon::unregisterHook('page_end', $file, 'cookienotice_page_end'); + Addon::unregisterHook('addon_settings', $file, 'cookienotice_addon_settings'); + Addon::unregisterHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); +} + +function cookienotice_addon_settings(&$a, &$s) +{ + if (!is_site_admin()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + + + $text = Config::get('cookienotice', 'text'); + if (!$text) { + $text = ''; + } + $oktext = Config::get('cookienotice', 'oktext'); + if (!$oktext) { + $oktext = ''; + } + + $t = get_markup_template("settings.tpl", "addon/cookienotice/"); + $s .= replace_macros($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; +} + +function cookienotice_addon_settings_post(&$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); + } +} + +/** + * adds the link and script to the page head + * + * @param App $a + * @param string $b - The page html before page_content_top + */ +function cookienotice_page_content_top($a, &$b) +{ + $head = file_get_contents(__DIR__ . '/templates/head.tpl'); + $a->page['htmlhead'] .= $head; +} + +/** + * adds the html to page end + * page_end hook function + * + * @param App $a + * @param string $b - The page html + */ +function cookienotice_page_end($a, &$b) +{ + + $text = (string) Config::get('cookienotice', 'text'); + $oktext = (string) Config::get('cookienotice', 'oktext'); + + $page_end_tpl = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); + + $page_end = replace_macros($page_end_tpl, [ + '$text' => $text, + '$oktext' => $oktext, + ]); + + $b .= $page_end; +} diff --git a/cookienotice/templates/cookienotice.tpl b/cookienotice/templates/cookienotice.tpl new file mode 100644 index 000000000..19ab471e2 --- /dev/null +++ b/cookienotice/templates/cookienotice.tpl @@ -0,0 +1,23 @@ + +

{{$text}}

+ diff --git a/cookienotice/templates/head.tpl b/cookienotice/templates/head.tpl new file mode 100644 index 000000000..7640b28dd --- /dev/null +++ b/cookienotice/templates/head.tpl @@ -0,0 +1,40 @@ + + diff --git a/cookienotice/templates/settings.tpl b/cookienotice/templates/settings.tpl new file mode 100644 index 000000000..6fa8f176d --- /dev/null +++ b/cookienotice/templates/settings.tpl @@ -0,0 +1,15 @@ + +

{{$title}}

+
+ +
diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 000000000..911a7b8bd --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_70 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 000000000..d3fa6afde --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + friendica addons + + + From f3a5f16fc17e6400cae27276ac31ebe2d531bd84 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Sun, 20 Jan 2019 14:20:20 +0100 Subject: [PATCH 2/9] convert spaces to tabs, removed netbeans project files --- .gitignore | 2 +- cookienotice/cookienotice.css | 24 +++--- cookienotice/cookienotice.php | 98 ++++++++++++------------- cookienotice/templates/cookienotice.tpl | 38 +++++----- cookienotice/templates/head.tpl | 72 +++++++++--------- cookienotice/templates/settings.tpl | 4 +- nbproject/project.properties | 7 -- nbproject/project.xml | 9 --- 8 files changed, 118 insertions(+), 136 deletions(-) delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml diff --git a/.gitignore b/.gitignore index 36ccc906e..0d32de00b 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/cookienotice.css b/cookienotice/cookienotice.css index 9c8cf5397..6bbc56bd5 100644 --- a/cookienotice/cookienotice.css +++ b/cookienotice/cookienotice.css @@ -1,23 +1,23 @@ #cookienotice-label { - float: left; - width: 300px; - margin-top: 10px; + float: left; + width: 300px; + margin-top: 10px; } #cookienotice-text { - float: left; - margin-top: 10px; - width: 400px; - height: 150px; + float: left; + margin-top: 10px; + width: 400px; + height: 150px; } #cookienotice-submit { - margin-top: 15px; + margin-top: 15px; } .cookienotice { - text-align: center; - width: 100%; - margin-top: 25px; - font-size: 20px; + text-align: center; + width: 100%; + margin-top: 25px; + font-size: 20px; } diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index e8c573ee6..dd5c1bbda 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -13,64 +13,63 @@ use Friendica\Core\L10n; function cookienotice_install() { - $file = 'addon/cookienotice/cookienotice.php'; - Addon::registerHook('page_content_top', $file, 'cookienotice_page_content_top'); - Addon::registerHook('page_end', $file, 'cookienotice_page_end'); - Addon::registerHook('addon_settings', $file, 'cookienotice_addon_settings'); - Addon::registerHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); + $file = 'addon/cookienotice/cookienotice.php'; + Addon::registerHook('page_content_top', $file, 'cookienotice_page_content_top'); + Addon::registerHook('page_end', $file, 'cookienotice_page_end'); + Addon::registerHook('addon_settings', $file, 'cookienotice_addon_settings'); + Addon::registerHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); } function cookienotice_uninstall() { - $file = 'addon/cookienotice/cookienotice.php'; - Addon::unregisterHook('page_content_top', $file, 'cookienotice_page_content_top'); - Addon::unregisterHook('page_end', $file, 'cookienotice_page_end'); - Addon::unregisterHook('addon_settings', $file, 'cookienotice_addon_settings'); - Addon::unregisterHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); + $file = 'addon/cookienotice/cookienotice.php'; + Addon::unregisterHook('page_content_top', $file, 'cookienotice_page_content_top'); + Addon::unregisterHook('page_end', $file, 'cookienotice_page_end'); + Addon::unregisterHook('addon_settings', $file, 'cookienotice_addon_settings'); + Addon::unregisterHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); } function cookienotice_addon_settings(&$a, &$s) { - if (!is_site_admin()) - return; + if (!is_site_admin()) + return; - /* Add our stylesheet to the page so we can make our settings look nice */ + /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; - $text = Config::get('cookienotice', 'text'); - if (!$text) { - $text = ''; - } - $oktext = Config::get('cookienotice', 'oktext'); - if (!$oktext) { - $oktext = ''; - } + $text = Config::get('cookienotice', 'text'); + if (!$text) { + $text = ''; + } + $oktext = Config::get('cookienotice', 'oktext'); + if (!$oktext) { + $oktext = ''; + } - $t = get_markup_template("settings.tpl", "addon/cookienotice/"); - $s .= replace_macros($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') - ]); + $t = get_markup_template("settings.tpl", "addon/cookienotice/"); + $s .= replace_macros($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; + return; } function cookienotice_addon_settings_post(&$a, &$b) { + if (!is_site_admin()) + return; - 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); - } + 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); + } } /** @@ -81,8 +80,8 @@ function cookienotice_addon_settings_post(&$a, &$b) */ function cookienotice_page_content_top($a, &$b) { - $head = file_get_contents(__DIR__ . '/templates/head.tpl'); - $a->page['htmlhead'] .= $head; + $head = file_get_contents(__DIR__ . '/templates/head.tpl'); + $a->page['htmlhead'] .= $head; } /** @@ -94,16 +93,15 @@ function cookienotice_page_content_top($a, &$b) */ function cookienotice_page_end($a, &$b) { + $text = (string) Config::get('cookienotice', 'text'); + $oktext = (string) Config::get('cookienotice', 'oktext'); - $text = (string) Config::get('cookienotice', 'text'); - $oktext = (string) Config::get('cookienotice', 'oktext'); + $page_end_tpl = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); - $page_end_tpl = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); + $page_end = replace_macros($page_end_tpl, [ + '$text' => $text, + '$oktext' => $oktext, + ]); - $page_end = replace_macros($page_end_tpl, [ - '$text' => $text, - '$oktext' => $oktext, - ]); - - $b .= $page_end; + $b .= $page_end; } diff --git a/cookienotice/templates/cookienotice.tpl b/cookienotice/templates/cookienotice.tpl index 19ab471e2..bee362d5b 100644 --- a/cookienotice/templates/cookienotice.tpl +++ b/cookienotice/templates/cookienotice.tpl @@ -1,23 +1,23 @@

{{$text}}

diff --git a/cookienotice/templates/head.tpl b/cookienotice/templates/head.tpl index 7640b28dd..ed0fc87a2 100644 --- a/cookienotice/templates/head.tpl +++ b/cookienotice/templates/head.tpl @@ -1,40 +1,40 @@ diff --git a/cookienotice/templates/settings.tpl b/cookienotice/templates/settings.tpl index 6fa8f176d..79a5d9bd3 100644 --- a/cookienotice/templates/settings.tpl +++ b/cookienotice/templates/settings.tpl @@ -5,9 +5,9 @@

{{$title}}

-

{{$description}}

+

{{$description}}

{{include file="field_textarea.tpl" field=$text}} - {{include file="field_input.tpl" field=$oktext}} + {{include file="field_input.tpl" field=$oktext}}
diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 911a7b8bd..000000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,7 +0,0 @@ -include.path=${php.global.include.path} -php.version=PHP_70 -source.encoding=UTF-8 -src.dir=. -tags.asp=false -tags.short=false -web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index d3fa6afde..000000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - org.netbeans.modules.php.project - - - friendica addons - - - From efda326527910ad9d50d6f8239cd335602c68560 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Sun, 20 Jan 2019 15:29:15 +0100 Subject: [PATCH 3/9] cookienotice addon - did the gettext jobs and added german language --- cookienotice/lang/C/messages.po | 53 ++++++++++++++++++++++++++++++ cookienotice/lang/de/messages.po | 56 ++++++++++++++++++++++++++++++++ cookienotice/lang/de/strings.php | 11 +++++++ 3 files changed, 120 insertions(+) create mode 100644 cookienotice/lang/C/messages.po create mode 100644 cookienotice/lang/de/messages.po create mode 100644 cookienotice/lang/de/strings.php diff --git a/cookienotice/lang/C/messages.po b/cookienotice/lang/C/messages.po new file mode 100644 index 000000000..99b843c39 --- /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 000000000..31b981889 --- /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 000000000..a96ff5ff0 --- /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"; From 12c4fcfcae4f9dd0dacff34087d79fb0986c9cc6 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Sun, 20 Jan 2019 20:35:58 +0100 Subject: [PATCH 4/9] cookienotice addon - fixes from pull request reviews --- cookienotice/README | 2 +- cookienotice/cookienotice.css | 26 ++++++ cookienotice/cookienotice.js | 37 +++++++++ cookienotice/cookienotice.php | 102 +++++++++++++++++------- cookienotice/templates/cookienotice.tpl | 21 ----- cookienotice/templates/head.tpl | 41 +--------- cookienotice/templates/settings.tpl | 4 +- 7 files changed, 139 insertions(+), 94 deletions(-) create mode 100644 cookienotice/cookienotice.js diff --git a/cookienotice/README b/cookienotice/README index 2eebff665..74edd44a1 100644 --- a/cookienotice/README +++ b/cookienotice/README @@ -2,6 +2,6 @@ Cookie Notice For server admins only. -Configure, show and handle a simple cookie usage notice. +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 index 6bbc56bd5..f25814323 100644 --- a/cookienotice/cookienotice.css +++ b/cookienotice/cookienotice.css @@ -1,3 +1,4 @@ +/* Admin css */ #cookienotice-label { float: left; width: 300px; @@ -21,3 +22,28 @@ 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 000000000..c92e8c210 --- /dev/null +++ b/cookienotice/cookienotice.js @@ -0,0 +1,37 @@ +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 () { + console.log('clicked'); + 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 index dd5c1bbda..4eea080f2 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -7,32 +7,55 @@ * Author: Peter Liebetrau * */ -use Friendica\Core\Addon; +use Friendica\Core\Hook; use Friendica\Core\Config; use Friendica\Core\L10n; +/** + * cookienotice_install + * registers hooks + * + * @return void + */ function cookienotice_install() { $file = 'addon/cookienotice/cookienotice.php'; - Addon::registerHook('page_content_top', $file, 'cookienotice_page_content_top'); - Addon::registerHook('page_end', $file, 'cookienotice_page_end'); - Addon::registerHook('addon_settings', $file, 'cookienotice_addon_settings'); - Addon::registerHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); + 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() { $file = 'addon/cookienotice/cookienotice.php'; - Addon::unregisterHook('page_content_top', $file, 'cookienotice_page_content_top'); - Addon::unregisterHook('page_end', $file, 'cookienotice_page_end'); - Addon::unregisterHook('addon_settings', $file, 'cookienotice_addon_settings'); - Addon::unregisterHook('addon_settings_post', $file, 'cookienotice_addon_settings_post'); + 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'); } -function cookienotice_addon_settings(&$a, &$s) +/** + * 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()) + if (!is_site_admin()) { return; + } /* Add our stylesheet to the page so we can make our settings look nice */ @@ -50,20 +73,31 @@ function cookienotice_addon_settings(&$a, &$s) $t = get_markup_template("settings.tpl", "addon/cookienotice/"); $s .= replace_macros($t, [ - '$title' => L10n::t('"cookienotice" Settings'), + '$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') + '$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; } -function cookienotice_addon_settings_post(&$a, &$b) +/** + * 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()) + if (!is_site_admin()) { return; + } if ($_POST['cookienotice-submit']) { Config::set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text']))); @@ -73,33 +107,41 @@ function cookienotice_addon_settings_post(&$a, &$b) } /** - * adds the link and script to the page head + * cookienotice_page_content_top + * page_content_top hook + * adds css and scripts to the section of the html * - * @param App $a - * @param string $b - The page html before page_content_top + * @param \Friendica\App $a + * @param string $b unnused - the header html incl. nav + * + * @return void */ -function cookienotice_page_content_top($a, &$b) +function cookienotice_page_content_top(\Friendica\App $a, &$b) { - $head = file_get_contents(__DIR__ . '/templates/head.tpl'); + $a->page['htmlhead'] .= '' . "\r\n"; + $head = file_get_contents(__DIR__ . '/templates/head.tpl'); $a->page['htmlhead'] .= $head; } /** - * adds the html to page end - * page_end hook function + * cookienotice_page_end + * page_end hook + * ads our cookienotice box to the end of the html * - * @param App $a - * @param string $b - The page html + * @param \Friendica\App $a + * @param string $b the page html + * + * @return void */ -function cookienotice_page_end($a, &$b) +function cookienotice_page_end(\Friendica\App $a, &$b) { - $text = (string) Config::get('cookienotice', 'text'); - $oktext = (string) Config::get('cookienotice', 'oktext'); + $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 = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); $page_end = replace_macros($page_end_tpl, [ - '$text' => $text, + '$text' => $text, '$oktext' => $oktext, ]); diff --git a/cookienotice/templates/cookienotice.tpl b/cookienotice/templates/cookienotice.tpl index bee362d5b..71e88c0f0 100644 --- a/cookienotice/templates/cookienotice.tpl +++ b/cookienotice/templates/cookienotice.tpl @@ -1,23 +1,2 @@ -

{{$text}}

diff --git a/cookienotice/templates/head.tpl b/cookienotice/templates/head.tpl index ed0fc87a2..6e21318ab 100644 --- a/cookienotice/templates/head.tpl +++ b/cookienotice/templates/head.tpl @@ -1,40 +1 @@ - - + \ No newline at end of file diff --git a/cookienotice/templates/settings.tpl b/cookienotice/templates/settings.tpl index 79a5d9bd3..68ca99c45 100644 --- a/cookienotice/templates/settings.tpl +++ b/cookienotice/templates/settings.tpl @@ -5,9 +5,9 @@

{{$title}}

-

{{$description}}

+

{{$description}}

{{include file="field_textarea.tpl" field=$text}} - {{include file="field_input.tpl" field=$oktext}} + {{include file="field_input.tpl" field=$oktext}}
From 308e0935890f1fc5791347de10392de8b0f913c4 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Tue, 22 Jan 2019 16:50:13 +0100 Subject: [PATCH 5/9] cookienotice addon - fixes for 2019.01 - Template loading and replace macros --- cookienotice/cookienotice.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index 4eea080f2..f0f7a8ee3 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -7,9 +7,11 @@ * Author: Peter Liebetrau * */ +use Friendica\Core\Addon; use Friendica\Core\Hook; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\Renderer; /** * cookienotice_install @@ -71,8 +73,8 @@ function cookienotice_addon_settings(\Friendica\App $a, &$s) $oktext = ''; } - $t = get_markup_template("settings.tpl", "addon/cookienotice/"); - $s .= replace_macros($t, [ + $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')], @@ -138,9 +140,9 @@ 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 = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); + $page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/"); - $page_end = replace_macros($page_end_tpl, [ + $page_end = Renderer::replaceMacros($page_end_tpl, [ '$text' => $text, '$oktext' => $oktext, ]); From e5cfe5b9a87f2849bbfb011dc29675b036f65b39 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Wed, 23 Jan 2019 10:47:08 +0100 Subject: [PATCH 6/9] cookienotice addon - fixes for #pullrequestreview-195091211 --- cookienotice/cookienotice.php | 22 ++++++++++++---------- cookienotice/templates/head.tpl | 1 - 2 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 cookienotice/templates/head.tpl diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index 4eea080f2..4e87b2c00 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -10,6 +10,7 @@ use Friendica\Core\Hook; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\Renderer; /** * cookienotice_install @@ -58,9 +59,8 @@ function cookienotice_addon_settings(\Friendica\App $a, &$s) } /* Add our stylesheet to the page so we can make our settings look nice */ - - $a->page['htmlhead'] .= '' . "\r\n"; - + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $a->registerStylesheet($stylesheetPath); $text = Config::get('cookienotice', 'text'); if (!$text) { @@ -71,8 +71,8 @@ function cookienotice_addon_settings(\Friendica\App $a, &$s) $oktext = ''; } - $t = get_markup_template("settings.tpl", "addon/cookienotice/"); - $s .= replace_macros($t, [ + $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')], @@ -118,9 +118,11 @@ function cookienotice_addon_settings_post(\Friendica\App $a, &$b) */ function cookienotice_page_content_top(\Friendica\App $a, &$b) { - $a->page['htmlhead'] .= '' . "\r\n"; - $head = file_get_contents(__DIR__ . '/templates/head.tpl'); - $a->page['htmlhead'] .= $head; + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $footerscriptPath = 'addon/cookienotice/cookienotice.js'; + + $a->registerStylesheet($stylesheetPath); + $a->registerFooterScript($footerscriptPath); } /** @@ -138,9 +140,9 @@ 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 = get_markup_template("cookienotice.tpl", "addon/cookienotice/"); + $page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/"); - $page_end = replace_macros($page_end_tpl, [ + $page_end = Renderer::replaceMacros($page_end_tpl, [ '$text' => $text, '$oktext' => $oktext, ]); diff --git a/cookienotice/templates/head.tpl b/cookienotice/templates/head.tpl deleted file mode 100644 index 6e21318ab..000000000 --- a/cookienotice/templates/head.tpl +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 145fb69eb64bf1afc5865d9d38f198dbf01e0371 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Wed, 23 Jan 2019 11:00:52 +0100 Subject: [PATCH 7/9] cookienotice addon - added default values for config data --- cookienotice/cookienotice.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index 7e945c157..fbe5a1b1f 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -7,7 +7,6 @@ * Author: Peter Liebetrau * */ -use Friendica\Core\Addon; use Friendica\Core\Hook; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -60,17 +59,11 @@ function cookienotice_addon_settings(\Friendica\App $a, &$s) } /* Add our stylesheet to the page so we can make our settings look nice */ - $stylesheetPath = 'addon/cookienotice/cookienotice.css'; - $a->registerStylesheet($stylesheetPath); + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $a->registerStylesheet($stylesheetPath); - $text = Config::get('cookienotice', 'text'); - if (!$text) { - $text = ''; - } - $oktext = Config::get('cookienotice', 'oktext'); - if (!$oktext) { - $oktext = ''; - } + $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, [ From 0d8a382f8d0468ff577672fd0b05dcef186bf7c1 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Wed, 23 Jan 2019 11:09:10 +0100 Subject: [PATCH 8/9] cookienotice addon - code styling fixes --- cookienotice/cookienotice.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index fbe5a1b1f..855144683 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -112,11 +112,11 @@ function cookienotice_addon_settings_post(\Friendica\App $a, &$b) */ function cookienotice_page_content_top(\Friendica\App $a, &$b) { - $stylesheetPath = 'addon/cookienotice/cookienotice.css'; - $footerscriptPath = 'addon/cookienotice/cookienotice.js'; + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $footerscriptPath = 'addon/cookienotice/cookienotice.js'; - $a->registerStylesheet($stylesheetPath); - $a->registerFooterScript($footerscriptPath); + $a->registerStylesheet($stylesheetPath); + $a->registerFooterScript($footerscriptPath); } /** From 174828070f88a34e7fa7fbd550687cf970fece02 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Wed, 23 Jan 2019 16:01:28 +0100 Subject: [PATCH 9/9] cookienotice addon - fixes for changerequest #pullrequestreview-195527901 --- cookienotice/cookienotice.js | 1 - cookienotice/cookienotice.php | 18 ++++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cookienotice/cookienotice.js b/cookienotice/cookienotice.js index c92e8c210..0ab06c665 100644 --- a/cookienotice/cookienotice.js +++ b/cookienotice/cookienotice.js @@ -5,7 +5,6 @@ window.addEventListener("load", function () { if (cookie == "") { document.getElementById('cookienotice-box').style.display = 'block'; document.getElementById('cookienotice-ok-button').onclick = function () { - console.log('clicked'); setCookie(cookiename, 1, 365); document.getElementById('cookienotice-box').style.display = 'none'; }; diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index 855144683..376de1ada 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -20,11 +20,10 @@ use Friendica\Core\Renderer; */ function cookienotice_install() { - $file = 'addon/cookienotice/cookienotice.php'; - 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'); + 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'); } /** @@ -35,11 +34,10 @@ function cookienotice_install() */ function cookienotice_uninstall() { - $file = 'addon/cookienotice/cookienotice.php'; - 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'); + 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'); } /**