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