Priority for native networks when searching by contact url

This commit is contained in:
Michael Vogel 2016-06-12 10:46:15 +02:00
parent 710822dca7
commit aac9caab2d
2 changed files with 22 additions and 22 deletions

View file

@ -207,35 +207,34 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
if ($uid == -1) if ($uid == -1)
$uid = local_user(); $uid = local_user();
// Fetch contact data from the contact table for the user and given network // Fetch contact data from the contact table for the given user
$r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
`keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, `self` `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, `self`
FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` IN ('%s', '')", FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
dbesc(normalise_link($url)), intval($uid), dbesc($profile["network"])); dbesc(normalise_link($url)), intval($uid));
// Is the contact present for the user in a different network? (Can happen with OStatus and the "Statusnet" addon)
if (!$r)
$r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
`keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, `self`
FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
dbesc(normalise_link($url)), intval($uid));
// Fetch the data from the contact table with "uid=0" (which is filled automatically) // Fetch the data from the contact table with "uid=0" (which is filled automatically)
if (!$r) if (!$r)
$r = q("SELECT `id`, 0 AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
`keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, 0 AS `self` `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, 0 AS `self`
FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0", FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
dbesc(normalise_link($url))); dbesc(normalise_link($url)));
// Fetch the data from the gcontact table // Fetch the data from the gcontact table
if (!$r) if (!$r)
$r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
`keywords`, `gender`, `photo`, `photo` AS `thumb`, `community` AS `forum`, 0 AS `prv`, `community`, `birthday`, 0 AS `self` `keywords`, `gender`, `photo`, `photo` AS `thumb`, `community` AS `forum`, 0 AS `prv`, `community`, `birthday`, 0 AS `self`
FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", FROM `gcontact` WHERE `nurl` = '%s'",
dbesc(normalise_link($url))); dbesc(normalise_link($url)));
if ($r) { if ($r) {
$profile = $r[0]; // If there is more than one entry we filter out the connector networks
if (count($r) > 1)
foreach ($r AS $id => $result)
if ($result["network"] == NETWORK_STATUSNET)
unset($r[$id]);
$profile = array_shift($r);
// "bd" always contains the upcoming birthday of a contact. // "bd" always contains the upcoming birthday of a contact.
// "birthday" might contain the birthday including the year of birth. // "birthday" might contain the birthday including the year of birth.

View file

@ -64,16 +64,15 @@ function dirfind_content(&$a, $prefix = "") {
$objresult->tags = ""; $objresult->tags = "";
$objresult->network = $user_data["network"]; $objresult->network = $user_data["network"];
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", $contact = get_contact_details_by_url($user_data["url"], local_user());
dbesc(normalise_link($user_data["url"])), intval(local_user())); $objresult->cid = $contact["cid"];
if ($contact)
$objresult->cid = $contact[0]["id"];
$j->results[] = $objresult; $j->results[] = $objresult;
poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"], // Add the contact to the global contacts if it isn't already in our system
"", "", "", "", "", datetime_convert(), 0); if (($contact["cid"] == 0) AND ($contact["zid"] == 0) AND ($contact["gid"] == 0))
poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
"", "", "", "", "", datetime_convert(), 0);
} elseif ($local) { } elseif ($local) {
if ($community) if ($community)
@ -98,6 +97,7 @@ function dirfind_content(&$a, $prefix = "") {
$count = q("SELECT count(*) AS `total` FROM `gcontact` $count = q("SELECT count(*) AS `total` FROM `gcontact`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
AND `contact`.`network` = `gcontact`.`network`
AND `contact`.`uid` = %d AND NOT `contact`.`blocked` AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
@ -112,6 +112,7 @@ function dirfind_content(&$a, $prefix = "") {
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr` $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
FROM `gcontact` FROM `gcontact`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
AND `contact`.`network` = `gcontact`.`network`
AND `contact`.`uid` = %d AND NOT `contact`.`blocked` AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND