]> git.mxchange.org Git - friendica-addons.git/blob - notifyall/notifyall.php
Changes:
[friendica-addons.git] / notifyall / notifyall.php
1 <?php
2 /**
3  *
4  * Name: Notifyall
5  * Description: Send admin email message to all account holders. <b>-><a href=/notifyall TARGET = "_blank">send now!</a><-</b>
6  * Version: 1.0
7  * Author: Mike Macgirvin (Inital Author of the hubbwall Addon for the Hubzilla Project)
8  * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus> (Port to Friendica)
9  */
10
11 use Friendica\Addon\notifyall\NotifyAllEmail;
12 use Friendica\App;
13 use Friendica\Database\DBA;
14 use Friendica\Core\Logger;
15 use Friendica\Core\Renderer;
16 use Friendica\DI;
17
18 /**
19  * This is a statement rather than an actual function definition. The simple
20  * existence of this method is checked to figure out if the addon offers a
21  * module.
22  */
23 function notifyall_module() {}
24
25 function notifyall_addon_admin(string &$o)
26 {
27         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . DI::baseUrl() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
28 }
29
30
31 function notifyall_post()
32 {
33         if (!DI::userSession()->isSiteAdmin()) {
34                 return;
35         }
36
37         $text = trim($_REQUEST['text']);
38
39         if(! $text) {
40                 return;
41         }
42
43         $condition = ['account_removed' => false, 'account_expired' => false];
44
45         // if this is a test, send it only to the admin(s)
46         // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
47         if (intval($_REQUEST['test'])) {
48                 $adminEmails = \Friendica\Model\User::getAdminListForEmailing(['email']);
49
50                 $condition['email'] = array_column($adminEmails, 'email');
51         }
52
53         $recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition);
54
55         if (! $recipients) {
56                 DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.'));
57                 return;
58         }
59
60         $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
61
62         foreach ($recipients as $recipient) {
63                 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
64         }
65
66         DI::sysmsg()->addInfo(DI::l10n()->t('Emails sent'));
67         DI::baseUrl()->redirect('admin');
68 }
69
70 function notifyall_content()
71 {
72         if (!DI::userSession()->isSiteAdmin()) {
73                 return '';
74         }
75
76         $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
77
78         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
79                 '$title' => $title,
80                 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
81                 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
82                 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
83                 '$submit' => DI::l10n()->t('Submit')
84         ]);
85
86         return $o;
87 }