From a8b6052c5a84ed84287660490651369a96bf50b6 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 22 Nov 2017 09:02:55 -0500 Subject: [PATCH 1/7] Contact Standards Some updates for Contact --- src/Object/Contact.php | 52 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 876083971c..b10c9a16d5 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -21,12 +21,15 @@ use dba; require_once 'boot.php'; require_once 'include/text.php'; +/** + * @brief functions for interacting with a contact + */ class Contact extends BaseObject { /** * @brief Marks a contact for removal * - * @param int $id + * @param int $id contact id * @return null */ public static function remove($id) @@ -56,7 +59,7 @@ class Contact extends BaseObject /** * @brief Sends an unfriend message. Does not remove the contact * - * @param array $user User unfriending + * @param array $user User unfriending * @param array $contact Contact unfriended */ public static function terminateFriendship(array $user, array $contact) @@ -88,7 +91,7 @@ class Contact extends BaseObject * This provides for the possibility that their database is temporarily messed * up or some other transient event and that there's a possibility we could recover from it. * - * @param array $contact + * @param array $contact contact to mark for archival * @return type */ public static function markForArchival(array $contact) @@ -110,7 +113,6 @@ class Contact extends BaseObject ); } } else { - /* @todo * We really should send a notification to the owner after 2-3 weeks * so they won't be surprised when the contact vanishes and can take @@ -120,7 +122,6 @@ class Contact extends BaseObject /// @todo Check for contact vitality via probing $expiry = $contact['term-date'] . ' + 32 days '; if (datetime_convert() > datetime_convert('UTC', 'UTC', $expiry)) { - /* Relationship is really truly dead. archive them rather than * delete, though if the owner tries to unarchive them we'll start * the whole process over again. @@ -143,7 +144,7 @@ class Contact extends BaseObject * * @see Contact::markForArchival() * - * @param array $contact + * @param array $contact contact to be unmarked for archival * @return null */ public static function unmarkForArchival(array $contact) @@ -172,9 +173,9 @@ class Contact extends BaseObject * The function looks at several places (contact table and gcontact table) for the contact * It caches its result for the same script execution to prevent duplicate calls * - * @param string $url The profile link - * @param int $uid User id - * @param array $default If not data was found take this data as default value + * @param string $url The profile link + * @param int $uid User id + * @param array $default If not data was found take this data as default value * * @return array Contact data */ @@ -237,7 +238,7 @@ class Contact extends BaseObject 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) { + foreach ($r as $id => $result) { if ($result["network"] == NETWORK_STATUSNET) { unset($r[$id]); } @@ -291,8 +292,9 @@ class Contact extends BaseObject $profile["micro"] = $profile["thumb"]; } - if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) && - in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { + if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) + && in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) + ) { Worker::add(PRIORITY_LOW, "UpdateGContact", $profile["gid"]); } @@ -315,7 +317,7 @@ class Contact extends BaseObject * The function looks at several places (contact table and gcontact table) for the contact * * @param string $addr The profile link - * @param int $uid User id + * @param int $uid User id * * @return array Contact data */ @@ -362,8 +364,8 @@ class Contact extends BaseObject /** * @brief Returns the data array for the photo menu of a given contact * - * @param array $contact - * @param int $uid + * @param array $contact contact + * @param int $uid optional, default 0 * @return array */ public static function photoMenu(array $contact, $uid = 0) @@ -386,7 +388,7 @@ class Contact extends BaseObject if ($contact['uid'] != $uid) { if ($uid == 0) { $profile_link = zrl($contact['url']); - $menu = Array('profile' => array(t('View Profile'), $profile_link, true)); + $menu = array('profile' => array(t('View Profile'), $profile_link, true)); return $menu; } @@ -438,7 +440,7 @@ class Contact extends BaseObject $contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1'; /** - * menu array: + * Menu array: * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ] */ $menu = array( @@ -459,7 +461,7 @@ class Contact extends BaseObject $menucondensed = array(); - foreach ($menu AS $menuname => $menuitem) { + foreach ($menu as $menuname => $menuitem) { if ($menuitem[1] != '') { $menucondensed[$menuname] = $menuitem; } @@ -469,14 +471,15 @@ class Contact extends BaseObject } /** + * @brief Returns ungrouped contact count or list for user + * * Returns either the total number of ungrouped contacts for the given user * id or a paginated list of ungrouped contacts. * - * @brief Returns ungrouped contact count or list for user + * @param int $uid uid + * @param int $start optional, default 0 + * @param int $count optional, default 0 * - * @param int $uid - * @param int $start - * @param int $count * @return array */ public static function getUngroupedList($uid, $start = 0, $count = 0) @@ -532,8 +535,8 @@ class Contact extends BaseObject * Fourth, we update the existing record with the new data (avatar, alias, nick) * if there's any updates * - * @param string $url Contact URL - * @param integer $uid The user id for the contact (0 = public contact) + * @param string $url Contact URL + * @param integer $uid The user id for the contact (0 = public contact) * @param boolean $no_update Don't update the contact * * @return integer Contact ID @@ -735,7 +738,6 @@ class Contact extends BaseObject /** * @brief Returns posts from a given contact url * - * @param App $a argv application class * @param string $contact_url Contact URL * * @return string posts in HTML From c25578a2e2ffd8a311f25c3f08e96f62af233983 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 22 Nov 2017 16:29:47 -0500 Subject: [PATCH 2/7] Cleanup Clean up messy commits. --- src/Object/Contact.php | 80 +++++++++++++----------------------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index b10c9a16d5..ffa71be27d 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -35,18 +35,16 @@ class Contact extends BaseObject public static function remove($id) { // We want just to make sure that we don't delete our "self" contact - $r = q( - "SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1", intval($id) - ); + $condition = array('`id` = ? AND NOT `self`', $id); + $r = dba::select('contact', array('uid'), $condition, array('limit' => 1)); + if (!DBM::is_result($r) || !intval($r[0]['uid'])) { return; } $archive = PConfig::get($r[0]['uid'], 'system', 'archive_removed_contacts'); if ($archive) { - q( - "UPDATE `contact` SET `archive` = 1, `network` = 'none', `writable` = 0 WHERE id = %d", intval($id) - ); + dba::update('contact', array('archive' => 1, 'network' => 'none', 'writable' => 0), array('id' => $id)); return; } @@ -102,15 +100,10 @@ class Contact extends BaseObject } if ($contact['term-date'] <= NULL_DATE) { - q( - "UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id']) - ); + dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id'])); if ($contact['url'] != '') { - q( - "UPDATE `contact` SET `term-date` = '%s' - WHERE `nurl` = '%s' AND `term-date` <= '1000-00-00'", dbesc(datetime_convert()), dbesc(normalise_link($contact['url'])) - ); + dba::update('contact', array('term-date' => datetime_convert()), array('nurl' => normalise_link($contact['url']), 'term-date' <= NULL_DATE)); } } else { /* @todo @@ -126,14 +119,10 @@ class Contact extends BaseObject * delete, though if the owner tries to unarchive them we'll start * the whole process over again. */ - q( - "UPDATE `contact` SET `archive` = 1 WHERE `id` = %d", intval($contact['id']) - ); + dba::update('contact', array('archive' => 1), array('id' => $contact['id'])); if ($contact['url'] != '') { - q( - "UPDATE `contact` SET `archive` = 1 WHERE `nurl` = '%s'", dbesc(normalise_link($contact['url'])) - ); + dba::update('contact', array('archive' => 1), array('nurl' => normalise_link($contact['url']))); } } } @@ -149,9 +138,8 @@ class Contact extends BaseObject */ public static function unmarkForArchival(array $contact) { - $r = q( - "SELECT `term-date` FROM `contact` WHERE `id` = %d AND (`term-date` > '%s' OR `archive`)", intval($contact['id']), dbesc('1000-00-00 00:00:00') - ); + $condition = array('`id` => ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE); + $r = dba::select('contact', array('term-date'), $condition); // We don't need to update, we never marked this contact for archival if (!DBM::is_result($r)) { @@ -393,7 +381,7 @@ class Contact extends BaseObject return $menu; } - $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `network` = '%s' AND `uid` = %d", dbesc($contact['nurl']), dbesc($contact['network']), intval($uid)); + $r = dba::select('contact', array(), array('nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid)); if ($r) { return self::photoMenu($r[0], $uid); } else { @@ -485,34 +473,15 @@ class Contact extends BaseObject public static function getUngroupedList($uid, $start = 0, $count = 0) { if (!$count) { - $r = q( - "SELECT COUNT(*) AS `total` - FROM `contact` - WHERE `uid` = %d - AND `self` = 0 - AND `id` NOT IN ( - SELECT DISTINCT(`contact-id`) - FROM `group_member` - WHERE `uid` = %d - ) ", intval($uid), intval($uid) - ); + $fields = array('COUNT(*) AS `total`'); + $condition = array('`uid` = ? AND `self` = 0 AND `id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid, $uid); + $r = dba::select('contact', $fields, $condition); return $r; } - $r = q( - "SELECT * - FROM `contact` - WHERE `uid` = %d - AND `self` = 0 - AND `id` NOT IN ( - SELECT DISTINCT(`contact-id`) - FROM `group_member` WHERE `uid` = %d - ) - AND `blocked` = 0 - AND `pending` = 0 - LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count) - ); + $innerCondition = array('`id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid); + $r = dba::select('contact', array(), array('uid' => $uid, 'self' => 0, $innerCondition, 'blocked' => 0, 'pending' => 0), array('limit ?, ?', $start, $count)); return $r; } @@ -564,7 +533,7 @@ class Contact extends BaseObject 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); - $r = dba::p("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ? LIMIT 1", $url, normalise_link($url), $ssl_url, $uid); + $r = dba::select('contact', array('id', 'avatar-date'), array('`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid), array('limit' => 1)); $contact = dba::fetch($r); dba::close($r); } @@ -611,7 +580,8 @@ class Contact extends BaseObject $url = $data["url"]; if (!$contact_id) { - dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"], + dba::insert( + 'contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"], 'nurl' => normalise_link($data["url"]), 'addr' => $data["addr"], 'alias' => $data["alias"], 'notify' => $data["notify"], 'poll' => $data["poll"], 'name' => $data["name"], 'nick' => $data["nick"], 'photo' => $data["photo"], @@ -622,9 +592,11 @@ class Contact extends BaseObject 'confirm' => $data["confirm"], 'poco' => $data["poco"], 'name-date' => datetime_convert(), 'uri-date' => datetime_convert(), 'avatar-date' => datetime_convert(), 'writable' => 1, 'blocked' => 0, - 'readonly' => 0, 'pending' => 0)); + 'readonly' => 0, 'pending' => 0) + ); - $contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2", dbesc(normalise_link($data["url"])), intval($uid)); + $s = dba::select('contact', array('id'), array('nurl' => normalise_link($data["url"]), 'uid' => $uid), array('order' => 'id', 'limit' => 2)); + $contacts = dba::inArray($s); if (!DBM::is_result($contacts)) { return 0; } @@ -748,8 +720,7 @@ class Contact extends BaseObject // There are no posts with "uid = 0" with connector networks // This speeds up the query a lot - $r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact` - WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0", dbesc(normalise_link($contact_url))); + $r = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0)); if (!DBM::is_result($r)) { return ''; @@ -792,8 +763,7 @@ class Contact extends BaseObject // "page-flags" is a field in the user table, // "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP. // "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP. - if ( - (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY)) + if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY)) || (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP)) || (isset($contact['forum']) && intval($contact['forum'])) || (isset($contact['prv']) && intval($contact['prv'])) From f5d682fe0ace90a0ede89fe5d1fe9f3e051ef3a9 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 22 Nov 2017 23:13:12 -0500 Subject: [PATCH 3/7] Review updates Updates based on review. --- src/Object/Contact.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index ffa71be27d..9fceb927af 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -38,11 +38,11 @@ class Contact extends BaseObject $condition = array('`id` = ? AND NOT `self`', $id); $r = dba::select('contact', array('uid'), $condition, array('limit' => 1)); - if (!DBM::is_result($r) || !intval($r[0]['uid'])) { + if (!DBM::is_result($r) || !intval($r['uid'])) { return; } - $archive = PConfig::get($r[0]['uid'], 'system', 'archive_removed_contacts'); + $archive = PConfig::get($r['uid'], 'system', 'archive_removed_contacts'); if ($archive) { dba::update('contact', array('archive' => 1, 'network' => 'none', 'writable' => 0), array('id' => $id)); return; @@ -59,6 +59,7 @@ class Contact extends BaseObject * * @param array $user User unfriending * @param array $contact Contact unfriended + * @return void */ public static function terminateFriendship(array $user, array $contact) { @@ -383,7 +384,7 @@ class Contact extends BaseObject $r = dba::select('contact', array(), array('nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid)); if ($r) { - return self::photoMenu($r[0], $uid); + return self::photoMenu(dba::fetch($r), $uid); } else { $profile_link = zrl($contact['url']); $connlnk = 'follow/?url=' . $contact['url']; @@ -477,13 +478,13 @@ class Contact extends BaseObject $condition = array('`uid` = ? AND `self` = 0 AND `id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid, $uid); $r = dba::select('contact', $fields, $condition); - return $r; + return dba::inArray($r); } $innerCondition = array('`id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid); $r = dba::select('contact', array(), array('uid' => $uid, 'self' => 0, $innerCondition, 'blocked' => 0, 'pending' => 0), array('limit ?, ?', $start, $count)); - return $r; + return dba::inArray($r); } /** @@ -720,21 +721,22 @@ class Contact extends BaseObject // There are no posts with "uid = 0" with connector networks // This speeds up the query a lot - $r = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0)); + $s = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0)); + $r = dba::inArray($s); if (!DBM::is_result($r)) { return ''; } - if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) { + if (in_array($r["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) { $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND NOT `item`.`global`))"; } else { $sql = "`item`.`uid` = %d"; } - $author_id = intval($r[0]["author-id"]); + $author_id = intval($r["author-id"]); - $contact = ($r[0]["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); + $contact = ($r["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); $r = q(item_query() . " AND `item`.`" . $contact . "` = %d AND " . $sql . " ORDER BY `item`.`created` DESC LIMIT %d, %d", intval($author_id), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']) From 9409010d2d87e02f74d5567a1ba4c2e72120d584 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 22 Nov 2017 23:32:24 -0500 Subject: [PATCH 4/7] Review dba updates updates based on review comments. --- src/Object/Contact.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 9fceb927af..81368bcb28 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -382,9 +382,9 @@ class Contact extends BaseObject return $menu; } - $r = dba::select('contact', array(), array('nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid)); + $r = dba::select('contact', array(), array('nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid), array('limit' => 1)); if ($r) { - return self::photoMenu(dba::fetch($r), $uid); + return self::photoMenu($r, $uid); } else { $profile_link = zrl($contact['url']); $connlnk = 'follow/?url=' . $contact['url']; @@ -721,8 +721,7 @@ class Contact extends BaseObject // There are no posts with "uid = 0" with connector networks // This speeds up the query a lot - $s = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0)); - $r = dba::inArray($s); + $r = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0), array('limit' => 1)); if (!DBM::is_result($r)) { return ''; From 6ea8b0441ba45ec81b4cd5cde3751971fdad2109 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 23 Nov 2017 08:15:38 -0500 Subject: [PATCH 5/7] More Review put back some q( calls and change some integer to boolean --- src/Object/Contact.php | 55 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 81368bcb28..50981659b2 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -35,8 +35,7 @@ class Contact extends BaseObject public static function remove($id) { // We want just to make sure that we don't delete our "self" contact - $condition = array('`id` = ? AND NOT `self`', $id); - $r = dba::select('contact', array('uid'), $condition, array('limit' => 1)); + $r = dba::select('contact', array('uid'), array('id' => $id, 'self' => false), array('limit' => 1)); if (!DBM::is_result($r) || !intval($r['uid'])) { return; @@ -44,7 +43,7 @@ class Contact extends BaseObject $archive = PConfig::get($r['uid'], 'system', 'archive_removed_contacts'); if ($archive) { - dba::update('contact', array('archive' => 1, 'network' => 'none', 'writable' => 0), array('id' => $id)); + dba::update('contact', array('archive' => true, 'network' => 'none', 'writable' => false), array('id' => $id)); return; } @@ -104,7 +103,7 @@ class Contact extends BaseObject dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id'])); if ($contact['url'] != '') { - dba::update('contact', array('term-date' => datetime_convert()), array('nurl' => normalise_link($contact['url']), 'term-date' <= NULL_DATE)); + dba::update('contact', array('term-date' => datetime_convert()), array('`nurl` = ? AND `term-date` <= 1000-00-00', normalise_link($contact['url']))); } } else { /* @todo @@ -140,10 +139,10 @@ class Contact extends BaseObject public static function unmarkForArchival(array $contact) { $condition = array('`id` => ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE); - $r = dba::select('contact', array('term-date'), $condition); + $exists = dba::exists('contact', $condition); // We don't need to update, we never marked this contact for archival - if (!DBM::is_result($r)) { + if (!$exists) { return; } @@ -474,17 +473,36 @@ class Contact extends BaseObject public static function getUngroupedList($uid, $start = 0, $count = 0) { if (!$count) { - $fields = array('COUNT(*) AS `total`'); - $condition = array('`uid` = ? AND `self` = 0 AND `id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid, $uid); - $r = dba::select('contact', $fields, $condition); - - return dba::inArray($r); + $r = q( + "SELECT COUNT(*) AS `total` + FROM `contact` + WHERE `uid` = %d + AND `self` = 0 + AND `id` NOT IN ( + SELECT DISTINCT(`contact-id`) + FROM `group_member` + WHERE `uid` = %d + ) ", intval($uid), intval($uid) + ); + + return $r; } - $innerCondition = array('`id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` WHERE `uid` = ?', $uid); - $r = dba::select('contact', array(), array('uid' => $uid, 'self' => 0, $innerCondition, 'blocked' => 0, 'pending' => 0), array('limit ?, ?', $start, $count)); + $r = q( + "SELECT * + FROM `contact` + WHERE `uid` = %d + AND `self` = 0 + AND `id` NOT IN ( + SELECT DISTINCT(`contact-id`) + FROM `group_member` WHERE `uid` = %d + ) + AND `blocked` = 0 + AND `pending` = 0 + LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count) + ); - return dba::inArray($r); + return $r; } /** @@ -721,21 +739,22 @@ class Contact extends BaseObject // There are no posts with "uid = 0" with connector networks // This speeds up the query a lot - $r = dba::select('contact', array('network', 'id AS author-id', 'contact-type'), array('nurl' => normalise_link($contact_url), 'uid' => 0), array('limit' => 1)); + $r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact` + WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0", dbesc(normalise_link($contact_url))); if (!DBM::is_result($r)) { return ''; } - if (in_array($r["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) { + if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) { $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND NOT `item`.`global`))"; } else { $sql = "`item`.`uid` = %d"; } - $author_id = intval($r["author-id"]); + $author_id = intval($r[0]["author-id"]); - $contact = ($r["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); + $contact = ($r[0]["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); $r = q(item_query() . " AND `item`.`" . $contact . "` = %d AND " . $sql . " ORDER BY `item`.`created` DESC LIMIT %d, %d", intval($author_id), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']) From 130e02ddef74ef10ff3a0864a40bf0485ba0daf5 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 23 Nov 2017 19:22:30 -0500 Subject: [PATCH 6/7] Review null_date and spaces at end of line --- src/Object/Contact.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 50981659b2..d799a7d892 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -103,7 +103,7 @@ class Contact extends BaseObject dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id'])); if ($contact['url'] != '') { - dba::update('contact', array('term-date' => datetime_convert()), array('`nurl` = ? AND `term-date` <= 1000-00-00', normalise_link($contact['url']))); + dba::update('contact', array('term-date' => datetime_convert()), array('`nurl` = ? AND `term-date` <= ?', normalise_link($contact['url']), NULL_DATE)); } } else { /* @todo @@ -484,7 +484,7 @@ class Contact extends BaseObject WHERE `uid` = %d ) ", intval($uid), intval($uid) ); - + return $r; } @@ -501,7 +501,7 @@ class Contact extends BaseObject AND `pending` = 0 LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count) ); - + return $r; } From 9df0457340b6497ccc2ccce0f99f18bb9274f9e0 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 23 Nov 2017 20:59:00 -0500 Subject: [PATCH 7/7] whitespace remove whitespace --- src/Object/Contact.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index d799a7d892..fff82e600d 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -501,7 +501,6 @@ class Contact extends BaseObject AND `pending` = 0 LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count) ); - return $r; }