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