5 * Description: Configure, show and handle a simple cookie notice
7 * Author: Peter Liebetrau <https://socivitas/profile/peerteer>
10 use Friendica\Core\Addon;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Core\Renderer;
17 * cookienotice_install
22 function cookienotice_install()
24 $file = 'addon/cookienotice/cookienotice.php';
25 Hook::register('page_content_top', $file, 'cookienotice_page_content_top');
26 Hook::register('page_end', $file, 'cookienotice_page_end');
27 Hook::register('addon_settings', $file, 'cookienotice_addon_settings');
28 Hook::register('addon_settings_post', $file, 'cookienotice_addon_settings_post');
32 * cookienotice_uninstall
37 function cookienotice_uninstall()
39 $file = 'addon/cookienotice/cookienotice.php';
40 Hook::unregister('page_content_top', $file, 'cookienotice_page_content_top');
41 Hook::unregister('page_end', $file, 'cookienotice_page_end');
42 Hook::unregister('addon_settings', $file, 'cookienotice_addon_settings');
43 Hook::unregister('addon_settings_post', $file, 'cookienotice_addon_settings_post');
47 * cookienotice_addon_settings
49 * creates the admins config panel
51 * @param \Friendica\App $a
52 * @param string $s The existing config panel html so far
56 function cookienotice_addon_settings(\Friendica\App $a, &$s)
58 if (!is_site_admin()) {
62 /* Add our stylesheet to the page so we can make our settings look nice */
63 $stylesheetPath = 'addon/cookienotice/cookienotice.css';
64 $a->registerStylesheet($stylesheetPath);
66 $text = Config::get('cookienotice', 'text');
70 $oktext = Config::get('cookienotice', 'oktext');
75 $t = Renderer::getMarkupTemplate("settings.tpl", "addon/cookienotice/");
76 $s .= Renderer::replaceMacros($t, [
77 '$title' => L10n::t('"cookienotice" Settings'),
78 '$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.'),
79 '$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text, L10n::t('The cookie usage notice')],
80 '$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext, L10n::t('The OK Button text')],
81 '$submit' => L10n::t('Save Settings')
88 * cookienotice_addon_settings_post
89 * addon_settings_post hook
90 * handles the post request from the admin panel
92 * @param \Friendica\App $a
97 function cookienotice_addon_settings_post(\Friendica\App $a, &$b)
99 if (!is_site_admin()) {
103 if ($_POST['cookienotice-submit']) {
104 Config::set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text'])));
105 Config::set('cookienotice', 'oktext', trim(strip_tags($_POST['cookienotice-oktext'])));
106 info(L10n::t('cookienotice Settings saved.') . EOL);
111 * cookienotice_page_content_top
112 * page_content_top hook
113 * adds css and scripts to the <head> section of the html
115 * @param \Friendica\App $a
116 * @param string $b unnused - the header html incl. nav
120 function cookienotice_page_content_top(\Friendica\App $a, &$b)
122 $stylesheetPath = 'addon/cookienotice/cookienotice.css';
123 $footerscriptPath = 'addon/cookienotice/cookienotice.js';
125 $a->registerStylesheet($stylesheetPath);
126 $a->registerFooterScript($footerscriptPath);
130 * cookienotice_page_end
132 * ads our cookienotice box to the end of the html
134 * @param \Friendica\App $a
135 * @param string $b the page html
139 function cookienotice_page_end(\Friendica\App $a, &$b)
141 $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.'));
142 $oktext = (string) Config::get('cookienotice', 'oktext', L10n::t('OK'));
144 $page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/");
146 $page_end = Renderer::replaceMacros($page_end_tpl, [
148 '$oktext' => $oktext,