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) {
85 DI::emailer()->send($sender_name, $sender_email, $sender_email, $recip['email'], $subject, $htmlversion, $textversion);
88 notice(DI::l10n()->t('Emails sent'));
89 DI::baseUrl()->redirect('admin');
92 function notifyall_content(&$a)
94 if (! is_site_admin()) {
98 $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
100 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
102 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
103 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
104 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
105 '$submit' => DI::l10n()->t('Submit')