Replace all functions from boot.php
[friendica-addons.git/.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\Core\Session;
16 use Friendica\DI;
17 use Friendica\Model\Notification;
18
19 function gnot_install()
20 {
21         Hook::register('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
22         Hook::register('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
23         Hook::register('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
24
25         Logger::notice("installed gnot");
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 function gnot_settings_post(App $a, $post) {
35         if(! Session::getLocalUser() || empty($_POST['gnot-submit']))
36                 return;
37
38         DI::pConfig()->set(Session::getLocalUser(),'gnot','enable',intval($_POST['gnot']));
39 }
40
41 /**
42  * Called from the Addon Setting form. 
43  * Add our own settings info to the page.
44  */
45 function gnot_settings(App &$a, array &$data)
46 {
47         if (!Session::getLocalUser()) {
48                 return;
49         }
50
51         $gnot = intval(DI::pConfig()->get(Session::getLocalUser(), 'gnot', 'enable'));
52
53         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
54         $html = Renderer::replaceMacros($t, [
55                 '$text'    => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line."),
56                 '$enabled' => ['gnot', DI::l10n()->t('Enable this addon?'), $gnot],
57         ]);
58
59         $data = [
60                 'addon' => 'gnot',
61                 'title' => DI::l10n()->t('Gnot Settings'),
62                 'html'  => $html,
63         ];
64 }
65
66 function gnot_enotify_mail(App $a, array &$b)
67 {
68         if ((!$b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable')))) {
69                 return;
70         }
71
72         if ($b['type'] == Notification\Type::COMMENT) {
73                 $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
74         }
75 }