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\Config;
12 use Friendica\Core\L10n;
14 function cookienotice_install()
16 $file = 'addon/cookienotice/cookienotice.php';
17 Addon::registerHook('page_content_top', $file, 'cookienotice_page_content_top');
18 Addon::registerHook('page_end', $file, 'cookienotice_page_end');
19 Addon::registerHook('addon_settings', $file, 'cookienotice_addon_settings');
20 Addon::registerHook('addon_settings_post', $file, 'cookienotice_addon_settings_post');
23 function cookienotice_uninstall()
25 $file = 'addon/cookienotice/cookienotice.php';
26 Addon::unregisterHook('page_content_top', $file, 'cookienotice_page_content_top');
27 Addon::unregisterHook('page_end', $file, 'cookienotice_page_end');
28 Addon::unregisterHook('addon_settings', $file, 'cookienotice_addon_settings');
29 Addon::unregisterHook('addon_settings_post', $file, 'cookienotice_addon_settings_post');
32 function cookienotice_addon_settings(&$a, &$s)
37 /* Add our stylesheet to the page so we can make our settings look nice */
39 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="/addon/cookienotice/cookienotice.css" media="all" />' . "\r\n";
42 $text = Config::get('cookienotice', 'text');
46 $oktext = Config::get('cookienotice', 'oktext');
51 $t = get_markup_template("settings.tpl", "addon/cookienotice/");
52 $s .= replace_macros($t, [
53 '$title' => L10n::t('"cookienotice" Settings'),
54 '$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.'),
55 '$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text, L10n::t('The cookie usage notice')],
56 '$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext, L10n::t('The OK Button text')],
57 '$submit' => L10n::t('Save Settings')
63 function cookienotice_addon_settings_post(&$a, &$b)
68 if ($_POST['cookienotice-submit']) {
69 Config::set('cookienotice', 'text', trim(strip_tags($_POST['cookienotice-text'])));
70 Config::set('cookienotice', 'oktext', trim(strip_tags($_POST['cookienotice-oktext'])));
71 info(L10n::t('cookienotice Settings saved.') . EOL);
76 * adds the link and script to the page head
79 * @param string $b - The page html before page_content_top
81 function cookienotice_page_content_top($a, &$b)
83 $head = file_get_contents(__DIR__ . '/templates/head.tpl');
84 $a->page['htmlhead'] .= $head;
88 * adds the html to page end
89 * page_end hook function
92 * @param string $b - The page html
94 function cookienotice_page_end($a, &$b)
96 $text = (string) Config::get('cookienotice', 'text');
97 $oktext = (string) Config::get('cookienotice', 'oktext');
99 $page_end_tpl = get_markup_template("cookienotice.tpl", "addon/cookienotice/");
101 $page_end = replace_macros($page_end_tpl, [
103 '$oktext' => $oktext,