]> git.mxchange.org Git - friendica.git/blob - src/Module/BaseProfile.php
be38a958377b93c93e09dd17595063b70d41e5d7
[friendica.git] / src / Module / BaseProfile.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\App;
25 use Friendica\BaseModule;
26 use Friendica\Core\Hook;
27 use Friendica\Core\Renderer;
28 use Friendica\DI;
29
30 class BaseProfile extends BaseModule
31 {
32         /**
33          * Returns the HTML for the profile pages tabs
34          *
35          * @param App    $a
36          * @param string $current
37          * @param bool   $is_owner
38          * @param string $nickname
39          * @return string
40          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
41          */
42         public static function getTabsHTML(App $a, string $current, bool $is_owner, string $nickname = null)
43         {
44                 if (is_null($nickname)) {
45                         $nickname = $a->user['nickname'];
46                 }
47
48                 $baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
49
50                 $tabs = [
51                         [
52                                 'label' => DI::l10n()->t('Profile'),
53                                 'url'   => $baseProfileUrl . '/profile',
54                                 'sel'   => $current == 'profile' ? 'active' : '',
55                                 'title' => DI::l10n()->t('Profile Details'),
56                                 'id'    => 'profile-tab',
57                                 'accesskey' => 'r',
58                         ],
59                         [
60                                 'label' => DI::l10n()->t('Status'),
61                                 'url'   => $baseProfileUrl . '/status',
62                                 'sel'   => $current == 'status' ? 'active' : '',
63                                 'title' => DI::l10n()->t('Status Messages and Posts'),
64                                 'id'    => 'status-tab',
65                                 'accesskey' => 'm',
66                         ],
67                         [
68                                 'label' => DI::l10n()->t('Photos'),
69                                 'url'   => DI::baseUrl() . '/photos/' . $nickname,
70                                 'sel'   => $current == 'photos' ? 'active' : '',
71                                 'title' => DI::l10n()->t('Photo Albums'),
72                                 'id'    => 'photo-tab',
73                                 'accesskey' => 'h',
74                         ],
75                         [
76                                 'label' => DI::l10n()->t('Videos'),
77                                 'url'   => DI::baseUrl() . '/videos/' . $nickname,
78                                 'sel'   => $current == 'videos' ? 'active' : '',
79                                 'title' => DI::l10n()->t('Videos'),
80                                 'id'    => 'video-tab',
81                                 'accesskey' => 'v',
82                         ],
83                 ];
84
85                 // the calendar link for the full featured events calendar
86                 if ($is_owner && $a->theme_events_in_profile) {
87                         $tabs[] = [
88                                 'label' => DI::l10n()->t('Events'),
89                                 'url'   => DI::baseUrl() . '/events',
90                                 'sel'   => $current == 'events' ? 'active' : '',
91                                 'title' => DI::l10n()->t('Events and Calendar'),
92                                 'id'    => 'events-tab',
93                                 'accesskey' => 'e',
94                         ];
95                         // if the user is not the owner of the calendar we only show a calendar
96                         // with the public events of the calendar owner
97                 } elseif (!$is_owner) {
98                         $tabs[] = [
99                                 'label' => DI::l10n()->t('Events'),
100                                 'url'   => DI::baseUrl() . '/cal/' . $nickname,
101                                 'sel'   => $current == 'cal' ? 'active' : '',
102                                 'title' => DI::l10n()->t('Events and Calendar'),
103                                 'id'    => 'events-tab',
104                                 'accesskey' => 'e',
105                         ];
106                 }
107
108                 if ($is_owner) {
109                         $tabs[] = [
110                                 'label' => DI::l10n()->t('Personal Notes'),
111                                 'url'   => DI::baseUrl() . '/notes',
112                                 'sel'   => $current == 'notes' ? 'active' : '',
113                                 'title' => DI::l10n()->t('Only You Can See This'),
114                                 'id'    => 'notes-tab',
115                                 'accesskey' => 't',
116                         ];
117                 }
118
119                 if (empty($a->profile['hide-friends'])) {
120                         $tabs[] = [
121                                 'label' => DI::l10n()->t('Contacts'),
122                                 'url'   => $baseProfileUrl . '/contacts',
123                                 'sel'   => $current == 'contacts' ? 'active' : '',
124                                 'title' => DI::l10n()->t('Contacts'),
125                                 'id'    => 'viewcontacts-tab',
126                                 'accesskey' => 'k',
127                         ];
128                 }
129
130                 if (DI::session()->get('new_member') && $is_owner) {
131                         $tabs[] = [
132                                 'label' => DI::l10n()->t('Tips for New Members'),
133                                 'url'   => DI::baseUrl() . '/newmember',
134                                 'sel'   => false,
135                                 'title' => DI::l10n()->t('Tips for New Members'),
136                                 'id'    => 'newmember-tab',
137                         ];
138                 }
139
140                 $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs];
141
142                 Hook::callAll('profile_tabs', $arr);
143
144                 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
145
146                 return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
147         }
148 }