X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=notifyall%2Fnotifyall.php;h=e5e94c7ec7e68786d9efe00926d52d0021bc48bd;hb=d754a5c0f9b27143e88251a76f9656a818168568;hp=2190a9d17437161ac4f52ca96e408b3b9ec09f2a;hpb=b8287629104fcfb1dbae2e72c0ae90ab615d6f7c;p=friendica-addons.git diff --git a/notifyall/notifyall.php b/notifyall/notifyall.php index 2190a9d1..e5e94c7e 100644 --- a/notifyall/notifyall.php +++ b/notifyall/notifyall.php @@ -8,22 +8,12 @@ * Author: Rabuzarus (Port to Friendica) */ +use Friendica\Addon\notifyall\NotifyAllEmail; use Friendica\App; -use Friendica\Content\Text\BBCode; +use Friendica\Database\DBA; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; -use Friendica\Util\Emailer; - -function notifyall_install() -{ - Logger::log("installed notifyall"); -} - -function notifyall_uninstall() -{ - Logger::log("removed notifyall"); -} function notifyall_module() {} @@ -45,27 +35,6 @@ function notifyall_post(App $a) return; } - $sitename = DI::config()->get('config', 'sitename'); - - if (empty(DI::config()->get('config', 'admin_name'))) { - $sender_name = '"' . DI::l10n()->t('%s Administrator', $sitename) . '"'; - } else { - $sender_name = '"' . DI::l10n()->t('%1$s, %2$s Administrator', DI::config()->get('config', 'admin_name'), $sitename) . '"'; - } - - if (!DI::config()->get('config', 'sender_email')) { - $sender_email = 'noreply@' . DI::baseUrl()->getHostname(); - } else { - $sender_email = DI::config()->get('config', 'sender_email'); - } - - $subject = $_REQUEST['subject']; - - - $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8')); - - $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "
\n"], $text))); - // if this is a test, send it only to the admin(s) // admin_email might be a comma separated list, but we need "a@b','c@d','e@f if (intval($_REQUEST['test'])) { @@ -74,25 +43,27 @@ function notifyall_post(App $a) } $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : ''); - $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra"); + $recipients = DBA::p("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra"); - if (! $recips) { + if (! $recipients) { notice(DI::l10n()->t('No recipients found.') . EOL); return; } - foreach ($recips as $recip) { - DI::emailer()->send($sender_name, $sender_email, $sender_email, $recip['email'], $subject, $htmlversion, $textversion); + $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text); + + foreach ($recipients as $recipient) { + DI::emailer()->send($notifyEmail->withRecipient($recipient['email'])); } - notice(DI::l10n()->t('Emails sent')); + info(DI::l10n()->t('Emails sent')); DI::baseUrl()->redirect('admin'); } function notifyall_content(&$a) { if (! is_site_admin()) { - return; + return ''; } $title = DI::l10n()->t('Send email to all members of this Friendica instance.');