]> git.mxchange.org Git - friendica-addons.git/blob - gnot/gnot.php
Update obsolete App::getBaseUrl calls to DI::baseUrl
[friendica-addons.git] / gnot / gnot.php
1 <?php
2 /**
3  * Name: Gnot
4  * Description: Thread email comment notifications on Gmail and anonymise them
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * 
8  *
9  */
10 use Friendica\Core\Hook;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Logger;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\Renderer;
15 use Friendica\DI;
16
17 function gnot_install() {
18
19         Hook::register('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
20         Hook::register('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
21         Hook::register('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
22
23         Logger::log("installed gnot");
24 }
25
26
27 function gnot_uninstall() {
28
29         Hook::unregister('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
30         Hook::unregister('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
31         Hook::unregister('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
32
33
34         Logger::log("removed gnot");
35 }
36
37
38
39 /**
40  *
41  * Callback from the settings post function.
42  * $post contains the $_POST array.
43  * We will make sure we've got a valid user account
44  * and if so set our configuration setting for this person.
45  *
46  */
47
48 function gnot_settings_post($a,$post) {
49         if(! local_user() || empty($_POST['gnot-submit']))
50                 return;
51
52         PConfig::set(local_user(),'gnot','enable',intval($_POST['gnot']));
53         info(L10n::t('Gnot settings updated.') . EOL);
54 }
55
56
57 /**
58  *
59  * Called from the Addon Setting form. 
60  * Add our own settings info to the page.
61  *
62  */
63
64
65
66 function gnot_settings(&$a,&$s) {
67
68         if(! local_user())
69                 return;
70
71         /* Add our stylesheet to the page so we can make our settings look nice */
72
73         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/gnot/gnot.css' . '" media="all" />' . "\r\n";
74
75         /* Get the current state of our config variable */
76
77         $gnot = intval(PConfig::get(local_user(),'gnot','enable'));
78
79         $gnot_checked = (($gnot) ? ' checked="checked" ' : '' );
80         
81         $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
82         /* Add some HTML to the existing form */
83
84         $s .= Renderer::replaceMacros($t, [
85                 '$title' => L10n::t('Gnot Settings') ,
86                 '$submit' => L10n::t('Save Settings'),
87                 '$enable' => L10n::t('Enable this addon?'),
88                 '$enabled' => $gnot_checked,
89                 '$text' => L10n::t("Allows threading of email comment notifications on Gmail and anonymising the subject line.") 
90         ]);
91 }
92
93
94 function gnot_enotify_mail(&$a,&$b) {
95         if((! $b['uid']) || (! intval(PConfig::get($b['uid'], 'gnot','enable'))))
96                 return;
97         if($b['type'] == NOTIFY_COMMENT)
98                 $b['subject'] = L10n::t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
99 }