const DETECT_UNSPECIFIC = [self::DETECT_MANUAL, self::DETECT_HEADER, self::DETECT_BODY, self::DETECT_HOST_META, self::DETECT_CONTACTS, self::DETECT_AP_ACTOR];
// Implementation specific endpoints
+ // @todo Possibly add Lemmy detection via the endpoint /api/v3/site
const DETECT_FRIENDIKA = 10;
const DETECT_FRIENDICA = 11;
const DETECT_STATUSNET = 12;
*/
public static function getID(string $url, bool $no_check = false): ?int
{
+ $url = self::cleanURL($url);
+
if (empty($url)) {
return null;
}
- $url = self::cleanURL($url);
-
$gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => Strings::normaliseLink($url)]);
if (DBA::isResult($gserver)) {
Logger::debug('Got ID for URL', ['id' => $gserver['id'], 'url' => $url, 'callstack' => System::callstack(20)]);
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool
{
if ($server == '') {
- $contact = Contact::getByURL($profile, null, ['baseurl']);
+ $contact = Contact::getByURL($profile, null, ['baseurl', 'network']);
if (!empty($contact['baseurl'])) {
$server = $contact['baseurl'];
+ } elseif ($contact['network'] == Protocol::DIASPORA) {
+ $parts = parse_url($profile);
+ unset($parts['path']);
+ $server = (string)Uri::fromParts($parts);
}
}
/**
* Remove unwanted content from the given URL
*
- * @param string $url
+ * @param string $dirtyUrl
*
* @return string cleaned URL
+ * @throws Exception
*/
- public static function cleanURL(string $url): string
+ public static function cleanURL(string $dirtyUrl): string
{
- $url = trim($url, '/');
- $url = str_replace('/index.php', '', $url);
-
- $urlparts = parse_url($url);
- unset($urlparts['user']);
- unset($urlparts['pass']);
- unset($urlparts['query']);
- unset($urlparts['fragment']);
- return (string)Uri::fromParts($urlparts);
+ try {
+ $url = str_replace('/index.php', '', trim($dirtyUrl, '/'));
+ return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment('');
+ } catch (\Throwable $e) {
+ Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]);
+ return '';
+ }
}
/**
if (!empty($data['url'])) {
$serverdata['platform'] = strtolower($data['platform']);
- $serverdata['version'] = $data['version'];
+ $serverdata['version'] = $data['version'] ?? 'N/A';
}
if (!empty($data['plugins'])) {
foreach ($servers['instances'] as $server) {
$url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
self::add($url);
- }
+ }
}
}
}