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