6 * send email invitations to join social network
10 require_once('include/email.php');
12 function invite_post(App &$a) {
15 notice( t('Permission denied.') . EOL);
19 check_form_security_token_redirectOnErr('/', 'send_invite');
21 $max_invites = intval(get_config('system','max_invites'));
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);
33 $recips = ((x($_POST,'recipients')) ? explode("\n",$_POST['recipients']) : array());
34 $message = ((x($_POST,'message')) ? notags(trim($_POST['message'])) : '');
38 if (get_config('system','invitation_only')) {
40 $x = get_pconfig(local_user(),'system','invites_remaining');
41 if ((! $x) && (! is_site_admin())) {
46 foreach ($recips as $recip) {
48 $recip = trim($recip);
50 if (! valid_email($recip)) {
51 notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL);
55 if ($invonly && ($x || is_site_admin())) {
56 $code = autoname(8) . srand(1000,9999);
57 $nmessage = str_replace('$invite_code',$code,$message);
59 $r = q("INSERT INTO `register` (`hash`,`created`) VALUES ('%s', '%s') ",
61 dbesc(datetime_convert())
64 if (! is_site_admin()) {
67 set_pconfig(local_user(),'system','invites_remaining',$x);
76 $res = mail($recip, email_header_encode( t('Please join us on Friendica'),'UTF-8'),
78 "From: " . $a->user['email'] . "\n"
79 . 'Content-type: text/plain; charset=UTF-8' . "\n"
80 . 'Content-transfer-encoding: 8bit' );
85 set_pconfig(local_user(),'system','sent_invites',$current_invites);
86 if($current_invites > $max_invites) {
87 notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
91 notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
95 notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
100 function invite_content(App &$a) {
102 if (! local_user()) {
103 notice( t('Permission denied.') . EOL);
107 $tpl = get_markup_template('invite.tpl');
110 if (get_config('system','invitation_only')) {
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);
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.'), App::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');
128 $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
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"
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" . App::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')