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)
10 use Friendica\Core\L10n;
11 use Friendica\Util\Emailer;
13 function notifyall_install() {
14 logger("installed notifyall");
17 function notifyall_uninstall() {
18 logger("removed notifyall");
21 function notifyall_module() {}
23 function notifyall_addon_admin(&$a, &$o) {
25 $o = '<div></div> <a href="' . z_root() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
29 function notifyall_post(&$a) {
33 $text = trim($_REQUEST['text']);
37 $sitename = $a->config['sitename'];
39 if (!x($a->config['admin_name']))
40 $sender_name = sprintf(L10n::t('%s Administrator'), $sitename);
42 $sender_name = sprintf(L10n::t('%1$s, %2$s Administrator'), $a->config['admin_name'], $sitename);
44 if (! x($a->config['sender_email']))
45 $sender_email = 'noreply@' . $a->get_hostname();
47 $sender_email = $a->config['sender_email'];
49 $subject = $_REQUEST['subject'];
52 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(["\\r", "\\n"],[ "", "\n"], $text))),ENT_QUOTES,'UTF-8'));
54 $htmlversion = bbcode(stripslashes(str_replace(["\\r","\\n"], ["","<br />\n"],$text)));
56 // if this is a test, send it only to the admin(s)
57 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
58 if (intval($_REQUEST['test'])) {
59 $email = $a->config['admin_email'];
60 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
62 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
64 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
67 notice(L10n::t('No recipients found.') . EOL);
71 foreach ($recips as $recip) {
73 'fromName' => $sender_name,
74 'fromEmail' => $sender_email,
75 'replyTo' => $sender_email,
76 'toEmail' => $recip['email'],
77 'messageSubject' => $subject,
78 'htmlVersion' => $htmlversion,
79 'textVersion' => $textversion
83 notice(L10n::t('Emails sent'));
87 function notifyall_content(&$a)
89 if (! is_site_admin()) {
93 $title = L10n::t('Send email to all members of this Friendica instance.');
95 $o = replace_macros(get_markup_template('notifyall_form.tpl', 'addon/notifyall/'), [
97 '$text' => htmlspecialchars($_REQUEST['text']),
98 '$subject' => ['subject',L10n::t('Message subject'),$_REQUEST['subject'],''],
99 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
100 '$submit' => L10n::t('Submit')