Merge pull request #7693 from annando/remove-obsolete

Remove obsolete function to guess the base url of a contact
This commit is contained in:
Hypolite Petovan 2019-10-02 11:24:00 -04:00 committed by GitHub
commit c5563e5e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 78 deletions

View 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 != "") {

View 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, ""])) {

View 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);