Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.5 KiB

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