From aac9caab2d39980c80ea3ae31b24b27561c4f646 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 12 Jun 2016 10:46:15 +0200 Subject: [PATCH 1/2] Priority for native networks when searching by contact url --- include/Contact.php | 29 ++++++++++++++--------------- mod/dirfind.php | 15 ++++++++------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index cbce6cf540..86ef4a30fa 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -207,35 +207,34 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { if ($uid == -1) $uid = local_user(); - // Fetch contact data from the contact table for the user and given network - $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, + // Fetch contact data from the contact table for the given user + $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` - FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` IN ('%s', '')", - dbesc(normalise_link($url)), intval($uid), dbesc($profile["network"])); - - // 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)); + 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) 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` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0", dbesc(normalise_link($url))); // Fetch the data from the gcontact table 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` - FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($url))); 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. // "birthday" might contain the birthday including the year of birth. diff --git a/mod/dirfind.php b/mod/dirfind.php index f193a5c45c..f6f50f65c0 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -64,16 +64,15 @@ function dirfind_content(&$a, $prefix = "") { $objresult->tags = ""; $objresult->network = $user_data["network"]; - $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", - dbesc(normalise_link($user_data["url"])), intval(local_user())); - if ($contact) - $objresult->cid = $contact[0]["id"]; - + $contact = get_contact_details_by_url($user_data["url"], local_user()); + $objresult->cid = $contact["cid"]; $j->results[] = $objresult; - poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"], - "", "", "", "", "", datetime_convert(), 0); + // Add the contact to the global contacts if it isn't already in our system + 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) { if ($community) @@ -98,6 +97,7 @@ function dirfind_content(&$a, $prefix = "") { $count = q("SELECT count(*) AS `total` FROM `gcontact` LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` + AND `contact`.`network` = `gcontact`.`network` AND `contact`.`uid` = %d AND NOT `contact`.`blocked` 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 @@ -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` FROM `gcontact` LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` + AND `contact`.`network` = `gcontact`.`network` AND `contact`.`uid` = %d AND NOT `contact`.`blocked` 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 From 09fbcbc685bc20d1cc123fbabc99805986e7070f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 12 Jun 2016 12:06:15 +0200 Subject: [PATCH 2/2] Just some added todo --- include/dfrn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dfrn.php b/include/dfrn.php index a974056e65..fb8df2faf8 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1596,6 +1596,7 @@ class dfrn { return false; // update items + /// @todo This is an extreme performance killer $fields = array( 'owner-link' => array($old["url"], $relocate["url"]), 'author-link' => array($old["url"], $relocate["url"]),