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