3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Content;
24 use Friendica\App\BaseURL;
25 use Friendica\App\Router;
26 use Friendica\Core\Config\Capability\IManageConfigValues;
27 use Friendica\Core\Hook;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Renderer;
30 use Friendica\Core\Session\Capability\IHandleUserSessions;
31 use Friendica\Database\Database;
32 use Friendica\Model\Contact;
33 use Friendica\Model\Profile;
34 use Friendica\Model\User;
35 use Friendica\Module\Conversation\Community;
36 use Friendica\Module\Home;
37 use Friendica\Module\Security\Login;
38 use Friendica\Network\HTTPException;
42 private static $selected = [
48 'introductions' => null,
49 'notifications' => null,
60 * An array of HTML links provided by addons providing a module via the app_menu hook
64 private $appMenu = null;
70 /** @var IHandleUserSessions */
74 /** @var IManageConfigValues */
79 public function __construct(BaseURL $baseUrl, L10n $l10n, IHandleUserSessions $session, Database $database, IManageConfigValues $config, Router $router)
81 $this->baseUrl = $baseUrl;
83 $this->session = $session;
84 $this->database = $database;
85 $this->config = $config;
86 $this->router = $router;
90 * Set a menu item in navbar as selected
94 public static function setSelected(string $item)
96 self::$selected[$item] = 'selected';
100 * Build page header and site navigation bars
103 * @throws HTTPException\InternalServerErrorException
104 * @throws HTTPException\MethodNotAllowedException
105 * @throws HTTPException\ServiceUnavailableException
107 public function getHtml(): string
109 // Placeholder div for popup panel
110 $nav = '<div id="panel" style="display: none;"></div>';
112 $nav_info = $this->getInfo();
114 $tpl = Renderer::getMarkupTemplate('nav.tpl');
116 $nav .= Renderer::replaceMacros($tpl, [
117 '$sitelocation' => $nav_info['sitelocation'],
118 '$nav' => $nav_info['nav'],
119 '$banner' => $nav_info['banner'],
120 '$emptynotifications' => $this->l10n->t('Nothing new here'),
121 '$userinfo' => $nav_info['userinfo'],
122 '$sel' => self::$selected,
123 '$apps' => $this->getAppMenu(),
124 '$home' => $this->l10n->t('Go back'),
125 '$clear_notifs' => $this->l10n->t('Clear notifications'),
126 '$search_hint' => $this->l10n->t('@name, !group, #tags, content')
129 Hook::callAll('page_header', $nav);
135 * Returns the addon app menu
138 * @throws HTTPException\InternalServerErrorException
140 public function getAppMenu(): array
142 if (is_null($this->appMenu)) {
143 $this->appMenu = $this->populateAppMenu();
146 return $this->appMenu;
150 * Returns menus for apps that require one
153 * @throws HTTPException\InternalServerErrorException
155 private function populateAppMenu(): array
159 //Don't populate apps_menu if apps are private
161 $this->session->getLocalUserId()
162 || !$this->config->get('config', 'private_addons', false)
164 $arr = ['app_menu' => $appMenu];
166 Hook::callAll('app_menu', $arr);
168 $appMenu = $arr['app_menu'];
175 * Prepares a list of navigation links
177 * @return array Navigation links
178 * string 'sitelocation' => The webbie (username@site.com)
179 * array 'nav' => Array of links used in the nav menu
180 * string 'banner' => Formatted html link with banner image
181 * array 'userinfo' => Array of user information (name, icon)
182 * @throws HTTPException\InternalServerErrorException
183 * @throws HTTPException\MethodNotAllowedException
185 private function getInfo(): array
188 * Our network is distributed, and as you visit friends some
189 * sites look exactly the same - it isn't always easy to know where you are.
190 * Display the current site location as a navigation aid.
193 $myident = !empty($this->session->getLocalUserNickname()) ? $this->session->getLocalUserNickname() . '@' : '';
195 $sitelocation = $myident . substr($this->baseUrl, strpos($this->baseUrl, '//') + 2);
199 'moderation' => null,
206 'langselector' => null,
209 'notifications' => null,
215 // Display login or logout
218 // nav links: array of array('href', 'text', 'extra css classes', 'title')
219 if ($this->session->isAuthenticated()) {
220 $nav['logout'] = ['logout', $this->l10n->t('Logout'), '', $this->l10n->t('End this session')];
222 $nav['login'] = ['login', $this->l10n->t('Login'), ($this->router->getModuleClass() == Login::class ? 'selected' : ''), $this->l10n->t('Sign in')];
225 if ($this->session->isAuthenticated()) {
227 $nav['usermenu'][] = ['profile/' . $this->session->getLocalUserNickname(), $this->l10n->t('Conversations'), '', $this->l10n->t('Conversations you started')];
228 $nav['usermenu'][] = ['profile/' . $this->session->getLocalUserNickname() . '/profile', $this->l10n->t('Profile'), '', $this->l10n->t('Your profile page')];
229 $nav['usermenu'][] = ['profile/' . $this->session->getLocalUserNickname() . '/photos', $this->l10n->t('Photos'), '', $this->l10n->t('Your photos')];
230 $nav['usermenu'][] = ['profile/' . $this->session->getLocalUserNickname() . '/media', $this->l10n->t('Media'), '', $this->l10n->t('Your postings with media')];
231 $nav['usermenu'][] = ['calendar/', $this->l10n->t('Calendar'), '', $this->l10n->t('Your calendar')];
232 $nav['usermenu'][] = ['notes/', $this->l10n->t('Personal notes'), '', $this->l10n->t('Your personal notes')];
235 $contact = $this->database->selectFirst('contact', ['id', 'url', 'avatar', 'micro', 'name', 'nick', 'baseurl', 'updated'], ['uid' => $this->session->getLocalUserId(), 'self' => true]);
237 'icon' => Contact::getMicro($contact),
238 'name' => $contact['name'],
242 // "Home" should also take you home from an authenticated remote profile connection
243 $homelink = $this->session->getMyUrl();
245 $homelink = $this->session->get('visitor_home', '');
248 if ($this->router->getModuleClass() != Home::class && !$this->session->getLocalUserId()) {
249 $nav['home'] = [$homelink, $this->l10n->t('Home'), '', $this->l10n->t('Home Page')];
252 if (intval($this->config->get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !$this->session->isAuthenticated()) {
253 $nav['register'] = ['register', $this->l10n->t('Register'), '', $this->l10n->t('Create an account')];
258 if (!$this->config->get('system', 'hide_help')) {
259 $nav['help'] = [$help_url, $this->l10n->t('Help'), '', $this->l10n->t('Help and documentation')];
262 if (count($this->getAppMenu()) > 0) {
263 $nav['apps'] = ['apps', $this->l10n->t('Apps'), '', $this->l10n->t('Addon applications, utilities, games')];
266 if ($this->session->getLocalUserId() || !$this->config->get('system', 'local_search')) {
267 $nav['search'] = ['search', $this->l10n->t('Search'), '', $this->l10n->t('Search site content')];
269 $nav['searchoption'] = [
270 $this->l10n->t('Full Text'),
271 $this->l10n->t('Tags'),
272 $this->l10n->t('Contacts')
275 if ($this->config->get('system', 'poco_local_search')) {
276 $nav['searchoption'][] = $this->l10n->t('Groups');
280 $gdirpath = 'directory';
281 if ($this->config->get('system', 'singleuser') && $this->config->get('system', 'directory')) {
282 $gdirpath = Profile::zrl($this->config->get('system', 'directory'), true);
285 if (($this->session->getLocalUserId() || $this->config->get('system', 'community_page_style') != Community::DISABLED_VISITOR) &&
286 !($this->config->get('system', 'community_page_style') == Community::DISABLED)) {
287 $nav['community'] = ['community', $this->l10n->t('Community'), '', $this->l10n->t('Conversations on this and other servers')];
290 if ($this->session->getLocalUserId()) {
291 $nav['calendar'] = ['calendar', $this->l10n->t('Calendar'), '', $this->l10n->t('Calendar')];
294 $nav['directory'] = [$gdirpath, $this->l10n->t('Directory'), '', $this->l10n->t('People directory')];
296 $nav['about'] = ['friendica', $this->l10n->t('Information'), '', $this->l10n->t('Information about this friendica instance')];
298 if ($this->config->get('system', 'tosdisplay')) {
299 $nav['tos'] = ['tos', $this->l10n->t('Terms of Service'), '', $this->l10n->t('Terms of Service of this Friendica instance')];
302 // The following nav links are only show to logged-in users
303 if ($this->session->getLocalUserNickname()) {
304 $nav['network'] = ['network', $this->l10n->t('Network'), '', $this->l10n->t('Conversations from your friends')];
306 $nav['home'] = ['profile/' . $this->session->getLocalUserNickname(), $this->l10n->t('Home'), '', $this->l10n->t('Your posts and conversations')];
308 // Don't show notifications for public communities
309 if ($this->session->get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
310 $nav['introductions'] = ['notifications/intros', $this->l10n->t('Introductions'), '', $this->l10n->t('Friend Requests')];
311 $nav['notifications'] = ['notifications', $this->l10n->t('Notifications'), '', $this->l10n->t('Notifications')];
312 $nav['notifications']['all'] = ['notifications/system', $this->l10n->t('See all notifications'), '', ''];
313 $nav['notifications']['mark'] = ['', $this->l10n->t('Mark as seen'), '', $this->l10n->t('Mark all system notifications as seen')];
316 $nav['messages'] = ['message', $this->l10n->t('Messages'), '', $this->l10n->t('Private mail')];
317 $nav['messages']['inbox'] = ['message', $this->l10n->t('Inbox'), '', $this->l10n->t('Inbox')];
318 $nav['messages']['outbox'] = ['message/sent', $this->l10n->t('Outbox'), '', $this->l10n->t('Outbox')];
319 $nav['messages']['new'] = ['message/new', $this->l10n->t('New Message'), '', $this->l10n->t('New Message')];
321 if (User::hasIdentities($this->session->getSubManagedUserId() ?: $this->session->getLocalUserId())) {
322 $nav['delegation'] = ['delegation', $this->l10n->t('Accounts'), '', $this->l10n->t('Manage other pages')];
325 $nav['settings'] = ['settings', $this->l10n->t('Settings'), '', $this->l10n->t('Account settings')];
327 $nav['contacts'] = ['contact', $this->l10n->t('Contacts'), '', $this->l10n->t('Manage/edit friends and contacts')];
330 // Show the link to the admin configuration page if user is admin
331 if ($this->session->isSiteAdmin()) {
332 $nav['admin'] = ['admin/', $this->l10n->t('Admin'), '', $this->l10n->t('Site setup and configuration')];
333 $nav['moderation'] = ['moderation/', $this->l10n->t('Moderation'), '', $this->l10n->t('Content and user moderation')];
336 $nav['navigation'] = ['navigation/', $this->l10n->t('Navigation'), '', $this->l10n->t('Site map')];
338 // Provide a banner/logo/whatever
339 $banner = $this->config->get('system', 'banner');
340 if (is_null($banner)) {
341 $banner = '<a href="https://friendi.ca"><img id="logo-img" width="32" height="32" src="images/friendica.svg" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
347 'sitelocation' => $sitelocation,
348 'userinfo' => $userinfo,
351 Hook::callAll('nav_info', $nav_info);