]> git.mxchange.org Git - friendica.git/blobdiff - include/user.php
Merge pull request #3879 from zeroadam/Remove-Includes-#3873
[friendica.git] / include / user.php
index 47cd7024dcf4d1a3d3016f6e328576b3ee0e66e9..7eb1058dc05655a9a174b460748ab4ae44ddd9e7 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
-require_once('include/config.php');
+use Friendica\Core\Config;
+use Friendica\Core\System;
+
 require_once('include/network.php');
 require_once('include/plugin.php');
 require_once('include/text.php');
@@ -16,8 +18,8 @@ function create_user($arr) {
        $a = get_app();
        $result = array('success' => false, 'user' => null, 'password' => '', 'message' => '');
 
-       $using_invites = get_config('system','invitation_only');
-       $num_invites   = get_config('system','number_invites');
+       $using_invites = Config::get('system','invitation_only');
+       $num_invites   = Config::get('system','number_invites');
 
 
        $invite_id  = ((x($arr,'invite_id'))  ? notags(trim($arr['invite_id']))  : '');
@@ -33,7 +35,7 @@ function create_user($arr) {
        $verified   = ((x($arr,'verified'))   ? intval($arr['verified']) : 0);
 
        $publish    = ((x($arr,'profile_publish_reg') && intval($arr['profile_publish_reg'])) ? 1 : 0);
-       $netpublish = ((strlen(get_config('system','directory'))) ? $publish : 0);
+       $netpublish = ((strlen(Config::get('system','directory'))) ? $publish : 0);
 
        if ($password1 != $confirm) {
                $result['message'] .= t('Passwords do not match. Password unchanged.') . EOL;
@@ -43,21 +45,21 @@ function create_user($arr) {
 
        $tmp_str = $openid_url;
 
-       if ($using_invites) {
-               if (! $invite_id) {
+       if($using_invites) {
+               if(! $invite_id) {
                        $result['message'] .= t('An invitation is required.') . EOL;
                        return $result;
                }
                $r = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
-               if (! results($r)) {
+               if(! results($r)) {
                        $result['message'] .= t('Invitation could not be verified.') . EOL;
                        return $result;
                }
        }
 
-       if ((! x($username)) || (! x($email)) || (! x($nickname))) {
-               if ($openid_url) {
-                       if (! validate_url($tmp_str)) {
+       if((! x($username)) || (! x($email)) || (! x($nickname))) {
+               if($openid_url) {
+                       if(! validate_url($tmp_str)) {
                                $result['message'] .= t('Invalid OpenID url') . EOL;
                                return $result;
                        }
@@ -66,7 +68,7 @@ function create_user($arr) {
                        require_once('library/openid.php');
                        $openid = new LightOpenID;
                        $openid->identity = $openid_url;
-                       $openid->returnUrl = z_root() . '/openid';
+                       $openid->returnUrl = System::baseUrl() . '/openid';
                        $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
                        $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default');
                        try {
@@ -83,7 +85,7 @@ function create_user($arr) {
                return;
        }
 
-       if (! validate_url($tmp_str))
+       if(! validate_url($tmp_str))
                $openid_url = '';
 
 
@@ -92,32 +94,25 @@ function create_user($arr) {
        // collapse multiple spaces in name
        $username = preg_replace('/ +/',' ',$username);
 
-       if (mb_strlen($username) > 48)
+       if(mb_strlen($username) > 48)
                $result['message'] .= t('Please use a shorter name.') . EOL;
-       if (mb_strlen($username) < 3)
+       if(mb_strlen($username) < 3)
                $result['message'] .= t('Name too short.') . EOL;
 
-       // I don't really like having this rule, but it cuts down
-       // on the number of auto-registrations by Russian spammers
-
-       //  Using preg_match was completely unreliable, due to mixed UTF-8 regex support
-       //      $no_utf = get_config('system','no_utf');
-       //      $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
-
        // So now we are just looking for a space in the full name.
 
-       $loose_reg = get_config('system','no_regfullname');
-       if (! $loose_reg) {
+       $loose_reg = Config::get('system','no_regfullname');
+       if(! $loose_reg) {
                $username = mb_convert_case($username,MB_CASE_TITLE,'UTF-8');
-               if (! strpos($username,' '))
+               if(! strpos($username,' '))
                        $result['message'] .= t("That doesn't appear to be your full \x28First Last\x29 name.") . EOL;
        }
 
 
-       if (! allowed_email($email))
+       if(! allowed_email($email))
                $result['message'] .= t('Your email domain is not among those allowed on this site.') . EOL;
 
-       if ((! valid_email($email)) || (! validate_email($email)))
+       if((! valid_email($email)) || (! validate_email($email)))
                $result['message'] .= t('Not a valid email address.') . EOL;
 
        // Disallow somebody creating an account using openid that uses the admin email address,
@@ -125,8 +120,8 @@ function create_user($arr) {
 
        $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email'])));
 
-       //if ((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) {
-       if ((x($a->config,'admin_email')) && in_array(strtolower($email), $adminlist) && strlen($openid_url)) {
+       //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) {
+       if((x($a->config,'admin_email')) && in_array(strtolower($email), $adminlist) && strlen($openid_url)) {
                $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1",
                        dbesc($email)
                );
@@ -136,7 +131,7 @@ function create_user($arr) {
 
        $nickname = $arr['nickname'] = strtolower($nickname);
 
-       if (! preg_match("/^[a-z0-9][a-z0-9\_]*$/",$nickname))
+       if(! preg_match("/^[a-z0-9][a-z0-9\_]*$/",$nickname))
                $result['message'] .= t('Your "nickname" can only contain "a-z", "0-9" and "_".') . EOL;
 
        $r = q("SELECT `uid` FROM `user`
@@ -156,7 +151,7 @@ function create_user($arr) {
        if (dbm::is_result($r))
                $result['message'] .= t('Nickname was once registered here and may not be re-used. Please choose another.') . EOL;
 
-       if (strlen($result['message'])) {
+       if(strlen($result['message'])) {
                return $result;
        }
 
@@ -169,37 +164,22 @@ function create_user($arr) {
 
        $keys = new_keypair(4096);
 
-       if ($keys === false) {
+       if($keys === false) {
                $result['message'] .= t('SERIOUS ERROR: Generation of security keys failed.') . EOL;
                return $result;
        }
 
-       $default_service_class = get_config('system','default_service_class');
-       if (! $default_service_class)
-               $default_service_class = '';
-
-
        $prvkey = $keys['prvkey'];
        $pubkey = $keys['pubkey'];
 
-       /**
-        *
-        * Create another keypair for signing/verifying
-        * salmon protocol messages. We have to use a slightly
-        * less robust key because this won't be using openssl
-        * but the phpseclib. Since it is PHP interpreted code
-        * it is not nearly as efficient, and the larger keys
-        * will take several minutes each to process.
-        *
-        */
-
+       // Create another keypair for signing/verifying salmon protocol messages.
        $sres    = new_keypair(512);
        $sprvkey = $sres['prvkey'];
        $spubkey = $sres['pubkey'];
 
-       $r = q("INSERT INTO `user` ( `guid`, `username`, `password`, `email`, `openid`, `nickname`,
-               `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `service_class`, `default-location` )
-               VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '%s', '' )",
+       $r = q("INSERT INTO `user` (`guid`, `username`, `password`, `email`, `openid`, `nickname`,
+               `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `default-location`)
+               VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '')",
                dbesc(generate_user_guid()),
                dbesc($username),
                dbesc($new_password_encoded),
@@ -212,8 +192,7 @@ function create_user($arr) {
                dbesc($sprvkey),
                dbesc(datetime_convert()),
                intval($verified),
-               intval($blocked),
-               dbesc($default_service_class)
+               intval($blocked)
        );
 
        if ($r) {
@@ -243,21 +222,19 @@ function create_user($arr) {
        );
        if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) {
                $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL;
-               q("DELETE FROM `user` WHERE `uid` = %d",
-                       intval($newuid)
-               );
+               dba::delete('user', array('uid' => $newuid));
                return $result;
        }
 
-       if (x($newuid) !== false) {
+       if(x($newuid) !== false) {
                $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb`, `publish`, `net-publish` )
                        VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, %d ) ",
                        intval($newuid),
                        t('default'),
                        1,
                        dbesc($username),
-                       dbesc(z_root() . "/photo/profile/{$newuid}.jpg"),
-                       dbesc(z_root() . "/photo/avatar/{$newuid}.jpg"),
+                       dbesc(System::baseUrl() . "/photo/profile/{$newuid}.jpg"),
+                       dbesc(System::baseUrl() . "/photo/avatar/{$newuid}.jpg"),
                        intval($publish),
                        intval($netpublish)
 
@@ -265,8 +242,7 @@ function create_user($arr) {
                if ($r === false) {
                        $result['message'] .=  t('An error occurred creating your default profile. Please try again.') . EOL;
                        // Start fresh next time.
-                       $r = q("DELETE FROM `user` WHERE `uid` = %d",
-                               intval($newuid));
+                       dba::delete('user', array('uid' => $newuid));
                        return $result;
                }
 
@@ -292,7 +268,7 @@ function create_user($arr) {
                        );
                }
 
-               if (get_config('system', 'newuser_private') && $def_gid) {
+               if(Config::get('system', 'newuser_private') && $def_gid) {
                        q("UPDATE `user` SET `allow_gid` = '%s' WHERE `uid` = %d",
                                dbesc("<" . $def_gid . ">"),
                                intval($newuid)
@@ -302,11 +278,11 @@ function create_user($arr) {
        }
 
        // if we have no OpenID photo try to look up an avatar
-       if (! strlen($photo))
+       if(! strlen($photo))
                $photo = avatar_img($email);
 
        // unless there is no avatar-plugin loaded
-       if (strlen($photo)) {
+       if(strlen($photo)) {
                require_once('include/Photo.php');
                $photo_failure = false;
 
@@ -317,7 +293,7 @@ function create_user($arr) {
 
 
                $img = new Photo($img_str, $type);
-               if ($img->is_valid()) {
+               if($img->is_valid()) {
 
                        $img->scaleImageSquare(175);
 
@@ -388,17 +364,17 @@ function user_create_self_contact($uid) {
                datetime_convert(),
                dbesc($user['username']),
                dbesc($user['nickname']),
-               dbesc(z_root()."/photo/profile/".$user['uid'].".jpg"),
-               dbesc(z_root()."/photo/avatar/".$user['uid'].".jpg"),
-               dbesc(z_root()."/photo/micro/".$user['uid'].".jpg"),
-               dbesc(z_root()."/profile/".$user['nickname']),
-               dbesc(normalise_link(z_root()."/profile/".$user['nickname'])),
-               dbesc($user['nickname'].'@'.substr(z_root(), strpos(z_root(),'://') + 3)),
-               dbesc(z_root()."/dfrn_request/".$user['nickname']),
-               dbesc(z_root()."/dfrn_notify/".$user['nickname']),
-               dbesc(z_root()."/dfrn_poll/".$user['nickname']),
-               dbesc(z_root()."/dfrn_confirm/".$user['nickname']),
-               dbesc(z_root()."/poco/".$user['nickname']),
+               dbesc(System::baseUrl()."/photo/profile/".$user['uid'].".jpg"),
+               dbesc(System::baseUrl()."/photo/avatar/".$user['uid'].".jpg"),
+               dbesc(System::baseUrl()."/photo/micro/".$user['uid'].".jpg"),
+               dbesc(System::baseUrl()."/profile/".$user['nickname']),
+               dbesc(normalise_link(System::baseUrl()."/profile/".$user['nickname'])),
+               dbesc($user['nickname'].'@'.substr(System::baseUrl(), strpos(System::baseUrl(),'://') + 3)),
+               dbesc(System::baseUrl()."/dfrn_request/".$user['nickname']),
+               dbesc(System::baseUrl()."/dfrn_notify/".$user['nickname']),
+               dbesc(System::baseUrl()."/dfrn_poll/".$user['nickname']),
+               dbesc(System::baseUrl()."/dfrn_confirm/".$user['nickname']),
+               dbesc(System::baseUrl()."/poco/".$user['nickname']),
                dbesc(datetime_convert()),
                dbesc(datetime_convert()),
                dbesc(datetime_convert())
@@ -422,7 +398,7 @@ function send_register_pending_eml($email, $sitename, $username) {
        $body = sprintf($body, $username, $sitename);
 
        return notification(array(
-               'type' => "SYSTEM_EMAIL",
+               'type' => SYSTEM_EMAIL,
                'to_email' => $email,
                'subject'=> sprintf( t('Registration at %s'), $sitename),
                'body' => $body));
@@ -468,7 +444,7 @@ function send_register_open_eml($email, $sitename, $siteurl, $username, $passwor
                $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
 
                return notification(array(
-                       'type' => "SYSTEM_EMAIL",
+                       'type' => SYSTEM_EMAIL,
                        'to_email' => $email,
                        'subject'=> sprintf( t('Registration details for %s'), $sitename),
                        'preamble'=> $preamble,