]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Invite.php
Use rawContent for Special Options to avoid a protected options() method
[friendica.git] / src / Module / Invite.php
index fc8b4abf90671fdd99b4e4a78d95605750939ffb..1ce9700697c6ae7e67b64fa44f1d2dbe9db24028 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module;
 
@@ -6,6 +25,7 @@ use Friendica\BaseModule;
 use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Email;
 use Friendica\Util\Strings;
@@ -15,7 +35,7 @@ use Friendica\Util\Strings;
  */
 class Invite extends BaseModule
 {
-       public static function post(array $parameters = [])
+       protected function post(array $request = [])
        {
                if (!local_user()) {
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
@@ -38,7 +58,7 @@ class Invite extends BaseModule
 
 
                $recipients = !empty($_POST['recipients']) ? explode("\n", $_POST['recipients']) : [];
-               $message = !empty($_POST['message']) ? Strings::escapeTags(trim($_POST['message'])) : '';
+               $message = !empty($_POST['message']) ? Strings::escapeHtml(trim($_POST['message'])) : '';
 
                $total = 0;
                $invitation_only = false;
@@ -47,24 +67,26 @@ class Invite extends BaseModule
                if ($config->get('system', 'invitation_only')) {
                        $invitation_only = true;
                        $invites_remaining = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
-                       if ((!$invites_remaining) && (!is_site_admin())) {
+                       if ((!$invites_remaining) && (!$app->isSiteAdmin())) {
                                throw new HTTPException\ForbiddenException();
                        }
                }
 
+               $user = User::getById(local_user());
+
                foreach ($recipients as $recipient) {
                        $recipient = trim($recipient);
 
                        if (!filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
-                               notice(DI::l10n()->t('%s : Not a valid email address.', $recipient) . EOL);
+                               notice(DI::l10n()->t('%s : Not a valid email address.', $recipient));
                                continue;
                        }
 
-                       if ($invitation_only && ($invites_remaining || is_site_admin())) {
+                       if ($invitation_only && ($invites_remaining || $app->isSiteAdmin())) {
                                $code = Model\Register::createForInvitation();
                                $nmessage = str_replace('$invite_code', $code, $message);
 
-                               if (!is_site_admin()) {
+                               if (!$app->isSiteAdmin()) {
                                        $invites_remaining--;
                                        if ($invites_remaining >= 0) {
                                                DI::pConfig()->set(local_user(), 'system', 'invites_remaining', $invites_remaining);
@@ -76,8 +98,7 @@ class Invite extends BaseModule
                                $nmessage = $message;
                        }
 
-                       $additional_headers = 'From: ' . $app->user['email'] . "\n"
-                               . 'Sender: ' . DI::emailer()->getSiteEmailAddress() . "\n"
+                       $additional_headers = 'From: "' . $user['email'] . '" <' . DI::emailer()->getSiteEmailAddress() . ">\n"
                                . 'Content-type: text/plain; charset=UTF-8' . "\n"
                                . 'Content-transfer-encoding: 8bit';
 
@@ -92,18 +113,18 @@ class Invite extends BaseModule
                                $current_invites++;
                                DI::pConfig()->set(local_user(), 'system', 'sent_invites', $current_invites);
                                if ($current_invites > $max_invites) {
-                                       notice(DI::l10n()->t('Invitation limit exceeded. Please contact your site administrator.') . EOL);
+                                       notice(DI::l10n()->t('Invitation limit exceeded. Please contact your site administrator.'));
                                        return;
                                }
                        } else {
-                               notice(DI::l10n()->t('%s : Message delivery failed.', $recipient) . EOL);
+                               notice(DI::l10n()->t('%s : Message delivery failed.', $recipient));
                        }
 
                }
-               notice(DI::l10n()->tt('%d message sent.', '%d messages sent.', $total) . EOL);
+               info(DI::l10n()->tt('%d message sent.', '%d messages sent.', $total));
        }
 
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
                if (!local_user()) {
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
@@ -117,7 +138,7 @@ class Invite extends BaseModule
                if ($config->get('system', 'invitation_only')) {
                        $inviteOnly = true;
                        $x = DI::pConfig()->get(local_user(), 'system', 'invites_remaining');
-                       if ((!$x) && (!is_site_admin())) {
+                       if ((!$x) && (!$app->isSiteAdmin())) {
                                throw new HTTPException\ForbiddenException(DI::l10n()->t('You have no more invitations available'));
                        }
                }
@@ -150,7 +171,7 @@ class Invite extends BaseModule
                                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"
                                . $linkTxt
                                . "\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:')
-                               . "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->user['nickname']
+                               . "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->getLoggedInUserNickname()
                                . "\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",
                        ],
                        '$submit'              => DI::l10n()->t('Submit')