3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Renderer;
9 use Friendica\Network\HTTPException;
10 use Friendica\Protocol\Email;
11 use Friendica\Util\Strings;
14 * Invite people to friendica
16 class Invite extends BaseModule
18 public static function post(array $parameters = [])
21 throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
24 self::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
27 $config = DI::config();
29 $max_invites = intval($config->get('system', 'max_invites'));
34 $current_invites = intval(DI::pConfig()->get(local_user(), 'system', 'sent_invites'));
35 if ($current_invites > $max_invites) {
36 throw new HTTPException\ForbiddenException(DI::l10n()->t('Total invitation limit exceeded.'));
40 $recipients = !empty($_POST['recipients']) ? explode("\n", $_POST['recipients']) : [];
41 $message = !empty($_POST['message']) ? Strings::escapeTags(trim($_POST['message'])) : '';
44 $invitation_only = false;
45 $invites_remaining = null;
47 if ($config->get('system', 'invitation_only')) {
48 $invitation_only = true;
49 $invites_remaining = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
50 if ((!$invites_remaining) && (!is_site_admin())) {
51 throw new HTTPException\ForbiddenException();
55 foreach ($recipients as $recipient) {
56 $recipient = trim($recipient);
58 if (!filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
59 notice(DI::l10n()->t('%s : Not a valid email address.', $recipient) . EOL);
63 if ($invitation_only && ($invites_remaining || is_site_admin())) {
64 $code = Model\Register::createForInvitation();
65 $nmessage = str_replace('$invite_code', $code, $message);
67 if (!is_site_admin()) {
69 if ($invites_remaining >= 0) {
70 DI::pConfig()->set(local_user(), 'system', 'invites_remaining', $invites_remaining);
79 $additional_headers = 'From: ' . $app->user['email'] . "\n"
80 . 'Sender: ' . $app->getSenderEmailAddress() . "\n"
81 . 'Content-type: text/plain; charset=UTF-8' . "\n"
82 . 'Content-transfer-encoding: 8bit';
86 Email::encodeHeader(DI::l10n()->t('Please join us on Friendica'), 'UTF-8'),
93 DI::pConfig()->set(local_user(), 'system', 'sent_invites', $current_invites);
94 if ($current_invites > $max_invites) {
95 notice(DI::l10n()->t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
99 notice(DI::l10n()->t('%s : Message delivery failed.', $recipient) . EOL);
103 notice(DI::l10n()->tt('%d message sent.', '%d messages sent.', $total) . EOL);
106 public static function content(array $parameters = [])
109 throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
113 $config = DI::config();
117 if ($config->get('system', 'invitation_only')) {
119 $x = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
120 if ((!$x) && (!is_site_admin())) {
121 throw new HTTPException\ForbiddenException(DI::l10n()->t('You have no more invitations available'));
125 $dirLocation = $config->get('system', 'directory');
126 if (strlen($dirLocation)) {
127 if ($config->get('config', 'register_policy') === Register::CLOSED) {
128 $linkTxt = DI::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');
130 $linkTxt = DI::l10n()->t('To accept this invitation, please visit and register at %s or any other public Friendica website.', DI::baseUrl()->get())
131 . "\r\n" . "\r\n" . DI::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');
133 } else { // there is no global directory URL defined
134 if ($config->get('config', 'register_policy') === Register::CLOSED) {
135 return DI::l10n()->t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
137 $linkTxt = DI::l10n()->t('To accept this invitation, please visit and register at %s.', DI::baseUrl()->get()
138 . "\r\n" . "\r\n" . DI::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.'));
142 $tpl = Renderer::getMarkupTemplate('invite.tpl');
143 return Renderer::replaceMacros($tpl, [
144 '$form_security_token' => self::getFormSecurityToken('send_invite'),
145 '$title' => DI::l10n()->t('Send invitations'),
146 '$recipients' => ['recipients', DI::l10n()->t('Enter email addresses, one per line:')],
149 DI::l10n()->t('Your message:'),
150 DI::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"
152 . "\r\n" . "\r\n" . (($inviteOnly) ? DI::l10n()->t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . DI::l10n()->t('Once you have registered, please connect with me via my profile page at:')
153 . "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->user['nickname']
154 . "\r\n" . "\r\n" . DI::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",
156 '$submit' => DI::l10n()->t('Submit')