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;
15 function notifyall_install() {
16 logger("installed notifyall");
19 function notifyall_uninstall() {
20 logger("removed notifyall");
23 function notifyall_module() {}
25 function notifyall_addon_admin(&$a, &$o) {
27 $o = '<div></div> <a href="' . z_root() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
31 function notifyall_post(&$a) {
35 $text = trim($_REQUEST['text']);
39 $sitename = $a->config['sitename'];
41 if (!x($a->config['admin_name']))
42 $sender_name = L10n::t('%s Administrator', $sitename);
44 $sender_name = L10n::t('%1$s, %2$s Administrator', $a->config['admin_name'], $sitename);
46 if (! x($a->config['sender_email']))
47 $sender_email = 'noreply@' . $a->get_hostname();
49 $sender_email = $a->config['sender_email'];
51 $subject = $_REQUEST['subject'];
54 $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
56 $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
58 // if this is a test, send it only to the admin(s)
59 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
60 if (intval($_REQUEST['test'])) {
61 $email = $a->config['admin_email'];
62 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
64 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
66 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
69 notice(L10n::t('No recipients found.') . EOL);
73 foreach ($recips as $recip) {
75 'fromName' => $sender_name,
76 'fromEmail' => $sender_email,
77 'replyTo' => $sender_email,
78 'toEmail' => $recip['email'],
79 'messageSubject' => $subject,
80 'htmlVersion' => $htmlversion,
81 'textVersion' => $textversion
85 notice(L10n::t('Emails sent'));
89 function notifyall_content(&$a)
91 if (! is_site_admin()) {
95 $title = L10n::t('Send email to all members of this Friendica instance.');
97 $o = replace_macros(get_markup_template('notifyall_form.tpl', 'addon/notifyall/'), [
99 '$text' => htmlspecialchars($_REQUEST['text']),
100 '$subject' => ['subject',L10n::t('Message subject'),$_REQUEST['subject'],''],
101 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
102 '$submit' => L10n::t('Submit')