]> git.mxchange.org Git - friendica-addons.git/blob - gnot/gnot.php
Merge pull request 'CLD2: Use ISO-639-1 for the language detection' (#1433) from...
[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  * Callback from the settings post function.
29  * $post contains the $_POST array.
30  * We will make sure we've got a valid user account
31  * and if so set our configuration setting for this person.
32  */
33 function gnot_settings_post($post) {
34         if(! DI::userSession()->getLocalUserId() || empty($_POST['gnot-submit']))
35                 return;
36
37         DI::pConfig()->set(DI::userSession()->getLocalUserId(),'gnot','enable',intval($_POST['gnot']));
38 }
39
40 /**
41  * Called from the Addon Setting form. 
42  * Add our own settings info to the page.
43  */
44 function gnot_settings(array &$data)
45 {
46         if (!DI::userSession()->getLocalUserId()) {
47                 return;
48         }
49
50         $gnot = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'gnot', 'enable'));
51
52         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
53         $html = Renderer::replaceMacros($t, [
54                 '$text'    => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line."),
55                 '$enabled' => ['gnot', DI::l10n()->t('Enable this addon?'), $gnot],
56         ]);
57
58         $data = [
59                 'addon' => 'gnot',
60                 'title' => DI::l10n()->t('Gnot Settings'),
61                 'html'  => $html,
62         ];
63 }
64
65 function gnot_enotify_mail(array &$b)
66 {
67         if ((!$b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable')))) {
68                 return;
69         }
70
71         if ($b['type'] == Notification\Type::COMMENT) {
72                 $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
73         }
74 }