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