]> git.mxchange.org Git - friendica.git/blobdiff - mod/register.php
Ops, one more left ...
[friendica.git] / mod / register.php
index f0ed5cd4a5bc8cf876175762961b62d424cb3074..b851faf2d6225f471e5cec43e93270b4beab3978 100644 (file)
@@ -4,24 +4,24 @@
  */
 
 use Friendica\App;
+use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\DBA;
 use Friendica\Model\User;
-use Friendica\Util\Temporal;
+use Friendica\Module\Tos;
+use Friendica\Util\DateTimeFormat;
 
 require_once 'include/enotify.php';
-require_once 'include/bbcode.php';
 
 function register_post(App $a)
 {
        check_form_security_token_redirectOnErr('/register', 'register');
 
-       global $lang;
-
        $verified = 0;
        $blocked  = 1;
 
@@ -36,7 +36,7 @@ function register_post(App $a)
                }
        }
 
-       switch ($a->config['register_policy']) {
+       switch (Config::get('config', 'register_policy')) {
                case REGISTER_OPEN:
                        $blocked = 0;
                        $verified = 1;
@@ -49,7 +49,7 @@ function register_post(App $a)
 
                default:
                case REGISTER_CLOSED:
-                       if ((!x($_SESSION, 'authenticated') && (!x($_SESSION, 'administrator')))) {
+                       if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
                                notice(L10n::t('Permission denied.') . EOL);
                                return;
                        }
@@ -58,6 +58,7 @@ function register_post(App $a)
                        break;
        }
 
+       $netpublish = !empty($_POST['profile_publish_reg']);
 
        $arr = $_POST;
 
@@ -74,7 +75,7 @@ function register_post(App $a)
 
        $user = $result['user'];
 
-       if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
+       if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
                $url = System::baseUrl() . '/profile/' . $user['nickname'];
                Worker::add(PRIORITY_LOW, "Directory", $url);
        }
@@ -83,16 +84,16 @@ function register_post(App $a)
        $num_invites   = Config::get('system', 'number_invites');
        $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
 
-       if ($a->config['register_policy'] == REGISTER_OPEN) {
+       if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
                if ($using_invites && $invite_id) {
-                       q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
+                       q("delete * from register where hash = '%s' limit 1", DBA::escape($invite_id));
                        PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
                }
 
                // Only send a password mail when the password wasn't manually provided
                if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
                        $res = User::sendRegisterOpenEmail(
-                                       $user['email'], $a->config['sitename'], System::baseUrl(), $user['username'], $result['password']);
+                                       $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password'], $user);
 
                        if ($res) {
                                info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
@@ -109,30 +110,30 @@ function register_post(App $a)
                        info(L10n::t('Registration successful.') . EOL);
                        goaway(System::baseUrl());
                }
-       } elseif ($a->config['register_policy'] == REGISTER_APPROVE) {
-               if (!strlen($a->config['admin_email'])) {
+       } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
+               if (!strlen(Config::get('config', 'admin_email'))) {
                        notice(L10n::t('Your registration can not be processed.') . EOL);
                        goaway(System::baseUrl());
                }
 
                $hash = random_string();
                $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
-                       dbesc($hash),
-                       dbesc(Temporal::convert()),
+                       DBA::escape($hash),
+                       DBA::escape(DateTimeFormat::utcNow()),
                        intval($user['uid']),
-                       dbesc($result['password']),
-                       dbesc($lang),
-                       dbesc($_POST['permonlybox'])
+                       DBA::escape($result['password']),
+                       DBA::escape(Config::get('system', 'language')),
+                       DBA::escape($_POST['permonlybox'])
                );
 
                // invite system
                if ($using_invites && $invite_id) {
-                       q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
+                       q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", DBA::escape($invite_id));
                        PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
                }
 
                // send email to admins
-               $admin_mail_list = "'" . implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email'])))) . "'";
+               $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
                $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
                        $admin_mail_list
                );
@@ -156,7 +157,7 @@ function register_post(App $a)
                }
                // send notification to the user, that the registration is pending
                User::sendRegisterPendingEmail(
-                       $user['email'], $a->config['sitename'], $user['username']);
+                       $user['email'], Config::get('config', 'sitename'), $user['username']);
 
                info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
                goaway(System::baseUrl());
@@ -177,7 +178,7 @@ function register_content(App $a)
                return;
        }
 
-       if ((!local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
+       if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
                notice("Permission denied." . EOL);
                return;
        }
@@ -231,8 +232,8 @@ function register_content(App $a)
                $profile_publish = replace_macros($publish_tpl, [
                        '$instance' => 'reg',
                        '$pubdesc' => L10n::t('Include your profile in member directory?'),
-                       '$yes_selected' => ' checked="checked" ',
-                       '$no_selected' => '',
+                       '$yes_selected' => '',
+                       '$no_selected' => ' checked="checked"',
                        '$str_yes' => L10n::t('Yes'),
                        '$str_no' => L10n::t('No'),
                ]);
@@ -251,17 +252,19 @@ function register_content(App $a)
 
        $tpl = $arr['template'];
 
+       $tos = new Tos();
+
        $o = replace_macros($tpl, [
                '$oidhtml' => $oidhtml,
                '$invitations' => Config::get('system', 'invitation_only'),
-               '$permonly'    => $a->config['register_policy'] == REGISTER_APPROVE,
+               '$permonly'    => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
                '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
                '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
-               '$invite_label' => L10n::t('Your invitation ID: '),
+               '$invite_label' => L10n::t('Your invitation code: '),
                '$invite_id'  => $invite_id,
                '$realpeople' => $realpeople,
                '$regtitle'  => L10n::t('Registration'),
-               '$registertext' => x($a->config, 'register_text') ? bbcode($a->config['register_text']) : "",
+               '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
                '$fillwith'  => $fillwith,
                '$fillext'   => $fillext,
                '$oidlabel'  => $oidlabel,
@@ -283,7 +286,14 @@ function register_content(App $a)
                '$sitename'  => $a->get_hostname(),
                '$importh'   => L10n::t('Import'),
                '$importt'   => L10n::t('Import your profile to this friendica instance'),
-               '$form_security_token' => get_form_security_token("register")
+               '$showtoslink' => Config::get('system', 'tosdisplay'),
+               '$tostext'   => L10n::t('Terms of Service'),
+               '$showprivstatement' => Config::get('system', 'tosprivstatement'),
+               '$privstatement' => $tos->privacy_complete,
+               '$baseurl'   => System::baseurl(),
+               '$form_security_token' => get_form_security_token("register"),
+               '$explicit_content' => Config::get('system', 'explicit_content', false),
+               '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
        ]);
        return $o;
 }