5 * Send email invitations to join social network
10 use Friendica\BaseModule;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\Renderer;
15 use Friendica\Core\System;
16 use Friendica\Protocol\Email;
17 use Friendica\Util\Strings;
19 function invite_post(App $a)
22 notice(L10n::t('Permission denied.') . EOL);
26 BaseModule::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
28 $max_invites = intval(Config::get('system', 'max_invites'));
33 $current_invites = intval(PConfig::get(local_user(), 'system', 'sent_invites'));
34 if ($current_invites > $max_invites) {
35 notice(L10n::t('Total invitation limit exceeded.') . EOL);
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 = PConfig::get(local_user(), 'system', 'invites_remaining');
50 if ((! $invites_remaining) && (! is_site_admin())) {
55 foreach ($recipients as $recipient) {
56 $recipient = trim($recipient);
58 if (!filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
59 notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL);
63 if ($invitation_only && ($invites_remaining || is_site_admin())) {
64 $code = Friendica\Model\Register::createForInvitation();
65 $nmessage = str_replace('$invite_code', $code, $message);
67 if (! is_site_admin()) {
68 $invites_remaining --;
69 if ($invites_remaining >= 0) {
70 PConfig::set(local_user(), 'system', 'invites_remaining', $invites_remaining);
79 $additional_headers = 'From: ' . $a->user['email'] . "\n"
80 . 'Sender: ' . $a->getSenderEmailAddress() . "\n"
81 . 'Content-type: text/plain; charset=UTF-8' . "\n"
82 . 'Content-transfer-encoding: 8bit';
86 Email::encodeHeader(L10n::t('Please join us on Friendica'), 'UTF-8'),
93 PConfig::set(local_user(), 'system', 'sent_invites', $current_invites);
94 if ($current_invites > $max_invites) {
95 notice(L10n::t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
99 notice(L10n::t('%s : Message delivery failed.', $recipient) . EOL);
103 notice(L10n::tt("%d message sent.", "%d messages sent.", $total) . EOL);
107 function invite_content(App $a) {
109 if (! local_user()) {
110 notice(L10n::t('Permission denied.') . EOL);
114 $tpl = Renderer::getMarkupTemplate('invite.tpl');
117 if (Config::get('system', 'invitation_only')) {
119 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
120 if ((! $x) && (! is_site_admin())) {
121 notice(L10n::t('You have no more invitations available') . EOL);
126 $dirloc = Config::get('system', 'directory');
127 if (strlen($dirloc)) {
128 if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
129 $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.', $dirloc . '/servers');
131 $linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl())
132 . "\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.', $dirloc . '/servers');
134 } else { // there is no global directory URL defined
135 if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
136 $o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
139 $linktxt = L10n::t('To accept this invitation, please visit and register at %s.', System::baseUrl()
140 . "\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.'));
144 $o = Renderer::replaceMacros($tpl, [
145 '$form_security_token' => BaseModule::getFormSecurityToken("send_invite"),
146 '$title' => L10n::t('Send invitations'),
147 '$recipients' => ['recipients', L10n::t('Enter email addresses, one per line:')],
148 '$message' => ['message', L10n::t('Your message:'),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"
150 . "\r\n" . "\r\n" . (($invonly) ? 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:')
151 . "\r\n" . "\r\n" . System::baseUrl() . '/profile/' . $a->user['nickname']
152 . "\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"],
153 '$submit' => L10n::t('Submit')