]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #5862 from nupplaphil/rename_App_Methods
[friendica.git] / src / Model / User.php
index bebfce3e0059f0c323a28b3b1d516eb68e95e22f..b8b694de87194a6bd6e143c9672c4b49782e9e2d 100644 (file)
@@ -11,10 +11,10 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Database\DBM;
 use Friendica\Object\Image;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
@@ -31,6 +31,23 @@ require_once 'include/text.php';
  */
 class User
 {
+       /**
+        * @brief Returns the user id of a given profile url
+        *
+        * @param string $profile
+        *
+        * @return integer user id
+        */
+       public static function getIdForURL($url)
+       {
+               $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($url), 'self' => true]);
+               if (!DBA::isResult($self)) {
+                       return false;
+               } else {
+                       return $self['uid'];
+               }
+       }
+
        /**
         * @brief Get owner data by user id
         *
@@ -38,7 +55,7 @@ class User
         * @return boolean|array
         */
        public static function getOwnerDataById($uid) {
-               $r = DBA::fetch_first("SELECT
+               $r = DBA::fetchFirst("SELECT
                        `contact`.*,
                        `user`.`prvkey` AS `uprvkey`,
                        `user`.`timezone`,
@@ -56,7 +73,7 @@ class User
                        LIMIT 1",
                        $uid
                );
-               if (!DBM::is_result($r)) {
+               if (!DBA::isResult($r)) {
                        return false;
                }
                return $r;
@@ -71,9 +88,11 @@ class User
        public static function getOwnerDataByNick($nick)
        {
                $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick]);
-               if (!DBM::is_result($user)) {
+
+               if (!DBA::isResult($user)) {
                        return false;
                }
+
                return self::getOwnerDataById($user['uid']);
        }
 
@@ -89,7 +108,7 @@ class User
        {
                $default_group = 0;
 
-               if ($network == NETWORK_OSTATUS) {
+               if ($network == Protocol::OSTATUS) {
                        $default_group = PConfig::get($uid, "ostatus", "default_group");
                }
 
@@ -99,7 +118,7 @@ class User
 
                $user = DBA::selectFirst('user', ['def_gid'], ['uid' => $uid]);
 
-               if (DBM::is_result($user)) {
+               if (DBA::isResult($user)) {
                        $default_group = $user["def_gid"];
                }
 
@@ -215,7 +234,7 @@ class User
                                $user = DBA::selectFirst('user', $fields, $condition);
                        }
 
-                       if (!DBM::is_result($user)) {
+                       if (!DBA::isResult($user)) {
                                throw new Exception(L10n::t('User not found'));
                        }
                }
@@ -395,7 +414,7 @@ class User
                                $_SESSION['register'] = 1;
                                $_SESSION['openid'] = $openid_url;
 
-                               $openid = new LightOpenID($a->get_hostname());
+                               $openid = new LightOpenID($a->getHostName());
                                $openid->identity = $openid_url;
                                $openid->returnUrl = System::baseUrl() . '/openid';
                                $openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
@@ -493,7 +512,7 @@ class User
                $spubkey = $sres['pubkey'];
 
                $insert_result = DBA::insert('user', [
-                       'guid'     => generate_user_guid(),
+                       'guid'     => System::createUUID(),
                        'username' => $username,
                        'password' => $new_password_encoded,
                        'email'    => $email,
@@ -660,7 +679,7 @@ class User
         * @param string $password
         * @return NULL|boolean from notification() and email() inherited
         */
-       public static function sendRegisterOpenEmail($email, $sitename, $siteurl, $username, $password)
+       public static function sendRegisterOpenEmail($email, $sitename, $siteurl, $username, $password, $user)
        {
                $preamble = deindent(L10n::t('
                        Dear %1$s,
@@ -698,6 +717,8 @@ class User
                $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
 
                return notification([
+                       'uid' => $user['uid'],
+                       'language' => $user['language'],
                        'type' => SYSTEM_EMAIL,
                        'to_email' => $email,
                        'subject'=> L10n::t('Registration details for %s', $sitename),
@@ -726,11 +747,15 @@ class User
                DBA::insert('userd', ['username' => $user['nickname']]);
 
                // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
-               DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utcNow()], ['uid' => $uid]);
+               DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc(DateTimeFormat::utcNow() . " + 7 day")], ['uid' => $uid]);
                Worker::add(PRIORITY_HIGH, "Notifier", "removeme", $uid);
 
                // Send an update to the directory
-               Worker::add(PRIORITY_LOW, "Directory", $user['url']);
+               $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
+               Worker::add(PRIORITY_LOW, "Directory", $self['url']);
+
+               // Remove the user relevant data
+               Worker::add(PRIORITY_LOW, "RemoveUser", $uid);
 
                if ($uid == local_user()) {
                        unset($_SESSION['authenticated']);