+ $fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'];
+ $contact = dba::selectFirst('gcontact', $fields, ['nurl' => normalise_link($url)]);
+ if (!DBM::is_result($contact)) {
+ $contact = dba::selectFirst('contact', $fields, ['nurl' => normalise_link($url)]);
+ }
+
+ if (!DBM::is_result($contact)) {
+ $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+ 'photo', 'keywords', 'location', 'about', 'network',
+ 'priority', 'batch', 'request', 'confirm', 'poco'];
+ $contact = dba::selectFirst('contact', $fields, ['addr' => $url]);
+ }
+
+ if (!DBM::is_result($contact)) {
+ // The link could be provided as http although we stored it as https
+ $ssl_url = str_replace('http://', 'https://', $url);
+ $condition = ['alias' => [$url, normalise_link($url), $ssl_url]];
+ $contact = dba::selectFirst('contact', $fields, $condition);
+ }
+
+ if (!DBM::is_result($contact)) {
+ $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+ 'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
+ $condition = ['url' => [$url, normalise_link($url), $ssl_url]];
+ $contact = dba::selectFirst('fcontact', $fields, $condition);
+ }
+
+ if (!empty($default)) {
+ $contact = $default;