[global] Renamed class ProxyUtils -> Proxy and aliased it back to ProxyUtils
[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\Addon;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Util\Proxy as ProxyUtils;
15
16 function impressum_install() {
17         Addon::registerHook('load_config', 'addon/impressum/impressum.php', 'impressum_load_config');
18     Addon::registerHook('about_hook', 'addon/impressum/impressum.php', 'impressum_show');
19     Addon::registerHook('page_end', 'addon/impressum/impressum.php', 'impressum_footer');
20     logger("installed impressum Addon");
21 }
22
23 function impressum_uninstall() {
24         Addon::unregisterHook('load_config', 'addon/impressum/impressum.php', 'impressum_load_config');
25     Addon::unregisterHook('about_hook', 'addon/impressum/impressum.php', 'impressum_show');
26     Addon::unregisterHook('page_end', 'addon/impressum/impressum.php', 'impressum_footer');
27     logger("uninstalled impressum Addon");
28 }
29
30 function impressum_module() {
31 }
32 function impressum_content() {
33     $a = get_app();
34     goaway('friendica/');
35 }
36
37 function obfuscate_email ($s) {
38     $s = str_replace('@','(at)',$s);
39     $s = str_replace('.','(dot)',$s);
40     return $s;
41 }
42 function impressum_footer($a, &$b) {
43     $text = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum','footer_text')));
44
45     if (! $text == '') {
46         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/impressum/impressum.css" media="all" />';
47         $b .= '<div class="clear"></div>';
48         $b .= '<div id="impressum_footer">'.$text.'</div>';
49     }
50 }
51
52 function impressum_load_config(\Friendica\App $a)
53 {
54         $a->loadConfigFile(__DIR__. '/config/impressum.ini.php');
55 }
56
57 function impressum_show($a,&$b) {
58     $b .= '<h3>'.L10n::t('Impressum').'</h3>';
59     $owner = Config::get('impressum', 'owner');
60     $owner_profile = Config::get('impressum','ownerprofile');
61     $postal = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum', 'postal')));
62     $notes = ProxyUtils::proxifyHtml(BBCode::convert(Config::get('impressum', 'notes')));
63     $email = obfuscate_email( Config::get('impressum','email') );
64     if (strlen($owner)) {
65         if (strlen($owner_profile)) {
66             $tmp = '<a href="'.$owner_profile.'">'.$owner.'</a>';
67         } else {
68             $tmp = $owner;
69         }
70         if (strlen($email)) {
71             $b .= '<p><strong>'.L10n::t('Site Owner').'</strong>: '. $tmp .'<br /><strong>'.L10n::t('Email Address').'</strong>: '.$email.'</p>';
72         } else {
73             $b .= '<p><strong>'.L10n::t('Site Owner').'</strong>: '. $tmp .'</p>';
74         }
75         if (strlen($postal)) {
76             $b .= '<p><strong>'.L10n::t('Postal Address').'</strong><br />'. $postal .'</p>';
77         }
78         if (strlen($notes)) {
79             $b .= '<p>'.$notes.'</p>';
80         }
81     } else {
82         $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>';
83     }
84 }
85
86 function impressum_addon_admin_post (&$a) {
87     $owner = ((x($_POST, 'owner')) ? notags(trim($_POST['owner'])) : '');
88     $ownerprofile = ((x($_POST, 'ownerprofile')) ? notags(trim($_POST['ownerprofile'])) : '');
89     $postal = ((x($_POST, 'postal')) ? (trim($_POST['postal'])) : '');
90     $notes = ((x($_POST, 'notes')) ? (trim($_POST['notes'])) : '');
91     $email = ((x($_POST, 'email')) ? notags(trim($_POST['email'])) : '');
92     $footer_text = ((x($_POST, 'footer_text')) ? (trim($_POST['footer_text'])) : '');
93     Config::set('impressum','owner',strip_tags($owner));
94     Config::set('impressum','ownerprofile',strip_tags($ownerprofile));
95     Config::set('impressum','postal',strip_tags($postal));
96     Config::set('impressum','email',strip_tags($email));
97     Config::set('impressum','notes',strip_tags($notes));
98     Config::set('impressum','footer_text',strip_tags($footer_text));
99     info(L10n::t('Settings updated.'). EOL );
100 }
101 function impressum_addon_admin (&$a, &$o) {
102     $t = get_markup_template( "admin.tpl", "addon/impressum/" );
103     $o = replace_macros($t, [
104         '$submit' => L10n::t('Save Settings'),
105         '$owner' => ['owner', L10n::t('Site Owner'), Config::get('impressum','owner'), L10n::t('The page operators name.')],
106         '$ownerprofile' => ['ownerprofile', L10n::t('Site Owners Profile'), Config::get('impressum','ownerprofile'), L10n::t('Profile address of the operator.')],
107         '$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.')],
108         '$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.')],
109         '$email' => ['email', L10n::t('Email Address'), Config::get('impressum','email'), L10n::t('How to contact the operator via email. (will be displayed obfuscated)')],
110         '$footer_text' => ['footer_text', L10n::t('Footer note'), Config::get('impressum','footer_text'), L10n::t('Text for the footer. You can use BBCode here.')],
111     ]);
112 }