5 * Description: Configure, show and handle a simple cookie notice
7 * Author: Peter Liebetrau <https://socivitas/profile/peerteer>
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
16 * cookienotice_install
21 function cookienotice_install()
23 Hook::register('page_content_top', __FILE__, 'cookienotice_page_content_top');
24 Hook::register('page_end', __FILE__, 'cookienotice_page_end');
28 * cookienotice_addon_admin
29 * creates the admins config panel
31 * @param string $s The existing config panel html so far
35 function cookienotice_addon_admin(&$s)
37 if (!DI::userSession()->isSiteAdmin()) {
41 $text = DI::config()->get('cookienotice', 'text', DI::l10n()->t('This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.'));
42 $oktext = DI::config()->get('cookienotice', 'oktext', DI::l10n()->t('OK'));
44 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/cookienotice/');
45 $s .= Renderer::replaceMacros($t, [
46 '$description' => DI::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.'),
47 '$text' => ['cookienotice-text', DI::l10n()->t('Cookie Usage Notice'), $text],
48 '$oktext' => ['cookienotice-oktext', DI::l10n()->t('OK Button Text'), $oktext],
49 '$submit' => DI::l10n()->t('Save Settings')
56 * cookienotice_addon_admin_post
57 * handles the post request from the admin panel
61 function cookienotice_addon_admin_post()
63 if (!DI::userSession()->isSiteAdmin()) {
67 if ($_POST['cookienotice-submit']) {
68 DI::config()->set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text'])));
69 DI::config()->set('cookienotice', 'oktext', trim(strip_tags($_POST['cookienotice-oktext'])));
74 * cookienotice_page_content_top
75 * page_content_top hook
76 * adds css and scripts to the <head> section of the html
78 * @param string $b unused - the header html incl. nav
82 function cookienotice_page_content_top(string &$b)
84 DI::page()->registerStylesheet(__DIR__ . '/cookienotice.css');
85 DI::page()->registerFooterScript(__DIR__ . '/cookienotice.js');
89 * cookienotice_page_end
91 * ads our cookienotice box to the end of the html
93 * @param string $b the page html
97 function cookienotice_page_end(string &$b)
99 $text = (string)DI::config()->get('cookienotice', 'text', DI::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.'));
100 $oktext = (string)DI::config()->get('cookienotice', 'oktext', DI::l10n()->t('OK'));
102 $page_end_tpl = Renderer::getMarkupTemplate('cookienotice.tpl', 'addon/cookienotice/');
104 $page_end = Renderer::replaceMacros($page_end_tpl, [
106 '$oktext' => $oktext,