]> git.mxchange.org Git - friendica-addons.git/blob - notifyall/notifyall.php
Changed function name
[friendica-addons.git] / notifyall / notifyall.php
1 <?php
2 /**
3  *
4  * Name: Notifyall
5  * Description: Send admin email message to all account holders. <b>-><a href=/notifyall TARGET = "_blank">send now!</a><-</b>
6  * Version: 1.0
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)
9  */
10
11 use Friendica\Addon\notifyall\NotifyAllEmail;
12 use Friendica\App;
13 use Friendica\Database\DBA;
14 use Friendica\Core\Logger;
15 use Friendica\Core\Renderer;
16 use Friendica\DI;
17
18 function notifyall_module() {}
19
20 function notifyall_addon_admin(App $a, &$o)
21 {
22         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . DI::baseUrl()->get() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
23 }
24
25
26 function notifyall_post(App $a)
27 {
28         if(!is_site_admin()) {
29                 return;
30         }
31
32         $text = trim($_REQUEST['text']);
33
34         if(! $text) {
35                 return;
36         }
37
38         // if this is a test, send it only to the admin(s)
39         // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
40         if (intval($_REQUEST['test'])) {
41                 $email = DI::config()->get('config', 'admin_email');
42                 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
43         }
44         $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
45
46         $recipients = DBA::p("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
47
48         if (! $recipients) {
49                 notice(DI::l10n()->t('No recipients found.') . EOL);
50                 return;
51         }
52
53         $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
54
55         foreach ($recipients as $recipient) {
56                 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
57         }
58
59         info(DI::l10n()->t('Emails sent'));
60         DI::baseUrl()->redirect('admin');
61 }
62
63 function notifyall_content(&$a)
64 {
65         if (! is_site_admin()) {
66                 return '';
67         }
68
69         $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
70
71         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
72                 '$title' => $title,
73                 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
74                 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
75                 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
76                 '$submit' => DI::l10n()->t('Submit')
77         ]);
78
79         return $o;
80 }