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;
public static function reachable($profile, $server = "", $network = "", $force = false)
{
if ($server == "") {
- $server = self::detectServer($profile);
+ $server = Contact::getBasepath($profile);
}
if ($server == "") {
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));
$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"] != "")) {
}
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, ""])) {
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;
continue;
}
- $server_url = PortableContact::detectServer($user["url"]);
+ $server_url = Contact::getBasepath($user["url"]);
$force_update = false;
if ($user["server_url"] != "") {
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);