From e6742af65c328a20fba346aa0fea4ffafaac52d1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 18 May 2019 11:44:04 -0400 Subject: [PATCH 1/4] Add contact relationship filter to /contact module --- src/Content/Widget.php | 52 ++++++++++++++++++++++++++++++++++++++---- src/Module/Contact.php | 19 ++++++++++++++- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/Content/Widget.php b/src/Content/Widget.php index b5f83a803..e89245cd2 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -121,17 +121,28 @@ class Widget } /** - * @param string $type + * Display a generic filter widget based on a list of options + * + * The options array must be the following format: + * [ + * [ + * 'ref' => {filter value}, + * 'name' => {option name} + * ], + * ... + * ] + * + * @param string $type The filter query string key * @param string $title * @param string $desc - * @param string $all - * @param string $baseUrl + * @param string $all The no filter label + * @param string $baseUrl The full page request URI * @param array $options - * @param string $selected + * @param string $selected The currently selected filter option value * @return string * @throws \Exception */ - public static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null) + private static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null) { $queryString = parse_url($baseUrl, PHP_URL_QUERY); $queryArray = []; @@ -160,6 +171,37 @@ class Widget ]); } + /** + * Return networks widget + * + * @param string $baseurl baseurl + * @param string $selected optional, default empty + * @return string + * @throws \Exception + */ + public static function contactRels($baseurl, $selected = '') + { + if (!local_user()) { + return ''; + } + + $options = [ + ['ref' => 'followers', 'name' => L10n::t('Followers')], + ['ref' => 'following', 'name' => L10n::t('Following')], + ['ref' => 'mutuals', 'name' => L10n::t('Mutual friends')], + ]; + + return self::filter( + 'rel', + L10n::t('Relationships'), + '', + L10n::t('All Contacts'), + $baseurl, + $options, + $selected + ); + } + /** * Return networks widget * diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 4429573ab..a7f0176e5 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -266,6 +266,7 @@ class Contact extends BaseModule $a = self::getApp(); $nets = defaults($_GET, 'nets', ''); + $rel = defaults($_GET, 'rel' , ''); if (empty($a->page['aside'])) { $a->page['aside'] = ''; @@ -321,6 +322,7 @@ class Contact extends BaseModule $findpeople_widget = ''; $follow_widget = ''; $networks_widget = ''; + $rel_widget = ''; } else { $vcard_widget = ''; $findpeople_widget = Widget::findPeople(); @@ -331,6 +333,7 @@ class Contact extends BaseModule } $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); + $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); } if ($contact['uid'] != 0) { @@ -339,7 +342,7 @@ class Contact extends BaseModule $groups_widget = null; } - $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget; + $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; $tpl = Renderer::getMarkupTemplate('contacts-head.tpl'); $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [ @@ -678,6 +681,7 @@ class Contact extends BaseModule $search = Strings::escapeTags(trim(defaults($_GET, 'search', ''))); $nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , ''))); + $rel = Strings::escapeTags(trim(defaults($_GET, 'rel' , ''))); $tabs = [ [ @@ -747,6 +751,12 @@ class Contact extends BaseModule $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets)); } + switch ($rel) { + case 'followers': $sql_extra .= " AND `rel` IN (1, 3)"; break; + case 'following': $sql_extra .= " AND `rel` IN (2, 3)"; break; + case 'mutuals': $sql_extra .= " AND `rel` = 3"; break; + } + $sql_extra .= " AND NOT `deleted` "; $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); @@ -777,6 +787,13 @@ class Contact extends BaseModule } } + switch ($rel) { + case 'followers': $header = L10n::t('Followers'); break; + case 'following': $header = L10n::t('Following'); break; + case 'mutuals': $header = L10n::t('Mutual friends'); break; + default: $header = L10n::t('Contacts'); + } + switch ($type) { case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break; case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break; From 709eba6ce396b7206dd929934361eb5f43003f05 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 18 May 2019 11:47:39 -0400 Subject: [PATCH 2/4] Move /viewcontacts to /profile/{nickname}/contacts[/{type}] - Add contact relationship filter to profile contacts page - Include feed contacts in contacts page and contact widget --- mod/viewcontacts.php | 120 --------------- src/App/Router.php | 1 + src/Content/Widget/ContactBlock.php | 2 +- src/Model/Profile.php | 8 +- src/Module/Profile/Contacts.php | 137 ++++++++++++++++++ src/Protocol/OStatus.php | 2 +- view/templates/profile/contacts.tpl | 20 +++ view/theme/duepuntozero/style.css | 4 - view/theme/frio/css/style.css | 4 +- .../theme/frio/templates/profile/contacts.tpl | 20 +++ view/theme/smoothly/style.css | 4 - 11 files changed, 186 insertions(+), 136 deletions(-) delete mode 100644 mod/viewcontacts.php create mode 100644 src/Module/Profile/Contacts.php create mode 100644 view/templates/profile/contacts.tpl create mode 100644 view/theme/frio/templates/profile/contacts.tpl diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php deleted file mode 100644 index 14919820d..000000000 --- a/mod/viewcontacts.php +++ /dev/null @@ -1,120 +0,0 @@ -argc < 2) { - throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.')); - } - - Nav::setSelected('home'); - - $user = DBA::selectFirst('user', [], ['nickname' => $a->argv[1], 'blocked' => false]); - if (!DBA::isResult($user)) { - throw new \Friendica\Network\HTTPException\NotFoundException(); - } - - $a->data['user'] = $user; - $a->profile_uid = $user['uid']; - - Profile::load($a, $a->argv[1]); -} - -function viewcontacts_content(App $a) -{ - if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { - notice(L10n::t('Public access denied.') . EOL); - return; - } - - $is_owner = $a->profile['profile_uid'] == local_user(); - - // tabs - $o = Profile::getTabs($a, $is_owner, $a->data['user']['nickname']); - - if (!count($a->profile) || $a->profile['hide-friends']) { - notice(L10n::t('Permission denied.') . EOL); - return $o; - } - - $condition = [ - 'uid' => $a->profile['uid'], - 'blocked' => false, - 'pending' => false, - 'hidden' => false, - 'archive' => false, - 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS] - ]; - - $total = DBA::count('contact', $condition); - - $pager = new Pager($a->query_string); - - $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; - - $contacts_stmt = DBA::select('contact', [], $condition, $params); - - if (!DBA::isResult($contacts_stmt)) { - info(L10n::t('No contacts.') . EOL); - return $o; - } - - $contacts = []; - - while ($contact = DBA::fetch($contacts_stmt)) { - /// @TODO This triggers an E_NOTICE if 'self' is not there - if ($contact['self']) { - continue; - } - - $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact); - - $contacts[] = [ - 'id' => $contact['id'], - 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']), - 'photo_menu' => Contact::photoMenu($contact), - 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB), - 'name' => substr($contact_details['name'], 0, 20), - 'username' => $contact_details['name'], - 'details' => $contact_details['location'], - 'tags' => $contact_details['keywords'], - 'about' => $contact_details['about'], - 'account_type' => Contact::getAccountType($contact_details), - 'url' => Contact::magicLink($contact['url']), - 'sparkle' => '', - 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $contact['url']), - 'network' => ContactSelector::networkToName($contact['network'], $contact['url']), - ]; - } - - DBA::close($contacts_stmt); - - $tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl"); - $o .= Renderer::replaceMacros($tpl, [ - '$title' => L10n::t('Contacts'), - '$contacts' => $contacts, - '$paginate' => $pager->renderFull($total), - ]); - - return $o; -} diff --git a/src/App/Router.php b/src/App/Router.php index be81c143d..f7ee24730 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -187,6 +187,7 @@ class Router $this->routeCollector->addRoute(['GET'], '/probe', Module\Debug\Probe::class); $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/{nickname}', Module\Profile::class); + $collector->addRoute(['GET'], '/{nickname}/contacts[/{type}]', Module\Profile\Contacts::class); $collector->addRoute(['GET'], '/{profile:\d+}/view', Module\Profile::class); }); $this->routeCollector->addGroup('/proxy', function (RouteCollector $collector) { diff --git a/src/Content/Widget/ContactBlock.php b/src/Content/Widget/ContactBlock.php index f4fdea2fb..bc33b9c9c 100644 --- a/src/Content/Widget/ContactBlock.php +++ b/src/Content/Widget/ContactBlock.php @@ -52,7 +52,7 @@ class ContactBlock 'pending' => false, 'hidden' => false, 'archive' => false, - 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA], + 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED], ]); $contacts_title = L10n::t('No contacts'); diff --git a/src/Model/Profile.php b/src/Model/Profile.php index a854b1c9e..38f5c0362 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -894,7 +894,7 @@ class Profile [ 'label' => L10n::t('Status'), 'url' => $url, - 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '', + 'sel' => !$tab && $a->argv[0] == 'profile' && (empty($a->argv[2]) || $a->argv[2] !== 'contacts') ? 'active' : '', 'title' => L10n::t('Status Messages and Posts'), 'id' => 'status-tab', 'accesskey' => 'm', @@ -969,11 +969,11 @@ class Profile ]; } - if (!$is_owner && empty($a->profile['hide-friends'])) { + if ($is_owner || empty($a->profile['hide-friends'])) { $tabs[] = [ 'label' => L10n::t('Contacts'), - 'url' => System::baseUrl() . '/viewcontacts/' . $nickname, - 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '', + 'url' => System::baseUrl() . '/profile/' . $nickname . '/contacts', + 'sel' => !$tab && !empty($a->argv[2]) && $a->argv[2] == 'contacts' ? 'active' : '', 'title' => L10n::t('Contacts'), 'id' => 'viewcontacts-tab', 'accesskey' => 'k', diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php new file mode 100644 index 000000000..340c9ef19 --- /dev/null +++ b/src/Module/Profile/Contacts.php @@ -0,0 +1,137 @@ +argv[1]; + $type = defaults($a->argv, 3, 'all'); + + Nav::setSelected('home'); + + $user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]); + if (!DBA::isResult($user)) { + throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.')); + } + + $a->data['user'] = $user; + $a->profile_uid = $user['uid']; + + Profile::load($a, $nickname); + + $is_owner = $a->profile['profile_uid'] == local_user(); + + // tabs + $o = Profile::getTabs($a, $is_owner, $nickname); + + if (!count($a->profile) || $a->profile['hide-friends']) { + notice(L10n::t('Permission denied.') . EOL); + return $o; + } + + $condition = [ + 'uid' => $a->profile['uid'], + 'blocked' => false, + 'pending' => false, + 'hidden' => false, + 'archive' => false, + 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED] + ]; + + switch ($type) { + case 'followers': $condition['rel'] = [1, 3]; break; + case 'following': $condition['rel'] = [2, 3]; break; + case 'mutuals': $condition['rel'] = 3; break; + } + + $total = DBA::count('contact', $condition); + + $pager = new Pager($a->query_string); + + $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; + + $contacts_stmt = DBA::select('contact', [], $condition, $params); + + if (!DBA::isResult($contacts_stmt)) { + info(L10n::t('No contacts.') . EOL); + return $o; + } + + $contacts = []; + + while ($contact = DBA::fetch($contacts_stmt)) { + /// @TODO This triggers an E_NOTICE if 'self' is not there + if ($contact['self']) { + continue; + } + + $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact); + + $contacts[] = [ + 'id' => $contact['id'], + 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']), + 'photo_menu' => Contact::photoMenu($contact), + 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB), + 'name' => substr($contact_details['name'], 0, 20), + 'username' => $contact_details['name'], + 'details' => $contact_details['location'], + 'tags' => $contact_details['keywords'], + 'about' => $contact_details['about'], + 'account_type' => Contact::getAccountType($contact_details), + 'url' => Contact::magicLink($contact['url']), + 'sparkle' => '', + 'itemurl' => $contact_details['addr'] ? : $contact['url'], + 'network' => ContactSelector::networkToName($contact['network'], $contact['url']), + ]; + } + + DBA::close($contacts_stmt); + + switch ($type) { + case 'followers': $title = L10n::tt('Follower (%s)', 'Followers (%s)', $total); break; + case 'following': $title = L10n::tt('Following (%s)', 'Following (%s)', $total); break; + case 'mutuals': $title = L10n::tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break; + + case 'all': default: $title = L10n::tt('Contact (%s)', 'Contacts (%s)', $total); break; + } + + $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl'); + $o .= Renderer::replaceMacros($tpl, [ + '$title' => $title, + '$nickname' => $nickname, + '$type' => $type, + + '$all_label' => L10n::t('All contacts'), + '$followers_label' => L10n::t('Followers'), + '$following_label' => L10n::t('Following'), + '$mutuals_label' => L10n::t('Mutual friends'), + + '$contacts' => $contacts, + '$paginate' => $pager->renderFull($total), + ]); + + return $o; + } +} diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index dec5c4c80..c7747e8cf 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1515,7 +1515,7 @@ class OStatus $author->appendChild($urls); } - XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]); + XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]); XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]); if ($profile["publish"]) { diff --git a/view/templates/profile/contacts.tpl b/view/templates/profile/contacts.tpl new file mode 100644 index 000000000..4e78a7a7f --- /dev/null +++ b/view/templates/profile/contacts.tpl @@ -0,0 +1,20 @@ +
+ {{include file="section_title.tpl"}} + + + +
+{{foreach $contacts as $contact}} + {{include file="contact_template.tpl"}} +{{/foreach}} +
+
+
+ + {{$paginate nofilter}} +
diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index f586d6e04..7e66570ad 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -680,10 +680,6 @@ input#dfrn-url { clear: both; } - -#viewcontacts { - margin-top: 15px; -} #profile-edit-default-desc { color: #FF0000; border: 1px solid #FF8888; diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 4a7262835..2a5706c85 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2317,7 +2317,7 @@ ul.dropdown-menu li:hover { .manage-content-wrapper, .notes-content-wrapper, .message-content-wrapper, .apps-content-wrapper, #adminpage, .delegate-content-wrapper, .uexport-content-wrapper, -.viewcontacts-content-wrapper, .dfrn_request-content-wrapper, +.dfrn_request-content-wrapper, .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper, .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper, .fsuggest-content-wrapper { @@ -3547,7 +3547,7 @@ section .profile-match-wrapper { right: 10px; } - .generic-page-wrapper, .profile_photo-content-wrapper, .videos-content-wrapper, .suggest-content-wrapper, .common-content-wrapper, .help-content-wrapper, .allfriends-content-wrapper, .match-content-wrapper, .dirfind-content-wrapper, .directory-content-wrapper, .manage-content-wrapper, .notes-content-wrapper, .message-content-wrapper, .apps-content-wrapper, #adminpage, .delegate-content-wrapper, .uexport-content-wrapper, .viewcontacts-content-wrapper, .dfrn_request-content-wrapper, .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper, .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper, .fsuggest-content-wrapper { + .generic-page-wrapper, .profile_photo-content-wrapper, .videos-content-wrapper, .suggest-content-wrapper, .common-content-wrapper, .help-content-wrapper, .allfriends-content-wrapper, .match-content-wrapper, .dirfind-content-wrapper, .directory-content-wrapper, .manage-content-wrapper, .notes-content-wrapper, .message-content-wrapper, .apps-content-wrapper, #adminpage, .delegate-content-wrapper, .uexport-content-wrapper, .dfrn_request-content-wrapper, .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper, .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper, .fsuggest-content-wrapper { border-radius: 0; padding: 10px; } diff --git a/view/theme/frio/templates/profile/contacts.tpl b/view/theme/frio/templates/profile/contacts.tpl new file mode 100644 index 000000000..69d34d05a --- /dev/null +++ b/view/theme/frio/templates/profile/contacts.tpl @@ -0,0 +1,20 @@ +
+ {{include file="section_title.tpl"}} + + + +
    +{{foreach $contacts as $contact}} +
  • {{include file="contact_template.tpl"}}
  • +{{/foreach}} +
+
+
+ + {{$paginate nofilter}} +
diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index 9bbf00c78..fec5d2bda 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -2834,10 +2834,6 @@ margin-left: 0px; clear: both; } -#viewcontacts { - margin-top: 15px; -} - .contact-entry-wrapper .contact-entry-photo-wrapper { float: left; margin-right: 10px; From c65faecc8c88c708e42e9ca686a23bbb34c5bf5a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 20 May 2019 15:09:33 -0400 Subject: [PATCH 3/4] Add current tab parameter to Model\Profile::getTabs --- mod/cal.php | 2 +- mod/events.php | 2 +- mod/notes.php | 2 +- mod/photos.php | 2 +- mod/videos.php | 2 +- src/Model/Profile.php | 41 ++++++++++++++++++--------------- src/Module/Profile.php | 7 ++---- src/Module/Profile/Contacts.php | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/mod/cal.php b/mod/cal.php index 3f3cba466..0a2a02e53 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -147,7 +147,7 @@ function cal_content(App $a) $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms; // get the tab navigation bar - $tabs = Profile::getTabs($a, false, $a->data['user']['nickname']); + $tabs = Profile::getTabs($a, 'cal', false, $a->data['user']['nickname']); // The view mode part is similiar to /mod/events.php if ($mode == 'view') { diff --git a/mod/events.php b/mod/events.php index 6569653a0..8e9606b20 100644 --- a/mod/events.php +++ b/mod/events.php @@ -246,7 +246,7 @@ function events_content(App $a) $tabs = ''; // tabs if ($a->theme_events_in_profile) { - $tabs = Profile::getTabs($a, true); + $tabs = Profile::getTabs($a, 'events', true); } $mode = 'view'; diff --git a/mod/notes.php b/mod/notes.php index fdb12d6cc..1f67e486d 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -28,7 +28,7 @@ function notes_content(App $a, $update = false) return; } - $o = Profile::getTabs($a, true); + $o = Profile::getTabs($a, 'notes', true); if (!$update) { $o .= '

' . L10n::t('Personal Notes') . '

'; diff --git a/mod/photos.php b/mod/photos.php index 7c0ca1b7b..61f1b7953 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -950,7 +950,7 @@ function photos_content(App $a) // tabs $is_owner = (local_user() && (local_user() == $owner_uid)); - $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']); + $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']); // Display upload form if ($datatype === 'upload') { diff --git a/mod/videos.php b/mod/videos.php index 3fb36a73e..9e19ecf11 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -217,7 +217,7 @@ function videos_content(App $a) // tabs $_is_owner = (local_user() && (local_user() == $owner_uid)); - $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']); + $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']); // // dispatch request diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 38f5c0362..9068943df 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -877,32 +877,35 @@ class Profile return ''; } - public static function getTabs($a, $is_owner = false, $nickname = null) + /** + * @param App $a + * @param string $current + * @param bool $is_owner + * @param string $nickname + * @return string + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function getTabs(App $a, string $current, bool $is_owner, string $nickname = null) { if (is_null($nickname)) { $nickname = $a->user['nickname']; } - $tab = false; - if (!empty($_GET['tab'])) { - $tab = Strings::escapeTags(trim($_GET['tab'])); - } - - $url = System::baseUrl() . '/profile/' . $nickname; + $baseProfileUrl = System::baseUrl() . '/profile/' . $nickname; $tabs = [ [ 'label' => L10n::t('Status'), - 'url' => $url, - 'sel' => !$tab && $a->argv[0] == 'profile' && (empty($a->argv[2]) || $a->argv[2] !== 'contacts') ? 'active' : '', + 'url' => $baseProfileUrl, + 'sel' => !$current ? 'active' : '', 'title' => L10n::t('Status Messages and Posts'), 'id' => 'status-tab', 'accesskey' => 'm', ], [ 'label' => L10n::t('Profile'), - 'url' => $url . '/?tab=profile', - 'sel' => $tab == 'profile' ? 'active' : '', + 'url' => $baseProfileUrl . '/?tab=profile', + 'sel' => $current == 'profile' ? 'active' : '', 'title' => L10n::t('Profile Details'), 'id' => 'profile-tab', 'accesskey' => 'r', @@ -910,7 +913,7 @@ class Profile [ 'label' => L10n::t('Photos'), 'url' => System::baseUrl() . '/photos/' . $nickname, - 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '', + 'sel' => $current == 'photos' ? 'active' : '', 'title' => L10n::t('Photo Albums'), 'id' => 'photo-tab', 'accesskey' => 'h', @@ -918,7 +921,7 @@ class Profile [ 'label' => L10n::t('Videos'), 'url' => System::baseUrl() . '/videos/' . $nickname, - 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '', + 'sel' => $current == 'videos' ? 'active' : '', 'title' => L10n::t('Videos'), 'id' => 'video-tab', 'accesskey' => 'v', @@ -930,7 +933,7 @@ class Profile $tabs[] = [ 'label' => L10n::t('Events'), 'url' => System::baseUrl() . '/events', - 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '', + 'sel' => $current == 'events' ? 'active' : '', 'title' => L10n::t('Events and Calendar'), 'id' => 'events-tab', 'accesskey' => 'e', @@ -941,7 +944,7 @@ class Profile $tabs[] = [ 'label' => L10n::t('Events'), 'url' => System::baseUrl() . '/cal/' . $nickname, - 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '', + 'sel' => $current == 'cal' ? 'active' : '', 'title' => L10n::t('Events and Calendar'), 'id' => 'events-tab', 'accesskey' => 'e', @@ -952,7 +955,7 @@ class Profile $tabs[] = [ 'label' => L10n::t('Personal Notes'), 'url' => System::baseUrl() . '/notes', - 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '', + 'sel' => $current == 'notes' ? 'active' : '', 'title' => L10n::t('Only You Can See This'), 'id' => 'notes-tab', 'accesskey' => 't', @@ -972,15 +975,15 @@ class Profile if ($is_owner || empty($a->profile['hide-friends'])) { $tabs[] = [ 'label' => L10n::t('Contacts'), - 'url' => System::baseUrl() . '/profile/' . $nickname . '/contacts', - 'sel' => !$tab && !empty($a->argv[2]) && $a->argv[2] == 'contacts' ? 'active' : '', + 'url' => $baseProfileUrl . '/contacts', + 'sel' => $current == 'contacts' ? 'active' : '', 'title' => L10n::t('Contacts'), 'id' => 'viewcontacts-tab', 'accesskey' => 'k', ]; } - $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs]; + $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs]; Hook::callAll('profile_tabs', $arr); $tpl = Renderer::getMarkupTemplate('common_tabs.tpl'); diff --git a/src/Module/Profile.php b/src/Module/Profile.php index fceea726b..1a515073d 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -178,12 +178,9 @@ class Profile extends BaseModule } if (!$update) { - $tab = false; - if (!empty($_GET['tab'])) { - $tab = Strings::escapeTags(trim($_GET['tab'])); - } + $tab = Strings::escapeTags(trim(defaults($_GET, 'tab', ''))); - $o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']); + $o .= ProfileModel::getTabs($a, $tab, $is_owner, $a->profile['nickname']); if ($tab === 'profile') { $o .= ProfileModel::getAdvanced($a); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 340c9ef19..9e6d7d6b2 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -44,7 +44,7 @@ class Contacts extends BaseModule $is_owner = $a->profile['profile_uid'] == local_user(); // tabs - $o = Profile::getTabs($a, $is_owner, $nickname); + $o = Profile::getTabs($a, 'contacts', $is_owner, $nickname); if (!count($a->profile) || $a->profile['hide-friends']) { notice(L10n::t('Permission denied.') . EOL); From bebff3271b861b82ffc833efc8ded9c101c4a4d4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 20 May 2019 15:10:34 -0400 Subject: [PATCH 4/4] Remove obsolete TODO comment in Module\Profile\Contacts --- src/Module/Profile/Contacts.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 9e6d7d6b2..346622b2e 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -82,7 +82,6 @@ class Contacts extends BaseModule $contacts = []; while ($contact = DBA::fetch($contacts_stmt)) { - /// @TODO This triggers an E_NOTICE if 'self' is not there if ($contact['self']) { continue; }