From: Hypolite Petovan Date: Mon, 20 May 2019 19:09:33 +0000 (-0400) Subject: Add current tab parameter to Model\Profile::getTabs X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c65faecc8c88c708e42e9ca686a23bbb34c5bf5a;p=friendica.git Add current tab parameter to Model\Profile::getTabs --- diff --git a/mod/cal.php b/mod/cal.php index 3f3cba466f..0a2a02e53c 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 6569653a06..8e9606b203 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 fdb12d6cc5..1f67e486d6 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 7c0ca1b7ba..61f1b79530 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 3fb36a73e4..9e19ecf117 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 38f5c03623..9068943dfe 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 fceea726b4..1a515073dd 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 340c9ef19c..9e6d7d6b2b 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);