5 * Description: Configure, show and handle a simple cookie notice
7 * Author: Peter Liebetrau <https://socivitas/profile/peerteer>
10 use Friendica\Core\Hook;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\Renderer;
16 * cookienotice_install
21 function cookienotice_install()
23 $file = 'addon/cookienotice/cookienotice.php';
24 Hook::register('page_content_top', $file, 'cookienotice_page_content_top');
25 Hook::register('page_end', $file, 'cookienotice_page_end');
26 Hook::register('addon_settings', $file, 'cookienotice_addon_settings');
27 Hook::register('addon_settings_post', $file, 'cookienotice_addon_settings_post');
31 * cookienotice_uninstall
36 function cookienotice_uninstall()
38 $file = 'addon/cookienotice/cookienotice.php';
39 Hook::unregister('page_content_top', $file, 'cookienotice_page_content_top');
40 Hook::unregister('page_end', $file, 'cookienotice_page_end');
41 Hook::unregister('addon_settings', $file, 'cookienotice_addon_settings');
42 Hook::unregister('addon_settings_post', $file, 'cookienotice_addon_settings_post');
46 * cookienotice_addon_settings
48 * creates the admins config panel
50 * @param \Friendica\App $a
51 * @param string $s The existing config panel html so far
55 function cookienotice_addon_settings(\Friendica\App $a, &$s)
57 if (!is_site_admin()) {
61 /* Add our stylesheet to the page so we can make our settings look nice */
62 $stylesheetPath = 'addon/cookienotice/cookienotice.css';
63 $a->registerStylesheet($stylesheetPath);
65 $text = Config::get('cookienotice', 'text');
69 $oktext = Config::get('cookienotice', 'oktext');
74 $t = Renderer::getMarkupTemplate("settings.tpl", "addon/cookienotice/");
75 $s .= Renderer::replaceMacros($t, [
76 '$title' => L10n::t('"cookienotice" Settings'),
77 '$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.'),
78 '$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text, L10n::t('The cookie usage notice')],
79 '$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext, L10n::t('The OK Button text')],
80 '$submit' => L10n::t('Save Settings')
87 * cookienotice_addon_settings_post
88 * addon_settings_post hook
89 * handles the post request from the admin panel
91 * @param \Friendica\App $a
96 function cookienotice_addon_settings_post(\Friendica\App $a, &$b)
98 if (!is_site_admin()) {
102 if ($_POST['cookienotice-submit']) {
103 Config::set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text'])));
104 Config::set('cookienotice', 'oktext', trim(strip_tags($_POST['cookienotice-oktext'])));
105 info(L10n::t('cookienotice Settings saved.') . EOL);
110 * cookienotice_page_content_top
111 * page_content_top hook
112 * adds css and scripts to the <head> section of the html
114 * @param \Friendica\App $a
115 * @param string $b unnused - the header html incl. nav
119 function cookienotice_page_content_top(\Friendica\App $a, &$b)
121 $stylesheetPath = 'addon/cookienotice/cookienotice.css';
122 $footerscriptPath = 'addon/cookienotice/cookienotice.js';
124 $a->registerStylesheet($stylesheetPath);
125 $a->registerFooterScript($footerscriptPath);
129 * cookienotice_page_end
131 * ads our cookienotice box to the end of the html
133 * @param \Friendica\App $a
134 * @param string $b the page html
138 function cookienotice_page_end(\Friendica\App $a, &$b)
140 $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.'));
141 $oktext = (string) Config::get('cookienotice', 'oktext', L10n::t('OK'));
143 $page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/");
145 $page_end = Renderer::replaceMacros($page_end_tpl, [
147 '$oktext' => $oktext,