]> git.mxchange.org Git - friendica.git/blob - mod/invite.php
Merge pull request #2324 from rabuzarus/0502_vier_dark
[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 require_once('include/email.php');
11
12 if(! function_exists('invite_post')) {
13 function invite_post(&$a) {
14
15         if(! local_user()) {
16                 notice( t('Permission denied.') . EOL);
17                 return;
18         }
19
20         check_form_security_token_redirectOnErr('/', 'send_invite');
21
22         $max_invites = intval(get_config('system','max_invites'));
23         if(! $max_invites)
24                 $max_invites = 50;
25
26         $current_invites = intval(get_pconfig(local_user(),'system','sent_invites'));
27         if($current_invites > $max_invites) {
28                 notice( t('Total invitation limit exceeded.') . EOL);
29                 return;
30         };
31
32
33         $recips  = ((x($_POST,'recipients')) ? explode("\n",$_POST['recipients']) : array());
34         $message = ((x($_POST,'message'))    ? notags(trim($_POST['message']))    : '');
35
36         $total = 0;
37
38         if(get_config('system','invitation_only')) {
39                 $invonly = true;
40                 $x = get_pconfig(local_user(),'system','invites_remaining');
41                 if((! $x) && (! is_site_admin()))
42                         return;
43         }
44
45         foreach($recips as $recip) {
46
47                 $recip = trim($recip);
48
49                 if(! valid_email($recip)) {
50                         notice(  sprintf( t('%s : Not a valid email address.'), $recip) . EOL);
51                         continue;
52                 }
53
54                 if($invonly && ($x || is_site_admin())) {
55                         $code = autoname(8) . srand(1000,9999);
56                         $nmessage = str_replace('$invite_code',$code,$message);
57
58                         $r = q("INSERT INTO `register` (`hash`,`created`) VALUES ('%s', '%s') ",
59                                 dbesc($code),
60                                 dbesc(datetime_convert())
61                         );
62
63                         if(! is_site_admin()) {
64                                 $x --;
65                                 if($x >= 0)
66                                         set_pconfig(local_user(),'system','invites_remaining',$x);
67                                 else
68                                         return;
69                         }
70                 }
71                 else
72                         $nmessage = $message;
73
74                 $res = mail($recip, email_header_encode( t('Please join us on Friendica'),'UTF-8'),
75                         $nmessage,
76                         "From: " . $a->user['email'] . "\n"
77                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
78                         . 'Content-transfer-encoding: 8bit' );
79
80                 if($res) {
81                         $total ++;
82                         $current_invites ++;
83                         set_pconfig(local_user(),'system','sent_invites',$current_invites);
84                         if($current_invites > $max_invites) {
85                                 notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
86                                 return;
87                         }
88                 }
89                 else {
90                         notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
91                 }
92
93         }
94         notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
95         return;
96 }
97 }
98
99 if(! function_exists('invite_content')) {
100 function invite_content(&$a) {
101
102         if(! local_user()) {
103                 notice( t('Permission denied.') . EOL);
104                 return;
105         }
106
107         $tpl = get_markup_template('invite.tpl');
108         $invonly = false;
109
110         if(get_config('system','invitation_only')) {
111                 $invonly = true;
112                 $x = get_pconfig(local_user(),'system','invites_remaining');
113                 if((! $x) && (! is_site_admin())) {
114                         notice( t('You have no more invitations available') . EOL);
115                         return '';
116                 }
117         }
118
119         $dirloc = get_config('system','directory');
120         if(strlen($dirloc)) {
121                 if($a->config['register_policy'] == REGISTER_CLOSED)
122                         $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 . '/siteinfo');
123                 elseif($a->config['register_policy'] != REGISTER_CLOSED)
124                         $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), $a->get_baseurl())
125                         . "\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 . '/siteinfo');
126         }
127         else {
128                 $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
129                 return $o;
130         }
131
132         $o = replace_macros($tpl, array(
133                 '$form_security_token' => get_form_security_token("send_invite"),
134                 '$invite' => t('Send invitations'),
135                 '$addr_text' => t('Enter email addresses, one per line:'),
136                 '$msg_text' => t('Your message:'),
137                 '$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"
138                         . $linktxt
139                         . "\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:')
140                         . "\r\n" . "\r\n" . $a->get_baseurl() . '/profile/' . $a->user['nickname']
141                         . "\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"  ,
142                 '$submit' => t('Submit')
143         ));
144
145         return $o;
146 }
147 }