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