]> git.mxchange.org Git - friendica.git/blob - src/Content/Nav.php
Move L10n::t() calls to DI::l10n()->t() calls
[friendica.git] / src / Content / Nav.php
1 <?php
2 /**
3  * @file src/Content/Nav.php
4  */
5 namespace Friendica\Content;
6
7 use Friendica\App;
8 use Friendica\Core\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\Session;
13 use Friendica\Database\DBA;
14 use Friendica\DI;
15 use Friendica\Model\Profile;
16 use Friendica\Model\User;
17
18 class Nav
19 {
20         private static $selected = [
21                 'global'    => null,
22                 'community' => null,
23                 'network'   => null,
24                 'home'      => null,
25                 'profiles'  => null,
26                 'introductions' => null,
27                 'notifications' => null,
28                 'messages'  => null,
29                 'directory' => null,
30                 'settings'  => null,
31                 'contacts'  => null,
32                 'delegation'=> null,
33                 'events'    => null,
34                 'register'  => null
35         ];
36
37         /**
38          * An array of HTML links provided by addons providing a module via the app_menu hook
39          *
40          * @var array
41          */
42         private static $app_menu = null;
43
44         /**
45          * Set a menu item in navbar as selected
46          *
47          * @param string $item
48          */
49         public static function setSelected($item)
50         {
51                 self::$selected[$item] = 'selected';
52         }
53
54         /**
55          * Build page header and site navigation bars
56          *
57          * @param  App    $a
58          * @return string
59          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
60          */
61         public static function build(App $a)
62         {
63                 // Placeholder div for popup panel
64                 $nav = '<div id="panel" style="display: none;"></div>';
65
66                 $nav_info = self::getInfo($a);
67
68                 $tpl = Renderer::getMarkupTemplate('nav.tpl');
69
70                 $nav .= Renderer::replaceMacros($tpl, [
71                         '$sitelocation' => $nav_info['sitelocation'],
72                         '$nav'          => $nav_info['nav'],
73                         '$banner'       => $nav_info['banner'],
74                         '$emptynotifications' => DI::l10n()->t('Nothing new here'),
75                         '$userinfo'     => $nav_info['userinfo'],
76                         '$sel'          => self::$selected,
77                         '$apps'         => self::getAppMenu(),
78                         '$clear_notifs' => DI::l10n()->t('Clear notifications'),
79                         '$search_hint'  => DI::l10n()->t('@name, !forum, #tags, content')
80                 ]);
81
82                 Hook::callAll('page_header', $nav);
83
84                 return $nav;
85         }
86
87         /**
88          * Returns the addon app menu
89          *
90          * @return array
91          */
92         public static function getAppMenu()
93         {
94                 if (is_null(self::$app_menu)) {
95                         self::populateAppMenu();
96                 }
97
98                 return self::$app_menu;
99         }
100
101         /**
102          * Fills the apps static variable with apps that require a menu
103          */
104         private static function populateAppMenu()
105         {
106                 self::$app_menu = [];
107
108                 //Don't populate apps_menu if apps are private
109                 $privateapps = Config::get('config', 'private_addons', false);
110                 if (local_user() || !$privateapps) {
111                         $arr = ['app_menu' => self::$app_menu];
112
113                         Hook::callAll('app_menu', $arr);
114
115                         self::$app_menu = $arr['app_menu'];
116                 }
117         }
118
119         /**
120          * Prepares a list of navigation links
121          *
122          * @param  App   $a
123          * @return array Navigation links
124          *    string 'sitelocation' => The webbie (username@site.com)
125          *    array 'nav' => Array of links used in the nav menu
126          *    string 'banner' => Formatted html link with banner image
127          *    array 'userinfo' => Array of user information (name, icon)
128          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
129          */
130         private static function getInfo(App $a)
131         {
132                 $ssl_state = ((local_user()) ? true : false);
133
134                 /*
135                  * Our network is distributed, and as you visit friends some of the
136                  * sites look exactly the same - it isn't always easy to know where you are.
137                  * Display the current site location as a navigation aid.
138                  */
139
140                 $myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
141
142                 $sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
143
144                 // nav links: array of array('href', 'text', 'extra css classes', 'title')
145                 $nav = [];
146
147                 // Display login or logout
148                 $nav['usermenu'] = [];
149                 $userinfo = null;
150
151                 if (Session::isAuthenticated()) {
152                         $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
153                 } else {
154                         $nav['login'] = ['login', DI::l10n()->t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
155                 }
156
157                 if (local_user()) {
158                         // user menu
159                         $nav['usermenu'][] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
160                         $nav['usermenu'][] = ['profile/' . $a->user['nickname'] . '?tab=profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
161                         $nav['usermenu'][] = ['photos/' . $a->user['nickname'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
162                         $nav['usermenu'][] = ['videos/' . $a->user['nickname'], DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')];
163                         $nav['usermenu'][] = ['events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')];
164                         $nav['usermenu'][] = ['notes/', DI::l10n()->t('Personal notes'), '', DI::l10n()->t('Your personal notes')];
165
166                         // user info
167                         $contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
168                         $userinfo = [
169                                 'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'),
170                                 'name' => $a->user['username'],
171                         ];
172                 }
173
174                 // "Home" should also take you home from an authenticated remote profile connection
175                 $homelink = Profile::getMyURL();
176                 if (! $homelink) {
177                         $homelink = Session::get('visitor_home', '');
178                 }
179
180                 if ((DI::module()->getName() != 'home') && (! (local_user()))) {
181                         $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')];
182                 }
183
184                 if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !Session::isAuthenticated()) {
185                         $nav['register'] = ['register', DI::l10n()->t('Register'), '', DI::l10n()->t('Create an account')];
186                 }
187
188                 $help_url = 'help';
189
190                 if (!Config::get('system', 'hide_help')) {
191                         $nav['help'] = [$help_url, DI::l10n()->t('Help'), '', DI::l10n()->t('Help and documentation')];
192                 }
193
194                 if (count(self::getAppMenu()) > 0) {
195                         $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')];
196                 }
197
198                 if (local_user() || !Config::get('system', 'local_search')) {
199                         $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')];
200
201                         $nav['searchoption'] = [
202                                 DI::l10n()->t('Full Text'),
203                                 DI::l10n()->t('Tags'),
204                                 DI::l10n()->t('Contacts')
205                         ];
206
207                         if (Config::get('system', 'poco_local_search')) {
208                                 $nav['searchoption'][] = DI::l10n()->t('Forums');
209                         }
210                 }
211
212                 $gdirpath = 'directory';
213
214                 if (strlen(Config::get('system', 'singleuser'))) {
215                         $gdir = Config::get('system', 'directory');
216                         if (strlen($gdir)) {
217                                 $gdirpath = Profile::zrl($gdir, true);
218                         }
219                 }
220
221                 if ((local_user() || Config::get('system', 'community_page_style') != CP_NO_COMMUNITY_PAGE) &&
222                         !(Config::get('system', 'community_page_style') == CP_NO_INTERNAL_COMMUNITY)) {
223                         $nav['community'] = ['community', DI::l10n()->t('Community'), '', DI::l10n()->t('Conversations on this and other servers')];
224                 }
225
226                 if (local_user()) {
227                         $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
228                 }
229
230                 $nav['directory'] = [$gdirpath, DI::l10n()->t('Directory'), '', DI::l10n()->t('People directory')];
231
232                 $nav['about'] = ['friendica', DI::l10n()->t('Information'), '', DI::l10n()->t('Information about this friendica instance')];
233
234                 if (Config::get('system', 'tosdisplay')) {
235                         $nav['tos'] = ['tos', DI::l10n()->t('Terms of Service'), '', DI::l10n()->t('Terms of Service of this Friendica instance')];
236                 }
237
238                 // The following nav links are only show to logged in users
239                 if (local_user()) {
240                         $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
241
242                         $nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
243
244                         // Don't show notifications for public communities
245                         if (Session::get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
246                                 $nav['introductions'] = ['notifications/intros', DI::l10n()->t('Introductions'), '', DI::l10n()->t('Friend Requests')];
247                                 $nav['notifications'] = ['notifications',       DI::l10n()->t('Notifications'), '', DI::l10n()->t('Notifications')];
248                                 $nav['notifications']['all'] = ['notifications/system', DI::l10n()->t('See all notifications'), '', ''];
249                                 $nav['notifications']['mark'] = ['', DI::l10n()->t('Mark as seen'), '', DI::l10n()->t('Mark all system notifications seen')];
250                         }
251
252                         $nav['messages'] = ['message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')];
253                         $nav['messages']['inbox'] = ['message', DI::l10n()->t('Inbox'), '', DI::l10n()->t('Inbox')];
254                         $nav['messages']['outbox'] = ['message/sent', DI::l10n()->t('Outbox'), '', DI::l10n()->t('Outbox')];
255                         $nav['messages']['new'] = ['message/new', DI::l10n()->t('New Message'), '', DI::l10n()->t('New Message')];
256
257                         if (is_array($a->identities) && count($a->identities) > 1) {
258                                 $nav['delegation'] = ['delegation', DI::l10n()->t('Delegation'), '', DI::l10n()->t('Manage other pages')];
259                         }
260
261                         $nav['settings'] = ['settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
262
263                         if (Feature::isEnabled(local_user(), 'multi_profiles')) {
264                                 $nav['profiles'] = ['profiles', DI::l10n()->t('Profiles'), '', DI::l10n()->t('Manage/Edit Profiles')];
265                         }
266
267                         $nav['contacts'] = ['contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
268                 }
269
270                 // Show the link to the admin configuration page if user is admin
271                 if (is_site_admin()) {
272                         $nav['admin'] = ['admin/', DI::l10n()->t('Admin'), '', DI::l10n()->t('Site setup and configuration')];
273                 }
274
275                 $nav['navigation'] = ['navigation/', DI::l10n()->t('Navigation'), '', DI::l10n()->t('Site map')];
276
277                 // Provide a banner/logo/whatever
278                 $banner = Config::get('system', 'banner');
279                 if (is_null($banner)) {
280                         $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
281                 }
282
283                 Hook::callAll('nav_info', $nav);
284
285                 return [
286                         'sitelocation' => $sitelocation,
287                         'nav' => $nav,
288                         'banner' => $banner,
289                         'userinfo' => $userinfo,
290                 ];
291         }
292 }