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