From 05a5e1792d27184d29e0c78fd9c61334232a507e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 10 Apr 2017 22:09:49 -0400 Subject: [PATCH 1/6] Left trim at sign from nicks in ACL --- include/acl_selectors.php | 12 ++++++------ mod/acl.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index f4b644d68..8404c8f4b 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -627,14 +627,14 @@ function acl_lookup(App $a, $out_type = 'json') { dbesc($search), implode("','", $known_contacts) ); - if (dbm::is_result($r)){ + if (dbm::is_result($r)) { foreach ($r as $row) { - // nickname.. $up = parse_url($row['author-link']); - $nick = explode("/",$up['path']); - $nick = $nick[count($nick)-1]; - $nick .= "@".$up['host']; - // /nickname + $nick = explode('/', $up['path']); + // Fix for Mastodon URLs with format https://domain.tld/@nick + $nick = ltrim($nick[count($nick) - 1], '@'); + $nick .= '@' . $up['host']; + $unknow_contacts[] = array( 'type' => 'c', 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), diff --git a/mod/acl.php b/mod/acl.php index 04aa9f50a..9220bc77a 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -1,7 +1,7 @@ Date: Mon, 10 Apr 2017 22:10:05 -0400 Subject: [PATCH 2/6] Add network for unknown contacts in ACL --- include/acl_selectors.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 8404c8f4b..2a435c8e7 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -615,7 +615,7 @@ function acl_lookup(App $a, $out_type = 'json') { function _contact_link($i){ return dbesc($i['link']); } $known_contacts = array_map(_contact_link, $contacts); $unknow_contacts=array(); - $r = q("SELECT `author-avatar`,`author-name`,`author-link` + $r = q("SELECT `author-avatar`,`author-name`,`author-link`, `network` FROM `item` WHERE `parent` = %d AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%') AND `author-link` NOT IN ('%s') @@ -640,7 +640,7 @@ function acl_lookup(App $a, $out_type = 'json') { 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), 'name' => htmlentities($row['author-name']), 'id' => '', - 'network' => 'unknown', + 'network' => $row['network'], 'link' => $row['author-link'], 'nick' => htmlentities($nick), 'forum' => false From 762e8eda7a7d314ce74180831a3f3bfe7b2dbe96 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 11 Apr 2017 02:41:19 -0400 Subject: [PATCH 3/6] Use get_contact_details_by_url for unknown contacts - Fix typo - Fix comment - Fix closure --- include/acl_selectors.php | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 2a435c8e7..4036886c4 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -610,12 +610,18 @@ function acl_lookup(App $a, $out_type = 'json') { $items = array_merge($groups, $contacts); if ($conv_id) { - /* if $conv_id is set, get unknow contacts in thread */ - /* but first get know contacts url to filter them out */ - function _contact_link($i){ return dbesc($i['link']); } - $known_contacts = array_map(_contact_link, $contacts); - $unknow_contacts=array(); - $r = q("SELECT `author-avatar`,`author-name`,`author-link`, `network` + /* + * if $conv_id is set, get unknown contacts in thread + * but first get known contacts url to filter them out + */ + $known_contacts = array_map( + function ($i) { + return dbesc($i['link']); + } + , $contacts); + + $unknown_contacts = array(); + $r = q("SELECT `author-link` FROM `item` WHERE `parent` = %d AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%') AND `author-link` NOT IN ('%s') @@ -625,31 +631,27 @@ function acl_lookup(App $a, $out_type = 'json') { intval($conv_id), dbesc($search), dbesc($search), - implode("','", $known_contacts) + implode("', '", $known_contacts) ); if (dbm::is_result($r)) { foreach ($r as $row) { - $up = parse_url($row['author-link']); - $nick = explode('/', $up['path']); - // Fix for Mastodon URLs with format https://domain.tld/@nick - $nick = ltrim($nick[count($nick) - 1], '@'); - $nick .= '@' . $up['host']; + $contact = get_contact_details_by_url($row['author-link'], 0); - $unknow_contacts[] = array( - 'type' => 'c', - 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), - 'name' => htmlentities($row['author-name']), - 'id' => '', - 'network' => $row['network'], - 'link' => $row['author-link'], - 'nick' => htmlentities($nick), + $unknown_contacts[] = array( + 'type' => 'cu', + 'photo' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), + 'name' => htmlentities($contact['name']), + 'id' => intval($contact['id']), + 'network' => $contact['network'], + 'link' => $contact['url'], + 'nick' => $contact['nick'], 'forum' => false ); } } - $items = array_merge($items, $unknow_contacts); - $tot += count($unknow_contacts); + $items = array_merge($items, $unknown_contacts); + $tot += count($unknown_contacts); } $results = array( From 6b8ad57399e46eef6db713861f74a6fbddf587e8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 11 Apr 2017 21:18:34 -0400 Subject: [PATCH 4/6] Add error handling for missing contacts --- include/acl_selectors.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 4036886c4..0e30ee06e 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -637,16 +637,18 @@ function acl_lookup(App $a, $out_type = 'json') { foreach ($r as $row) { $contact = get_contact_details_by_url($row['author-link'], 0); - $unknown_contacts[] = array( - 'type' => 'cu', - 'photo' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), - 'name' => htmlentities($contact['name']), - 'id' => intval($contact['id']), - 'network' => $contact['network'], - 'link' => $contact['url'], - 'nick' => $contact['nick'], - 'forum' => false - ); + if (count($contact) > 0) { + $unknown_contacts[] = array( + 'type' => 'cu', + 'photo' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), + 'name' => htmlentities($contact['name']), + 'id' => intval($contact['id']), + 'network' => $contact['network'], + 'link' => $contact['url'], + 'nick' => $contact['nick'], + 'forum' => false + ); + } } } From 96b1a00e91e204515e632bc9e8d29c46aedddcbf Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 12 Apr 2017 21:32:06 -0400 Subject: [PATCH 5/6] Fiddling with the unknown contact array values --- include/acl_selectors.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 0e30ee06e..4cc810fb5 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -635,18 +635,18 @@ function acl_lookup(App $a, $out_type = 'json') { ); if (dbm::is_result($r)) { foreach ($r as $row) { - $contact = get_contact_details_by_url($row['author-link'], 0); + $contact = get_contact_details_by_url($row['author-link']); if (count($contact) > 0) { $unknown_contacts[] = array( 'type' => 'cu', 'photo' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), 'name' => htmlentities($contact['name']), - 'id' => intval($contact['id']), + 'id' => intval($contact['cid']), 'network' => $contact['network'], 'link' => $contact['url'], - 'nick' => $contact['nick'], - 'forum' => false + 'nick' => $contact['nick'] ? : $contact['addr'], + 'forum' => $contact['forum'] ); } } From bffd3f230470f435ccd3b1eb810c166dbc90125f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 13 Apr 2017 18:33:40 -0400 Subject: [PATCH 6/6] Add htmlentities to protect nick/addr in acl_lookup --- include/acl_selectors.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 4cc810fb5..9c3eab58b 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -639,13 +639,13 @@ function acl_lookup(App $a, $out_type = 'json') { if (count($contact) > 0) { $unknown_contacts[] = array( - 'type' => 'cu', + 'type' => 'c', 'photo' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), 'name' => htmlentities($contact['name']), 'id' => intval($contact['cid']), 'network' => $contact['network'], 'link' => $contact['url'], - 'nick' => $contact['nick'] ? : $contact['addr'], + 'nick' => htmlentities($contact['nick'] ? : $contact['addr']), 'forum' => $contact['forum'] ); }