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;
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
23 function notifyall_module() {}
25 function notifyall_addon_admin(string &$o)
27 $o = '<div></div> <a href="' . DI::baseUrl() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
31 function notifyall_post()
33 if (!DI::userSession()->isSiteAdmin()) {
37 $text = trim($_REQUEST['text']);
43 $condition = ['account_removed' => false, 'account_expired' => false];
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']);
50 $condition['email'] = array_column($adminEmails, 'email');
53 $recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition);
56 DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.'));
60 $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
62 foreach ($recipients as $recipient) {
63 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
66 DI::sysmsg()->addInfo(DI::l10n()->t('Emails sent'));
67 DI::baseUrl()->redirect('admin');
70 function notifyall_content()
72 if (!DI::userSession()->isSiteAdmin()) {
76 $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
78 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
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')