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\Logger;
14 use Friendica\Core\Renderer;
16 use Friendica\Util\Emailer;
18 function notifyall_install()
20 Logger::log("installed notifyall");
23 function notifyall_uninstall()
25 Logger::log("removed notifyall");
28 function notifyall_module() {}
30 function notifyall_addon_admin(App $a, &$o)
32 $o = '<div></div> <a href="' . DI::baseUrl()->get() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
36 function notifyall_post(App $a)
38 if(!is_site_admin()) {
42 $text = trim($_REQUEST['text']);
48 $sitename = DI::config()->get('config', 'sitename');
50 if (empty(DI::config()->get('config', 'admin_name'))) {
51 $sender_name = '"' . DI::l10n()->t('%s Administrator', $sitename) . '"';
53 $sender_name = '"' . DI::l10n()->t('%1$s, %2$s Administrator', DI::config()->get('config', 'admin_name'), $sitename) . '"';
56 if (!DI::config()->get('config', 'sender_email')) {
57 $sender_email = 'noreply@' . DI::baseUrl()->getHostname();
59 $sender_email = DI::config()->get('config', 'sender_email');
62 $subject = $_REQUEST['subject'];
65 $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
67 $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
69 // if this is a test, send it only to the admin(s)
70 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
71 if (intval($_REQUEST['test'])) {
72 $email = DI::config()->get('config', 'admin_email');
73 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
75 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
77 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
80 notice(DI::l10n()->t('No recipients found.') . EOL);
84 foreach ($recips as $recip) {
86 'fromName' => $sender_name,
87 'fromEmail' => $sender_email,
88 'replyTo' => $sender_email,
89 'toEmail' => $recip['email'],
90 'messageSubject' => $subject,
91 'htmlVersion' => $htmlversion,
92 'textVersion' => $textversion
96 notice(DI::l10n()->t('Emails sent'));
97 DI::baseUrl()->redirect('admin');
100 function notifyall_content(&$a)
102 if (! is_site_admin()) {
106 $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
108 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
110 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
111 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
112 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
113 '$submit' => DI::l10n()->t('Submit')