[pumpio] Replace share_header calls with BBCode::getShareOpeningTag
[friendica-addons.git/.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_install()
19 {
20         Logger::log("installed notifyall");
21 }
22
23 function notifyall_uninstall()
24 {
25         Logger::log("removed notifyall");
26 }
27
28 function notifyall_module() {}
29
30 function notifyall_addon_admin(App $a, &$o)
31 {
32         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . DI::baseUrl()->get() . '/notifyall">' . DI::l10n()->t('Send email to all members') . '</a></br/>';
33 }
34
35
36 function notifyall_post(App $a)
37 {
38         if(!is_site_admin()) {
39                 return;
40         }
41
42         $text = trim($_REQUEST['text']);
43
44         if(! $text) {
45                 return;
46         }
47
48         // if this is a test, send it only to the admin(s)
49         // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
50         if (intval($_REQUEST['test'])) {
51                 $email = DI::config()->get('config', 'admin_email');
52                 $email = "'" . str_replace([" ",","], ["","','"], $email) . "'";
53         }
54         $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
55
56         $recipients = DBA::p("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
57
58         if (! $recipients) {
59                 notice(DI::l10n()->t('No recipients found.') . EOL);
60                 return;
61         }
62
63         $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
64
65         foreach ($recipients as $recipient) {
66                 DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
67         }
68
69         notice(DI::l10n()->t('Emails sent'));
70         DI::baseUrl()->redirect('admin');
71 }
72
73 function notifyall_content(&$a)
74 {
75         if (! is_site_admin()) {
76                 return '';
77         }
78
79         $title = DI::l10n()->t('Send email to all members of this Friendica instance.');
80
81         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('notifyall_form.tpl', 'addon/notifyall/'), [
82                 '$title' => $title,
83                 '$text' => htmlspecialchars($_REQUEST['text'] ?? ''),
84                 '$subject' => ['subject', DI::l10n()->t('Message subject'), $_REQUEST['subject'] ?? '',''],
85                 '$test' => ['test',DI::l10n()->t('Test mode (only send to administrator)'), 0,''],
86                 '$submit' => DI::l10n()->t('Submit')
87         ]);
88
89         return $o;
90 }