]> git.mxchange.org Git - friendica-addons.git/blob - notifyall/notifyall.php
c49128319f3ce102340e7316bbe514efafd315b4
[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\Content\Text\BBCode;
12 use Friendica\Core\L10n;
13 use Friendica\Util\Emailer;
14
15 function notifyall_install() {
16         logger("installed notifyall");
17 }
18
19 function notifyall_uninstall() {
20         logger("removed notifyall");
21 }
22
23 function notifyall_module() {}
24
25 function notifyall_addon_admin(&$a, &$o) {
26
27         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . z_root() . '/notifyall">' . L10n::t('Send email to all members') . '</a></br/>';
28 }
29
30
31 function notifyall_post(&$a) {
32         if(! is_site_admin())
33                 return;
34
35         $text = trim($_REQUEST['text']);
36         if(! $text)
37                 return;
38
39         $sitename = $a->config['sitename'];
40
41         if (!x($a->config['admin_name']))
42                 $sender_name = L10n::t('%s Administrator', $sitename);
43         else
44                 $sender_name = L10n::t('%1$s, %2$s Administrator', $a->config['admin_name'], $sitename);
45
46         if (! x($a->config['sender_email']))
47                 $sender_email = 'noreply@' . $a->get_hostname();
48         else
49                 $sender_email = $a->config['sender_email'];
50
51         $subject = $_REQUEST['subject'];
52
53
54         $textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
55
56         $htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
57
58         $htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","<br />\n"),$text)));
59         
60         // if this is a test, send it only to the admin(s)
61         // admin_email might be a comma separated list, but we need "a@b','c@d','e@f
62         if (intval($_REQUEST['test'])) {
63                 $email = $a->config['admin_email'];
64                 $email = "'" . str_replace(array(" ",","), array("","','"), $email) . "'";
65         }
66         $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` in ( %s )", $email) : '');
67
68         $recips = q("SELECT DISTINCT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
69
70         if (! $recips) {
71                 notice(L10n::t('No recipients found.') . EOL);
72                 return;
73         }
74
75         foreach ($recips as $recip) {
76                 Emailer::send([
77                         'fromName'             => $sender_name,
78                         'fromEmail'            => $sender_email,
79                         'replyTo'              => $sender_email,
80                         'toEmail'              => $recip['email'],
81                         'messageSubject'       => $subject,
82                         'htmlVersion'          => $htmlversion,
83                         'textVersion'          => $textversion
84                 ));
85         }
86
87         notice(L10n::t('Emails sent'));
88         goaway('admin');
89 }
90
91 function notifyall_content(&$a)
92 {
93         if (! is_site_admin()) {
94                 return;
95         }
96
97         $title = L10n::t('Send email to all members of this Friendica instance.');
98
99         $o = replace_macros(get_markup_template('notifyall_form.tpl', 'addon/notifyall/'), [
100                 '$title' => $title,
101                 '$text' => htmlspecialchars($_REQUEST['text']),
102                 '$subject' => ['subject',L10n::t('Message subject'),$_REQUEST['subject'],''],
103                 '$test' => ['test',L10n::t('Test mode (only send to administrator)'), 0,''],
104                 '$submit' => L10n::t('Submit')
105         ]);
106
107         return $o;
108 }