[various] Move notification classes
[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
11 use Friendica\Core\Hook;
12 use Friendica\Core\Logger;
13 use Friendica\Core\Renderer;
14 use Friendica\DI;
15 use Friendica\Model\Notification;
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  *
28  * Callback from the settings post function.
29  * $post contains the $_POST array.
30  * We will make sure we've got a valid user account
31  * and if so set our configuration setting for this person.
32  *
33  */
34
35 function gnot_settings_post($a,$post) {
36         if(! local_user() || empty($_POST['gnot-submit']))
37                 return;
38
39         DI::pConfig()->set(local_user(),'gnot','enable',intval($_POST['gnot']));
40 }
41
42
43 /**
44  *
45  * Called from the Addon Setting form. 
46  * Add our own settings info to the page.
47  *
48  */
49
50
51
52 function gnot_settings(&$a,&$s) {
53
54         if(! local_user())
55                 return;
56
57         /* Add our stylesheet to the page so we can make our settings look nice */
58
59         DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/gnot/gnot.css' . '" media="all" />' . "\r\n";
60
61         /* Get the current state of our config variable */
62
63         $gnot = intval(DI::pConfig()->get(local_user(),'gnot','enable'));
64
65         $gnot_checked = (($gnot) ? ' checked="checked" ' : '' );
66         
67         $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
68         /* Add some HTML to the existing form */
69
70         $s .= Renderer::replaceMacros($t, [
71                 '$title' => DI::l10n()->t('Gnot Settings') ,
72                 '$submit' => DI::l10n()->t('Save Settings'),
73                 '$enable' => DI::l10n()->t('Enable this addon?'),
74                 '$enabled' => $gnot_checked,
75                 '$text' => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line.")
76         ]);
77 }
78
79
80 function gnot_enotify_mail(&$a,&$b) {
81         if((! $b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable'))))
82                 return;
83         if($b['type'] == Notification\Type::COMMENT)
84                 $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
85 }