mirror of
https://github.com/friendica/friendica
synced 2025-05-07 23:04:10 +02:00
normalise_link calls
implement normaliseLink function
This commit is contained in:
parent
5276c28a78
commit
ffc406d819
54 changed files with 248 additions and 222 deletions
|
@ -23,6 +23,7 @@ use Friendica\Model\Profile;
|
|||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once 'include/dba.php';
|
||||
|
@ -284,7 +285,7 @@ class PortableContact
|
|||
|
||||
$r = q(
|
||||
"SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
|
||||
DBA::escape(normalise_link($server_url))
|
||||
DBA::escape(Strings::normaliseLink($server_url))
|
||||
);
|
||||
|
||||
if (DBA::isResult($r)) {
|
||||
|
@ -309,7 +310,7 @@ class PortableContact
|
|||
{
|
||||
$gcontacts = q(
|
||||
"SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
DBA::escape(normalise_link($profile))
|
||||
DBA::escape(Strings::normaliseLink($profile))
|
||||
);
|
||||
|
||||
if (!DBA::isResult($gcontacts)) {
|
||||
|
@ -324,7 +325,7 @@ class PortableContact
|
|||
|
||||
$server_url = '';
|
||||
if ($force) {
|
||||
$server_url = normalise_link(self::detectServer($profile));
|
||||
$server_url = Strings::normaliseLink(self::detectServer($profile));
|
||||
}
|
||||
|
||||
if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) {
|
||||
|
@ -332,7 +333,7 @@ class PortableContact
|
|||
}
|
||||
|
||||
if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) {
|
||||
$server_url = normalise_link(self::detectServer($profile));
|
||||
$server_url = Strings::normaliseLink(self::detectServer($profile));
|
||||
}
|
||||
|
||||
if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
|
||||
|
@ -344,7 +345,7 @@ class PortableContact
|
|||
if (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) {
|
||||
if ($force) {
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
}
|
||||
|
||||
Logger::log("Profile ".$profile.": Server ".$server_url." wasn't reachable.", Logger::DEBUG);
|
||||
|
@ -356,7 +357,7 @@ class PortableContact
|
|||
if (in_array($gcontacts[0]["network"], ["", Protocol::FEED])) {
|
||||
$server = q(
|
||||
"SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
|
||||
DBA::escape(normalise_link($server_url))
|
||||
DBA::escape(Strings::normaliseLink($server_url))
|
||||
);
|
||||
|
||||
if ($server) {
|
||||
|
@ -369,7 +370,7 @@ class PortableContact
|
|||
// noscrape is really fast so we don't cache the call.
|
||||
if (($server_url != "") && ($gcontacts[0]["nick"] != "")) {
|
||||
// Use noscrape if possible
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(normalise_link($server_url)));
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(Strings::normaliseLink($server_url)));
|
||||
|
||||
if ($server) {
|
||||
$curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
|
||||
|
@ -425,7 +426,7 @@ class PortableContact
|
|||
|
||||
if (!empty($noscrape["updated"])) {
|
||||
$fields = ['last_contact' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
|
||||
Logger::log("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", Logger::DEBUG);
|
||||
|
||||
|
@ -449,11 +450,11 @@ class PortableContact
|
|||
// Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
|
||||
// Then check the other link and delete this one
|
||||
if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile)
|
||||
&& (normalise_link($profile) == normalise_link($data["alias"]))
|
||||
&& (normalise_link($profile) != normalise_link($data["url"]))
|
||||
&& (Strings::normaliseLink($profile) == Strings::normaliseLink($data["alias"]))
|
||||
&& (Strings::normaliseLink($profile) != Strings::normaliseLink($data["url"]))
|
||||
) {
|
||||
// Delete the old entry
|
||||
DBA::delete('gcontact', ['nurl' => normalise_link($profile)]);
|
||||
DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($profile)]);
|
||||
|
||||
$gcontact = array_merge($gcontacts[0], $data);
|
||||
|
||||
|
@ -474,7 +475,7 @@ class PortableContact
|
|||
|
||||
if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) {
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
|
||||
Logger::log("Profile ".$profile." wasn't reachable (profile)", Logger::DEBUG);
|
||||
return false;
|
||||
|
@ -490,7 +491,7 @@ class PortableContact
|
|||
|
||||
if (!$curlResult->isSuccess()) {
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
|
||||
Logger::log("Profile ".$profile." wasn't reachable (no feed)", Logger::DEBUG);
|
||||
return false;
|
||||
|
@ -533,11 +534,11 @@ class PortableContact
|
|||
$fields['updated'] = $last_updated;
|
||||
}
|
||||
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
|
||||
if (($gcontacts[0]["generation"] == 0)) {
|
||||
$fields = ['generation' => 9];
|
||||
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
|
||||
}
|
||||
|
||||
Logger::log("Profile ".$profile." was last updated at ".$last_updated, Logger::DEBUG);
|
||||
|
@ -930,11 +931,11 @@ class PortableContact
|
|||
return false;
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
|
||||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
if ($gserver["created"] <= DBA::NULL_DATETIME) {
|
||||
$fields = ['created' => DateTimeFormat::utcNow()];
|
||||
$condition = ['nurl' => normalise_link($server_url)];
|
||||
$condition = ['nurl' => Strings::normaliseLink($server_url)];
|
||||
DBA::update('gserver', $fields, $condition);
|
||||
}
|
||||
$poco = $gserver["poco"];
|
||||
|
@ -990,7 +991,7 @@ class PortableContact
|
|||
// Mastodon uses the "@" for user profiles.
|
||||
// But this can be misunderstood.
|
||||
if (parse_url($server_url, PHP_URL_USER) != '') {
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1006,7 +1007,7 @@ class PortableContact
|
|||
if (DBA::isResult($gserver) && ($orig_server_url == $server_url) &&
|
||||
($curlResult->isTimeout())) {
|
||||
Logger::log("Connection to server ".$server_url." timed out.", Logger::DEBUG);
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1021,7 +1022,7 @@ class PortableContact
|
|||
// Quit if there is a timeout
|
||||
if ($curlResult->isTimeout()) {
|
||||
Logger::log("Connection to server " . $server_url . " timed out.", Logger::DEBUG);
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1048,7 +1049,7 @@ class PortableContact
|
|||
|
||||
if (!$failure) {
|
||||
// This will be too low, but better than no value at all.
|
||||
$registered_users = DBA::count('gcontact', ['server_url' => normalise_link($server_url)]);
|
||||
$registered_users = DBA::count('gcontact', ['server_url' => Strings::normaliseLink($server_url)]);
|
||||
}
|
||||
|
||||
// Look for poco
|
||||
|
@ -1410,7 +1411,7 @@ class PortableContact
|
|||
}
|
||||
|
||||
// Check again if the server exists
|
||||
$found = DBA::exists('gserver', ['nurl' => normalise_link($server_url)]);
|
||||
$found = DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
|
||||
$version = strip_tags($version);
|
||||
$site_name = strip_tags($site_name);
|
||||
|
@ -1424,9 +1425,9 @@ class PortableContact
|
|||
'last_contact' => $last_contact, 'last_failure' => $last_failure];
|
||||
|
||||
if ($found) {
|
||||
DBA::update('gserver', $fields, ['nurl' => normalise_link($server_url)]);
|
||||
DBA::update('gserver', $fields, ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
} elseif (!$failure) {
|
||||
$fields['nurl'] = normalise_link($server_url);
|
||||
$fields['nurl'] = Strings::normaliseLink($server_url);
|
||||
$fields['created'] = DateTimeFormat::utcNow();
|
||||
DBA::insert('gserver', $fields);
|
||||
}
|
||||
|
@ -1461,7 +1462,7 @@ class PortableContact
|
|||
return;
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => normalise_link($server_url)]);
|
||||
$gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
|
||||
if (!DBA::isResult($gserver)) {
|
||||
return;
|
||||
|
@ -1560,7 +1561,7 @@ class PortableContact
|
|||
foreach ($serverlist as $server) {
|
||||
$server_url = str_replace("/index.php", "", $server['url']);
|
||||
|
||||
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(normalise_link($server_url)));
|
||||
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(Strings::normaliseLink($server_url)));
|
||||
|
||||
if (!DBA::isResult($r)) {
|
||||
Logger::log("Call server check for server ".$server_url, Logger::DEBUG);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue