]> git.mxchange.org Git - friendica.git/commitdiff
Use "User::getIdForURL"
authorMichael <heluecht@pirati.ca>
Tue, 18 Aug 2020 19:45:01 +0000 (19:45 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 18 Aug 2020 19:45:01 +0000 (19:45 +0000)
src/Model/User.php
src/Network/Probe.php

index 9f3cadb376f0b5e97d8bc17b966f6905bd060c3b..38fe3b0ec4798c4826680218b3e4b7042dca2598 100644 (file)
@@ -162,14 +162,24 @@ class User
         * @return integer user id
         * @throws Exception
         */
-       public static function getIdForURL($url)
+       public static function getIdForURL(string $url)
        {
-               $self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]);
-               if (!DBA::isResult($self)) {
-                       return false;
-               } else {
+               $self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
+               if (!empty($self['uid'])) {
+                       return $self['uid'];
+               }
+
+               $self = Contact::selectFirst(['uid'], ['self' => true, 'addr' => $url]);
+               if (!empty($self['uid'])) {
                        return $self['uid'];
                }
+
+               $self = Contact::selectFirst(['uid'], ['self' => true, 'alias' => [$url, Strings::normaliseLink($url)]]);
+               if (!empty($self['uid'])) {
+                       return $self['uid'];
+               }
+
+               return 0;
        }
 
        /**
index 01cd886fb16dd629db06c626fda0d3add6472906..9f6b3a485eb955f5c6d0e00e0768129692dc8087 100644 (file)
@@ -29,7 +29,6 @@ use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\Contact;
 use Friendica\Model\GServer;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
@@ -2165,25 +2164,25 @@ class Probe
                return '';
        }
 
-       public static function localProbe($url)
+       /**
+        * Probe data from local profiles without network traffic
+        *
+        * @param string $url
+        * @return array probed data
+        */
+       public static function localProbe(string $url)
        {
-               $self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
-               if (empty($self['uid'])) {
-                       $self = Contact::selectFirst(['uid'], ['self' => true, 'addr' => $url]);
-               }
-               if (empty($self['uid'])) {
-                       $self = Contact::selectFirst(['uid'], ['self' => true, 'alias' => [$url, Strings::normaliseLink($url)]]);
-               }
-               if (empty($self['uid'])) {
+               $uid = User::getIdForURL($url);
+               if (empty($uid)) {
                        return [];
                }
 
-               $profile = User::getOwnerDataById($self['uid']);
+               $profile = User::getOwnerDataById($uid);
                if (empty($profile)) {
                        return [];
                }
 
-               $approfile = ActivityPub\Transmitter::getProfile($self['uid']);
+               $approfile = ActivityPub\Transmitter::getProfile($uid);
                if (empty($approfile)) {
                        return [];
                }
@@ -2195,7 +2194,7 @@ class Probe
                $data = ['name' => $profile['name'], 'nick' => $profile['nick'], 'guid' => $approfile['diaspora:guid'],
                        'url' => $profile['url'], 'addr' => $profile['addr'], 'alias' => $profile['alias'],
                        'photo' => $profile['photo'], 'account-type' => $profile['contact-type'],
-                       'community' => ($profile['contact-type'] == Contact::TYPE_COMMUNITY),
+                       'community' => ($profile['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
                        'keywords' => $profile['keywords'], 'location' => $profile['location'], 'about' => $profile['about'], 
                        'hide' => !$profile['net-publish'], 'batch' => '', 'notify' => $profile['notify'],
                        'poll' => $profile['poll'], 'request' => $profile['request'], 'confirm' => $profile['confirm'],