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