]> git.mxchange.org Git - friendica-addons.git/blob - notifyall/notifyall.php
[saml] Replace $_SESSION with DI::session()
[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(App $a, string &$o)
26 {
27         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . DI::baseUrl()->get() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
28 }
29
30
31 function notifyall_post(App $a)
32 {
33         if (!$a->isSiteAdmin()) {
34                 return;
35         }
36
37         $text = trim($_REQUEST['text']);
38
39         if(! $text) {
40                 return;
41         }
42
43         // if this is a test, send it only to the admin(s)
44         // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
45         if (intval($_REQUEST['test'])) {
46                 $email = DI::config()->get('config', 'admin_email');
47                 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
48         }
49         $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
50
51         $recipients = DBA::p("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
52
53         if (! $recipients) {
54                 DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.'));
55                 return;
56         }
57
58         $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
59
60         foreach ($recipients as $recipient) {
61                 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
62         }
63
64         DI::sysmsg()->addInfo(DI::l10n()->t('Emails sent'));
65         DI::baseUrl()->redirect('admin');
66 }
67
68 function notifyall_content(App $a)
69 {
70         if (!$a->isSiteAdmin()) {
71                 return '';
72         }
73
74         $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
75
76         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
77                 '$title' => $title,
78                 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
79                 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
80                 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
81                 '$submit' => DI::l10n()->t('Submit')
82         ]);
83
84         return $o;
85 }