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