5 * Description: Send admin email message to all account holders. <b>-><a href=/notifyall TARGET = "_blank">send now!</a><-</b>
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)
11 use Friendica\Addon\notifyall\NotifyAllEmail;
13 use Friendica\Database\DBA;
14 use Friendica\Core\Logger;
15 use Friendica\Core\Renderer;
18 function notifyall_module() {}
20 function notifyall_addon_admin(App $a, &$o)
22 $o = '<div></div> <a href="' . DI::baseUrl()->get() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
26 function notifyall_post(App $a)
28 if(!is_site_admin()) {
32 $text = trim($_REQUEST['text']);
38 // if this is a test, send it only to the admin(s)
39 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
40 if (intval($_REQUEST['test'])) {
41 $email = DI::config()->get('config', 'admin_email');
42 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
44 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
46 $recipients = DBA::p("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
49 notice(DI::l10n()->t('No recipients found.') . EOL);
53 $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
55 foreach ($recipients as $recipient) {
56 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
59 info(DI::l10n()->t('Emails sent'));
60 DI::baseUrl()->redirect('admin');
63 function notifyall_content(&$a)
65 if (! is_site_admin()) {
69 $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
71 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
73 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
74 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
75 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
76 '$submit' => DI::l10n()->t('Submit')