]> git.mxchange.org Git - friendica.git/blob - src/Content/Nav.php
Merge pull request #8191 from MrPetovan/task/7967-mastodon-api-custom_emojis
[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                         '$clear_notifs' => DI::l10n()->t('Clear notifications'),
77                         '$search_hint'  => DI::l10n()->t('@name, !forum, #tags, content')
78                 ]);
79
80                 Hook::callAll('page_header', $nav);
81
82                 return $nav;
83         }
84
85         /**
86          * Returns the addon app menu
87          *
88          * @return array
89          */
90         public static function getAppMenu()
91         {
92                 if (is_null(self::$app_menu)) {
93                         self::populateAppMenu();
94                 }
95
96                 return self::$app_menu;
97         }
98
99         /**
100          * Fills the apps static variable with apps that require a menu
101          */
102         private static function populateAppMenu()
103         {
104                 self::$app_menu = [];
105
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];
110
111                         Hook::callAll('app_menu', $arr);
112
113                         self::$app_menu = $arr['app_menu'];
114                 }
115         }
116
117         /**
118          * Prepares a list of navigation links
119          *
120          * @param  App   $a
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
127          */
128         private static function getInfo(App $a)
129         {
130                 $ssl_state = ((local_user()) ? true : false);
131
132                 /*
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.
136                  */
137
138                 $myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
139
140                 $sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
141
142                 // nav links: array of array('href', 'text', 'extra css classes', 'title')
143                 $nav = [];
144
145                 // Display login or logout
146                 $nav['usermenu'] = [];
147                 $userinfo = null;
148
149                 if (Session::isAuthenticated()) {
150                         $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
151                 } else {
152                         $nav['login'] = ['login', DI::l10n()->t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
153                 }
154
155                 if (local_user()) {
156                         // user menu
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')];
163
164                         // user info
165                         $contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
166                         $userinfo = [
167                                 'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'),
168                                 'name' => $a->user['username'],
169                         ];
170                 }
171
172                 // "Home" should also take you home from an authenticated remote profile connection
173                 $homelink = Profile::getMyURL();
174                 if (! $homelink) {
175                         $homelink = Session::get('visitor_home', '');
176                 }
177
178                 if ((DI::module()->getName() != 'home') && (! (local_user()))) {
179                         $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')];
180                 }
181
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')];
184                 }
185
186                 $help_url = 'help';
187
188                 if (!DI::config()->get('system', 'hide_help')) {
189                         $nav['help'] = [$help_url, DI::l10n()->t('Help'), '', DI::l10n()->t('Help and documentation')];
190                 }
191
192                 if (count(self::getAppMenu()) > 0) {
193                         $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')];
194                 }
195
196                 if (local_user() || !DI::config()->get('system', 'local_search')) {
197                         $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')];
198
199                         $nav['searchoption'] = [
200                                 DI::l10n()->t('Full Text'),
201                                 DI::l10n()->t('Tags'),
202                                 DI::l10n()->t('Contacts')
203                         ];
204
205                         if (DI::config()->get('system', 'poco_local_search')) {
206                                 $nav['searchoption'][] = DI::l10n()->t('Forums');
207                         }
208                 }
209
210                 $gdirpath = 'directory';
211
212                 if (strlen(DI::config()->get('system', 'singleuser'))) {
213                         $gdir = DI::config()->get('system', 'directory');
214                         if (strlen($gdir)) {
215                                 $gdirpath = Profile::zrl($gdir, true);
216                         }
217                 }
218
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')];
222                 }
223
224                 if (local_user()) {
225                         $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
226                 }
227
228                 $nav['directory'] = [$gdirpath, DI::l10n()->t('Directory'), '', DI::l10n()->t('People directory')];
229
230                 $nav['about'] = ['friendica', DI::l10n()->t('Information'), '', DI::l10n()->t('Information about this friendica instance')];
231
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')];
234                 }
235
236                 // The following nav links are only show to logged in users
237                 if (local_user()) {
238                         $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
239
240                         $nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
241
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')];
248                         }
249
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')];
254
255                         if (is_array($a->identities) && count($a->identities) > 1) {
256                                 $nav['delegation'] = ['delegation', DI::l10n()->t('Delegation'), '', DI::l10n()->t('Manage other pages')];
257                         }
258
259                         $nav['settings'] = ['settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
260
261                         $nav['contacts'] = ['contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
262                 }
263
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')];
267                 }
268
269                 $nav['navigation'] = ['navigation/', DI::l10n()->t('Navigation'), '', DI::l10n()->t('Site map')];
270
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>';
275                 }
276
277                 Hook::callAll('nav_info', $nav);
278
279                 return [
280                         'sitelocation' => $sitelocation,
281                         'nav' => $nav,
282                         'banner' => $banner,
283                         'userinfo' => $userinfo,
284                 ];
285         }
286 }