]> git.mxchange.org Git - friendica.git/blob - mod/invite.php
Merge pull request #3613 from annando/some-ostatus
[friendica.git] / mod / invite.php
1 <?php
2
3 /**
4  * module: invite.php
5  *
6  * send email invitations to join social network
7  *
8  */
9
10 use Friendica\App;
11
12 require_once('include/email.php');
13
14 function invite_post(App $a) {
15
16         if (! local_user()) {
17                 notice( t('Permission denied.') . EOL);
18                 return;
19         }
20
21         check_form_security_token_redirectOnErr('/', 'send_invite');
22
23         $max_invites = intval(get_config('system','max_invites'));
24         if (! $max_invites) {
25                 $max_invites = 50;
26         }
27
28         $current_invites = intval(get_pconfig(local_user(),'system','sent_invites'));
29         if ($current_invites > $max_invites) {
30                 notice( t('Total invitation limit exceeded.') . EOL);
31                 return;
32         }
33
34
35         $recips  = ((x($_POST,'recipients')) ? explode("\n",$_POST['recipients']) : array());
36         $message = ((x($_POST,'message'))    ? notags(trim($_POST['message']))    : '');
37
38         $total = 0;
39
40         if (get_config('system','invitation_only')) {
41                 $invonly = true;
42                 $x = get_pconfig(local_user(),'system','invites_remaining');
43                 if ((! $x) && (! is_site_admin())) {
44                         return;
45                 }
46         }
47
48         foreach ($recips as $recip) {
49
50                 $recip = trim($recip);
51
52                 if (! valid_email($recip)) {
53                         notice(  sprintf( t('%s : Not a valid email address.'), $recip) . EOL);
54                         continue;
55                 }
56
57                 if ($invonly && ($x || is_site_admin())) {
58                         $code = autoname(8) . srand(1000,9999);
59                         $nmessage = str_replace('$invite_code',$code,$message);
60
61                         $r = q("INSERT INTO `register` (`hash`,`created`) VALUES ('%s', '%s') ",
62                                 dbesc($code),
63                                 dbesc(datetime_convert())
64                         );
65
66                         if (! is_site_admin()) {
67                                 $x --;
68                                 if ($x >= 0) {
69                                         set_pconfig(local_user(),'system','invites_remaining',$x);
70                                 } else {
71                                         return;
72                                 }
73                         }
74                 } else {
75                         $nmessage = $message;
76                 }
77
78                 $res = mail($recip, email_header_encode( t('Please join us on Friendica'),'UTF-8'),
79                         $nmessage,
80                         "From: " . $a->user['email'] . "\n"
81                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
82                         . 'Content-transfer-encoding: 8bit' );
83
84                 if ($res) {
85                         $total ++;
86                         $current_invites ++;
87                         set_pconfig(local_user(),'system','sent_invites',$current_invites);
88                         if($current_invites > $max_invites) {
89                                 notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
90                                 return;
91                         }
92                 } else {
93                         notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
94                 }
95
96         }
97         notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
98         return;
99 }
100
101
102 function invite_content(App $a) {
103
104         if (! local_user()) {
105                 notice( t('Permission denied.') . EOL);
106                 return;
107         }
108
109         $tpl = get_markup_template('invite.tpl');
110         $invonly = false;
111
112         if (get_config('system','invitation_only')) {
113                 $invonly = true;
114                 $x = get_pconfig(local_user(),'system','invites_remaining');
115                 if ((! $x) && (! is_site_admin())) {
116                         notice( t('You have no more invitations available') . EOL);
117                         return '';
118                 }
119         }
120
121         $dirloc = get_config('system','directory');
122         if (strlen($dirloc)) {
123                 if ($a->config['register_policy'] == REGISTER_CLOSED) {
124                         $linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), $dirloc . '/servers');
125                 } else {
126                         $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), App::get_baseurl())
127                         . "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),$dirloc . '/servers');
128                 }
129         } else { // there is no global directory URL defined
130                 if ($a->config['register_policy'] == REGISTER_CLOSED) {
131                         $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
132                         return $o;
133                 } else {
134                         $linktxt = sprintf( t('To accept this invitation, please visit and register at %s.'), App::get_baseurl()
135                         . "\r\n" . "\r\n" . t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks.');
136                 }
137         }
138
139         $o = replace_macros($tpl, array(
140                 '$form_security_token' => get_form_security_token("send_invite"),
141                 '$invite'              => t('Send invitations'),
142                 '$addr_text'           => t('Enter email addresses, one per line:'),
143                 '$msg_text'            => t('Your message:'),
144                 '$default_message'     => t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n"
145                         . $linktxt
146                         . "\r\n" . "\r\n" . (($invonly) ? t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') .t('Once you have registered, please connect with me via my profile page at:')
147                         . "\r\n" . "\r\n" . App::get_baseurl() . '/profile/' . $a->user['nickname']
148                         . "\r\n" . "\r\n" . t('For more information about the Friendica project and why we feel it is important, please visit http://friendica.com') . "\r\n" . "\r\n"  ,
149                 '$submit'              => t('Submit')
150         ));
151
152         return $o;
153 }