From 748a0ca21b34987e62a00512f90a9f5a159d2e19 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 2 Mar 2019 09:28:37 -0500 Subject: [PATCH] Fix allow_cid variable type in mod/network - Improve SQL query for network contacts - Add missing query statement closure - Addresses https://github.com/friendica/friendica/issues/6337#issuecomment-467111446 --- mod/network.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/mod/network.php b/mod/network.php index b5c218de2..cdc887c2a 100644 --- a/mod/network.php +++ b/mod/network.php @@ -539,20 +539,28 @@ function networkThreadedView(App $a, $update, $parent) $order = Strings::escapeTags(defaults($_GET, 'order', 'comment')); $nets = defaults($_GET, 'nets' , ''); + $allowedCids = []; if ($cid) { - $default_permissions['allow_cid'] = [(int) $cid]; + $allowedCids[] = (int) $cid; + } elseif ($nets) { + $condition = [ + 'uid' => local_user(), + 'network' => $nets, + 'self' => false, + 'blocked' => false, + 'pending' => false, + 'archive' => false, + 'rel' => [Contact::SHARING, Contact::FRIEND], + ]; + $contactStmt = DBA::select('contact', ['id'], $condition); + while ($contact = DBA::fetch($contactStmt)) { + $allowedCids[] = (int) $contact['id']; + } + DBA::close($contactStmt); } - if ($nets) { - $r = DBA::select('contact', ['id'], ['uid' => local_user(), 'network' => $nets], ['self' => false]); - - $str = []; - while ($rr = DBA::fetch($r)) { - $str[] = (int) $rr['id']; - } - if (strlen($str)) { - $default_permissions['allow_cid'] = $str; - } + if (count($allowedCids)) { + $default_permissions['allow_cid'] = $allowedCids; } if (!$update && !$rawmode) {