3 * @file src/Content/Nav.php
5 namespace Friendica\Content;
8 use Friendica\Core\Hook;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
13 use Friendica\Model\Profile;
14 use Friendica\Model\User;
18 private static $selected = [
24 'introductions' => null,
25 'notifications' => null,
36 * An array of HTML links provided by addons providing a module via the app_menu hook
40 private static $app_menu = null;
43 * Set a menu item in navbar as selected
47 public static function setSelected($item)
49 self::$selected[$item] = 'selected';
53 * Build page header and site navigation bars
57 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
59 public static function build(App $a)
61 // Placeholder div for popup panel
62 $nav = '<div id="panel" style="display: none;"></div>';
64 $nav_info = self::getInfo($a);
66 $tpl = Renderer::getMarkupTemplate('nav.tpl');
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')
81 Hook::callAll('page_header', $nav);
87 * Returns the addon app menu
91 public static function getAppMenu()
93 if (is_null(self::$app_menu)) {
94 self::populateAppMenu();
97 return self::$app_menu;
101 * Fills the apps static variable with apps that require a menu
103 private static function populateAppMenu()
105 self::$app_menu = [];
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];
112 Hook::callAll('app_menu', $arr);
114 self::$app_menu = $arr['app_menu'];
119 * Prepares a list of navigation links
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
129 private static function getInfo(App $a)
131 $ssl_state = ((local_user()) ? true : false);
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.
139 $myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
141 $sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
143 // nav links: array of array('href', 'text', 'extra css classes', 'title')
146 // Display login or logout
147 $nav['usermenu'] = [];
150 if (Session::isAuthenticated()) {
151 $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
153 $nav['login'] = ['login', DI::l10n()->t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
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')];
166 $contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
168 'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'),
169 'name' => $a->user['username'],
173 // "Home" should also take you home from an authenticated remote profile connection
174 $homelink = Profile::getMyURL();
176 $homelink = Session::get('visitor_home', '');
179 if ((DI::module()->getName() != 'home') && (! (local_user()))) {
180 $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')];
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')];
189 if (!DI::config()->get('system', 'hide_help')) {
190 $nav['help'] = [$help_url, DI::l10n()->t('Help'), '', DI::l10n()->t('Help and documentation')];
193 if (count(self::getAppMenu()) > 0) {
194 $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')];
197 if (local_user() || !DI::config()->get('system', 'local_search')) {
198 $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')];
200 $nav['searchoption'] = [
201 DI::l10n()->t('Full Text'),
202 DI::l10n()->t('Tags'),
203 DI::l10n()->t('Contacts')
206 if (DI::config()->get('system', 'poco_local_search')) {
207 $nav['searchoption'][] = DI::l10n()->t('Forums');
211 $gdirpath = 'directory';
213 if (strlen(DI::config()->get('system', 'singleuser'))) {
214 $gdir = DI::config()->get('system', 'directory');
216 $gdirpath = Profile::zrl($gdir, true);
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')];
226 $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
229 $nav['directory'] = [$gdirpath, DI::l10n()->t('Directory'), '', DI::l10n()->t('People directory')];
231 $nav['about'] = ['friendica', DI::l10n()->t('Information'), '', DI::l10n()->t('Information about this friendica instance')];
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')];
237 // The following nav links are only show to logged in users
239 $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
241 $nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
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')];
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')];
256 if (is_array($a->identities) && count($a->identities) > 1) {
257 $nav['delegation'] = ['delegation', DI::l10n()->t('Delegation'), '', DI::l10n()->t('Manage other pages')];
260 $nav['settings'] = ['settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
262 $nav['contacts'] = ['contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
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')];
270 $nav['navigation'] = ['navigation/', DI::l10n()->t('Navigation'), '', DI::l10n()->t('Site map')];
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>';
278 Hook::callAll('nav_info', $nav);
281 'sitelocation' => $sitelocation,
284 'userinfo' => $userinfo,