]> git.mxchange.org Git - friendica.git/commitdiff
Remove obsolete function to guess the base url of a contact
authorMichael <heluecht@pirati.ca>
Wed, 2 Oct 2019 15:10:42 +0000 (15:10 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 2 Oct 2019 15:10:42 +0000 (15:10 +0000)
src/Model/GContact.php
src/Protocol/PortableContact.php
src/Worker/DiscoverPoCo.php

index 6b0ebab7aab765f5bca52788aba77977e7c92f66..5aaf0f2c98bddb4e421cff62897b25cff321808f 100644 (file)
@@ -222,7 +222,7 @@ class GContact
 
                if (!isset($gcontact['server_url'])) {
                        // We check the server url to be sure that it is a real one
-                       $server_url = PortableContact::detectServer($gcontact['url']);
+                       $server_url = Contact::getBasepath($gcontact['url']);
 
                        // We are now sure that it is a correct URL. So we use it in the future
                        if ($server_url != "") {
index a1e6f7e21c1f17da1fdac8324262b4fe458ebd90..c7ca1c7429c661b84a4cf13cf0f787f10771c862 100644 (file)
@@ -18,6 +18,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
 use Friendica\Module\Register;
@@ -215,7 +216,7 @@ class PortableContact
        public static function reachable($profile, $server = "", $network = "", $force = false)
        {
                if ($server == "") {
-                       $server = self::detectServer($profile);
+                       $server = Contact::getBasepath($profile);
                }
 
                if ($server == "") {
@@ -225,78 +226,6 @@ class PortableContact
                return self::checkServer($server, $network, $force);
        }
 
-       public static function detectServer($profile)
-       {
-               // Try to detect the server path based upon some known standard paths
-               $server_url = "";
-
-               if ($server_url == "") {
-                       $friendica = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $profile);
-                       if ($friendica != $profile) {
-                               $server_url = $friendica;
-                       }
-               }
-
-               if ($server_url == "") {
-                       $diaspora = preg_replace("=(https?://)(.*)/u/(.*)=ism", "$1$2", $profile);
-                       if ($diaspora != $profile) {
-                               $server_url = $diaspora;
-                       }
-               }
-
-               if ($server_url == "") {
-                       $red = preg_replace("=(https?://)(.*)/channel/(.*)=ism", "$1$2", $profile);
-                       if ($red != $profile) {
-                               $server_url = $red;
-                       }
-               }
-
-               // Mastodon
-               if ($server_url == "") {
-                       $mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
-                       if ($mastodon != $profile) {
-                               $server_url = $mastodon;
-                       }
-               }
-
-               // Numeric OStatus variant
-               if ($server_url == "") {
-                       $ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile);
-                       if ($ostatus != $profile) {
-                               $server_url = $ostatus;
-                       }
-               }
-
-               // Wild guess
-               if ($server_url == "") {
-                       $base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
-                       if ($base != $profile) {
-                               $server_url = $base;
-                       }
-               }
-
-               if ($server_url == "") {
-                       return "";
-               }
-
-               $r = q(
-                       "SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
-                       DBA::escape(Strings::normaliseLink($server_url))
-               );
-
-               if (DBA::isResult($r)) {
-                       return $server_url;
-               }
-
-               // Fetch the host-meta to check if this really is a server
-               $curlResult = Network::curl($server_url."/.well-known/host-meta");
-               if (!$curlResult->isSuccess()) {
-                       return "";
-               }
-
-               return $server_url;
-       }
-
        public static function alternateOStatusUrl($url)
        {
                return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
@@ -321,7 +250,7 @@ class PortableContact
 
                $server_url = '';
                if ($force) {
-                       $server_url = Strings::normaliseLink(self::detectServer($profile));
+                       $server_url = Strings::normaliseLink(Contact::getBasepath($profile));
                }
 
                if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) {
@@ -329,7 +258,7 @@ class PortableContact
                }
 
                if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) {
-                       $server_url = Strings::normaliseLink(self::detectServer($profile));
+                       $server_url = Strings::normaliseLink(Contact::getBasepath($profile));
                }
 
                if (!in_array($gcontacts[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
index e8f5055c8642a95db7748acc23246ac28172c704..8a783e18652a226286877533410211a1830e2be1 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\GContact;
+use Friendica\Model\Contact;
 use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
@@ -175,7 +176,7 @@ class DiscoverPoCo
                                continue;
                        }
 
-                       $server_url = PortableContact::detectServer($user["url"]);
+                       $server_url = Contact::getBasepath($user["url"]);
                        $force_update = false;
 
                        if ($user["server_url"] != "") {
@@ -234,7 +235,7 @@ class DiscoverPoCo
                                        continue;
                                }
 
-                               $server_url = PortableContact::detectServer($jj->url);
+                               $server_url = Contact::getBasepath($jj->url);
                                if ($server_url != '') {
                                        if (!PortableContact::checkServer($server_url)) {
                                                Logger::log("Friendica server ".$server_url." doesn't answer.", Logger::DEBUG);