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