]> git.mxchange.org Git - friendica-addons.git/blob - gnot/gnot.php
advanced content filter added RU translation THX Alexander An
[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\App;
12 use Friendica\Core\Hook;
13 use Friendica\Core\Logger;
14 use Friendica\Core\Renderer;
15 use Friendica\DI;
16 use Friendica\Model\Notification;
17
18 function gnot_install() {
19
20         Hook::register('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
21         Hook::register('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
22         Hook::register('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
23
24         Logger::notice("installed gnot");
25 }
26
27 /**
28  *
29  * Callback from the settings post function.
30  * $post contains the $_POST array.
31  * We will make sure we've got a valid user account
32  * and if so set our configuration setting for this person.
33  *
34  */
35
36 function gnot_settings_post($a,$post) {
37         if(! local_user() || empty($_POST['gnot-submit']))
38                 return;
39
40         DI::pConfig()->set(local_user(),'gnot','enable',intval($_POST['gnot']));
41 }
42
43
44 /**
45  *
46  * Called from the Addon Setting form. 
47  * Add our own settings info to the page.
48  *
49  */
50
51
52
53 function gnot_settings(App &$a, array &$data)
54 {
55         if (!local_user()) {
56                 return;
57         }
58
59         $gnot = intval(DI::pConfig()->get(local_user(), 'gnot', 'enable'));
60
61         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
62         $html = Renderer::replaceMacros($t, [
63                 '$text'    => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line."),
64                 '$enabled' => ['gnot', DI::l10n()->t('Enable this addon?'), $gnot],
65         ]);
66
67         $data = [
68                 'addon' => 'gnot',
69                 'title' => DI::l10n()->t('Gnot Settings'),
70                 'html'  => $html,
71         ];
72 }
73
74
75 function gnot_enotify_mail(&$a,&$b) {
76         if((! $b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable'))))
77                 return;
78         if($b['type'] == Notification\Type::COMMENT)
79                 $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
80 }