Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

161 righe
5.9 KiB

  1. <?php
  2. namespace Friendica\Module;
  3. use Friendica\BaseModule;
  4. use Friendica\Core\L10n;
  5. use Friendica\Core\Renderer;
  6. use Friendica\DI;
  7. use Friendica\Model;
  8. use Friendica\Network\HTTPException;
  9. use Friendica\Protocol\Email;
  10. use Friendica\Util\Strings;
  11. /**
  12. * Invite people to friendica
  13. */
  14. class Invite extends BaseModule
  15. {
  16. public static function post(array $parameters = [])
  17. {
  18. if (!local_user()) {
  19. throw new HTTPException\ForbiddenException(L10n::t('Permission denied.'));
  20. }
  21. self::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
  22. $app = DI::app();
  23. $config = DI::config();
  24. $max_invites = intval($config->get('system', 'max_invites'));
  25. if (!$max_invites) {
  26. $max_invites = 50;
  27. }
  28. $current_invites = intval(DI::pConfig()->get(local_user(), 'system', 'sent_invites'));
  29. if ($current_invites > $max_invites) {
  30. throw new HTTPException\ForbiddenException(L10n::t('Total invitation limit exceeded.'));
  31. }
  32. $recipients = !empty($_POST['recipients']) ? explode("\n", $_POST['recipients']) : [];
  33. $message = !empty($_POST['message']) ? Strings::escapeTags(trim($_POST['message'])) : '';
  34. $total = 0;
  35. $invitation_only = false;
  36. $invites_remaining = null;
  37. if ($config->get('system', 'invitation_only')) {
  38. $invitation_only = true;
  39. $invites_remaining = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
  40. if ((!$invites_remaining) && (!is_site_admin())) {
  41. throw new HTTPException\ForbiddenException();
  42. }
  43. }
  44. foreach ($recipients as $recipient) {
  45. $recipient = trim($recipient);
  46. if (!filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
  47. notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL);
  48. continue;
  49. }
  50. if ($invitation_only && ($invites_remaining || is_site_admin())) {
  51. $code = Model\Register::createForInvitation();
  52. $nmessage = str_replace('$invite_code', $code, $message);
  53. if (!is_site_admin()) {
  54. $invites_remaining--;
  55. if ($invites_remaining >= 0) {
  56. DI::pConfig()->set(local_user(), 'system', 'invites_remaining', $invites_remaining);
  57. } else {
  58. return;
  59. }
  60. }
  61. } else {
  62. $nmessage = $message;
  63. }
  64. $additional_headers = 'From: ' . $app->user['email'] . "\n"
  65. . 'Sender: ' . $app->getSenderEmailAddress() . "\n"
  66. . 'Content-type: text/plain; charset=UTF-8' . "\n"
  67. . 'Content-transfer-encoding: 8bit';
  68. $res = mail(
  69. $recipient,
  70. Email::encodeHeader(L10n::t('Please join us on Friendica'), 'UTF-8'),
  71. $nmessage,
  72. $additional_headers);
  73. if ($res) {
  74. $total++;
  75. $current_invites++;
  76. DI::pConfig()->set(local_user(), 'system', 'sent_invites', $current_invites);
  77. if ($current_invites > $max_invites) {
  78. notice(L10n::t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
  79. return;
  80. }
  81. } else {
  82. notice(L10n::t('%s : Message delivery failed.', $recipient) . EOL);
  83. }
  84. }
  85. notice(L10n::tt('%d message sent.', '%d messages sent.', $total) . EOL);
  86. }
  87. public static function content(array $parameters = [])
  88. {
  89. if (!local_user()) {
  90. throw new HTTPException\ForbiddenException(L10n::t('Permission denied.'));
  91. }
  92. $app = DI::app();
  93. $config = DI::config();
  94. $inviteOnly = false;
  95. if ($config->get('system', 'invitation_only')) {
  96. $inviteOnly = true;
  97. $x = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
  98. if ((!$x) && (!is_site_admin())) {
  99. throw new HTTPException\ForbiddenException(L10n::t('You have no more invitations available'));
  100. }
  101. }
  102. $dirLocation = $config->get('system', 'directory');
  103. if (strlen($dirLocation)) {
  104. if ($config->get('config', 'register_policy') === Register::CLOSED) {
  105. $linkTxt = L10n::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.', $dirLocation . '/servers');
  106. } else {
  107. $linkTxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', DI::baseUrl()->get())
  108. . "\r\n" . "\r\n" . L10n::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.', $dirLocation . '/servers');
  109. }
  110. } else { // there is no global directory URL defined
  111. if ($config->get('config', 'register_policy') === Register::CLOSED) {
  112. return L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
  113. } else {
  114. $linkTxt = L10n::t('To accept this invitation, please visit and register at %s.', DI::baseUrl()->get()
  115. . "\r\n" . "\r\n" . L10n::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.'));
  116. }
  117. }
  118. $tpl = Renderer::getMarkupTemplate('invite.tpl');
  119. return Renderer::replaceMacros($tpl, [
  120. '$form_security_token' => self::getFormSecurityToken('send_invite'),
  121. '$title' => L10n::t('Send invitations'),
  122. '$recipients' => ['recipients', L10n::t('Enter email addresses, one per line:')],
  123. '$message' => [
  124. 'message',
  125. L10n::t('Your message:'),
  126. L10n::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"
  127. . $linkTxt
  128. . "\r\n" . "\r\n" . (($inviteOnly) ? L10n::t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . L10n::t('Once you have registered, please connect with me via my profile page at:')
  129. . "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->user['nickname']
  130. . "\r\n" . "\r\n" . L10n::t('For more information about the Friendica project and why we feel it is important, please visit http://friendi.ca') . "\r\n" . "\r\n",
  131. ],
  132. '$submit' => L10n::t('Submit')
  133. ]);
  134. }
  135. }