]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / src / Model / User.php
index f7a235effe6674ee559117af4b857bcfc4e4d036..2ba0f05bd81a279ed5d27a95fdd738eb941a9571 100644 (file)
@@ -16,11 +16,12 @@ use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
+use Friendica\Util\Crypto;
 use dba;
 use Exception;
 
 require_once 'boot.php';
-require_once 'include/crypto.php';
+require_once 'include/dba.php';
 require_once 'include/enotify.php';
 require_once 'include/network.php';
 require_once 'library/openid.php';
@@ -32,6 +33,37 @@ require_once 'include/text.php';
  */
 class User
 {
+       /**
+        * @brief Get owner data by user id
+        *
+        * @param int $uid
+        * @return boolean|array
+        */
+       public static function getOwnerDataById($uid) {
+               $r = dba::fetch_first("SELECT
+                       `contact`.*,
+                       `user`.`prvkey` AS `uprvkey`,
+                       `user`.`timezone`,
+                       `user`.`nickname`,
+                       `user`.`sprvkey`,
+                       `user`.`spubkey`,
+                       `user`.`page-flags`,
+                       `user`.`account-type`,
+                       `user`.`prvnets`
+                       FROM `contact`
+                       INNER JOIN `user`
+                               ON `user`.`uid` = `contact`.`uid`
+                       WHERE `contact`.`uid` = ?
+                       AND `contact`.`self`
+                       LIMIT 1",
+                       $uid
+               );
+               if (!DBM::is_result($r)) {
+                       return false;
+               }
+               return $r;
+       }
+
        /**
         * @brief Returns the default group for a given user and network
         *
@@ -52,7 +84,7 @@ class User
                        return $default_group;
                }
 
-               $user = dba::select('user', ['def_gid'], ['uid' => $uid], ['limit' => 1]);
+               $user = dba::selectFirst('user', ['def_gid'], ['uid' => $uid]);
 
                if (DBM::is_result($user)) {
                        $default_group = $user["def_gid"];
@@ -80,16 +112,14 @@ class User
                if (is_object($user_info)) {
                        $user = (array) $user_info;
                } elseif (is_int($user_info)) {
-                       $user = dba::select('user',
-                               ['uid', 'password'],
+                       $user = dba::selectFirst('user', ['uid', 'password'],
                                [
                                        'uid' => $user_info,
                                        'blocked' => 0,
                                        'account_expired' => 0,
                                        'account_removed' => 0,
                                        'verified' => 1
-                               ],
-                               ['limit' => 1]
+                               ]
                        );
                } elseif (is_string($user_info)) {
                        $user = dba::fetch_first('SELECT `uid`, `password`
@@ -166,8 +196,6 @@ class User
                        $password = $password1;
                }
 
-               $tmp_str = $openid_url;
-
                if ($using_invites) {
                        if (!$invite_id) {
                                throw new Exception(t('An invitation is required.'));
@@ -180,17 +208,17 @@ class User
 
                if (!x($username) || !x($email) || !x($nickname)) {
                        if ($openid_url) {
-                               if (!validate_url($tmp_str)) {
+                               if (!validate_url($openid_url)) {
                                        throw new Exception(t('Invalid OpenID url'));
                                }
                                $_SESSION['register'] = 1;
                                $_SESSION['openid'] = $openid_url;
 
-                               $openid = new LightOpenID;
+                               $openid = new \LightOpenID;
                                $openid->identity = $openid_url;
                                $openid->returnUrl = System::baseUrl() . '/openid';
-                               $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
-                               $openid->optional = array('namePerson/first', 'media/image/aspect11', 'media/image/default');
+                               $openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
+                               $openid->optional = ['namePerson/first', 'media/image/aspect11', 'media/image/default'];
                                try {
                                        $authurl = $openid->authUrl();
                                } catch (Exception $e) {
@@ -203,7 +231,7 @@ class User
                        throw new Exception(t('Please enter the required information.'));
                }
 
-               if (!validate_url($tmp_str)) {
+               if (!validate_url($openid_url)) {
                        $openid_url = '';
                }
 
@@ -267,7 +295,7 @@ class User
 
                $return['password'] = $new_password;
 
-               $keys = new_keypair(4096);
+               $keys = Crypto::newKeypair(4096);
                if ($keys === false) {
                        throw new Exception(t('SERIOUS ERROR: Generation of security keys failed.'));
                }
@@ -276,7 +304,7 @@ class User
                $pubkey = $keys['pubkey'];
 
                // Create another keypair for signing/verifying salmon protocol messages.
-               $sres = new_keypair(512);
+               $sres = Crypto::newKeypair(512);
                $sprvkey = $sres['prvkey'];
                $spubkey = $sres['pubkey'];
 
@@ -300,7 +328,7 @@ class User
 
                if ($insert_result) {
                        $uid = dba::lastInsertId();
-                       $user = dba::select('user', [], ['uid' => $uid], ['limit' => 1]);
+                       $user = dba::selectFirst('user', [], ['uid' => $uid]);
                } else {
                        throw new Exception(t('An error occurred during registration. Please try again.'));
                }
@@ -407,8 +435,8 @@ class User
 
                call_hooks('register_account', $uid);
 
-               $result['user'] = $user;
-               return $result;
+               $return['user'] = $user;
+               return $return;
        }
 
        /**
@@ -428,11 +456,11 @@ class User
 
                $body = sprintf($body, $username, $sitename);
 
-               return notification(array(
+               return notification([
                        'type' => SYSTEM_EMAIL,
                        'to_email' => $email,
                        'subject'=> sprintf( t('Registration at %s'), $sitename),
-                       'body' => $body));
+                       'body' => $body]);
        }
 
        /**
@@ -482,12 +510,12 @@ class User
                $preamble = sprintf($preamble, $username, $sitename);
                $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
 
-               return notification(array(
+               return notification([
                        'type' => SYSTEM_EMAIL,
                        'to_email' => $email,
                        'subject'=> sprintf( t('Registration details for %s'), $sitename),
                        'preamble'=> $preamble,
-                       'body' => $body));
+                       'body' => $body]);
        }
 
        /**
@@ -502,7 +530,7 @@ class User
 
                logger('Removing user: ' . $uid);
 
-               $user = dba::select('user', [], ['uid' => $uid], ['limit' => 1]);
+               $user = dba::selectFirst('user', [], ['uid' => $uid]);
 
                call_hooks('remove_user', $user);