From f604f13d7da004b52c5858091aeecc678ee54082 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 2 Feb 2016 20:57:19 +0100 Subject: [PATCH] New method to create a guid if none was given --- include/items.php | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/include/items.php b/include/items.php index 21a0c414d..ff5d919c9 100644 --- a/include/items.php +++ b/include/items.php @@ -773,6 +773,18 @@ function item_add_language_opt(&$arr) { } } +function uri_to_guid($uri) { + $parsed = parse_url($uri); + $guid_prefix = hash("crc32", $parsed["host"]); + + unset($parsed["scheme"]); + + $host_id = implode("/", $parsed); + $host_hash = hash("ripemd128", $host_id); + + return $guid_prefix.$host_hash; +} + function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) { // If it is a posting where users should get notifications, then define it as wall posting @@ -848,33 +860,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } } - // If there is no guid then take the same guid that was taken before for the same uri - if ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "") AND (trim($arr['network']) != "")) { - logger('item_store: checking for an existing guid for uri '.$arr['uri'], LOGGER_DEBUG); - $r = q("SELECT `guid` FROM `guid` WHERE `uri` = '%s' AND `network` = '%s' LIMIT 1", - dbesc(trim($arr['uri'])), dbesc(trim($arr['network']))); - - if(count($r)) { - $arr['guid'] = $r[0]["guid"]; - logger('item_store: found guid '.$arr['guid'].' for uri '.$arr['uri'], LOGGER_DEBUG); - } - } - - // If there is no guid then take the same guid that was taken before for the same plink - if ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "") AND (trim($arr['network']) != "")) { - logger('item_store: checking for an existing guid for plink '.$arr['plink'], LOGGER_DEBUG); - $r = q("SELECT `guid`, `uri` FROM `guid` WHERE `plink` = '%s' AND `network` = '%s' LIMIT 1", - dbesc(trim($arr['plink'])), dbesc(trim($arr['network']))); - - if(count($r)) { - $arr['guid'] = $r[0]["guid"]; - logger('item_store: found guid '.$arr['guid'].' for plink '.$arr['plink'], LOGGER_DEBUG); - - if ($r[0]["uri"] != $arr['uri']) - logger('Different uri for same guid: '.$arr['uri'].' and '.$r[0]["uri"].' - this shouldnt happen!', LOGGER_DEBUG); - } - } - // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) @@ -884,6 +869,10 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa if ($notify) $guid_prefix = ""; + elseif ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "")) + $arr['guid'] = uri_to_guid($arr['plink']); + elseif ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) + $arr['guid'] = uri_to_guid($arr['uri']); else { $parsed = parse_url($arr["author-link"]); $guid_prefix = hash("crc32", $parsed["host"]);