From 2d99e86b12ec004411c1443ec7cf2eb1e0293e74 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 14 Aug 2017 20:17:17 +0000 Subject: [PATCH 1/3] Bugfix for PR 3630: "get_contact_details_by_url" not always returned a value --- include/Contact.php | 9 +++++---- mod/hovercard.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 00c25df83..c7b512cea 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -210,23 +210,24 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self` FROM `contact` WHERE `nurl` = ? AND `uid` = ?", normalise_link($url), $uid); + $r = dba::inArray($s); // Fetch the data from the contact table with "uid=0" (which is filled automatically) - if (!dbm::is_result($s)) + if (!dbm::is_result($r)) $s = dba::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` FROM `contact` WHERE `nurl` = ? AND `uid` = 0", normalise_link($url)); + $r = dba::inArray($s); // Fetch the data from the gcontact table - if (!dbm::is_result($s)) + if (!dbm::is_result($r)) $s = dba::p("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`, '' AS `xmpp`, `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self` FROM `gcontact` WHERE `nurl` = ?", normalise_link($url)); - if (dbm::is_result($s)) { - $r = dba::inArray($s); + if (dbm::is_result($r)) { // If there is more than one entry we filter out the connector networks if (count($r) > 1) { foreach ($r AS $id => $result) { diff --git a/mod/hovercard.php b/mod/hovercard.php index 5c9ef61fc..83306aa11 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -39,7 +39,7 @@ function hovercard_content() { // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for // the contact. So we strip out the contact id from the internal url and look in the contact table for // the real url (nurl) - if(local_user() && strpos($profileurl, "redir/") === 0) { + if (local_user() && strpos($profileurl, "redir/") === 0) { $cid = intval(substr($profileurl, 6)); $r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1)); $profileurl = ($r["nurl"] ? $r["nurl"] : ""); From 4f6f47f71445caceb6fd208f5bb794690d08316f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 14 Aug 2017 20:58:02 +0000 Subject: [PATCH 2/3] Now the bugfix really should work --- include/Contact.php | 9 ++++++--- include/dba.php | 4 ++++ mod/hovercard.php | 1 - 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index c7b512cea..f69454e39 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -213,19 +213,22 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { $r = dba::inArray($s); // Fetch the data from the contact table with "uid=0" (which is filled automatically) - if (!dbm::is_result($r)) + if (!dbm::is_result($r)) { $s = dba::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` FROM `contact` WHERE `nurl` = ? AND `uid` = 0", normalise_link($url)); - $r = dba::inArray($s); + $r = dba::inArray($s); + } // Fetch the data from the gcontact table - if (!dbm::is_result($r)) + if (!dbm::is_result($r)) { $s = dba::p("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`, '' AS `xmpp`, `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self` FROM `gcontact` WHERE `nurl` = ?", normalise_link($url)); + $r = dba::inArray($s); + } if (dbm::is_result($r)) { // If there is more than one entry we filter out the connector networks diff --git a/include/dba.php b/include/dba.php index a7689bc0f..6bb18a0b7 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1338,6 +1338,10 @@ class dba { * @return array Data array */ static public function inArray($stmt, $do_close = true) { + if (is_bool($stmt)) { + return $stmt; + } + $data = array(); while ($row = self::fetch($stmt)) { $data[] = $row; diff --git a/mod/hovercard.php b/mod/hovercard.php index 83306aa11..26c606251 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -52,7 +52,6 @@ function hovercard_content() { // Search for contact data $contact = get_contact_details_by_url($nurl); } - if(!is_array($contact)) return; From 3290ccc779ff70e9a8fb17d438eba9cd6e2f10dc Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 14 Aug 2017 21:46:58 +0000 Subject: [PATCH 3/3] Now some more stuff is fixed --- include/identity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/identity.php b/include/identity.php index 7ce18309b..34c0413df 100644 --- a/include/identity.php +++ b/include/identity.php @@ -49,7 +49,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile); - if (($pdata === false) || (!count($pdata)) && !count($profiledata)) { + if (empty($pdata) && empty($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404;