]> git.mxchange.org Git - friendica-addons.git/blob - notifyall/notifyall.php
port hubzillas hubwall addon to friendica (notifyall)
[friendica-addons.git] / notifyall / notifyall.php
1 <?php
2
3 /**
4  *
5  * Name: Notifyall
6  * Description: Send admin email message to all account holders. <b>-><a href=/notifyall TARGET = "_blank">send now!</a><-</b>
7  * Version: 1.0
8  * Author: Mike Macgirvin (Inital Author of the hubbwall Addon for the Hubzilla Project)
9  * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus> (Port to Friendica)
10  */
11
12 require_once('include/Emailer.php');
13
14 function notifyall_install() {
15         logger("installed notifyall");
16 }
17
18 function notifyall_uninstall() {
19         logger("removed notifyall");
20 }
21
22 function notifyall_module() {}
23
24 function notifyall_plugin_admin(&$a, &$o) {
25
26         $o = '<div></div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . z_root() . '/notifyall">' . t('Send email to all members') . '</a></br/>';
27
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 = sprintf(t('%s Administrator'), $sitename);
43         else
44                 $sender_name = sprintf(t('%1$s, %2$s Administrator'), $a->config['admin_name'], $sitename);
45
46         $sender_email = 'sys@' . $a->get_hostname();
47         $subject = $_REQUEST['subject'];
48
49
50         $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"),array( "", "\n"), $text))),ENT_QUOTES,'UTF-8'));
51
52         $htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","<br />\n"),$text)));
53
54         $sql_extra = ((intval($_REQUEST['test'])) ? sprintf(" AND `email` = '%s' ", get_config('system','admin_email')) : ''); 
55
56
57         $recips = q("SELECT `email` FROM `user` WHERE `verified` AND NOT `account_removed` AND NOT `account_expired` $sql_extra");
58
59         if(! $recips) {
60                 notice( t('No recipients found.') . EOL);
61                 return;
62         }
63
64         foreach($recips as $recip) {
65
66
67                 Emailer::send(array(
68                         'fromName'             => $sender_name,
69                         'fromEmail'            => $sender_email,
70                         'replyTo'              => $sender_email,
71                         'toEmail'              => $recip['email'],
72                         'messageSubject'       => $subject,
73                         'htmlVersion'          => $htmlversion,
74                         'textVersion'          => $textversion
75                 ));
76         }
77
78         notice( t('Emails sent'));
79         goaway('admin');
80 }
81
82 function notifyall_content(&$a) {
83         if(! is_site_admin())
84                 return;
85
86         $title = t('Send email to all members of this Friendica instance.');
87
88         $o = replace_macros(get_markup_template('notifyall_form.tpl','addon/notifyall/'),array(
89                 '$title' => $title,
90                 '$text' => htmlspecialchars($_REQUEST['text']),
91                 '$subject' => array('subject',t('Message subject'),$_REQUEST['subject'],''),
92                 '$test' => array('test',t('Test mode (only send to administrator)'), 0,''),
93                 '$submit' => t('Submit')
94         ));
95
96         return $o;
97
98 }