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