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