4 * Description: Thread email comment notifications on Gmail and anonymise them
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
10 use Friendica\Core\Hook;
11 use Friendica\Core\Logger;
12 use Friendica\Core\Renderer;
15 function gnot_install() {
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');
21 Logger::log("installed gnot");
25 function gnot_uninstall() {
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');
32 Logger::log("removed gnot");
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.
46 function gnot_settings_post($a,$post) {
47 if(! local_user() || empty($_POST['gnot-submit']))
50 DI::pConfig()->set(local_user(),'gnot','enable',intval($_POST['gnot']));
51 info(DI::l10n()->t('Gnot settings updated.') . EOL);
57 * Called from the Addon Setting form.
58 * Add our own settings info to the page.
64 function gnot_settings(&$a,&$s) {
69 /* Add our stylesheet to the page so we can make our settings look nice */
71 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/gnot/gnot.css' . '" media="all" />' . "\r\n";
73 /* Get the current state of our config variable */
75 $gnot = intval(DI::pConfig()->get(local_user(),'gnot','enable'));
77 $gnot_checked = (($gnot) ? ' checked="checked" ' : '' );
79 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
80 /* Add some HTML to the existing form */
82 $s .= Renderer::replaceMacros($t, [
83 '$title' => DI::l10n()->t('Gnot Settings') ,
84 '$submit' => DI::l10n()->t('Save Settings'),
85 '$enable' => DI::l10n()->t('Enable this addon?'),
86 '$enabled' => $gnot_checked,
87 '$text' => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line.")
92 function gnot_enotify_mail(&$a,&$b) {
93 if((! $b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable'))))
95 if($b['type'] == NOTIFY_COMMENT)
96 $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);