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\Content\Text\BBCode;
12 use Friendica\Core\L10n;
13 use Friendica\Util\Emailer;
16 function notifyall_install()
18 logger("installed notifyall");
21 function notifyall_uninstall()
23 logger("removed notifyall");
26 function notifyall_module() {}
28 function notifyall_addon_admin(App $a, &$o)
30 $o = '<div></div> <a href="' . z_root() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
34 function notifyall_post(App $a)
41 $text = trim($_REQUEST['text']);
48 $sitename = $a->config['sitename'];
50 if (empty($a->config['admin_name']))
52 $sender_name = '"' . L10n::t('%s Administrator', $sitename) . '"';
54 $sender_name = '"' . L10n::t('%1$s, %2$s Administrator', $a->config['admin_name'], $sitename) . '"';
57 if (! x($a->config['sender_email']))
59 $sender_email = 'noreply@' . $a->get_hostname();
61 $sender_email = $a->config['sender_email'];
64 $subject = $_REQUEST['subject'];
67 $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
69 $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
71 // if this is a test, send it only to the admin(s)
72 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
73 if (intval($_REQUEST['test']))
75 $email = $a->config['admin_email'];
76 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
78 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
80 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
84 notice(L10n::t('No recipients found.') . EOL);
88 foreach ($recips as $recip)
91 'fromName' => $sender_name,
92 'fromEmail' => $sender_email,
93 'replyTo' => $sender_email,
94 'toEmail' => $recip['email'],
95 'messageSubject' => $subject,
96 'htmlVersion' => $htmlversion,
97 'textVersion' => $textversion
101 notice(L10n::t('Emails sent'));
105 function notifyall_content(&$a)
107 if (! is_site_admin()) {
111 $title = L10n::t('Send email to all members of this Friendica instance.');
113 $o = replace_macros(get_markup_template('notifyall_form.tpl', 'addon/notifyall/'), [
115 '$text' => htmlspecialchars($_REQUEST['text']),
116 '$subject' => ['subject',L10n::t('Message subject'),$_REQUEST['subject'],''],
117 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
118 '$submit' => L10n::t('Submit')