"addr" and "server_url" are now generated directly in "update_gcontact" if not given.

This commit is contained in:
Michael Vogel 2016-02-14 11:56:23 +01:00
parent b9e1792076
commit 5d35974c19
3 changed files with 75 additions and 36 deletions

View File

@ -841,18 +841,18 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
$vcard['fn'] = $url; $vcard['fn'] = $url;
if (($notify != "") AND ($poll != "")) { if (($notify != "") AND ($poll != "")) {
$baseurl = matching(normalise_link($notify), normalise_link($poll)); $baseurl = matching_url(normalise_link($notify), normalise_link($poll));
$baseurl2 = matching($baseurl, normalise_link($profile)); $baseurl2 = matching_url($baseurl, normalise_link($profile));
if ($baseurl2 != "") if ($baseurl2 != "")
$baseurl = $baseurl2; $baseurl = $baseurl2;
} }
if (($baseurl == "") AND ($notify != "")) if (($baseurl == "") AND ($notify != ""))
$baseurl = matching(normalise_link($profile), normalise_link($notify)); $baseurl = matching_url(normalise_link($profile), normalise_link($notify));
if (($baseurl == "") AND ($poll != "")) if (($baseurl == "") AND ($poll != ""))
$baseurl = matching(normalise_link($profile), normalise_link($poll)); $baseurl = matching_url(normalise_link($profile), normalise_link($poll));
$baseurl = rtrim($baseurl, "/"); $baseurl = rtrim($baseurl, "/");
@ -907,19 +907,56 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
return $result; return $result;
} }
function matching($part1, $part2) { /**
$len = min(strlen($part1), strlen($part2)); * @brief Find the matching part between two url
*
* @param string $url1
* @param string $url2
* @return string The matching part
*/
function matching_url($url1, $url2) {
if (($url1 == "") OR ($url2 == ""))
return "";
$url1 = normalise_link($url1);
$url2 = normalise_link($url2);
$parts1 = parse_url($url1);
$parts2 = parse_url($url2);
if (!isset($parts1["host"]) OR !isset($parts2["host"]))
return "";
if ($parts1["scheme"] != $parts2["scheme"])
return "";
if ($parts1["host"] != $parts2["host"])
return "";
if ($parts1["port"] != $parts2["port"])
return "";
$match = $parts1["scheme"]."://".$parts1["host"];
if ($parts1["port"])
$match .= ":".$parts1["port"];
$pathparts1 = explode("/", $parts1["path"]);
$pathparts2 = explode("/", $parts2["path"]);
$match = "";
$matching = true;
$i = 0; $i = 0;
while (($i <= $len) AND $matching) { $path = "";
if (substr($part1, $i, 1) == substr($part2, $i, 1)) do {
$match .= substr($part1, $i, 1); $path1 = $pathparts1[$i];
else $path2 = $pathparts2[$i];
$matching = false;
$i++; if ($path1 == $path2)
} $path .= $path1."/";
return($match);
} while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
$match .= $path;
return normalise_link($match);
} }

View File

@ -164,8 +164,6 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]); update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
} }
/// @todo Add the "addr" field
$contact["generation"] = 2; $contact["generation"] = 2;
$contact["photo"] = $author["author-avatar"]; $contact["photo"] = $author["author-avatar"];
update_gcontact($contact); update_gcontact($contact);
@ -675,24 +673,6 @@ function ostatus_conv_fetch_actor($actor) {
} }
} }
$contact["server_url"] = $contact["url"];
$server_url = matching($contact["server_url"], $contact["alias"]);
if (strlen($server_url) > 8)
$contact["server_url"] = $server_url;
$server_url = matching($contact["server_url"], $contact["photo"]);
if (strlen($server_url) > 8)
$contact["server_url"] = $server_url;
if (($contact["server_url"] == $contact["url"]) OR ($contact["server_url"] == $contact["alias"]))
unset($contact["server_url"]);
else {
$hostname = str_replace("http://", "", normalise_link($contact["server_url"]));
if ($hostname AND $contact["nick"])
$contact["addr"] = $contact["nick"]."@".$hostname;
}
update_gcontact($contact); update_gcontact($contact);
} }

View File

@ -1433,6 +1433,28 @@ function update_gcontact($contact) {
if (!isset($contact["updated"])) if (!isset($contact["updated"]))
$contact["updated"] = datetime_convert(); $contact["updated"] = datetime_convert();
if ($contact["server_url"] == "") {
$server_url = $contact["url"];
$server_url = matching_url($server_url, $contact["alias"]);
if ($server_url != "")
$contact["server_url"] = $server_url;
$server_url = matching_url($server_url, $contact["photo"]);
if ($server_url != "")
$contact["server_url"] = $server_url;
$server_url = matching_url($server_url, $contact["notify"]);
if ($server_url != "")
$contact["server_url"] = $server_url;
} else
$contact["server_url"] = normalise_link($contact["server_url"]);
if (($contact["addr"] == "") AND ($contact["server_url"] != "") AND ($contact["nick"] != "")) {
$hostname = str_replace("http://", "", $contact["server_url"]);
$contact["addr"] = $contact["nick"]."@".$hostname;
}
// Check if any field changed // Check if any field changed
$update = false; $update = false;
unset($fields["generation"]); unset($fields["generation"]);