]> git.mxchange.org Git - friendica-addons.git/blob - cookienotice/cookienotice.php
invidious/invidious.php aktualisiert
[friendica-addons.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\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 /**
16  * cookienotice_install
17  * registers hooks
18  *
19  * @return void
20  */
21 function cookienotice_install()
22 {
23         Hook::register('page_content_top', __FILE__, 'cookienotice_page_content_top');
24         Hook::register('page_end', __FILE__, 'cookienotice_page_end');
25 }
26
27 /**
28  * cookienotice_addon_admin
29  * creates the admins config panel
30  *
31  * @param string $s The existing config panel html so far
32  *
33  * @return void
34  */
35 function cookienotice_addon_admin(&$s)
36 {
37         if (!DI::userSession()->isSiteAdmin()) {
38                 return;
39         }
40
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'));
43
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')
50         ]);
51
52         return;
53 }
54
55 /**
56  * cookienotice_addon_admin_post
57  * handles the post request from the admin panel
58  *
59  * @return void
60  */
61 function cookienotice_addon_admin_post()
62 {
63         if (!DI::userSession()->isSiteAdmin()) {
64                 return;
65         }
66
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'])));
70         }
71 }
72
73 /**
74  * cookienotice_page_content_top
75  * page_content_top hook
76  * adds css and scripts to the <head> section of the html
77  *
78  * @param string $b unused - the header html incl. nav
79  *
80  * @return void
81  */
82 function cookienotice_page_content_top(string &$b)
83 {
84         DI::page()->registerStylesheet(__DIR__ . '/cookienotice.css');
85         DI::page()->registerFooterScript(__DIR__ . '/cookienotice.js');
86 }
87
88 /**
89  * cookienotice_page_end
90  * page_end hook
91  * ads our cookienotice box to the end of the html
92  *
93  * @param string $b the page html
94  *
95  * @return void
96  */
97 function cookienotice_page_end(string &$b)
98 {
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'));
101
102         $page_end_tpl = Renderer::getMarkupTemplate('cookienotice.tpl', 'addon/cookienotice/');
103
104         $page_end = Renderer::replaceMacros($page_end_tpl, [
105                 '$text' => $text,
106                 '$oktext' => $oktext,
107         ]);
108
109         $b .= $page_end;
110 }