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\Core\Logger;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\System;
19 use Friendica\Util\Emailer;
21 function notifyall_install()
23 Logger::log("installed notifyall");
26 function notifyall_uninstall()
28 Logger::log("removed notifyall");
31 function notifyall_module() {}
33 function notifyall_addon_admin(App $a, &$o)
35 $o = '<div></div> <a href="' . $a->getBaseURL() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
39 function notifyall_post(App $a)
41 if(!is_site_admin()) {
45 $text = trim($_REQUEST['text']);
51 $sitename = Config::get('config', 'sitename');
53 if (empty(Config::get('config', 'admin_name'))) {
54 $sender_name = '"' . L10n::t('%s Administrator', $sitename) . '"';
56 $sender_name = '"' . L10n::t('%1$s, %2$s Administrator', Config::get('config', 'admin_name'), $sitename) . '"';
59 if (!Config::get('config', 'sender_email')) {
60 $sender_email = 'noreply@' . DI::baseUrl()->getHostname();
62 $sender_email = Config::get('config', 'sender_email');
65 $subject = $_REQUEST['subject'];
68 $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
70 $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
72 // if this is a test, send it only to the admin(s)
73 // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
74 if (intval($_REQUEST['test'])) {
75 $email = Config::get('config', 'admin_email');
76 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
78 $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
80 $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
83 notice(L10n::t('No recipients found.') . EOL);
87 foreach ($recips as $recip) {
89 'fromName' => $sender_name,
90 'fromEmail' => $sender_email,
91 'replyTo' => $sender_email,
92 'toEmail' => $recip['email'],
93 'messageSubject' => $subject,
94 'htmlVersion' => $htmlversion,
95 'textVersion' => $textversion
99 notice(L10n::t('Emails sent'));
100 DI::baseUrl()->redirect('admin');
103 function notifyall_content(&$a)
105 if (! is_site_admin()) {
109 $title = L10n::t('Send email to all members of this Friendica instance.');
111 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
113 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
114 '$subject' => ['subject', L10n::t('Message subject'), $_REQUEST['subject'] ?? '',''],
115 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
116 '$submit' => L10n::t('Submit')