]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Register.php
Merge pull request #9509 from MrPetovan/task/5616-clear-notifications-display
[friendica.git] / src / Module / Register.php
index 9530d29f147daf1a296386f32fca7ed2f35e4451..2a74894b18f42a96f6fab349737944db144f2ef2 100644 (file)
@@ -1,13 +1,30 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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;
 
 use Friendica\BaseModule;
 use Friendica\Content\Text\BBCode;
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
-use Friendica\Core\L10n as L10nClass;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\Worker;
@@ -39,7 +56,7 @@ class Register extends BaseModule
                // logged in users can register others (people/pages/groups)
                // even with closed registrations, unless specifically prohibited by site policy.
                // 'block_extended_register' blocks all registrations, period.
-               $block = Config::get('system', 'block_extended_register');
+               $block = DI::config()->get('system', 'block_extended_register');
 
                if (local_user() && $block) {
                        notice(DI::l10n()->t('Permission denied.'));
@@ -54,12 +71,12 @@ class Register extends BaseModule
                        }
                }
 
-               if (!local_user() && (intval(Config::get('config', 'register_policy')) === self::CLOSED)) {
+               if (!local_user() && (intval(DI::config()->get('config', 'register_policy')) === self::CLOSED)) {
                        notice(DI::l10n()->t('Permission denied.'));
                        return '';
                }
 
-               $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
+               $max_dailies = intval(DI::config()->get('system', 'max_daily_registrations'));
                if ($max_dailies) {
                        $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
                        if ($count >= $max_dailies) {
@@ -76,7 +93,7 @@ class Register extends BaseModule
                $photo      = $_REQUEST['photo']      ?? '';
                $invite_id  = $_REQUEST['invite_id']  ?? '';
 
-               if (local_user() || Config::get('system', 'no_openid')) {
+               if (local_user() || DI::config()->get('system', 'no_openid')) {
                        $fillwith = '';
                        $fillext  = '';
                        $oidlabel = '';
@@ -86,10 +103,10 @@ class Register extends BaseModule
                        $oidlabel = DI::l10n()->t('Your OpenID (optional): ');
                }
 
-               if (Config::get('system', 'publish_all')) {
+               if (DI::config()->get('system', 'publish_all')) {
                        $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
                } else {
-                       $publish_tpl = Renderer::getMarkupTemplate('profile_publish.tpl');
+                       $publish_tpl = Renderer::getMarkupTemplate('profile/publish.tpl');
                        $profile_publish = Renderer::replaceMacros($publish_tpl, [
                                '$instance'     => 'reg',
                                '$pubdesc'      => DI::l10n()->t('Include your profile in member directory?'),
@@ -113,14 +130,14 @@ class Register extends BaseModule
                $tos = new Tos();
 
                $o = Renderer::replaceMacros($tpl, [
-                       '$invitations'  => Config::get('system', 'invitation_only'),
-                       '$permonly'     => intval(Config::get('config', 'register_policy')) === self::APPROVE,
+                       '$invitations'  => DI::config()->get('system', 'invitation_only'),
+                       '$permonly'     => intval(DI::config()->get('config', 'register_policy')) === self::APPROVE,
                        '$permonlybox'  => ['permonlybox', DI::l10n()->t('Note for the admin'), '', DI::l10n()->t('Leave a message for the admin, why you want to join this node'), 'required'],
                        '$invite_desc'  => DI::l10n()->t('Membership on this site is by invitation only.'),
                        '$invite_label' => DI::l10n()->t('Your invitation code: '),
                        '$invite_id'    => $invite_id,
                        '$regtitle'     => DI::l10n()->t('Registration'),
-                       '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
+                       '$registertext' => BBCode::convert(DI::config()->get('config', 'register_text', '')),
                        '$fillwith'     => $fillwith,
                        '$fillext'      => $fillext,
                        '$oidlabel'     => $oidlabel,
@@ -142,12 +159,12 @@ class Register extends BaseModule
                        '$sitename'     => DI::baseUrl()->getHostname(),
                        '$importh'      => DI::l10n()->t('Import'),
                        '$importt'      => DI::l10n()->t('Import your profile to this friendica instance'),
-                       '$showtoslink'  => Config::get('system', 'tosdisplay'),
+                       '$showtoslink'  => DI::config()->get('system', 'tosdisplay'),
                        '$tostext'      => DI::l10n()->t('Terms of Service'),
-                       '$showprivstatement' => Config::get('system', 'tosprivstatement'),
+                       '$showprivstatement' => DI::config()->get('system', 'tosprivstatement'),
                        '$privstatement'=> $tos->privacy_complete,
                        '$form_security_token' => BaseModule::getFormSecurityToken('register'),
-                       '$explicit_content' => Config::get('system', 'explicit_content', false),
+                       '$explicit_content' => DI::config()->get('system', 'explicit_content', false),
                        '$explicit_content_note' => DI::l10n()->t('Note: This node explicitly contains adult content'),
                        '$additional'   => !empty(local_user()),
                        '$parent_password' => ['parent_password', DI::l10n()->t('Parent Password:'), '', DI::l10n()->t('Please enter the password of the parent account to legitimize your request.')]
@@ -167,8 +184,6 @@ class Register extends BaseModule
        {
                BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
 
-               $a = DI::app();
-
                $arr = ['post' => $_POST];
                Hook::callAll('register_post', $arr);
 
@@ -192,7 +207,7 @@ class Register extends BaseModule
                        DI::baseUrl()->redirect('register?' . http_build_query($regdata));
                }
 
-               $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
+               $max_dailies = intval(DI::config()->get('system', 'max_daily_registrations'));
                if ($max_dailies) {
                        $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
                        if ($count >= $max_dailies) {
@@ -200,7 +215,7 @@ class Register extends BaseModule
                        }
                }
 
-               switch (Config::get('config', 'register_policy')) {
+               switch (DI::config()->get('config', 'register_policy')) {
                        case self::OPEN:
                                $blocked = 0;
                                $verified = 1;
@@ -260,7 +275,7 @@ class Register extends BaseModule
 
                $arr['blocked'] = $blocked;
                $arr['verified'] = $verified;
-               $arr['language'] = L10nClass::detectLanguage($_SERVER, $_GET, DI::config()->get('system', 'language'));
+               $arr['language'] = L10n::detectLanguage($_SERVER, $_GET, DI::config()->get('system', 'language'));
 
                try {
                        $result = Model\User::create($arr);
@@ -273,7 +288,7 @@ class Register extends BaseModule
 
                $base_url = DI::baseUrl()->get();
 
-               if ($netpublish && intval(Config::get('config', 'register_policy')) !== self::APPROVE) {
+               if ($netpublish && intval(DI::config()->get('config', 'register_policy')) !== self::APPROVE) {
                        $url = $base_url . '/profile/' . $user['nickname'];
                        Worker::add(PRIORITY_LOW, 'Directory', $url);
                }
@@ -284,11 +299,11 @@ class Register extends BaseModule
                        DI::baseUrl()->redirect('delegation');
                }
 
-               $using_invites = Config::get('system', 'invitation_only');
-               $num_invites   = Config::get('system', 'number_invites');
+               $using_invites = DI::config()->get('system', 'invitation_only');
+               $num_invites   = DI::config()->get('system', 'number_invites');
                $invite_id = (!empty($_POST['invite_id']) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
 
-               if (intval(Config::get('config', 'register_policy')) === self::OPEN) {
+               if (intval(DI::config()->get('config', 'register_policy')) === self::OPEN) {
                        if ($using_invites && $invite_id) {
                                Model\Register::deleteByHash($invite_id);
                                DI::pConfig()->set($user['uid'], 'system', 'invites_remaining', $num_invites);
@@ -299,7 +314,7 @@ class Register extends BaseModule
                                $res = Model\User::sendRegisterOpenEmail(
                                        DI::l10n()->withLang($arr['language']),
                                        $user,
-                                       Config::get('config', 'sitename'),
+                                       DI::config()->get('config', 'sitename'),
                                        $base_url,
                                        $result['password']
                                );
@@ -318,8 +333,8 @@ class Register extends BaseModule
                                info(DI::l10n()->t('Registration successful.'));
                                DI::baseUrl()->redirect();
                        }
-               } elseif (intval(Config::get('config', 'register_policy')) === self::APPROVE) {
-                       if (!strlen(Config::get('config', 'admin_email'))) {
+               } elseif (intval(DI::config()->get('config', 'register_policy')) === self::APPROVE) {
+                       if (!strlen(DI::config()->get('config', 'admin_email'))) {
                                notice(DI::l10n()->t('Your registration can not be processed.'));
                                DI::baseUrl()->redirect();
                        }
@@ -332,7 +347,7 @@ class Register extends BaseModule
                                DI::baseUrl()->redirect('register/');
                        }
 
-                       Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
+                       Model\Register::createForApproval($user['uid'], DI::config()->get('system', 'language'), $_POST['permonlybox']);
 
                        // invite system
                        if ($using_invites && $invite_id) {
@@ -344,13 +359,13 @@ class Register extends BaseModule
                        $admins_stmt = DBA::select(
                                'user',
                                ['uid', 'language', 'email'],
-                               ['email' => explode(',', str_replace(' ', '', Config::get('config', 'admin_email')))]
+                               ['email' => explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')))]
                        );
 
                        // send notification to admins
                        while ($admin = DBA::fetch($admins_stmt)) {
                                \notification([
-                                       'type'         => NOTIFY_SYSTEM,
+                                       'type'         => Model\Notify\Type::SYSTEM,
                                        'event'        => 'SYSTEM_REGISTER_REQUEST',
                                        'source_name'  => $user['username'],
                                        'source_mail'  => $user['email'],
@@ -369,7 +384,7 @@ class Register extends BaseModule
                        // send notification to the user, that the registration is pending
                        Model\User::sendRegisterPendingEmail(
                                $user,
-                               Config::get('config', 'sitename'),
+                               DI::config()->get('config', 'sitename'),
                                $base_url,
                                $result['password']
                        );