bcbe4235964735f0c244b688d04bbb793fc86685
[friendica-addons.git/.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\Content\Text\BBCode;
11 use Friendica\Core\Config;
12 use Friendica\Core\Hook;
13 use Friendica\Core\Logger;
14 use Friendica\Core\Renderer;
15 use Friendica\DI;
16 use Friendica\Util\ConfigFileLoader;
17 use Friendica\Util\Proxy as ProxyUtils;
18 use Friendica\Util\Strings;
19
20 function impressum_install() {
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::log("installed impressum Addon");
25 }
26
27 function impressum_uninstall() {
28         Hook::unregister('load_config', 'addon/impressum/impressum.php', 'impressum_load_config');
29     Hook::unregister('about_hook', 'addon/impressum/impressum.php', 'impressum_show');
30     Hook::unregister('page_end', 'addon/impressum/impressum.php', 'impressum_footer');
31     Logger::log("uninstalled impressum Addon");
32 }
33
34 function impressum_module() {
35 }
36 function impressum_content() {
37     DI::baseUrl()->redirect('friendica/');
38 }
39
40 function obfuscate_email ($s) {
41     $s = str_replace('@','(at)',$s);
42     $s = str_replace('.','(dot)',$s);
43     return $s;
44 }
45 function impressum_footer($a, &$b) {
46     $text = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum','footer_text')));
47
48     if (! $text == '') {
49         DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.DI::baseUrl()->get().'/addon/impressum/impressum.css" media="all" />';
50         $b .= '<div class="clear"></div>';
51         $b .= '<div id="impressum_footer">'.$text.'</div>';
52     }
53 }
54
55 function impressum_load_config(\Friendica\App $a, ConfigFileLoader $loader)
56 {
57         $a->getConfigCache()->load($loader->loadAddonConfig('impressum'));
58 }
59
60 function impressum_show($a,&$b) {
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     if (strlen($owner)) {
68         if (strlen($owner_profile)) {
69             $tmp = '<a href="'.$owner_profile.'">'.$owner.'</a>';
70         } else {
71             $tmp = $owner;
72         }
73         if (strlen($email)) {
74             $b .= '<p><strong>'.DI::l10n()->t('Site Owner').'</strong>: '. $tmp .'<br /><strong>'.DI::l10n()->t('Email Address').'</strong>: '.$email.'</p>';
75         } else {
76             $b .= '<p><strong>'.DI::l10n()->t('Site Owner').'</strong>: '. $tmp .'</p>';
77         }
78         if (strlen($postal)) {
79             $b .= '<p><strong>'.DI::l10n()->t('Postal Address').'</strong><br />'. $postal .'</p>';
80         }
81         if (strlen($notes)) {
82             $b .= '<p>'.$notes.'</p>';
83         }
84     } else {
85         $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>';
86     }
87 }
88
89 function impressum_addon_admin_post (&$a) {
90     $owner = (!empty($_POST['owner']) ? Strings::escapeTags(trim($_POST['owner'])) : '');
91     $ownerprofile = (!empty($_POST['ownerprofile']) ? Strings::escapeTags(trim($_POST['ownerprofile'])) : '');
92     $postal = (!empty($_POST['postal']) ? (trim($_POST['postal'])) : '');
93     $notes = (!empty($_POST['notes']) ? (trim($_POST['notes'])) : '');
94     $email = (!empty($_POST['email']) ? Strings::escapeTags(trim($_POST['email'])) : '');
95     $footer_text = (!empty($_POST['footer_text']) ? (trim($_POST['footer_text'])) : '');
96     Config::set('impressum','owner',strip_tags($owner));
97     Config::set('impressum','ownerprofile',strip_tags($ownerprofile));
98     Config::set('impressum','postal',strip_tags($postal));
99     Config::set('impressum','email',strip_tags($email));
100     Config::set('impressum','notes',strip_tags($notes));
101     Config::set('impressum','footer_text',strip_tags($footer_text));
102     info(DI::l10n()->t('Settings updated.'). EOL );
103 }
104 function impressum_addon_admin (&$a, &$o) {
105     $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/impressum/" );
106     $o = Renderer::replaceMacros($t, [
107         '$submit' => DI::l10n()->t('Save Settings'),
108         '$owner' => ['owner', DI::l10n()->t('Site Owner'), DI::config()->get('impressum','owner'), DI::l10n()->t('The page operators name.')],
109         '$ownerprofile' => ['ownerprofile', DI::l10n()->t('Site Owners Profile'), DI::config()->get('impressum','ownerprofile'), DI::l10n()->t('Profile address of the operator.')],
110         '$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.')],
111         '$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.')],
112         '$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)')],
113         '$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.')],
114     ]);
115 }