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) . '/' .
substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-';
if ($static) {
$query_params['static'] = true;
}
-
+
return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
}
}
$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
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
* Posts that are created on this system are using System::createUUID.
* Received ActivityPub posts are using Processor::getGUIDByURL.
*
- * @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
* @return string Unique guid
+ * @throws \Exception
*/
public static function guidFromUri(string $uri, string $host = null): string
{
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
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
$host_id = implode('/', $parsed);
// 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);
}
/**
}
if (empty($msg['guid'])) {
- $host = parse_url($msg['from-url'], PHP_URL_HOST);
- $msg['guid'] = Item::guidFromUri($msg['uri'], $host);
+ $msg['guid'] = Item::guidFromUri($msg['uri'], parse_url($msg['from-url'], PHP_URL_HOST));
}
$msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
$notify = Item::isRemoteSelf($contact, $item);
- // Distributed items should have a well formatted URI.
- // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
+ // Distributed items should have a well-formatted URI.
+ // Additionally, we have to avoid conflicts with identical URI between imported feeds and these items.
if ($notify) {
$item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
$item['uri'] = Item::newURI($item['guid']);