+/**
+ * @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"];
+
+ if ($new_url != $url)
+ logger("Cleaned contact url ".$url." to ".$new_url." - Called by: ".App::callstack(), LOGGER_DEBUG);
+
+ return $new_url;
+}
+
+/**
+ * @brief Replace alternate OStatus user format with the primary one
+ *
+ * @param arr $contact contact array (called by reference)
+ */
+function fix_alternate_contact_address(&$contact) {
+ if (($contact["network"] == NETWORK_OSTATUS) AND poco_alternate_ostatus_url($contact["url"])) {
+ $data = probe_url($contact["url"]);
+ if ($contact["network"] == NETWORK_OSTATUS) {
+ logger("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".App::callstack(), LOGGER_DEBUG);
+ $contact["url"] = $data["url"];
+ $contact["addr"] = $data["addr"];
+ $contact["alias"] = $data["alias"];
+ $contact["server_url"] = $data["baseurl"];
+ }
+ }
+}
+