convert spaces to tabs, removed netbeans project files
[friendica-addons.git/.git] / cookienotice / cookienotice.php
1 <?php
2
3 /**
4  * Name: Cookie Notice
5  * Description: Configure, show and handle a simple cookie notice
6  * Version: 1.0
7  * Author: Peter Liebetrau <https://socivitas/profile/peerteer>
8  * 
9  */
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13
14 function cookienotice_install()
15 {
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');
21 }
22
23 function cookienotice_uninstall()
24 {
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');
30 }
31
32 function cookienotice_addon_settings(&$a, &$s)
33 {
34         if (!is_site_admin())
35                 return;
36
37         /* Add our stylesheet to the page so we can make our settings look nice */
38
39         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="/addon/cookienotice/cookienotice.css" media="all" />' . "\r\n";
40
41
42         $text = Config::get('cookienotice', 'text');
43         if (!$text) {
44                 $text = '';
45         }
46         $oktext = Config::get('cookienotice', 'oktext');
47         if (!$oktext) {
48                 $oktext = '';
49         }
50
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')
58         ]);
59
60         return;
61 }
62
63 function cookienotice_addon_settings_post(&$a, &$b)
64 {
65         if (!is_site_admin())
66                 return;
67
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);
72         }
73 }
74
75 /**
76  * adds the link and script to the page head
77  * 
78  * @param App $a
79  * @param string $b - The page html before page_content_top
80  */
81 function cookienotice_page_content_top($a, &$b)
82 {
83         $head                           = file_get_contents(__DIR__ . '/templates/head.tpl');
84         $a->page['htmlhead'] .= $head;
85 }
86
87 /**
88  * adds the html to page end
89  * page_end hook function
90  * 
91  * @param App $a
92  * @param string $b - The page html
93  */
94 function cookienotice_page_end($a, &$b)
95 {
96         $text   = (string) Config::get('cookienotice', 'text');
97         $oktext = (string) Config::get('cookienotice', 'oktext');
98
99         $page_end_tpl = get_markup_template("cookienotice.tpl", "addon/cookienotice/");
100
101         $page_end = replace_macros($page_end_tpl, [
102                 '$text'   => $text,
103                 '$oktext' => $oktext,
104         ]);
105
106         $b .= $page_end;
107 }