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 '$clear_notifs' => DI::l10n()->t('Clear notifications'),
77 '$search_hint' => DI::l10n()->t('@name, !forum, #tags, content')
80 Hook::callAll('page_header', $nav);
86 * Returns the addon app menu
90 public static function getAppMenu()
92 if (is_null(self::$app_menu)) {
93 self::populateAppMenu();
96 return self::$app_menu;
100 * Fills the apps static variable with apps that require a menu
102 private static function populateAppMenu()
104 self::$app_menu = [];
106 //Don't populate apps_menu if apps are private
107 $privateapps = DI::config()->get('config', 'private_addons', false);
108 if (local_user() || !$privateapps) {
109 $arr = ['app_menu' => self::$app_menu];
111 Hook::callAll('app_menu', $arr);
113 self::$app_menu = $arr['app_menu'];
118 * Prepares a list of navigation links
121 * @return array Navigation links
122 * string 'sitelocation' => The webbie (username@site.com)
123 * array 'nav' => Array of links used in the nav menu
124 * string 'banner' => Formatted html link with banner image
125 * array 'userinfo' => Array of user information (name, icon)
126 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
128 private static function getInfo(App $a)
130 $ssl_state = ((local_user()) ? true : false);
133 * Our network is distributed, and as you visit friends some of the
134 * sites look exactly the same - it isn't always easy to know where you are.
135 * Display the current site location as a navigation aid.
138 $myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
140 $sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
142 // nav links: array of array('href', 'text', 'extra css classes', 'title')
145 // Display login or logout
146 $nav['usermenu'] = [];
149 if (Session::isAuthenticated()) {
150 $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
152 $nav['login'] = ['login', DI::l10n()->t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
157 $nav['usermenu'][] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
158 $nav['usermenu'][] = ['profile/' . $a->user['nickname'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
159 $nav['usermenu'][] = ['photos/' . $a->user['nickname'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
160 $nav['usermenu'][] = ['videos/' . $a->user['nickname'], DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')];
161 $nav['usermenu'][] = ['events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')];
162 $nav['usermenu'][] = ['notes/', DI::l10n()->t('Personal notes'), '', DI::l10n()->t('Your personal notes')];
165 $contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
167 'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'),
168 'name' => $a->user['username'],
172 // "Home" should also take you home from an authenticated remote profile connection
173 $homelink = Profile::getMyURL();
175 $homelink = Session::get('visitor_home', '');
178 if ((DI::module()->getName() != 'home') && (! (local_user()))) {
179 $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')];
182 if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !Session::isAuthenticated()) {
183 $nav['register'] = ['register', DI::l10n()->t('Register'), '', DI::l10n()->t('Create an account')];
188 if (!DI::config()->get('system', 'hide_help')) {
189 $nav['help'] = [$help_url, DI::l10n()->t('Help'), '', DI::l10n()->t('Help and documentation')];
192 if (count(self::getAppMenu()) > 0) {
193 $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')];
196 if (local_user() || !DI::config()->get('system', 'local_search')) {
197 $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')];
199 $nav['searchoption'] = [
200 DI::l10n()->t('Full Text'),
201 DI::l10n()->t('Tags'),
202 DI::l10n()->t('Contacts')
205 if (DI::config()->get('system', 'poco_local_search')) {
206 $nav['searchoption'][] = DI::l10n()->t('Forums');
210 $gdirpath = 'directory';
212 if (strlen(DI::config()->get('system', 'singleuser'))) {
213 $gdir = DI::config()->get('system', 'directory');
215 $gdirpath = Profile::zrl($gdir, true);
219 if ((local_user() || DI::config()->get('system', 'community_page_style') != CP_NO_COMMUNITY_PAGE) &&
220 !(DI::config()->get('system', 'community_page_style') == CP_NO_INTERNAL_COMMUNITY)) {
221 $nav['community'] = ['community', DI::l10n()->t('Community'), '', DI::l10n()->t('Conversations on this and other servers')];
225 $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
228 $nav['directory'] = [$gdirpath, DI::l10n()->t('Directory'), '', DI::l10n()->t('People directory')];
230 $nav['about'] = ['friendica', DI::l10n()->t('Information'), '', DI::l10n()->t('Information about this friendica instance')];
232 if (DI::config()->get('system', 'tosdisplay')) {
233 $nav['tos'] = ['tos', DI::l10n()->t('Terms of Service'), '', DI::l10n()->t('Terms of Service of this Friendica instance')];
236 // The following nav links are only show to logged in users
238 $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
240 $nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
242 // Don't show notifications for public communities
243 if (Session::get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
244 $nav['introductions'] = ['notifications/intros', DI::l10n()->t('Introductions'), '', DI::l10n()->t('Friend Requests')];
245 $nav['notifications'] = ['notifications', DI::l10n()->t('Notifications'), '', DI::l10n()->t('Notifications')];
246 $nav['notifications']['all'] = ['notifications/system', DI::l10n()->t('See all notifications'), '', ''];
247 $nav['notifications']['mark'] = ['', DI::l10n()->t('Mark as seen'), '', DI::l10n()->t('Mark all system notifications seen')];
250 $nav['messages'] = ['message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')];
251 $nav['messages']['inbox'] = ['message', DI::l10n()->t('Inbox'), '', DI::l10n()->t('Inbox')];
252 $nav['messages']['outbox'] = ['message/sent', DI::l10n()->t('Outbox'), '', DI::l10n()->t('Outbox')];
253 $nav['messages']['new'] = ['message/new', DI::l10n()->t('New Message'), '', DI::l10n()->t('New Message')];
255 if (is_array($a->identities) && count($a->identities) > 1) {
256 $nav['delegation'] = ['delegation', DI::l10n()->t('Delegation'), '', DI::l10n()->t('Manage other pages')];
259 $nav['settings'] = ['settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
261 $nav['contacts'] = ['contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
264 // Show the link to the admin configuration page if user is admin
265 if (is_site_admin()) {
266 $nav['admin'] = ['admin/', DI::l10n()->t('Admin'), '', DI::l10n()->t('Site setup and configuration')];
269 $nav['navigation'] = ['navigation/', DI::l10n()->t('Navigation'), '', DI::l10n()->t('Site map')];
271 // Provide a banner/logo/whatever
272 $banner = DI::config()->get('system', 'banner');
273 if (is_null($banner)) {
274 $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>';
277 Hook::callAll('nav_info', $nav);
280 'sitelocation' => $sitelocation,
283 'userinfo' => $userinfo,