6 * send email invitations to join social network
10 function invite_post(&$a) {
13 notice( t('Permission denied.') . EOL);
18 $recips = ((x($_POST,'recipients')) ? explode("\n",$_POST['recipients']) : array());
19 $message = ((x($_POST,'message')) ? notags(trim($_POST['message'])) : '');
23 if(get_config('system','invitation_only')) {
25 $x = get_pconfig(local_user(),'system','invites_remaining');
26 if((! $x) && (! is_site_admin()))
30 foreach($recips as $recip) {
32 $recip = trim($recip);
34 if(! valid_email($recip)) {
35 notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL);
39 if($invonly && ($x || is_site_admin())) {
40 $code = autoname(8) . srand(1000,9999);
41 $nmessage = str_replace('$invite_code',$code,$message);
43 $r = q("INSERT INTO `register` (`hash`,`created`) VALUES ('%s', '%s') ",
45 dbesc(datetime_convert())
48 if(! is_site_admin()) {
51 set_pconfig(local_user(),'system','invites_remaining',$x);
59 $res = mail($recip, sprintf( t('Please join my network on %s'), $a->config['sitename']),
61 "From: " . $a->user['email'] . "\n"
62 . 'Content-type: text/plain; charset=UTF-8' . "\n"
63 . 'Content-transfer-encoding: 8bit' );
69 notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
73 notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
78 function invite_content(&$a) {
81 notice( t('Permission denied.') . EOL);
85 $tpl = get_markup_template('invite.tpl');
88 if(get_config('system','invitation_only')) {
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);
98 $o = replace_macros($tpl, array(
99 '$invite' => t('Send invitations'),
100 '$addr_text' => t('Enter email addresses, one per line:'),
101 '$msg_text' => t('Your message:'),
102 '$default_message' => sprintf(t('Please join my social network on %s'), $a->config['sitename']) . "\r\n" . "\r\n"
103 . t('To accept this invitation, please visit:') . "\r\n" . "\r\n" . $a->get_baseurl()
104 . "\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:')
105 . "\r\n" . "\r\n" . $a->get_baseurl() . '/profile/' . $a->user['nickname'] ,
106 '$submit' => t('Submit')