Add current tab parameter to Model\Profile::getTabs

This commit is contained in:
Hypolite Petovan 2019-05-20 15:09:33 -04:00
parent 709eba6ce3
commit c65faecc8c
8 changed files with 30 additions and 30 deletions

View File

@ -147,7 +147,7 @@ function cal_content(App $a)
$sql_extra = " AND `event`.`cid` = 0 " . $sql_perms; $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
// get the tab navigation bar // 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 // The view mode part is similiar to /mod/events.php
if ($mode == 'view') { if ($mode == 'view') {

View File

@ -246,7 +246,7 @@ function events_content(App $a)
$tabs = ''; $tabs = '';
// tabs // tabs
if ($a->theme_events_in_profile) { if ($a->theme_events_in_profile) {
$tabs = Profile::getTabs($a, true); $tabs = Profile::getTabs($a, 'events', true);
} }
$mode = 'view'; $mode = 'view';

View File

@ -28,7 +28,7 @@ function notes_content(App $a, $update = false)
return; return;
} }
$o = Profile::getTabs($a, true); $o = Profile::getTabs($a, 'notes', true);
if (!$update) { if (!$update) {
$o .= '<h3>' . L10n::t('Personal Notes') . '</h3>'; $o .= '<h3>' . L10n::t('Personal Notes') . '</h3>';

View File

@ -950,7 +950,7 @@ function photos_content(App $a)
// tabs // tabs
$is_owner = (local_user() && (local_user() == $owner_uid)); $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 // Display upload form
if ($datatype === 'upload') { if ($datatype === 'upload') {

View File

@ -217,7 +217,7 @@ function videos_content(App $a)
// tabs // tabs
$_is_owner = (local_user() && (local_user() == $owner_uid)); $_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 // dispatch request

View File

@ -877,32 +877,35 @@ class Profile
return ''; 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)) { if (is_null($nickname)) {
$nickname = $a->user['nickname']; $nickname = $a->user['nickname'];
} }
$tab = false; $baseProfileUrl = System::baseUrl() . '/profile/' . $nickname;
if (!empty($_GET['tab'])) {
$tab = Strings::escapeTags(trim($_GET['tab']));
}
$url = System::baseUrl() . '/profile/' . $nickname;
$tabs = [ $tabs = [
[ [
'label' => L10n::t('Status'), 'label' => L10n::t('Status'),
'url' => $url, 'url' => $baseProfileUrl,
'sel' => !$tab && $a->argv[0] == 'profile' && (empty($a->argv[2]) || $a->argv[2] !== 'contacts') ? 'active' : '', 'sel' => !$current ? 'active' : '',
'title' => L10n::t('Status Messages and Posts'), 'title' => L10n::t('Status Messages and Posts'),
'id' => 'status-tab', 'id' => 'status-tab',
'accesskey' => 'm', 'accesskey' => 'm',
], ],
[ [
'label' => L10n::t('Profile'), 'label' => L10n::t('Profile'),
'url' => $url . '/?tab=profile', 'url' => $baseProfileUrl . '/?tab=profile',
'sel' => $tab == 'profile' ? 'active' : '', 'sel' => $current == 'profile' ? 'active' : '',
'title' => L10n::t('Profile Details'), 'title' => L10n::t('Profile Details'),
'id' => 'profile-tab', 'id' => 'profile-tab',
'accesskey' => 'r', 'accesskey' => 'r',
@ -910,7 +913,7 @@ class Profile
[ [
'label' => L10n::t('Photos'), 'label' => L10n::t('Photos'),
'url' => System::baseUrl() . '/photos/' . $nickname, 'url' => System::baseUrl() . '/photos/' . $nickname,
'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '', 'sel' => $current == 'photos' ? 'active' : '',
'title' => L10n::t('Photo Albums'), 'title' => L10n::t('Photo Albums'),
'id' => 'photo-tab', 'id' => 'photo-tab',
'accesskey' => 'h', 'accesskey' => 'h',
@ -918,7 +921,7 @@ class Profile
[ [
'label' => L10n::t('Videos'), 'label' => L10n::t('Videos'),
'url' => System::baseUrl() . '/videos/' . $nickname, 'url' => System::baseUrl() . '/videos/' . $nickname,
'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '', 'sel' => $current == 'videos' ? 'active' : '',
'title' => L10n::t('Videos'), 'title' => L10n::t('Videos'),
'id' => 'video-tab', 'id' => 'video-tab',
'accesskey' => 'v', 'accesskey' => 'v',
@ -930,7 +933,7 @@ class Profile
$tabs[] = [ $tabs[] = [
'label' => L10n::t('Events'), 'label' => L10n::t('Events'),
'url' => System::baseUrl() . '/events', 'url' => System::baseUrl() . '/events',
'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '', 'sel' => $current == 'events' ? 'active' : '',
'title' => L10n::t('Events and Calendar'), 'title' => L10n::t('Events and Calendar'),
'id' => 'events-tab', 'id' => 'events-tab',
'accesskey' => 'e', 'accesskey' => 'e',
@ -941,7 +944,7 @@ class Profile
$tabs[] = [ $tabs[] = [
'label' => L10n::t('Events'), 'label' => L10n::t('Events'),
'url' => System::baseUrl() . '/cal/' . $nickname, 'url' => System::baseUrl() . '/cal/' . $nickname,
'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '', 'sel' => $current == 'cal' ? 'active' : '',
'title' => L10n::t('Events and Calendar'), 'title' => L10n::t('Events and Calendar'),
'id' => 'events-tab', 'id' => 'events-tab',
'accesskey' => 'e', 'accesskey' => 'e',
@ -952,7 +955,7 @@ class Profile
$tabs[] = [ $tabs[] = [
'label' => L10n::t('Personal Notes'), 'label' => L10n::t('Personal Notes'),
'url' => System::baseUrl() . '/notes', 'url' => System::baseUrl() . '/notes',
'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '', 'sel' => $current == 'notes' ? 'active' : '',
'title' => L10n::t('Only You Can See This'), 'title' => L10n::t('Only You Can See This'),
'id' => 'notes-tab', 'id' => 'notes-tab',
'accesskey' => 't', 'accesskey' => 't',
@ -972,15 +975,15 @@ class Profile
if ($is_owner || empty($a->profile['hide-friends'])) { if ($is_owner || empty($a->profile['hide-friends'])) {
$tabs[] = [ $tabs[] = [
'label' => L10n::t('Contacts'), 'label' => L10n::t('Contacts'),
'url' => System::baseUrl() . '/profile/' . $nickname . '/contacts', 'url' => $baseProfileUrl . '/contacts',
'sel' => !$tab && !empty($a->argv[2]) && $a->argv[2] == 'contacts' ? 'active' : '', 'sel' => $current == 'contacts' ? 'active' : '',
'title' => L10n::t('Contacts'), 'title' => L10n::t('Contacts'),
'id' => 'viewcontacts-tab', 'id' => 'viewcontacts-tab',
'accesskey' => 'k', '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); Hook::callAll('profile_tabs', $arr);
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl'); $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');

View File

@ -178,12 +178,9 @@ class Profile extends BaseModule
} }
if (!$update) { if (!$update) {
$tab = false; $tab = Strings::escapeTags(trim(defaults($_GET, 'tab', '')));
if (!empty($_GET['tab'])) {
$tab = Strings::escapeTags(trim($_GET['tab']));
}
$o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']); $o .= ProfileModel::getTabs($a, $tab, $is_owner, $a->profile['nickname']);
if ($tab === 'profile') { if ($tab === 'profile') {
$o .= ProfileModel::getAdvanced($a); $o .= ProfileModel::getAdvanced($a);

View File

@ -44,7 +44,7 @@ class Contacts extends BaseModule
$is_owner = $a->profile['profile_uid'] == local_user(); $is_owner = $a->profile['profile_uid'] == local_user();
// tabs // tabs
$o = Profile::getTabs($a, $is_owner, $nickname); $o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
if (!count($a->profile) || $a->profile['hide-friends']) { if (!count($a->profile) || $a->profile['hide-friends']) {
notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.') . EOL);