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