Bot added, false positive added
[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\L10n;
14 use Friendica\Core\Logger;
15 use Friendica\Core\Renderer;
16 use Friendica\Util\Config\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     $a = \get_app();
38     $a->internalRedirect('friendica/');
39 }
40
41 function obfuscate_email ($s) {
42     $s = str_replace('@','(at)',$s);
43     $s = str_replace('.','(dot)',$s);
44     return $s;
45 }
46 function impressum_footer($a, &$b) {
47     $text = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum','footer_text')));
48
49     if (! $text == '') {
50         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->getBaseURL().'/addon/impressum/impressum.css" media="all" />';
51         $b .= '<div class="clear"></div>';
52         $b .= '<div id="impressum_footer">'.$text.'</div>';
53     }
54 }
55
56 function impressum_load_config(\Friendica\App $a, ConfigFileLoader $loader)
57 {
58         $a->getConfigCache()->load($loader->loadAddonConfig('impressum'));
59 }
60
61 function impressum_show($a,&$b) {
62     $b .= '<h3>'.L10n::t('Impressum').'</h3>';
63     $owner = Config::get('impressum', 'owner');
64     $owner_profile = Config::get('impressum','ownerprofile');
65     $postal = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum', 'postal')));
66     $notes = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum', 'notes')));
67     $email = obfuscate_email( Config::get('impressum','email') );
68     if (strlen($owner)) {
69         if (strlen($owner_profile)) {
70             $tmp = '<a href="'.$owner_profile.'">'.$owner.'</a>';
71         } else {
72             $tmp = $owner;
73         }
74         if (strlen($email)) {
75             $b .= '<p><strong>'.L10n::t('Site Owner').'</strong>: '. $tmp .'<br /><strong>'.L10n::t('Email Address').'</strong>: '.$email.'</p>';
76         } else {
77             $b .= '<p><strong>'.L10n::t('Site Owner').'</strong>: '. $tmp .'</p>';
78         }
79         if (strlen($postal)) {
80             $b .= '<p><strong>'.L10n::t('Postal Address').'</strong><br />'. $postal .'</p>';
81         }
82         if (strlen($notes)) {
83             $b .= '<p>'.$notes.'</p>';
84         }
85     } else {
86         $b .= '<p>'.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>';
87     }
88 }
89
90 function impressum_addon_admin_post (&$a) {
91     $owner = (!empty($_POST['owner']) ? Strings::escapeTags(trim($_POST['owner'])) : '');
92     $ownerprofile = (!empty($_POST['ownerprofile']) ? Strings::escapeTags(trim($_POST['ownerprofile'])) : '');
93     $postal = (!empty($_POST['postal']) ? (trim($_POST['postal'])) : '');
94     $notes = (!empty($_POST['notes']) ? (trim($_POST['notes'])) : '');
95     $email = (!empty($_POST['email']) ? Strings::escapeTags(trim($_POST['email'])) : '');
96     $footer_text = (!empty($_POST['footer_text']) ? (trim($_POST['footer_text'])) : '');
97     Config::set('impressum','owner',strip_tags($owner));
98     Config::set('impressum','ownerprofile',strip_tags($ownerprofile));
99     Config::set('impressum','postal',strip_tags($postal));
100     Config::set('impressum','email',strip_tags($email));
101     Config::set('impressum','notes',strip_tags($notes));
102     Config::set('impressum','footer_text',strip_tags($footer_text));
103     info(L10n::t('Settings updated.'). EOL );
104 }
105 function impressum_addon_admin (&$a, &$o) {
106     $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/impressum/" );
107     $o = Renderer::replaceMacros($t, [
108         '$submit' => L10n::t('Save Settings'),
109         '$owner' => ['owner', L10n::t('Site Owner'), Config::get('impressum','owner'), L10n::t('The page operators name.')],
110         '$ownerprofile' => ['ownerprofile', L10n::t('Site Owners Profile'), Config::get('impressum','ownerprofile'), L10n::t('Profile address of the operator.')],
111         '$postal' => ['postal', L10n::t('Postal Address'), Config::get('impressum','postal'), L10n::t('How to contact the operator via snail mail. You can use BBCode here.')],
112         '$notes' => ['notes', L10n::t('Notes'), Config::get('impressum','notes'), L10n::t('Additional notes that are displayed beneath the contact information. You can use BBCode here.')],
113         '$email' => ['email', L10n::t('Email Address'), Config::get('impressum','email'), L10n::t('How to contact the operator via email. (will be displayed obfuscated)')],
114         '$footer_text' => ['footer_text', L10n::t('Footer note'), Config::get('impressum','footer_text'), L10n::t('Text for the footer. You can use BBCode here.')],
115     ]);
116 }