]> git.mxchange.org Git - friendica.git/blob - mod/invite.php
begin invites, fb setup changes
[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','invitations_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                         // store in db
43
44                         if(! is_site_admin()) {
45                                 $x --;
46                                 if($x >= 0)
47                                         set_pconfig(local_user(),'system','invites_remaining,$x);
48                                 else
49                                         return;
50                         }
51                 }
52                 else
53                         $nmessage = $message;
54
55                 $res = mail($recip, sprintf( t('Please join my network on %s'), $a->config['sitename']), 
56                         $nmessage, 
57                         "From: " . $a->user['email'] . "\n"
58                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
59                         . 'Content-transfer-encoding: 8bit' );
60
61                 if($res) {
62                         $total ++;
63                 }
64                 else {
65                         notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
66                 }
67
68         }
69         notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
70         return;
71 }
72
73
74 function invite_content(&$a) {
75
76         if(! local_user()) {
77                 notice( t('Permission denied.') . EOL);
78                 return;
79         }
80
81         $tpl = get_markup_template('invite.tpl');
82         $invonly = false;
83
84         if(get_config('system','invitations_only')) {
85                 $invonly = true;
86                 $x = get_pconfig(local_user(),'system','invites_remaining');
87                 if((! $x) && (! is_site_admin())) {
88                         notice( t('You have no more invitations available') . EOL);
89                         return '';
90                 }
91         }                       
92
93
94         $o = replace_macros($tpl, array(
95                 '$invite' => t('Send invitations'),
96                 '$addr_text' => t('Enter email addresses, one per line:'),
97                 '$msg_text' => t('Your message:'),
98                 '$default_message' => sprintf(t('Please join my social network on %s'), $a->config['sitename']) . "\r\n" . "\r\n"
99                         . t('To accept this invitation, please visit:') . "\r\n" . "\r\n" . $a->get_baseurl()
100                         . "\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:') 
101                         . "\r\n" . "\r\n" . $a->get_baseurl() . '/profile/' . $a->user['nickname'] ,
102                 '$submit' => t('Submit')
103         ));
104
105         return $o;
106 }