From: Michael Date: Sun, 19 Jan 2020 14:33:16 +0000 (+0000) Subject: AP: Create a GUID out of an URL X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bb253ceeaafaa317276ad38c692b292692a2cadf;p=friendica.git AP: Create a GUID out of an URL --- diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 89abac6c94..cc5c90d3b8 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -389,6 +389,26 @@ class Processor return $item; } + /** + * Generate a GUID out of an URL + * + * @param string $url message URL + * @return string with GUID + */ + private static function getGUIDByURL(string $url) + { + $parsed = parse_url($url); + + $host_hash = hash('crc32', $parsed['host']); + + unset($parsed["scheme"]); + unset($parsed["host"]); + + $path = implode("/", $parsed); + + return $host_hash . '-'. hash('fnv164', $path) . '-'. hash('joaat', $path); + } + /** * Creates an item post * @@ -431,7 +451,7 @@ class Processor $item['created'] = DateTimeFormat::utc($activity['published']); $item['edited'] = DateTimeFormat::utc($activity['updated']); - $item['guid'] = $activity['diaspora:guid']; + $item['guid'] = $activity['diaspora:guid'] ?: self::getGUIDByURL($item['uri']); $item = self::processContent($activity, $item); if (empty($item)) {