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