]> git.mxchange.org Git - friendica-addons.git/blob - impressum/impressum.php
4002963221b54b7c186fac84e5aa990c11822735
[friendica-addons.git] / impressum / impressum.php
1 <?php
2 /**
3  * Name: Impressum
4  * Description: Addon to add contact information to the about page (/friendica)
5  * Version: 1.3
6  * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
7  * License: 3-clause BSD license
8  */
9
10 use Friendica\App;
11 use Friendica\Content\Text\BBCode;
12 use Friendica\Core\Hook;
13 use Friendica\Core\Logger;
14 use Friendica\Core\Renderer;
15 use Friendica\DI;
16 use Friendica\Core\Config\Util\ConfigFileLoader;
17 use Friendica\Util\Proxy as ProxyUtils;
18
19 function impressum_install()
20 {
21         Hook::register('load_config', 'addon/impressum/impressum.php', 'impressum_load_config');
22         Hook::register('about_hook', 'addon/impressum/impressum.php', 'impressum_show');
23         Hook::register('page_end', 'addon/impressum/impressum.php', 'impressum_footer');
24         Logger::notice("installed impressum Addon");
25 }
26
27 function impressum_module()
28 {
29 }
30
31 function impressum_content()
32 {
33         DI::baseUrl()->redirect('friendica/');
34 }
35
36 function obfuscate_email (string $s): string
37 {
38         $s = str_replace('@', '(at)', $s);
39         $s = str_replace('.', '(dot)', $s);
40         return $s;
41 }
42
43 function impressum_footer(App $a, array &$b)
44 {
45         $text = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum','footer_text')));
46
47         if (! $text == '') {
48                 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.DI::baseUrl()->get().'/addon/impressum/impressum.css" media="all" />';
49                 $b .= '<div class="clear"></div>';
50                 $b .= '<div id="impressum_footer">'.$text.'</div>';
51         }
52 }
53
54 function impressum_load_config(App $a, ConfigFileLoader $loader)
55 {
56         $a->getConfigCache()->load($loader->loadAddonConfig('impressum'));
57 }
58
59 function impressum_show(App $a, array &$b)
60 {
61         $b .= '<h3>' . DI::l10n()->t('Impressum') . '</h3>';
62         $owner = DI::config()->get('impressum', 'owner');
63         $owner_profile = DI::config()->get('impressum', 'ownerprofile');
64         $postal = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'postal')));
65         $notes = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'notes')));
66         $email = obfuscate_email( DI::config()->get('impressum', 'email') );
67
68         if (strlen($owner)) {
69                 if (strlen($owner_profile)) {
70                         $tmp = '<a href="' . $owner_profile . '">' . $owner . '</a>';
71                 } else {
72                         $tmp = $owner;
73                 }
74
75                 if (strlen($email)) {
76                         $b .= '<p><strong>' . DI::l10n()->t('Site Owner').'</strong>: ' . $tmp .'<br /><strong>' . DI::l10n()->t('Email Address') . '</strong>: ' . $email . '</p>';
77                 } else {
78                         $b .= '<p><strong>' . DI::l10n()->t('Site Owner').'</strong>: ' . $tmp .'</p>';
79                 }
80
81                 if (strlen($postal)) {
82                         $b .= '<p><strong>' . DI::l10n()->t('Postal Address') . '</strong><br />' . $postal . '</p>';
83                 }
84
85                 if (strlen($notes)) {
86                         $b .= '<p>' . $notes . '</p>';
87                 }
88         } else {
89                 $b .= '<p>' . DI::l10n()->t('The impressum addon needs to be configured!<br />Please add at least the <tt>owner</tt> variable to your config file. For other variables please refer to the README file of the addon.') . '</p>';
90         }
91 }
92
93 function impressum_addon_admin_post (App $a)
94 {
95         $owner = trim($_POST['owner'] ?? '');
96         $ownerprofile = trim($_POST['ownerprofile'] ?? '');
97         $postal = trim($_POST['postal'] ?? '');
98         $notes = trim($_POST['notes'] ?? '');
99         $email = trim($_POST['email'] ?? '');
100         $footer_text = trim($_POST['footer_text'] ?? '');
101
102         DI::config()->set('impressum', 'owner', strip_tags($owner));
103         DI::config()->set('impressum', 'ownerprofile', strip_tags($ownerprofile));
104         DI::config()->set('impressum', 'postal', strip_tags($postal));
105         DI::config()->set('impressum', 'email', strip_tags($email));
106         DI::config()->set('impressum', 'notes', strip_tags($notes));
107         DI::config()->set('impressum', 'footer_text', strip_tags($footer_text));
108 }
109
110 function impressum_addon_admin (App $a, &$o)
111 {
112         $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/impressum/' );
113         $o = Renderer::replaceMacros($t, [
114                 '$submit' => DI::l10n()->t('Save Settings'),
115                 '$owner' => ['owner', DI::l10n()->t('Site Owner'), DI::config()->get('impressum','owner'), DI::l10n()->t('The page operators name.')],
116                 '$ownerprofile' => ['ownerprofile', DI::l10n()->t('Site Owners Profile'), DI::config()->get('impressum','ownerprofile'), DI::l10n()->t('Profile address of the operator.')],
117                 '$postal' => ['postal', DI::l10n()->t('Postal Address'), DI::config()->get('impressum','postal'), DI::l10n()->t('How to contact the operator via snail mail. You can use BBCode here.')],
118                 '$notes' => ['notes', DI::l10n()->t('Notes'), DI::config()->get('impressum','notes'), DI::l10n()->t('Additional notes that are displayed beneath the contact information. You can use BBCode here.')],
119                 '$email' => ['email', DI::l10n()->t('Email Address'), DI::config()->get('impressum','email'), DI::l10n()->t('How to contact the operator via email. (will be displayed obfuscated)')],
120                 '$footer_text' => ['footer_text', DI::l10n()->t('Footer note'), DI::config()->get('impressum','footer_text'), DI::l10n()->t('Text for the footer. You can use BBCode here.')],
121         ]);
122 }