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)
12 use Friendica\Content\Text\BBCode;
13 use Friendica\Core\Config;
14 use Friendica\Core\L10n;
15 use Friendica\Util\Emailer;
17 function notifyall_install()
19 logger("installed notifyall");
22 function notifyall_uninstall()
24 logger("removed notifyall");
27 function notifyall_module() {}
29 function notifyall_addon_admin(App $a, &$o)
31 $o = '<div></div> <a href="' . $a->getBaseURL() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
35 function notifyall_post(App $a)
37 if(!is_site_admin()) {
41 $text = trim($_REQUEST['text']);
47 $sitename = Config::get('config', 'sitename');
49 if (empty(Config::get('config', 'admin_name'))) {
50 $sender_name = '"' . L10n::t('%s Administrator', $sitename) . '"';
52 $sender_name = '"' . L10n::t('%1$s, %2$s Administrator', Config::get('config', 'admin_name'), $sitename) . '"';
55 if (! x(Config::get('config', 'sender_email'))) {
56 $sender_email = 'noreply@' . $a->getHostName();
58 $sender_email = Config::get('config', 'sender_email');
61 $subject = $_REQUEST['subject'];
64 $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
66 $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
68 // if this is a test, send it only to the admin(s)
69 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
70 if (intval($_REQUEST['test'])) {
71 $email = Config::get('config', 'admin_email');
72 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
74 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
76 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
79 notice(L10n::t('No recipients found.') . EOL);
83 foreach ($recips as $recip) {
85 'fromName' => $sender_name,
86 'fromEmail' => $sender_email,
87 'replyTo' => $sender_email,
88 'toEmail' => $recip['email'],
89 'messageSubject' => $subject,
90 'htmlVersion' => $htmlversion,
91 'textVersion' => $textversion
95 notice(L10n::t('Emails sent'));
99 function notifyall_content(&$a)
101 if (! is_site_admin()) {
105 $title = L10n::t('Send email to all members of this Friendica instance.');
107 $o = replace_macros(get_markup_template('notifyall_form.tpl', 'addon/notifyall/'), [
109 '$text' => htmlspecialchars(defaults($_REQUEST, 'text', '')),
110 '$subject' => ['subject', L10n::t('Message subject'), defaults($_REQUEST, 'subject', ''),''],
111 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
112 '$submit' => L10n::t('Submit')