From: Michael Date: Wed, 2 Oct 2019 15:10:42 +0000 (+0000) Subject: Remove obsolete function to guess the base url of a contact X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=21e9e9f3c2e21d6028f7d59e2c68513dcefd5a1d;p=friendica.git Remove obsolete function to guess the base url of a contact --- diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 6b0ebab7aa..5aaf0f2c98 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -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 != "") { diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index a1e6f7e21c..c7ca1c7429 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -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, ""])) { diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index e8f5055c86..8a783e1865 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -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);