+function update_contact($id) {
+ /*
+ Warning: Never ever fetch the public key via probe_url and write it into the contacts.
+ This will reliably kill your communication with Friendica contacts.
+ */
+
+ $r = q("SELECT `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `network` FROM `contact` WHERE `id` = %d", intval($id));
+ if (!$r)
+ return false;
+
+ $ret = probe_url($r[0]["url"]);
+
+ // If probe_url fails the network code will be different
+ if ($ret["network"] != $r[0]["network"])
+ return false;
+
+ $update = false;
+
+ // make sure to not overwrite existing values with blank entries
+ foreach ($ret AS $key => $val) {
+ if (isset($r[0][$key]) AND ($r[0][$key] != "") AND ($val == ""))
+ $ret[$key] = $r[0][$key];
+
+ if (isset($r[0][$key]) AND ($ret[$key] != $r[0][$key]))
+ $update = true;
+ }
+
+ if (!$update)
+ return true;
+
+ q("UPDATE `contact` SET `url` = '%s', `nurl` = '%s', `addr` = '%s', `alias` = '%s', `batch` = '%s', `notify` = '%s', `poll` = '%s', `poco` = '%s' WHERE `id` = %d",
+ dbesc($ret['url']),
+ dbesc(normalise_link($ret['url'])),
+ dbesc($ret['addr']),
+ dbesc($ret['alias']),
+ dbesc($ret['batch']),
+ dbesc($ret['notify']),
+ dbesc($ret['poll']),
+ dbesc($ret['poco']),
+ intval($id)
+ );
+
+ return true;
+}