]> git.mxchange.org Git - friendica.git/commitdiff
Add current tab parameter to Model\Profile::getTabs
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 May 2019 19:09:33 +0000 (15:09 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 May 2019 19:09:33 +0000 (15:09 -0400)
mod/cal.php
mod/events.php
mod/notes.php
mod/photos.php
mod/videos.php
src/Model/Profile.php
src/Module/Profile.php
src/Module/Profile/Contacts.php

index 3f3cba466f5d8cbc5c63f55ab6cc3809daa917ac..0a2a02e53c49e1613b8c02c6702c34aeb3f6afe6 100644 (file)
@@ -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') {
index 6569653a063f01779e411c2f84a696a7632e2a62..8e9606b203cb8e15b236a6c45f28e494ab409635 100644 (file)
@@ -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';
index fdb12d6cc5a6d0300aabe03671fad0759f69499e..1f67e486d6a6d06ab98bddb4116dd70874575611 100644 (file)
@@ -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 .= '<h3>' . L10n::t('Personal Notes') . '</h3>';
index 7c0ca1b7badc4465b7276052100ad6530a8db8cf..61f1b795301836f96687f3bbc38d8d27d974bf91 100644 (file)
@@ -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') {
index 3fb36a73e4d319e20b04d8d634c03e3e44cf4436..9e19ecf11744d4d53da9b6d163095007919b2e52 100644 (file)
@@ -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
index 38f5c036231b0ae6d610e2de988698c819dd3e15..9068943dfe17dc0e58b65e012ced357db0eecfe0 100644 (file)
@@ -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');
index fceea726b4cfe863d203673dbf11095810c0595b..1a515073ddd845adde68edbeac15dcabf3fbcf50 100644 (file)
@@ -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);
index 340c9ef19ce046e9e58cdd3ae846c831af7e2af2..9e6d7d6b2b66e4d5f847c9984859a4431caca5e4 100644 (file)
@@ -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);