Provide default host value to hash() in Model\Item::guidFromUri
- Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1338133783
This commit is contained in:
parent
0af2be14ee
commit
fc246424a9
|
@ -125,7 +125,7 @@ class Avatar
|
||||||
|
|
||||||
private static function getFilename(string $url): string
|
private static function getFilename(string $url): string
|
||||||
{
|
{
|
||||||
$guid = Item::guidFromUri($url, parse_url($url, PHP_URL_HOST));
|
$guid = Item::guidFromUri($url);
|
||||||
|
|
||||||
return substr($guid, 0, 2) . '/' . substr($guid, 3, 2) . '/' . substr($guid, 5, 3) . '/' .
|
return substr($guid, 0, 2) . '/' . substr($guid, 3, 2) . '/' . substr($guid, 5, 3) . '/' .
|
||||||
substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-';
|
substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-';
|
||||||
|
|
|
@ -2675,7 +2675,7 @@ class Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
$update = false;
|
$update = false;
|
||||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
|
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url']);
|
||||||
|
|
||||||
// make sure to not overwrite existing values with blank entries except some technical fields
|
// make sure to not overwrite existing values with blank entries except some technical fields
|
||||||
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
||||||
|
|
|
@ -2037,6 +2037,7 @@ class Item
|
||||||
* @param string $uri uri of an item entry
|
* @param string $uri uri of an item entry
|
||||||
* @param string|null $host hostname for the GUID prefix
|
* @param string|null $host hostname for the GUID prefix
|
||||||
* @return string Unique guid
|
* @return string Unique guid
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function guidFromUri(string $uri, string $host = null): string
|
public static function guidFromUri(string $uri, string $host = null): string
|
||||||
{
|
{
|
||||||
|
@ -2047,11 +2048,16 @@ class Item
|
||||||
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
|
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
|
||||||
unset($parsed['scheme']);
|
unset($parsed['scheme']);
|
||||||
|
|
||||||
|
$hostPart = $host ?? $parsed['host'] ?? '';
|
||||||
|
if (!$hostPart) {
|
||||||
|
Logger::warning('Empty host GUID part', ['uri' => $uri, 'host' => $host, 'parsed' => $parsed, 'callstack' => System::callstack(10)]);
|
||||||
|
}
|
||||||
|
|
||||||
// Glue it together to be able to make a hash from it
|
// Glue it together to be able to make a hash from it
|
||||||
$host_id = implode('/', $parsed);
|
$host_id = implode('/', $parsed);
|
||||||
|
|
||||||
// Use a mixture of several hashes to provide some GUID like experience
|
// Use a mixture of several hashes to provide some GUID like experience
|
||||||
return hash('crc32', $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
|
return hash('crc32', $hostPart) . '-' . hash('joaat', $host_id) . '-' . hash('fnv164', $host_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,8 +59,7 @@ class Mail
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($msg['guid'])) {
|
if (empty($msg['guid'])) {
|
||||||
$host = parse_url($msg['from-url'], PHP_URL_HOST);
|
$msg['guid'] = Item::guidFromUri($msg['uri'], parse_url($msg['from-url'], PHP_URL_HOST));
|
||||||
$msg['guid'] = Item::guidFromUri($msg['uri'], $host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
|
$msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
|
||||||
|
|
|
@ -625,8 +625,8 @@ class Feed
|
||||||
|
|
||||||
$notify = Item::isRemoteSelf($contact, $item);
|
$notify = Item::isRemoteSelf($contact, $item);
|
||||||
|
|
||||||
// Distributed items should have a well formatted URI.
|
// Distributed items should have a well-formatted URI.
|
||||||
// Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
|
// Additionally, we have to avoid conflicts with identical URI between imported feeds and these items.
|
||||||
if ($notify) {
|
if ($notify) {
|
||||||
$item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
|
$item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
|
||||||
$item['uri'] = Item::newURI($item['guid']);
|
$item['uri'] = Item::newURI($item['guid']);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user