From 57cadf5b8f5d5c45f1931607c22145647ca52f36 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 16 Apr 2016 15:22:54 +0200 Subject: [PATCH] Clean gcontact url before saving in gcontact table --- include/socgraph.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/socgraph.php b/include/socgraph.php index 33d62dc5b9..8942d8be0c 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1354,6 +1354,29 @@ function poco_discover_server($data, $default_generation = 0) { return $success; } +/** + * @brief Removes unwanted parts from a contact url + * + * @param string $url Contact url + * @return string Contact url with the wanted parts + */ +function clean_contact_url($url) { + $parts = parse_url($url); + + if (!isset($parts["scheme"]) OR !isset($parts["host"])) + return $url; + + $new_url = $parts["scheme"]."://".$parts["host"]; + + if (isset($parts["port"])) + $new_url .= ":".$parts["port"]; + + if (isset($parts["path"])) + $new_url .= $parts["path"]; + + return $new_url; +} + /** * @brief Fetch the gcontact id, add an entry if not existed * @@ -1367,6 +1390,8 @@ function get_gcontact_id($contact) { if ($contact["network"] == NETWORK_STATUSNET) $contact["network"] = NETWORK_OSTATUS; + $contact["url"] = clean_contact_url($contact["url"]); + $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2", dbesc(normalise_link($contact["url"])));